~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to tools/designer/src/components/propertyeditor/qpropertyeditor_items.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-08-24 04:09:09 UTC
  • Revision ID: james.westby@ubuntu.com-20050824040909-xmxe9jfr4a0w5671
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
 
4
**
 
5
** This file is part of the designer application of the Qt Toolkit.
 
6
**
 
7
** This file may be distributed under the terms of the Q Public License
 
8
** as defined by Trolltech AS of Norway and appearing in the file
 
9
** LICENSE.QPL included in the packaging of this file.
 
10
**
 
11
** This file may be distributed and/or modified under the terms of the
 
12
** GNU General Public License version 2 as published by the Free Software
 
13
** Foundation and appearing in the file LICENSE.GPL included in the
 
14
** packaging of this file.
 
15
**
 
16
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
 
17
**   information about Qt Commercial License Agreements.
 
18
** See http://www.trolltech.com/qpl/ for QPL licensing information.
 
19
** See http://www.trolltech.com/gpl/ for GPL licensing information.
 
20
**
 
21
** Contact info@trolltech.com if any conditions of this licensing are
 
22
** not clear to you.
 
23
**
 
24
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 
25
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 
26
**
 
27
****************************************************************************/
 
28
 
 
29
#include "qpropertyeditor_items_p.h"
 
30
#include "flagbox_p.h"
 
31
#include "paletteeditorbutton.h"
 
32
#include "defs.h"
 
33
 
 
34
#include <QtDesigner/propertysheet.h>
 
35
 
 
36
#include <qdesigner_utils_p.h>
 
37
 
 
38
#include <QtGui/QLineEdit>
 
39
#include <QtGui/QListView>
 
40
#include <QtGui/QComboBox>
 
41
#include <QtGui/QSpinBox>
 
42
#include <QtGui/QValidator>
 
43
#include <QtGui/QFontDatabase>
 
44
#include <QtGui/QPainter>
 
45
#include <QtGui/QDateTimeEdit>
 
46
#include <QtGui/QBitmap>
 
47
#include <QtGui/QLabel>
 
48
 
 
49
#include <QtCore/qdebug.h>
 
50
#include <limits.h>
 
51
 
 
52
using namespace qdesigner_internal;
 
53
 
 
54
Q_GLOBAL_STATIC(QFontDatabase, fontDatabase)
 
55
 
 
56
void IProperty::setDirty(bool b)
 
57
{
 
58
    if (isFake()) {
 
59
        IProperty *p = parent();
 
60
        while (p != 0 && p->isFake())
 
61
            p = p->parent();
 
62
        if (p != 0)
 
63
            p->setDirty(true);
 
64
    } else {
 
65
        m_dirty = b;
 
66
    }
 
67
}
 
68
 
 
69
void IProperty::setChanged(bool b)
 
70
{
 
71
    if (isFake()) {
 
72
        IProperty *p = parent();
 
73
        while (p != 0 && p->isFake())
 
74
            p = p->parent();
 
75
        if (p != 0)
 
76
            p->setChanged(true);
 
77
    } else {
 
78
        m_changed = b;
 
79
    }
 
80
    setDirty(true);
 
81
}
 
82
 
 
83
// -------------------------------------------------------------------------
 
84
 
 
85
QWidget *AbstractPropertyGroup::createEditor(QWidget *parent, const QObject *target, const char *receiver) const
 
86
{
 
87
    Q_UNUSED(target);
 
88
    Q_UNUSED(receiver);
 
89
 
 
90
    QLabel *label = new QLabel(parent);
 
91
    label->setIndent(2); // ### hardcode it should have the same value of textMargin in QItemDelegate
 
92
    return label;
 
93
}
 
94
 
 
95
void AbstractPropertyGroup::updateEditorContents(QWidget *editor)
 
96
{
 
97
    QLabel *label = qobject_cast<QLabel*>(editor);
 
98
    if (label == 0)
 
99
        return;
 
100
    label->setText(toString());
 
101
}
 
102
 
 
103
// -------------------------------------------------------------------------
 
104
BoolProperty::BoolProperty(bool value, const QString &name)
 
105
    : AbstractProperty<bool>(value, name)
 
106
{
 
107
}
 
108
 
 
109
void BoolProperty::setValue(const QVariant &value)
 
110
{
 
111
    m_value = value.toBool();
 
112
}
 
113
 
 
114
QString BoolProperty::toString() const
 
115
{
 
116
    return m_value ? QLatin1String("true") : QLatin1String("false");
 
117
}
 
118
 
 
119
QWidget *BoolProperty::createEditor(QWidget *parent, const QObject *target, const char *receiver) const
 
120
{
 
121
    QComboBox *combo = new QComboBox(parent);
 
122
    combo->view()->setTextElideMode(Qt::ElideLeft);
 
123
    combo->setFrame(0);
 
124
    combo->addItems(QStringList() << QString::fromUtf8("false") << QString::fromUtf8("true"));
 
125
    QObject::connect(combo, SIGNAL(activated(int)), target, receiver);
 
126
 
 
127
    return combo;
 
128
}
 
129
 
 
130
void BoolProperty::updateEditorContents(QWidget *editor)
 
131
{
 
132
    if (QComboBox *combo = qobject_cast<QComboBox*>(editor)) {
 
133
        combo->setCurrentIndex(m_value ? 1 : 0);
 
134
    }
 
135
}
 
136
 
 
137
void BoolProperty::updateValue(QWidget *editor)
 
138
{
 
139
    if (QComboBox *combo = qobject_cast<QComboBox*>(editor)) {
 
140
        bool newValue = combo->currentIndex() ? true : false;
 
141
 
 
142
        if (newValue != m_value) {
 
143
            m_value = newValue;
 
144
            setChanged(true);
 
145
        }
 
146
    }
 
147
}
 
148
 
 
149
// -------------------------------------------------------------------------
 
150
PointProperty::PointProperty(const QPoint &value, const QString &name)
 
151
    : AbstractPropertyGroup(name)
 
152
{
 
153
    IProperty *px = new IntProperty(value.x(), QLatin1String("x"));
 
154
    px->setFake(true);
 
155
    px->setParent(this);
 
156
 
 
157
    IProperty *py = new IntProperty(value.y(), QLatin1String("y"));
 
158
    py->setFake(true);
 
159
    py->setParent(this);
 
160
 
 
161
    m_properties << px << py;
 
162
}
 
163
 
 
164
QVariant PointProperty::value() const
 
165
{
 
166
    return QPoint(propertyAt(0)->value().toInt(),
 
167
                  propertyAt(1)->value().toInt());
 
168
}
 
169
 
 
170
void PointProperty::setValue(const QVariant &value)
 
