~l3on/ubuntu/oneiric/qwt/fix-921430

« back to all changes in this revision

Viewing changes to qwt-5.0.1/designer/qwt_designer_plugin.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Fathi Boudra
  • Date: 2007-10-05 15:20:41 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20071005152041-qmybqh4fj9jejyo2
Tags: 5.0.2-2
* Handle nostrip build option. (Closes: #437877)
* Build libqwt5-doc package in binary-indep target. (Closes: #443110)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
2
 
 * Qwt Widget Library
3
 
 * Copyright (C) 1997   Josef Wilgen
4
 
 * Copyright (C) 2002   Uwe Rathmann
5
 
 *
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
 
 *****************************************************************************/
9
 
 
10
 
#if defined(_MSC_VER) /* MSVC Compiler */
11
 
#pragma warning ( disable : 4786 )
12
 
#endif
13
 
 
14
 
#include <qglobal.h>
15
 
#include <qaction.h>
16
 
#include <QtPlugin>
17
 
#include <QDesignerFormEditorInterface>
18
 
#include <QDesignerFormWindowInterface>
19
 
#include <QDesignerFormWindowCursorInterface>
20
 
#include <QExtensionManager>
21
 
#include <QErrorMessage>
22
 
 
23
 
#include "qwt_designer_plugin.h"
24
 
 
25
 
#ifndef NO_QWT_PLOT
26
 
#include "qwt_designer_plotdialog.h"
27
 
#include "qwt_plot.h"
28
 
#include "qwt_scale_widget.h"
29
 
#endif
30
 
 
31
 
#ifndef NO_QWT_WIDGETS
32
 
#include "qwt_counter.h"
33
 
#include "qwt_wheel.h"
34
 
#include "qwt_thermo.h"
35
 
#include "qwt_knob.h"
36
 
#include "qwt_slider.h"
37
 
#include "qwt_analog_clock.h"
38
 
#include "qwt_compass.h"
39
 
#endif
40
 
 
41
 
#include "qwt_text_label.h"
42
 
 
43
 
using namespace QwtDesignerPlugin;
44
 
 
45
 
CustomWidgetInterface::CustomWidgetInterface(QObject *parent): 
46
 
    QObject(parent),
47
 
    d_isInitialized(false)
48
 
{
49
 
}
50
 
 
51
 
bool CustomWidgetInterface::isContainer() const
52
 
{
53
 
    return false;
54
 
}
55
 
 
56
 
bool CustomWidgetInterface::isInitialized() const
57
 
{
58
 
    return d_isInitialized;
59
 
}
60
 
 
61
 
QIcon CustomWidgetInterface::icon() const
62
 
{
63
 
    return d_icon;
64
 
}
65
 
 
66
 
QString CustomWidgetInterface::codeTemplate() const
67
 
{
68
 
    return d_codeTemplate;
69
 
}
70
 
 
71
 
QString CustomWidgetInterface::domXml() const
72
 
{
73
 
    return d_domXml;
74
 
}
75
 
 
76
 
QString CustomWidgetInterface::group() const
77
 
{
78
 
    return "Qwt Widgets";
79
 
}
80
 
 
81
 
QString CustomWidgetInterface::includeFile() const
82
 
{
83
 
    return d_include;
84
 
}
85
 
 
86
 
QString CustomWidgetInterface::name() const
87
 
{
88
 
    return d_name;
89
 
}
90
 
 
91
 
QString CustomWidgetInterface::toolTip() const
92
 
{
93
 
    return d_toolTip;
94
 
}
95
 
 
96
 
QString CustomWidgetInterface::whatsThis() const
97
 
{
98
 
    return d_whatsThis;
99
 
}
100
 
 
101
 
void CustomWidgetInterface::initialize(
102
 
    QDesignerFormEditorInterface *formEditor)
103
 
{
104
 
    if ( d_isInitialized )
105
 
        return;
106
 
 
107
 
    QExtensionManager *manager = formEditor->extensionManager();
108
 
    if ( manager )
109
 
    {
110
 
        manager->registerExtensions(new TaskMenuFactory(manager),
111
 
            Q_TYPEID(QDesignerTaskMenuExtension));
112
 
    }
113
 
 
114
 
    d_isInitialized = true;
115
 
}
116
 
 
117
 
#ifndef NO_QWT_PLOT
118
 
 
119
 
PlotInterface::PlotInterface(QObject *parent): 
120
 
    CustomWidgetInterface(parent)
121
 
{
122
 
    d_name = "QwtPlot";
123
 
    d_include = "qwt_plot.h";
124
 
    d_icon = QPixmap(":/pixmaps/qwtplot.png");
125
 
    d_domXml = 
126
 
        "<widget class=\"QwtPlot\" name=\"qwtPlot\">\n"
127
 
        " <property name=\"geometry\">\n"
128
 
        "  <rect>\n"
129
 
        "   <x>0</x>\n"
130
 
        "   <y>0</y>\n"
131
 
        "   <width>400</width>\n"
132
 
        "   <height>200</height>\n"
133
 
        "  </rect>\n"
134
 
        " </property>\n"
135
 
        "</widget>\n";
136
 
}
137
 
 
138
 
QWidget *PlotInterface::createWidget(QWidget *parent)
139
 
{
140
 
    return new QwtPlot(parent);
141
 
}
142
 
 
143
 
#endif
144
 
 
145
 
#ifndef NO_QWT_WIDGETS
146
 
 
147
 
AnalogClockInterface::AnalogClockInterface(QObject *parent): 
148
 
    CustomWidgetInterface(parent)
149
 
{
150
 
    d_name = "QwtAnalogClock";
151
 
    d_include = "qwt_analog_clock.h";
152
 
    d_icon = QPixmap(":/pixmaps/qwtanalogclock.png");
153
 
    d_domXml = 
154
 
        "<widget class=\"QwtAnalogClock\" name=\"AnalogClock\">\n"
155
 
        " <property name=\"geometry\">\n"
156
 
        "  <rect>\n"
157
 
        "   <x>0</x>\n"
158
 
        "   <y>0</y>\n"
159
 
        "   <width>200</width>\n"
160
 
        "   <height>200</height>\n"
161
 
        "  </rect>\n"
162
 
        " </property>\n"
163
 
        " <property name=\"lineWidth\">\n"
164
 
        "  <number>4</number>\n"
165
 
        " </property>\n"
166
 
        "</widget>\n";
167
 
}
168
 
 
169
 
QWidget *AnalogClockInterface::createWidget(QWidget *parent)
170
 
{
171
 
    return new QwtAnalogClock(parent);
172
 
}
173
 
 
174
 
#endif
175
 
 
176
 
#ifndef NO_QWT_WIDGETS
177
 
 
178
 
CompassInterface::CompassInterface(QObject *parent): 
179
 
    CustomWidgetInterface(parent)
180
 
{
181
 
    d_name = "QwtCompass";
182
 
    d_include = "qwt_compass.h";
183
 
    d_icon = QPixmap(":/pixmaps/qwtcompass.png");
184
 
    d_domXml = 
185
 
        "<widget class=\"QwtCompass\" name=\"Compass\">\n"
186
 
        " <property name=\"geometry\">\n"
187
 
        "  <rect>\n"
188
 
        "   <x>0</x>\n"
189
 
        "   <y>0</y>\n"
190
 
        "   <width>200</width>\n"
191
 
        "   <height>200</height>\n"
192
 
        "  </rect>\n"
193
 
        " </property>\n"
194
 
        " <property name=\"lineWidth\">\n"
195
 
        "  <number>4</number>\n"
196
 
        " </property>\n"
197
 
        "</widget>\n";
198
 
}
199
 
 
200
 
QWidget *CompassInterface::createWidget(QWidget *parent)
201
 
{
202
 
    return new QwtCompass(parent);
203
 
}
204
 
 
205
 
#endif
206
 
 
207
 
#ifndef NO_QWT_WIDGETS
208
 
 
209
 
CounterInterface::CounterInterface(QObject *parent): 
210
 
    CustomWidgetInterface(parent)
211
 
{
212
 
    d_name = "QwtCounter";
213
 
    d_include = "qwt_counter.h";
214
 
    d_icon = QPixmap(":/pixmaps/qwtcounter.png");
215
 
    d_domXml = 
216
 
        "<widget class=\"QwtCounter\" name=\"Counter\">\n"
217
 
        "</widget>\n";
218
 
}
219
 
 
220
 
QWidget *CounterInterface::createWidget(QWidget *parent)
221
 
{
222
 
    return new QwtCounter(parent);
223
 
}
224
 
 
225
 
#endif
226
 
 
227
 
#ifndef NO_QWT_WIDGETS
228
 
 
229
 
DialInterface::DialInterface(QObject *parent): 
230
 
    CustomWidgetInterface(parent)
231
 
{
232
 
    d_name = "QwtDial";
233
 
    d_include = "qwt_dial.h";
234
 
    d_icon = QPixmap(":/pixmaps/qwtdial.png");
235
 
    d_domXml = 
236
 
        "<widget class=\"QwtDial\" name=\"Dial\">\n"
237
 
        " <property name=\"geometry\">\n"
238
 
        "  <rect>\n"
239
 
        "   <x>0</x>\n"
240
 
        "   <y>0</y>\n"
241
 
        "   <width>200</width>\n"
242
 
        "   <height>200</height>\n"
243
 
        "  </rect>\n"
244
 
        " </property>\n"
245
 
        " <property name=\"lineWidth\">\n"
246
 
        "  <number>4</number>\n"
247
 
        " </property>\n"
248
 
        "</widget>\n";
249
 
}
250
 
 
251
 
QWidget *DialInterface::createWidget(QWidget *parent)
252
 
{
253
 
    return new QwtDial(parent);
254
 
}
255
 
 
256
 
#endif
257
 
 
258
 
#ifndef NO_QWT_WIDGETS
259
 
 
260
 
KnobInterface::KnobInterface(QObject *parent): 
261
 
    CustomWidgetInterface(parent)
262
 
{
263
 
    d_name = "QwtKnob";
264
 
    d_include = "qwt_knob.h";
265
 
    d_icon = QPixmap(":/pixmaps/qwtknob.png");
266
 
    d_domXml = 
267
 
        "<widget class=\"QwtKnob\" name=\"Knob\">\n"
268
 
        " <property name=\"geometry\">\n"
269
 
        "  <rect>\n"
270
 
        "   <x>0</x>\n"
271
 
        "   <y>0</y>\n"
272
 
        "   <width>100</width>\n"
273
 
        "   <height>100</height>\n"
274
 
        "  </rect>\n"
275
 
        " </property>\n"
276
 
        "</widget>\n";
277
 
}
278
 
 
279
 
QWidget *KnobInterface::createWidget(QWidget *parent)
280
 
{
281
 
    return new QwtKnob(parent);
282
 
}
283
 
 
284
 
#endif
285
 
 
286
 
#ifndef NO_QWT_PLOT
287
 
 
288
 
ScaleWidgetInterface::ScaleWidgetInterface(QObject *parent): 
289
 
    CustomWidgetInterface(parent)
290
 
{
291
 
    d_name = "QwtScale";
292
 
    d_include = "qwt_scale_widget.h";
293
 
    d_icon = QPixmap(":/pixmaps/qwtscale.png");
294
 
    d_domXml = 
295
 
        "<widget class=\"QwtScale\" name=\"Scale\">\n"
296
 
        "</widget>\n";
297
 
}
298
 
 
299
 
QWidget *ScaleWidgetInterface::createWidget(QWidget *parent)
300
 
{
301
 
    return new QwtScaleWidget(QwtScaleDraw::LeftScale, parent);
302
 
}
303
 
 
304
 
#endif
305
 
 
306
 
#ifndef NO_QWT_WIDGETS
307
 
 
308
 
SliderInterface::SliderInterface(QObject *parent): 
309
 
    CustomWidgetInterface(parent)
310
 
{
311
 
    d_name = "QwtSlider";
312
 
    d_include = "qwt_slider.h";
313
 
    d_icon = QPixmap(":/pixmaps/qwtslider.png");
314
 
    d_domXml = 
315
 
        "<widget class=\"QwtSlider\" name=\"Slider\">\n"
316
 
        " <property name=\"geometry\">\n"
317
 
        "  <rect>\n"
318
 
        "   <x>0</x>\n"
319
 
        "   <y>0</y>\n"
320
 
        "   <width>200</width>\n"
321
 
        "   <height>60</height>\n"
322
 
        "  </rect>\n"
323
 
        " </property>\n"
324
 
        "</widget>\n";
325
 
}
326
 
 
327
 
QWidget *SliderInterface::createWidget(QWidget *parent)
328
 
{
329
 
    QwtSlider *slider = new QwtSlider(parent);
330
 
#if 0
331
 
    slider->setScalePosition(QwtSlider::Bottom);
332
 
    slider->setRange(0.0, 10.0, 1.0, 0);
333
 
    slider->setValue(3.0);
334
 
#endif
335
 
    return slider;
336
 
}
337
 
 
338
 
#endif
339
 
 
340
 
TextLabelInterface::TextLabelInterface(QObject *parent): 
341
 
    CustomWidgetInterface(parent)
342
 
{
343
 
    d_name = "QwtTextLabel";
344
 
    d_include = "qwt_text_label.h";
345
 
 
346
 
#ifdef __GNUC__
347
 
#endif
348
 
 
349
 
    d_icon = QPixmap(":/pixmaps/qwtwidget.png");
350
 
    d_domXml = 
351
 
        "<widget class=\"QwtTextLabel\" name=\"TextLabel\">\n"
352
 
        " <property name=\"geometry\">\n"
353
 
        "  <rect>\n"
354
 
        "   <x>0</x>\n"
355
 
        "   <y>0</y>\n"
356
 
        "   <width>100</width>\n"
357
 
        "   <height>20</height>\n"
358
 
        "  </rect>\n"
359
 
        " </property>\n"
360
 
        "</widget>\n";
361
 
}
362
 
 
363
 
QWidget *TextLabelInterface::createWidget(QWidget *parent)
364
 
{
365
 
    return new QwtTextLabel(parent);
366
 
}
367
 
 
368
 
#ifndef NO_QWT_WIDGETS
369
 
 
370
 
ThermoInterface::ThermoInterface(QObject *parent): 
371
 
    CustomWidgetInterface(parent)
372
 
{
373
 
    d_name = "QwtThermo";
374
 
    d_include = "qwt_thermo.h";
375
 
    d_icon = QPixmap(":/pixmaps/qwtthermo.png");
376
 
    d_domXml = 
377
 
        "<widget class=\"QwtThermo\" name=\"Thermo\">\n"
378
 
        "</widget>\n";
379
 
}
380
 
 
381
 
QWidget *ThermoInterface::createWidget(QWidget *parent)
382
 
{
383
 
    return new QwtThermo(parent);
384
 
}
385
 
 
386
 
#endif
387
 
 
388
 
#ifndef NO_QWT_WIDGETS
389
 
 
390
 
WheelInterface::WheelInterface(QObject *parent): 
391
 
    CustomWidgetInterface(parent)
392
 
{
393
 
    d_name = "QwtWheel";
394
 
    d_include = "qwt_wheel.h";
395
 
    d_icon = QPixmap(":/pixmaps/qwtwheel.png");
396
 
    d_domXml = 
397
 
        "<widget class=\"QwtWheel\" name=\"Wheel\">\n"
398
 
        "</widget>\n";
399
 
}
400
 
 
401
 
QWidget *WheelInterface::createWidget(QWidget *parent)
402
 
{
403
 
    return new QwtWheel(parent);
404
 
}
405
 
 
406
 
#endif
407
 
 
408
 
CustomWidgetCollectionInterface::CustomWidgetCollectionInterface(   
409
 
        QObject *parent): 
410
 
    QObject(parent)
411
 
{
412
 
#ifndef NO_QWT_PLOT
413
 
    d_plugins.append(new PlotInterface(this));
414
 
    d_plugins.append(new ScaleWidgetInterface(this));
415
 
#endif
416
 
 
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));
426
 
#endif
427
 
 
428
 
    d_plugins.append(new TextLabelInterface(this));
429
 
}
430
 
 
431
 
