1 /****************************************************************************
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 ** This file is part of the demonstration applications of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
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
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
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
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
)