1
/****************************************************************************
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
5
** This file is part of the designer application of the Qt Toolkit.
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.
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.
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.
21
** Contact info@trolltech.com if any conditions of this licensing are
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.
27
****************************************************************************/
29
#include "qpropertyeditor_items_p.h"
30
#include "flagbox_p.h"
31
#include "paletteeditorbutton.h"
34
#include <QtDesigner/propertysheet.h>
36
#include <qdesigner_utils_p.h>
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>
49
#include <QtCore/qdebug.h>
52
using namespace qdesigner_internal;
54
Q_GLOBAL_STATIC(QFontDatabase, fontDatabase)
56
void IProperty::setDirty(bool b)
59
IProperty *p = parent();
60
while (p != 0 && p->isFake())
69
void IProperty::setChanged(bool b)
72
IProperty *p = parent();
73
while (p != 0 && p->isFake())
83
// -------------------------------------------------------------------------
85
QWidget *AbstractPropertyGroup::createEditor(QWidget *parent, const QObject *target, const char *receiver) const
90
QLabel *label = new QLabel(parent);
91
label->setIndent(2); // ### hardcode it should have the same value of textMargin in QItemDelegate
95
void AbstractPropertyGroup::updateEditorContents(QWidget *editor)
97
QLabel *label = qobject_cast<QLabel*>(editor);
100
label->setText(toString());
103
// -------------------------------------------------------------------------
104
BoolProperty::BoolProperty(bool value, const QString &name)
105
: AbstractProperty<bool>(value, name)
109
void BoolProperty::setValue(const QVariant &value)
111
m_value = value.toBool();
114
QString BoolProperty::toString() const
116
return m_value ? QLatin1String("true") : QLatin1String("false");
119
QWidget *BoolProperty::createEditor(QWidget *parent, const QObject *target, const char *receiver) const
121
QComboBox *combo = new QComboBox(parent);
122
combo->view()->setTextElideMode(Qt::ElideLeft);
124
combo->addItems(QStringList() << QString::fromUtf8("false") << QString::fromUtf8("true"));
125
QObject::connect(combo, SIGNAL(activated(int)), target, receiver);
130
void BoolProperty::updateEditorContents(QWidget *editor)
132
if (QComboBox *combo = qobject_cast<QComboBox*>(editor)) {
133
combo->setCurrentIndex(m_value ? 1 : 0);
137
void BoolProperty::updateValue(QWidget *editor)
139
if (QComboBox *combo = qobject_cast<QComboBox*>(editor)) {
140
bool newValue = combo->currentIndex() ? true : false;
142
if (newValue != m_value) {
149
// -------------------------------------------------------------------------
150
PointProperty::PointProperty(const QPoint &value, const QString &name)
151
: AbstractPropertyGroup(name)
153
IProperty *px = new IntProperty(value.x(), QLatin1String("x"));
157
IProperty *py = new IntProperty(value.y(), QLatin1String("y"));
161
m_properties << px << py;
164
QVariant PointProperty::value() const
166
return QPoint(propertyAt(0)->value().toInt(),
167
propertyAt(1)->value().toInt());
170
void PointProperty::setValue(const QVariant &value)
172
QPoint pt = value.toPoint();
173
propertyAt(0)->setValue(pt.x());
174
propertyAt(1)->setValue(pt.y());
177
// -------------------------------------------------------------------------
178
PropertyCollection::PropertyCollection(const QString &name)
183
PropertyCollection::~PropertyCollection()
185
qDeleteAll(m_properties);
188
void PropertyCollection::addProperty(IProperty *property)
190
property->setParent(this);
191
m_properties.append(property);
194
void PropertyCollection::removeProperty(IProperty *property)
199
int PropertyCollection::indexOf(IProperty *property) const
201
return m_properties.indexOf(property);
204
int PropertyCollection::propertyCount() const
206
return m_properties.size();
209
IProperty *PropertyCollection::propertyAt(int index) const
211
return m_properties.at(index);
214
QString PropertyCollection::propertyName() const
219
QVariant PropertyCollection::value() const
224
void PropertyCollection::setValue(const QVariant &value)
229
QString PropertyCollection::toString() const
234
bool PropertyCollection::hasEditor() const
239
QWidget *PropertyCollection::createEditor(QWidget *parent, const QObject *target, const char *receiver) const
247
bool PropertyCollection::hasExternalEditor() const
252
QWidget *PropertyCollection::createExternalEditor(QWidget *parent)
258
// -------------------------------------------------------------------------
260
StringProperty::StringProperty(const QString &value, const QString &name)
261
: AbstractProperty<QString>(value, name)
265
void StringProperty::setValue(const QVariant &value)
267
m_value = value.toString();
270
QString StringProperty::toString() const
275
QWidget *StringProperty::createEditor(QWidget *parent, const QObject *target, const char *receiver) const
277
QLineEdit *lineEdit = new QLineEdit(parent);
278
lineEdit->setFrame(0);
280
if (propertyName() == QLatin1String("objectName")) {
281
lineEdit->setValidator(new QRegExpValidator(QRegExp(QLatin1String("[_a-zA-Z][_a-zA-Z0-9]*")), lineEdit));
284
QObject::connect(lineEdit, SIGNAL(textChanged(QString)), target, receiver);
288
void StringProperty::updateEditorContents(QWidget *editor)
290
if (QLineEdit *lineEdit = qobject_cast<QLineEdit*>(editor)) {
291
if (lineEdit->text() != m_value)
292
lineEdit->setText(m_value);
296
void StringProperty::updateValue(QWidget *editor)
298
if (QLineEdit *lineEdit = qobject_cast<QLineEdit*>(editor)) {
299
QString newValue = lineEdit->text();
301
if (newValue != m_value) {
310
// -------------------------------------------------------------------------
311
ListProperty::ListProperty(const QStringList &items, int value, const QString &name)
312
: AbstractProperty<int>(value, name), m_items(items)
316
QStringList ListProperty::items() const
321
void ListProperty::setValue(const QVariant &value)
323
m_value = value.toInt();
326
QString ListProperty::toString() const
328
if (m_items.isEmpty())
330
else if (m_value < 0 || m_value >= m_items.count())
331
return m_items.first();
333
return m_items.at(m_value);
336
QWidget *ListProperty::createEditor(QWidget *parent, const QObject *target, const char *receiver) const
338
QComboBox *combo = new QComboBox(parent);
339
combo->view()->setTextElideMode(Qt::ElideLeft);
342
combo->addItems(items());
343
QObject::connect(combo, SIGNAL(activated(int)), target, receiver);
347
void ListProperty::updateEditorContents(QWidget *editor)
349
if (QComboBox *combo = qobject_cast<QComboBox*>(editor)) {
350
combo->setCurrentIndex(m_value);
354
void ListProperty::updateValue(QWidget *editor)
356
if (QComboBox *combo = qobject_cast<QComboBox*>(editor)) {
357
int newValue = combo->currentIndex();
359
if (newValue != m_value) {
366
// -------------------------------------------------------------------------
367
SizeProperty::SizeProperty(const QSize &value, const QString &name)
368
: AbstractPropertyGroup(name)
370
IntProperty *pw = new IntProperty(value.width(), QLatin1String("width"));
373
pw->setRange(0, INT_MAX);
375
IntProperty *ph = new IntProperty(value.height(), QLatin1String("height"));
378
ph->setRange(0, INT_MAX);
380
m_properties << pw << ph;
383
QVariant SizeProperty::value() const
385
return QSize(propertyAt(0)->value().toInt(),
386
propertyAt(1)->value().toInt());
389
void SizeProperty::setValue(const QVariant &value)
391
QSize pt = value.toSize();
392
propertyAt(0)->setValue(pt.width());
393
propertyAt(1)->setValue(pt.height());
396
// -------------------------------------------------------------------------
397
IntProperty::IntProperty(int value, const QString &name)
398
: AbstractProperty<int>(value, name), m_low(INT_MIN), m_hi(INT_MAX)
402
void IntProperty::setRange(int low, int hi)
408
QString IntProperty::specialValue() const
410
return m_specialValue;
413
void IntProperty::setSpecialValue(const QString &specialValue)
415
m_specialValue = specialValue;
418
void IntProperty::setValue(const QVariant &value)
420
m_value = value.toInt();
423
QString IntProperty::toString() const
425
return QString::number(m_value);
428
QWidget *IntProperty::createEditor(QWidget *parent, const QObject *target, const char *receiver) const
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();
437
QObject::connect(spinBox, SIGNAL(valueChanged(int)), target, receiver);
442
void IntProperty::updateEditorContents(QWidget *editor)
444
if (QSpinBox *spinBox = qobject_cast<QSpinBox*>(editor)) {
445
spinBox->setValue(m_value);
449
void IntProperty::updateValue(QWidget *editor)
451
if (QSpinBox *spinBox = qobject_cast<QSpinBox*>(editor)) {
452
int newValue = spinBox->value();
454
if (newValue != m_value) {
461
// -------------------------------------------------------------------------
462
RectProperty::RectProperty(const QRect &value, const QString &name)
463
: AbstractPropertyGroup(name)
465
IntProperty *px = new IntProperty(value.x(), QLatin1String("x"));
469
IntProperty *py = new IntProperty(value.y(), QLatin1String("y"));
473
IntProperty *pw = new IntProperty(value.width(), QLatin1String("width"));
476
pw->setRange(0, INT_MAX);
478
IntProperty *ph = new IntProperty(value.height(), QLatin1String("height"));
481
ph->setRange(0, INT_MAX);
483
m_properties << px << py << pw << ph;
486
QVariant RectProperty::value() const
488
return QRect(propertyAt(0)->value().toInt(),
489
propertyAt(1)->value().toInt(),
490
propertyAt(2)->value().toInt(),
491
propertyAt(3)->value().toInt());
494
void RectProperty::setValue(const QVariant &value)
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());
504
// -------------------------------------------------------------------------
505
ColorProperty::ColorProperty(const QColor &value, const QString &name)
506
: AbstractPropertyGroup(name)
508
IntProperty *r = new IntProperty(value.red(), QLatin1String("red"));
513
IntProperty *g = new IntProperty(value.green(), QLatin1String("green"));
518
IntProperty *b = new IntProperty(value.blue(), QLatin1String("blue"));
523
m_properties << r << g << b;
526
QVariant ColorProperty::value() const
528
return qVariantFromValue(QColor(propertyAt(0)->value().toInt(),
529
propertyAt(1)->value().toInt(),
530
propertyAt(2)->value().toInt()));
533
void ColorProperty::setValue(const QVariant &value)
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());
541
QVariant ColorProperty::decoration() const
544
pix.fill(qvariant_cast<QColor>(value()));
545
return qVariantFromValue(pix);
548
// -------------------------------------------------------------------------
549
FontProperty::FontProperty(const QFont &value, const QString &name)
550
: AbstractPropertyGroup(name)
552
QStringList fonts = fontDatabase()->families();
553
int index = fonts.indexOf(value.family());
558
i = new ListProperty(fonts, index, QLatin1String("Family"));
563
IntProperty *ii = new IntProperty(value.pointSize(), QLatin1String("Point Size"));
565
ii->setRange(1, INT_MAX); // ### check
569
i = new BoolProperty(value.bold(), QLatin1String("Bold"));
574
i = new BoolProperty(value.italic(), QLatin1String("Italic"));
579
i = new BoolProperty(value.underline(), QLatin1String("Underline"));
584
i = new BoolProperty(value.strikeOut(), QLatin1String("Strikeout"));
590
QVariant FontProperty::value() const
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());
600
return qVariantFromValue(fnt);
603
void FontProperty::setValue(const QVariant &value)
605
QFont fnt = qvariant_cast<QFont>(value);
607
int family = fontDatabase()->families().indexOf(fnt.family());
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());
617
QVariant FontProperty::decoration() const
622
QFont fnt = qvariant_cast<QFont>(value());
623
fnt.setPointSize(10); // ### always 10pt!!
624
p.drawRect(0, 0, 16, 16);
626
p.drawText(0, 16 - 2, QLatin1String("Aa")); // ### 2px for the border!!
627
return qVariantFromValue(pix);
630
QString FontProperty::toString() const
632
QString family = propertyAt(0)->toString();
633
QString pointSize = propertyAt(1)->value().toString();
635
return QLatin1String(" ") // ### temp hack
636
+ QLatin1String("[") + family + QLatin1String(", ") + pointSize + QLatin1String("]");
639
// -------------------------------------------------------------------------
640
MapProperty::MapProperty(const QMap<QString, QVariant> &items,
641
const QVariant &value,
643
: AbstractProperty<QVariant>(value, name),
645
m_keys(m_items.keys())
649
QStringList MapProperty::keys() const
654
QMap<QString, QVariant> MapProperty::items() const
659
QVariant MapProperty::value() const
664
void MapProperty::setValue(const QVariant &value)
666
if (qVariantCanConvert<EnumType>(value)) {
667
EnumType e = qvariant_cast<EnumType>(value);
674
QString MapProperty::toString() const
676
return m_items.key(m_value);
679
int MapProperty::indexOf(const QVariant &value) const
681
QString key = m_items.key(value);
682
return m_keys.indexOf(key);
685
QWidget *MapProperty::createEditor(QWidget *parent, const QObject *target, const char *receiver) const
687
QComboBox *combo = new QComboBox(parent);
688
combo->view()->setTextElideMode(Qt::ElideLeft);
691
combo->addItems(m_keys);
692
QObject::connect(combo, SIGNAL(activated(int)), target, receiver);
697
void MapProperty::updateEditorContents(QWidget *editor)
699
if (QComboBox *combo = qobject_cast<QComboBox*>(editor)) {
700
combo->setCurrentIndex(indexOf(m_value));
704
void MapProperty::updateValue(QWidget *editor)
706
if (QComboBox *combo = qobject_cast<QComboBox*>(editor)) {
707
QString key = combo->currentText();
708
QVariant newValue = m_items.value(key);
710
if (newValue != m_value) {
717
// -------------------------------------------------------------------------
718
FlagsProperty::FlagsProperty(const QMap<QString, QVariant> &items, unsigned int value,
720
: MapProperty(items, QVariant(value), name)
724
QWidget *FlagsProperty::createEditor(QWidget *parent, const QObject *target, const char *receiver) const
726
QList<FlagBoxModelItem> l;
727
QMapIterator<QString, QVariant> it(items());
728
while (it.hasNext()) {
730
l.append(FlagBoxModelItem(it.key(), it.value().toUInt(), /*checked=*/false));
733
FlagBox *editor = new FlagBox(parent);
735
QObject::connect(editor, SIGNAL(activated(int)), target, receiver);
739
void FlagsProperty::updateEditorContents(QWidget *editor)
741
FlagBox *box = qobject_cast<FlagBox*>(editor);
745
unsigned int v = m_value.toUInt();
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);
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);
761
if (!foundPerfectMatch) {
763
for (int i=0; i<box->count(); ++i) {
764
FlagBoxModelItem &item = box->item(i);
765
item.setChecked((item.value() & v) == item.value());
769
box->view()->reset();
772
void FlagsProperty::updateValue(QWidget *editor)
774
FlagBox *box = qobject_cast<FlagBox*>(editor);
778
unsigned int newValue = 0;
780
for (int i=0; i<box->count(); ++i) {
781
FlagBoxModelItem &item = box->item(i);
782
if (item.isChecked())
783
newValue |= item.value();
786
if (newValue != m_value) {
792
// -------------------------------------------------------------------------
793
SizePolicyProperty::SizePolicyProperty(const QSizePolicy &value, const QString &name)
794
: AbstractPropertyGroup(name)
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");
806
i = new ListProperty(lst, size_type_to_int(value.horizontalPolicy()), QLatin1String("hSizeType"));
811
i = new ListProperty(lst, size_type_to_int(value.verticalPolicy()), QLatin1String("vSizeType"));
816
i = new IntProperty(value.horizontalStretch(), QLatin1String("horizontalStretch"));
821
i = new IntProperty(value.verticalStretch(), QLatin1String("verticalStretch"));
827
QVariant SizePolicyProperty::value() const
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);
837
void SizePolicyProperty::setValue(const QVariant &value)
839
QSizePolicy sizePolicy = qvariant_cast<QSizePolicy>(value);
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());
847
QVariant SizePolicyProperty::decoration() const
852
QString SizePolicyProperty::toString() const
854
return AbstractPropertyGroup::toString();
857
// -------------------------------------------------------------------------
858
DateTimeProperty::DateTimeProperty(const QDateTime &value, const QString &name)
859
: AbstractProperty<QDateTime>(value, name)
863
void DateTimeProperty::setValue(const QVariant &value)
865
m_value = value.toDateTime();
868
QString DateTimeProperty::toString() const
870
return m_value.toString();
873
QWidget *DateTimeProperty::createEditor(QWidget *parent, const QObject *target, const char *receiver) const
875
QDateTimeEdit *lineEdit = new QDateTimeEdit(parent);
876
QObject::connect(lineEdit, SIGNAL(dateTimeChanged(QDateTime)), target, receiver);
880
void DateTimeProperty::updateEditorContents(QWidget *editor)
882
if (QDateTimeEdit *lineEdit = qobject_cast<QDateTimeEdit*>(editor)) {
883
lineEdit->setDateTime(m_value);
887
void DateTimeProperty::updateValue(QWidget *editor)
889
if (QDateTimeEdit *lineEdit = qobject_cast<QDateTimeEdit*>(editor)) {
890
QDateTime newValue = lineEdit->dateTime();
892
if (newValue != m_value) {
900
// -------------------------------------------------------------------------
901
DateProperty::DateProperty(const QDate &value, const QString &name)
902
: AbstractProperty<QDate>(value, name)
906
void DateProperty::setValue(const QVariant &value)
908
m_value = value.toDate();
911
QString DateProperty::toString() const
913
return m_value.toString();
916
QWidget *DateProperty::createEditor(QWidget *parent, const QObject *target, const char *receiver) const
918
QDateEdit *lineEdit = new QDateEdit(parent);
919
QObject::connect(lineEdit, SIGNAL(dateChanged(QDate)), target, receiver);
923
void DateProperty::updateEditorContents(QWidget *editor)
925
if (QDateEdit *lineEdit = qobject_cast<QDateEdit*>(editor)) {
926
lineEdit->setDate(m_value);
930
void DateProperty::updateValue(QWidget *editor)
932
if (QDateEdit *lineEdit = qobject_cast<QDateEdit*>(editor)) {
933
QDate newValue = lineEdit->date();
935
if (newValue != m_value) {
943
// -------------------------------------------------------------------------
944
TimeProperty::TimeProperty(const QTime &value, const QString &name)
945
: AbstractProperty<QTime>(value, name)
949
void TimeProperty::setValue(const QVariant &value)
951
m_value = value.toTime();
954
QString TimeProperty::toString() const
956
return m_value.toString();
959
QWidget *TimeProperty::createEditor(QWidget *parent, const QObject *target, const char *receiver) const
961
QTimeEdit *lineEdit = new QTimeEdit(parent);
962
QObject::connect(lineEdit, SIGNAL(timeChanged(QTime)), target, receiver);
966
void TimeProperty::updateEditorContents(QWidget *editor)
968
if (QTimeEdit *lineEdit = qobject_cast<QTimeEdit*>(editor)) {
969
lineEdit->setTime(m_value);
973
void TimeProperty::updateValue(QWidget *editor)
975
if (QTimeEdit *lineEdit = qobject_cast<QTimeEdit*>(editor)) {
976
QTime newValue = lineEdit->time();
978
if (newValue != m_value) {
986
// -------------------------------------------------------------------------
987
CursorProperty::CursorProperty(const QCursor &value, const QString &name)
988
: AbstractProperty<QCursor>(value, name)
992
void CursorProperty::setValue(const QVariant &value)
994
m_value = qvariant_cast<QCursor>(value);
997
QString CursorProperty::toString() const
999
return cursorName(m_value.shape());
1002
QVariant CursorProperty::decoration() const
1004
return qVariantFromValue(cursorPixmap(m_value.shape()));
1007
QWidget *CursorProperty::createEditor(QWidget *parent, const QObject *target, const char *receiver) const
1009
QComboBox *combo = new QComboBox(parent);
1010
combo->view()->setTextElideMode(Qt::ElideLeft);
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);
1029
QObject::connect(combo, SIGNAL(activated(int)), target, receiver);
1034
void CursorProperty::updateEditorContents(QWidget *editor)
1036
if (QComboBox *combo = qobject_cast<QComboBox*>(editor)) {
1037
combo->setCurrentIndex(m_value.shape());
1041
void CursorProperty::updateValue(QWidget *editor)
1043
if (QComboBox *combo = qobject_cast<QComboBox*>(editor)) {
1044
QCursor newValue(static_cast<Qt::CursorShape>(combo->currentIndex()));
1046
if (newValue.shape() != m_value.shape()) {
1053
QString CursorProperty::cursorName(int 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();
1077
QPixmap CursorProperty::cursorPixmap(int 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:
1092
QBitmap cur = QBitmap(25, 25);
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();
1106
void CursorProperty::addCursor(QComboBox *combo, int shape) const
1108
combo->addItem(cursorPixmap(shape), cursorName(shape), shape);
1111
// -------------------------------------------------------------------------
1112
AlignmentProperty::AlignmentProperty(const QMap<QString, QVariant> &items, Qt::Alignment value, const QString &name)
1113
: AbstractPropertyGroup(name)
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"
1119
QMap<QString, QVariant> horz_map;
1120
foreach (QString h, horz_keys) {
1121
horz_map.insert(h, items.value(h));
1124
MapProperty *ph = new MapProperty(horz_map, uint(value & Qt::AlignHorizontal_Mask), QLatin1String("horizontal"));
1126
ph->setParent(this);
1130
QStringList vert_keys = QStringList()
1131
<< QString::fromUtf8("Qt::AlignTop") << QString::fromUtf8("Qt::AlignBottom") << QString::fromUtf8("Qt::AlignVCenter");
1133
QMap<QString, QVariant> vert_map;
1134
foreach (QString h, vert_keys) {
1135
vert_map.insert(h, items.value(h));
1138
MapProperty *pv = new MapProperty(vert_map, int(value & Qt::AlignVertical_Mask), QLatin1String("vertical"));
1140
pv->setParent(this);
1144
QVariant AlignmentProperty::value() const
1146
return uint(propertyAt(0)->value().toUInt() | propertyAt(1)->value().toUInt());
1149
void AlignmentProperty::setValue(const QVariant &value)
1151
propertyAt(0)->setValue(value.toUInt() & Qt::AlignHorizontal_Mask);
1152
propertyAt(1)->setValue(value.toUInt() & Qt::AlignVertical_Mask);
1155
// -------------------------------------------------------------------------
1156
DoubleProperty::DoubleProperty(double value, const QString &name)
1157
: AbstractProperty<double>(value, name)
1161
void DoubleProperty::setValue(const QVariant &value)
1163
m_value = value.toDouble();
1166
QString DoubleProperty::toString() const
1168
return QString::number(m_value);
1171
QWidget *DoubleProperty::createEditor(QWidget *parent, const QObject *target, const char *receiver) const
1173
QLineEdit *lineEdit = new QLineEdit(parent);
1174
lineEdit->setFrame(0);
1175
lineEdit->setValidator(new QDoubleValidator(lineEdit));
1177
QObject::connect(lineEdit, SIGNAL(textChanged(QString)), target, receiver);
1181
void DoubleProperty::updateEditorContents(QWidget *editor)
1183
if (QLineEdit *lineEdit = qobject_cast<QLineEdit*>(editor)) {
1184
double v = lineEdit->text().toDouble();
1186
lineEdit->setText(QString::number(m_value));
1190
void DoubleProperty::updateValue(QWidget *editor)
1192
if (QLineEdit *lineEdit = qobject_cast<QLineEdit*>(editor)) {
1193
double newValue = lineEdit->text().toDouble();
1195
if (newValue != m_value) {
1203
// -------------------------------------------------------------------------
1204
PaletteProperty::PaletteProperty(const QPalette &value, const QString &name)
1205
: AbstractProperty<QPalette>(value, name)
1209
void PaletteProperty::setValue(const QVariant &value)
1211
m_value = qvariant_cast<QPalette>(value);
1214
QString PaletteProperty::toString() const
1216
return QString(); // ### implement me
1219
QWidget *PaletteProperty::createEditor(QWidget *parent, const QObject *target, const char *receiver) const
1221
PaletteEditorButton *btn = new PaletteEditorButton(m_value, parent);
1222
QObject::connect(btn, SIGNAL(changed()), target, receiver);
1226
void PaletteProperty::updateEditorContents(QWidget *editor)
1228
if (PaletteEditorButton *btn = qobject_cast<PaletteEditorButton*>(editor)) {
1229
btn->setPalette(m_value);
1233
void PaletteProperty::updateValue(QWidget *editor)
1235
if (PaletteEditorButton *btn = qobject_cast<PaletteEditorButton*>(editor)) {
1236
QPalette newValue = btn->palette();
1238
if (newValue != m_value) {
1245
// -------------------------------------------------------------------------
1246
SeparatorProperty::SeparatorProperty(const QString &value, const QString &name)
1247
: StringProperty(value, name)
1251
QWidget *SeparatorProperty::createEditor(QWidget *parent, const QObject *target, const char *receiver) const
1259
bool SeparatorProperty::hasEditor() const
1262
void SeparatorProperty::updateEditorContents(QWidget *editor)
1263
{ Q_UNUSED(editor); }
1265
void SeparatorProperty::updateValue(QWidget *editor)
1266
{ Q_UNUSED(editor); }