diff options
Diffstat (limited to 'utils/wpseditor/gui')
28 files changed, 2309 insertions, 0 deletions
diff --git a/utils/wpseditor/gui/gui.pro b/utils/wpseditor/gui/gui.pro new file mode 100644 index 0000000000..db7cfa1343 --- /dev/null +++ b/utils/wpseditor/gui/gui.pro | |||
@@ -0,0 +1,40 @@ | |||
1 | TEMPLATE = app | ||
2 | TARGET = | ||
3 | DEPENDPATH += . build src ui | ||
4 | INCLUDEPATH += . src/QPropertyEditor ../libwps/src | ||
5 | DESTDIR = bin | ||
6 | OBJECTS_DIR = build | ||
7 | MOC_DIR = build | ||
8 | UI_DIR = build | ||
9 | QMAKE_LIBDIR += lib | ||
10 | QT = gui core | ||
11 | CONFIG += qt warn_on console debug_and_release | ||
12 | libwps.commands += $(MAKE) -C ../libwps shared | ||
13 | QMAKE_EXTRA_TARGETS += libwps | ||
14 | PRE_TARGETDEPS += libwps | ||
15 | HEADERS += ../libwps/src/api.h \ | ||
16 | ../libwps/src/defs.h \ | ||
17 | src/slider.h \ | ||
18 | src/qtrackstate.h \ | ||
19 | src/qwpsstate.h \ | ||
20 | src/qwpseditorwindow.h \ | ||
21 | src/utils.h \ | ||
22 | src/qwpsdrawer.h | ||
23 | FORMS += ui/mainwindow.ui ui/slider.ui | ||
24 | SOURCES += src/main.cpp \ | ||
25 | src/slider.cpp \ | ||
26 | src/qtrackstate.cpp \ | ||
27 | src/qwpsstate.cpp \ | ||
28 | src/qwpseditorwindow.cpp \ | ||
29 | src/utils.cpp \ | ||
30 | src/qwpsdrawer.cpp \ | ||
31 | src/qwpsdrawer_static.cpp | ||
32 | LIBS += -Lbin | ||
33 | CONFIG(debug, debug|release) { | ||
34 | LIBS += -lQPropertyEditord | ||
35 | TARGET = wpseditord | ||
36 | } | ||
37 | CONFIG(release, debug|release) { | ||
38 | LIBS += -lQPropertyEditor | ||
39 | TARGET = wpseditor | ||
40 | } | ||
diff --git a/utils/wpseditor/gui/src/QPropertyEditor/ColorCombo.cpp b/utils/wpseditor/gui/src/QPropertyEditor/ColorCombo.cpp new file mode 100644 index 0000000000..f5eeb030dc --- /dev/null +++ b/utils/wpseditor/gui/src/QPropertyEditor/ColorCombo.cpp | |||
@@ -0,0 +1,73 @@ | |||
1 | // ************************************************************************************************* | ||
2 | // | ||
3 | // QPropertyEditor v 0.1 | ||
4 | // | ||
5 | // -------------------------------------- | ||
6 | // Copyright (C) 2007 Volker Wiendl | ||
7 | // | ||
8 | // | ||
9 | // This library is free software; you can redistribute it and/or | ||
10 | // modify it under the terms of the GNU Lesser General Public | ||
11 | // License as published by the Free Software Foundation; either | ||
12 | // version 2.1 of the License, or any later version. | ||
13 | // | ||
14 | // This library is distributed in the hope that it will be useful, | ||
15 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
17 | // Lesser General Public License for more details. | ||
18 | // | ||
19 | // You should have received a copy of the GNU Lesser General Public | ||
20 | // License along with this library; if not, write to the Free Software | ||
21 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
22 | // | ||
23 | // | ||
24 | // This class is based on the Color Editor Factory Example by Trolltech | ||
25 | // | ||
26 | // ************************************************************************************************* | ||
27 | |||
28 | #include "ColorCombo.h" | ||
29 | |||
30 | #include <Qt/qcolordialog.h> | ||
31 | |||
32 | ColorCombo::ColorCombo(QWidget* parent /*= 0*/) : QComboBox(parent) { | ||
33 | QStringList colorNames = QColor::colorNames(); | ||
34 | for (int i = 0; i < colorNames.size(); ++i) { | ||
35 | QColor color(colorNames[i]); | ||
36 | insertItem(i, colorNames[i]); | ||
37 | setItemData(i, color, Qt::DecorationRole); | ||
38 | } | ||
39 | addItem(tr("Custom"), QVariant((int)QVariant::UserType)); | ||
40 | connect(this, SIGNAL(currentIndexChanged(int)), this, SLOT(currentChanged(int))); | ||
41 | } | ||
42 | |||
43 | |||
44 | ColorCombo::~ColorCombo() {} | ||
45 | |||
46 | |||
47 | QColor ColorCombo::color() const { | ||
48 | return qVariantValue<QColor>(itemData(currentIndex(), Qt::DecorationRole)); | ||
49 | } | ||
50 | |||
51 | void ColorCombo::setColor(QColor color) { | ||
52 | m_init = color; | ||
53 | setCurrentIndex(findData(color, int(Qt::DecorationRole))); | ||
54 | if (currentIndex() == -1) { | ||
55 | addItem(color.name()); | ||
56 | setItemData(count()-1, color, Qt::DecorationRole); | ||
57 | setCurrentIndex(count()-1); | ||
58 | } | ||
59 | } | ||
60 | |||
61 | void ColorCombo::currentChanged(int index) { | ||
62 | if (itemData(index).isValid() && itemData(index) == QVariant((int)QVariant::UserType)) { | ||
63 | QColor color = QColorDialog::getColor(m_init, this); | ||
64 | if (color.isValid()) { | ||
65 | if (findData(color, int(Qt::DecorationRole)) == -1) { | ||
66 | addItem(color.name()); | ||
67 | setItemData(count()-1, color, Qt::DecorationRole); | ||
68 | } | ||
69 | setCurrentIndex(findData(color, int(Qt::DecorationRole))); | ||
70 | } else | ||
71 | setCurrentIndex(findData(m_init)); | ||
72 | } | ||
73 | } | ||
diff --git a/utils/wpseditor/gui/src/QPropertyEditor/ColorCombo.h b/utils/wpseditor/gui/src/QPropertyEditor/ColorCombo.h new file mode 100644 index 0000000000..530b05bbc5 --- /dev/null +++ b/utils/wpseditor/gui/src/QPropertyEditor/ColorCombo.h | |||
@@ -0,0 +1,49 @@ | |||
1 | // ************************************************************************************************* | ||
2 | // | ||
3 | // QPropertyEditor v 0.1 | ||
4 | // | ||
5 | // -------------------------------------- | ||
6 | // Copyright (C) 2007 Volker Wiendl | ||
7 | // | ||
8 | // | ||
9 | // This library is free software; you can redistribute it and/or | ||
10 | // modify it under the terms of the GNU Lesser General Public | ||
11 | // License as published by the Free Software Foundation; either | ||
12 | // version 2.1 of the License, or any later version. | ||
13 | // | ||
14 | // This library is distributed in the hope that it will be useful, | ||
15 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
17 | // Lesser General Public License for more details. | ||
18 | // | ||
19 | // You should have received a copy of the GNU Lesser General Public | ||
20 | // License along with this library; if not, write to the Free Software | ||
21 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
22 | // | ||
23 | // | ||
24 | // This class is based on the Color Editor Factory Example by Trolltech | ||
25 | // | ||
26 | // ************************************************************************************************* | ||
27 | |||
28 | #ifndef COLORCOMBO_H_ | ||
29 | #define COLORCOMBO_H_ | ||
30 | |||
31 | #include <Qt/qcombobox.h> | ||
32 | |||
33 | class ColorCombo : public QComboBox { | ||
34 | Q_OBJECT | ||
35 | public: | ||
36 | ColorCombo(QWidget* parent = 0); | ||
37 | virtual ~ColorCombo(); | ||
38 | |||
39 | QColor color() const; | ||
40 | void setColor(QColor c); | ||
41 | |||
42 | private slots: | ||
43 | void currentChanged(int index); | ||
44 | |||
45 | private: | ||
46 | QColor m_init; | ||
47 | |||
48 | }; | ||
49 | #endif | ||
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 @@ | |||
1 | // **************************************************************************************** | ||
2 | // | ||
3 | // QPropertyEditor Library | ||
4 | // -------------------------------------- | ||
5 | // Copyright (C) 2007 Volker Wiendl | ||
6 | // | ||
7 | // This file is part of the Horde3D Scene Editor. | ||
8 | // | ||
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 | ||
12 | // | ||
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. | ||
17 | // | ||
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/>. | ||
20 | // | ||
21 | // **************************************************************************************** | ||
22 | |||
23 | #include "Property.h" | ||
24 | #include "ColorCombo.h" | ||
25 | |||
26 | #include <Qt/qmetaobject.h> | ||
27 | #include <Qt/qspinbox.h> | ||
28 | |||
29 | #include <limits.h> | ||
30 | |||
31 | Property::Property(const QString& name /*= QString()*/, QObject* propertyObject /*= 0*/, QObject* parent /*= 0*/) : QObject(parent), | ||
32 | m_propertyObject(propertyObject) { | ||
33 | setObjectName(name); | ||
34 | } | ||
35 | |||
36 | QVariant Property::value(int /*role = Qt::UserRole*/) const { | ||
37 | if (m_propertyObject) | ||
38 | return m_propertyObject->property(qPrintable(objectName())); | ||
39 | else | ||
40 | return QVariant(); | ||
41 | } | ||
42 | |||
43 | void Property::setValue(const QVariant &value) { | ||
44 | if (m_propertyObject) | ||
45 | m_propertyObject->setProperty(qPrintable(objectName()), value); | ||
46 | } | ||
47 | |||
48 | bool Property::isReadOnly() { | ||
49 | if (m_propertyObject && m_propertyObject->metaObject()->property(m_propertyObject->metaObject()->indexOfProperty(qPrintable(objectName()))).isWritable()) | ||
50 | return false; | ||
51 | else | ||
52 | return true; | ||
53 | } | ||
54 | |||
55 | QWidget* Property::createEditor(QWidget *parent, const QStyleOptionViewItem &option) { | ||
56 | (void)option; | ||
57 | QWidget* editor = 0; | ||
58 | switch (value().type()) { | ||
59 | case QVariant::Color: | ||
60 | editor = new ColorCombo(parent); | ||
61 | break; | ||
62 | case QVariant::Int: | ||
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))); | ||
67 | break; | ||
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))); | ||
74 | break; | ||
75 | default: | ||
76 | return editor; | ||
77 | } | ||
78 | return editor; | ||
79 | } | ||
80 | |||
81 | bool Property::setEditorData(QWidget *editor, const QVariant &data) { | ||
82 | switch (value().type()) { | ||
83 | case QVariant::Color: | ||
84 | static_cast<ColorCombo*>(editor)->setColor(data.value<QColor>()); | ||
85 | return true; | ||
86 | ; | ||
87 | case QVariant::Int: | ||
88 | editor->blockSignals(true); | ||
89 | static_cast<QSpinBox*>(editor)->setValue(data.toInt()); | ||
90 | editor->blockSignals(false); | ||
91 | return true; | ||
92 | case QMetaType::Float: | ||
93 | case QVariant::Double: | ||
94 | editor->blockSignals(true); | ||
95 | static_cast<QDoubleSpinBox*>(editor)->setValue(data.toDouble()); | ||
96 | editor->blockSignals(false); | ||
97 | return true; | ||
98 | default: | ||
99 | return false; | ||
100 | } | ||
101 | return false; | ||
102 | } | ||
103 | |||
104 | QVariant Property::editorData(QWidget *editor) { | ||
105 | switch (value().type()) { | ||
106 | case QVariant::Color: | ||
107 | return QVariant::fromValue(static_cast<ColorCombo*>(editor)->color()); | ||
108 | case QVariant::Int: | ||
109 | return QVariant(static_cast<QSpinBox*>(editor)->value()); | ||
110 | case QMetaType::Float: | ||
111 | case QVariant::Double: | ||
112 | return QVariant(static_cast<QDoubleSpinBox*>(editor)->value()); | ||
113 | break; | ||
114 | default: | ||
115 | return QVariant(); | ||
116 | } | ||
117 | } | ||
118 | |||
119 | Property* Property::findPropertyObject(QObject* propertyObject) { | ||
120 | if (m_propertyObject == propertyObject) | ||
121 | return this; | ||
122 | for (int i=0; i<children().size(); ++i) { | ||
123 | Property* child = static_cast<Property*>(children()[i])->findPropertyObject(propertyObject); | ||
124 | if (child) | ||
125 | return child; | ||
126 | } | ||
127 | return 0; | ||
128 | } | ||
129 | |||
130 | void Property::setValue(double value) { | ||
131 | setValue(QVariant(value)); | ||
132 | } | ||
133 | |||
134 | void Property::setValue(int value) { | ||
135 | setValue(QVariant(value)); | ||
136 | } | ||
diff --git a/utils/wpseditor/gui/src/QPropertyEditor/Property.h b/utils/wpseditor/gui/src/QPropertyEditor/Property.h new file mode 100644 index 0000000000..52d6842987 --- /dev/null +++ b/utils/wpseditor/gui/src/QPropertyEditor/Property.h | |||
@@ -0,0 +1,157 @@ | |||
1 | // ************************************************************************************************* | ||
2 | // | ||
3 | // QPropertyEditor v 0.1 | ||
4 | // | ||
5 | // -------------------------------------- | ||
6 | // Copyright (C) 2007 Volker Wiendl | ||
7 | // | ||
8 | // | ||
9 | // This library is free software; you can redistribute it and/or | ||
10 | // modify it under the terms of the GNU Lesser General Public | ||
11 | // License as published by the Free Software Foundation; either | ||
12 | // version 2.1 of the License, or any later version. | ||
13 | // | ||
14 | // This library is distributed in the hope that it will be useful, | ||
15 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
17 | // Lesser General Public License for more details. | ||
18 | // | ||
19 | // You should have received a copy of the GNU Lesser General Public | ||
20 | // License along with this library; if not, write to the Free Software | ||
21 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
22 | // | ||
23 | // ************************************************************************************************* | ||
24 | |||
25 | #ifndef PROPERTY_H_ | ||
26 | #define PROPERTY_H_ | ||
27 | |||
28 | #include <Qt/qwidget.h> | ||
29 | #include <Qt/qstyleoption.h> | ||
30 | #include <Qt/qvariant.h> | ||
31 | |||
32 | /** | ||
33 | * The Property class is the base class for all properties in the QPropertyEditor | ||
34 | * You can implement custom properties inherited from this class to further enhence the | ||
35 | * functionality of the QPropertyEditor | ||
36 | */ | ||
37 | class Property : public QObject { | ||
38 | Q_OBJECT | ||
39 | |||
40 | public: | ||
41 | |||
42 | /** | ||
43 | * Constructor | ||
44 | * | ||
45 | * @param name the name of the property within the propertyObject (will be used in the QPropertyEditorWidget view too) | ||
46 | * @param propertyObject the object that contains the property | ||
47 | * @param parent optional parent object | ||
48 | */ | ||
49 | Property(const QString& name = QString(), QObject* propertyObject = 0, QObject* parent = 0); | ||
50 | |||
51 | /** | ||
52 | * The value stored by this property | ||
53 | * @return QVariant the data converted to a QVariant | ||
54 | */ | ||
55 | virtual QVariant value(int role = Qt::UserRole) const; | ||
56 | /** | ||
57 | * Sets the value stored by this property | ||
58 | * @param value the data converted to a QVariant | ||
59 | */ | ||
60 | virtual void setValue(const QVariant& value); | ||
61 | |||
62 | /** | ||
63 | * Returns the QObject which contains the property managed by this instance | ||
64 | * @return QObject* pointer to the QObject that contains user defined properties | ||
65 | */ | ||
66 | QObject* propertyObject() { | ||
67 | return m_propertyObject; | ||
68 | } | ||
69 | |||
70 | /** | ||
71 | * Flag if property is used for indicating a group or really manages a property | ||
72 | * @return bool true if this property is only used to display a category in the QPropertyEditorWidget | ||
73 | */ | ||
74 | bool isRoot() { | ||
75 | return m_propertyObject == 0; | ||
76 | } | ||
77 | |||
78 | /** | ||
79 | * Flag if the property can be set | ||
80 | * @return bool true if this property has no set method | ||
81 | */ | ||
82 | bool isReadOnly(); | ||
83 | |||
84 | /** | ||
85 | * Returns the row of this instance within the QPropertyModel | ||
86 | * @return int row within the QPropertyModel | ||
87 | */ | ||
88 | int row() { | ||
89 | return parent()->children().indexOf(this); | ||
90 | } | ||
91 | |||
92 | /** | ||
93 | * returns optional settings for the editor widget that is used to manipulate the properties value | ||
94 | * @return QString a string that contains property settings for the editor widget (e.g. "minimum=1.0;maximum=10.0;") | ||
95 | */ | ||
96 | QString editorHints() { | ||
97 | return m_hints; | ||
98 | } | ||
99 | |||
100 | /** | ||
101 | * Sets properties for the editor widget that is used to manipulate the data value managed by this instance | ||
102 | * @param hints a string containing property settings for the editor widget that manipulates this property | ||
103 | */ | ||
104 | virtual void setEditorHints(const QString& hints) { | ||
105 | m_hints = hints; | ||
106 | } | ||
107 | |||
108 | /** | ||
109 | * Creates an editor for the data managed by this instance | ||
110 | * @param parent widget the newly created editor widget will be child of | ||
111 | * @param option currently not used | ||
112 | * @return QWidget* pointer to the editor widget | ||
113 | */ | ||
114 | virtual QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option); | ||
115 | |||
116 | /** | ||
117 | * Returns the data of the editor widget used to manipulate this instance | ||
118 | * @return QVariant the data converted to a QVariant | ||
119 | */ | ||
120 | virtual QVariant editorData(QWidget *editor); | ||
121 | |||
122 | /** | ||
123 | * Changes the editor widget's data to a specific value | ||
124 | * @param editor the editor widget | ||
125 | * @param data the data to set in the editor widget | ||
126 | * @return bool true if editor widget was set to the given data successfully, false if the data can not be set in the editor (e.g. wrong datatype) | ||
127 | */ | ||
128 | virtual bool setEditorData(QWidget *editor, const QVariant& data); | ||
129 | |||
130 | /** | ||
131 | * Tries to find the first property that manages the given propertyObject | ||
132 | * @param propertyObject | ||
133 | * @return Property | ||
134 | */ | ||
135 | Property* findPropertyObject(QObject* propertyObject); | ||
136 | |||
137 | private slots: | ||
138 | /** | ||
139 | * This slot is used to immediately set the properties when the editor widget's value of a double or float | ||
140 | * property has changed | ||
141 | * @param value the new value | ||
142 | */ | ||
143 | void setValue(double value); | ||
144 | /** | ||
145 | * This slot is used to immediately set the properties when the editor widget's value of an integer | ||
146 | * property has changed | ||
147 | * @param value the new value | ||
148 | */ | ||
149 | void setValue(int value); | ||
150 | |||
151 | private: | ||
152 | QObject* m_propertyObject; | ||
153 | QString m_hints; | ||
154 | |||
155 | }; | ||
156 | |||
157 | #endif | ||
diff --git a/utils/wpseditor/gui/src/QPropertyEditor/QPropertyEditor.pro b/utils/wpseditor/gui/src/QPropertyEditor/QPropertyEditor.pro new file mode 100644 index 0000000000..85fd29ee2c --- /dev/null +++ b/utils/wpseditor/gui/src/QPropertyEditor/QPropertyEditor.pro | |||
@@ -0,0 +1,26 @@ | |||
1 | TEMPLATE = lib | ||
2 | CONFIG += staticlib debug_and_release | ||
3 | SOURCES = ColorCombo.cpp \ | ||
4 | Property.cpp \ | ||
5 | QPropertyEditorWidget.cpp \ | ||
6 | QPropertyModel.cpp \ | ||
7 | QVariantDelegate.cpp | ||
8 | HEADERS = ColorCombo.h \ | ||
9 | Property.h \ | ||
10 | QPropertyEditorWidget.h \ | ||
11 | QPropertyModel.h \ | ||
12 | QVariantDelegate.h | ||
13 | INCLUDEPATH += . | ||
14 | DESTDIR = ../../lib | ||
15 | UI_DIR = . | ||
16 | CONFIG(debug, debug|release) { | ||
17 | TARGET = QPropertyEditord | ||
18 | OBJECTS_DIR = ../../build/QPropertyEditor/debug | ||
19 | MOC_DIR = ../../build/QPropertyEditor/debug | ||
20 | } | ||
21 | CONFIG(release, debug|release) { | ||
22 | TARGET = QPropertyEditor | ||
23 | OBJECTS_DIR = ../../build/QPropertyEditor/release | ||
24 | MOC_DIR = ../../build/QPropertyEditor/release | ||
25 | DEFINES += QT_NO_DEBUG | ||
26 | } | ||
diff --git a/utils/wpseditor/gui/src/QPropertyEditor/QPropertyEditorWidget.cpp b/utils/wpseditor/gui/src/QPropertyEditor/QPropertyEditorWidget.cpp new file mode 100644 index 0000000000..fc4b90c227 --- /dev/null +++ b/utils/wpseditor/gui/src/QPropertyEditor/QPropertyEditorWidget.cpp | |||
@@ -0,0 +1,56 @@ | |||
1 | // ************************************************************************************************* | ||
2 | // | ||
3 | // QPropertyEditor v 0.1 | ||
4 | // | ||
5 | // -------------------------------------- | ||
6 | // Copyright (C) 2007 Volker Wiendl | ||
7 | // | ||
8 | // | ||
9 | // This library is free software; you can redistribute it and/or | ||
10 | // modify it under the terms of the GNU Lesser General Public | ||
11 | // License as published by the Free Software Foundation; either | ||
12 | // version 2.1 of the License, or any later version. | ||
13 | // | ||
14 | // This library is distributed in the hope that it will be useful, | ||
15 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
17 | // Lesser General Public License for more details. | ||
18 | // | ||
19 | // You should have received a copy of the GNU Lesser General Public | ||
20 | // License along with this library; if not, write to the Free Software | ||
21 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
22 | // | ||
23 | // ************************************************************************************************* | ||
24 | |||
25 | #include "QPropertyEditorWidget.h" | ||
26 | #include "QPropertyModel.h" | ||
27 | #include "QVariantDelegate.h" | ||
28 | #include "Property.h" | ||
29 | |||
30 | QPropertyEditorWidget::QPropertyEditorWidget(QWidget* parent /*= 0*/) : QTreeView(parent) { | ||
31 | m_model = new QPropertyModel(this); | ||
32 | setModel(m_model); | ||
33 | setItemDelegate(new QVariantDelegate(this)); | ||
34 | } | ||
35 | |||
36 | |||
37 | QPropertyEditorWidget::~QPropertyEditorWidget() {} | ||
38 | |||
39 | void QPropertyEditorWidget::addObject(QObject* propertyObject) { | ||
40 | m_model->addItem(propertyObject); | ||
41 | expandToDepth(0); | ||
42 | } | ||
43 | |||
44 | void QPropertyEditorWidget::setObject(QObject* propertyObject) { | ||
45 | m_model->clear(); | ||
46 | if (propertyObject) | ||
47 | addObject(propertyObject); | ||
48 | } | ||
49 | |||
50 | void QPropertyEditorWidget::updateObject(QObject* propertyObject) { | ||
51 | m_model->updateItem(propertyObject); | ||
52 | } | ||
53 | |||
54 | void QPropertyEditorWidget::setCustomPropertyCB(UserTypeCB callback) { | ||
55 | m_model->setCustomPropertyCB(callback); | ||
56 | } | ||
diff --git a/utils/wpseditor/gui/src/QPropertyEditor/QPropertyEditorWidget.h b/utils/wpseditor/gui/src/QPropertyEditor/QPropertyEditorWidget.h new file mode 100644 index 0000000000..2dab87722a --- /dev/null +++ b/utils/wpseditor/gui/src/QPropertyEditor/QPropertyEditorWidget.h | |||
@@ -0,0 +1,113 @@ | |||
1 | // ************************************************************************************************* | ||
2 | // | ||
3 | // QPropertyEditor v 0.1 | ||
4 | // | ||
5 | // -------------------------------------- | ||
6 | // Copyright (C) 2007 Volker Wiendl | ||
7 | // | ||
8 | // | ||
9 | // This library is free software; you can redistribute it and/or | ||
10 | // modify it under the terms of the GNU Lesser General Public | ||
11 | // License as published by the Free Software Foundation; either | ||
12 | // version 2.1 of the License, or any later version. | ||
13 | // | ||
14 | // This library is distributed in the hope that it will be useful, | ||
15 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
17 | // Lesser General Public License for more details. | ||
18 | // | ||
19 | // You should have received a copy of the GNU Lesser General Public | ||
20 | // License along with this library; if not, write to the Free Software | ||
21 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
22 | // | ||
23 | // ************************************************************************************************* | ||
24 | |||
25 | #ifndef QPROPERTYEDITORWIDGET_H_ | ||
26 | #define QPROPERTYEDITORWIDGET_H_ | ||
27 | |||
28 | #include <Qt/qtreeview.h> | ||
29 | |||
30 | class QPropertyModel; | ||
31 | class Property; | ||
32 | |||
33 | /** | ||
34 | * \mainpage QPropertyEditor | ||
35 | * | ||
36 | * \section intro_sec Introduction | ||
37 | * | ||
38 | * The main purpose for the QPropertyEditor is the visualization and manipulation of properties defined via the Q_PROPERTY macro in | ||
39 | * QObject based classes. | ||
40 | */ | ||
41 | |||
42 | /** | ||
43 | * \brief The QPropertyEditorWidget offers an easy to use mechanism to visualize properties of a class inherited from QObject. | ||
44 | * | ||
45 | * Qt provides a nice way to define class properties by using the Q_PROPERTY macro. The purpose of the QPropertyEditor | ||
46 | * is to visualize these properties in an easy way. | ||
47 | * | ||
48 | * To use the property editor, all you have to do is to create a class that defines it's properties by using Q_PROPERTY | ||
49 | * and to add this class by using the addObject() method of this QPropertyEditorWidget class. | ||
50 | * The QPropertyEditorWidget is inherited from QTreeView and will display the properties in a tree with two columns: Name and Value | ||
51 | * | ||
52 | * For basic data types the build in editor widgets of Qt will be used. The QPropertyEditor itself only defines an additional | ||
53 | * editor for QColor (based on the Color Editor Factory Example from Trolltech). But it can easily be extended by yourself | ||
54 | * either within the library or for special datatypes also outside of the library in your application. | ||
55 | */ | ||
56 | class QPropertyEditorWidget : public QTreeView { | ||
57 | Q_OBJECT | ||
58 | public: | ||
59 | |||
60 | /** | ||
61 | * A typedef for a callback used to create user defined properties for custom datatypes | ||
62 | */ | ||
63 | typedef Property* (*UserTypeCB)(const QString& name, QObject* propertyObject, Property* parent); | ||
64 | |||
65 | /** | ||
66 | * \brief Constructor | ||
67 | * | ||
68 | * Creates a new editor widget based on QTreeView | ||
69 | * @param parent optional parent widget | ||
70 | */ | ||
71 | QPropertyEditorWidget(QWidget* parent = 0); | ||
72 | |||
73 | /// Destructor | ||
74 | virtual ~QPropertyEditorWidget(); | ||
75 | |||
76 | /** | ||
77 | * Adds the user properties of the given class to the QPropertyModel associated with this view | ||
78 | * | ||
79 | * @param propertyObject the class inherited from QObject that contains user properties that should be | ||
80 | * managed by the QPropertyModel associated with this view | ||
81 | */ | ||
82 | void addObject(QObject* propertyObject); | ||
83 | |||
84 | /** | ||
85 | * Similar to the addObject() method this method adds the properties of the given class to the QPropertyModel | ||
86 | * associated with this view. But in contrast to addObject() it will clear the model before, removing all | ||
87 | * previously added objects. | ||
88 | * | ||
89 | * @param propertyObject the class inherited from QObject that contains user properties that should be | ||
90 | * managed by the QPropertyModel associated with this view | ||
91 | */ | ||
92 | void setObject(QObject* propertyObject); | ||
93 | |||
94 | /** | ||
95 | * Updates the view for the given object. This can be usefull if a property was changed programmatically instead | ||
96 | * of using the view. In this case the view normally will display the new property values only after the user clicked | ||
97 | * on it. To overcome this problem you can call updateObject with the object whose property was changed. | ||
98 | */ | ||
99 | void updateObject(QObject* propertyObject); | ||
100 | |||
101 | /** | ||
102 | * If you define custom datatypes outside of this library the QPropertyModel will check if you | ||
103 | * also defined a callback that is responsible to create custom property classes inherited from Property to handle | ||
104 | * these datatypes. With this method you can set such a callback that will create custom properties for custom datatypes. | ||
105 | */ | ||
106 | void setCustomPropertyCB(UserTypeCB callback); | ||
107 | |||
108 | private: | ||
109 | /// The Model for this view | ||
110 | QPropertyModel* m_model; | ||
111 | |||
112 | }; | ||
113 | #endif | ||
diff --git a/utils/wpseditor/gui/src/QPropertyEditor/QPropertyModel.cpp b/utils/wpseditor/gui/src/QPropertyEditor/QPropertyModel.cpp new file mode 100644 index 0000000000..b147cd089d --- /dev/null +++ b/utils/wpseditor/gui/src/QPropertyEditor/QPropertyModel.cpp | |||
@@ -0,0 +1,236 @@ | |||
1 | // ************************************************************************************************* | ||
2 | // | ||
3 | // QPropertyEditor v 0.1 | ||
4 | // | ||
5 | // -------------------------------------- | ||
6 | // Copyright (C) 2007 Volker Wiendl | ||
7 | // | ||
8 | // | ||
9 | // This library is free software; you can redistribute it and/or | ||
10 | // modify it under the terms of the GNU Lesser General Public | ||
11 | // License as published by the Free Software Foundation; either | ||
12 | // version 2.1 of the License, or any later version. | ||
13 | // | ||
14 | // This library is distributed in the hope that it will be useful, | ||
15 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
17 | // Lesser General Public License for more details. | ||
18 | // | ||
19 | // You should have received a copy of the GNU Lesser General Public | ||
20 | // License along with this library; if not, write to the Free Software | ||
21 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
22 | // | ||
23 | // ************************************************************************************************* | ||
24 | |||
25 | #include "QPropertyModel.h" | ||
26 | |||
27 | #include "Property.h" | ||
28 | |||
29 | #include <Qt/qapplication.h> | ||
30 | #include <Qt/qmetaobject.h> | ||
31 | #include <Qt/qitemeditorfactory.h> | ||
32 | |||
33 | struct PropertyPair { | ||
34 | PropertyPair(const QMetaObject* obj, QMetaProperty property) : Property(property), Object(obj) {} | ||
35 | |||
36 | QMetaProperty Property; | ||
37 | const QMetaObject* Object; | ||
38 | |||
39 | bool operator==(const PropertyPair& other) const { | ||
40 | return QString(other.Property.name()) == QString(Property.name()); | ||
41 | } | ||
42 | }; | ||
43 | |||
44 | |||
45 | QPropertyModel::QPropertyModel(QObject* parent /*= 0*/) : QAbstractItemModel(parent), m_userCallback(0) { | ||
46 | m_rootItem = new Property("Root",0, this); | ||
47 | } | ||
48 | |||
49 | |||
50 | QPropertyModel::~QPropertyModel() {} | ||
51 | |||
52 | QModelIndex QPropertyModel::index ( int row, int column, const QModelIndex & parent /*= QModelIndex()*/ ) const { | ||
53 | Property *parentItem = m_rootItem; | ||
54 | if (parent.isValid()) | ||
55 | parentItem = static_cast<Property*>(parent.internalPointer()); | ||
56 | if (row >= parentItem->children().size()) | ||
57 | return QModelIndex(); | ||
58 | return createIndex(row, column, parentItem->children().at(row)); | ||
59 | |||
60 | } | ||
61 | |||
62 | QModelIndex QPropertyModel::parent ( const QModelIndex & index ) const { | ||
63 | if (!index.isValid()) | ||
64 | return QModelIndex(); | ||
65 | |||
66 | Property *childItem = static_cast<Property*>(index.internalPointer()); | ||
67 | Property *parentItem = qobject_cast<Property*>(childItem->parent()); | ||
68 | |||
69 | if (!parentItem || parentItem == m_rootItem) | ||
70 | return QModelIndex(); | ||
71 | |||
72 | return createIndex(parentItem->row(), 0, parentItem); | ||
73 | } | ||
74 | |||
75 | int QPropertyModel::rowCount ( const QModelIndex & parent /*= QModelIndex()*/ ) const { | ||
76 | Property *parentItem = m_rootItem; | ||
77 | if (parent.isValid()) | ||
78 | parentItem = static_cast<Property*>(parent.internalPointer()); | ||
79 | return parentItem->children().size(); | ||
80 | } | ||
81 | |||
82 | int QPropertyModel::columnCount ( const QModelIndex & parent /*= QModelIndex()*/ ) const { | ||
83 | (void)parent; | ||
84 | return 2; | ||
85 | } | ||
86 | |||
87 | QVariant QPropertyModel::data ( const QModelIndex & index, int role /*= Qt::DisplayRole*/ ) const { | ||
88 | if (!index.isValid()) | ||
89 | return QVariant(); | ||
90 | |||
91 | Property *item = static_cast<Property*>(index.internalPointer()); | ||
92 | switch (role) { | ||
93 | case Qt::ToolTipRole: | ||
94 | case Qt::DecorationRole: | ||
95 | case Qt::DisplayRole: | ||
96 | case Qt::EditRole: | ||
97 | if (index.column() == 0) | ||
98 | return item->objectName(); | ||
99 | if (index.column() == 1) | ||
100 | return item->value(role); | ||
101 | case Qt::BackgroundRole: | ||
102 | if (item->isRoot()) return QApplication::palette("QTreeView").brush(QPalette::Normal, QPalette::Button).color(); | ||
103 | break; | ||
104 | }; | ||
105 | return QVariant(); | ||
106 | } | ||
107 | |||
108 | // edit methods | ||
109 | bool QPropertyModel::setData ( const QModelIndex & index, const QVariant & value, int role /*= Qt::EditRole*/ ) { | ||
110 | if (index.isValid() && role == Qt::EditRole) { | ||
111 | Property *item = static_cast<Property*>(index.internalPointer()); | ||
112 | item->setValue(value); | ||
113 | emit dataChanged(index, index); | ||
114 | return true; | ||
115 | } | ||
116 | return false; | ||
117 | } | ||
118 | |||
119 | Qt::ItemFlags QPropertyModel::flags ( const QModelIndex & index ) const { | ||
120 | if (!index.isValid()) | ||
121 | return Qt::ItemIsEnabled; | ||
122 | Property *item = static_cast<Property*>(index.internalPointer()); | ||
123 | // only allow change of value attribute | ||
124 | if (item->isRoot()) | ||
125 | return Qt::ItemIsEnabled; | ||
126 | else if (item->isReadOnly()) | ||
127 | return Qt::ItemIsDragEnabled | Qt::ItemIsSelectable; | ||
128 | else | ||
129 | return Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable; | ||
130 | } | ||
131 | |||
132 | |||
133 | QVariant QPropertyModel::headerData ( int section, Qt::Orientation orientation, int role /*= Qt::DisplayRole*/ ) const { | ||
134 | if (orientation == Qt::Horizontal && role == Qt::DisplayRole) { | ||
135 | switch (section) { | ||
136 | case 0: | ||
137 | return tr("Name"); | ||
138 | case 1: | ||
139 | return tr("Value"); | ||
140 | } | ||
141 | } | ||
142 | return QVariant(); | ||
143 | } | ||
144 | |||
145 | QModelIndex QPropertyModel::buddy ( const QModelIndex & index ) const { | ||
146 | if (index.isValid() && index.column() == 0) | ||
147 | return createIndex(index.row(), 1, index.internalPointer()); | ||
148 | return index; | ||
149 | } | ||
150 | |||
151 | void QPropertyModel::addItem(QObject *propertyObject) { | ||
152 | // first create property <-> class hierarchy | ||
153 | QList<PropertyPair> propertyMap; | ||
154 | QList<const QMetaObject*> classList; | ||
155 | const QMetaObject* metaObject = propertyObject->metaObject(); | ||
156 | do { | ||
157 | int count = metaObject->propertyCount(); | ||
158 | for (int i=0; i<count; ++i) { | ||
159 | QMetaProperty property = metaObject->property(i); | ||
160 | if (property.isUser()) // Hide Qt specific properties | ||
161 | { | ||
162 | PropertyPair pair(metaObject, property); | ||
163 | int index = propertyMap.indexOf(pair); | ||
164 | if (index != -1) | ||
165 | propertyMap[index] = pair; | ||
166 | else | ||
167 | propertyMap.push_back(pair); | ||
168 | } | ||
169 | } | ||
170 | classList.push_front(metaObject); | ||
171 | } while ((metaObject = metaObject->superClass())!=0); | ||
172 | |||
173 | QList<const QMetaObject*> finalClassList; | ||
174 | // remove empty classes from hierarchy list | ||
175 | foreach(const QMetaObject* obj, classList) { | ||
176 | bool keep = false; | ||
177 | foreach(PropertyPair pair, propertyMap) { | ||
178 | if (pair.Object == obj) { | ||
179 | keep = true; | ||
180 | break; | ||
181 | } | ||
182 | } | ||
183 | if (keep) | ||
184 | finalClassList.push_back(obj); | ||
185 | } | ||
186 | |||
187 | // finally insert properties for classes containing them | ||
188 | int i=rowCount(); | ||
189 | beginInsertRows(QModelIndex(), i, i + finalClassList.count()); | ||
190 | foreach(const QMetaObject* metaObject, finalClassList) { | ||
191 | // Set default name of the hierarchy property to the class name | ||
192 | QString name = metaObject->className(); | ||
193 | // Check if there is a special name for the class | ||
194 | int index = metaObject->indexOfClassInfo(qPrintable(name)); | ||
195 | if (index != -1) | ||
196 | name = metaObject->classInfo(index).value(); | ||
197 | // Create Property Item for class node | ||
198 | Property* propertyItem = new Property(name, 0, m_rootItem); | ||
199 | foreach(PropertyPair pair, propertyMap) { | ||
200 | // Check if the property is associated with the current class from the finalClassList | ||
201 | if (pair.Object == metaObject) { | ||
202 | QMetaProperty property(pair.Property); | ||
203 | Property* p = 0; | ||
204 | if (property.type() == QVariant::UserType && m_userCallback) | ||
205 | p = m_userCallback(property.name(), propertyObject, propertyItem); | ||
206 | else | ||
207 | p = new Property(property.name(), propertyObject, propertyItem); | ||
208 | int index = metaObject->indexOfClassInfo(property.name()); | ||
209 | if (index != -1) | ||
210 | p->setEditorHints(metaObject->classInfo(index).value()); | ||
211 | } | ||
212 | } | ||
213 | } | ||
214 | endInsertRows(); | ||
215 | } | ||
216 | |||
217 | void QPropertyModel::updateItem ( QObject* propertyObject, const QModelIndex& parent /*= QModelIndex() */ ) { | ||
218 | Property *parentItem = m_rootItem; | ||
219 | if (parent.isValid()) | ||
220 | parentItem = static_cast<Property*>(parent.internalPointer()); | ||
221 | if (parentItem->propertyObject() != propertyObject) | ||
222 | parentItem = parentItem->findPropertyObject(propertyObject); | ||
223 | if (parentItem) // Indicate view that the data for the indices have changed | ||
224 | dataChanged(createIndex(parentItem->row(), 0, static_cast<Property*>(parentItem)), createIndex(parentItem->row(), 1, static_cast<Property*>(parentItem))); | ||
225 | } | ||
226 | |||
227 | void QPropertyModel::clear() { | ||
228 | beginRemoveRows(QModelIndex(), 0, rowCount()); | ||
229 | delete m_rootItem; | ||
230 | m_rootItem = new Property("Root",0, this); | ||
231 | endRemoveRows(); | ||
232 | } | ||
233 | |||
234 | void QPropertyModel::setCustomPropertyCB(QPropertyEditorWidget::UserTypeCB callback) { | ||
235 | m_userCallback = callback; | ||
236 | } | ||
diff --git a/utils/wpseditor/gui/src/QPropertyEditor/QPropertyModel.h b/utils/wpseditor/gui/src/QPropertyEditor/QPropertyModel.h new file mode 100644 index 0000000000..8a52bbe87c --- /dev/null +++ b/utils/wpseditor/gui/src/QPropertyEditor/QPropertyModel.h | |||
@@ -0,0 +1,105 @@ | |||
1 | // ************************************************************************************************* | ||
2 | // | ||
3 | // QPropertyEditor v 0.1 | ||
4 | // | ||
5 | // -------------------------------------- | ||
6 | // Copyright (C) 2007 Volker Wiendl | ||
7 | // | ||
8 | // | ||
9 | // This library is free software; you can redistribute it and/or | ||
10 | // modify it under the terms of the GNU Lesser General Public | ||
11 | // License as published by the Free Software Foundation; either | ||
12 | // version 2.1 of the License, or any later version. | ||
13 | // | ||
14 | // This library is distributed in the hope that it will be useful, | ||
15 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
17 | // Lesser General Public License for more details. | ||
18 | // | ||
19 | // You should have received a copy of the GNU Lesser General Public | ||
20 | // License along with this library; if not, write to the Free Software | ||
21 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
22 | // | ||
23 | // ************************************************************************************************* | ||
24 | #ifndef QPROPERTYMODEL_H_ | ||
25 | #define QPROPERTYMODEL_H_ | ||
26 | |||
27 | #include <Qt/qabstractitemmodel.h> | ||
28 | #include <Qt/qmap.h> | ||
29 | |||
30 | #include "QPropertyEditorWidget.h" | ||
31 | |||
32 | class Property; | ||
33 | |||
34 | /** | ||
35 | * The QPropertyModel handles the user defined properties of QObjects | ||
36 | */ | ||
37 | class QPropertyModel : public QAbstractItemModel { | ||
38 | Q_OBJECT | ||
39 | public: | ||
40 | /** | ||
41 | * Constructor | ||
42 | * @param parent optional parent object | ||
43 | */ | ||
44 | QPropertyModel(QObject* parent = 0); | ||
45 | /// Destructor | ||
46 | virtual ~QPropertyModel(); | ||
47 | |||
48 | /// QAbstractItemModel implementation | ||
49 | QModelIndex index ( int row, int column, const QModelIndex & parent = QModelIndex() ) const; | ||
50 | |||
51 | /// QAbstractItemModel implementation | ||
52 | QModelIndex parent ( const QModelIndex & index ) const; | ||
53 | /// QAbstractItemModel implementation | ||
54 | int rowCount ( const QModelIndex & parent = QModelIndex() ) const; | ||
55 | /// QAbstractItemModel implementation | ||
56 | int columnCount ( const QModelIndex & parent = QModelIndex() ) const; | ||
57 | /// QAbstractItemModel implementation | ||
58 | QVariant data ( const QModelIndex & index, int role = Qt::DisplayRole ) const; | ||
59 | |||
60 | /// QAbstractItemModel implementation | ||
61 | bool setData ( const QModelIndex & index, const QVariant & value, int role = Qt::EditRole ); | ||
62 | /// QAbstractItemModel implementation | ||
63 | Qt::ItemFlags flags ( const QModelIndex & index ) const; | ||
64 | |||
65 | /// QAbstractItemModel implementation | ||
66 | QVariant headerData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const; | ||
67 | |||
68 | /// QAbstractItemModel implementation | ||
69 | QModelIndex buddy ( const QModelIndex & index ) const; | ||
70 | |||
71 | /** | ||
72 | * Adds the user properties of the given class to the QPropertyModel instance | ||
73 | * | ||
74 | * @param propertyObject the class inherited from QObject that contains user properties that should be | ||
75 | * managed by this instance | ||
76 | */ | ||
77 | void addItem(QObject* propertyObject); | ||
78 | |||
79 | /** | ||
80 | * Creates a dataChanged signal for the given object | ||
81 | * @param propertyObject the instance of a QObject based class that should be updated | ||
82 | * @param parent optional model index the propertyObject is child of | ||
83 | */ | ||
84 | void updateItem ( QObject* propertyObject, const QModelIndex& parent = QModelIndex() ) ; | ||
85 | |||
86 | /** | ||
87 | * Removes all objects from the model | ||
88 | */ | ||
89 | void clear(); | ||
90 | |||
91 | /** | ||
92 | * Sets custom callback that will be used to create Property instances for custom datatypes | ||
93 | */ | ||
94 | void setCustomPropertyCB(QPropertyEditorWidget::UserTypeCB callback); | ||
95 | |||
96 | private: | ||
97 | |||
98 | /// The Root Property for all objects | ||
99 | Property* m_rootItem; | ||
100 | |||
101 | /// Custom callback | ||
102 | QPropertyEditorWidget::UserTypeCB m_userCallback; | ||
103 | |||
104 | }; | ||
105 | #endif | ||
diff --git a/utils/wpseditor/gui/src/QPropertyEditor/QVariantDelegate.cpp b/utils/wpseditor/gui/src/QPropertyEditor/QVariantDelegate.cpp new file mode 100644 index 0000000000..ebda9b2c31 --- /dev/null +++ b/utils/wpseditor/gui/src/QPropertyEditor/QVariantDelegate.cpp | |||
@@ -0,0 +1,105 @@ | |||
1 | // ************************************************************************************************* | ||
2 | // | ||
3 | // QPropertyEditor v 0.1 | ||
4 | // | ||
5 | // -------------------------------------- | ||
6 | // Copyright (C) 2007 Volker Wiendl | ||
7 | // | ||
8 | // | ||
9 | // This library is free software; you can redistribute it and/or | ||
10 | // modify it under the terms of the GNU Lesser General Public | ||
11 | // License as published by the Free Software Foundation; either | ||
12 | // version 2.1 of the License, or any later version. | ||
13 | // | ||
14 | // This library is distributed in the hope that it will be useful, | ||
15 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
17 | // Lesser General Public License for more details. | ||
18 | // | ||
19 | // You should have received a copy of the GNU Lesser General Public | ||
20 | // License along with this library; if not, write to the Free Software | ||
21 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
22 | // | ||
23 | // ************************************************************************************************* | ||
24 | |||
25 | #include "QVariantDelegate.h" | ||
26 | |||
27 | #include "Property.h" | ||
28 | |||
29 | #include <Qt/qabstractitemview.h> | ||
30 | |||
31 | |||
32 | QVariantDelegate::QVariantDelegate(QObject* parent) : QItemDelegate(parent) {} | ||
33 | |||
34 | |||
35 | QVariantDelegate::~QVariantDelegate() {} | ||
36 | |||
37 | QWidget *QVariantDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem& option , const QModelIndex & index ) const { | ||
38 | QWidget* editor = 0; | ||
39 | Property* p = static_cast<Property*>(index.internalPointer()); | ||
40 | switch (p->value().type()) { | ||
41 | case QVariant::Color: | ||
42 | case QVariant::Int: | ||
43 | case QMetaType::Float: | ||
44 | case QVariant::Double: | ||
45 | case QVariant::UserType: | ||
46 | editor = p->createEditor(parent, option); | ||
47 | if (editor) break; // if no editor could be created take default case | ||
48 | default: | ||
49 | editor = QItemDelegate::createEditor(parent, option, index); | ||
50 | } | ||
51 | parseEditorHints(editor, p->editorHints()); | ||
52 | return editor; | ||
53 | } | ||
54 | |||
55 | void QVariantDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const { | ||
56 | QVariant data = index.model()->data(index, Qt::EditRole); | ||
57 | switch (data.type()) { | ||
58 | case QVariant::Color: | ||
59 | case QMetaType::Double: | ||
60 | case QMetaType::Float: | ||
61 | case QVariant::UserType: | ||
62 | if (static_cast<Property*>(index.internalPointer())->setEditorData(editor, data)) // if editor couldn't be recognized use default | ||
63 | break; | ||
64 | default: | ||
65 | QItemDelegate::setEditorData(editor, index); | ||
66 | break; | ||
67 | } | ||
68 | } | ||
69 | |||
70 | void QVariantDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const { | ||
71 | QVariant data = index.model()->data(index, Qt::EditRole); | ||
72 | switch (data.type()) { | ||
73 | case QVariant::Color: | ||
74 | case QMetaType::Double: | ||
75 | case QMetaType::Float: | ||
76 | case QVariant::UserType: { | ||
77 | QVariant data = static_cast<Property*>(index.internalPointer())->editorData(editor); | ||
78 | if (data.isValid()) { | ||
79 | model->setData(index, data , Qt::EditRole); | ||
80 | break; | ||
81 | } | ||
82 | } | ||
83 | default: | ||
84 | QItemDelegate::setModelData(editor, model, index); | ||
85 | break; | ||
86 | } | ||
87 | } | ||
88 | |||
89 | void QVariantDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex& index ) const { | ||
90 | return QItemDelegate::updateEditorGeometry(editor, option, index); | ||
91 | } | ||
92 | |||
93 | void QVariantDelegate::parseEditorHints(QWidget* editor, const QString& editorHints) const { | ||
94 | if (editor && !editorHints.isEmpty()) { | ||
95 | // Parse for property values | ||
96 | QRegExp rx("(.*)(=\\s*)(.*)(;{1})"); | ||
97 | rx.setMinimal(true); | ||
98 | int pos = 0; | ||
99 | while ((pos = rx.indexIn(editorHints, pos)) != -1) { | ||
100 | qDebug("Setting %s to %s", qPrintable(rx.cap(1)), qPrintable(rx.cap(3))); | ||
101 | editor->setProperty(qPrintable(rx.cap(1).trimmed()), rx.cap(3).trimmed()); | ||
102 | pos += rx.matchedLength(); | ||
103 | } | ||
104 | } | ||
105 | } | ||
diff --git a/utils/wpseditor/gui/src/QPropertyEditor/QVariantDelegate.h b/utils/wpseditor/gui/src/QPropertyEditor/QVariantDelegate.h new file mode 100644 index 0000000000..e06265af82 --- /dev/null +++ b/utils/wpseditor/gui/src/QPropertyEditor/QVariantDelegate.h | |||
@@ -0,0 +1,78 @@ | |||
1 | // ************************************************************************************************* | ||
2 | // | ||
3 | // QPropertyEditor v 0.1 | ||
4 | // | ||
5 | // -------------------------------------- | ||
6 | // Copyright (C) 2007 Volker Wiendl | ||
7 | // | ||
8 | // | ||
9 | // This library is free software; you can redistribute it and/or | ||
10 | // modify it under the terms of the GNU Lesser General Public | ||
11 | // License as published by the Free Software Foundation; either | ||
12 | // version 2.1 of the License, or any later version. | ||
13 | // | ||
14 | // This library is distributed in the hope that it will be useful, | ||
15 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
17 | // Lesser General Public License for more details. | ||
18 | // | ||
19 | // You should have received a copy of the GNU Lesser General Public | ||
20 | // License along with this library; if not, write to the Free Software | ||
21 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
22 | // | ||
23 | // ************************************************************************************************* | ||
24 | |||
25 | #ifndef COLORSELECTIONBUTTON_H_ | ||
26 | #define COLORSELECTIONBUTTON_H_ | ||
27 | |||
28 | #include <Qt/qitemdelegate.h> | ||
29 | |||
30 | |||
31 | /** | ||
32 | * This class is used to create the editor widgets for datatypes encapsulated in QVariant variables | ||
33 | */ | ||
34 | class QVariantDelegate : public QItemDelegate { | ||
35 | Q_OBJECT | ||
36 | |||
37 | public: | ||
38 | /** | ||
39 | * Constructor | ||
40 | * @param parent optional parent object | ||
41 | */ | ||
42 | QVariantDelegate(QObject* parent = 0); | ||
43 | /// Destructor | ||
44 | virtual ~QVariantDelegate(); | ||
45 | |||
46 | /** | ||
47 | * Creates an editor widget as child of a given widget for a specific QModelIndex | ||
48 | * | ||
49 | * @param parent the parent widget for the editor | ||
50 | * @param option some style options that the editor should use | ||
51 | * @param index the index of the item the editor will be created for | ||
52 | * @return QWidget the editor widget | ||
53 | */ | ||
54 | QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const; | ||
55 | |||
56 | /** | ||
57 | * Tries to set the editor data based on the value stored at a specific QModelIndex | ||
58 | * @param editor the editor widget | ||
59 | * @param index the model index of the value that should be used in the editor | ||
60 | */ | ||
61 | virtual void setEditorData(QWidget *editor, const QModelIndex &index) const; | ||
62 | |||
63 | /** | ||
64 | * Sets the data of a specific QModelIndex to tha value of the editor widget | ||
65 | * @param editor the editor widget that contains the new value | ||
66 | * @param model the model that contains the index | ||
67 | * @param index the index within the model whose data value should be set to the data value of the editor | ||
68 | */ | ||
69 | virtual void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const; | ||
70 | |||
71 | /// QItemDelegate implementation | ||
72 | virtual void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const; | ||
73 | |||
74 | protected: | ||
75 | void parseEditorHints(QWidget* editor, const QString& editorHints) const; | ||
76 | |||
77 | }; | ||
78 | #endif | ||
diff --git a/utils/wpseditor/gui/src/main.cpp b/utils/wpseditor/gui/src/main.cpp new file mode 100644 index 0000000000..0ba22c9fce --- /dev/null +++ b/utils/wpseditor/gui/src/main.cpp | |||
@@ -0,0 +1,16 @@ | |||
1 | #include <QApplication> | ||
2 | #include "qwpseditorwindow.h" | ||
3 | #include "utils.h" | ||
4 | #include <QPointer> | ||
5 | |||
6 | QPointer<QWpsEditorWindow> win; | ||
7 | |||
8 | int main(int argc, char ** argv) { | ||
9 | QApplication app( argc, argv ); | ||
10 | |||
11 | win = new QWpsEditorWindow; | ||
12 | win->show(); | ||
13 | app.connect( &app, SIGNAL( lastWindowClosed() ), &app, SLOT( quit() ) ); | ||
14 | |||
15 | return app.exec(); | ||
16 | } | ||
diff --git a/utils/wpseditor/gui/src/qtrackstate.cpp b/utils/wpseditor/gui/src/qtrackstate.cpp new file mode 100644 index 0000000000..dad2f9a4aa --- /dev/null +++ b/utils/wpseditor/gui/src/qtrackstate.cpp | |||
@@ -0,0 +1,41 @@ | |||
1 | #include "qtrackstate.h" | ||
2 | #include <stdlib.h> | ||
3 | |||
4 | // | ||
5 | QTrackState::QTrackState( ) | ||
6 | : QObject() { | ||
7 | memset(&state,0,sizeof(state)); | ||
8 | state.title = (char*)"title"; | ||
9 | state.artist = (char*)"artist"; | ||
10 | state.album = (char*)"album"; | ||
11 | state.length = 100; | ||
12 | state.elapsed = 50; | ||
13 | } | ||
14 | |||
15 | void QTrackState::setTitle(const QString& name) { | ||
16 | state.title = new char[name.length()]; | ||
17 | strcpy(state.title,name.toAscii()); | ||
18 | emit stateChanged(state); | ||
19 | } | ||
20 | |||
21 | void QTrackState::setArtist(const QString& name) { | ||
22 | state.artist = new char[name.length()]; | ||
23 | strcpy(state.artist,name.toAscii()); | ||
24 | emit stateChanged(state); | ||
25 | } | ||
26 | |||
27 | void QTrackState::setAlbum(const QString& name) { | ||
28 | state.album = new char[name.length()]; | ||
29 | strcpy(state.album,name.toAscii()); | ||
30 | emit stateChanged(state); | ||
31 | } | ||
32 | |||
33 | void QTrackState::setLength(int le) { | ||
34 | state.length = le; | ||
35 | emit stateChanged(state); | ||
36 | } | ||
37 | |||
38 | void QTrackState::setElapsed(int le) { | ||
39 | state.elapsed = le; | ||
40 | emit stateChanged(state); | ||
41 | } | ||
diff --git a/utils/wpseditor/gui/src/qtrackstate.h b/utils/wpseditor/gui/src/qtrackstate.h new file mode 100644 index 0000000000..b57f7a8376 --- /dev/null +++ b/utils/wpseditor/gui/src/qtrackstate.h | |||
@@ -0,0 +1,57 @@ | |||
1 | #ifndef __QTRACKSTATE_H__ | ||
2 | #define __QTRACKSTATE_H__ | ||
3 | |||
4 | #include "wpsstate.h" | ||
5 | #include <QObject> | ||
6 | |||
7 | class QWpsState; | ||
8 | |||
9 | class QTrackState : public QObject { | ||
10 | Q_OBJECT | ||
11 | Q_CLASSINFO ( "QTrackState", "Mp3 State" ); | ||
12 | Q_PROPERTY ( QString Title READ title WRITE setTitle DESIGNABLE true USER true ) | ||
13 | Q_PROPERTY ( QString Artist READ artist WRITE setArtist DESIGNABLE true USER true ) | ||
14 | Q_PROPERTY ( QString Album READ album WRITE setAlbum DESIGNABLE true USER true ) | ||
15 | Q_PROPERTY ( int Length READ length WRITE setLength DESIGNABLE true USER true ) | ||
16 | Q_CLASSINFO("Length", "readOnly=true;value=100"); | ||
17 | Q_PROPERTY ( int Elapsed READ elapsed WRITE setElapsed DESIGNABLE true USER true ) | ||
18 | Q_CLASSINFO("Elapsed", "minimum=0;maximum=100;value=50"); | ||
19 | |||
20 | |||
21 | trackstate state; | ||
22 | |||
23 | public: | ||
24 | QTrackState(); | ||
25 | |||
26 | public slots: | ||
27 | QString title() const { | ||
28 | return state.title; | ||
29 | } | ||
30 | void setTitle ( const QString& name ); | ||
31 | |||
32 | QString artist() const { | ||
33 | return state.artist; | ||
34 | } | ||
35 | void setArtist ( const QString& name ); | ||
36 | |||
37 | QString album() const { | ||
38 | return state.album; | ||
39 | } | ||
40 | void setAlbum ( const QString& name ); | ||
41 | |||
42 | int length() const { | ||
43 | return state.length; | ||
44 | } | ||
45 | void setLength ( int l ); | ||
46 | |||
47 | int elapsed() const { | ||
48 | return state.elapsed; | ||
49 | } | ||
50 | void setElapsed ( int l ); | ||
51 | |||
52 | signals: | ||
53 | void stateChanged ( trackstate state ); | ||
54 | |||
55 | }; | ||
56 | |||
57 | #endif // __QTRACKSTATE_H__ | ||
diff --git a/utils/wpseditor/gui/src/qwpsdrawer.cpp b/utils/wpseditor/gui/src/qwpsdrawer.cpp new file mode 100644 index 0000000000..ab8a4b32d6 --- /dev/null +++ b/utils/wpseditor/gui/src/qwpsdrawer.cpp | |||
@@ -0,0 +1,200 @@ | |||
1 | #include "qwpsdrawer.h" | ||
2 | #include "slider.h" | ||
3 | #include "utils.h" | ||
4 | #include <QtGui> | ||
5 | #include <QLibrary> | ||
6 | #include <stdarg.h> | ||
7 | // | ||
8 | |||
9 | |||
10 | QPointer<QWpsDrawer> drawer; | ||
11 | QPixmap *QWpsDrawer::pix = NULL; | ||
12 | QString QWpsDrawer::mTmpWpsString; | ||
13 | QImage QWpsDrawer::backdrop; | ||
14 | proxy_api QWpsDrawer::api; | ||
15 | |||
16 | QWpsDrawer::QWpsDrawer( QWpsState *ws,QTrackState *ms, QWidget *parent ) | ||
17 | : QWidget(parent),wpsState(ws),trackState(ms),showGrid(false),mTargetLibName("libwps") { | ||
18 | |||
19 | tryResolve(); | ||
20 | memset(&api,0,sizeof(struct proxy_api)); | ||
21 | |||
22 | api.verbose = 2; | ||
23 | api.putsxy = &QWpsDrawer::putsxy; | ||
24 | api.transparent_bitmap_part = &QWpsDrawer::transparent_bitmap_part; | ||
25 | api.bitmap_part = &QWpsDrawer::bitmap_part; | ||
26 | api.drawpixel = &QWpsDrawer::drawpixel; | ||
27 | api.fillrect = &QWpsDrawer::fillrect; | ||
28 | api.hline = &QWpsDrawer::hline; | ||
29 | api.vline = &QWpsDrawer::vline; | ||
30 | api.clear_viewport = &QWpsDrawer::clear_viewport; | ||
31 | api.load_wps_backdrop = &QWpsDrawer::load_wps_backdrop; | ||
32 | api.read_bmp_file = &QWpsDrawer::read_bmp_file; | ||
33 | api.debugf = &qlogger; | ||
34 | newTempWps(); | ||
35 | } | ||
36 | |||
37 | bool QWpsDrawer::tryResolve() { | ||
38 | QLibrary lib(qApp->applicationDirPath()+"/"+mTargetLibName); | ||
39 | wps_init = (pfwps_init)lib.resolve("wps_init"); | ||
40 | wps_display = (pfwps_display)lib.resolve("wps_display"); | ||
41 | wps_refresh = (pfwps_refresh)lib.resolve("wps_refresh"); | ||
42 | mResolved = wps_init && wps_display && wps_refresh; | ||
43 | if (!mResolved) | ||
44 | DEBUGF1(tr("ERR: Failed to resolve funcs!")); | ||
45 | return mResolved; | ||
46 | } | ||
47 | QWpsDrawer::~QWpsDrawer() { | ||
48 | qDebug()<<"QWpsDrawer::~QWpsDrawer()"; | ||
49 | cleanTemp(); | ||
50 | } | ||
51 | |||
52 | void QWpsDrawer::mouseReleaseEvent ( QMouseEvent * event ) { | ||
53 | Q_UNUSED(event); | ||
54 | /*int x = event->x() - (this->width()-pix->width())/2, | ||
55 | y = event->y() - (this->height()-pix->height())/2; | ||
56 | DEBUGF1("x=%d,y=%d",x,y);*/ | ||
57 | } | ||
58 | void QWpsDrawer::newTempWps() { | ||
59 | QTemporaryFile tmpWps; | ||
60 | tmpWps.setAutoRemove(false); | ||
61 | tmpWps.setFileTemplate(QDir::tempPath()+"/XXXXXXXXXX.wps"); | ||
62 | if (tmpWps.open()) { | ||
63 | QString tmpDir = tmpWps.fileName().left(tmpWps.fileName().length()-4); | ||
64 | if (QDir::temp().mkpath(tmpDir)) { | ||
65 | mTmpWpsString = tmpDir; | ||
66 | DEBUGF1(mTmpWpsString); | ||
67 | } | ||
68 | } | ||
69 | } | ||
70 | |||
71 | void QWpsDrawer::WpsInit(QString buffer, bool isFile) { | ||
72 | |||
73 | if (!mResolved) | ||
74 | if (!tryResolve()) | ||
75 | return; | ||
76 | if (isFile) { | ||
77 | cleanTemp(); | ||
78 | DEBUGF1( tr("Loading %1").arg(buffer)); | ||
79 | QFile file(buffer); | ||
80 | if (file.open(QIODevice::ReadOnly | QIODevice::Text)) | ||
81 | mWpsString = file.readAll(); | ||
82 | newTempWps(); | ||
83 | } else | ||
84 | mWpsString = buffer; | ||
85 | { | ||
86 | QFile tfile(mTmpWpsString+".wps"); | ||
87 | if (tfile.open(QIODevice::WriteOnly | QIODevice::Text)) | ||
88 | tfile.write(mWpsString.toAscii(),mWpsString.length()); | ||
89 | } | ||
90 | |||
91 | if (isFile) | ||
92 | wps_init(buffer.toAscii(), &api, isFile); | ||
93 | else | ||
94 | wps_init(QString(mTmpWpsString+".wps").toAscii(), &api, true); | ||
95 | pix = new QPixmap(api.getwidth(),api.getheight()); | ||
96 | |||
97 | drawBackdrop(); | ||
98 | |||
99 | setMinimumWidth(api.getwidth()); | ||
100 | setMinimumHeight(api.getheight()); | ||
101 | |||
102 | update(); | ||
103 | } | ||
104 | |||
105 | void QWpsDrawer::paintEvent(QPaintEvent * event) { | ||
106 | if (!mResolved) | ||
107 | return; | ||
108 | if (pix==NULL) | ||
109 | return; | ||
110 | QPainter p(this); | ||
111 | QRect rect = event->rect(); | ||
112 | |||
113 | drawBackdrop(); | ||
114 | wps_refresh(); | ||
115 | |||
116 | if (showGrid) { | ||
117 | QPainter g(pix); | ||
118 | viewport_api avp; | ||
119 | api.get_current_vp(&avp); | ||
120 | |||
121 | g.setPen(Qt::green); | ||
122 | |||
123 | for (int i=0;i*avp.fontheight/1.5<avp.width ;i++) { | ||
124 | g.drawLine(int(i*avp.fontheight/1.5), 0, int(i*avp.fontheight/1.5), avp.height); | ||
125 | } | ||
126 | for (int j=0;j*avp.fontheight<avp.height; j++) { | ||
127 | g.drawLine(0,j*avp.fontheight,avp.width,j*avp.fontheight); | ||
128 | } | ||
129 | } | ||
130 | |||
131 | p.drawPixmap((rect.width()-pix->width())/2,(rect.height()-pix->height())/2,*pix); | ||
132 | |||
133 | } | ||
134 | |||
135 | void QWpsDrawer::clear_viewport(int x,int y,int w,int h, int color) { | ||
136 | DEBUGF2("clear_viewport(int x=%d,int y=%d,int w=%d,int h=%d, int color)",x,y,w,h); | ||
137 | QPainter p(pix); | ||
138 | //p.setOpacity(0.1); | ||
139 | //QImage img = backdrop.copy(x,y,w,h); | ||
140 | //p.drawImage(x,y,img); | ||
141 | } | ||
142 | |||
143 | void QWpsDrawer::slotSetVolume() { | ||
144 | Slider *slider = new Slider(this, tr("Volume"),-74,10); | ||
145 | slider->show(); | ||
146 | connect(slider, SIGNAL(valueChanged(int)), wpsState, SLOT(setVolume(int))); | ||
147 | connect(this, SIGNAL(destroyed()),slider, SLOT(close())); | ||
148 | } | ||
149 | |||
150 | void QWpsDrawer::slotSetProgress() { | ||
151 | Slider *slider = new Slider(this,tr("Progress"),0,100); | ||
152 | slider->show(); | ||
153 | connect(slider, SIGNAL(valueChanged(int)), trackState, SLOT(setElapsed(int))); | ||
154 | connect(this, SIGNAL(destroyed()),slider, SLOT(close())); | ||
155 | } | ||
156 | |||
157 | void QWpsDrawer::slotWpsStateChanged(wpsstate ws_) { | ||
158 | if (api.set_wpsstate) | ||
159 | api.set_wpsstate(ws_); | ||
160 | update(); | ||
161 | } | ||
162 | |||
163 | void QWpsDrawer::slotTrackStateChanged(trackstate ms_) { | ||
164 | if (api.set_wpsstate) | ||
165 | api.set_trackstate(ms_); | ||
166 | update(); | ||
167 | } | ||
168 | |||
169 | void QWpsDrawer::slotShowGrid(bool show) { | ||
170 | showGrid = show; | ||
171 | update(); | ||
172 | } | ||
173 | |||
174 | void QWpsDrawer::drawBackdrop() { | ||
175 | QPainter b(pix); | ||
176 | QImage pink = backdrop.createMaskFromColor(qRgb(255,0,255),Qt::MaskOutColor); | ||
177 | backdrop.setAlphaChannel(pink); | ||
178 | b.drawImage(0,0,backdrop); | ||
179 | } | ||
180 | |||
181 | void QWpsDrawer::slotSetAudioStatus(int status) { | ||
182 | api.set_audio_status(status); | ||
183 | update(); | ||
184 | } | ||
185 | |||
186 | void QWpsDrawer::cleanTemp(bool fileToo) { | ||
187 | if (fileToo) | ||
188 | QFile::remove(mTmpWpsString+".wps"); | ||
189 | QDirIterator it(mTmpWpsString, QDirIterator::Subdirectories); | ||
190 | while (it.hasNext()) { | ||
191 | QFile::remove(it.next()); | ||
192 | } | ||
193 | QDir(mTmpWpsString).rmdir(mTmpWpsString); | ||
194 | } | ||
195 | |||
196 | void QWpsDrawer::closeEvent(QCloseEvent *event) { | ||
197 | qDebug()<<"QWpsDrawer::closeEvent()"; | ||
198 | cleanTemp(); | ||
199 | event->accept(); | ||
200 | } | ||
diff --git a/utils/wpseditor/gui/src/qwpsdrawer.h b/utils/wpseditor/gui/src/qwpsdrawer.h new file mode 100644 index 0000000000..d4dfa6c7a2 --- /dev/null +++ b/utils/wpseditor/gui/src/qwpsdrawer.h | |||
@@ -0,0 +1,82 @@ | |||
1 | #ifndef WPSDRAWER_H | ||
2 | #define WPSDRAWER_H | ||
3 | // | ||
4 | #include <QWidget> | ||
5 | #include <QPixmap> | ||
6 | #include <QPointer> | ||
7 | #include <QTemporaryFile> | ||
8 | #include "api.h" | ||
9 | #include "qtrackstate.h" | ||
10 | #include "qwpsstate.h" | ||
11 | // | ||
12 | |||
13 | typedef int (*pfwps_init)(const char* buff,struct proxy_api *api, bool isfile); | ||
14 | typedef int (*pfwps_display)(); | ||
15 | typedef int (*pfwps_refresh)(); | ||
16 | |||
17 | class QWpsDrawer : public QWidget { | ||
18 | Q_OBJECT | ||
19 | |||
20 | pfwps_init wps_init; | ||
21 | pfwps_display wps_display; | ||
22 | pfwps_refresh wps_refresh; | ||
23 | |||
24 | static QPixmap *pix; | ||
25 | static QImage backdrop; | ||
26 | |||
27 | QWpsState *wpsState; | ||
28 | QTrackState *trackState; | ||
29 | |||
30 | bool showGrid; | ||
31 | bool mResolved; | ||
32 | QString mWpsString; | ||
33 | QString mTargetLibName; | ||
34 | static QString mTmpWpsString; | ||
35 | |||
36 | |||
37 | protected: | ||
38 | virtual void paintEvent(QPaintEvent * event); | ||
39 | virtual void closeEvent(QCloseEvent *event); | ||
40 | virtual void mouseReleaseEvent ( QMouseEvent * event ) ; | ||
41 | void drawBackdrop(); | ||
42 | void newTempWps(); | ||
43 | void cleanTemp(bool fileToo=true); | ||
44 | bool tryResolve(); | ||
45 | public: | ||
46 | QWpsDrawer(QWpsState *ws,QTrackState *ms, QWidget *parent=0); | ||
47 | ~QWpsDrawer(); | ||
48 | void WpsInit(QString buffer, bool isFile = true); | ||
49 | |||
50 | QString wpsString() const { | ||
51 | return mWpsString; | ||
52 | }; | ||
53 | QString tempWps() const { | ||
54 | return mTmpWpsString; | ||
55 | }; | ||
56 | |||
57 | |||
58 | static proxy_api api; | ||
59 | /***********Drawing api******************/ | ||
60 | static void putsxy(int x, int y, const unsigned char *str); | ||
61 | static void transparent_bitmap_part(const void *src, int src_x, int src_y, | ||
62 | int stride, int x, int y, int width, int height); | ||
63 | static void bitmap_part(const void *src, int src_x, int src_y, | ||
64 | int stride, int x, int y, int width, int height); | ||
65 | static void drawpixel(int x, int y); | ||
66 | static void fillrect(int x, int y, int width, int height); | ||
67 | static void hline(int x1, int x2, int y); | ||
68 | static void vline(int x, int y1, int y2); | ||
69 | static void clear_viewport(int x,int y,int w,int h, int color); | ||
70 | static bool load_wps_backdrop(char* filename); | ||
71 | static int read_bmp_file(const char* filename,int *width, int *height); | ||
72 | /****************************************/ | ||
73 | public slots: | ||
74 | void slotSetVolume(); | ||
75 | void slotSetProgress(); | ||
76 | |||
77 | void slotShowGrid(bool); | ||
78 | void slotWpsStateChanged(wpsstate); | ||
79 | void slotTrackStateChanged(trackstate); | ||
80 | void slotSetAudioStatus(int); | ||
81 | }; | ||
82 | #endif | ||
diff --git a/utils/wpseditor/gui/src/qwpsdrawer_static.cpp b/utils/wpseditor/gui/src/qwpsdrawer_static.cpp new file mode 100644 index 0000000000..bf94d28a5a --- /dev/null +++ b/utils/wpseditor/gui/src/qwpsdrawer_static.cpp | |||
@@ -0,0 +1,77 @@ | |||
1 | #include "qwpsdrawer.h" | ||
2 | #include <QPainter> | ||
3 | #include <QFile> | ||
4 | #include <QFileInfo> | ||
5 | #include "utils.h" | ||
6 | |||
7 | void QWpsDrawer::putsxy(int x, int y, const unsigned char *str) { | ||
8 | QPainter p(pix); | ||
9 | viewport_api avp; | ||
10 | api.get_current_vp(&avp); | ||
11 | p.setPen(Qt::gray); | ||
12 | |||
13 | |||
14 | QFont font("times",avp.fontheight,QFont::Bold); | ||
15 | p.setFont(font); | ||
16 | p.drawText(x+avp.x,y + avp.fontheight + avp.y,(char*)str); | ||
17 | } | ||
18 | void QWpsDrawer::transparent_bitmap_part(const void *src, int src_x, int src_y, | ||
19 | int stride, int x, int y, int width, int height) { | ||
20 | QImage img; | ||
21 | img.load((char*)src); | ||
22 | DEBUGF2("transparent_bitmap_part(const void *src=%s, int src_x=%d, int src_y=%d,int stride=%d, int x=%d, int y=%d, int width=%d, int height=%d",(char*)src,src_x, src_y,stride, x, y, width, height); | ||
23 | QPainter p(pix); | ||
24 | QPoint target(x,y); | ||
25 | QRectF source(src_x, src_y, width, height); | ||
26 | |||
27 | QImage pink = img.createMaskFromColor(qRgb(255,0,255),Qt::MaskOutColor); | ||
28 | img.setAlphaChannel(pink); | ||
29 | |||
30 | p.drawImage(target, img, source); | ||
31 | } | ||
32 | void QWpsDrawer::bitmap_part(const void *src, int src_x, int src_y, | ||
33 | int stride, int x, int y, int width, int height) { | ||
34 | transparent_bitmap_part(src,src_x,src_y,stride,x,y,width,height); | ||
35 | } | ||
36 | void QWpsDrawer::drawpixel(int x, int y) { | ||
37 | QPainter p(pix); | ||
38 | p.setPen(Qt::blue); | ||
39 | p.drawPoint(x,y); | ||
40 | } | ||
41 | void QWpsDrawer::fillrect(int x, int y, int width, int height) { | ||
42 | QPainter p(pix); | ||
43 | DEBUGF2("fillrect(int x=%d, int y=%d, int width=%d, int height=%d)\n",x, y, width, height); | ||
44 | p.setPen(Qt::green); | ||
45 | } | ||
46 | void QWpsDrawer::hline(int x1, int x2, int y) { | ||
47 | QPainter p(pix); | ||
48 | p.setPen(Qt::black); | ||
49 | p.drawLine(x1,y,x2,y); | ||
50 | } | ||
51 | void QWpsDrawer::vline(int x, int y1, int y2) { | ||
52 | QPainter p(pix); | ||
53 | p.setPen(Qt::black); | ||
54 | p.drawLine(x,y1,x,y2); | ||
55 | } | ||
56 | bool QWpsDrawer::load_wps_backdrop(char* filename) { | ||
57 | DEBUGF2("load backdrop: %s", filename); | ||
58 | QFile file(filename); | ||
59 | QFileInfo info(file); | ||
60 | file.copy(mTmpWpsString+"/"+info.fileName()); | ||
61 | backdrop.load(filename); | ||
62 | return true; | ||
63 | } | ||
64 | |||
65 | int QWpsDrawer::read_bmp_file(const char* filename,int *width, int *height) { | ||
66 | QImage img; | ||
67 | |||
68 | QFile file(filename); | ||
69 | QFileInfo info(file); | ||
70 | file.copy(mTmpWpsString+"/"+info.fileName()); | ||
71 | |||
72 | img.load(filename); | ||
73 | //qDebug()<<"QWpsDrawer::read_bmp_file"<<img.width()<<img.height(); | ||
74 | *width = img.width(); | ||
75 | *height = img.height(); | ||
76 | return 1; | ||
77 | } | ||
diff --git a/utils/wpseditor/gui/src/qwpseditorwindow.cpp b/utils/wpseditor/gui/src/qwpseditorwindow.cpp new file mode 100644 index 0000000000..c3090bd027 --- /dev/null +++ b/utils/wpseditor/gui/src/qwpseditorwindow.cpp | |||
@@ -0,0 +1,120 @@ | |||
1 | #include "qwpseditorwindow.h" | ||
2 | #include "qwpsdrawer.h" | ||
3 | #include "utils.h" | ||
4 | #include <QFileDialog> | ||
5 | #include <QDebug> | ||
6 | #include <QInputDialog> | ||
7 | |||
8 | enum api_playmode playmodes[PLAYMODES_NUM] = { | ||
9 | API_STATUS_PLAY, | ||
10 | API_STATUS_STOP, | ||
11 | API_STATUS_PAUSE, | ||
12 | API_STATUS_FASTFORWARD, | ||
13 | API_STATUS_FASTBACKWARD | ||
14 | }; | ||
15 | |||
16 | const char *playmodeNames[] = { | ||
17 | "Play", | ||
18 | "Stop", | ||
19 | "Pause", | ||
20 | "FastForward", | ||
21 | "FastBackward" | ||
22 | }; | ||
23 | |||
24 | QWpsEditorWindow::QWpsEditorWindow( QWidget * parent, Qt::WFlags f) | ||
25 | : QMainWindow(parent, f) { | ||
26 | logEdit = 0; | ||
27 | setupUi(this); | ||
28 | drawer = new QWpsDrawer(&wpsState,&trackState, this); | ||
29 | QWpsDrawer::api.verbose = 1; | ||
30 | //drawer->WpsInit("iCatcher.wps"); | ||
31 | setCentralWidget(drawer); | ||
32 | connectActions(); | ||
33 | m_propertyEditor->addObject(&trackState); | ||
34 | m_propertyEditor->addObject(&wpsState); | ||
35 | } | ||
36 | |||
37 | void QWpsEditorWindow::connectActions() { | ||
38 | qDebug()<<"connect actions"; | ||
39 | connect(actOpenWps, SIGNAL(triggered()), this, SLOT(slotOpenWps())); | ||
40 | connect(actSetVolume, SIGNAL(triggered()), drawer, SLOT(slotSetVolume())); | ||
41 | connect(actSetProgress, SIGNAL(triggered()), drawer, SLOT(slotSetProgress())); | ||
42 | connect(actShowGrid, SIGNAL(triggered(bool)), drawer, SLOT(slotShowGrid(bool))); | ||
43 | |||
44 | connect(actUpdatePlainWps, SIGNAL(triggered()), SLOT(slotUpdatePlainWps())); | ||
45 | connect(plainWpsEdit->document(), SIGNAL(modificationChanged(bool)), SLOT(slotPlainDocModChanged(bool))); | ||
46 | |||
47 | connect(&wpsState, SIGNAL(stateChanged(wpsstate)), drawer, SLOT(slotWpsStateChanged(wpsstate))); | ||
48 | connect(&trackState, SIGNAL(stateChanged(trackstate)), drawer, SLOT(slotTrackStateChanged(trackstate))); | ||
49 | connect(&wpsState, SIGNAL(stateChanged(wpsstate)), this, SLOT(slotWpsStateChanged(wpsstate))); | ||
50 | connect(&trackState, SIGNAL(stateChanged(trackstate)), this, SLOT(slotTrackStateChanged(trackstate))); | ||
51 | |||
52 | connect(actClearLog, SIGNAL(triggered()), logEdit, SLOT(clear())); | ||
53 | connect(actVerboseLevel, SIGNAL(triggered()), SLOT(slotVerboseLevel())); | ||
54 | |||
55 | actGroupAudios = new QActionGroup(this); | ||
56 | signalMapper = new QSignalMapper(this); | ||
57 | for (int i=0;i<PLAYMODES_NUM;i++) { | ||
58 | QAction *act = new QAction(playmodeNames[i],this); | ||
59 | act->setCheckable(true); | ||
60 | actGroupAudios->addAction(act); | ||
61 | connect(act,SIGNAL(triggered()),signalMapper,SLOT(map())); | ||
62 | signalMapper->setMapping(act, i); | ||
63 | menuPlay->addAction(act); | ||
64 | actAudios[playmodes[i]] = act; | ||
65 | } | ||
66 | connect(signalMapper, SIGNAL(mapped(int)), SIGNAL(signalAudioStatusChanged(int))); | ||
67 | connect(this, SIGNAL(signalAudioStatusChanged(int)), drawer, SLOT(slotSetAudioStatus(int))); | ||
68 | actGroupAudios->setEnabled(false); | ||
69 | } | ||
70 | |||
71 | void QWpsEditorWindow::slotWpsStateChanged(wpsstate) { | ||
72 | m_propertyEditor->updateObject(&wpsState); | ||
73 | m_propertyEditor->update(); | ||
74 | } | ||
75 | |||
76 | void QWpsEditorWindow::slotTrackStateChanged(trackstate) { | ||
77 | m_propertyEditor->updateObject(&trackState); | ||
78 | m_propertyEditor->update(); | ||
79 | } | ||
80 | |||
81 | void QWpsEditorWindow::slotOpenWps() { | ||
82 | QString wpsfile = QFileDialog::getOpenFileName(this, | ||
83 | tr("Open WPS"), "", tr("WPS Files (*.wps);; All Files (*.*)")); | ||
84 | if (wpsfile == "") { | ||
85 | DEBUGF1(tr("File wasn't chosen")); | ||
86 | return; | ||
87 | } | ||
88 | m_propertyEditor->setEnabled(true); | ||
89 | drawer->WpsInit(wpsfile); | ||
90 | plainWpsEdit->clear(); | ||
91 | plainWpsEdit->append(drawer->wpsString()); | ||
92 | trackState.setAlbum(trackState.album()); | ||
93 | actGroupAudios->setEnabled(true); | ||
94 | } | ||
95 | |||
96 | void QWpsEditorWindow::logMsg(QString s) { | ||
97 | logEdit->append(s); | ||
98 | } | ||
99 | |||
100 | void QWpsEditorWindow::slotVerboseLevel() { | ||
101 | bool ok; | ||
102 | int i = QInputDialog::getInteger(this, tr("Set Verbose Level"),tr("Level:"), QWpsDrawer::api.verbose, 0, 3, 1, &ok); | ||
103 | if (ok) | ||
104 | QWpsDrawer::api.verbose = i; | ||
105 | } | ||
106 | |||
107 | void QWpsEditorWindow::slotUpdatePlainWps() { | ||
108 | DEBUGF1(tr("Updating WPS")); | ||
109 | plainWpsEdit->document()->setModified(false); | ||
110 | drawer->WpsInit(plainWpsEdit->toPlainText(),false); | ||
111 | |||
112 | } | ||
113 | |||
114 | void QWpsEditorWindow::slotPlainDocModChanged(bool changed) { | ||
115 | if (changed) | ||
116 | dockPlainWps->setWindowTitle(tr("PlainWps*")); | ||
117 | else | ||
118 | dockPlainWps->setWindowTitle(tr("PlainWps")); | ||
119 | } | ||
120 | |||
diff --git a/utils/wpseditor/gui/src/qwpseditorwindow.h b/utils/wpseditor/gui/src/qwpseditorwindow.h new file mode 100644 index 0000000000..019eb63808 --- /dev/null +++ b/utils/wpseditor/gui/src/qwpseditorwindow.h | |||
@@ -0,0 +1,45 @@ | |||
1 | #ifndef MAINWINDOWIMPL_H | ||
2 | #define MAINWINDOWIMPL_H | ||
3 | // | ||
4 | #include <QMainWindow> | ||
5 | #include <QActionGroup> | ||
6 | #include <QSignalMapper> | ||
7 | #include "ui_mainwindow.h" | ||
8 | #include "wpsstate.h" | ||
9 | #include "qwpsdrawer.h" | ||
10 | #include "qwpsstate.h" | ||
11 | #include "qtrackstate.h" | ||
12 | // | ||
13 | class QWpsEditorWindow : public QMainWindow, public Ui::MainWindow { | ||
14 | Q_OBJECT | ||
15 | QWpsState wpsState; | ||
16 | QTrackState trackState; | ||
17 | QPointer<QWpsDrawer> drawer; | ||
18 | |||
19 | QHash<int, QAction*> actAudios; | ||
20 | QActionGroup *actGroupAudios; | ||
21 | QSignalMapper *signalMapper; | ||
22 | |||
23 | protected: | ||
24 | void connectActions(); | ||
25 | public: | ||
26 | QWpsEditorWindow( QWidget * parent = 0, Qt::WFlags f = 0 ); | ||
27 | void logMsg(QString s); | ||
28 | private slots: | ||
29 | void slotOpenWps(); | ||
30 | void slotVerboseLevel(); | ||
31 | void slotWpsStateChanged(wpsstate); | ||
32 | void slotTrackStateChanged(trackstate); | ||
33 | |||
34 | void slotUpdatePlainWps(); | ||
35 | void slotPlainDocModChanged(bool m); | ||
36 | |||
37 | signals: | ||
38 | void signalAudioStatusChanged(int); | ||
39 | |||
40 | }; | ||
41 | #endif | ||
42 | |||
43 | |||
44 | |||
45 | |||
diff --git a/utils/wpseditor/gui/src/qwpsstate.cpp b/utils/wpseditor/gui/src/qwpsstate.cpp new file mode 100644 index 0000000000..4244bf6293 --- /dev/null +++ b/utils/wpseditor/gui/src/qwpsstate.cpp | |||
@@ -0,0 +1,29 @@ | |||
1 | #include "qwpsstate.h" | ||
2 | |||
3 | QWpsState::QWpsState(): QObject() { | ||
4 | state.fontheight = 8; | ||
5 | state.fontwidth = 5; | ||
6 | state.volume = -30; | ||
7 | state.battery_level = 50; | ||
8 | |||
9 | } | ||
10 | |||
11 | void QWpsState::setFontHeight(int val) { | ||
12 | state.fontheight = val; | ||
13 | emit stateChanged(state); | ||
14 | } | ||
15 | |||
16 | void QWpsState::setFontWidth(int val) { | ||
17 | state.fontwidth = val; | ||
18 | emit stateChanged(state); | ||
19 | } | ||
20 | |||
21 | void QWpsState::setVolume(int val) { | ||
22 | state.volume = val; | ||
23 | emit stateChanged(state); | ||
24 | } | ||
25 | |||
26 | void QWpsState::setBattery(int val) { | ||
27 | state.battery_level = val; | ||
28 | emit stateChanged(state); | ||
29 | } | ||
diff --git a/utils/wpseditor/gui/src/qwpsstate.h b/utils/wpseditor/gui/src/qwpsstate.h new file mode 100644 index 0000000000..eb43531de6 --- /dev/null +++ b/utils/wpseditor/gui/src/qwpsstate.h | |||
@@ -0,0 +1,54 @@ | |||
1 | #ifndef __WPSSTATE_H__ | ||
2 | #define __WPSSTATE_H__ | ||
3 | |||
4 | #include <QObject> | ||
5 | #include "wpsstate.h" | ||
6 | |||
7 | class QWpsState : public QObject { | ||
8 | Q_OBJECT | ||
9 | |||
10 | |||
11 | Q_CLASSINFO("QWpsState", "WPS State"); | ||
12 | Q_PROPERTY(int FontHeight READ fontHeight WRITE setFontHeight DESIGNABLE true USER true) | ||
13 | Q_CLASSINFO("FontHeight", "minimum=6;maximum=20;value=10"); | ||
14 | Q_PROPERTY(int FontWidth READ fontWidth WRITE setFontWidth DESIGNABLE true USER true) | ||
15 | Q_CLASSINFO("FontWidth", "minimum=4;maximum=20;value=8"); | ||
16 | Q_PROPERTY(int Volume READ volume WRITE setVolume DESIGNABLE true USER true) | ||
17 | Q_CLASSINFO("Volume", "minimum=-74;maximum=24;value=-15"); | ||
18 | Q_PROPERTY(int Battery READ battery WRITE setBattery DESIGNABLE true USER true) | ||
19 | Q_CLASSINFO("Battery", "minimum=0;maximum=100;value=50"); | ||
20 | |||
21 | wpsstate state; | ||
22 | |||
23 | public: | ||
24 | QWpsState(); | ||
25 | |||
26 | int fontHeight() const { | ||
27 | return state.fontheight; | ||
28 | } | ||
29 | void setFontHeight(int val); | ||
30 | |||
31 | int fontWidth() const { | ||
32 | return state.fontwidth; | ||
33 | } | ||
34 | void setFontWidth(int val); | ||
35 | |||
36 | int battery() const { | ||
37 | return state.battery_level; | ||
38 | } | ||
39 | void setBattery(int val); | ||
40 | |||
41 | int volume() const { | ||
42 | return state.volume; | ||
43 | } | ||
44 | public slots: | ||
45 | void setVolume(int val); | ||
46 | |||
47 | |||
48 | |||
49 | |||
50 | |||
51 | signals: | ||
52 | void stateChanged ( wpsstate state ); | ||
53 | }; | ||
54 | #endif // __WPSSTATE_H__ | ||
diff --git a/utils/wpseditor/gui/src/slider.cpp b/utils/wpseditor/gui/src/slider.cpp new file mode 100644 index 0000000000..7e3c9a942c --- /dev/null +++ b/utils/wpseditor/gui/src/slider.cpp | |||
@@ -0,0 +1,20 @@ | |||
1 | #include "slider.h" | ||
2 | #include <QDebug> | ||
3 | // | ||
4 | Slider::Slider(QWidget *parent, QString caption, int min, int max ):QDialog(parent) { | ||
5 | setupUi ( this ); | ||
6 | connect(horslider, SIGNAL(valueChanged(int)), this, SIGNAL(valueChanged(int))); | ||
7 | connect(this, SIGNAL(valueChanged(int)), this, SLOT(slotValueChanged(int))); | ||
8 | setWindowTitle(caption); | ||
9 | horslider->setMinimum(min); | ||
10 | horslider->setMaximum(max); | ||
11 | } | ||
12 | // | ||
13 | int Slider::value() { | ||
14 | return horslider->value(); | ||
15 | } | ||
16 | void Slider::slotValueChanged(int step) { | ||
17 | setWindowTitle(tr("Value =%1 ").arg(step)); | ||
18 | } | ||
19 | |||
20 | |||
diff --git a/utils/wpseditor/gui/src/slider.h b/utils/wpseditor/gui/src/slider.h new file mode 100644 index 0000000000..2620731644 --- /dev/null +++ b/utils/wpseditor/gui/src/slider.h | |||
@@ -0,0 +1,21 @@ | |||
1 | #ifndef SLIDERIMPL_H | ||
2 | #define SLIDERIMPL_H | ||
3 | // | ||
4 | #include <QWidget> | ||
5 | #include <QDialog> | ||
6 | #include "ui_slider.h" | ||
7 | // | ||
8 | class Slider : public QDialog , Ui::slider { | ||
9 | Q_OBJECT | ||
10 | public slots: | ||
11 | void slotValueChanged(int step); | ||
12 | signals: | ||
13 | void valueChanged(int); | ||
14 | public: | ||
15 | Slider(QWidget *parent, QString caption, int min, int max ); | ||
16 | int value(); | ||
17 | |||
18 | |||
19 | |||
20 | }; | ||
21 | #endif | ||
diff --git a/utils/wpseditor/gui/src/utils.cpp b/utils/wpseditor/gui/src/utils.cpp new file mode 100644 index 0000000000..f18442555b --- /dev/null +++ b/utils/wpseditor/gui/src/utils.cpp | |||
@@ -0,0 +1,28 @@ | |||
1 | #include "utils.h" | ||
2 | #include <QPointer> | ||
3 | #include <QtGlobal> | ||
4 | #include "qwpseditorwindow.h" | ||
5 | |||
6 | extern QPointer<QWpsEditorWindow> win; | ||
7 | |||
8 | int qlogger(const char* fmt,...) { | ||
9 | va_list ap; | ||
10 | va_start(ap, fmt); | ||
11 | QString s; | ||
12 | s.vsprintf(fmt,ap); | ||
13 | va_end(ap); | ||
14 | s.replace("\n",""); | ||
15 | //qDebug()<<s; | ||
16 | if (win==0) | ||
17 | qDebug()<<s; | ||
18 | if (s.indexOf("ERR")>=0) | ||
19 | s = "<font color=red>"+s+"</font>"; | ||
20 | if (win!=0) | ||
21 | win->logMsg(s); | ||
22 | va_end(ap); | ||
23 | return s.length(); | ||
24 | } | ||
25 | |||
26 | int qlogger(const QString& s) { | ||
27 | return qlogger(s.toAscii().data()); | ||
28 | } | ||
diff --git a/utils/wpseditor/gui/src/utils.h b/utils/wpseditor/gui/src/utils.h new file mode 100644 index 0000000000..ae88d78249 --- /dev/null +++ b/utils/wpseditor/gui/src/utils.h | |||
@@ -0,0 +1,12 @@ | |||
1 | #ifndef __UTILS_H__ | ||
2 | #define __UTILS_H__ | ||
3 | |||
4 | #include <QDebug> | ||
5 | |||
6 | #define DEBUGF1 qlogger | ||
7 | #define DEBUGF2(...) | ||
8 | |||
9 | extern int qlogger(const char* fmt,...); | ||
10 | extern int qlogger(const QString& s); | ||
11 | |||
12 | #endif // __UTILS_H__ | ||
diff --git a/utils/wpseditor/gui/ui/mainwindow.ui b/utils/wpseditor/gui/ui/mainwindow.ui new file mode 100644 index 0000000000..cd3f52bd66 --- /dev/null +++ b/utils/wpseditor/gui/ui/mainwindow.ui | |||
@@ -0,0 +1,290 @@ | |||
1 | <ui version="4.0" > | ||
2 | <class>MainWindow</class> | ||
3 | <widget class="QMainWindow" name="MainWindow" > | ||
4 | <property name="geometry" > | ||
5 | <rect> | ||
6 | <x>0</x> | ||
7 | <y>0</y> | ||
8 | <width>882</width> | ||
9 | <height>669</height> | ||
10 | </rect> | ||
11 | </property> | ||
12 | <property name="windowTitle" > | ||
13 | <string>WPS Editor</string> | ||
14 | </property> | ||
15 | <widget class="QWidget" name="centralwidget" > | ||
16 | <property name="geometry" > | ||
17 | <rect> | ||
18 | <x>260</x> | ||
19 | <y>21</y> | ||
20 | <width>344</width> | ||
21 | <height>345</height> | ||
22 | </rect> | ||
23 | </property> | ||
24 | </widget> | ||
25 | <widget class="QMenuBar" name="menubar" > | ||
26 | <property name="geometry" > | ||
27 | <rect> | ||
28 | <x>0</x> | ||
29 | <y>0</y> | ||
30 | <width>882</width> | ||
31 | <height>21</height> | ||
32 | </rect> | ||
33 | </property> | ||
34 | <widget class="QMenu" name="menuFile" > | ||
35 | <property name="title" > | ||
36 | <string>File</string> | ||
37 | </property> | ||
38 | <addaction name="actOpenWps" /> | ||
39 | <addaction name="actSetVolume" /> | ||
40 | <addaction name="actSetProgress" /> | ||
41 | <addaction name="actShowGrid" /> | ||
42 | <addaction name="actClearLog" /> | ||
43 | <addaction name="actVerboseLevel" /> | ||
44 | <addaction name="actQuit" /> | ||
45 | </widget> | ||
46 | <widget class="QMenu" name="menuPlay" > | ||
47 | <property name="title" > | ||
48 | <string>Play</string> | ||
49 | </property> | ||
50 | </widget> | ||
51 | <addaction name="menuFile" /> | ||
52 | <addaction name="menuPlay" /> | ||
53 | </widget> | ||
54 | <widget class="QStatusBar" name="statusbar" > | ||
55 | <property name="geometry" > | ||
56 | <rect> | ||
57 | <x>0</x> | ||
58 | <y>650</y> | ||
59 | <width>882</width> | ||
60 | <height>19</height> | ||
61 | </rect> | ||
62 | </property> | ||
63 | </widget> | ||
64 | <widget class="QDockWidget" name="dockPlainWps" > | ||
65 | <property name="geometry" > | ||
66 | <rect> | ||
67 | <x>0</x> | ||
68 | <y>370</y> | ||
69 | <width>882</width> | ||
70 | <height>280</height> | ||
71 | </rect> | ||
72 | </property> | ||
73 | <property name="minimumSize" > | ||
74 | <size> | ||
75 | <width>0</width> | ||
76 | <height>30</height> | ||
77 | </size> | ||
78 | </property> | ||
79 | <property name="windowTitle" > | ||
80 | <string>PlainWps</string> | ||
81 | </property> | ||
82 | <attribute name="dockWidgetArea" > | ||
83 | <number>8</number> | ||
84 | </attribute> | ||
85 | <widget class="QWidget" name="dockWidgetContents_3" > | ||
86 | <property name="geometry" > | ||
87 | <rect> | ||
88 | <x>0</x> | ||
89 | <y>22</y> | ||
90 | <width>882</width> | ||
91 | <height>258</height> | ||
92 | </rect> | ||
93 | </property> | ||
94 | <layout class="QGridLayout" name="gridLayout_2" > | ||
95 | <item rowspan="2" row="0" column="0" > | ||
96 | <widget class="QTextEdit" name="plainWpsEdit" > | ||
97 | <property name="autoFillBackground" > | ||
98 | <bool>false</bool> | ||
99 | </property> | ||
100 | <property name="readOnly" > | ||
101 | <bool>false</bool> | ||
102 | </property> | ||
103 | </widget> | ||
104 | </item> | ||
105 | <item row="0" column="1" > | ||
106 | <widget class="QPushButton" name="btnUpdatePlainWps" > | ||
107 | <property name="text" > | ||
108 | <string>Update WPS</string> | ||
109 | </property> | ||
110 | </widget> | ||
111 | </item> | ||
112 | <item row="1" column="1" > | ||
113 | <spacer name="verticalSpacer" > | ||
114 | <property name="orientation" > | ||
115 | <enum>Qt::Vertical</enum> | ||
116 | </property> | ||
117 | <property name="sizeHint" stdset="0" > | ||
118 | <size> | ||
119 | <width>20</width> | ||
120 | <height>211</height> | ||
121 | </size> | ||
122 | </property> | ||
123 | </spacer> | ||
124 | </item> | ||
125 | </layout> | ||
126 | </widget> | ||
127 | </widget> | ||
128 | <widget class="QDockWidget" name="m_dockWidget" > | ||
129 | <property name="geometry" > | ||
130 | <rect> | ||
131 | <x>0</x> | ||
132 | <y>21</y> | ||
133 | <width>256</width> | ||
134 | <height>345</height> | ||
135 | </rect> | ||
136 | </property> | ||
137 | <property name="windowTitle" > | ||
138 | <string>Property Editor</string> | ||
139 | </property> | ||
140 | <attribute name="dockWidgetArea" > | ||
141 | <number>1</number> | ||
142 | </attribute> | ||
143 | <widget class="QPropertyEditorWidget" name="m_propertyEditor" > | ||
144 | <property name="enabled" > | ||
145 | <bool>false</bool> | ||
146 | </property> | ||
147 | <property name="geometry" > | ||
148 | <rect> | ||
149 | <x>0</x> | ||
150 | <y>22</y> | ||
151 | <width>256</width> | ||
152 | <height>323</height> | ||
153 | </rect> | ||
154 | </property> | ||
155 | </widget> | ||
156 | </widget> | ||
157 | <widget class="QDockWidget" name="dockWidget" > | ||
158 | <property name="geometry" > | ||
159 | <rect> | ||
160 | <x>608</x> | ||
161 | <y>21</y> | ||
162 | <width>274</width> | ||
163 | <height>345</height> | ||
164 | </rect> | ||
165 | </property> | ||
166 | <property name="minimumSize" > | ||
167 | <size> | ||
168 | <width>0</width> | ||
169 | <height>30</height> | ||
170 | </size> | ||
171 | </property> | ||
172 | <property name="windowTitle" > | ||
173 | <string>Log</string> | ||
174 | </property> | ||
175 | <attribute name="dockWidgetArea" > | ||
176 | <number>2</number> | ||
177 | </attribute> | ||
178 | <widget class="QWidget" name="dockWidgetContents" > | ||
179 | <property name="geometry" > | ||
180 | <rect> | ||
181 | <x>0</x> | ||
182 | <y>22</y> | ||
183 | <width>274</width> | ||
184 | <height>323</height> | ||
185 | </rect> | ||
186 | </property> | ||
187 | <layout class="QGridLayout" name="gridLayout" > | ||
188 | <item row="0" column="0" > | ||
189 | <widget class="QTextEdit" name="logEdit" > | ||
190 | <property name="autoFillBackground" > | ||
191 | <bool>false</bool> | ||
192 | </property> | ||
193 | <property name="readOnly" > | ||
194 | <bool>true</bool> | ||
195 | </property> | ||
196 | </widget> | ||
197 | </item> | ||
198 | </layout> | ||
199 | </widget> | ||
200 | </widget> | ||
201 | <action name="actQuit" > | ||
202 | <property name="text" > | ||
203 | <string>Quit</string> | ||
204 | </property> | ||
205 | </action> | ||
206 | <action name="actOpenWps" > | ||
207 | <property name="text" > | ||
208 | <string>Open WPS</string> | ||
209 | </property> | ||
210 | </action> | ||
211 | <action name="actSetVolume" > | ||
212 | <property name="text" > | ||
213 | <string>Set Volume</string> | ||
214 | </property> | ||
215 | </action> | ||
216 | <action name="actSetProgress" > | ||
217 | <property name="text" > | ||
218 | <string>Set Progress</string> | ||
219 | </property> | ||
220 | </action> | ||
221 | <action name="actShowGrid" > | ||
222 | <property name="checkable" > | ||
223 | <bool>true</bool> | ||
224 | </property> | ||
225 | <property name="checked" > | ||
226 | <bool>false</bool> | ||
227 | </property> | ||
228 | <property name="text" > | ||
229 | <string>Show Grid</string> | ||
230 | </property> | ||
231 | </action> | ||
232 | <action name="actClearLog" > | ||
233 | <property name="text" > | ||
234 | <string>Clear Log</string> | ||
235 | </property> | ||
236 | </action> | ||
237 | <action name="actVerboseLevel" > | ||
238 | <property name="text" > | ||
239 | <string>Verbose Level</string> | ||
240 | </property> | ||
241 | </action> | ||
242 | <action name="actUpdatePlainWps" > | ||
243 | <property name="text" > | ||
244 | <string>Update WPS</string> | ||
245 | </property> | ||
246 | </action> | ||
247 | </widget> | ||
248 | <customwidgets> | ||
249 | <customwidget> | ||
250 | <class>QPropertyEditorWidget</class> | ||
251 | <extends>QTreeView</extends> | ||
252 | <header>QPropertyEditorWidget.h</header> | ||
253 | </customwidget> | ||
254 | </customwidgets> | ||
255 | <resources/> | ||
256 | <connections> | ||
257 | <connection> | ||
258 | <sender>btnUpdatePlainWps</sender> | ||
259 | <signal>clicked()</signal> | ||
260 | <receiver>actUpdatePlainWps</receiver> | ||
261 | <slot>trigger()</slot> | ||
262 | <hints> | ||
263 | <hint type="sourcelabel" > | ||
264 | <x>835</x> | ||
265 | <y>411</y> | ||
266 | </hint> | ||
267 | <hint type="destinationlabel" > | ||
268 | <x>-1</x> | ||
269 | <y>-1</y> | ||
270 | </hint> | ||
271 | </hints> | ||
272 | </connection> | ||
273 | <connection> | ||
274 | <sender>actQuit</sender> | ||
275 | <signal>triggered()</signal> | ||
276 | <receiver>MainWindow</receiver> | ||
277 | <slot>close()</slot> | ||
278 | <hints> | ||
279 | <hint type="sourcelabel" > | ||
280 | <x>-1</x> | ||
281 | <y>-1</y> | ||
282 | </hint> | ||
283 | <hint type="destinationlabel" > | ||
284 | <x>440</x> | ||
285 | <y>334</y> | ||
286 | </hint> | ||
287 | </hints> | ||
288 | </connection> | ||
289 | </connections> | ||
290 | </ui> | ||
diff --git a/utils/wpseditor/gui/ui/slider.ui b/utils/wpseditor/gui/ui/slider.ui new file mode 100644 index 0000000000..24fff0bf23 --- /dev/null +++ b/utils/wpseditor/gui/ui/slider.ui | |||
@@ -0,0 +1,43 @@ | |||
1 | <ui version="4.0" > | ||
2 | <class>slider</class> | ||
3 | <widget class="QWidget" name="slider" > | ||
4 | <property name="geometry" > | ||
5 | <rect> | ||
6 | <x>0</x> | ||
7 | <y>0</y> | ||
8 | <width>295</width> | ||
9 | <height>37</height> | ||
10 | </rect> | ||
11 | </property> | ||
12 | <property name="windowTitle" > | ||
13 | <string>Value</string> | ||
14 | </property> | ||
15 | <widget class="QSlider" name="horslider" > | ||
16 | <property name="geometry" > | ||
17 | <rect> | ||
18 | <x>0</x> | ||
19 | <y>10</y> | ||
20 | <width>291</width> | ||
21 | <height>21</height> | ||
22 | </rect> | ||
23 | </property> | ||
24 | <property name="minimum" > | ||
25 | <number>-78</number> | ||
26 | </property> | ||
27 | <property name="maximum" > | ||
28 | <number>24</number> | ||
29 | </property> | ||
30 | <property name="singleStep" > | ||
31 | <number>1</number> | ||
32 | </property> | ||
33 | <property name="value" > | ||
34 | <number>-78</number> | ||
35 | </property> | ||
36 | <property name="orientation" > | ||
37 | <enum>Qt::Horizontal</enum> | ||
38 | </property> | ||
39 | </widget> | ||
40 | </widget> | ||
41 | <resources/> | ||
42 | <connections/> | ||
43 | </ui> | ||