QList<QDesignerCustomWidgetInterface*> 
432
 
    CustomWidgetCollectionInterface::customWidgets(void) const
433
 
{
434
 
    return d_plugins;
435
 
}
436
 
 
437
 
TaskMenuFactory::TaskMenuFactory(QExtensionManager *parent): 
438
 
    QExtensionFactory(parent)
439
 
{
440
 
}
441
 
 
442
 
QObject *TaskMenuFactory::createExtension(
443
 
    QObject *object, const QString &iid, QObject *parent) const
444
 
{
445
 
    if (iid == Q_TYPEID(QDesignerTaskMenuExtension))
446
 
    {
447
 
#ifndef NO_QWT_PLOT
448
 
        if (QwtPlot *plot = qobject_cast<QwtPlot*>(object))
449
 
            return new TaskMenuExtension(plot, parent);
450
 
#endif
451
 
#ifndef NO_QWT_WIDGETS
452
 
        if (QwtDial *dial = qobject_cast<QwtDial*>(object))
453
 
            return new TaskMenuExtension(dial, parent);
454
 
#endif
455
 
    }
456
 
 
457
 
    return QExtensionFactory::createExtension(object, iid, parent);
458
 
}
459
 
 
460
 
 
461
 
TaskMenuExtension::TaskMenuExtension(QWidget *widget, QObject *parent):
462
 
    QObject(parent),    
