summaryrefslogtreecommitdiff
path: root/utils/wpseditor/gui
diff options
context:
space:
mode:
Diffstat (limited to 'utils/wpseditor/gui')
-rw-r--r--utils/wpseditor/gui/gui.pro44
-rw-r--r--utils/wpseditor/gui/src/QPropertyEditor/ColorCombo.cpp73
-rw-r--r--utils/wpseditor/gui/src/QPropertyEditor/ColorCombo.h49
-rw-r--r--utils/wpseditor/gui/src/QPropertyEditor/Property.cpp136
-rw-r--r--utils/wpseditor/gui/src/QPropertyEditor/Property.h157
-rw-r--r--utils/wpseditor/gui/src/QPropertyEditor/QPropertyEditor.pro26
-rw-r--r--utils/wpseditor/gui/src/QPropertyEditor/QPropertyEditorWidget.cpp56
-rw-r--r--utils/wpseditor/gui/src/QPropertyEditor/QPropertyEditorWidget.h113
-rw-r--r--utils/wpseditor/gui/src/QPropertyEditor/QPropertyModel.cpp236
-rw-r--r--utils/wpseditor/gui/src/QPropertyEditor/QPropertyModel.h105
-rw-r--r--utils/wpseditor/gui/src/QPropertyEditor/QVariantDelegate.cpp105
-rw-r--r--utils/wpseditor/gui/src/QPropertyEditor/QVariantDelegate.h78
-rw-r--r--utils/wpseditor/gui/src/main.cpp37
-rw-r--r--utils/wpseditor/gui/src/numberedtextview.cpp181
-rw-r--r--utils/wpseditor/gui/src/numberedtextview.h87
-rw-r--r--utils/wpseditor/gui/src/qsyntaxer.cpp64
-rw-r--r--utils/wpseditor/gui/src/qsyntaxer.h42
-rw-r--r--utils/wpseditor/gui/src/qtrackstate.cpp62
-rw-r--r--utils/wpseditor/gui/src/qtrackstate.h75
-rw-r--r--utils/wpseditor/gui/src/qwpsdrawer.cpp274
-rw-r--r--utils/wpseditor/gui/src/qwpsdrawer.h118
-rw-r--r--utils/wpseditor/gui/src/qwpsdrawer_static.cpp97
-rw-r--r--utils/wpseditor/gui/src/qwpseditorwindow.cpp191
-rw-r--r--utils/wpseditor/gui/src/qwpseditorwindow.h79
-rw-r--r--utils/wpseditor/gui/src/qwpsstate.cpp50
-rw-r--r--utils/wpseditor/gui/src/qwpsstate.h75
-rw-r--r--utils/wpseditor/gui/src/slider.cpp42
-rw-r--r--utils/wpseditor/gui/src/slider.h43
-rw-r--r--utils/wpseditor/gui/src/utils.cpp48
-rw-r--r--utils/wpseditor/gui/src/utils.h34
-rw-r--r--utils/wpseditor/gui/ui/mainwindow.ui242
-rw-r--r--utils/wpseditor/gui/ui/slider.ui43
32 files changed, 0 insertions, 3062 deletions
diff --git a/utils/wpseditor/gui/gui.pro b/utils/wpseditor/gui/gui.pro
deleted file mode 100644
index 088ab04119..0000000000
--- a/utils/wpseditor/gui/gui.pro
+++ /dev/null
@@ -1,44 +0,0 @@
1TEMPLATE = app
2TARGET =
3DEPENDPATH += . build src ui
4INCLUDEPATH += . src src/QPropertyEditor ../libwps/src
5DESTDIR = bin
6OBJECTS_DIR = build
7MOC_DIR = build
8UI_DIR = build
9QMAKE_LIBDIR += lib
10QT = gui core
11CONFIG += qt warn_on debug
12HEADERS += ../libwps/src/api.h \
13 ../libwps/src/defs.h \
14 src/slider.h \
15 src/qtrackstate.h \
16 src/qwpsstate.h \
17 src/qwpseditorwindow.h \
18 src/utils.h \
19 src/qwpsdrawer.h \
20 src/qsyntaxer.h \
21 src/numberedtextview.h
22
23FORMS += ui/mainwindow.ui ui/slider.ui
24SOURCES += 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 src/qsyntaxer.cpp \
33 src/numberedtextview.cpp
34
35 LIBS += -Lbin
36CONFIG(debug, debug|release) {
37 LIBS += -lQPropertyEditord
38 TARGET = wpseditord
39 CONFIG += console
40}
41CONFIG(release, debug|release) {
42 LIBS += -lQPropertyEditor
43 TARGET = wpseditor
44}
diff --git a/utils/wpseditor/gui/src/QPropertyEditor/ColorCombo.cpp b/utils/wpseditor/gui/src/QPropertyEditor/ColorCombo.cpp
deleted file mode 100644
index f5eeb030dc..0000000000
--- a/utils/wpseditor/gui/src/QPropertyEditor/ColorCombo.cpp
+++ /dev/null
@@ -1,73 +0,0 @@
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
32ColorCombo::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
44ColorCombo::~ColorCombo() {}
45
46
47QColor ColorCombo::color() const {
48 return qVariantValue<QColor>(itemData(currentIndex(), Qt::DecorationRole));
49}
50
51void 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
61void 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
deleted file mode 100644
index 530b05bbc5..0000000000
--- a/utils/wpseditor/gui/src/QPropertyEditor/ColorCombo.h
+++ /dev/null
@@ -1,49 +0,0 @@
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
33class ColorCombo : public QComboBox {
34 Q_OBJECT
35public:
36 ColorCombo(QWidget* parent = 0);
37 virtual ~ColorCombo();
38
39 QColor color() const;
40 void setColor(QColor c);
41
42private slots:
43 void currentChanged(int index);
44
45private:
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
deleted file mode 100644
index 0746d15140..0000000000
--- a/utils/wpseditor/gui/src/QPropertyEditor/Property.cpp
+++ /dev/null
@@ -1,136 +0,0 @@
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
31Property::Property(const QString& name /*= QString()*/, QObject* propertyObject /*= 0*/, QObject* parent /*= 0*/) : QObject(parent),
32 m_propertyObject(propertyObject) {
33 setObjectName(name);
34}
35
36QVariant 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
43void Property::setValue(const QVariant &value) {
44 if (m_propertyObject)
45 m_propertyObject->setProperty(qPrintable(objectName()), value);
46}
47
48bool 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
55QWidget* 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
81bool 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
104QVariant 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
119Property* 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
130void Property::setValue(double value) {
131 setValue(QVariant(value));
132}
133
134void 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
deleted file mode 100644
index 52d6842987..0000000000
--- a/utils/wpseditor/gui/src/QPropertyEditor/Property.h
+++ /dev/null
@@ -1,157 +0,0 @@
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 */
37class Property : public QObject {
38 Q_OBJECT
39
40public:
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
137private 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
151private:
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
deleted file mode 100644
index ad1e31ce9a..0000000000
--- a/utils/wpseditor/gui/src/QPropertyEditor/QPropertyEditor.pro
+++ /dev/null
@@ -1,26 +0,0 @@
1TEMPLATE = lib
2CONFIG += staticlib debug
3SOURCES = ColorCombo.cpp \
4 Property.cpp \
5 QPropertyEditorWidget.cpp \
6 QPropertyModel.cpp \
7 QVariantDelegate.cpp
8HEADERS = ColorCombo.h \
9 Property.h \
10 QPropertyEditorWidget.h \
11 QPropertyModel.h \
12 QVariantDelegate.h
13INCLUDEPATH += .
14DESTDIR = ../../lib
15UI_DIR = .
16CONFIG(debug, debug|release) {
17 TARGET = QPropertyEditord
18 OBJECTS_DIR = ../../build/QPropertyEditor/debug
19 MOC_DIR = ../../build/QPropertyEditor/debug
20}
21CONFIG(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
deleted file mode 100644
index fc4b90c227..0000000000
--- a/utils/wpseditor/gui/src/QPropertyEditor/QPropertyEditorWidget.cpp
+++ /dev/null
@@ -1,56 +0,0 @@
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
30QPropertyEditorWidget::QPropertyEditorWidget(QWidget* parent /*= 0*/) : QTreeView(parent) {
31 m_model = new QPropertyModel(this);
32 setModel(m_model);
33 setItemDelegate(new QVariantDelegate(this));
34}
35
36
37QPropertyEditorWidget::~QPropertyEditorWidget() {}
38
39void QPropertyEditorWidget::addObject(QObject* propertyObject) {
40 m_model->addItem(propertyObject);
41 expandToDepth(0);
42}
43
44void QPropertyEditorWidget::setObject(QObject* propertyObject) {
45 m_model->clear();
46 if (propertyObject)
47 addObject(propertyObject);
48}
49
50void QPropertyEditorWidget::updateObject(QObject* propertyObject) {
51 m_model->updateItem(propertyObject);
52}
53
54void 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
deleted file mode 100644
index 2dab87722a..0000000000
--- a/utils/wpseditor/gui/src/QPropertyEditor/QPropertyEditorWidget.h
+++ /dev/null
@@ -1,113 +0,0 @@
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
30class QPropertyModel;
31class 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 */
56class QPropertyEditorWidget : public QTreeView {
57 Q_OBJECT
58public:
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
108private:
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
deleted file mode 100644
index b147cd089d..0000000000
--- a/utils/wpseditor/gui/src/QPropertyEditor/QPropertyModel.cpp
+++ /dev/null
@@ -1,236 +0,0 @@
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
33struct 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
45QPropertyModel::QPropertyModel(QObject* parent /*= 0*/) : QAbstractItemModel(parent), m_userCallback(0) {
46 m_rootItem = new Property("Root",0, this);
47}
48
49
50QPropertyModel::~QPropertyModel() {}
51
52QModelIndex 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
62QModelIndex 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
75int 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
82int QPropertyModel::columnCount ( const QModelIndex & parent /*= QModelIndex()*/ ) const {
83 (void)parent;
84 return 2;
85}
86
87QVariant 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
109bool 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
119Qt::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
133QVariant 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
145QModelIndex 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
151void 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
217void 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
227void QPropertyModel::clear() {
228 beginRemoveRows(QModelIndex(), 0, rowCount());
229 delete m_rootItem;
230 m_rootItem = new Property("Root",0, this);
231 endRemoveRows();
232}
233
234void 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
deleted file mode 100644
index 8a52bbe87c..0000000000
--- a/utils/wpseditor/gui/src/QPropertyEditor/QPropertyModel.h
+++ /dev/null
@@ -1,105 +0,0 @@
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
32class Property;
33
34/**
35 * The QPropertyModel handles the user defined properties of QObjects
36 */
37class QPropertyModel : public QAbstractItemModel {
38 Q_OBJECT
39public:
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
96private:
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
deleted file mode 100644
index ebda9b2c31..0000000000
--- a/utils/wpseditor/gui/src/QPropertyEditor/QVariantDelegate.cpp
+++ /dev/null
@@ -1,105 +0,0 @@
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
32QVariantDelegate::QVariantDelegate(QObject* parent) : QItemDelegate(parent) {}
33
34
35QVariantDelegate::~QVariantDelegate() {}
36
37QWidget *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
55void 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
70void 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
89void QVariantDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex& index ) const {
90 return QItemDelegate::updateEditorGeometry(editor, option, index);
91}
92
93void 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
deleted file mode 100644
index e06265af82..0000000000
--- a/utils/wpseditor/gui/src/QPropertyEditor/QVariantDelegate.h
+++ /dev/null
@@ -1,78 +0,0 @@
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 */
34class QVariantDelegate : public QItemDelegate {
35 Q_OBJECT
36
37public:
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
74protected:
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
deleted file mode 100644
index 9c07120007..0000000000
--- a/utils/wpseditor/gui/src/main.cpp
+++ /dev/null
@@ -1,37 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 *
9 * Copyright (C) 2007 by Rostilav Checkan
10 * $Id$
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#include <QApplication>
23#include "qwpseditorwindow.h"
24#include "utils.h"
25#include <QPointer>
26
27QPointer<QWpsEditorWindow> win;
28
29int main(int argc, char ** argv) {
30 QApplication app( argc, argv );
31
32 win = new QWpsEditorWindow;
33 win->show();
34 app.connect( &app, SIGNAL( lastWindowClosed() ), &app, SLOT( quit() ) );
35
36 return app.exec();
37}
diff --git a/utils/wpseditor/gui/src/numberedtextview.cpp b/utils/wpseditor/gui/src/numberedtextview.cpp
deleted file mode 100644
index 81c4208b59..0000000000
--- a/utils/wpseditor/gui/src/numberedtextview.cpp
+++ /dev/null
@@ -1,181 +0,0 @@
1/* This file is part of the KDE libraries
2 Copyright (C) 2005, 2006 KJSEmbed Authors
3 See included AUTHORS file.
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19
20
21 --------------------------------------------------------------------------------------
22 Imported into the WPS editor and simplified by Dominik Wenger
23
24*/
25
26
27#include <QTextDocument>
28#include <QTextBlock>
29#include <QTextEdit>
30#include <QHBoxLayout>
31#include <QScrollBar>
32#include <QPainter>
33#include <QAbstractTextDocumentLayout>
34#include <QDebug>
35
36#include "numberedtextview.h"
37
38NumberBar::NumberBar( QWidget *parent )
39 : QWidget( parent ), edit(0), markedLine(-1)
40{
41 // Make room for 4 digits and the breakpoint icon
42 setFixedWidth( fontMetrics().width( QString("0000") + 10 + 32 ) );
43 markerIcon = QPixmap( "images/marker.png" );
44}
45
46NumberBar::~NumberBar()
47{
48}
49
50
51void NumberBar::markLine( int lineno )
52{
53 markedLine = lineno;
54}
55
56void NumberBar::setTextEdit( QTextEdit *edit )
57{
58 this->edit = edit;
59 connect( edit->document()->documentLayout(), SIGNAL( update(const QRectF &) ),
60 this, SLOT( update() ) );
61 connect( edit->verticalScrollBar(), SIGNAL(valueChanged(int) ),
62 this, SLOT( update() ) );
63}
64
65void NumberBar::paintEvent( QPaintEvent * )
66{
67 QAbstractTextDocumentLayout *layout = edit->document()->documentLayout();
68 int contentsY = edit->verticalScrollBar()->value();
69 qreal pageBottom = contentsY + edit->viewport()->height();
70 const QFontMetrics fm = fontMetrics();
71 const int ascent = fontMetrics().ascent() + 1; // height = ascent + descent + 1
72 int lineCount = 1;
73
74 QPainter p(this);
75
76 markedRect = QRect();
77
78 for ( QTextBlock block = edit->document()->begin();
79 block.isValid(); block = block.next(), ++lineCount )
80 {
81
82 const QRectF boundingRect = layout->blockBoundingRect( block );
83
84 QPointF position = boundingRect.topLeft();
85 if ( position.y() + boundingRect.height() < contentsY )
86 continue;
87 if ( position.y() > pageBottom )
88 break;
89
90 const QString txt = QString::number( lineCount );
91 p.drawText( width() - fm.width(txt), qRound( position.y() ) - contentsY + ascent, txt );
92
93 // marker
94 if ( markedLine == lineCount )
95 {
96 p.drawPixmap( 1, qRound( position.y() ) - contentsY, markerIcon );
97 markedRect = QRect( 1, qRound( position.y() ) - contentsY, markerIcon.width(), markerIcon.height() );
98 }
99 }
100}
101
102NumberedTextView::NumberedTextView( QWidget *parent )
103 : QFrame( parent )
104{
105 setFrameStyle( QFrame::StyledPanel | QFrame::Sunken );
106 setLineWidth( 2 );
107
108 // Setup the main view
109 view = new QTextEdit( this );
110 //view->setFontFamily( "Courier" );
111 view->setLineWrapMode( QTextEdit::NoWrap );
112 view->setFrameStyle( QFrame::NoFrame );
113
114 connect( view->document(), SIGNAL(contentsChange(int,int,int)), this, SLOT(textChanged(int,int,int)) );
115
116 // Setup the line number pane
117 numbers = new NumberBar( this );
118 numbers->setTextEdit( view );
119
120 // Test
121 markLine(2);
122
123 //setup layout
124 box = new QHBoxLayout( this );
125 box->setSpacing( 0 );
126 box->setMargin( 0 );
127 box->addWidget( numbers );
128 box->addWidget( view );
129}
130
131NumberedTextView::~NumberedTextView()
132{
133}
134
135void NumberedTextView::markLine( int lineno )
136{
137 markedLine = lineno;
138 numbers->markLine( lineno );
139 textChanged(1,1,1);
140}
141
142void NumberedTextView::scrolltoLine( int lineno )
143{
144 int max = view->verticalScrollBar()->maximum();
145 int min = view->verticalScrollBar()->minimum();
146 int lines = view->document()->blockCount();
147 view->verticalScrollBar()->setValue( (max*lineno)/lines+min );
148}
149
150void NumberedTextView::textChanged( int pos, int removed, int added )
151{
152 Q_UNUSED( pos );
153
154 if ( removed == 0 && added == 0 )
155 return;
156
157 QTextBlock block = highlight.block();
158 QTextBlockFormat fmt = block.blockFormat();
159 QColor bg = view->palette().base().color();
160 fmt.setBackground( bg );
161 highlight.setBlockFormat( fmt );
162
163 int lineCount = 1;
164 for ( QTextBlock block = view->document()->begin();
165 block.isValid(); block = block.next(), ++lineCount )
166 {
167 if ( lineCount == markedLine )
168 {
169 fmt = block.blockFormat();
170 QColor bg = Qt::red;
171 fmt.setBackground( bg.light(150) );
172
173 highlight = QTextCursor( block );
174 highlight.movePosition( QTextCursor::EndOfBlock, QTextCursor::KeepAnchor );
175 highlight.setBlockFormat( fmt );
176
177 break;
178 }
179 }
180}
181
diff --git a/utils/wpseditor/gui/src/numberedtextview.h b/utils/wpseditor/gui/src/numberedtextview.h
deleted file mode 100644
index 2a0d1de068..0000000000
--- a/utils/wpseditor/gui/src/numberedtextview.h
+++ /dev/null
@@ -1,87 +0,0 @@
1/* This file is part of the KDE libraries
2 Copyright (C) 2005, 2006 KJSEmbed Authors
3 See included AUTHORS file.
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19
20 --------------------------------------------------------------------------------------
21 Imported into the WPS editor and simplified by Dominik Wenger
22
23*/
24
25
26#ifndef NUMBERED_TEXT_VIEW_H
27#define NUMBERED_TEXT_VIEW_H
28
29#include <QFrame>
30#include <QPixmap>
31#include <QTextCursor>
32
33class QTextEdit;
34class QHBoxLayout;
35
36// Shows the Line numbers
37class NumberBar : public QWidget
38{
39 Q_OBJECT
40
41public:
42 NumberBar( QWidget *parent );
43 ~NumberBar();
44
45 void markLine( int lineno );
46
47 void setTextEdit( QTextEdit *edit );
48 void paintEvent( QPaintEvent *ev );
49
50private:
51 QTextEdit *edit;
52 QPixmap markerIcon;
53 int markedLine;
54 QRect markedRect;
55};
56
57// Shows a QTextEdit with Line numbers
58class NumberedTextView : public QFrame
59{
60 Q_OBJECT
61
62public:
63 NumberedTextView( QWidget *parent = 0 );
64 ~NumberedTextView();
65
66 /** Returns the QTextEdit of the main view. */
67 QTextEdit *textEdit() const { return view; }
68
69 /* marks the line with a icon */
70 void markLine( int lineno );
71
72 void scrolltoLine( int lineno );
73
74private slots:
75 void textChanged( int pos, int removed, int added );
76
77private:
78 QTextEdit *view;
79 NumberBar *numbers;
80 QHBoxLayout *box;
81 QTextCursor highlight;
82 int markedLine;
83};
84
85
86#endif // NUMBERED_TEXT_VIEW_H
87
diff --git a/utils/wpseditor/gui/src/qsyntaxer.cpp b/utils/wpseditor/gui/src/qsyntaxer.cpp
deleted file mode 100644
index 5a0b6cd97c..0000000000
--- a/utils/wpseditor/gui/src/qsyntaxer.cpp
+++ /dev/null
@@ -1,64 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 *
9 * Copyright (C) 2007 by Rostilav Checkan
10 * $Id$
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#include <QTextCharFormat>
23
24#include "qsyntaxer.h"
25
26QSyntaxer::QSyntaxer(QTextDocument *parent)
27 : QSyntaxHighlighter(parent) {
28 HighlightingRule rule;
29
30 hrules[0].pattern = QRegExp("%[^\\| \n<\\?%]{1,2}");
31 hrules[0].format.setFontWeight(QFont::Bold);
32 hrules[0].format.setForeground(Qt::darkBlue);
33
34
35 hrules[1].pattern = QRegExp("%[\\?]{1}[^<]{1,2}");
36 hrules[1].format.setForeground(Qt::darkMagenta);
37
38 hrules[2].pattern = QRegExp("(<|>)");
39 hrules[2].format.setForeground(Qt::red);
40
41 hrules[3].pattern = QRegExp("\\|");
42 hrules[3].format.setForeground(Qt::darkRed);
43
44 hrules[4].pattern = QRegExp("#[^\n]*");
45 hrules[4].format.setForeground(Qt::darkGreen);
46 hrules[4].format.setFontItalic(true);
47}
48//
49void QSyntaxer::highlightBlock(const QString &text) {
50 QTextCharFormat wholeText;
51 wholeText.setFont(QFont("arial",11,QFont::Normal));
52 setFormat(0,text.length(),wholeText);
53
54 foreach (HighlightingRule rule, hrules) {
55 QRegExp expression(rule.pattern);
56 int index = text.indexOf(expression);
57 while (index >= 0) {
58 int length = expression.matchedLength();
59 setFormat(index, length, rule.format);
60 index = text.indexOf(expression, index + length);
61 }
62 }
63
64}
diff --git a/utils/wpseditor/gui/src/qsyntaxer.h b/utils/wpseditor/gui/src/qsyntaxer.h
deleted file mode 100644
index 56f7cfaf48..0000000000
--- a/utils/wpseditor/gui/src/qsyntaxer.h
+++ /dev/null
@@ -1,42 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 *
9 * Copyright (C) 2007 by Rostilav Checkan
10 * $Id$
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#ifndef QSYNTAXER_H
23#define QSYNTAXER_H
24//
25#include <QSyntaxHighlighter>
26
27class QTextCharFormat;
28
29class QSyntaxer : public QSyntaxHighlighter {
30 Q_OBJECT
31 struct HighlightingRule {
32 QRegExp pattern;
33 QTextCharFormat format;
34 };
35 QMap<int,HighlightingRule> hrules;
36public:
37 QSyntaxer(QTextDocument *parent = 0);
38
39protected:
40 void highlightBlock(const QString &text);
41};
42#endif
diff --git a/utils/wpseditor/gui/src/qtrackstate.cpp b/utils/wpseditor/gui/src/qtrackstate.cpp
deleted file mode 100644
index 85398971b0..0000000000
--- a/utils/wpseditor/gui/src/qtrackstate.cpp
+++ /dev/null
@@ -1,62 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 *
9 * Copyright (C) 2007 by Rostilav Checkan
10 * $Id$
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#include "qtrackstate.h"
23#include <stdlib.h>
24
25//
26QTrackState::QTrackState( )
27 : QObject() {
28 memset(&state,0,sizeof(state));
29 state.title = (char*)"title";
30 state.artist = (char*)"artist";
31 state.album = (char*)"album";
32 state.length = 100;
33 state.elapsed = 50;
34}
35
36void QTrackState::setTitle(const QString& name) {
37 state.title = new char[name.length()];
38 strcpy(state.title,name.toAscii());
39 emit stateChanged(state);
40}
41
42void QTrackState::setArtist(const QString& name) {
43 state.artist = new char[name.length()];
44 strcpy(state.artist,name.toAscii());
45 emit stateChanged(state);
46}
47
48void QTrackState::setAlbum(const QString& name) {
49 state.album = new char[name.length()];
50 strcpy(state.album,name.toAscii());
51 emit stateChanged(state);
52}
53
54void QTrackState::setLength(int le) {
55 state.length = le;
56 emit stateChanged(state);
57}
58
59void QTrackState::setElapsed(int le) {
60 state.elapsed = le;
61 emit stateChanged(state);
62}
diff --git a/utils/wpseditor/gui/src/qtrackstate.h b/utils/wpseditor/gui/src/qtrackstate.h
deleted file mode 100644
index ebe000dd25..0000000000
--- a/utils/wpseditor/gui/src/qtrackstate.h
+++ /dev/null
@@ -1,75 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 *
9 * Copyright (C) 2007 by Rostilav Checkan
10 * $Id$
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#ifndef __QTRACKSTATE_H__
23#define __QTRACKSTATE_H__
24
25#include "wpsstate.h"
26#include <QObject>
27
28class QTrackState : public QObject {
29 Q_OBJECT
30 Q_CLASSINFO ( "QTrackState", "Track State" );
31 Q_PROPERTY ( QString Title READ title WRITE setTitle DESIGNABLE true USER true )
32 Q_PROPERTY ( QString Artist READ artist WRITE setArtist DESIGNABLE true USER true )
33 Q_PROPERTY ( QString Album READ album WRITE setAlbum DESIGNABLE true USER true )
34 Q_PROPERTY ( int Length READ length WRITE setLength DESIGNABLE true USER true )
35 Q_CLASSINFO("Length", "readOnly=true;value=100");
36 Q_PROPERTY ( int Elapsed READ elapsed WRITE setElapsed DESIGNABLE true USER true )
37 Q_CLASSINFO("Elapsed", "minimum=0;maximum=100;value=50");
38
39 trackstate state;
40
41public:
42 QTrackState();
43
44public slots:
45 QString title() const {
46 return state.title;
47 }
48 void setTitle ( const QString& name );
49
50 QString artist() const {
51 return state.artist;
52 }
53 void setArtist ( const QString& name );
54
55 QString album() const {
56 return state.album;
57 }
58 void setAlbum ( const QString& name );
59
60 int length() const {
61 return state.length;
62 }
63 void setLength ( int l );
64
65 int elapsed() const {
66 return state.elapsed;
67 }
68 void setElapsed ( int l );
69
70signals:
71 void stateChanged ( trackstate state );
72
73};
74
75#endif // __QTRACKSTATE_H__
diff --git a/utils/wpseditor/gui/src/qwpsdrawer.cpp b/utils/wpseditor/gui/src/qwpsdrawer.cpp
deleted file mode 100644
index ce2dbd0149..0000000000
--- a/utils/wpseditor/gui/src/qwpsdrawer.cpp
+++ /dev/null
@@ -1,274 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 *
9 * Copyright (C) 2007 by Rostilav Checkan
10 * $Id$
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#include <stdarg.h>
23
24#include <QtGui>
25#include <QLibrary>
26
27#include "qwpsdrawer.h"
28#include "slider.h"
29#include "utils.h"
30#include "qtrackstate.h"
31#include "qwpsstate.h"
32#include "api.h"
33
34QPointer<QWpsDrawer> drawer;
35QPixmap *QWpsDrawer::pix = NULL;
36QString QWpsDrawer::mTmpWpsString;
37QImage QWpsDrawer::backdrop;
38proxy_api QWpsDrawer::api;
39
40QWpsDrawer::QWpsDrawer( QWpsState *ws,QTrackState *ms, QWidget *parent )
41 : QWidget(parent),wpsState(ws),trackState(ms),showGrid(false),mCurTarget(qApp->applicationDirPath()+"/libwps_IRIVER_H10_5GB") {
42
43 tryResolve();
44 newTempWps();
45}
46
47bool QWpsDrawer::tryResolve() {
48 QLibrary lib(mCurTarget);
49 lib_wps_init = (pfwps_init)lib.resolve("wps_init");
50 lib_wps_display = (pfwps_display)lib.resolve("wps_display");
51 lib_wps_refresh = (pfwps_refresh)lib.resolve("wps_refresh");
52 lib_get_model_name = (pfget_model_name)lib.resolve("get_model_name");
53 mResolved = lib_wps_init && lib_wps_display && lib_wps_refresh && lib_get_model_name;
54 if (!mResolved)
55 DEBUGF1(tr("ERR: Failed to resolve funcs!"));
56 else {
57 int v = api.verbose;
58 memset(&api,0,sizeof(struct proxy_api));
59 api.verbose = v;
60 api.putsxy = &QWpsDrawer::putsxy;
61 api.transparent_bitmap_part = &QWpsDrawer::transparent_bitmap_part;
62 api.bitmap_part = &QWpsDrawer::bitmap_part;
63 api.drawpixel = &QWpsDrawer::drawpixel;
64 api.fillrect = &QWpsDrawer::fillrect;
65 api.hline = &QWpsDrawer::hline;
66 api.vline = &QWpsDrawer::vline;
67 api.clear_viewport = &QWpsDrawer::clear_viewport;
68 api.load_wps_backdrop = &QWpsDrawer::load_wps_backdrop;
69 api.read_bmp_file = &QWpsDrawer::read_bmp_file;
70 api.debugf = &qlogger;
71 qDebug()<<(mCurTarget+" resolved");
72 }
73 return mResolved;
74}
75QWpsDrawer::~QWpsDrawer() {
76 qDebug()<<"QWpsDrawer::~QWpsDrawer()";
77 cleanTemp();
78}
79
80void QWpsDrawer::mouseReleaseEvent ( QMouseEvent * event ) {
81 Q_UNUSED(event);
82 /*int x = event->x() - (this->width()-pix->width())/2,
83 y = event->y() - (this->height()-pix->height())/2;
84 DEBUGF1("x=%d,y=%d",x,y);*/
85}
86void QWpsDrawer::newTempWps() {
87 QTemporaryFile tmpWps;
88 tmpWps.setAutoRemove(false);
89 tmpWps.setFileTemplate(QDir::tempPath()+"/XXXXXXXXXX.wps");
90 if (tmpWps.open()) {
91 QString tmpDir = tmpWps.fileName().left(tmpWps.fileName().length()-4);
92 if (QDir::temp().mkpath(tmpDir)) {
93 mTmpWpsString = tmpDir;
94 DEBUGF3(QString("Created :"+mTmpWpsString).toAscii());
95 }
96 }
97}
98
99void QWpsDrawer::WpsInit(QString buffer, bool isFile) {
100 DEBUGF3("QWpsDrawer::WpsInit");
101 if (!mResolved)
102 if (!tryResolve())
103 return;
104 if (isFile) {
105 cleanTemp();
106 DEBUGF1( tr("Loading %1").arg(buffer));
107 QFile file(buffer);
108 if (file.open(QIODevice::ReadOnly | QIODevice::Text))
109 mWpsString = file.readAll();
110 newTempWps();
111 } else
112 mWpsString = buffer;
113 {
114 QFile tfile(mTmpWpsString+".wps");
115 if (tfile.open(QIODevice::WriteOnly | QIODevice::Text))
116 tfile.write(mWpsString.toAscii(),mWpsString.length());
117 }
118 backdrop.fill(Qt::black);
119 DEBUGF3("clear backdrop");
120 if (isFile)
121 lib_wps_init(buffer.toAscii(), &api, isFile);
122 else
123 lib_wps_init(QString(mTmpWpsString+".wps").toAscii(), &api, true);
124 pix = new QPixmap(api.getwidth(),api.getheight());
125 pix->fill(Qt::black);
126
127 drawBackdrop();
128
129 setMinimumWidth(api.getwidth());
130 setMinimumHeight(api.getheight());
131 update();
132}
133
134void QWpsDrawer::paintEvent(QPaintEvent * event) {
135 DEBUGF3("QWpsDrawer::paintEvent()");
136 if (!mResolved)
137 return;
138 if (pix==NULL)
139 return;
140 QPainter p(this);
141 QRect rect = event->rect();
142
143 drawBackdrop();
144 lib_wps_refresh();
145
146 if (showGrid) {
147 QPainter g(pix);
148 viewport_api avp;
149 api.get_current_vp(&avp);
150
151 g.setPen(Qt::green);
152
153 for (int i=0;i*avp.fontheight/1.5<avp.width ;i++) {
154 g.drawLine(int(i*avp.fontheight/1.5), 0, int(i*avp.fontheight/1.5), avp.height);
155 }
156 for (int j=0;j*avp.fontheight<avp.height; j++) {
157 g.drawLine(0,j*avp.fontheight,avp.width,j*avp.fontheight);
158 }
159 }
160
161 p.drawPixmap((rect.width()-pix->width())/2,(rect.height()-pix->height())/2,*pix);
162
163}
164
165void QWpsDrawer::clear_viewport(int x,int y,int w,int h, int color) {
166 DEBUGF2("clear_viewport(int x=%d,int y=%d,int w=%d,int h=%d, int color)",x,y,w,h);
167 QPainter p(pix);
168 //p.setOpacity(0.1);
169 //QImage img = backdrop.copy(x,y,w,h);
170 //p.drawImage(x,y,img);
171}
172
173void QWpsDrawer::slotSetVolume() {
174 Slider *slider = new Slider(this, tr("Volume"),-74,10);
175 slider->show();
176 connect(slider, SIGNAL(valueChanged(int)), wpsState, SLOT(setVolume(int)));
177 connect(this, SIGNAL(destroyed()),slider, SLOT(close()));
178}
179
180void QWpsDrawer::slotSetProgress() {
181 Slider *slider = new Slider(this,tr("Progress"),0,100);
182 slider->show();
183 connect(slider, SIGNAL(valueChanged(int)), trackState, SLOT(setElapsed(int)));
184 connect(this, SIGNAL(destroyed()),slider, SLOT(close()));
185}
186
187void QWpsDrawer::slotWpsStateChanged(wpsstate ws_) {
188 if (api.set_wpsstate)
189 api.set_wpsstate(ws_);
190 update();
191}
192
193void QWpsDrawer::slotTrackStateChanged(trackstate ms_) {
194 if (api.set_wpsstate)
195 api.set_trackstate(ms_);
196 update();
197}
198
199void QWpsDrawer::slotShowGrid(bool show) {
200 showGrid = show;
201 update();
202}
203
204void QWpsDrawer::drawBackdrop() {
205 DEBUGF3("QWpsDrawer::drawBackdrop()");
206 if (backdrop.isNull())
207 return;
208 QPainter b(pix);
209 QImage pink = backdrop.createMaskFromColor(qRgb(255,0,255),Qt::MaskOutColor);
210 backdrop.setAlphaChannel(pink);
211 b.drawImage(0,0,backdrop,0,0,pix->width(),pix->height());
212}
213
214void QWpsDrawer::slotSetAudioStatus(int status) {
215 api.set_audio_status(status);
216 update();
217}
218
219void QWpsDrawer::cleanTemp(bool fileToo) {
220 if (fileToo)
221 QFile::remove(mTmpWpsString+".wps");
222 QDirIterator it(mTmpWpsString, QDirIterator::Subdirectories);
223 while (it.hasNext()) {
224 QFile::remove(it.next());
225 }
226 QDir(mTmpWpsString).rmdir(mTmpWpsString);
227}
228
229void QWpsDrawer::closeEvent(QCloseEvent *event) {
230 qDebug()<<"QWpsDrawer::closeEvent()";
231 cleanTemp();
232 event->accept();
233}
234
235QString QWpsDrawer::getModelName(QString libraryName) {
236 QLibrary lib(libraryName);
237 if ((pfget_model_name)lib.resolve("get_model_name"))
238 return ((pfget_model_name)lib.resolve("get_model_name"))();
239 DEBUGF1("ERR: failed to resolve <get_model_name>");
240 return "unknown";
241}
242
243QList<QString> QWpsDrawer::getTargets() {
244 QList<QString> list ;
245 QDir d = QDir(qApp->applicationDirPath());
246 QFileInfoList libs = d.entryInfoList(QStringList("libwps_*"));
247 qDebug() << libs.size()<<"libs found";
248 for (int i = 0; i < libs.size(); i++) {
249 QString modelName = getModelName(libs[i].absoluteFilePath());
250 qDebug() << libs[i].fileName()<<modelName;
251 if (modelName == "unknown")
252 continue;
253 list.append(modelName);
254 libs_array[i].target_name = modelName;
255 libs_array[i].lib = libs[i].absoluteFilePath();
256 }
257 return list;
258}
259bool QWpsDrawer::setTarget(QString target) {
260 foreach(lib_t cur_lib, libs_array)
261 {
262 if(cur_lib.target_name == target)
263 {
264 QLibrary lib(cur_lib.lib);
265 //lib.unload();
266 if (getModelName(cur_lib.lib) != "unknown")
267 {
268 mCurTarget = cur_lib.lib;
269 return tryResolve();
270 }
271 }
272 }
273 return false;
274}
diff --git a/utils/wpseditor/gui/src/qwpsdrawer.h b/utils/wpseditor/gui/src/qwpsdrawer.h
deleted file mode 100644
index fd290a24ae..0000000000
--- a/utils/wpseditor/gui/src/qwpsdrawer.h
+++ /dev/null
@@ -1,118 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 *
9 * Copyright (C) 2007 by Rostilav Checkan
10 * $Id$
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#ifndef WPSDRAWER_H
23#define WPSDRAWER_H
24
25#include <QWidget>
26#include <QPixmap>
27#include <QPointer>
28#include <QTemporaryFile>
29#include <QMap>
30
31#include "wpsstate.h"
32
33struct proxy_api;
34
35class QWpsState;
36class QTrackState;
37
38typedef int (*pfwps_init)(const char* buff,struct proxy_api *api, bool isfile);
39typedef int (*pfwps_display)();
40typedef int (*pfwps_refresh)();
41typedef const char* (*pfget_model_name)();
42
43class QWpsDrawer : public QWidget {
44 Q_OBJECT
45
46 pfwps_init lib_wps_init;
47 pfwps_display lib_wps_display;
48 pfwps_refresh lib_wps_refresh;
49 pfget_model_name lib_get_model_name;
50
51 static QPixmap *pix;
52 static QImage backdrop;
53
54 QWpsState *wpsState;
55 QTrackState *trackState;
56
57 bool showGrid;
58 bool mResolved;
59 QString mWpsString;
60 QString mCurTarget;
61 static QString mTmpWpsString;
62
63 struct lib_t
64 {
65 QString target_name;
66 QString lib;
67 };
68 QMap<int, lib_t> libs_array;
69
70
71protected:
72 virtual void paintEvent(QPaintEvent * event);
73 virtual void closeEvent(QCloseEvent *event);
74 virtual void mouseReleaseEvent ( QMouseEvent * event ) ;
75 void drawBackdrop();
76 void newTempWps();
77 void cleanTemp(bool fileToo=true);
78 bool tryResolve();
79 QString getModelName(QString libraryName);
80public:
81 QWpsDrawer(QWpsState *ws,QTrackState *ms, QWidget *parent=0);
82 ~QWpsDrawer();
83 void WpsInit(QString buffer, bool isFile = true);
84
85 QString wpsString() const {
86 return mWpsString;
87 };
88 QString tempWps() const {
89 return mTmpWpsString;
90 };
91 QList<QString> getTargets();
92 bool setTarget(QString target);
93
94
95 static proxy_api api;
96 /***********Drawing api******************/
97 static void putsxy(int x, int y, const unsigned char *str);
98 static void transparent_bitmap_part(const void *src, int src_x, int src_y,
99 int stride, int x, int y, int width, int height);
100 static void bitmap_part(const void *src, int src_x, int src_y,
101 int stride, int x, int y, int width, int height);
102 static void drawpixel(int x, int y);
103 static void fillrect(int x, int y, int width, int height);
104 static void hline(int x1, int x2, int y);
105 static void vline(int x, int y1, int y2);
106 static void clear_viewport(int x,int y,int w,int h, int color);
107 static bool load_wps_backdrop(char* filename);
108 static int read_bmp_file(const char* filename,int *width, int *height);
109 /****************************************/
110public slots:
111 void slotSetVolume();
112 void slotSetProgress();
113 void slotShowGrid(bool);
114 void slotWpsStateChanged(wpsstate);
115 void slotTrackStateChanged(trackstate);
116 void slotSetAudioStatus(int);
117};
118#endif
diff --git a/utils/wpseditor/gui/src/qwpsdrawer_static.cpp b/utils/wpseditor/gui/src/qwpsdrawer_static.cpp
deleted file mode 100644
index d5da623722..0000000000
--- a/utils/wpseditor/gui/src/qwpsdrawer_static.cpp
+++ /dev/null
@@ -1,97 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 *
9 * Copyright (C) 2007 by Rostilav Checkan
10 * $Id$
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#include "qwpsdrawer.h"
23#include <QPainter>
24#include <QFile>
25#include <QFileInfo>
26#include "utils.h"
27#include "api.h"
28
29void QWpsDrawer::putsxy(int x, int y, const unsigned char *str) {
30 DEBUGF3("putsxy(int x=%d, int y=%d, *str=%s)",x,y,str);
31 QPainter p(pix);
32 viewport_api avp;
33 api.get_current_vp(&avp);
34 p.setPen(Qt::gray);
35 QFont font("times",avp.fontheight,QFont::Bold);
36 p.setFont(font);
37 p.drawText(x+avp.x,y + avp.fontheight + avp.y,(char*)str);
38}
39void QWpsDrawer::transparent_bitmap_part(const void *src, int src_x, int src_y,
40 int stride, int x, int y, int width, int height) {
41 QImage img;
42 img.load((char*)src);
43 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);
44 QPainter p(pix);
45 QPoint target(x,y);
46 QRectF source(src_x, src_y, width, height);
47
48 QImage pink = img.createMaskFromColor(qRgb(255,0,255),Qt::MaskOutColor);
49 img.setAlphaChannel(pink);
50
51 p.drawImage(target, img, source);
52}
53void QWpsDrawer::bitmap_part(const void *src, int src_x, int src_y,
54 int stride, int x, int y, int width, int height) {
55 transparent_bitmap_part(src,src_x,src_y,stride,x,y,width,height);
56}
57void QWpsDrawer::drawpixel(int x, int y) {
58 QPainter p(pix);
59 p.setPen(Qt::blue);
60 p.drawPoint(x,y);
61}
62void QWpsDrawer::fillrect(int x, int y, int width, int height) {
63 QPainter p(pix);
64 DEBUGF2("fillrect(int x=%d, int y=%d, int width=%d, int height=%d)\n",x, y, width, height);
65 p.setPen(Qt::green);
66}
67void QWpsDrawer::hline(int x1, int x2, int y) {
68 QPainter p(pix);
69 p.setPen(Qt::black);
70 p.drawLine(x1,y,x2,y);
71}
72void QWpsDrawer::vline(int x, int y1, int y2) {
73 QPainter p(pix);
74 p.setPen(Qt::black);
75 p.drawLine(x,y1,x,y2);
76}
77bool QWpsDrawer::load_wps_backdrop(char* filename) {
78 DEBUGF3("load backdrop: %s", filename);
79 QFile file(filename);
80 QFileInfo info(file);
81 file.copy(mTmpWpsString+"/"+info.fileName());
82 backdrop.load(filename);
83 return true;
84}
85
86int QWpsDrawer::read_bmp_file(const char* filename,int *width, int *height) {
87 QImage img;
88
89 QFile file(filename);
90 QFileInfo info(file);
91 file.copy(mTmpWpsString+"/"+info.fileName());
92
93 img.load(filename);
94 *width = img.width();
95 *height = img.height();
96 return 1;
97}
diff --git a/utils/wpseditor/gui/src/qwpseditorwindow.cpp b/utils/wpseditor/gui/src/qwpseditorwindow.cpp
deleted file mode 100644
index 1527fef57a..0000000000
--- a/utils/wpseditor/gui/src/qwpseditorwindow.cpp
+++ /dev/null
@@ -1,191 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 *
9 * Copyright (C) 2007 by Rostilav Checkan
10 * $Id$
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#include <QFileDialog>
23#include <QDebug>
24#include <QInputDialog>
25#include "api.h"
26#include "qwpseditorwindow.h"
27#include "utils.h"
28#include "qsyntaxer.h"
29
30
31enum api_playmode playmodes[PLAYMODES_NUM] = {
32 API_STATUS_PLAY,
33 API_STATUS_STOP,
34 API_STATUS_PAUSE,
35 API_STATUS_FASTFORWARD,
36 API_STATUS_FASTBACKWARD
37 };
38
39const char *playmodeNames[] = {
40 "Play",
41 "Stop",
42 "Pause",
43 "FastForward",
44 "FastBackward"
45 };
46
47QWpsEditorWindow::QWpsEditorWindow( QWidget * parent, Qt::WFlags f)
48 : QMainWindow(parent, f) {
49 logEdit = 0;
50 scrollingLine = -1;
51 setupUi(this);
52 drawer = new QWpsDrawer(&wpsState,&trackState, this);
53 QWpsDrawer::api.verbose = 1;
54 setCentralWidget(drawer);
55 connectActions();
56 m_propertyEditor->addObject(&trackState);
57 m_propertyEditor->addObject(&wpsState);
58 new QSyntaxer(plainWpsEdit->textEdit()->document());
59 plainWpsEdit->markLine(-1);
60}
61
62void QWpsEditorWindow::connectActions() {
63 DEBUGF3("connect actions");
64 connect(actOpenWps, SIGNAL(triggered()), this, SLOT(slotOpenWps()));
65 connect(actSetVolume, SIGNAL(triggered()), drawer, SLOT(slotSetVolume()));
66 connect(actSetProgress, SIGNAL(triggered()), drawer, SLOT(slotSetProgress()));
67 connect(actShowGrid, SIGNAL(triggered(bool)), drawer, SLOT(slotShowGrid(bool)));
68
69 connect(actUpdatePlainWps, SIGNAL(triggered()), SLOT(slotUpdatePlainWps()));
70 connect(plainWpsEdit->textEdit()->document(),SIGNAL(modificationChanged(bool)),SLOT(slotPlainDocModChanged(bool)));
71
72 connect(&wpsState, SIGNAL(stateChanged(wpsstate)), drawer, SLOT(slotWpsStateChanged(wpsstate)));
73 connect(&trackState, SIGNAL(stateChanged(trackstate)), drawer, SLOT(slotTrackStateChanged(trackstate)));
74 connect(&wpsState, SIGNAL(stateChanged(wpsstate)), this, SLOT(slotWpsStateChanged(wpsstate)));
75 connect(&trackState, SIGNAL(stateChanged(trackstate)), this, SLOT(slotTrackStateChanged(trackstate)));
76
77 connect(actClearLog, SIGNAL(triggered()), logEdit, SLOT(clear()));
78 connect(actVerboseLevel, SIGNAL(triggered()), SLOT(slotVerboseLevel()));
79
80 actGroupAudios = new QActionGroup(this);
81 audiosSignalMapper = new QSignalMapper(this);
82 for (int i=0;i<PLAYMODES_NUM;i++) {
83 QAction *act = new QAction(playmodeNames[i],this);
84 act->setCheckable(true);
85 actGroupAudios->addAction(act);
86 connect(act,SIGNAL(triggered()),audiosSignalMapper,SLOT(map()));
87 audiosSignalMapper->setMapping(act, i);
88 menuPlay->addAction(act);
89 actAudios[playmodes[i]] = act;
90 }
91 connect(audiosSignalMapper, SIGNAL(mapped(int)), SIGNAL(signalAudioStatusChanged(int)));
92 connect(this, SIGNAL(signalAudioStatusChanged(int)), drawer, SLOT(slotSetAudioStatus(int)));
93 actGroupAudios->setEnabled(false);
94
95 QList<QString> targets = drawer->getTargets();
96 actGroupTargets = new QActionGroup(this);
97 targetsSignalMapper = new QSignalMapper(this);
98
99 for (int i=0;i<targets.size();i++) {
100 QAction *act = new QAction(targets[i],this);
101 act->setCheckable(true);
102 actGroupTargets->addAction(act);
103 connect(act,SIGNAL(triggered()),targetsSignalMapper,SLOT(map()));
104 targetsSignalMapper->setMapping(act, targets[i]);
105 menuTarget->addAction(act);
106 actTargets[targets[i]] = act;
107 }
108 connect(targetsSignalMapper, SIGNAL(mapped(const QString &)),this, SIGNAL(signalSetTarget(const QString &)));
109 connect(this, SIGNAL(signalSetTarget(const QString &)),this, SLOT(slotSetTarget(const QString &)));
110}
111
112void QWpsEditorWindow::slotWpsStateChanged(wpsstate) {
113 m_propertyEditor->updateObject(&wpsState);
114 m_propertyEditor->update();
115}
116
117void QWpsEditorWindow::slotTrackStateChanged(trackstate) {
118 m_propertyEditor->updateObject(&trackState);
119 m_propertyEditor->update();
120}
121
122void QWpsEditorWindow::slotOpenWps() {
123 QString wpsfile = QFileDialog::getOpenFileName(this,
124 tr("Open WPS"), "", tr("WPS Files (*.wps);; All Files (*.*)"));
125 if (wpsfile == "") {
126 DEBUGF1(tr("File wasn't chosen"));
127 return;
128 }
129 scrollingLine = -1;
130 drawer->WpsInit(wpsfile);
131 plainWpsEdit->textEdit()->clear();
132 plainWpsEdit->textEdit()->append(drawer->wpsString());
133 postWpsUpdate();
134}
135
136void QWpsEditorWindow::logMsg(QString s) {
137 logEdit->append(s);
138 // check for error line:
139 if (s.contains("ERR: Failed parsing on line ")) {
140 QRegExp error("\\d+");
141 if (error.indexIn(s) != -1) {
142 scrollingLine = error.cap(0).toInt();
143 plainWpsEdit->markLine(scrollingLine);
144 }
145 }
146}
147
148void QWpsEditorWindow::slotVerboseLevel() {
149 bool ok;
150 int i = QInputDialog::getInteger(this, tr("Set Verbose Level"),tr("Level:"), QWpsDrawer::api.verbose, 0, 3, 1, &ok);
151 if (ok)
152 QWpsDrawer::api.verbose = i;
153}
154
155void QWpsEditorWindow::slotUpdatePlainWps() {
156 DEBUGF1(tr("Updating WPS"));
157 scrollingLine = -1;
158 drawer->WpsInit(plainWpsEdit->textEdit()->toPlainText(),false);
159 postWpsUpdate();
160}
161
162void QWpsEditorWindow::slotPlainDocModChanged(bool changed) {
163 if (changed) {
164 dockPlainWps->setWindowTitle(tr("PlainWps*"));
165 plainWpsEdit->markLine(-1);
166 } else {
167 dockPlainWps->setWindowTitle(tr("PlainWps"));
168 }
169}
170void QWpsEditorWindow::slotSetTarget(const QString & target) {
171 if (drawer->setTarget(target)) {
172 DEBUGF1(tr("New target <%1> switched").arg(target));
173 actTargets[target]->setChecked(true);
174 } else
175 DEBUGF1(tr("ERR: Target <%1> failed!").arg(target));
176 update();
177 slotUpdatePlainWps();
178}
179
180void QWpsEditorWindow::postWpsUpdate() {
181 m_propertyEditor->setEnabled(true);
182 actGroupAudios->setEnabled(true);
183 trackState.setAlbum(trackState.album()); ////updating property editor
184 plainWpsEdit->markLine(scrollingLine);
185 plainWpsEdit->textEdit()->document()->setModified(false);
186 plainWpsEdit->scrolltoLine(scrollingLine);
187 scrollingLine = -1;
188}
189
190
191
diff --git a/utils/wpseditor/gui/src/qwpseditorwindow.h b/utils/wpseditor/gui/src/qwpseditorwindow.h
deleted file mode 100644
index 0009548be2..0000000000
--- a/utils/wpseditor/gui/src/qwpseditorwindow.h
+++ /dev/null
@@ -1,79 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 *
9 * Copyright (C) 2007 by Rostilav Checkan
10 * $Id$
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#ifndef MAINWINDOWIMPL_H
23#define MAINWINDOWIMPL_H
24//
25#include <QMainWindow>
26#include <QActionGroup>
27#include <QSignalMapper>
28
29#include "wpsstate.h"
30#include "ui_mainwindow.h"
31#include "wpsstate.h"
32#include "qwpsstate.h"
33#include "qtrackstate.h"
34#include "qwpsdrawer.h"
35
36class QWpsEditorWindow : public QMainWindow, public Ui::MainWindow {
37 Q_OBJECT
38
39 QWpsState wpsState;
40 QTrackState trackState;
41 QPointer<QWpsDrawer> drawer;
42
43 QHash<int, QAction*> actAudios;
44 QActionGroup *actGroupAudios;
45 QSignalMapper *audiosSignalMapper;
46
47 QHash<QString,QAction *> actTargets;
48 QActionGroup *actGroupTargets;
49 QSignalMapper *targetsSignalMapper;
50
51 int scrollingLine;
52protected:
53 void connectActions();
54 void postWpsUpdate();
55public:
56 QWpsEditorWindow( QWidget * parent = 0, Qt::WFlags f = 0 );
57 void logMsg(QString s);
58private slots:
59 void slotOpenWps();
60 void slotVerboseLevel();
61 void slotWpsStateChanged(wpsstate);
62 void slotTrackStateChanged(trackstate);
63
64 void slotUpdatePlainWps();
65 void slotPlainDocModChanged(bool m);
66 void slotSetTarget(const QString &);
67
68signals:
69 void signalAudioStatusChanged(int);
70 void signalSetTarget(const QString &);
71
72};
73#endif
74
75
76
77
78
79
diff --git a/utils/wpseditor/gui/src/qwpsstate.cpp b/utils/wpseditor/gui/src/qwpsstate.cpp
deleted file mode 100644
index 7afeee4332..0000000000
--- a/utils/wpseditor/gui/src/qwpsstate.cpp
+++ /dev/null
@@ -1,50 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 *
9 * Copyright (C) 2007 by Rostilav Checkan
10 * $Id$
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#include "qwpsstate.h"
23
24QWpsState::QWpsState(): QObject() {
25 state.fontheight = 8;
26 state.fontwidth = 5;
27 state.volume = -30;
28 state.battery_level = 50;
29
30}
31
32void QWpsState::setFontHeight(int val) {
33 state.fontheight = val;
34 emit stateChanged(state);
35}
36
37void QWpsState::setFontWidth(int val) {
38 state.fontwidth = val;
39 emit stateChanged(state);
40}
41
42void QWpsState::setVolume(int val) {
43 state.volume = val;
44 emit stateChanged(state);
45}
46
47void QWpsState::setBattery(int val) {
48 state.battery_level = val;
49 emit stateChanged(state);
50}
diff --git a/utils/wpseditor/gui/src/qwpsstate.h b/utils/wpseditor/gui/src/qwpsstate.h
deleted file mode 100644
index 4e250079da..0000000000
--- a/utils/wpseditor/gui/src/qwpsstate.h
+++ /dev/null
@@ -1,75 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 *
9 * Copyright (C) 2007 by Rostilav Checkan
10 * $Id$
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#ifndef __WPSSTATE_H__
23#define __WPSSTATE_H__
24
25#include <QObject>
26#include "wpsstate.h"
27
28class QWpsState : public QObject {
29 Q_OBJECT
30
31
32 Q_CLASSINFO("QWpsState", "WPS State");
33 Q_PROPERTY(int FontHeight READ fontHeight WRITE setFontHeight DESIGNABLE true USER true)
34 Q_CLASSINFO("FontHeight", "minimum=6;maximum=20;value=10");
35 Q_PROPERTY(int FontWidth READ fontWidth WRITE setFontWidth DESIGNABLE true USER true)
36 Q_CLASSINFO("FontWidth", "minimum=4;maximum=20;value=8");
37 Q_PROPERTY(int Volume READ volume WRITE setVolume DESIGNABLE true USER true)
38 Q_CLASSINFO("Volume", "minimum=-74;maximum=24;value=-15");
39 Q_PROPERTY(int Battery READ battery WRITE setBattery DESIGNABLE true USER true)
40 Q_CLASSINFO("Battery", "minimum=0;maximum=100;value=50");
41
42 wpsstate state;
43
44public:
45 QWpsState();
46
47 int fontHeight() const {
48 return state.fontheight;
49 }
50 void setFontHeight(int val);
51
52 int fontWidth() const {
53 return state.fontwidth;
54 }
55 void setFontWidth(int val);
56
57 int battery() const {
58 return state.battery_level;
59 }
60 void setBattery(int val);
61
62 int volume() const {
63 return state.volume;
64 }
65public slots:
66 void setVolume(int val);
67
68
69
70
71
72signals:
73 void stateChanged ( wpsstate state );
74};
75#endif // __WPSSTATE_H__
diff --git a/utils/wpseditor/gui/src/slider.cpp b/utils/wpseditor/gui/src/slider.cpp
deleted file mode 100644
index 32b79f5047..0000000000
--- a/utils/wpseditor/gui/src/slider.cpp
+++ /dev/null
@@ -1,42 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 *
9 * Copyright (C) 2007 by Rostilav Checkan
10 * $Id$
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#include "slider.h"
23#include <QDebug>
24//
25Slider::Slider(QWidget *parent, QString caption, int min, int max ):QDialog(parent),mCaption(caption) {
26 setupUi ( this );
27 connect(horslider, SIGNAL(valueChanged(int)), this, SIGNAL(valueChanged(int)));
28 connect(this, SIGNAL(valueChanged(int)), this, SLOT(slotValueChanged(int)));
29 setWindowTitle(mCaption);
30 horslider->setMinimum(min);
31 horslider->setMaximum(max);
32}
33//
34int Slider::value() {
35 return horslider->value();
36}
37void Slider::slotValueChanged(int step) {
38 setWindowTitle(tr("%1 = %2 ").arg(mCaption).arg(step));
39}
40
41
42
diff --git a/utils/wpseditor/gui/src/slider.h b/utils/wpseditor/gui/src/slider.h
deleted file mode 100644
index 5ece49d596..0000000000
--- a/utils/wpseditor/gui/src/slider.h
+++ /dev/null
@@ -1,43 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 *
9 * Copyright (C) 2007 by Rostilav Checkan
10 * $Id$
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#ifndef SLIDERIMPL_H
23#define SLIDERIMPL_H
24//
25#include <QWidget>
26#include <QDialog>
27#include "ui_slider.h"
28//
29class Slider : public QDialog , Ui::slider {
30 Q_OBJECT
31 QString mCaption;
32public slots:
33 void slotValueChanged(int step);
34signals:
35 void valueChanged(int);
36public:
37 Slider(QWidget *parent, QString caption, int min, int max );
38 int value();
39
40
41
42};
43#endif
diff --git a/utils/wpseditor/gui/src/utils.cpp b/utils/wpseditor/gui/src/utils.cpp
deleted file mode 100644
index 74e4c907c8..0000000000
--- a/utils/wpseditor/gui/src/utils.cpp
+++ /dev/null
@@ -1,48 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 *
9 * Copyright (C) 2007 by Rostilav Checkan
10 * $Id$
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#include "utils.h"
23#include <QPointer>
24#include <QtGlobal>
25#include "qwpseditorwindow.h"
26
27extern QPointer<QWpsEditorWindow> win;
28
29int qlogger(const char* fmt,...) {
30 va_list ap;
31 va_start(ap, fmt);
32 QString s;
33 s.vsprintf(fmt,ap);
34 va_end(ap);
35 s.replace("\n","");
36 //qDebug()<<s;
37 if (win==0)
38 qDebug()<<s;
39 if (s.indexOf("ERR")>=0)
40 s = "<font color=red>"+s+"</font>";
41 if (win!=0)
42 win->logMsg(s);
43 return s.length();
44}
45
46int qlogger(const QString& s) {
47 return qlogger(s.toAscii().data());
48}
diff --git a/utils/wpseditor/gui/src/utils.h b/utils/wpseditor/gui/src/utils.h
deleted file mode 100644
index 144f9f0f0b..0000000000
--- a/utils/wpseditor/gui/src/utils.h
+++ /dev/null
@@ -1,34 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 *
9 * Copyright (C) 2007 by Rostilav Checkan
10 * $Id$
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#ifndef __UTILS_H__
23#define __UTILS_H__
24
25#include <QDebug>
26
27#define DEBUGF1 qlogger
28#define DEBUGF2(...)
29#define DEBUGF3 qDebug
30
31extern int qlogger(const char* fmt,...);
32extern int qlogger(const QString& s);
33
34#endif // __UTILS_H__
diff --git a/utils/wpseditor/gui/ui/mainwindow.ui b/utils/wpseditor/gui/ui/mainwindow.ui
deleted file mode 100644
index a14eb832ad..0000000000
--- a/utils/wpseditor/gui/ui/mainwindow.ui
+++ /dev/null
@@ -1,242 +0,0 @@
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 <widget class="QMenuBar" name="menubar" >
17 <property name="geometry" >
18 <rect>
19 <x>0</x>
20 <y>0</y>
21 <width>882</width>
22 <height>21</height>
23 </rect>
24 </property>
25 <widget class="QMenu" name="menuFile" >
26 <property name="title" >
27 <string>File</string>
28 </property>
29 <addaction name="actOpenWps" />
30 <addaction name="actSetVolume" />
31 <addaction name="actSetProgress" />
32 <addaction name="actShowGrid" />
33 <addaction name="actClearLog" />
34 <addaction name="actVerboseLevel" />
35 <addaction name="actQuit" />
36 </widget>
37 <widget class="QMenu" name="menuPlay" >
38 <property name="title" >
39 <string>Play</string>
40 </property>
41 </widget>
42 <widget class="QMenu" name="menuTarget" >
43 <property name="title" >
44 <string>Target</string>
45 </property>
46 </widget>
47 <addaction name="menuFile" />
48 <addaction name="menuPlay" />
49 <addaction name="menuTarget" />
50 </widget>
51 <widget class="QStatusBar" name="statusbar" />
52 <widget class="QDockWidget" name="dockPlainWps" >
53 <property name="minimumSize" >
54 <size>
55 <width>0</width>
56 <height>30</height>
57 </size>
58 </property>
59 <property name="windowTitle" >
60 <string>PlainWps</string>
61 </property>
62 <attribute name="dockWidgetArea" >
63 <number>8</number>
64 </attribute>
65 <widget class="QWidget" name="dockWidgetContents_3" >
66 <layout class="QGridLayout" name="gridLayout_2" >
67 <item row="0" column="1" >
68 <widget class="QPushButton" name="btnUpdatePlainWps" >
69 <property name="text" >
70 <string>Update WPS</string>
71 </property>
72 </widget>
73 </item>
74 <item row="1" column="1" >
75 <spacer name="verticalSpacer" >
76 <property name="orientation" >
77 <enum>Qt::Vertical</enum>
78 </property>
79 <property name="sizeHint" stdset="0" >
80 <size>
81 <width>20</width>
82 <height>211</height>
83 </size>
84 </property>
85 </spacer>
86 </item>
87 <item rowspan="2" row="0" column="0" >
88 <widget class="NumberedTextView" name="plainWpsEdit" >
89 <property name="sizePolicy" >
90 <sizepolicy vsizetype="Preferred" hsizetype="Preferred" >
91 <horstretch>2</horstretch>
92 <verstretch>0</verstretch>
93 </sizepolicy>
94 </property>
95 <property name="frameShape" >
96 <enum>QFrame::StyledPanel</enum>
97 </property>
98 <property name="frameShadow" >
99 <enum>QFrame::Raised</enum>
100 </property>
101 </widget>
102 </item>
103 </layout>
104 </widget>
105 </widget>
106 <widget class="QDockWidget" name="m_dockWidget" >
107 <property name="windowTitle" >
108 <string>Property Editor</string>
109 </property>
110 <attribute name="dockWidgetArea" >
111 <number>1</number>
112 </attribute>
113 <widget class="QPropertyEditorWidget" name="m_propertyEditor" >
114 <property name="enabled" >
115 <bool>false</bool>
116 </property>
117 </widget>
118 </widget>
119 <widget class="QDockWidget" name="dockWidget" >
120 <property name="minimumSize" >
121 <size>
122 <width>0</width>
123 <height>30</height>
124 </size>
125 </property>
126 <property name="windowTitle" >
127 <string>Log</string>
128 </property>
129 <attribute name="dockWidgetArea" >
130 <number>2</number>
131 </attribute>
132 <widget class="QWidget" name="dockWidgetContents" >
133 <layout class="QGridLayout" name="gridLayout" >
134 <item row="0" column="0" >
135 <widget class="QTextEdit" name="logEdit" >
136 <property name="autoFillBackground" >
137 <bool>false</bool>
138 </property>
139 <property name="readOnly" >
140 <bool>true</bool>
141 </property>
142 </widget>
143 </item>
144 </layout>
145 </widget>
146 </widget>
147 <action name="actQuit" >
148 <property name="text" >
149 <string>Quit</string>
150 </property>
151 </action>
152 <action name="actOpenWps" >
153 <property name="text" >
154 <string>Open WPS</string>
155 </property>
156 </action>
157 <action name="actSetVolume" >
158 <property name="text" >
159 <string>Set Volume</string>
160 </property>
161 </action>
162 <action name="actSetProgress" >
163 <property name="text" >
164 <string>Set Progress</string>
165 </property>
166 </action>
167 <action name="actShowGrid" >
168 <property name="checkable" >
169 <bool>true</bool>
170 </property>
171 <property name="checked" >
172 <bool>false</bool>
173 </property>
174 <property name="text" >
175 <string>Show Grid</string>
176 </property>
177 </action>
178 <action name="actClearLog" >
179 <property name="text" >
180 <string>Clear Log</string>
181 </property>
182 </action>
183 <action name="actVerboseLevel" >
184 <property name="text" >
185 <string>Verbose Level</string>
186 </property>
187 </action>
188 <action name="actUpdatePlainWps" >
189 <property name="text" >
190 <string>Update WPS</string>
191 </property>
192 </action>
193 </widget>
194 <customwidgets>
195 <customwidget>
196 <class>QPropertyEditorWidget</class>
197 <extends>QTreeView</extends>
198 <header>QPropertyEditorWidget.h</header>
199 </customwidget>
200 <customwidget>
201 <class>NumberedTextView</class>
202 <extends>QFrame</extends>
203 <header>numberedtextview.h</header>
204 <container>1</container>
205 </customwidget>
206 </customwidgets>
207 <resources/>
208 <connections>
209 <connection>
210 <sender>btnUpdatePlainWps</sender>
211 <signal>clicked()</signal>
212 <receiver>actUpdatePlainWps</receiver>
213 <slot>trigger()</slot>
214 <hints>
215 <hint type="sourcelabel" >
216 <x>835</x>
217 <y>411</y>
218 </hint>
219 <hint type="destinationlabel" >
220 <x>-1</x>
221 <y>-1</y>
222 </hint>
223 </hints>
224 </connection>
225 <connection>
226 <sender>actQuit</sender>
227 <signal>triggered()</signal>
228 <receiver>MainWindow</receiver>
229 <slot>close()</slot>
230 <hints>
231 <hint type="sourcelabel" >
232 <x>-1</x>
233 <y>-1</y>
234 </hint>
235 <hint type="destinationlabel" >
236 <x>440</x>
237 <y>334</y>
238 </hint>
239 </hints>
240 </connection>
241 </connections>
242</ui>
diff --git a/utils/wpseditor/gui/ui/slider.ui b/utils/wpseditor/gui/ui/slider.ui
deleted file mode 100644
index 24fff0bf23..0000000000
--- a/utils/wpseditor/gui/ui/slider.ui
+++ /dev/null
@@ -1,43 +0,0 @@
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>