1
/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
3
* Copyright (C) 1997 Josef Wilgen
4
* Copyright (C) 2002 Uwe Rathmann
6
* This library is free software; you can redistribute it and/or
7
* modify it under the terms of the Qwt License, Version 1.0
8
*****************************************************************************/
10
#if defined(_MSC_VER) /* MSVC Compiler */
11
#pragma warning ( disable : 4786 )
17
#include <QDesignerFormEditorInterface>
18
#include <QDesignerFormWindowInterface>
19
#include <QDesignerFormWindowCursorInterface>
20
#include <QExtensionManager>
21
#include <QErrorMessage>
23
#include "qwt_designer_plugin.h"
26
#include "qwt_designer_plotdialog.h"
28
#include "qwt_scale_widget.h"
31
#ifndef NO_QWT_WIDGETS
32
#include "qwt_counter.h"
33
#include "qwt_wheel.h"
34
#include "qwt_thermo.h"
36
#include "qwt_slider.h"
37
#include "qwt_analog_clock.h"
38
#include "qwt_compass.h"
41
#include "qwt_text_label.h"
43
using namespace QwtDesignerPlugin;
45
CustomWidgetInterface::CustomWidgetInterface(QObject *parent):
47
d_isInitialized(false)
51
bool CustomWidgetInterface::isContainer() const
56
bool CustomWidgetInterface::isInitialized() const
58
return d_isInitialized;
61
QIcon CustomWidgetInterface::icon() const
66
QString CustomWidgetInterface::codeTemplate() const
68
return d_codeTemplate;
71
QString CustomWidgetInterface::domXml() const
76
QString CustomWidgetInterface::group() const
81
QString CustomWidgetInterface::includeFile() const
86
QString CustomWidgetInterface::name() const
91
QString CustomWidgetInterface::toolTip() const
96
QString CustomWidgetInterface::whatsThis() const
101
void CustomWidgetInterface::initialize(
102
QDesignerFormEditorInterface *formEditor)
104
if ( d_isInitialized )
107
QExtensionManager *manager = formEditor->extensionManager();
110
manager->registerExtensions(new TaskMenuFactory(manager),
111
Q_TYPEID(QDesignerTaskMenuExtension));
114
d_isInitialized = true;
119
PlotInterface::PlotInterface(QObject *parent):
120
CustomWidgetInterface(parent)
123
d_include = "qwt_plot.h";
124
d_icon = QPixmap(":/pixmaps/qwtplot.png");
126
"<widget class=\"QwtPlot\" name=\"qwtPlot\">\n"
127
" <property name=\"geometry\">\n"
131
" <width>400</width>\n"
132
" <height>200</height>\n"
138
QWidget *PlotInterface::createWidget(QWidget *parent)
140
return new QwtPlot(parent);
145
#ifndef NO_QWT_WIDGETS
147
AnalogClockInterface::AnalogClockInterface(QObject *parent):
148
CustomWidgetInterface(parent)
150
d_name = "QwtAnalogClock";
151
d_include = "qwt_analog_clock.h";
152
d_icon = QPixmap(":/pixmaps/qwtanalogclock.png");
154
"<widget class=\"QwtAnalogClock\" name=\"AnalogClock\">\n"
155
" <property name=\"geometry\">\n"
159
" <width>200</width>\n"
160
" <height>200</height>\n"
163
" <property name=\"lineWidth\">\n"
164
" <number>4</number>\n"
169
QWidget *AnalogClockInterface::createWidget(QWidget *parent)
171
return new QwtAnalogClock(parent);
176
#ifndef NO_QWT_WIDGETS
178
CompassInterface::CompassInterface(QObject *parent):
179
CustomWidgetInterface(parent)
181
d_name = "QwtCompass";
182
d_include = "qwt_compass.h";
183
d_icon = QPixmap(":/pixmaps/qwtcompass.png");
185
"<widget class=\"QwtCompass\" name=\"Compass\">\n"
186
" <property name=\"geometry\">\n"
190
" <width>200</width>\n"
191
" <height>200</height>\n"
194
" <property name=\"lineWidth\">\n"
195
" <number>4</number>\n"
200
QWidget *CompassInterface::createWidget(QWidget *parent)
202
return new QwtCompass(parent);
207
#ifndef NO_QWT_WIDGETS
209
CounterInterface::CounterInterface(QObject *parent):
210
CustomWidgetInterface(parent)
212
d_name = "QwtCounter";
213
d_include = "qwt_counter.h";
214
d_icon = QPixmap(":/pixmaps/qwtcounter.png");
216
"<widget class=\"QwtCounter\" name=\"Counter\">\n"
220
QWidget *CounterInterface::createWidget(QWidget *parent)
222
return new QwtCounter(parent);
227
#ifndef NO_QWT_WIDGETS
229
DialInterface::DialInterface(QObject *parent):
230
CustomWidgetInterface(parent)
233
d_include = "qwt_dial.h";
234
d_icon = QPixmap(":/pixmaps/qwtdial.png");
236
"<widget class=\"QwtDial\" name=\"Dial\">\n"
237
" <property name=\"geometry\">\n"
241
" <width>200</width>\n"
242
" <height>200</height>\n"
245
" <property name=\"lineWidth\">\n"
246
" <number>4</number>\n"
251
QWidget *DialInterface::createWidget(QWidget *parent)
253
return new QwtDial(parent);
258
#ifndef NO_QWT_WIDGETS
260
KnobInterface::KnobInterface(QObject *parent):
261
CustomWidgetInterface(parent)
264
d_include = "qwt_knob.h";
265
d_icon = QPixmap(":/pixmaps/qwtknob.png");
267
"<widget class=\"QwtKnob\" name=\"Knob\">\n"
268
" <property name=\"geometry\">\n"
272
" <width>100</width>\n"
273
" <height>100</height>\n"
279
QWidget *KnobInterface::createWidget(QWidget *parent)
281
return new QwtKnob(parent);
288
ScaleWidgetInterface::ScaleWidgetInterface(QObject *parent):
289
CustomWidgetInterface(parent)
292
d_include = "qwt_scale_widget.h";
293
d_icon = QPixmap(":/pixmaps/qwtscale.png");
295
"<widget class=\"QwtScale\" name=\"Scale\">\n"
299
QWidget *ScaleWidgetInterface::createWidget(QWidget *parent)
301
return new QwtScaleWidget(QwtScaleDraw::LeftScale, parent);
306
#ifndef NO_QWT_WIDGETS
308
SliderInterface::SliderInterface(QObject *parent):
309
CustomWidgetInterface(parent)
311
d_name = "QwtSlider";
312
d_include = "qwt_slider.h";
313
d_icon = QPixmap(":/pixmaps/qwtslider.png");
315
"<widget class=\"QwtSlider\" name=\"Slider\">\n"
316
" <property name=\"geometry\">\n"
320
" <width>200</width>\n"
321
" <height>60</height>\n"
327
QWidget *SliderInterface::createWidget(QWidget *parent)
329
QwtSlider *slider = new QwtSlider(parent);
331
slider->setScalePosition(QwtSlider::Bottom);
332
slider->setRange(0.0, 10.0, 1.0, 0);
333
slider->setValue(3.0);
340
TextLabelInterface::TextLabelInterface(QObject *parent):
341
CustomWidgetInterface(parent)
343
d_name = "QwtTextLabel";
344
d_include = "qwt_text_label.h";
349
d_icon = QPixmap(":/pixmaps/qwtwidget.png");
351
"<widget class=\"QwtTextLabel\" name=\"TextLabel\">\n"
352
" <property name=\"geometry\">\n"
356
" <width>100</width>\n"
357
" <height>20</height>\n"
363
QWidget *TextLabelInterface::createWidget(QWidget *parent)
365
return new QwtTextLabel(parent);
368
#ifndef NO_QWT_WIDGETS
370
ThermoInterface::ThermoInterface(QObject *parent):
371
CustomWidgetInterface(parent)
373
d_name = "QwtThermo";
374
d_include = "qwt_thermo.h";
375
d_icon = QPixmap(":/pixmaps/qwtthermo.png");
377
"<widget class=\"QwtThermo\" name=\"Thermo\">\n"
381
QWidget *ThermoInterface::createWidget(QWidget *parent)
383
return new QwtThermo(parent);
388
#ifndef NO_QWT_WIDGETS
390
WheelInterface::WheelInterface(QObject *parent):
391
CustomWidgetInterface(parent)
394
d_include = "qwt_wheel.h";
395
d_icon = QPixmap(":/pixmaps/qwtwheel.png");
397
"<widget class=\"QwtWheel\" name=\"Wheel\">\n"
401
QWidget *WheelInterface::createWidget(QWidget *parent)
403
return new QwtWheel(parent);
408
CustomWidgetCollectionInterface::CustomWidgetCollectionInterface(
413
d_plugins.append(new PlotInterface(this));
414
d_plugins.append(new ScaleWidgetInterface(this));
417
#ifndef NO_QWT_WIDGETS
418
d_plugins.append(new AnalogClockInterface(this));
419
d_plugins.append(new CompassInterface(this));
420
d_plugins.append(new CounterInterface(this));
421
d_plugins.append(new DialInterface(this));
422
d_plugins.append(new KnobInterface(this));
423
d_plugins.append(new SliderInterface(this));
424
d_plugins.append(new ThermoInterface(this));
425
d_plugins.append(new WheelInterface(this));
428
d_plugins.append(new TextLabelInterface(this));
431
QList<QDesignerCustomWidgetInterface*>
432
CustomWidgetCollectionInterface::customWidgets(void) const
437
TaskMenuFactory::TaskMenuFactory(QExtensionManager *parent):
438
QExtensionFactory(parent)
442
QObject *TaskMenuFactory::createExtension(
443
QObject *object, const QString &iid, QObject *parent) const
445
if (iid == Q_TYPEID(QDesignerTaskMenuExtension))
448
if (QwtPlot *plot = qobject_cast<QwtPlot*>(object))
449
return new TaskMenuExtension(plot, parent);
451
#ifndef NO_QWT_WIDGETS
452
if (QwtDial *dial = qobject_cast<QwtDial*>(object))
453
return new TaskMenuExtension(dial, parent);
457
return QExtensionFactory::createExtension(object, iid, parent);
461
TaskMenuExtension::TaskMenuExtension(QWidget *widget, QObject *parent):
465
d_editAction = new QAction(tr("Edit Qwt Attributes ..."), this);
466
connect(d_editAction, SIGNAL(triggered()),
467
this, SLOT(editProperties()));
470
QList<QAction *> TaskMenuExtension::taskActions() const
472
QList<QAction *> list;
473
list.append(d_editAction);
477
QAction *TaskMenuExtension::preferredEditAction() const
482
void TaskMenuExtension::editProperties()
484
const QVariant v = d_widget->property("propertiesDocument");
485
if ( v.type() != QVariant::String )
489
QString properties = v.toString();
491
if ( qobject_cast<QwtPlot*>(d_widget) )
493
PlotDialog dialog(properties);
494
connect(&dialog, SIGNAL(edited(const QString&)),
495
SLOT(applyProperties(const QString &)));
501
static QErrorMessage *errorMessage = NULL;
502
if ( errorMessage == NULL )
503
errorMessage = new QErrorMessage();
504
errorMessage->showMessage("Not implemented yet.");
507
void TaskMenuExtension::applyProperties(const QString &properties)
509
QDesignerFormWindowInterface *formWindow
510
= QDesignerFormWindowInterface::findFormWindow(d_widget);
511
if ( formWindow && formWindow->cursor() )
512
formWindow->cursor()->setProperty("propertiesDocument", properties);
515
Q_EXPORT_PLUGIN2(QwtDesignerPlugin, CustomWidgetCollectionInterface)