171
{
 
172
    QPoint pt = value.toPoint();
 
173
    propertyAt(0)->setValue(pt.x());
 
174
    propertyAt(1)->setValue(pt.y());
 
175
}
 
176
 
 
177
// -------------------------------------------------------------------------
 
178
PropertyCollection::PropertyCollection(const QString &name)
 
179
    : m_name(name)
 
180
{
 
181
}
 
182
 
 
183
PropertyCollection::~PropertyCollection()
 
184
{
 
185
    qDeleteAll(m_properties);
 
186
}
 
187
 
 
188
void PropertyCollection::addProperty(IProperty *property)
 
189
{
 
190
    property->setParent(this);
 
191
    m_properties.append(property);
 
192
}
 
193
 
 
194
void PropertyCollection::removeProperty(IProperty *property)
 
195
{
 
196
    Q_UNUSED(property);
 
197
}
 
198
 
 
199
int PropertyCollection::indexOf(IProperty *property) const
 
200
{
 
201
    return m_properties.indexOf(property);
 
202
}
 
203
 
 
204
int PropertyCollection::propertyCount() const
 
205
{
 
206
    return m_properties.size();
 
207
}
 
208
 
 
209
IProperty *PropertyCollection::propertyAt(int index) const
 
210
{
 
211
    return m_properties.at(index);
 
212
}
 
213
 
 
214
QString PropertyCollection::propertyName() const
 
215
{
 
216
    return m_name;
 
217
}
 
218
 
 
219
QVariant PropertyCollection::value() const
 
220
{
 
221
    return QVariant();
 
222
}
 
223
 
 
224
void PropertyCollection::setValue(const QVariant &value)
 
225
{
 
226
    Q_UNUSED(value);
 
227
}
 
228
 
 
229
QString PropertyCollection::toString() const
 
230
{
 
231
    return QString();
 
232
}
 
233
 
 
234
bool PropertyCollection::hasEditor() const
 
235
{
 
236
    return false;
 
237
}
 
238
 
 
239
QWidget *PropertyCollection::createEditor(QWidget *parent, const QObject *target, const char *receiver) const
 
240
{
 
241
    Q_UNUSED(parent);
 
242
    Q_UNUSED(target);
 
243
    Q_UNUSED(receiver);
 
244
    return 0;
 
245
}
 
246
 
 
247
bool PropertyCollection::hasExternalEditor() const
 
248
{
 
249
    return false;
 
250
}
 
251
 
 
252
QWidget *PropertyCollection::createExternalEditor(QWidget *parent)
 
253
{
 
254
    Q_UNUSED(parent);
 
255
    return 0;
 
256
}
 
257
 
 
258
// -------------------------------------------------------------------------
 
259
 
 
260
StringProperty::StringProperty(const QString &value, const QString &name)
 
261
    : AbstractProperty<QString>(value, name)
 
262
{
 
263
}
 
264
 
 
265
void StringProperty::setValue(const QVariant &value)
 
266
{
 
267
    m_value = value.toString();
 
268
}
 
269
 
 
270
QString StringProperty::toString() const
 
271
{
 
272
    return m_value;
 
273
}
 
274
 
 
275
QWidget *StringProperty::createEditor(QWidget *parent, const QObject *target, const char *receiver) const
 
276
{
 
277
    QLineEdit *lineEdit = new QLineEdit(parent);
 
278
    lineEdit->setFrame(0);
 
279
 
 
280
    if (propertyName() == QLatin1String("objectName")) {
 
281
        lineEdit->setValidator(new QRegExpValidator(QRegExp(QLatin1String("[_a-zA-Z][_a-zA-Z0-9]*")), lineEdit));
 
282
    }
 
283
 
 
284
    QObject::connect(lineEdit, SIGNAL(textChanged(QString)), target, receiver);
 
285
    return lineEdit;
 
286
}
 
287
 
 
288
void StringProperty::updateEditorContents(QWidget *editor)
 
289
{
 
290
    if (QLineEdit *lineEdit = qobject_cast<QLineEdit*>(editor)) {
 
291
        if (lineEdit->text() != m_value)
 
292
            lineEdit->setText(m_value);
 
293
    }
 
294
}
 
295
 
 
296
void StringProperty::updateValue(QWidget *editor)
 
297
{
 
298
    if (QLineEdit *lineEdit = qobject_cast<QLineEdit*>(editor)) {
 
299
        QString newValue = lineEdit->text();
 
300
 
 
301
        if (newValue != m_value) {
 
302
            m_value = newValue;
 
303
            setChanged(true);
 
304
        }
 
305
 
 
306
    }
 
307
}
 
308
 
 
309
 
 
310
// -------------------------------------------------------------------------
 
311
ListProperty::ListProperty(const QStringList &items, int value, const QString &name)
 
312
    : AbstractProperty<int>(value, name), m_items(items)
 
313
{
 
314
}
 
315
 
 
316
QStringList ListProperty::items() const
 
317
{
 
318
    return m_items;
 
319
}
 
320
 
 
321
void ListProperty::setValue(const QVariant &value)
 
322
{
 
323
    m_value = value.toInt();
 
324
}
 
325
 
 
326
QString ListProperty::toString() const
 
327
{
 
328
    if (m_items.isEmpty())
 
329
        return QString();
 
330
    else if (m_value < 0 || m_value >= m_items.count())
 
331
        return m_items.first();
 
332
 
 
333
    return m_items.at(m_value);
 
334
}
 
335
 
 
336
QWidget *ListProperty::createEditor(QWidget *parent, const QObject *target, const char *receiver) const
 
337
{
 
338
    QComboBox *combo = new QComboBox(parent);
 
339
    combo->view()->setTextElideMode(Qt::ElideLeft);
 
340
    combo->setFrame(0);
 
341
 
 
342
    combo->addItems(items());
 
343
    QObject::connect(combo, SIGNAL(activated(int)), target, receiver);
 
344
    return combo;
 
345
}
 
346
 
 
347
void ListProperty::updateEditorContents(QWidget *editor)
 
348
{
 
349
    if (QComboBox *combo = qobject_cast<QComboBox*>(editor)) {
 
350
        combo->setCurrentIndex(m_value);
 
351
    }
 
352
}
 
353
 
 
354
void ListProperty::updateValue(QWidget *editor)
 
355
{
 
356
    if (QComboBox *combo = qobject_cast<QComboBox*>(editor)) {
 
357
        int newValue = combo->currentIndex();
 
358
 
 
359
        if (newValue != m_value) {
 
360
            m_value = newValue;
 
361
            setChanged(true);
 
362
        }
 
363
    }
 
364
}
 
365
 
 
366
// -------------------------------------------------------------------------
 
367
SizeProperty::SizeProperty(const QSize &value, const QString &name)
 
