diff options
| author | Frank Gevaerts <frank@gevaerts.be> | 2008-08-29 21:08:38 +0000 |
|---|---|---|
| committer | Frank Gevaerts <frank@gevaerts.be> | 2008-08-29 21:08:38 +0000 |
| commit | 5d22e3cbdd251819a4d2d07b9a12994d5aef778d (patch) | |
| tree | 4c6a81187ccf065a5f296a903b9f7da88503e403 /utils/wpseditor/gui/src/QPropertyEditor/Property.cpp | |
| parent | cc31b1fbdae455f975b69dd6bffc23d8bd021566 (diff) | |
| download | rockbox-5d22e3cbdd251819a4d2d07b9a12994d5aef778d.zip rockbox-5d22e3cbdd251819a4d2d07b9a12994d5aef778d.tar.gz rockbox-5d22e3cbdd251819a4d2d07b9a12994d5aef778d.tar.bz2 rockbox-5d22e3cbdd251819a4d2d07b9a12994d5aef778d.tar.xz | |
Add wpseditor, the Google Summer of Code 2008 project of Rostislav Chekan. Closes FS#9327
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@18362 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'utils/wpseditor/gui/src/QPropertyEditor/Property.cpp')
| -rw-r--r-- | utils/wpseditor/gui/src/QPropertyEditor/Property.cpp | 136 |
1 files changed, 136 insertions, 0 deletions
diff --git a/utils/wpseditor/gui/src/QPropertyEditor/Property.cpp b/utils/wpseditor/gui/src/QPropertyEditor/Property.cpp new file mode 100644 index 0000000..0746d15 --- /dev/null +++ b/utils/wpseditor/gui/src/QPropertyEditor/Property.cpp @@ -0,0 +1,136 @@ +// **************************************************************************************** +// +// QPropertyEditor Library +// -------------------------------------- +// Copyright (C) 2007 Volker Wiendl +// +// This file is part of the Horde3D Scene Editor. +// +// The QPropertyEditor Library is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation version 3 of the License +// +// The Horde3D Scene Editor is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see <http://www.gnu.org/licenses/>. +// +// **************************************************************************************** + +#include "Property.h" +#include "ColorCombo.h" + +#include <Qt/qmetaobject.h> +#include <Qt/qspinbox.h> + +#include <limits.h> + +Property::Property(const QString& name /*= QString()*/, QObject* propertyObject /*= 0*/, QObject* parent /*= 0*/) : QObject(parent), + m_propertyObject(propertyObject) { + setObjectName(name); +} + +QVariant Property::value(int /*role = Qt::UserRole*/) const { + if (m_propertyObject) + return m_propertyObject->property(qPrintable(objectName())); + else + return QVariant(); +} + +void Property::setValue(const QVariant &value) { + if (m_propertyObject) + m_propertyObject->setProperty(qPrintable(objectName()), value); +} + +bool Property::isReadOnly() { + if (m_propertyObject && m_propertyObject->metaObject()->property(m_propertyObject->metaObject()->indexOfProperty(qPrintable(objectName()))).isWritable()) + return false; + else + return true; +} + +QWidget* Property::createEditor(QWidget *parent, const QStyleOptionViewItem &option) { + (void)option; + QWidget* editor = 0; + switch (value().type()) { + case QVariant::Color: + editor = new ColorCombo(parent); + break; + case QVariant::Int: + editor = new QSpinBox(parent); + editor->setProperty("minimum", -INT_MAX); + editor->setProperty("maximum", INT_MAX); + connect(editor, SIGNAL(valueChanged(int)), this, SLOT(setValue(int))); + break; + case QMetaType::Float: + case QVariant::Double: + editor = new QDoubleSpinBox(parent); + editor->setProperty("minimum", -INT_MAX); + editor->setProperty("maximum", INT_MAX); + connect(editor, SIGNAL(valueChanged(double)), this, SLOT(setValue(double))); + break; + default: + return editor; + } + return editor; +} + +bool Property::setEditorData(QWidget *editor, const QVariant &data) { + switch (value().type()) { + case QVariant::Color: + static_cast<ColorCombo*>(editor)->setColor(data.value<QColor>()); + return true; + ; + case QVariant::Int: + editor->blockSignals(true); + static_cast<QSpinBox*>(editor)->setValue(data.toInt()); + editor->blockSignals(false); + return true; + case QMetaType::Float: + case QVariant::Double: + editor->blockSignals(true); + static_cast<QDoubleSpinBox*>(editor)->setValue(data.toDouble()); + editor->blockSignals(false); + return true; + default: + return false; + } + return false; +} + +QVariant Property::editorData(QWidget *editor) { + switch (value().type()) { + case QVariant::Color: + return QVariant::fromValue(static_cast<ColorCombo*>(editor)->color()); + case QVariant::Int: + return QVariant(static_cast<QSpinBox*>(editor)->value()); + case QMetaType::Float: + case QVariant::Double: + return QVariant(static_cast<QDoubleSpinBox*>(editor)->value()); + break; + default: + return QVariant(); + } +} + +Property* Property::findPropertyObject(QObject* propertyObject) { + if (m_propertyObject == propertyObject) + return this; + for (int i=0; i<children().size(); ++i) { + Property* child = static_cast<Property*>(children()[i])->findPropertyObject(propertyObject); + if (child) + return child; + } + return 0; +} + +void Property::setValue(double value) { + setValue(QVariant(value)); +} + +void Property::setValue(int value) { + setValue(QVariant(value)); +} |