From 5d22e3cbdd251819a4d2d07b9a12994d5aef778d Mon Sep 17 00:00:00 2001 From: Frank Gevaerts Date: Fri, 29 Aug 2008 21:08:38 +0000 Subject: 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 --- .../wpseditor/gui/src/QPropertyEditor/Property.cpp | 136 +++++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 utils/wpseditor/gui/src/QPropertyEditor/Property.cpp (limited to 'utils/wpseditor/gui/src/QPropertyEditor/Property.cpp') diff --git a/utils/wpseditor/gui/src/QPropertyEditor/Property.cpp b/utils/wpseditor/gui/src/QPropertyEditor/Property.cpp new file mode 100644 index 0000000000..0746d15140 --- /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 . +// +// **************************************************************************************** + +#include "Property.h" +#include "ColorCombo.h" + +#include +#include + +#include + +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(editor)->setColor(data.value()); + return true; + ; + case QVariant::Int: + editor->blockSignals(true); + static_cast(editor)->setValue(data.toInt()); + editor->blockSignals(false); + return true; + case QMetaType::Float: + case QVariant::Double: + editor->blockSignals(true); + static_cast(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(editor)->color()); + case QVariant::Int: + return QVariant(static_cast(editor)->value()); + case QMetaType::Float: + case QVariant::Double: + return QVariant(static_cast(editor)->value()); + break; + default: + return QVariant(); + } +} + +Property* Property::findPropertyObject(QObject* propertyObject) { + if (m_propertyObject == propertyObject) + return this; + for (int i=0; i(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)); +} -- cgit v1.2.3