368
    : AbstractPropertyGroup(name)
 
369
{
 
370
    IntProperty *pw = new IntProperty(value.width(), QLatin1String("width"));
 
371
    pw->setFake(true);
 
372
    pw->setParent(this);
 
373
    pw->setRange(0, INT_MAX);
 
374
 
 
375
    IntProperty *ph = new IntProperty(value.height(), QLatin1String("height"));
 
376
    ph->setFake(true);
 
377
    ph->setParent(this);
 
378
    ph->setRange(0, INT_MAX);
 
379
 
 
380
    m_properties << pw << ph;
 
381
}
 
382
 
 
383
QVariant SizeProperty::value() const
 
384
{
 
385
    return QSize(propertyAt(0)->value().toInt(),
 
386
                 propertyAt(1)->value().toInt());
 
387
}
 
388
 
 
389
void SizeProperty::setValue(const QVariant &value)
 
390
{
 
391
    QSize pt = value.toSize();
 
392
    propertyAt(0)->setValue(pt.width());
 
393
    propertyAt(1)->setValue(pt.height());
 
394
}
 
395
 
 
396
// -------------------------------------------------------------------------
 
397
IntProperty::IntProperty(int value, const QString &name)
 
398
    : AbstractProperty<int>(value, name), m_low(INT_MIN), m_hi(INT_MAX)
 
399
{
 
400
}
 
401
 
 
402
void IntProperty::setRange(int low, int hi)
 
403
{
 
404
    m_low = low;
 
405
    m_hi = hi;
 
406
}
 
407
 
 
408
QString IntProperty::specialValue() const
 
409
{
 
410
    return m_specialValue;
 
411
}
 
412
 
 
413
void IntProperty::setSpecialValue(const QString &specialValue)
 
414
{
 
415
    m_specialValue = specialValue;
 
416
}
 
417
 
 
418
void IntProperty::setValue(const QVariant &value)
 
419
{
 
420
    m_value = value.toInt();
 
421
}
 
422
 
 
423
QString IntProperty::toString() const
 
424
{
 
425
    return QString::number(m_value);
 
426
}
 
427
 
 
428
QWidget *IntProperty::createEditor(QWidget *parent, const QObject *target, const char *receiver) const
 
429
{
 
430
    QSpinBox *spinBox = new QSpinBox(parent);
 
431
    spinBox->setFrame(0);
 
432
    spinBox->setSpecialValueText(m_specialValue);
 
433
    spinBox->setRange(m_low, m_hi);
 
434
    spinBox->setValue(m_value);
 
435
    spinBox->selectAll();
 
436
 
 
437
    QObject::connect(spinBox, SIGNAL(valueChanged(int)), target, receiver);
 
438
 
 
439
    return spinBox;
 
440
}
 
441
 
 
442
void IntProperty::updateEditorContents(QWidget *editor)
 
443
{
 
444
    if (QSpinBox *spinBox = qobject_cast<QSpinBox*>(editor)) {
 
445
        spinBox->setValue(m_value);
 
446
    }
 
447
}
 
448
 
 
449
void IntProperty::updateValue(QWidget *editor)
 
450
{
 
451
    if (QSpinBox *spinBox = qobject_cast<QSpinBox*>(editor)) {
 
452
        int newValue = spinBox->value();
 
453
 
 
454
        if (newValue != m_value) {
 
455
            m_value = newValue;
 
456
            setChanged(true);
 
457
        }
 
458
    }
 
459
}
 
460
 
 
461
// -------------------------------------------------------------------------
 
462
RectProperty::RectProperty(const QRect &value, const QString &name)
 
463
    : AbstractPropertyGroup(name)
 
464
{
 
465
    IntProperty *px = new IntProperty(value.x(), QLatin1String("x"));
 
466
    px->setFake(true);
 
467
    px->setParent(this);
 
468
 
 
469
    IntProperty *py = new IntProperty(value.y(), QLatin1String("y"));
 
470
    py->setFake(true);
 
471
    py->setParent(this);
 
472
 
 
473
    IntProperty *pw = new IntProperty(value.width(), QLatin1String("width"));
 
474
    pw->setFake(true);
 
475
    pw->setParent(this);
 
476
    pw->setRange(0, INT_MAX);
 
477
 
 
478
    IntProperty *ph = new IntProperty(value.height(), QLatin1String("height"));
 
479
    ph->setFake(true);
 
480
    ph->setParent(this);
 
481
    ph->setRange(0, INT_MAX);
 
482
 
 
483
    m_properties << px << py << pw << ph;
 
484
}
 
485
 
 
486
QVariant RectProperty::value() const
 
487
{
 
488
    return QRect(propertyAt(0)->value().toInt(),
 
489
                 propertyAt(1)->value().toInt(),
 
490
                 propertyAt(2)->value().toInt(),
 
491
                 propertyAt(3)->value().toInt());
 
492
}
 
493
 
 
494
void RectProperty::setValue(const QVariant &value)
 
495
{
 
496
    QRect pt = value.toRect();
 
497
    propertyAt(0)->setValue(pt.x());
 
498
    propertyAt(1)->setValue(pt.y());
 
499
    propertyAt(2)->setValue(pt.width());
 
500
    propertyAt(3)->setValue(pt.height());
 
501
}
 
502
 
 
503
 
 
504
// -------------------------------------------------------------------------
 
505
ColorProperty::ColorProperty(const QColor &value, const QString &name)
 
506
    : AbstractPropertyGroup(name)
 
507
{
 
508
    IntProperty *r = new IntProperty(value.red(), QLatin1String("red"));
 
509
    r->setFake(true);
 
510
    r->setRange(0, 255);
 
511
    r->setParent(this);
 
512
 
 
513
    IntProperty *g = new IntProperty(value.green(), QLatin1String("green"));
 
514
    g->setFake(true);
 
515
    g->setRange(0, 255);
 
516
    g->setParent(this);
 
517
 
 
518
    IntProperty *b = new IntProperty(value.blue(), QLatin1String("blue"));
 
519
    b->setFake(true);
 
520
    b->setRange(0, 255);
 
521
    b->setParent(this);
 
522
 
 
523
    m_properties << r << g << b;
 
524
}
 
525
 
 
526
QVariant ColorProperty::value() const
 
527
{
 
528
    return qVariantFromValue(QColor(propertyAt(0)->value().toInt(),
 
529
                  propertyAt(1)->value().toInt(),
 
530
                  propertyAt(2)->value().toInt()));
 
531
}
 
532
 
 
533
void ColorProperty::setValue(const QVariant &value)
 
534
{
 
535
    QColor c = qvariant_cast<QColor>(value);
 
536
    propertyAt(0)->setValue(c.red());
 
537
    propertyAt(1)->setValue(c.green());
 
538
    propertyAt(2)->setValue(c.blue());
 
539
}
 
