diff options
Diffstat (limited to 'utils/themeeditor/gui')
-rw-r--r-- | utils/themeeditor/gui/configdocument.cpp | 150 | ||||
-rw-r--r-- | utils/themeeditor/gui/configdocument.h | 19 | ||||
-rw-r--r-- | utils/themeeditor/gui/configdocument.ui | 81 |
3 files changed, 223 insertions, 27 deletions
diff --git a/utils/themeeditor/gui/configdocument.cpp b/utils/themeeditor/gui/configdocument.cpp index 0962484ba9..f3bfc7280c 100644 --- a/utils/themeeditor/gui/configdocument.cpp +++ b/utils/themeeditor/gui/configdocument.cpp | |||
@@ -27,14 +27,50 @@ | |||
27 | #include <QFile> | 27 | #include <QFile> |
28 | #include <QSettings> | 28 | #include <QSettings> |
29 | #include <QFileDialog> | 29 | #include <QFileDialog> |
30 | #include <QPair> | ||
30 | 31 | ||
31 | ConfigDocument::ConfigDocument(QMap<QString, QString>& settings, QString file, | 32 | ConfigDocument::ConfigDocument(QMap<QString, QString>& settings, QString file, |
32 | QWidget *parent) | 33 | QWidget *parent) |
33 | : TabContent(parent), | 34 | : TabContent(parent), |
34 | ui(new Ui::ConfigDocument), | 35 | ui(new Ui::ConfigDocument), |
35 | filePath(file) | 36 | filePath(file), block(false) |
36 | { | 37 | { |
37 | ui->setupUi(this); | 38 | ui->setupUi(this); |
39 | editor = new CodeEditor(this); | ||
40 | editor->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); | ||
41 | editor->setLineWrapMode(CodeEditor::NoWrap); | ||
42 | ui->splitter->addWidget(editor); | ||
43 | |||
44 | QObject::connect(editor, SIGNAL(textChanged()), | ||
45 | this, SLOT(textChanged())); | ||
46 | |||
47 | /* Loading the splitter status */ | ||
48 | QSettings appSettings; | ||
49 | appSettings.beginGroup("ConfigDocument"); | ||
50 | |||
51 | if(!appSettings.value("textVisible", true).toBool()) | ||
52 | { | ||
53 | editor->setVisible(false); | ||
54 | ui->textButton->setChecked(false); | ||
55 | } | ||
56 | else | ||
57 | { | ||
58 | ui->textButton->setChecked(true); | ||
59 | } | ||
60 | if(!appSettings.value("linesVisible", false).toBool()) | ||
61 | { | ||
62 | ui->scrollArea->setVisible(false); | ||
63 | ui->linesButton->setChecked(false); | ||
64 | } | ||
65 | else | ||
66 | { | ||
67 | ui->linesButton->setChecked(true); | ||
68 | } | ||
69 | |||
70 | if(!appSettings.value("splitter", QByteArray()).toByteArray().isNull()) | ||
71 | ui->splitter->restoreState(appSettings.value("splitter").toByteArray()); | ||
72 | |||
73 | appSettings.endGroup(); | ||
38 | 74 | ||
39 | /* Populating the known keys list */ | 75 | /* Populating the known keys list */ |
40 | QFile fin(":/resources/configkeys"); | 76 | QFile fin(":/resources/configkeys"); |
@@ -50,20 +86,29 @@ ConfigDocument::ConfigDocument(QMap<QString, QString>& settings, QString file, | |||
50 | container->append(current.trimmed()); | 86 | container->append(current.trimmed()); |
51 | } | 87 | } |
52 | 88 | ||
53 | QMap<QString, QString>::iterator i; | 89 | /* Loading the text file */ |
54 | for(i = settings.begin(); i != settings.end(); i++) | 90 | QFile finT(settings.value("configfile", "")); |
55 | if(i.key() != "themebase") | 91 | if(finT.open(QFile::Text | QFile::ReadOnly)) |
56 | addRow(i.key(), i.value()); | 92 | { |
93 | editor->setPlainText(QString(finT.readAll())); | ||
94 | finT.close(); | ||
95 | } | ||
57 | 96 | ||
58 | saved = toPlainText(); | 97 | saved = toPlainText(); |
59 | 98 | ||
60 | QObject::connect(ui->addKeyButton, SIGNAL(pressed()), | 99 | QObject::connect(ui->addKeyButton, SIGNAL(pressed()), |
61 | this, SLOT(addClicked())); | 100 | this, SLOT(addClicked())); |
101 | |||
102 | QObject::connect(ui->linesButton, SIGNAL(toggled(bool)), | ||
103 | this, SLOT(buttonChecked())); | ||
104 | QObject::connect(ui->textButton, SIGNAL(toggled(bool)), | ||
105 | this, SLOT(buttonChecked())); | ||
62 | } | 106 | } |
63 | 107 | ||
64 | ConfigDocument::~ConfigDocument() | 108 | ConfigDocument::~ConfigDocument() |
65 | { | 109 | { |
66 | delete ui; | 110 | delete ui; |
111 | editor->deleteLater(); | ||
67 | } | 112 | } |
68 | 113 | ||
69 | void ConfigDocument::changeEvent(QEvent *e) | 114 | void ConfigDocument::changeEvent(QEvent *e) |
@@ -171,6 +216,15 @@ bool ConfigDocument::requestClose() | |||
171 | 216 | ||
172 | QString ConfigDocument::toPlainText() const | 217 | QString ConfigDocument::toPlainText() const |
173 | { | 218 | { |
219 | return editor->toPlainText(); | ||
220 | } | ||
221 | |||
222 | void ConfigDocument::syncFromBoxes() | ||
223 | { | ||
224 | if(block) | ||
225 | return; | ||
226 | blockUpdates(); | ||
227 | |||
174 | QString buffer = ""; | 228 | QString buffer = ""; |
175 | 229 | ||
176 | for(int i = 0; i < keys.count(); i++) | 230 | for(int i = 0; i < keys.count(); i++) |
@@ -181,7 +235,61 @@ QString ConfigDocument::toPlainText() const | |||
181 | buffer += "\n"; | 235 | buffer += "\n"; |
182 | } | 236 | } |
183 | 237 | ||
184 | return buffer; | 238 | editor->setPlainText(buffer); |
239 | } | ||
240 | |||
241 | void ConfigDocument::syncFromText() | ||
242 | { | ||
243 | if(block) | ||
244 | return; | ||
245 | |||
246 | blockUpdates(); | ||
247 | |||
248 | QStringList lines = editor->toPlainText().split("\n"); | ||
249 | QList<QPair<QString, QString> > splits; | ||
250 | for(int i = 0; i < lines.count(); i++) | ||
251 | { | ||
252 | QString line = lines[i]; | ||
253 | QStringList split = line.split(":"); | ||
254 | if(split.count() != 2) | ||
255 | continue; | ||
256 | |||
257 | splits.append(QPair<QString, QString>(split[0].trimmed(), | ||
258 | split[1].trimmed())); | ||
259 | } | ||
260 | |||
261 | while(deleteButtons.count() > splits.count()) | ||
262 | { | ||
263 | deleteButtons[0]->deleteLater(); | ||
264 | keys[0]->deleteLater(); | ||
265 | values[0]->deleteLater(); | ||
266 | containers[0]->deleteLater(); | ||
267 | labels[0]->deleteLater(); | ||
268 | |||
269 | deleteButtons.removeAt(0); | ||
270 | keys.removeAt(0); | ||
271 | values.removeAt(0); | ||
272 | containers.removeAt(0); | ||
273 | labels.removeAt(0); | ||
274 | } | ||
275 | |||
276 | int initialCount = deleteButtons.count(); | ||
277 | for(int i = 0; i < splits.count(); i++) | ||
278 | { | ||
279 | if(i >= initialCount) | ||
280 | { | ||
281 | addRow(splits[i].first, splits[i].second); | ||
282 | } | ||
283 | else | ||
284 | { | ||
285 | int index = keys[i]->findText(splits[i].first); | ||
286 | if(index != -1) | ||
287 | keys[i]->setCurrentIndex(index); | ||
288 | else | ||
289 | keys[i]->setEditText(splits[i].first); | ||
290 | values[i]->setText(splits[i].second); | ||
291 | } | ||
292 | } | ||
185 | } | 293 | } |
186 | 294 | ||
187 | void ConfigDocument::addRow(QString key, QString value) | 295 | void ConfigDocument::addRow(QString key, QString value) |
@@ -215,11 +323,11 @@ void ConfigDocument::addRow(QString key, QString value) | |||
215 | QObject::connect(delButton, SIGNAL(clicked()), | 323 | QObject::connect(delButton, SIGNAL(clicked()), |
216 | this, SLOT(deleteClicked())); | 324 | this, SLOT(deleteClicked())); |
217 | QObject::connect(keyEdit, SIGNAL(currentIndexChanged(QString)), | 325 | QObject::connect(keyEdit, SIGNAL(currentIndexChanged(QString)), |
218 | this, SLOT(textChanged())); | 326 | this, SLOT(boxesChanged())); |
219 | QObject::connect(keyEdit, SIGNAL(textChanged(QString)), | 327 | QObject::connect(keyEdit, SIGNAL(textChanged(QString)), |
220 | this, SLOT(textChanged())); | 328 | this, SLOT(boxesChanged())); |
221 | QObject::connect(valueEdit, SIGNAL(textChanged(QString)), | 329 | QObject::connect(valueEdit, SIGNAL(textChanged(QString)), |
222 | this, SLOT(textChanged())); | 330 | this, SLOT(boxesChanged())); |
223 | 331 | ||
224 | ui->configBoxes->addLayout(layout); | 332 | ui->configBoxes->addLayout(layout); |
225 | 333 | ||
@@ -259,10 +367,34 @@ void ConfigDocument::addClicked() | |||
259 | addRow(tr("Key"), tr("Value")); | 367 | addRow(tr("Key"), tr("Value")); |
260 | } | 368 | } |
261 | 369 | ||
370 | void ConfigDocument::boxesChanged() | ||
371 | { | ||
372 | syncFromBoxes(); | ||
373 | contentsChanged(); | ||
374 | } | ||
375 | |||
262 | void ConfigDocument::textChanged() | 376 | void ConfigDocument::textChanged() |
263 | { | 377 | { |
378 | syncFromText(); | ||
379 | contentsChanged(); | ||
380 | } | ||
381 | |||
382 | void ConfigDocument::contentsChanged() | ||
383 | { | ||
264 | if(toPlainText() != saved) | 384 | if(toPlainText() != saved) |
265 | emit titleChanged(title() + "*"); | 385 | emit titleChanged(title() + "*"); |
266 | else | 386 | else |
267 | emit titleChanged(title()); | 387 | emit titleChanged(title()); |
268 | } | 388 | } |
389 | |||
390 | void ConfigDocument::buttonChecked() | ||
391 | { | ||
392 | editor->setVisible(ui->textButton->isChecked()); | ||
393 | ui->scrollArea->setVisible(ui->linesButton->isChecked()); | ||
394 | |||
395 | QSettings settings; | ||
396 | settings.beginGroup("ConfigDocument"); | ||
397 | settings.setValue("textVisible", ui->textButton->isChecked()); | ||
398 | settings.setValue("linesVisible", ui->linesButton->isChecked()); | ||
399 | settings.endGroup(); | ||
400 | } | ||
diff --git a/utils/themeeditor/gui/configdocument.h b/utils/themeeditor/gui/configdocument.h index e91c5cc357..29278dbd11 100644 --- a/utils/themeeditor/gui/configdocument.h +++ b/utils/themeeditor/gui/configdocument.h | |||
@@ -30,8 +30,10 @@ | |||
30 | #include <QLabel> | 30 | #include <QLabel> |
31 | #include <QMap> | 31 | #include <QMap> |
32 | #include <QWheelEvent> | 32 | #include <QWheelEvent> |
33 | #include <QTimer> | ||
33 | 34 | ||
34 | #include "tabcontent.h" | 35 | #include "tabcontent.h" |
36 | #include "codeeditor.h" | ||
35 | 37 | ||
36 | namespace Ui { | 38 | namespace Ui { |
37 | class ConfigDocument; | 39 | class ConfigDocument; |
@@ -58,6 +60,8 @@ public: | |||
58 | QString title() const; | 60 | QString title() const; |
59 | 61 | ||
60 | QString toPlainText() const; | 62 | QString toPlainText() const; |
63 | void syncFromBoxes(); | ||
64 | void syncFromText(); | ||
61 | 65 | ||
62 | void save(); | 66 | void save(); |
63 | void saveAs(); | 67 | void saveAs(); |
@@ -73,9 +77,20 @@ signals: | |||
73 | private slots: | 77 | private slots: |
74 | void deleteClicked(); | 78 | void deleteClicked(); |
75 | void addClicked(); | 79 | void addClicked(); |
80 | void boxesChanged(); | ||
76 | void textChanged(); | 81 | void textChanged(); |
82 | void contentsChanged(); | ||
83 | void blockUpdates() | ||
84 | { | ||
85 | block = true; | ||
86 | QTimer::singleShot(20, this, SLOT(unblockUpdates())); | ||
87 | } | ||
88 | void unblockUpdates(){ block = false; } | ||
89 | void buttonChecked(); | ||
77 | 90 | ||
78 | private: | 91 | private: |
92 | void addRow(QString key, QString value); | ||
93 | |||
79 | Ui::ConfigDocument *ui; | 94 | Ui::ConfigDocument *ui; |
80 | QList<QHBoxLayout*> containers; | 95 | QList<QHBoxLayout*> containers; |
81 | QList<NoScrollCombo*> keys; | 96 | QList<NoScrollCombo*> keys; |
@@ -89,7 +104,9 @@ private: | |||
89 | QString filePath; | 104 | QString filePath; |
90 | QString saved; | 105 | QString saved; |
91 | 106 | ||
92 | void addRow(QString key, QString value); | 107 | CodeEditor* editor; |
108 | |||
109 | bool block; | ||
93 | }; | 110 | }; |
94 | 111 | ||
95 | #endif // CONFIGDOCUMENT_H | 112 | #endif // CONFIGDOCUMENT_H |
diff --git a/utils/themeeditor/gui/configdocument.ui b/utils/themeeditor/gui/configdocument.ui index e2f9e7fb21..88d44d2191 100644 --- a/utils/themeeditor/gui/configdocument.ui +++ b/utils/themeeditor/gui/configdocument.ui | |||
@@ -15,30 +15,75 @@ | |||
15 | </property> | 15 | </property> |
16 | <layout class="QVBoxLayout" name="verticalLayout"> | 16 | <layout class="QVBoxLayout" name="verticalLayout"> |
17 | <item> | 17 | <item> |
18 | <widget class="QScrollArea" name="scrollArea"> | 18 | <widget class="QSplitter" name="splitter"> |
19 | <property name="widgetResizable"> | 19 | <property name="orientation"> |
20 | <bool>true</bool> | 20 | <enum>Qt::Vertical</enum> |
21 | </property> | 21 | </property> |
22 | <widget class="QWidget" name="scrollAreaWidgetContents"> | 22 | <widget class="QScrollArea" name="scrollArea"> |
23 | <property name="geometry"> | 23 | <property name="widgetResizable"> |
24 | <rect> | 24 | <bool>true</bool> |
25 | <x>0</x> | ||
26 | <y>0</y> | ||
27 | <width>402</width> | ||
28 | <height>244</height> | ||
29 | </rect> | ||
30 | </property> | 25 | </property> |
31 | <layout class="QVBoxLayout" name="verticalLayout_3"> | 26 | <widget class="QWidget" name="scrollAreaWidgetContents"> |
32 | <item> | 27 | <property name="geometry"> |
33 | <layout class="QVBoxLayout" name="configBoxes"/> | 28 | <rect> |
34 | </item> | 29 | <x>0</x> |
35 | </layout> | 30 | <y>0</y> |
31 | <width>402</width> | ||
32 | <height>244</height> | ||
33 | </rect> | ||
34 | </property> | ||
35 | <layout class="QVBoxLayout" name="verticalLayout_3"> | ||
36 | <item> | ||
37 | <layout class="QVBoxLayout" name="configBoxes"/> | ||
38 | </item> | ||
39 | </layout> | ||
40 | </widget> | ||
36 | </widget> | 41 | </widget> |
37 | </widget> | 42 | </widget> |
38 | </item> | 43 | </item> |
39 | <item> | 44 | <item> |
40 | <layout class="QHBoxLayout" name="horizontalLayout"> | 45 | <layout class="QHBoxLayout" name="horizontalLayout"> |
41 | <item> | 46 | <item> |
47 | <widget class="QToolButton" name="textButton"> | ||
48 | <property name="text"> | ||
49 | <string/> | ||
50 | </property> | ||
51 | <property name="icon"> | ||
52 | <iconset resource="../resources.qrc"> | ||
53 | <normaloff>:/resources/resources/cursor.png</normaloff>:/resources/resources/cursor.png</iconset> | ||
54 | </property> | ||
55 | <property name="checkable"> | ||
56 | <bool>true</bool> | ||
57 | </property> | ||
58 | <property name="checked"> | ||
59 | <bool>true</bool> | ||
60 | </property> | ||
61 | <property name="autoExclusive"> | ||
62 | <bool>true</bool> | ||
63 | </property> | ||
64 | </widget> | ||
65 | </item> | ||
66 | <item> | ||
67 | <widget class="QToolButton" name="linesButton"> | ||
68 | <property name="text"> | ||
69 | <string/> | ||
70 | </property> | ||
71 | <property name="icon"> | ||
72 | <iconset resource="../resources.qrc"> | ||
73 | <normaloff>:/resources/resources/lines.png</normaloff>:/resources/resources/lines.png</iconset> | ||
74 | </property> | ||
75 | <property name="checkable"> | ||
76 | <bool>true</bool> | ||
77 | </property> | ||
78 | <property name="checked"> | ||
79 | <bool>false</bool> | ||
80 | </property> | ||
81 | <property name="autoExclusive"> | ||
82 | <bool>true</bool> | ||
83 | </property> | ||
84 | </widget> | ||
85 | </item> | ||
86 | <item> | ||
42 | <spacer name="horizontalSpacer"> | 87 | <spacer name="horizontalSpacer"> |
43 | <property name="orientation"> | 88 | <property name="orientation"> |
44 | <enum>Qt::Horizontal</enum> | 89 | <enum>Qt::Horizontal</enum> |
@@ -74,6 +119,8 @@ | |||
74 | </item> | 119 | </item> |
75 | </layout> | 120 | </layout> |
76 | </widget> | 121 | </widget> |
77 | <resources/> | 122 | <resources> |
123 | <include location="../resources.qrc"/> | ||
124 | </resources> | ||
78 | <connections/> | 125 | <connections/> |
79 | </ui> | 126 | </ui> |