source: trunk/demos/arthurplugin/plugin.cpp@ 1037

Last change on this file since 1037 was 846, checked in by Dmitry A. Kuminov, 14 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

File size: 9.2 KB
Line 
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
56QT_FORWARD_DECLARE_CLASS(QDesignerFormEditorInterface)
57
58// Specify "text" to be a singleline property (no richtext)
59static 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
76static 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
91class PathDeformRendererEx : public PathDeformRenderer
92{
93 Q_OBJECT
94public:
95 PathDeformRendererEx(QWidget *parent) : PathDeformRenderer(parent) { }
96 QSize sizeHint() const { return QSize(300, 200); }
97};
98
99class DemoPlugin : public QDesignerCustomWidgetInterface
100{
101 Q_INTERFACES(QDesignerCustomWidgetInterface)
102
103protected:
104 explicit DemoPlugin(const QString &className, const QString &customSection = QString());
105
106public:
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
123private:
124 const QString m_className;
125 const QString m_domXml;
126 bool m_initialized;
127};
128
129DemoPlugin::DemoPlugin(const QString &className, const QString &customSection) :
130 m_className(className),
131 m_domXml(customWidgetDomXml(className, customSection)),
132 m_initialized(false)
133{
134}
135
136class DeformPlugin : public QObject, public DemoPlugin
137{
138 Q_OBJECT
139
140public:
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
156DeformPlugin::DeformPlugin(QObject *parent) :
157 QObject(parent),
158 DemoPlugin(QLatin1String("PathDeformRendererEx"),
159 textSingleLinePropertyDeclaration(QLatin1String("PathDeformRendererEx")))
160{
161}
162
163class XFormRendererEx : public XFormView
164{
165 Q_OBJECT
166public:
167 XFormRendererEx(QWidget *parent) : XFormView(parent) {}
168 QSize sizeHint() const { return QSize(300, 200); }
169};
170
171class XFormPlugin : public QObject, public DemoPlugin
172{
173 Q_OBJECT
174public:
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
187XFormPlugin::XFormPlugin(QObject *parent) :
188 QObject(parent),
189 DemoPlugin(QLatin1String("XFormRendererEx"),
190 textSingleLinePropertyDeclaration(QLatin1String("XFormRendererEx")))
191{
192}
193
194class GradientEditorPlugin : public QObject, public DemoPlugin
195{
196 Q_OBJECT
197public:
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
208class GradientRendererEx : public GradientRenderer
209{
210 Q_OBJECT
211public:
212 GradientRendererEx(QWidget *p) : GradientRenderer(p) { }
213 QSize sizeHint() const { return QSize(300, 200); }
214};
215
216class GradientRendererPlugin : public QObject, public DemoPlugin
217{
218 Q_OBJECT
219public:
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
231class PathStrokeRendererEx : public PathStrokeRenderer
232{
233 Q_OBJECT
234public:
235 explicit PathStrokeRendererEx(QWidget *p) : PathStrokeRenderer(p) { }
236 QSize sizeHint() const { return QSize(300, 200); }
237};
238
239class StrokeRenderPlugin : public QObject, public DemoPlugin
240{
241 Q_OBJECT
242public:
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
254class CompositionModePlugin : public QObject, public DemoPlugin
255{
256 Q_OBJECT
257public:
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
270class ArthurPlugins : public QObject, public QDesignerCustomWidgetCollectionInterface
271{
272 Q_OBJECT
273 Q_INTERFACES(QDesignerCustomWidgetCollectionInterface)
274
275public:
276 explicit ArthurPlugins(QObject *parent = 0);
277 QList<QDesignerCustomWidgetInterface*> customWidgets() const { return m_plugins; }
278
279private:
280 QList<QDesignerCustomWidgetInterface *> m_plugins;
281};
282
283ArthurPlugins::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
296Q_EXPORT_PLUGIN2(ArthurPlugins, ArthurPlugins)
Note: See TracBrowser for help on using the repository browser.