540
 
 
541
QVariant ColorProperty::decoration() const
 
542
{
 
543
    QPixmap pix(16, 16);
 
544
    pix.fill(qvariant_cast<QColor>(value()));
 
545
    return qVariantFromValue(pix);
 
546
}
 
547
 
 
548
// -------------------------------------------------------------------------
 
549
FontProperty::FontProperty(const QFont &value, const QString &name)
 
550
    : AbstractPropertyGroup(name)
 
551
{
 
552
    QStringList fonts = fontDatabase()->families();
 
553
    int index = fonts.indexOf(value.family());
 
554
    if (index == -1)
 
555
        index = 0;
 
556
 
 
557
    IProperty *i = 0;
 
558
    i = new ListProperty(fonts, index, QLatin1String("Family"));
 
559
    i->setFake(true);
 
560
    i->setParent(this);
 
561
    m_properties << i;
 
562
 
 
563
    IntProperty *ii = new IntProperty(value.pointSize(), QLatin1String("Point Size"));
 
564
    ii->setFake(true);
 
565
    ii->setRange(1, INT_MAX); // ### check
 
566
    ii->setParent(this);
 
567
    m_properties << ii;
 
568
 
 
569
    i = new BoolProperty(value.bold(), QLatin1String("Bold"));
 
570
    i->setFake(true);
 
571
    i->setParent(this);
 
572
    m_properties << i;
 
573
 
 
574
    i = new BoolProperty(value.italic(), QLatin1String("Italic"));
 
575
    i->setFake(true);
 
576
    i->setParent(this);
 
577
    m_properties << i;
 
578
 
 
579
    i = new BoolProperty(value.underline(), QLatin1String("Underline"));
 
580
    i->setFake(true);
 
581
    i->setParent(this);
 
582
    m_properties << i;
 
583
 
 
584
    i = new BoolProperty(value.strikeOut(), QLatin1String("Strikeout"));
 
585
    i->setFake(true);
 
586
    i->setParent(this);
 
587
    m_properties << i;
 
588
}
 
589
 
 
590
QVariant FontProperty::value() const
 
591
{
 
592
    QFont fnt;
 
593
    fnt.setFamily(propertyAt(0)->toString());
 
594
    fnt.setPointSize(propertyAt(1)->value().toInt());
 
595
    fnt.setBold(propertyAt(2)->value().toBool());
 
596
    fnt.setItalic(propertyAt(3)->value().toBool());
 
597
    fnt.setUnderline(propertyAt(4)->value().toBool());
 
598
    fnt.setStrikeOut(propertyAt(5)->value().toBool());
 
599
 
 
600
    return qVariantFromValue(fnt);
 
601
}
 
602
 
 
603
void FontProperty::setValue(const QVariant &value)
 
604
{
 
605
    QFont fnt = qvariant_cast<QFont>(value);
 
606
 
 
607
    int family = fontDatabase()->families().indexOf(fnt.family());
 
608
 
 
609
    propertyAt(0)->setValue(family);
 
610
    propertyAt(1)->setValue(fnt.pointSize());
 
611
    propertyAt(2)->setValue(fnt.bold());
 
612
    propertyAt(3)->setValue(fnt.italic());
 
613
    propertyAt(4)->setValue(fnt.underline());
 
614
    propertyAt(5)->setValue(fnt.strikeOut());
 
615
}
 
616
 
 
617
QVariant FontProperty::decoration() const
 
618
{
 
619
    QPixmap pix(16, 16);
 
620
    pix.fill(Qt::white);
 
621
    QPainter p(&pix);
 
622
    QFont fnt = qvariant_cast<QFont>(value());
 
623
    fnt.setPointSize(10); // ### always 10pt!!
 
624
    p.drawRect(0, 0, 16, 16);
 
625
    p.setFont(fnt);
 
626
    p.drawText(0, 16 - 2, QLatin1String("Aa")); // ### 2px for the border!!
 
627
    return qVariantFromValue(pix);
 
628
}
 
629
 
 
630
QString FontProperty::toString() const
 
631
{
 
632
    QString family = propertyAt(0)->toString();
 
633
    QString pointSize = propertyAt(1)->value().toString();
 
634
 
 
635
    return QLatin1String("  ")  // ### temp hack
 
636
        + QLatin1String("[") + family + QLatin1String(", ") + pointSize + QLatin1String("]");
 
637
}
 
638
 
 
639
// -------------------------------------------------------------------------
 
640
MapProperty::MapProperty(const QMap<QString, QVariant> &items,
 
641
                         const QVariant &value,
 
642
                         const QString &name)
 
643
    : AbstractProperty<QVariant>(value, name),
 
644
      m_items(items),
 
645
      m_keys(m_items.keys())
 
646
{
 
647
}
 
648
 
 
649
QStringList MapProperty::keys() const
 
650
{
 
651
    return m_keys;
 
652
}
 
653
 
 
654
QMap<QString, QVariant> MapProperty::items() const
 
655
{
 
656
    return m_items;
 
657
}
 
658
 
 
659
QVariant MapProperty::value() const
 
660
{
 
661
    return m_value;
 
662
}
 
663
 
 
664
void MapProperty::setValue(const QVariant &value)
 
665
{
 
666
   if (qVariantCanConvert<EnumType>(value)) {
 
667
        EnumType e = qvariant_cast<EnumType>(value);
 
668
        m_value = e.value;
 
669
    } else {
 
670
        m_value = value;
 
671
    }
 
672
}
 
673
 
 
674
QString MapProperty::toString() const
 
675
{
 
676
    return m_items.key(m_value);
 
677
}
 
678
 
 
679
int MapProperty::indexOf(const QVariant &value) const
 
680
{
 
681
    QString key = m_items.key(value);
 
682
    return m_keys.indexOf(key);
 
683
}
 
684
 
 
685
QWidget *MapProperty::createEditor(QWidget *parent, const QObject *target, const char *receiver) const
 
686
{
 
687
    QComboBox *combo = new QComboBox(parent);
 
688
    combo->view()->setTextElideMode(Qt::ElideLeft);
 
689
    combo->setFrame(0);
 
690
 
 
691
    combo->addItems(m_keys);
 
692
    QObject::connect(combo, SIGNAL(activated(int)), target, receiver);
 
693
 
 
694
    return combo;
 
695
}
 
696
 
 
697
void MapProperty::updateEditorContents(QWidget *editor)
 
698
{
 
699
    if (QComboBox *combo = qobject_cast<QComboBox*>(editor)) {
 
700
        combo->setCurrentIndex(indexOf(m_value));
 
701
    }
 
702
}
 
