1 /****************************************************************************
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
6 ** This file is part of the demonstration applications of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see http://www.qt.io/terms-conditions. For further
15 ** information use the contact form at http://www.qt.io/contact-us.
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 or version 3 as published by the Free
20 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and
21 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the
22 ** following information to ensure the GNU Lesser General Public License
23 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
24 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
26 ** As a special exception, The Qt Company gives you certain additional
27 ** rights. These rights are described in The Qt Company LGPL Exception
28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
30 ** GNU General Public License Usage
31 ** Alternatively, this file may be used under the terms of the GNU
32 ** General Public License version 3.0 as published by the Free Software
33 ** Foundation and appearing in the file LICENSE.GPL included in the
34 ** packaging of this file. Please review the following information to
35 ** ensure the GNU General Public License version 3.0 requirements will be
36 ** met: http://www.gnu.org/copyleft/gpl.html.
40 ****************************************************************************/
42 #include <QtDesigner/QDesignerContainerExtension>
43 #include <QtDesigner/QDesignerCustomWidgetInterface>
45 #include <QtCore/qplugin.h>
46 #include <QtGui/QIcon>
47 #include <QtGui/QPixmap>
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(
66 rc += QLatin1String("</class>\n"
67 " <propertyspecifications>\n"
68 " <stringpropertyspecification name=\"text\" type=\"singleline\"/>\n"
69 " </propertyspecifications>\n"
71 "</customwidgets>\n");
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=\"");
81 rc += QLatin1String("\" name=\"");
82 QString objectName = className;
83 objectName[0] = objectName.at(0).toLower();
85 rc += QLatin1String("\"/>");
87 rc += QLatin1String("</ui>");
91 class PathDeformRendererEx : public PathDeformRenderer
95 PathDeformRendererEx(QWidget *parent) : PathDeformRenderer(parent) { }
96 QSize sizeHint() const { return QSize(300, 200); }
99 class DemoPlugin : public QDesignerCustomWidgetInterface
101 Q_INTERFACES(QDesignerCustomWidgetInterface)
104 explicit DemoPlugin(const QString &className, const QString &customSection = QString());
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 *)
119 m_initialized = true;
121 QString domXml() const { return m_domXml; }
124 const QString m_className;
125 const QString m_domXml;
129 DemoPlugin::DemoPlugin(const QString &className, const QString &customSection) :
130 m_className(className),
131 m_domXml(customWidgetDomXml(className, customSection)),
136 class DeformPlugin : public QObject, public DemoPlugin
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"));
156 DeformPlugin::DeformPlugin(QObject *parent) :
158 DemoPlugin(QLatin1String("PathDeformRendererEx"),
159 textSingleLinePropertyDeclaration(QLatin1String("PathDeformRendererEx")))
163 class XFormRendererEx : public XFormView
167 XFormRendererEx(QWidget *parent) : XFormView(parent) {}
168 QSize sizeHint() const { return QSize(300, 200); }
171 class XFormPlugin : public QObject, public DemoPlugin
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")));
187 XFormPlugin::XFormPlugin(QObject *parent) :
189 DemoPlugin(QLatin1String("XFormRendererEx"),
190 textSingleLinePropertyDeclaration(QLatin1String("XFormRendererEx")))
194 class GradientEditorPlugin : public QObject, public DemoPlugin
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);
208 class GradientRendererEx : public GradientRenderer
212 GradientRendererEx(QWidget *p) : GradientRenderer(p) { }
213 QSize sizeHint() const { return QSize(300, 200); }
216 class GradientRendererPlugin : public QObject, public DemoPlugin
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();
231 class PathStrokeRendererEx : public PathStrokeRenderer
235 explicit PathStrokeRendererEx(QWidget *p) : PathStrokeRenderer(p) { }
236 QSize sizeHint() const { return QSize(300, 200); }
239 class StrokeRenderPlugin : public QObject, public DemoPlugin
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);
254 class CompositionModePlugin : public QObject, public DemoPlugin
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);
270 class ArthurPlugins : public QObject, public QDesignerCustomWidgetCollectionInterface
273 Q_INTERFACES(QDesignerCustomWidgetCollectionInterface)
276 explicit ArthurPlugins(QObject *parent = 0);
277 QList<QDesignerCustomWidgetInterface*> customWidgets() const { return m_plugins; }
280 QList<QDesignerCustomWidgetInterface *> m_plugins;
283 ArthurPlugins::ArthurPlugins(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)