463
 
    d_widget(widget)
464
 
{
465
 
    d_editAction = new QAction(tr("Edit Qwt Attributes ..."), this);
466
 
    connect(d_editAction, SIGNAL(triggered()), 
467
 
        this, SLOT(editProperties()));
468
 
}
469
 
 
470
 
QList<QAction *> TaskMenuExtension::taskActions() const
471
 
{
472
 
    QList<QAction *> list;
473
 
    list.append(d_editAction);
474
 
    return list;
475
 
}
476
 
 
477
 
QAction *TaskMenuExtension::preferredEditAction() const
478
 
{
479
 
    return d_editAction;
480
 
}
481
 
 
482
 
void TaskMenuExtension::editProperties()
483
 
{
484
 
    const QVariant v = d_widget->property("propertiesDocument");
485
 
    if ( v.type() != QVariant::String )
486
 
        return;
487
 
 
488
 
#ifndef NO_QWT_PLOT
489
 
    QString properties = v.toString();
490
 
 
491
 
    if ( qobject_cast<QwtPlot*>(d_widget) )
492
 
    {
493
 
        PlotDialog dialog(properties);
494
 
        connect(&dialog, SIGNAL(edited(const QString&)), 
495
 
            SLOT(applyProperties(const QString &)));
496
 
        (void)dialog.exec();
497
 
        return;
498
 
    }
499
 
#endif
500
 
 
501
 
    static QErrorMessage *errorMessage = NULL;
502
 
    if ( errorMessage == NULL )
503
 
        errorMessage = new QErrorMessage();
504
 
    errorMessage->showMessage("Not implemented yet.");
505
 
}
506
 
 
507
 
void TaskMenuExtension::applyProperties(const QString &properties)
508
 
{
509
 
    QDesignerFormWindowInterface *formWindow
510
 
        = QDesignerFormWindowInterface::findFormWindow(d_widget);
511
 
    if ( formWindow && formWindow->cursor() )
512
 
        formWindow->cursor()->setProperty("propertiesDocument", properties);
513
 
}
514
 
 
515
 
Q_EXPORT_PLUGIN2(QwtDesignerPlugin, CustomWidgetCollectionInterface)