703
 
 
704
void MapProperty::updateValue(QWidget *editor)
 
705
{
 
706
    if (QComboBox *combo = qobject_cast<QComboBox*>(editor)) {
 
707
        QString key = combo->currentText();
 
708
        QVariant newValue = m_items.value(key);
 
709
 
 
710
        if (newValue != m_value) {
 
711
            m_value = newValue;
 
712
            setChanged(true);
 
713
        }
 
714
    }
 
715
}
 
716
 
 
717
// -------------------------------------------------------------------------
 
718
FlagsProperty::FlagsProperty(const QMap<QString, QVariant> &items, unsigned int value,
 
719
                             const QString &name)
 
720
    : MapProperty(items, QVariant(value), name)
 
721
{
 
722
}
 
723
 
 
724
QWidget *FlagsProperty::createEditor(QWidget *parent, const QObject *target, const char *receiver) const
 
725
{
 
726
    QList<FlagBoxModelItem> l;
 
727
    QMapIterator<QString, QVariant> it(items());
 
728
    while (it.hasNext()) {
 
729
        it.next();
 
730
        l.append(FlagBoxModelItem(it.key(), it.value().toUInt(), /*checked=*/false));
 
731
    }
 
732
 
 
733
    FlagBox *editor = new FlagBox(parent);
 
734
    editor->setItems(l);
 
735
    QObject::connect(editor, SIGNAL(activated(int)), target, receiver);
 
736
    return editor;
 
737
}
 
738
 
 
739
void FlagsProperty::updateEditorContents(QWidget *editor)
 
740
{
 
741
    FlagBox *box = qobject_cast<FlagBox*>(editor);
 
742
    if (box == 0)
 
743
        return;
 
744
 
 
745
    unsigned int v = m_value.toUInt();
 
746
 
 
747
    // step 0) clear the contents
 
748
    for (int i=0; i<box->count(); ++i) {
 
749
        FlagBoxModelItem &item = box->item(i);
 
750
        item.setChecked(false);
 
751
    }
 
752
 
 
753
    // step 1) perfect match
 
754
    bool foundPerfectMatch = false;
 
755
    for (int i=0; !foundPerfectMatch && i<box->count(); ++i) {
 
756
        FlagBoxModelItem &item = box->item(i);
 
757
        foundPerfectMatch = item.value() == v;
 
758
        item.setChecked(foundPerfectMatch);
 
759
    }
 
760
 
 
761
    if (!foundPerfectMatch) {
 
762
        // step 2)
 
763
        for (int i=0; i<box->count(); ++i) {
 
764
            FlagBoxModelItem &item = box->item(i);
 
765
            item.setChecked((item.value() & v) == item.value());
 
766
        }
 
767
    }
 
768
 
 
769
    box->view()->reset();
 
770
}
 
771
 
 
772
void FlagsProperty::updateValue(QWidget *editor)
 
773
{
 
774
    FlagBox *box = qobject_cast<FlagBox*>(editor);
 
775
    if (box == 0)
 
776
        return;
 
777
 
 
778
    unsigned int newValue = 0;
 
779
 
 
780
    for (int i=0; i<box->count(); ++i) {
 
781
        FlagBoxModelItem &item = box->item(i);
 
782
        if (item.isChecked())
 
783
            newValue |= item.value();
 
784
    }
 
785
 
 
786
    if (newValue != m_value) {
 
787
        m_value = newValue;
 
788
        setChanged(true);
 
789
    }
 
790
}
 
791
 
 
792
// -------------------------------------------------------------------------
 
793
SizePolicyProperty::SizePolicyProperty(const QSizePolicy &value, const QString &name)
 
794
    : AbstractPropertyGroup(name)
 
795
{
 
796
    QStringList lst;
 
797
    lst << QString::fromUtf8("Fixed")
 
798
        << QString::fromUtf8("Minimum")
 
799
        << QString::fromUtf8("Maximum")
 
800
        << QString::fromUtf8("Preferred")
 
801
        << QString::fromUtf8("MinimumExpanding")
 
802
        << QString::fromUtf8("Expanding")
 
803
        << QString::fromUtf8("Ignored");
 
804
 
 
805
    IProperty *i = 0;
 
806
    i = new ListProperty(lst, size_type_to_int(value.horizontalPolicy()), QLatin1String("hSizeType"));
 
807
    i->setFake(true);
 
808
    i->setParent(this);
 
809
    m_properties << i;
 
810
 
 
811
    i = new ListProperty(lst, size_type_to_int(value.verticalPolicy()), QLatin1String("vSizeType"));
 
812
    i->setFake(true);
 
813
    i->setParent(this);
 
814
    m_properties << i;
 
815
 
 
816
    i = new IntProperty(value.horizontalStretch(), QLatin1String("horizontalStretch"));
 
817
    i->setFake(true);
 
818
    i->setParent(this);
 
819
    m_properties << i;
 
820
 
 
821
    i = new IntProperty(value.verticalStretch(), QLatin1String("verticalStretch"));
 
822
    i->setFake(true);
 
823
    i->setParent(this);
 
824
    m_properties << i;
 
825
}
 
826
 
 
827
QVariant SizePolicyProperty::value() const
 
828
{
 
829
    QSizePolicy sizePolicy;
 
830
    sizePolicy.setHorizontalPolicy(int_to_size_type(propertyAt(0)->value().toInt()));
 
831
    sizePolicy.setVerticalPolicy(int_to_size_type(propertyAt(1)->value().toInt()));
 
832
    sizePolicy.setHorizontalStretch(propertyAt(2)->value().toInt());
 
833
    sizePolicy.setVerticalStretch(propertyAt(3)->value().toInt());
 
834
    return qVariantFromValue(sizePolicy);
 
835
}
 
836
 
 
837
void SizePolicyProperty::setValue(const QVariant &value)
 
838
{
 
839
    QSizePolicy sizePolicy = qvariant_cast<QSizePolicy>(value);
 
840
 
 
841
    propertyAt(0)->setValue(size_type_to_int(sizePolicy.horizontalPolicy()));
 
842
    propertyAt(1)->setValue(size_type_to_int(sizePolicy.verticalPolicy()));
 
843
    propertyAt(2)->setValue(sizePolicy.horizontalStretch());
 
844
    propertyAt(3)->setValue(sizePolicy.verticalStretch());
 
845
}
 
846
 
 
847
QVariant SizePolicyProperty::decoration() const
 
848
{
 
849
    return QVariant();
 
850
}
 
851
 
 
852
QString SizePolicyProperty::toString() const
 
853
{
 
854
    return AbstractPropertyGroup::toString();
 
855
}
 
856
 
 
857
// -------------------------------------------------------------------------
 
