1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2011 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:BSD$
|
---|
10 | ** You may use this file under the terms of the BSD license as follows:
|
---|
11 | **
|
---|
12 | ** "Redistribution and use in source and binary forms, with or without
|
---|
13 | ** modification, are permitted provided that the following conditions are
|
---|
14 | ** met:
|
---|
15 | ** * Redistributions of source code must retain the above copyright
|
---|
16 | ** notice, this list of conditions and the following disclaimer.
|
---|
17 | ** * Redistributions in binary form must reproduce the above copyright
|
---|
18 | ** notice, this list of conditions and the following disclaimer in
|
---|
19 | ** the documentation and/or other materials provided with the
|
---|
20 | ** distribution.
|
---|
21 | ** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
|
---|
22 | ** the names of its contributors may be used to endorse or promote
|
---|
23 | ** products derived from this software without specific prior written
|
---|
24 | ** permission.
|
---|
25 | **
|
---|
26 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
---|
27 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
---|
28 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
---|
29 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
---|
30 | ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
---|
31 | ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
---|
32 | ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
33 | ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
34 | ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
35 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
---|
36 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
---|
37 | ** $QT_END_LICENSE$
|
---|
38 | **
|
---|
39 | ****************************************************************************/
|
---|
40 |
|
---|
41 | //! [0]
|
---|
42 | #include <QtDesigner>
|
---|
43 | //! [0]
|
---|
44 |
|
---|
45 |
|
---|
46 | //! [1]
|
---|
47 | CONFIG += designer
|
---|
48 | //! [1]
|
---|
49 |
|
---|
50 |
|
---|
51 | //! [2]
|
---|
52 | QDesignerMemberSheetExtension *memberSheet = 0;
|
---|
53 | QExtensionManager manager = formEditor->extensionManager();
|
---|
54 |
|
---|
55 | memberSheet = qt_extension<QDesignerMemberSheetExtension*>(manager, widget);
|
---|
56 | int index = memberSheet->indexOf(setEchoMode);
|
---|
57 | memberSheet->setVisible(index, false);
|
---|
58 |
|
---|
59 | delete memberSheet;
|
---|
60 | //! [2]
|
---|
61 |
|
---|
62 |
|
---|
63 | //! [3]
|
---|
64 | class MyMemberSheetExtension : public QObject,
|
---|
65 | public QDesignerMemberSheetExtension
|
---|
66 | {
|
---|
67 | Q_OBJECT
|
---|
68 | Q_INTERFACES(QDesignerMemberSheetExtension)
|
---|
69 |
|
---|
70 | public:
|
---|
71 | ...
|
---|
72 | }
|
---|
73 | //! [3]
|
---|
74 |
|
---|
75 |
|
---|
76 | //! [4]
|
---|
77 | QObject *ANewExtensionFactory::createExtension(QObject *object,
|
---|
78 | const QString &iid, QObject *parent) const
|
---|
79 | {
|
---|
80 | if (iid != Q_TYPEID(QDesignerMemberSheetExtension))
|
---|
81 | return 0;
|
---|
82 |
|
---|
83 | if (MyCustomWidget *widget = qobject_cast<MyCustomWidget*>
|
---|
84 | (object))
|
---|
85 | return new MyMemberSheetExtension(widget, parent);
|
---|
86 |
|
---|
87 | return 0;
|
---|
88 | }
|
---|
89 | //! [4]
|
---|
90 |
|
---|
91 |
|
---|
92 | //! [5]
|
---|
93 | QObject *AGeneralExtensionFactory::createExtension(QObject *object,
|
---|
94 | const QString &iid, QObject *parent) const
|
---|
95 | {
|
---|
96 | MyCustomWidget *widget = qobject_cast<MyCustomWidget*>(object);
|
---|
97 |
|
---|
98 | if (widget && (iid == Q_TYPEID(QDesignerTaskMenuExtension))) {
|
---|
99 | return new MyTaskMenuExtension(widget, parent);
|
---|
100 |
|
---|
101 | } else if (widget && (iid == Q_TYPEID(QDesignerMemberSheetExtension))) {
|
---|
102 | return new MyMemberSheetExtension(widget, parent);
|
---|
103 |
|
---|
104 | } else {
|
---|
105 | return 0;
|
---|
106 | }
|
---|
107 | }
|
---|
108 | //! [5]
|
---|
109 |
|
---|
110 |
|
---|
111 | //! [6]
|
---|
112 | class MyContainerExtension : public QObject,
|
---|
113 | public QDesignerContainerExtension
|
---|
114 | {
|
---|
115 | Q_OBJECT
|
---|
116 | Q_INTERFACES(QDesignerContainerExtension)
|
---|
117 |
|
---|
118 | public:
|
---|
119 | MyContainerExtension(MyCustomWidget *widget,
|
---|
120 | QObject *parent = 0);
|
---|
121 | int count() const;
|
---|
122 | QWidget *widget(int index) const;
|
---|
123 | int currentIndex() const;
|
---|
124 | void setCurrentIndex(int index);
|
---|
125 | void addWidget(QWidget *widget);
|
---|
126 | void insertWidget(int index, QWidget *widget);
|
---|
127 | void remove(int index);
|
---|
128 |
|
---|
129 | private:
|
---|
130 | MyCustomWidget *myWidget;
|
---|
131 | };
|
---|
132 | //! [6]
|
---|
133 |
|
---|
134 |
|
---|
135 | //! [7]
|
---|
136 | QObject *ANewExtensionFactory::createExtension(QObject *object,
|
---|
137 | const QString &iid, QObject *parent) const
|
---|
138 | {
|
---|
139 | if (iid != Q_TYPEID(QDesignerContainerExtension))
|
---|
140 | return 0;
|
---|
141 |
|
---|
142 | if (MyCustomWidget *widget = qobject_cast<MyCustomWidget*>
|
---|
143 | (object))
|
---|
144 | return new MyContainerExtension(widget, parent);
|
---|
145 |
|
---|
146 | return 0;
|
---|
147 | }
|
---|
148 | //! [7]
|
---|
149 |
|
---|
150 |
|
---|
151 | //! [8]
|
---|
152 | QObject *AGeneralExtensionFactory::createExtension(QObject *object,
|
---|
153 | const QString &iid, QObject *parent) const
|
---|
154 | {
|
---|
155 | MyCustomWidget *widget = qobject_cast<MyCustomWidget*>(object);
|
---|
156 |
|
---|
157 | if (widget && (iid == Q_TYPEID(QDesignerTaskMenuExtension))) {
|
---|
158 | return new MyTaskMenuExtension(widget, parent);
|
---|
159 |
|
---|
160 | } else if (widget && (iid == Q_TYPEID(QDesignerContainerExtension))) {
|
---|
161 | return new MyContainerExtension(widget, parent);
|
---|
162 |
|
---|
163 | } else {
|
---|
164 | return 0;
|
---|
165 | }
|
---|
166 | }
|
---|
167 | //! [8]
|
---|
168 |
|
---|
169 |
|
---|
170 | //! [9]
|
---|
171 | class MyTaskMenuExtension : public QObject,
|
---|
172 | public QDesignerTaskMenuExtension
|
---|
173 | {
|
---|
174 | Q_OBJECT
|
---|
175 | Q_INTERFACES(QDesignerTaskMenuExtension)
|
---|
176 |
|
---|
177 | public:
|
---|
178 | MyTaskMenuExtension(MyCustomWidget *widget, QObject *parent);
|
---|
179 |
|
---|
180 | QAction *preferredEditAction() const;
|
---|
181 | QList<QAction *> taskActions() const;
|
---|
182 |
|
---|
183 | private slots:
|
---|
184 | void mySlot();
|
---|
185 |
|
---|
186 | private:
|
---|
187 | MyCustomWidget *widget;
|
---|
188 | QAction *myAction;
|
---|
189 | };
|
---|
190 | //! [9]
|
---|
191 |
|
---|
192 |
|
---|
193 | //! [10]
|
---|
194 | QObject *ANewExtensionFactory::createExtension(QObject *object,
|
---|
195 | const QString &iid, QObject *parent) const
|
---|
196 | {
|
---|
197 | if (iid != Q_TYPEID(QDesignerTaskMenuExtension))
|
---|
198 | return 0;
|
---|
199 |
|
---|
200 | if (MyCustomWidget *widget = qobject_cast<MyCustomWidget*>(object))
|
---|
201 | return new MyTaskMenuExtension(widget, parent);
|
---|
202 |
|
---|
203 | return 0;
|
---|
204 | }
|
---|
205 | //! [10]
|
---|
206 |
|
---|
207 |
|
---|
208 | //! [11]
|
---|
209 | QObject *AGeneralExtensionFactory::createExtension(QObject *object,
|
---|
210 | const QString &iid, QObject *parent) const
|
---|
211 | {
|
---|
212 | MyCustomWidget *widget = qobject_cast<MyCustomWidget*>(object);
|
---|
213 |
|
---|
214 | if (widget && (iid == Q_TYPEID(QDesignerContainerExtension))) {
|
---|
215 | return new MyContainerExtension(widget, parent);
|
---|
216 |
|
---|
217 | } else if (widget && (iid == Q_TYPEID(QDesignerTaskMenuExtension))) {
|
---|
218 | return new MyTaskMenuExtension(widget, parent);
|
---|
219 |
|
---|
220 | } else {
|
---|
221 | return 0;
|
---|
222 | }
|
---|
223 | }
|
---|
224 | //! [11]
|
---|
225 |
|
---|
226 |
|
---|
227 | //! [12]
|
---|
228 | #include customwidgetoneinterface.h
|
---|
229 | #include customwidgettwointerface.h
|
---|
230 | #include customwidgetthreeinterface.h
|
---|
231 |
|
---|
232 | #include <QtDesigner/QtDesigner>
|
---|
233 | #include <QtCore/qplugin.h>
|
---|
234 |
|
---|
235 | class MyCustomWidgets: public QObject, public QDesignerCustomWidgetCollectionInterface
|
---|
236 | {
|
---|
237 | Q_OBJECT
|
---|
238 | Q_INTERFACES(QDesignerCustomWidgetCollectionInterface)
|
---|
239 |
|
---|
240 | public:
|
---|
241 | MyCustomWidgets(QObject *parent = 0);
|
---|
242 |
|
---|
243 | virtual QList<QDesignerCustomWidgetInterface*> customWidgets() const;
|
---|
244 |
|
---|
245 | private:
|
---|
246 | QList<QDesignerCustomWidgetInterface*> widgets;
|
---|
247 | };
|
---|
248 | //! [12]
|
---|
249 |
|
---|
250 |
|
---|
251 | //! [13]
|
---|
252 | MyCustomWidgets::MyCustomWidgets(QObject *parent)
|
---|
253 | : QObject(parent)
|
---|
254 | {
|
---|
255 | widgets.append(new CustomWidgetOneInterface(this));
|
---|
256 | widgets.append(new CustomWidgetTwoInterface(this));
|
---|
257 | widgets.append(new CustomWidgetThreeInterface(this));
|
---|
258 | }
|
---|
259 |
|
---|
260 | QList<QDesignerCustomWidgetInterface*> MyCustomWidgets::customWidgets() const
|
---|
261 | {
|
---|
262 | return widgets;
|
---|
263 | }
|
---|
264 |
|
---|
265 | Q_EXPORT_PLUGIN2(customwidgetsplugin, MyCustomWidgets)
|
---|
266 | //! [13]
|
---|
267 |
|
---|
268 |
|
---|
269 | //! [14]
|
---|
270 | Q_EXPORT_PLUGIN2(customwidgetplugin, MyCustomWidget)
|
---|
271 | //! [14]
|
---|
272 |
|
---|
273 |
|
---|
274 | //! [15]
|
---|
275 | QDesignerPropertySheetExtension *propertySheet = 0;
|
---|
276 | QExtensionManager manager = formEditor->extensionManager();
|
---|
277 |
|
---|
278 | propertySheet = qt_extension<QDesignerPropertySheetExtension*>(manager, widget);
|
---|
279 | int index = propertySheet->indexOf(QLatin1String("margin"));
|
---|
280 |
|
---|
281 | propertySheet->setProperty(index, 10);
|
---|
282 | propertySheet->setChanged(index, true);
|
---|
283 |
|
---|
284 | delete propertySheet;
|
---|
285 | //! [15]
|
---|
286 |
|
---|
287 |
|
---|
288 | //! [16]
|
---|
289 | class MyPropertySheetExtension : public QObject,
|
---|
290 | public QDesignerPropertySheetExtension
|
---|
291 | {
|
---|
292 | Q_OBJECT
|
---|
293 | Q_INTERFACES(QDesignerPropertySheetExtension)
|
---|
294 |
|
---|
295 | public:
|
---|
296 | ...
|
---|
297 | }
|
---|
298 | //! [16]
|
---|
299 |
|
---|
300 |
|
---|
301 | //! [17]
|
---|
302 | QObject *ANewExtensionFactory::createExtension(QObject *object,
|
---|
303 | const QString &iid, QObject *parent) const
|
---|
304 | {
|
---|
305 | if (iid != Q_TYPEID(QDesignerPropertySheetExtension))
|
---|
306 | return 0;
|
---|
307 |
|
---|
308 | if (MyCustomWidget *widget = qobject_cast<MyCustomWidget*>
|
---|
309 | (object))
|
---|
310 | return new MyPropertySheetExtension(widget, parent);
|
---|
311 |
|
---|
312 | return 0;
|
---|
313 | }
|
---|
314 | //! [17]
|
---|
315 |
|
---|
316 |
|
---|
317 | //! [18]
|
---|
318 | QObject *AGeneralExtensionFactory::createExtension(QObject *object,
|
---|
319 | const QString &iid, QObject *parent) const
|
---|
320 | {
|
---|
321 | MyCustomWidget *widget = qobject_cast<MyCustomWidget*>(object);
|
---|
322 |
|
---|
323 | if (widget && (iid == Q_TYPEID(QDesignerTaskMenuExtension))) {
|
---|
324 | return new MyTaskMenuExtension(widget, parent);
|
---|
325 |
|
---|
326 | } else if (widget && (iid == Q_TYPEID(QDesignerPropertySheetExtension))) {
|
---|
327 | return new MyPropertySheetExtension(widget, parent);
|
---|
328 |
|
---|
329 | } else {
|
---|
330 | return 0;
|
---|
331 | }
|
---|
332 | }
|
---|
333 | //! [18]
|
---|