source: trunk/tools/designer/src/plugins/activeqt/qdesigneraxwidget.h@ 561

Last change on this file since 561 was 561, checked in by Dmitry A. Kuminov, 15 years ago

trunk: Merged in qt 4.6.1 sources.

File size: 4.7 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the Qt Designer of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
15**
16** GNU Lesser General Public License Usage
17** Alternatively, this file may be used under the terms of the GNU Lesser
18** General Public License version 2.1 as published by the Free Software
19** Foundation and appearing in the file LICENSE.LGPL included in the
20** packaging of this file. Please review the following information to
21** ensure the GNU Lesser General Public License version 2.1 requirements
22** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23**
24** In addition, as a special exception, Nokia gives you certain additional
25** rights. These rights are described in the Nokia Qt LGPL Exception
26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you have questions regarding the use of this file, please contact
37** Nokia at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#ifndef QACTIVEXPLUGINOBJECT_H
43#define QACTIVEXPLUGINOBJECT_H
44
45#include <QtCore/QPointer>
46#include <QtCore/QMap>
47#include <QtGui/QWidget>
48#include <QtGui/QPixmap>
49
50QT_BEGIN_NAMESPACE
51
52class QAxWidget;
53
54/* QDesignerAxWidget aggregates QAxWidget to keep it out of the event loop while applying
55 * properties directly.
56 * Thus, it is possible to set property values in designer that are out of range
57 * for the control, which might cause it to throw exceptions.
58 *
59 * QDesignerAxWidget is the base class following the internal naming
60 * conventions that makes the control property visible to the introspection interface.
61 *
62 * The trick to aggregate a QAxWidget is to overwrite the metaObject() function
63 * generated by moc to return the QMetaObject of QAxWidget. This is what QDesignerAxPluginWidget does. */
64
65class QDesignerAxWidget : public QWidget
66{
67 Q_OBJECT
68 Q_PROPERTY(QString control READ control WRITE setControl RESET resetControl DESIGNABLE true)
69 Q_DISABLE_COPY(QDesignerAxWidget)
70
71protected:
72 explicit QDesignerAxWidget(QWidget *parent);
73
74public:
75 virtual ~QDesignerAxWidget();
76
77 bool loadControl(const QString &clsid);
78
79 void resetControl();
80 void setControl(const QString &clsid);
81 QString control() const;
82
83 QSize sizeHint() const;
84 QSize minimumSizeHint() const;
85
86 bool loaded() { return (m_axobject != 0); }
87
88 static QPixmap widgetIcon();
89
90 enum { DrawIndicator = 0x1, DrawFrame = 0x2, DrawControl = 0x4 };
91
92 unsigned drawFlags() const { return m_drawFlags; }
93 void setDrawFlags(unsigned f) { m_drawFlags = f; }
94
95protected:
96 void paintEvent(QPaintEvent *event);
97 QAxWidget *axobject() const { return m_axobject; }
98
99private:
100 const QSize m_defaultSize;
101 unsigned m_drawFlags;
102 QAxWidget *m_axobject;
103 QPixmap m_axImage;
104};
105
106class QDesignerAxPluginWidget : public QDesignerAxWidget
107{
108 // No Q_OBJECT here! - meta functionality is overriden
109public:
110 explicit QDesignerAxPluginWidget(QWidget *parent);
111 virtual ~QDesignerAxPluginWidget();
112
113 virtual const QMetaObject *metaObject() const;
114 virtual int qt_metacall(QMetaObject::Call, int, void **);
115
116private:
117 QMap<int, bool> m_propValues;
118};
119
120#if defined Q_CC_MSVC && _MSC_VER < 1300
121template <> inline QDesignerAxWidget *qobject_cast_helper<QDesignerAxWidget*>(QObject *o, QDesignerAxWidget*)
122#else
123template <> inline QDesignerAxWidget *qobject_cast<QDesignerAxWidget*>(QObject *o)
124#endif
125{
126 if (!o)
127 return 0;
128
129 // Unloaded state
130 if (strcmp(o->metaObject()->className(), "QDesignerAxWidget") == 0)
131 return static_cast<QDesignerAxPluginWidget*>(o);
132
133 // Loaded state with fake meta object
134 if (strcmp(o->metaObject()->className(), "QAxWidget") == 0)
135 return static_cast<QDesignerAxPluginWidget*>(o);
136
137 return 0;
138}
139
140QT_END_NAMESPACE
141
142#endif // ACTIVEQT_EXTRAINFO_H
Note: See TracBrowser for help on using the repository browser.