858
DateTimeProperty::DateTimeProperty(const QDateTime &value, const QString &name)
 
859
    : AbstractProperty<QDateTime>(value, name)
 
860
{
 
861
}
 
862
 
 
863
void DateTimeProperty::setValue(const QVariant &value)
 
864
{
 
865
    m_value = value.toDateTime();
 
866
}
 
867
 
 
868
QString DateTimeProperty::toString() const
 
869
{
 
870
    return m_value.toString();
 
871
}
 
872
 
 
873
QWidget *DateTimeProperty::createEditor(QWidget *parent, const QObject *target, const char *receiver) const
 
874
{
 
875
    QDateTimeEdit *lineEdit = new QDateTimeEdit(parent);
 
876
    QObject::connect(lineEdit, SIGNAL(dateTimeChanged(QDateTime)), target, receiver);
 
877
    return lineEdit;
 
878
}
 
879
 
 
880
void DateTimeProperty::updateEditorContents(QWidget *editor)
 
881
{
 
882
    if (QDateTimeEdit *lineEdit = qobject_cast<QDateTimeEdit*>(editor)) {
 
883
        lineEdit->setDateTime(m_value);
 
884
    }
 
885
}
 
886
 
 
887
void DateTimeProperty::updateValue(QWidget *editor)
 
888
{
 
889
    if (QDateTimeEdit *lineEdit = qobject_cast<QDateTimeEdit*>(editor)) {
 
890
        QDateTime newValue = lineEdit->dateTime();
 
891
 
 
892
        if (newValue != m_value) {
 
893
            m_value = newValue;
 
894
            setChanged(true);
 
895
        }
 
896
 
 
897
    }
 
898
}
 
899
 
 
900
// -------------------------------------------------------------------------
 
901
DateProperty::DateProperty(const QDate &value, const QString &name)
 
902
    : AbstractProperty<QDate>(value, name)
 
903
{
 
904
}
 
905
 
 
906
void DateProperty::setValue(const QVariant &value)
 
907
{
 
908
    m_value = value.toDate();
 
909
}
 
910
 
 
911
QString DateProperty::toString() const
 
912
{
 
913
    return m_value.toString();
 
914
}
 
915
 
 
916
QWidget *DateProperty::createEditor(QWidget *parent, const QObject *target, const char *receiver) const
 
917
{
 
918
    QDateEdit *lineEdit = new QDateEdit(parent);
 
919
    QObject::connect(lineEdit, SIGNAL(dateChanged(QDate)), target, receiver);
 
920
    return lineEdit;
 
921
}
 
922
 
 
923
void DateProperty::updateEditorContents(QWidget *editor)
 
924
{
 
925
    if (QDateEdit *lineEdit = qobject_cast<QDateEdit*>(editor)) {
 
926
        lineEdit->setDate(m_value);
 
927
    }
 
928
}
 
929
 
 
930
void DateProperty::updateValue(QWidget *editor)
 
931
{
 
932
    if (QDateEdit *lineEdit = qobject_cast<QDateEdit*>(editor)) {
 
933
        QDate newValue = lineEdit->date();
 
934
 
 
935
        if (newValue != m_value) {
 
936
            m_value = newValue;
 
937
            setChanged(true);
 
938
        }
 
939
 
 
940
    }
 
941
}
 
942
 
 
943
// -------------------------------------------------------------------------
 
944
TimeProperty::TimeProperty(const QTime &value, const QString &name)
 
945
    : AbstractProperty<QTime>(value, name)
 
946
{
 
947
}
 
948
 
 
949
void TimeProperty::setValue(const QVariant &value)
 
950
{
 
951
    m_value = value.toTime();
 
952
}
 
953
 
 
954
QString TimeProperty::toString() const
 
955
{
 
956
    return m_value.toString();
 
957
}
 
958
 
 
959
QWidget *TimeProperty::createEditor(QWidget *parent, const QObject *target, const char *receiver) const
 
960
{
 
961
    QTimeEdit *lineEdit = new QTimeEdit(parent);
 
962
    QObject::connect(lineEdit, SIGNAL(timeChanged(QTime)), target, receiver);
 
963
    return lineEdit;
 
964
}
 
965
 
 
966
void TimeProperty::updateEditorContents(QWidget *editor)
 
967
{
 
968
    if (QTimeEdit *lineEdit = qobject_cast<QTimeEdit*>(editor)) {
 
969
        lineEdit->setTime(m_value);
 
970
    }
 
971
}
 
972
 
 
973
void TimeProperty::updateValue(QWidget *editor)
 
974
{
 
975
    if (QTimeEdit *lineEdit = qobject_cast<QTimeEdit*>(editor)) {
 
976
        QTime newValue = lineEdit->time();
 
977
 
 
978
        if (newValue != m_value) {
 
979
            m_value = newValue;
 
980
            setChanged(true);
 
981
        }
 
982
 
 
983
    }
 
984
}
 
985
 
 
986
// -------------------------------------------------------------------------
 
987
CursorProperty::CursorProperty(const QCursor &value, const QString &name)
 
988
    : AbstractProperty<QCursor>(value, name)
 
989
{
 
990
}
 
991
 
 
992
void CursorProperty::setValue(const QVariant &value)
 
993
{
 
994
    m_value = qvariant_cast<QCursor>(value);
 
995
}
 
996
 
 
997
QString CursorProperty::toString() const
 
998
{
 
999
    return cursorName(m_value.shape());
 
1000
}
 
1001
 
 
1002
QVariant CursorProperty::decoration() const
 
1003
{
 
1004
    return qVariantFromValue(cursorPixmap(m_value.shape()));
 
1005
}
 
1006
 
 
1007
QWidget *CursorProperty::createEditor(QWidget *parent, const QObject *target, const char *receiver) const
 
1008
{
 
1009
    QComboBox *combo = new QComboBox(parent);
 
1010
    combo->view()->setTextElideMode(Qt::ElideLeft);
 
1011
    combo->setFrame(0);
 
1012
 
 
1013
    addCursor(combo, Qt::ArrowCursor);
 
1014
    addCursor(combo, Qt::UpArrowCursor);
 
1015
    addCursor(combo, Qt::CrossCursor);
 
1016
    addCursor(combo, Qt::WaitCursor);
 
1017
    addCursor(combo, Qt::IBeamCursor);
 
1018
    addCursor(combo, Qt::SizeVerCursor);
 
1019
    addCursor(combo, Qt::SizeHorCursor);
 
1020
    addCursor(combo, Qt::SizeBDiagCursor);
 
1021
    addCursor(combo, Qt::SizeFDiagCursor);
 
1022
    addCursor(combo, Qt::SizeAllCursor);
 
1023
    addCursor(combo, Qt::BlankCursor);
 
1024
    addCursor(combo, Qt::SplitVCursor);
 
1025
    addCursor(combo, Qt::SplitHCursor);
 
1026
    addCursor(combo, Qt::PointingHandCursor);
 
1027
    addCursor(combo, Qt::ForbiddenCursor);
 
1028
 
 
1029
    QObject::connect(combo, SIGNAL(activated(int)), target, receiver);
 
1030
 
 
1031
    return combo;
 
1032
}
 
