1 // ****************************************************************************************
3 // QPropertyEditor Library
4 // --------------------------------------
5 // Copyright (C) 2007 Volker Wiendl
7 // This file is part of the Horde3D Scene Editor.
9 // The QPropertyEditor Library is free software; you can redistribute it and/or modify
10 // it under the terms of the GNU General Public License as published by
11 // the Free Software Foundation version 3 of the License
13 // The Horde3D Scene Editor is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program. If not, see <http://www.gnu.org/licenses/>.
21 // ****************************************************************************************
24 #include "ColorCombo.h"
26 #include <Qt/qmetaobject.h>
27 #include <Qt/qspinbox.h>
31 Property::Property(const QString
& name
/*= QString()*/, QObject
* propertyObject
/*= 0*/, QObject
* parent
/*= 0*/) : QObject(parent
),
32 m_propertyObject(propertyObject
) {
36 QVariant
Property::value(int /*role = Qt::UserRole*/) const {
38 return m_propertyObject
->property(qPrintable(objectName()));
43 void Property::setValue(const QVariant
&value
) {
45 m_propertyObject
->setProperty(qPrintable(objectName()), value
);
48 bool Property::isReadOnly() {
49 if (m_propertyObject
&& m_propertyObject
->metaObject()->property(m_propertyObject
->metaObject()->indexOfProperty(qPrintable(objectName()))).isWritable())
55 QWidget
* Property::createEditor(QWidget
*parent
, const QStyleOptionViewItem
&option
) {
58 switch (value().type()) {
60 editor
= new ColorCombo(parent
);
63 editor
= new QSpinBox(parent
);
64 editor
->setProperty("minimum", -INT_MAX
);
65 editor
->setProperty("maximum", INT_MAX
);
66 connect(editor
, SIGNAL(valueChanged(int)), this, SLOT(setValue(int)));
68 case QMetaType::Float
:
69 case QVariant::Double
:
70 editor
= new QDoubleSpinBox(parent
);
71 editor
->setProperty("minimum", -INT_MAX
);
72 editor
->setProperty("maximum", INT_MAX
);
73 connect(editor
, SIGNAL(valueChanged(double)), this, SLOT(setValue(double)));
81 bool Property::setEditorData(QWidget
*editor
, const QVariant
&data
) {
82 switch (value().type()) {
84 static_cast<ColorCombo
*>(editor
)->setColor(data
.value
<QColor
>());
88 editor
->blockSignals(true);
89 static_cast<QSpinBox
*>(editor
)->setValue(data
.toInt());
90 editor
->blockSignals(false);
92 case QMetaType::Float
:
93 case QVariant::Double
:
94 editor
->blockSignals(true);
95 static_cast<QDoubleSpinBox
*>(editor
)->setValue(data
.toDouble());
96 editor
->blockSignals(false);
104 QVariant
Property::editorData(QWidget
*editor
) {
105 switch (value().type()) {
106 case QVariant::Color
:
107 return QVariant::fromValue(static_cast<ColorCombo
*>(editor
)->color());
109 return QVariant(static_cast<QSpinBox
*>(editor
)->value());
110 case QMetaType::Float
:
111 case QVariant::Double
:
112 return QVariant(static_cast<QDoubleSpinBox
*>(editor
)->value());
119 Property
* Property::findPropertyObject(QObject
* propertyObject
) {
120 if (m_propertyObject
== propertyObject
)
122 for (int i
=0; i
<children().size(); ++i
) {
123 Property
* child
= static_cast<Property
*>(children()[i
])->findPropertyObject(propertyObject
);
130 void Property::setValue(double value
) {
131 setValue(QVariant(value
));
134 void Property::setValue(int value
) {
135 setValue(QVariant(value
));