summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Bieber <robby@bieberphoto.com>2010-06-24 07:59:41 +0000
committerRobert Bieber <robby@bieberphoto.com>2010-06-24 07:59:41 +0000
commit1ae6ee263b9ef6f356760002f3f02197927a963b (patch)
treec9fec66fd676f421e22554f0b51a3a4a2f9ffab8
parent103eabd31fb4a5b21e183a7a081ad204720e0eb0 (diff)
downloadrockbox-1ae6ee263b9ef6f356760002f3f02197927a963b.tar.gz
rockbox-1ae6ee263b9ef6f356760002f3f02197927a963b.zip
Theme Editor: Fixed some resource alias issues, implemented device configuration panel that loads options from a text file
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27102 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--utils/themeeditor/gui/devicestate.cpp182
-rw-r--r--utils/themeeditor/gui/devicestate.h25
-rw-r--r--utils/themeeditor/gui/devicestate.ui130
-rw-r--r--utils/themeeditor/gui/editorwindow.cpp4
-rw-r--r--utils/themeeditor/gui/editorwindow.ui5
-rw-r--r--utils/themeeditor/gui/preferencesdialog.ui8
-rw-r--r--utils/themeeditor/resources.qrc3
-rw-r--r--utils/themeeditor/resources/deviceoptions39
-rw-r--r--utils/themeeditor/themeeditor.pro6
9 files changed, 257 insertions, 145 deletions
diff --git a/utils/themeeditor/gui/devicestate.cpp b/utils/themeeditor/gui/devicestate.cpp
index af0b846372..fb35e77b36 100644
--- a/utils/themeeditor/gui/devicestate.cpp
+++ b/utils/themeeditor/gui/devicestate.cpp
@@ -22,14 +22,188 @@
22#include "devicestate.h" 22#include "devicestate.h"
23#include "ui_devicestate.h" 23#include "ui_devicestate.h"
24 24
25#include <QScrollArea>
26#include <QFile>
27#include <QCheckBox>
28#include <QSpinBox>
29#include <QComboBox>
30
25DeviceState::DeviceState(QWidget *parent) : 31DeviceState::DeviceState(QWidget *parent) :
26 QWidget(parent), 32 QWidget(parent), tabs(this)
27 ui(new Ui::DeviceState)
28{ 33{
29 ui->setupUi(this); 34 /* UI stuff */
35 resize(500,400);
36 setWindowIcon(QIcon(":/resources/windowicon.png"));
37 setWindowTitle(tr("Device Settings"));
38
39 QVBoxLayout* layout = new QVBoxLayout(this);
40 layout->addWidget(&tabs);
41 this->setLayout(layout);
42
43 /* Loading the tabs */
44 QScrollArea* currentArea;
45 QHBoxLayout* subLayout;
46 QWidget* panel;
47 QWidget* temp;
48
49 QFile fin(":/resources/deviceoptions");
50 fin.open(QFile::Text | QFile::ReadOnly);
51 while(!fin.atEnd())
52 {
53 QString line = QString(fin.readLine());
54 line = line.trimmed();
55
56 /* Continue on a comment or an empty line */
57 if(line[0] == '#' || line.length() == 0)
58 continue;
59
60 if(line[0] == '[')
61 {
62 QString buffer;
63 for(int i = 1; line[i] != ']'; i++)
64 buffer.append(line[i]);
65 buffer = buffer.trimmed();
66
67 panel = new QWidget();
68 currentArea = new QScrollArea();
69 layout = new QVBoxLayout(panel);
70 currentArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
71 currentArea->setWidget(panel);
72 currentArea->setWidgetResizable(true);
73
74 tabs.addTab(currentArea, buffer);
75
76 continue;
77 }
78
79 QStringList elements = line.split(";");
80 QString tag = elements[0].trimmed();
81 QString title = elements[1].trimmed();
82 QString type = elements[2].trimmed();
83 QString defVal = elements[3].trimmed();
84
85 subLayout = new QHBoxLayout();
86 if(type != "check")
87 subLayout->addWidget(new QLabel(elements[1].trimmed(), currentArea));
88 layout->addLayout(subLayout);
89
90
91 elements = type.split("(");
92 if(elements[0].trimmed() == "text")
93 {
94 temp = new QLineEdit(defVal, currentArea);
95 subLayout->addWidget(temp);
96 inputs.insert(tag, QPair<InputType, QWidget*>(Text, temp));
97 }
98 else if(elements[0].trimmed() == "check")
99 {
100 temp = new QCheckBox(title, currentArea);
101 subLayout->addWidget(temp);
102 if(defVal.toLower() == "true")
103 dynamic_cast<QCheckBox*>(temp)->setChecked(true);
104 else
105 dynamic_cast<QCheckBox*>(temp)->setChecked(false);
106 inputs.insert(tag, QPair<InputType, QWidget*>(Check, temp));
107 }
108 else if(elements[0].trimmed() == "slider")
109 {
110 elements = elements[1].trimmed().split(",");
111 int min = elements[0].trimmed().toInt();
112 QString maxS = elements[1].trimmed();
113 maxS.chop(1);
114 int max = maxS.toInt();
115
116 temp = new QSlider(Qt::Horizontal, currentArea);
117 dynamic_cast<QSlider*>(temp)->setMinimum(min);
118 dynamic_cast<QSlider*>(temp)->setMaximum(max);
119 dynamic_cast<QSlider*>(temp)->setValue(defVal.toInt());
120 subLayout->addWidget(temp);
121 inputs.insert(tag, QPair<InputType, QWidget*>(Slide, temp));
122 }
123 else if(elements[0].trimmed() == "spin")
124 {
125 elements = elements[1].trimmed().split(",");
126 int min = elements[0].trimmed().toInt();
127 QString maxS = elements[1].trimmed();
128 maxS.chop(1);
129 int max = maxS.toInt();
130
131 temp = new QSpinBox(currentArea);
132 dynamic_cast<QSpinBox*>(temp)->setMinimum(min);
133 dynamic_cast<QSpinBox*>(temp)->setMaximum(max);
134 dynamic_cast<QSpinBox*>(temp)->setValue(defVal.toInt());
135 subLayout->addWidget(temp);
136 inputs.insert(tag, QPair<InputType, QWidget*>(Spin, temp));
137 }
138 else if(elements[0].trimmed() == "fspin")
139 {
140 elements = elements[1].trimmed().split(",");
141 int min = elements[0].trimmed().toDouble();
142 QString maxS = elements[1].trimmed();
143 maxS.chop(1);
144 int max = maxS.toDouble();
145
146 temp = new QDoubleSpinBox(currentArea);
147 dynamic_cast<QDoubleSpinBox*>(temp)->setMinimum(min);
148 dynamic_cast<QDoubleSpinBox*>(temp)->setMaximum(max);
149 dynamic_cast<QDoubleSpinBox*>(temp)->setValue(defVal.toDouble());
150 dynamic_cast<QDoubleSpinBox*>(temp)->setSingleStep(0.1);
151 subLayout->addWidget(temp);
152 inputs.insert(tag, QPair<InputType, QWidget*>(DSpin, temp));
153 }
154 else if(elements[0].trimmed() == "combo")
155 {
156 elements = elements[1].trimmed().split(",");
157
158 int defIndex;
159 temp = new QComboBox(currentArea);
160 for(int i = 0; i < elements.count(); i++)
161 {
162 QString current = elements[i].trimmed();
163 if(i == elements.count() - 1)
164 current.chop(1);
165 dynamic_cast<QComboBox*>(temp)->addItem(current, i);
166 if(current == defVal)
167 defIndex = i;
168 }
169 dynamic_cast<QComboBox*>(temp)->setCurrentIndex(defIndex);
170 subLayout->addWidget(temp);
171 inputs.insert(tag, QPair<InputType, QWidget*>(Combo, temp));
172 }
173
174 }
30} 175}
31 176
32DeviceState::~DeviceState() 177DeviceState::~DeviceState()
33{ 178{
34 delete ui; 179}
180
181QVariant DeviceState::data(QString tag)
182{
183 QPair<InputType, QWidget*> found =
184 inputs.value(tag, QPair<InputType, QWidget*>(Slide, 0));
185
186 if(found.second == 0)
187 return QVariant();
188
189 switch(found.first)
190 {
191 case Text:
192 return dynamic_cast<QLineEdit*>(found.second)->text();
193
194 case Slide:
195 return dynamic_cast<QSlider*>(found.second)->value();
196
197 case Spin:
198 return dynamic_cast<QSpinBox*>(found.second)->value();
199
200 case DSpin:
201 return dynamic_cast<QDoubleSpinBox*>(found.second)->value();
202
203 case Combo:
204 return dynamic_cast<QComboBox*>(found.second)->currentIndex();
205
206 case Check:
207 return dynamic_cast<QCheckBox*>(found.second)->isChecked();
208 }
35} 209}
diff --git a/utils/themeeditor/gui/devicestate.h b/utils/themeeditor/gui/devicestate.h
index 66cd98be78..8938e01f29 100644
--- a/utils/themeeditor/gui/devicestate.h
+++ b/utils/themeeditor/gui/devicestate.h
@@ -23,19 +23,34 @@
23#define DEVICESTATE_H 23#define DEVICESTATE_H
24 24
25#include <QWidget> 25#include <QWidget>
26 26#include <QMap>
27namespace Ui { 27#include <QPair>
28 class DeviceState; 28#include <QVariant>
29} 29#include <QTabWidget>
30 30
31class DeviceState : public QWidget { 31class DeviceState : public QWidget {
32
32 Q_OBJECT 33 Q_OBJECT
34
33public: 35public:
36 enum InputType
37 {
38 Text,
39 Slide,
40 Spin,
41 DSpin,
42 Combo,
43 Check
44 };
45
34 DeviceState(QWidget *parent = 0); 46 DeviceState(QWidget *parent = 0);
35 virtual ~DeviceState(); 47 virtual ~DeviceState();
36 48
49 QVariant data(QString tag);
50
37private: 51private:
38 Ui::DeviceState *ui; 52 QMap<QString, QPair<InputType, QWidget*> > inputs;
53 QTabWidget tabs;
39}; 54};
40 55
41#endif // DEVICESTATE_H 56#endif // DEVICESTATE_H
diff --git a/utils/themeeditor/gui/devicestate.ui b/utils/themeeditor/gui/devicestate.ui
deleted file mode 100644
index 17f6129c9e..0000000000
--- a/utils/themeeditor/gui/devicestate.ui
+++ /dev/null
@@ -1,130 +0,0 @@
1<?xml version="1.0" encoding="UTF-8"?>
2<ui version="4.0">
3 <class>DeviceState</class>
4 <widget class="QWidget" name="DeviceState">
5 <property name="geometry">
6 <rect>
7 <x>0</x>
8 <y>0</y>
9 <width>400</width>
10 <height>300</height>
11 </rect>
12 </property>
13 <property name="windowTitle">
14 <string>Device Settings</string>
15 </property>
16 <property name="windowIcon">
17 <iconset resource="../resources.qrc">
18 <normaloff>:/resources/resources/windowicon.png</normaloff>:/resources/resources/windowicon.png</iconset>
19 </property>
20 <layout class="QVBoxLayout" name="verticalLayout">
21 <item>
22 <widget class="QToolBox" name="toolBox">
23 <property name="currentIndex">
24 <number>1</number>
25 </property>
26 <widget class="QWidget" name="page">
27 <property name="geometry">
28 <rect>
29 <x>0</x>
30 <y>0</y>
31 <width>382</width>
32 <height>220</height>
33 </rect>
34 </property>
35 <attribute name="label">
36 <string>Device Basics</string>
37 </attribute>
38 <layout class="QVBoxLayout" name="verticalLayout_2">
39 <item>
40 <layout class="QHBoxLayout" name="horizontalLayout">
41 <item>
42 <widget class="QLabel" name="label">
43 <property name="text">
44 <string>Screen Width</string>
45 </property>
46 <property name="buddy">
47 <cstring>widthBox</cstring>
48 </property>
49 </widget>
50 </item>
51 <item>
52 <widget class="QLineEdit" name="widthBox"/>
53 </item>
54 </layout>
55 </item>
56 <item>
57 <layout class="QHBoxLayout" name="horizontalLayout_2">
58 <item>
59 <widget class="QLabel" name="label_2">
60 <property name="text">
61 <string>Screen Height</string>
62 </property>
63 <property name="buddy">
64 <cstring>heightBox</cstring>
65 </property>
66 </widget>
67 </item>
68 <item>
69 <widget class="QLineEdit" name="heightBox"/>
70 </item>
71 </layout>
72 </item>
73 <item>
74 <layout class="QHBoxLayout" name="horizontalLayout_3">
75 <item>
76 <widget class="QLabel" name="label_3">
77 <property name="text">
78 <string>Remote Width</string>
79 </property>
80 <property name="buddy">
81 <cstring>rWidthBox</cstring>
82 </property>
83 </widget>
84 </item>
85 <item>
86 <widget class="QLineEdit" name="rWidthBox"/>
87 </item>
88 </layout>
89 </item>
90 <item>
91 <layout class="QHBoxLayout" name="horizontalLayout_4">
92 <item>
93 <widget class="QLabel" name="label_4">
94 <property name="text">
95 <string>Remote Height</string>
96 </property>
97 <property name="buddy">
98 <cstring>rHeightBox</cstring>
99 </property>
100 </widget>
101 </item>
102 <item>
103 <widget class="QLineEdit" name="rHeightBox"/>
104 </item>
105 </layout>
106 </item>
107 </layout>
108 </widget>
109 <widget class="QWidget" name="page_2">
110 <property name="geometry">
111 <rect>
112 <x>0</x>
113 <y>0</y>
114 <width>382</width>
115 <height>220</height>
116 </rect>
117 </property>
118 <attribute name="label">
119 <string>Device Status</string>
120 </attribute>
121 </widget>
122 </widget>
123 </item>
124 </layout>
125 </widget>
126 <resources>
127 <include location="../resources.qrc"/>
128 </resources>
129 <connections/>
130</ui>
diff --git a/utils/themeeditor/gui/editorwindow.cpp b/utils/themeeditor/gui/editorwindow.cpp
index 2bd3b5343e..1aec46a7cc 100644
--- a/utils/themeeditor/gui/editorwindow.cpp
+++ b/utils/themeeditor/gui/editorwindow.cpp
@@ -144,6 +144,10 @@ void EditorWindow::setupUI()
144 viewer = new SkinViewer(this); 144 viewer = new SkinViewer(this);
145 ui->skinPreviewLayout->addWidget(viewer); 145 ui->skinPreviewLayout->addWidget(viewer);
146 146
147 /* Positioning the device settings dialog */
148 QPoint thisPos = pos();
149 deviceConfig.move(thisPos.x() + width() / 4, thisPos.y() + height() / 4);
150
147} 151}
148 152
149void EditorWindow::setupMenus() 153void EditorWindow::setupMenus()
diff --git a/utils/themeeditor/gui/editorwindow.ui b/utils/themeeditor/gui/editorwindow.ui
index a7d804bd6b..2f84d384c8 100644
--- a/utils/themeeditor/gui/editorwindow.ui
+++ b/utils/themeeditor/gui/editorwindow.ui
@@ -15,7 +15,7 @@
15 </property> 15 </property>
16 <property name="windowIcon"> 16 <property name="windowIcon">
17 <iconset resource="../resources.qrc"> 17 <iconset resource="../resources.qrc">
18 <normaloff>:/resources/resources/windowicon.png</normaloff>:/resources/resources/windowicon.png</iconset> 18 <normaloff>:/resources/windowicon.png</normaloff>:/resources/windowicon.png</iconset>
19 </property> 19 </property>
20 <widget class="QWidget" name="centralwidget"> 20 <widget class="QWidget" name="centralwidget">
21 <layout class="QVBoxLayout" name="verticalLayout"> 21 <layout class="QVBoxLayout" name="verticalLayout">
@@ -299,6 +299,9 @@
299 <property name="text"> 299 <property name="text">
300 <string>&amp;Device Configuration</string> 300 <string>&amp;Device Configuration</string>
301 </property> 301 </property>
302 <property name="shortcut">
303 <string>Ctrl+D</string>
304 </property>
302 </action> 305 </action>
303 </widget> 306 </widget>
304 <tabstops> 307 <tabstops>
diff --git a/utils/themeeditor/gui/preferencesdialog.ui b/utils/themeeditor/gui/preferencesdialog.ui
index 1da7811b62..7dddcf9057 100644
--- a/utils/themeeditor/gui/preferencesdialog.ui
+++ b/utils/themeeditor/gui/preferencesdialog.ui
@@ -13,6 +13,10 @@
13 <property name="windowTitle"> 13 <property name="windowTitle">
14 <string>Preferences</string> 14 <string>Preferences</string>
15 </property> 15 </property>
16 <property name="windowIcon">
17 <iconset resource="../resources.qrc">
18 <normaloff>:/resources/windowicon.png</normaloff>:/resources/windowicon.png</iconset>
19 </property>
16 <layout class="QVBoxLayout" name="verticalLayout"> 20 <layout class="QVBoxLayout" name="verticalLayout">
17 <item> 21 <item>
18 <widget class="QTabWidget" name="prefsGroups"> 22 <widget class="QTabWidget" name="prefsGroups">
@@ -268,7 +272,9 @@
268 </item> 272 </item>
269 </layout> 273 </layout>
270 </widget> 274 </widget>
271 <resources/> 275 <resources>
276 <include location="../resources.qrc"/>
277 </resources>
272 <connections> 278 <connections>
273 <connection> 279 <connection>
274 <sender>buttonBox</sender> 280 <sender>buttonBox</sender>
diff --git a/utils/themeeditor/resources.qrc b/utils/themeeditor/resources.qrc
index 6815ccf8ea..27d808c240 100644
--- a/utils/themeeditor/resources.qrc
+++ b/utils/themeeditor/resources.qrc
@@ -1,10 +1,11 @@
1<RCC> 1<RCC>
2 <qresource prefix="/resources"> 2 <qresource prefix="/resources">
3 <file>resources/windowicon.png</file> 3 <file alias="windowicon.png">resources/windowicon.png</file>
4 <file>resources/document-new.png</file> 4 <file>resources/document-new.png</file>
5 <file>resources/document-open.png</file> 5 <file>resources/document-open.png</file>
6 <file>resources/document-save.png</file> 6 <file>resources/document-save.png</file>
7 <file alias="configkeys">resources/configkeys</file> 7 <file alias="configkeys">resources/configkeys</file>
8 <file alias="deviceoptions">resources/deviceoptions</file>
8 </qresource> 9 </qresource>
9 <qresource prefix="/render"> 10 <qresource prefix="/render">
10 <file alias="scenebg.png">resources/render/scenebg.png</file> 11 <file alias="scenebg.png">resources/render/scenebg.png</file>
diff --git a/utils/themeeditor/resources/deviceoptions b/utils/themeeditor/resources/deviceoptions
new file mode 100644
index 0000000000..cd306f50db
--- /dev/null
+++ b/utils/themeeditor/resources/deviceoptions
@@ -0,0 +1,39 @@
1# This file defines the options for the device configuration panel
2# Declare a section with a line containing a string inside brackets, i.e.
3# [Some Section]
4# Declare options within the section in the following format, one per line
5# tag;Tag Label;[input];default
6# tag is the skin tag represented by that option
7#
8# Tag Label is a human-readable label to attach to the input
9#
10# [input] is the type of widget that should be used for the tag, and its range
11# if applicable. The valid forms are
12# check - Inserts a true/false checkbox
13# text - Inserts a line edit box
14# slider(min, max) - Inserts a horizontal slider with range specified
15# spin(min, max) - Inserts a spin box with range specified
16# fspin(min, max) - Inserts a floating point spin box with range specified
17# combo(option1, option2...) - Inserts a combo box with the options specified
18#
19# default is the default value for the input
20#
21# Note that there aren't any provisions for escaping characters at the moment,
22# so don't include [, ], or ; in your text, or (, ) in combo box choices
23#
24# Blank lines are ignored
25#
26# Be warned: because this file is compiled into the application, I'm not
27# performing much of any error checking on it: screwing up the syntax may very
28# well segfault the application on startup
29
30[Test Section 1]
31a ; Text Input ; text ; Some text
32b ; Checkbox ; check ; false
33c ; Slider 1 - 5 ; slider(1, 5) ; 4
34
35[Test Section 2]
36d ; Spinbox 6 - 10 ; spin(6, 10) ; 8
37e ; Float Spinbox 2.5 - 6.3; fspin(2.5, 6.3) ; 3.9
38# A combo box ends up returning an integer from 0 to n - 1, with n choices
39f ; Combo Box; combo(An option, Another Option, A Third option) ; Another Option
diff --git a/utils/themeeditor/themeeditor.pro b/utils/themeeditor/themeeditor.pro
index 6237ee8f70..50cafe054d 100644
--- a/utils/themeeditor/themeeditor.pro
+++ b/utils/themeeditor/themeeditor.pro
@@ -64,10 +64,10 @@ OTHER_FILES += README \
64 resources/COPYING \ 64 resources/COPYING \
65 resources/document-save.png \ 65 resources/document-save.png \
66 resources/document-open.png \ 66 resources/document-open.png \
67 resources/document-new.png 67 resources/document-new.png \
68 resources/deviceoptions
68FORMS += gui/editorwindow.ui \ 69FORMS += gui/editorwindow.ui \
69 gui/preferencesdialog.ui \ 70 gui/preferencesdialog.ui \
70 gui/configdocument.ui \ 71 gui/configdocument.ui \
71 gui/skinviewer.ui \ 72 gui/skinviewer.ui
72 gui/devicestate.ui
73RESOURCES += resources.qrc 73RESOURCES += resources.qrc