1033
 
 
1034
void CursorProperty::updateEditorContents(QWidget *editor)
 
1035
{
 
1036
    if (QComboBox *combo = qobject_cast<QComboBox*>(editor)) {
 
1037
        combo->setCurrentIndex(m_value.shape());
 
1038
    }
 
1039
}
 
1040
 
 
1041
void CursorProperty::updateValue(QWidget *editor)
 
1042
{
 
1043
    if (QComboBox *combo = qobject_cast<QComboBox*>(editor)) {
 
1044
        QCursor newValue(static_cast<Qt::CursorShape>(combo->currentIndex()));
 
1045
 
 
1046
        if (newValue.shape() != m_value.shape()) {
 
1047
            m_value = newValue;
 
1048
            setChanged(true);
 
1049
        }
 
1050
    }
 
1051
}
 
1052
 
 
1053
QString CursorProperty::cursorName(int shape)
 
1054
{
 
1055
    switch (shape) {
 
1056
    case Qt::ArrowCursor: return QString::fromUtf8("Arrow");
 
1057
    case Qt::UpArrowCursor: return QString::fromUtf8("Up-Arrow");
 
1058
    case Qt::CrossCursor: return QString::fromUtf8("Cross");
 
1059
    case Qt::WaitCursor: return QString::fromUtf8("Waiting");
 
1060
    case Qt::IBeamCursor: return QString::fromUtf8("IBeam");
 
1061
    case Qt::SizeVerCursor: return QString::fromUtf8("Size Vertical");
 
1062
    case Qt::SizeHorCursor: return QString::fromUtf8("Size Horizontal");
 
1063
    case Qt::SizeBDiagCursor: return QString::fromUtf8("Size Slash");
 
1064
    case Qt::SizeFDiagCursor: return QString::fromUtf8("Size Backslash");
 
1065
    case Qt::SizeAllCursor: return QString::fromUtf8("Size All");
 
1066
    case Qt::BlankCursor: return QString::fromUtf8("Blank");
 
1067
    case Qt::SplitVCursor: return QString::fromUtf8("Split Vertical");
 
1068
    case Qt::SplitHCursor: return QString::fromUtf8("Split Horizontal");
 
1069
    case Qt::PointingHandCursor: return QString::fromUtf8("Pointing Hand");
 
1070
    case Qt::ForbiddenCursor: return QString::fromUtf8("Forbidden");
 
1071
    case Qt::WhatsThisCursor: return QString::fromUtf8("Whats This");
 
1072
    case Qt::BusyCursor: return QString::fromUtf8("Busy");
 
1073
    default: return QString();
 
1074
    }
 
1075
}
 
1076
 
 
1077
QPixmap CursorProperty::cursorPixmap(int shape)
 
1078
{
 
1079
    switch (shape) {
 
1080
    case Qt::ArrowCursor: return QPixmap(QString::fromUtf8(":/trolltech/formeditor/images/cursors/arrow.png"));
 
1081
    case Qt::UpArrowCursor: return QPixmap(QString::fromUtf8(":/trolltech/formeditor/images/cursors/uparrow.png"));
 
1082
    case Qt::CrossCursor: return QPixmap(QString::fromUtf8(":/trolltech/formeditor/images/cursors/cross.png"));
 
1083
    case Qt::WaitCursor: return QPixmap(QString::fromUtf8(":/trolltech/formeditor/images/cursors/wait.png"));
 
1084
    case Qt::IBeamCursor: return QPixmap(QString::fromUtf8(":/trolltech/formeditor/images/cursors/ibeam.png"));
 
1085
    case Qt::SizeVerCursor: return QPixmap(QString::fromUtf8(":/trolltech/formeditor/images/cursors/sizev.png"));
 
1086
    case Qt::SizeHorCursor: return QPixmap(QString::fromUtf8(":/trolltech/formeditor/images/cursors/sizeh.png"));
 
1087
    case Qt::SizeBDiagCursor: return QPixmap(QString::fromUtf8(":/trolltech/formeditor/images/cursors/sizef.png"));
 
1088
    case Qt::SizeFDiagCursor: return QPixmap(QString::fromUtf8(":/trolltech/formeditor/images/cursors/sizeb.png"));
 
1089
    case Qt::SizeAllCursor: return QPixmap(QString::fromUtf8(":/trolltech/formeditor/images/cursors/sizeall.png"));
 
1090
    case Qt::BlankCursor:
 
1091
    {
 
1092
        QBitmap cur = QBitmap(25, 25);
 
1093
        cur.clear();
 
1094
        return cur;
 
1095
    }
 
1096
    case Qt::SplitVCursor: return QPixmap(QString::fromUtf8(":/trolltech/formeditor/images/cursors/vsplit.png"));
 
1097
    case Qt::SplitHCursor: return QPixmap(QString::fromUtf8(":/trolltech/formeditor/images/cursors/hsplit.png"));
 
1098
    case Qt::PointingHandCursor: return QPixmap(QString::fromUtf8(":/trolltech/formeditor/images/cursors/hand.png"));
 
1099
    case Qt::ForbiddenCursor: return QPixmap(QString::fromUtf8(":/trolltech/formeditor/images/cursors/no.png"));
 
1100
    case Qt::WhatsThisCursor: return QPixmap(QString::fromUtf8(":/trolltech/formeditor/images/cursors/whatsthis.png"));
 
1101
    case Qt::BusyCursor: return QPixmap(QString::fromUtf8(":/trolltech/formeditor/images/cursors/busy.png"));
 
1102
    default: return QPixmap();
 
1103
    }
 
1104
}
 
1105
 
 
1106
void CursorProperty::addCursor(QComboBox *combo, int shape) const
 
1107
{
 
1108
    combo->addItem(cursorPixmap(shape), cursorName(shape), shape);
 
1109
}
 
1110
 
 
1111
// -------------------------------------------------------------------------
 
1112
AlignmentProperty::AlignmentProperty(const QMap<QString, QVariant> &items, Qt::Alignment value, const QString &name)
 
1113
    : AbstractPropertyGroup(name)
 
