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 demonstration applications 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 | #include <QtDesigner/QDesignerContainerExtension>
|
---|
43 | #include <QtDesigner/QDesignerCustomWidgetInterface>
|
---|
44 |
|
---|
45 | #include <QtCore/qplugin.h>
|
---|
46 | #include <QtGui/QIcon>
|
---|
47 | #include <QtGui/QPixmap>
|
---|
48 |
|
---|
49 | #include "xform.h"
|
---|
50 | #include "pathdeform.h"
|
---|
51 | #include "gradients.h"
|
---|
52 | #include "pathstroke.h"
|
---|
53 | #include "hoverpoints.h"
|
---|
54 | #include "composition.h"
|
---|
55 |
|
---|
56 | QT_FORWARD_DECLARE_CLASS(QDesignerFormEditorInterface)
|
---|
57 |
|
---|
58 | // Specify "text" to be a singleline property (no richtext)
|
---|
59 | static inline QString textSingleLinePropertyDeclaration(const QString &className)
|
---|
60 | {
|
---|
61 | QString rc = QLatin1String(
|
---|
62 | "<customwidgets>\n"
|
---|
63 | " <customwidget>\n"
|
---|
64 | " <class>");
|
---|
65 | rc += className;
|
---|
66 | rc += QLatin1String("</class>\n"
|
---|
67 | " <propertyspecifications>\n"
|
---|
68 | " <stringpropertyspecification name=\"text\" type=\"singleline\"/>\n"
|
---|
69 | " </propertyspecifications>\n"
|
---|
70 | " </customwidget>\n"
|
---|
71 | "</customwidgets>\n");
|
---|
72 | return rc;
|
---|
73 | }
|
---|
74 |
|
---|
75 | // Plain XML for a custom widget
|
---|
76 | static inline QString customWidgetDomXml(const QString &className,
|
---|
77 | const QString &customSection = QString())
|
---|
78 | {
|
---|
79 | QString rc = QLatin1String("<ui language=\"c++\"><widget class=\"");
|
---|
80 | rc += className;
|
---|
81 | rc += QLatin1String("\" name=\"");
|
---|
82 | QString objectName = className;
|
---|
83 | objectName[0] = objectName.at(0).toLower();
|
---|
84 | rc += objectName;
|
---|
85 | rc += QLatin1String("\"/>");
|
---|
86 | rc += customSection;
|
---|
87 | rc += QLatin1String("</ui>");
|
---|
88 | return rc;
|
---|
89 | }
|
---|
90 |
|
---|
91 | class PathDeformRendererEx : public PathDeformRenderer
|
---|
92 | {
|
---|
93 | Q_OBJECT
|
---|
94 | public:
|
---|
95 | PathDeformRendererEx(QWidget *parent) : PathDeformRenderer(parent) { }
|
---|
96 | QSize sizeHint() const { return QSize(300, 200); }
|
---|
97 | };
|
---|
98 |
|
---|
99 | class DemoPlugin : public QDesignerCustomWidgetInterface
|
---|
100 | {
|
---|
101 | Q_INTERFACES(QDesignerCustomWidgetInterface)
|
---|
102 |
|
---|
103 | protected:
|
---|
104 | explicit DemoPlugin(const QString &className, const QString &customSection = QString());
|
---|
105 |
|
---|
106 | public:
|
---|
107 | QString name() const { return m_className; }
|
---|
108 | bool isContainer() const { return false; }
|
---|
109 | bool isInitialized() const { return m_initialized; }
|
---|
110 | QIcon icon() const { return QIcon(); }
|
---|
111 | QString codeTemplate() const { return QString(); }
|
---|
112 | QString whatsThis() const { return QString(); }
|
---|
113 | QString toolTip() const { return QString(); }
|
---|
114 | QString group() const { return "Arthur Widgets [Demo]"; }
|
---|
115 | void initialize(QDesignerFormEditorInterface *)
|
---|
116 | {
|
---|
117 | if (m_initialized)
|
---|
118 | return;
|
---|
119 | m_initialized = true;
|
---|
120 | }
|
---|
121 | QString domXml() const { return m_domXml; }
|
---|
122 |
|
---|
123 | private:
|
---|
124 | const QString m_className;
|
---|
125 | const QString m_domXml;
|
---|
126 | bool m_initialized;
|
---|
127 | };
|
---|
128 |
|
---|
129 | DemoPlugin::DemoPlugin(const QString &className, const QString &customSection) :
|
---|
130 | m_className(className),
|
---|
131 | m_domXml(customWidgetDomXml(className, customSection)),
|
---|
132 | m_initialized(false)
|
---|
133 | {
|
---|
134 | }
|
---|
135 |
|
---|
136 | class DeformPlugin : public QObject, public DemoPlugin
|
---|
137 | {
|
---|
138 | Q_OBJECT
|
---|
139 |
|
---|
140 | public:
|
---|
141 | explicit DeformPlugin(QObject *parent = 0);
|
---|
142 | QString includeFile() const { return QLatin1String("deform.h"); }
|
---|
143 |
|
---|
144 | QWidget *createWidget(QWidget *parent)
|
---|
145 | {
|
---|
146 | PathDeformRenderer *deform = new PathDeformRendererEx(parent);
|
---|
147 | deform->setRadius(70);
|
---|
148 | deform->setAnimated(false);
|
---|
149 | deform->setFontSize(20);
|
---|
150 | deform->setText(QLatin1String("Arthur Widgets Demo"));
|
---|
151 |
|
---|
152 | return deform;
|
---|
153 | }
|
---|
154 | };
|
---|
155 |
|
---|
156 | DeformPlugin::DeformPlugin(QObject *parent) :
|
---|
157 | QObject(parent),
|
---|
158 | DemoPlugin(QLatin1String("PathDeformRendererEx"),
|
---|
159 | textSingleLinePropertyDeclaration(QLatin1String("PathDeformRendererEx")))
|
---|
160 | {
|
---|
161 | }
|
---|
162 |
|
---|
163 | class XFormRendererEx : public XFormView
|
---|
164 | {
|
---|
165 | Q_OBJECT
|
---|
166 | public:
|
---|
167 | XFormRendererEx(QWidget *parent) : XFormView(parent) {}
|
---|
168 | QSize sizeHint() const { return QSize(300, 200); }
|
---|
169 | };
|
---|
170 |
|
---|
171 | class XFormPlugin : public QObject, public DemoPlugin
|
---|
172 | {
|
---|
173 | Q_OBJECT
|
---|
174 | public:
|
---|
175 | explicit XFormPlugin(QObject *parent = 0);
|
---|
176 | QString includeFile() const { return QLatin1String("xform.h"); }
|
---|
177 |
|
---|
178 | QWidget *createWidget(QWidget *parent)
|
---|
179 | {
|
---|
180 | XFormRendererEx *xform = new XFormRendererEx(parent);
|
---|
181 | xform->setText(QLatin1String("Qt - Hello World!!"));
|
---|
182 | xform->setPixmap(QPixmap(QLatin1String(":/trolltech/arthurplugin/bg1.jpg")));
|
---|
183 | return xform;
|
---|
184 | }
|
---|
185 | };
|
---|
186 |
|
---|
187 | XFormPlugin::XFormPlugin(QObject *parent) :
|
---|
188 | QObject(parent),
|
---|
189 | DemoPlugin(QLatin1String("XFormRendererEx"),
|
---|
190 | textSingleLinePropertyDeclaration(QLatin1String("XFormRendererEx")))
|
---|
191 | {
|
---|
192 | }
|
---|
193 |
|
---|
194 | class GradientEditorPlugin : public QObject, public DemoPlugin
|
---|
195 | {
|
---|
196 | Q_OBJECT
|
---|
197 | public:
|
---|
198 | explicit GradientEditorPlugin(QObject *parent = 0) : QObject(parent), DemoPlugin(QLatin1String("GradientEditor")) { }
|
---|
199 | QString includeFile() const { return "gradients.h"; }
|
---|
200 |
|
---|
201 | QWidget *createWidget(QWidget *parent)
|
---|
202 | {
|
---|
203 | GradientEditor *editor = new GradientEditor(parent);
|
---|
204 | return editor;
|
---|
205 | }
|
---|
206 | };
|
---|
207 |
|
---|
208 | class GradientRendererEx : public GradientRenderer
|
---|
209 | {
|
---|
210 | Q_OBJECT
|
---|
211 | public:
|
---|
212 | GradientRendererEx(QWidget *p) : GradientRenderer(p) { }
|
---|
213 | QSize sizeHint() const { return QSize(300, 200); }
|
---|
214 | };
|
---|
215 |
|
---|
216 | class GradientRendererPlugin : public QObject, public DemoPlugin
|
---|
217 | {
|
---|
218 | Q_OBJECT
|
---|
219 | public:
|
---|
220 | GradientRendererPlugin(QObject *parent = 0) : QObject(parent), DemoPlugin(QLatin1String("GradientRendererEx")) { }
|
---|
221 | QString includeFile() const { return QLatin1String("gradients.h"); }
|
---|
222 |
|
---|
223 | QWidget *createWidget(QWidget *parent)
|
---|
224 | {
|
---|
225 | GradientRenderer *renderer = new GradientRendererEx(parent);
|
---|
226 | renderer->setConicalGradient();
|
---|
227 | return renderer;
|
---|
228 | }
|
---|
229 | };
|
---|
230 |
|
---|
231 | class PathStrokeRendererEx : public PathStrokeRenderer
|
---|
232 | {
|
---|
233 | Q_OBJECT
|
---|
234 | public:
|
---|
235 | explicit PathStrokeRendererEx(QWidget *p) : PathStrokeRenderer(p) { }
|
---|
236 | QSize sizeHint() const { return QSize(300, 200); }
|
---|
237 | };
|
---|
238 |
|
---|
239 | class StrokeRenderPlugin : public QObject, public DemoPlugin
|
---|
240 | {
|
---|
241 | Q_OBJECT
|
---|
242 | public:
|
---|
243 | explicit StrokeRenderPlugin(QObject *parent = 0) : QObject(parent), DemoPlugin(QLatin1String("PathStrokeRendererEx")) { }
|
---|
244 | QString includeFile() const { return QLatin1String("pathstroke.h"); }
|
---|
245 |
|
---|
246 | QWidget *createWidget(QWidget *parent)
|
---|
247 | {
|
---|
248 | PathStrokeRenderer *stroke = new PathStrokeRendererEx(parent);
|
---|
249 | return stroke;
|
---|
250 | }
|
---|
251 | };
|
---|
252 |
|
---|
253 |
|
---|
254 | class CompositionModePlugin : public QObject, public DemoPlugin
|
---|
255 | {
|
---|
256 | Q_OBJECT
|
---|
257 | public:
|
---|
258 | explicit CompositionModePlugin(QObject *parent = 0) : QObject(parent), DemoPlugin(QLatin1String("CompositionRenderer")) { }
|
---|
259 | QString includeFile() const { return QLatin1String("composition.h"); }
|
---|
260 |
|
---|
261 | QWidget *createWidget(QWidget *parent)
|
---|
262 | {
|
---|
263 | CompositionRenderer *renderer = new CompositionRenderer(parent);
|
---|
264 | renderer->setAnimationEnabled(false);
|
---|
265 | return renderer;
|
---|
266 | }
|
---|
267 | };
|
---|
268 |
|
---|
269 |
|
---|
270 | class ArthurPlugins : public QObject, public QDesignerCustomWidgetCollectionInterface
|
---|
271 | {
|
---|
272 | Q_OBJECT
|
---|
273 | Q_INTERFACES(QDesignerCustomWidgetCollectionInterface)
|
---|
274 |
|
---|
275 | public:
|
---|
276 | explicit ArthurPlugins(QObject *parent = 0);
|
---|
277 | QList<QDesignerCustomWidgetInterface*> customWidgets() const { return m_plugins; }
|
---|
278 |
|
---|
279 | private:
|
---|
280 | QList<QDesignerCustomWidgetInterface *> m_plugins;
|
---|
281 | };
|
---|
282 |
|
---|
283 | ArthurPlugins::ArthurPlugins(QObject *parent) :
|
---|
284 | QObject(parent)
|
---|
285 | {
|
---|
286 | m_plugins << new DeformPlugin(this)
|
---|
287 | << new XFormPlugin(this)
|
---|
288 | << new GradientEditorPlugin(this)
|
---|
289 | << new GradientRendererPlugin(this)
|
---|
290 | << new StrokeRenderPlugin(this)
|
---|
291 | << new CompositionModePlugin(this);
|
---|
292 | }
|
---|
293 |
|
---|
294 | #include "plugin.moc"
|
---|
295 |
|
---|
296 | Q_EXPORT_PLUGIN2(ArthurPlugins, ArthurPlugins)
|
---|