Fix access to uninitialized memory
[qt-netbsd.git] / demos / arthurplugin / plugin.cpp
blob727fd12b000a345e3731cec50686e3af72c6909d
1 /****************************************************************************
2 **
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: Nokia Corporation (qt-info@nokia.com)
5 **
6 ** This file is part of the demonstration applications of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** No Commercial Usage
10 ** This file contains pre-release code and may not be distributed.
11 ** You may use this file in accordance with the terms and conditions
12 ** contained in the Technology Preview License Agreement accompanying
13 ** this package.
15 ** GNU Lesser General Public License Usage
16 ** Alternatively, this file may be used under the terms of the GNU Lesser
17 ** General Public License version 2.1 as published by the Free Software
18 ** Foundation and appearing in the file LICENSE.LGPL included in the
19 ** packaging of this file. Please review the following information to
20 ** ensure the GNU Lesser General Public License version 2.1 requirements
21 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23 ** In addition, as a special exception, Nokia gives you certain
24 ** additional rights. These rights are described in the Nokia Qt LGPL
25 ** Exception version 1.1, included in the file LGPL_EXCEPTION.txt in this
26 ** package.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
38 ** $QT_END_LICENSE$
40 ****************************************************************************/
42 #include <QtDesigner/QDesignerContainerExtension>
43 #include <QtDesigner/QDesignerCustomWidgetInterface>
45 #include <QtCore/qplugin.h>
46 #include <QtGui/QIcon>
47 #include <QtGui/QPixmap>
49 #include "xform.h"
50 #include "pathdeform.h"
51 #include "gradients.h"
52 #include "pathstroke.h"
53 #include "hoverpoints.h"
54 #include "composition.h"
56 QT_FORWARD_DECLARE_CLASS(QDesignerFormEditorInterface)
58 // Specify "text" to be a singleline property (no richtext)
59 static inline QString textSingleLinePropertyDeclaration(const QString &className)
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;
75 // Plain XML for a custom widget
76 static inline QString customWidgetDomXml(const QString &className,
77 const QString &customSection = QString())
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;
91 class PathDeformRendererEx : public PathDeformRenderer
93 Q_OBJECT
94 public:
95 PathDeformRendererEx(QWidget *parent) : PathDeformRenderer(parent) { }
96 QSize sizeHint() const { return QSize(300, 200); }
99 class DemoPlugin : public QDesignerCustomWidgetInterface
101 Q_INTERFACES(QDesignerCustomWidgetInterface)
103 protected:
104 explicit DemoPlugin(const QString &className, const QString &customSection = QString());
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 *)
117 if (m_initialized)
118 return;
119 m_initialized = true;
121 QString domXml() const { return m_domXml; }
123 private:
124 const QString m_className;
125 const QString m_domXml;
126 bool m_initialized;
129 DemoPlugin::DemoPlugin(const QString &className, const QString &customSection) :
130 m_className(className),
131 m_domXml(customWidgetDomXml(className, customSection)),
132 m_initialized(false)
136 class DeformPlugin : public QObject, public DemoPlugin
138 Q_OBJECT
140 public:
141 explicit DeformPlugin(QObject *parent = 0);
142 QString includeFile() const { return QLatin1String("deform.h"); }
144 QWidget *createWidget(QWidget *parent)
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"));
152 return deform;
156 DeformPlugin::DeformPlugin(QObject *parent) :
157 QObject(parent),
158 DemoPlugin(QLatin1String("PathDeformRendererEx"),
159 textSingleLinePropertyDeclaration(QLatin1String("PathDeformRendererEx")))
163 class XFormRendererEx : public XFormView
165 Q_OBJECT
166 public:
167 XFormRendererEx(QWidget *parent) : XFormView(parent) {}
168 QSize sizeHint() const { return QSize(300, 200); }
171 class XFormPlugin : public QObject, public DemoPlugin
173 Q_OBJECT
174 public:
175 explicit XFormPlugin(QObject *parent = 0);
176 QString includeFile() const { return QLatin1String("xform.h"); }
178 QWidget *createWidget(QWidget *parent)
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;
187 XFormPlugin::XFormPlugin(QObject *parent) :
188 QObject(parent),
189 DemoPlugin(QLatin1String("XFormRendererEx"),
190 textSingleLinePropertyDeclaration(QLatin1String("XFormRendererEx")))
194 class GradientEditorPlugin : public QObject, public DemoPlugin
196 Q_OBJECT
197 public:
198 explicit GradientEditorPlugin(QObject *parent = 0) : QObject(parent), DemoPlugin(QLatin1String("GradientEditor")) { }
199 QString includeFile() const { return "gradients.h"; }
201 QWidget *createWidget(QWidget *parent)
203 GradientEditor *editor = new GradientEditor(parent);
204 return editor;
208 class GradientRendererEx : public GradientRenderer
210 Q_OBJECT
211 public:
212 GradientRendererEx(QWidget *p) : GradientRenderer(p) { }
213 QSize sizeHint() const { return QSize(300, 200); }
216 class GradientRendererPlugin : public QObject, public DemoPlugin
218 Q_OBJECT
219 public:
220 GradientRendererPlugin(QObject *parent = 0) : QObject(parent), DemoPlugin(QLatin1String("GradientRendererEx")) { }
221 QString includeFile() const { return QLatin1String("gradients.h"); }
223 QWidget *createWidget(QWidget *parent)
225 GradientRenderer *renderer = new GradientRendererEx(parent);
226 renderer->setConicalGradient();
227 return renderer;
231 class PathStrokeRendererEx : public PathStrokeRenderer
233 Q_OBJECT
234 public:
235 explicit PathStrokeRendererEx(QWidget *p) : PathStrokeRenderer(p) { }
236 QSize sizeHint() const { return QSize(300, 200); }
239 class StrokeRenderPlugin : public QObject, public DemoPlugin
241 Q_OBJECT
242 public:
243 explicit StrokeRenderPlugin(QObject *parent = 0) : QObject(parent), DemoPlugin(QLatin1String("PathStrokeRendererEx")) { }
244 QString includeFile() const { return QLatin1String("pathstroke.h"); }
246 QWidget *createWidget(QWidget *parent)
248 PathStrokeRenderer *stroke = new PathStrokeRendererEx(parent);
249 return stroke;
254 class CompositionModePlugin : public QObject, public DemoPlugin
256 Q_OBJECT
257 public:
258 explicit CompositionModePlugin(QObject *parent = 0) : QObject(parent), DemoPlugin(QLatin1String("CompositionRenderer")) { }
259 QString includeFile() const { return QLatin1String("composition.h"); }
261 QWidget *createWidget(QWidget *parent)
263 CompositionRenderer *renderer = new CompositionRenderer(parent);
264 renderer->setAnimationEnabled(false);
265 return renderer;
270 class ArthurPlugins : public QObject, public QDesignerCustomWidgetCollectionInterface
272 Q_OBJECT
273 Q_INTERFACES(QDesignerCustomWidgetCollectionInterface)
275 public:
276 explicit ArthurPlugins(QObject *parent = 0);
277 QList<QDesignerCustomWidgetInterface*> customWidgets() const { return m_plugins; }
279 private:
280 QList<QDesignerCustomWidgetInterface *> m_plugins;
283 ArthurPlugins::ArthurPlugins(QObject *parent) :
284 QObject(parent)
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);
294 #include "plugin.moc"
296 Q_EXPORT_PLUGIN2(ArthurPlugins, ArthurPlugins)