1114
{
 
1115
    QStringList horz_keys = QStringList()
 
1116
        << QString::fromUtf8("Qt::AlignLeft") << QString::fromUtf8("Qt::AlignRight")
 
1117
        << QString::fromUtf8("Qt::AlignHCenter") << QString::fromUtf8("Qt::AlignJustify"); // << "Qt::AlignAbsolute"
 
1118
 
 
1119
    QMap<QString, QVariant> horz_map;
 
1120
    foreach (QString h, horz_keys) {
 
1121
        horz_map.insert(h, items.value(h));
 
1122
    }
 
1123
 
 
1124
    MapProperty *ph = new MapProperty(horz_map, uint(value & Qt::AlignHorizontal_Mask), QLatin1String("horizontal"));
 
1125
    ph->setFake(true);
 
1126
    ph->setParent(this);
 
1127
    m_properties << ph;
 
1128
 
 
1129
 
 
1130
    QStringList vert_keys = QStringList()
 
1131
        << QString::fromUtf8("Qt::AlignTop") << QString::fromUtf8("Qt::AlignBottom") << QString::fromUtf8("Qt::AlignVCenter");
 
1132
 
 
1133
    QMap<QString, QVariant> vert_map;
 
1134
    foreach (QString h, vert_keys) {
 
1135
        vert_map.insert(h, items.value(h));
 
1136
    }
 
1137
 
 
1138
    MapProperty *pv = new MapProperty(vert_map, int(value & Qt::AlignVertical_Mask), QLatin1String("vertical"));
 
1139
    pv->setFake(true);
 
1140
    pv->setParent(this);
 
1141
    m_properties << pv;
 
1142
}
 
1143
 
 
1144
QVariant AlignmentProperty::value() const
 
1145
{
 
1146
    return uint(propertyAt(0)->value().toUInt() | propertyAt(1)->value().toUInt());
 
1147
}
 
1148
 
 
1149
void AlignmentProperty::setValue(const QVariant &value)
 
1150
{
 
1151
    propertyAt(0)->setValue(value.toUInt() & Qt::AlignHorizontal_Mask);
 
1152
    propertyAt(1)->setValue(value.toUInt() & Qt::AlignVertical_Mask);
 
1153
}
 
1154
 
 
1155
// -------------------------------------------------------------------------
 
1156
DoubleProperty::DoubleProperty(double value, const QString &name)
 
1157
    : AbstractProperty<double>(value, name)
 
1158
{
 
1159
}
 
1160
 
 
1161
void DoubleProperty::setValue(const QVariant &value)
 
1162
{
 
1163
    m_value = value.toDouble();
 
1164
}
 
1165
 
 
1166
QString DoubleProperty::toString() const
 
1167
{
 
1168
    return QString::number(m_value);
 
1169
}
 
1170
 
 
1171
QWidget *DoubleProperty::createEditor(QWidget *parent, const QObject *target, const char *receiver) const
 
1172
{
 
1173
    QLineEdit *lineEdit = new QLineEdit(parent);
 
1174
    lineEdit->setFrame(0);
 
1175
    lineEdit->setValidator(new QDoubleValidator(lineEdit));
 
1176
 
 
1177
    QObject::connect(lineEdit, SIGNAL(textChanged(QString)), target, receiver);
 
1178
    return lineEdit;
 
1179
}
 
1180
 
 
1181
void DoubleProperty::updateEditorContents(QWidget *editor)
 
1182
{
 
1183
    if (QLineEdit *lineEdit = qobject_cast<QLineEdit*>(editor)) {
 
1184
        double v = lineEdit->text().toDouble();
 
1185
        if (v != m_value)
 
1186
            lineEdit->setText(QString::number(m_value));
 
1187
    }
 
1188
}
 
1189
 
 
1190
void DoubleProperty::updateValue(QWidget *editor)
 
1191
{
 
1192
    if (QLineEdit *lineEdit = qobject_cast<QLineEdit*>(editor)) {
 
1193
        double newValue = lineEdit->text().toDouble();
 
1194
 
 
1195
        if (newValue != m_value) {
 
1196
            m_value = newValue;
 
1197
            setChanged(true);
 
1198
        }
 
1199
 
 
1200
    }
 
1201
}
 
1202
 
 
1203
// -------------------------------------------------------------------------
 
1204
PaletteProperty::PaletteProperty(const QPalette &value, const QString &name)
 
1205
    : AbstractProperty<QPalette>(value, name)
 
1206
{
 
1207
}
 
1208
 
 
1209
void PaletteProperty::setValue(const QVariant &value)
 
1210
{
 
1211
    m_value = qvariant_cast<QPalette>(value);
 
1212
}
 
1213
 
 
1214
QString PaletteProperty::toString() const
 
1215
{
 
1216
    return QString(); // ### implement me
 
1217
}
 
1218
 
 
1219
QWidget *PaletteProperty::createEditor(QWidget *parent, const QObject *target, const char *receiver) const
 
1220
{
 
1221
    PaletteEditorButton *btn = new PaletteEditorButton(m_value, parent);
 
1222
    QObject::connect(btn, SIGNAL(changed()), target, receiver);
 
1223
    return btn;
 
1224
}
 
1225
 
 
1226
void PaletteProperty::updateEditorContents(QWidget *editor)
 
1227
{
 
1228
    if (PaletteEditorButton *btn = qobject_cast<PaletteEditorButton*>(editor)) {
 
1229
        btn->setPalette(m_value);
 
1230
    }
 
1231
}
 
1232
 
 
1233
void PaletteProperty::updateValue(QWidget *editor)
 
1234
{
 
1235
    if (PaletteEditorButton *btn = qobject_cast<PaletteEditorButton*>(editor)) {
 
1236
        QPalette newValue = btn->palette();
 
1237
 
 
1238
        if (newValue != m_value) {
 
1239
            m_value = newValue;
 
1240
            setChanged(true);
 
1241
        }
 
1242
    }
 
1243
}
 
1244
 
 
1245
// -------------------------------------------------------------------------
 
1246
SeparatorProperty::SeparatorProperty(const QString &value, const QString &name)
 
1247
    : StringProperty(value, name)
 
1248
{
 
1249
}
 
1250
 
 
1251
QWidget *SeparatorProperty::createEditor(QWidget *parent, const QObject *target, const char *receiver) const
 
1252
{
 
1253
    Q_UNUSED(parent);
 
1254
    Q_UNUSED(target);
 
1255
    Q_UNUSED(receiver);
 
1256
    return 0;
 
1257
}
 
1258
 
 
1259
bool SeparatorProperty::hasEditor() const
 
1260
{ return false; }
 
1261
 
 
1262
void SeparatorProperty::updateEditorContents(QWidget *editor)
 
1263
{ Q_UNUSED(editor); }
 
1264
 
 
1265
void SeparatorProperty::updateValue(QWidget *editor)
 
1266
{ Q_UNUSED(editor); }