1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2010 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 documentation 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 | //! [0]
|
---|
43 | #include <QtDesigner>
|
---|
44 | //! [0]
|
---|
45 |
|
---|
46 |
|
---|
47 | //! [1]
|
---|
48 | CONFIG += designer
|
---|
49 | //! [1]
|
---|
50 |
|
---|
51 |
|
---|
52 | //! [2]
|
---|
53 | QDesignerMemberSheetExtension *memberSheet = 0;
|
---|
54 | QExtensionManager manager = formEditor->extensionManager();
|
---|
55 |
|
---|
56 | memberSheet = qt_extension<QDesignerMemberSheetExtension*>(manager, widget);
|
---|
57 | int index = memberSheet->indexOf(setEchoMode);
|
---|
58 | memberSheet->setVisible(index, false);
|
---|
59 |
|
---|
60 | delete memberSheet;
|
---|
61 | //! [2]
|
---|
62 |
|
---|
63 |
|
---|
64 | //! [3]
|
---|
65 | class MyMemberSheetExtension : public QObject,
|
---|
66 | public QDesignerMemberSheetExtension
|
---|
67 | {
|
---|
68 | Q_OBJECT
|
---|
69 | Q_INTERFACES(QDesignerMemberSheetExtension)
|
---|
70 |
|
---|
71 | public:
|
---|
72 | ...
|
---|
73 | }
|
---|
74 | //! [3]
|
---|
75 |
|
---|
76 |
|
---|
77 | //! [4]
|
---|
78 | QObject *ANewExtensionFactory::createExtension(QObject *object,
|
---|
79 | const QString &iid, QObject *parent) const
|
---|
80 | {
|
---|
81 | if (iid != Q_TYPEID(QDesignerMemberSheetExtension))
|
---|
82 | return 0;
|
---|
83 |
|
---|
84 | if (MyCustomWidget *widget = qobject_cast<MyCustomWidget*>
|
---|
85 | (object))
|
---|
86 | return new MyMemberSheetExtension(widget, parent);
|
---|
87 |
|
---|
88 | return 0;
|
---|
89 | }
|
---|
90 | //! [4]
|
---|
91 |
|
---|
92 |
|
---|
93 | //! [5]
|
---|
94 | QObject *AGeneralExtensionFactory::createExtension(QObject *object,
|
---|
95 | const QString &iid, QObject *parent) const
|
---|
96 | {
|
---|
97 | MyCustomWidget *widget = qobject_cast<MyCustomWidget*>(object);
|
---|
98 |
|
---|
99 | if (widget && (iid == Q_TYPEID(QDesignerTaskMenuExtension))) {
|
---|
100 | return new MyTaskMenuExtension(widget, parent);
|
---|
101 |
|
---|
102 | } else if (widget && (iid == Q_TYPEID(QDesignerMemberSheetExtension))) {
|
---|
103 | return new MyMemberSheetExtension(widget, parent);
|
---|
104 |
|
---|
105 | } else {
|
---|
106 | return 0;
|
---|
107 | }
|
---|
108 | }
|
---|
109 | //! [5]
|
---|
110 |
|
---|
111 |
|
---|
112 | //! [6]
|
---|
113 | class MyContainerExtension : public QObject,
|
---|
114 | public QDesignerContainerExtension
|
---|
115 | {
|
---|
116 | Q_OBJECT
|
---|
117 | Q_INTERFACES(QDesignerContainerExtension)
|
---|
118 |
|
---|
119 | public:
|
---|
120 | MyContainerExtension(MyCustomWidget *widget,
|
---|
121 | QObject *parent = 0);
|
---|
122 | int count() const;
|
---|
123 | QWidget *widget(int index) const;
|
---|
124 | int currentIndex() const;
|
---|
125 | void setCurrentIndex(int index);
|
---|
126 | void addWidget(QWidget *widget);
|
---|
127 | void insertWidget(int index, QWidget *widget);
|
---|
128 | void remove(int index);
|
---|
129 |
|
---|
130 | private:
|
---|
131 | MyCustomWidget *myWidget;
|
---|
132 | };
|
---|
133 | //! [6]
|
---|
134 |
|
---|
135 |
|
---|
136 | //! [7]
|
---|
137 | QObject *ANewExtensionFactory::createExtension(QObject *object,
|
---|
138 | const QString &iid, QObject *parent) const
|
---|
139 | {
|
---|
140 | if (iid != Q_TYPEID(QDesignerContainerExtension))
|
---|
141 | return 0;
|
---|
142 |
|
---|
143 | if (MyCustomWidget *widget = qobject_cast<MyCustomWidget*>
|
---|
144 | (object))
|
---|
145 | return new MyContainerExtension(widget, parent);
|
---|
146 |
|
---|
147 | return 0;
|
---|
148 | }
|
---|
149 | //! [7]
|
---|
150 |
|
---|
151 |
|
---|
152 | //! [8]
|
---|
153 | QObject *AGeneralExtensionFactory::createExtension(QObject *object,
|
---|
154 | const QString &iid, QObject *parent) const
|
---|
155 | {
|
---|
156 | MyCustomWidget *widget = qobject_cast<MyCustomWidget*>(object);
|
---|
157 |
|
---|
158 | if (widget && (iid == Q_TYPEID(QDesignerTaskMenuExtension))) {
|
---|
159 | return new MyTaskMenuExtension(widget, parent);
|
---|
160 |
|
---|
161 | } else if (widget && (iid == Q_TYPEID(QDesignerContainerExtension))) {
|
---|
162 | return new MyContainerExtension(widget, parent);
|
---|
163 |
|
---|
164 | } else {
|
---|
165 | return 0;
|
---|
166 | }
|
---|
167 | }
|
---|
168 | //! [8]
|
---|
169 |
|
---|
170 |
|
---|
171 | //! [9]
|
---|
172 | class MyTaskMenuExtension : public QObject,
|
---|
173 | public QDesignerTaskMenuExtension
|
---|
174 | {
|
---|
175 | Q_OBJECT
|
---|
176 | Q_INTERFACES(QDesignerTaskMenuExtension)
|
---|
177 |
|
---|
178 | public:
|
---|
179 | MyTaskMenuExtension(MyCustomWidget *widget, QObject *parent);
|
---|
180 |
|
---|
181 | QAction *preferredEditAction() const;
|
---|
182 | QList<QAction *> taskActions() const;
|
---|
183 |
|
---|
184 | private slots:
|
---|
185 | void mySlot();
|
---|
186 |
|
---|
187 | private:
|
---|
188 | MyCustomWidget *widget;
|
---|
189 | QAction *myAction;
|
---|
190 | };
|
---|
191 | //! [9]
|
---|
192 |
|
---|
193 |
|
---|
194 | //! [10]
|
---|
195 | QObject *ANewExtensionFactory::createExtension(QObject *object,
|
---|
196 | const QString &iid, QObject *parent) const
|
---|
197 | {
|
---|
198 | if (iid != Q_TYPEID(QDesignerTaskMenuExtension))
|
---|
199 | return 0;
|
---|
200 |
|
---|
201 | if (MyCustomWidget *widget = qobject_cast<MyCustomWidget*>(object))
|
---|
202 | return new MyTaskMenuExtension(widget, parent);
|
---|
203 |
|
---|
204 | return 0;
|
---|
205 | }
|
---|
206 | //! [10]
|
---|
207 |
|
---|
208 |
|
---|
209 | //! [11]
|
---|
210 | QObject *AGeneralExtensionFactory::createExtension(QObject *object,
|
---|
211 | const QString &iid, QObject *parent) const
|
---|
212 | {
|
---|
213 | MyCustomWidget *widget = qobject_cast<MyCustomWidget*>(object);
|
---|
214 |
|
---|
215 | if (widget && (iid == Q_TYPEID(QDesignerContainerExtension))) {
|
---|
216 | return new MyContainerExtension(widget, parent);
|
---|
217 |
|
---|
218 | } else if (widget && (iid == Q_TYPEID(QDesignerTaskMenuExtension))) {
|
---|
219 | return new MyTaskMenuExtension(widget, parent);
|
---|
220 |
|
---|
221 | } else {
|
---|
222 | return 0;
|
---|
223 | }
|
---|
224 | }
|
---|
225 | //! [11]
|
---|
226 |
|
---|
227 |
|
---|
228 | //! [12]
|
---|
229 | #include customwidgetoneinterface.h
|
---|
230 | #include customwidgettwointerface.h
|
---|
231 | #include customwidgetthreeinterface.h
|
---|
232 |
|
---|
233 | #include <QtDesigner/QtDesigner>
|
---|
234 | #include <QtCore/qplugin.h>
|
---|
235 |
|
---|
236 | class MyCustomWidgets: public QObject, public QDesignerCustomWidgetCollectionInterface
|
---|
237 | {
|
---|
238 | Q_OBJECT
|
---|
239 | Q_INTERFACES(QDesignerCustomWidgetCollectionInterface)
|
---|
240 |
|
---|
241 | public:
|
---|
242 | MyCustomWidgets(QObject *parent = 0);
|
---|
243 |
|
---|
244 | virtual QList<QDesignerCustomWidgetInterface*> customWidgets() const;
|
---|
245 |
|
---|
246 | private:
|
---|
247 | QList<QDesignerCustomWidgetInterface*> widgets;
|
---|
248 | };
|
---|
249 | //! [12]
|
---|
250 |
|
---|
251 |
|
---|
252 | //! [13]
|
---|
253 | MyCustomWidgets::MyCustomWidgets(QObject *parent)
|
---|
254 | : QObject(parent)
|
---|
255 | {
|
---|
256 | widgets.append(new CustomWidgetOneInterface(this));
|
---|
257 | widgets.append(new CustomWidgetTwoInterface(this));
|
---|
258 | widgets.append(new CustomWidgetThreeInterface(this));
|
---|
259 | }
|
---|
260 |
|
---|
261 | QList<QDesignerCustomWidgetInterface*> MyCustomWidgets::customWidgets() const
|
---|
262 | {
|
---|
263 | return widgets;
|
---|
264 | }
|
---|
265 |
|
---|
266 | Q_EXPORT_PLUGIN2(customwidgetsplugin, MyCustomWidgets)
|
---|
267 | //! [13]
|
---|
268 |
|
---|
269 |
|
---|
270 | //! [14]
|
---|
271 | Q_EXPORT_PLUGIN2(customwidgetplugin, MyCustomWidget)
|
---|
272 | //! [14]
|
---|
273 |
|
---|
274 |
|
---|
275 | //! [15]
|
---|
276 | QDesignerPropertySheetExtension *propertySheet = 0;
|
---|
277 | QExtensionManager manager = formEditor->extensionManager();
|
---|
278 |
|
---|
279 | propertySheet = qt_extension<QDesignerPropertySheetExtension*>(manager, widget);
|
---|
280 | int index = propertySheet->indexOf(QLatin1String("margin"));
|
---|
281 |
|
---|
282 | propertySheet->setProperty(index, 10);
|
---|
283 | propertySheet->setChanged(index, true);
|
---|
284 |
|
---|
285 | delete propertySheet;
|
---|
286 | //! [15]
|
---|
287 |
|
---|
288 |
|
---|
289 | //! [16]
|
---|
290 | class MyPropertySheetExtension : public QObject,
|
---|
291 | public QDesignerPropertySheetExtension
|
---|
292 | {
|
---|
293 | Q_OBJECT
|
---|
294 | Q_INTERFACES(QDesignerPropertySheetExtension)
|
---|
295 |
|
---|
296 | public:
|
---|
297 | ...
|
---|
298 | }
|
---|
299 | //! [16]
|
---|
300 |
|
---|
301 |
|
---|
302 | //! [17]
|
---|
303 | QObject *ANewExtensionFactory::createExtension(QObject *object,
|
---|
304 | const QString &iid, QObject *parent) const
|
---|
305 | {
|
---|
306 | if (iid != Q_TYPEID(QDesignerPropertySheetExtension))
|
---|
307 | return 0;
|
---|
308 |
|
---|
309 | if (MyCustomWidget *widget = qobject_cast<MyCustomWidget*>
|
---|
310 | (object))
|
---|
311 | return new MyPropertySheetExtension(widget, parent);
|
---|
312 |
|
---|
313 | return 0;
|
---|
314 | }
|
---|
315 | //! [17]
|
---|
316 |
|
---|
317 |
|
---|
318 | //! [18]
|
---|
319 | QObject *AGeneralExtensionFactory::createExtension(QObject *object,
|
---|
320 | const QString &iid, QObject *parent) const
|
---|
321 | {
|
---|
322 | MyCustomWidget *widget = qobject_cast<MyCustomWidget*>(object);
|
---|
323 |
|
---|
324 | if (widget && (iid == Q_TYPEID(QDesignerTaskMenuExtension))) {
|
---|
325 | return new MyTaskMenuExtension(widget, parent);
|
---|
326 |
|
---|
327 | } else if (widget && (iid == Q_TYPEID(QDesignerPropertySheetExtension))) {
|
---|
328 | return new MyPropertySheetExtension(widget, parent);
|
---|
329 |
|
---|
330 | } else {
|
---|
331 | return 0;
|
---|
332 | }
|
---|
333 | }
|
---|
334 | //! [18]
|
---|