From 4b457d688b9b9c5b4b15babf93c04b8d2db489a9 Mon Sep 17 00:00:00 2001 From: Robert Bieber Date: Wed, 14 Jul 2010 07:38:09 +0000 Subject: [PATCH] Theme Editor: Added optional plaintext editing for config files git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27415 a1c6a512-1295-4272-9138-f99709370657 --- utils/themeeditor/gui/configdocument.cpp | 150 ++++++++++++++++++++-- utils/themeeditor/gui/configdocument.h | 19 ++- utils/themeeditor/gui/configdocument.ui | 81 +++++++++--- utils/themeeditor/models/projectmodel.cpp | 2 + utils/themeeditor/resources.qrc | 2 + utils/themeeditor/resources/cursor.png | Bin 0 -> 235 bytes utils/themeeditor/resources/cursor.xcf | Bin 0 -> 1096 bytes utils/themeeditor/resources/lines.png | Bin 0 -> 231 bytes utils/themeeditor/resources/lines.xcf | Bin 0 -> 918 bytes utils/themeeditor/themeeditor.pro | 6 +- 10 files changed, 232 insertions(+), 28 deletions(-) create mode 100644 utils/themeeditor/resources/cursor.png create mode 100644 utils/themeeditor/resources/cursor.xcf create mode 100644 utils/themeeditor/resources/lines.png create mode 100644 utils/themeeditor/resources/lines.xcf 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 @@ #include #include #include +#include ConfigDocument::ConfigDocument(QMap& settings, QString file, QWidget *parent) : TabContent(parent), ui(new Ui::ConfigDocument), - filePath(file) + filePath(file), block(false) { ui->setupUi(this); + editor = new CodeEditor(this); + editor->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); + editor->setLineWrapMode(CodeEditor::NoWrap); + ui->splitter->addWidget(editor); + + QObject::connect(editor, SIGNAL(textChanged()), + this, SLOT(textChanged())); + + /* Loading the splitter status */ + QSettings appSettings; + appSettings.beginGroup("ConfigDocument"); + + if(!appSettings.value("textVisible", true).toBool()) + { + editor->setVisible(false); + ui->textButton->setChecked(false); + } + else + { + ui->textButton->setChecked(true); + } + if(!appSettings.value("linesVisible", false).toBool()) + { + ui->scrollArea->setVisible(false); + ui->linesButton->setChecked(false); + } + else + { + ui->linesButton->setChecked(true); + } + + if(!appSettings.value("splitter", QByteArray()).toByteArray().isNull()) + ui->splitter->restoreState(appSettings.value("splitter").toByteArray()); + + appSettings.endGroup(); /* Populating the known keys list */ QFile fin(":/resources/configkeys"); @@ -50,20 +86,29 @@ ConfigDocument::ConfigDocument(QMap& settings, QString file, container->append(current.trimmed()); } - QMap::iterator i; - for(i = settings.begin(); i != settings.end(); i++) - if(i.key() != "themebase") - addRow(i.key(), i.value()); + /* Loading the text file */ + QFile finT(settings.value("configfile", "")); + if(finT.open(QFile::Text | QFile::ReadOnly)) + { + editor->setPlainText(QString(finT.readAll())); + finT.close(); + } saved = toPlainText(); QObject::connect(ui->addKeyButton, SIGNAL(pressed()), this, SLOT(addClicked())); + + QObject::connect(ui->linesButton, SIGNAL(toggled(bool)), + this, SLOT(buttonChecked())); + QObject::connect(ui->textButton, SIGNAL(toggled(bool)), + this, SLOT(buttonChecked())); } ConfigDocument::~ConfigDocument() { delete ui; + editor->deleteLater(); } void ConfigDocument::changeEvent(QEvent *e) @@ -171,6 +216,15 @@ bool ConfigDocument::requestClose() QString ConfigDocument::toPlainText() const { + return editor->toPlainText(); +} + +void ConfigDocument::syncFromBoxes() +{ + if(block) + return; + blockUpdates(); + QString buffer = ""; for(int i = 0; i < keys.count(); i++) @@ -181,7 +235,61 @@ QString ConfigDocument::toPlainText() const buffer += "\n"; } - return buffer; + editor->setPlainText(buffer); +} + +void ConfigDocument::syncFromText() +{ + if(block) + return; + + blockUpdates(); + + QStringList lines = editor->toPlainText().split("\n"); + QList > splits; + for(int i = 0; i < lines.count(); i++) + { + QString line = lines[i]; + QStringList split = line.split(":"); + if(split.count() != 2) + continue; + + splits.append(QPair(split[0].trimmed(), + split[1].trimmed())); + } + + while(deleteButtons.count() > splits.count()) + { + deleteButtons[0]->deleteLater(); + keys[0]->deleteLater(); + values[0]->deleteLater(); + containers[0]->deleteLater(); + labels[0]->deleteLater(); + + deleteButtons.removeAt(0); + keys.removeAt(0); + values.removeAt(0); + containers.removeAt(0); + labels.removeAt(0); + } + + int initialCount = deleteButtons.count(); + for(int i = 0; i < splits.count(); i++) + { + if(i >= initialCount) + { + addRow(splits[i].first, splits[i].second); + } + else + { + int index = keys[i]->findText(splits[i].first); + if(index != -1) + keys[i]->setCurrentIndex(index); + else + keys[i]->setEditText(splits[i].first); + values[i]->setText(splits[i].second); + } + } } void ConfigDocument::addRow(QString key, QString value) @@ -215,11 +323,11 @@ void ConfigDocument::addRow(QString key, QString value) QObject::connect(delButton, SIGNAL(clicked()), this, SLOT(deleteClicked())); QObject::connect(keyEdit, SIGNAL(currentIndexChanged(QString)), - this, SLOT(textChanged())); + this, SLOT(boxesChanged())); QObject::connect(keyEdit, SIGNAL(textChanged(QString)), - this, SLOT(textChanged())); + this, SLOT(boxesChanged())); QObject::connect(valueEdit, SIGNAL(textChanged(QString)), - this, SLOT(textChanged())); + this, SLOT(boxesChanged())); ui->configBoxes->addLayout(layout); @@ -259,10 +367,34 @@ void ConfigDocument::addClicked() addRow(tr("Key"), tr("Value")); } +void ConfigDocument::boxesChanged() +{ + syncFromBoxes(); + contentsChanged(); +} + void ConfigDocument::textChanged() +{ + syncFromText(); + contentsChanged(); +} + +void ConfigDocument::contentsChanged() { if(toPlainText() != saved) emit titleChanged(title() + "*"); else emit titleChanged(title()); } + +void ConfigDocument::buttonChecked() +{ + editor->setVisible(ui->textButton->isChecked()); + ui->scrollArea->setVisible(ui->linesButton->isChecked()); + + QSettings settings; + settings.beginGroup("ConfigDocument"); + settings.setValue("textVisible", ui->textButton->isChecked()); + settings.setValue("linesVisible", ui->linesButton->isChecked()); + settings.endGroup(); +} 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 @@ #include #include #include +#include #include "tabcontent.h" +#include "codeeditor.h" namespace Ui { class ConfigDocument; @@ -58,6 +60,8 @@ public: QString title() const; QString toPlainText() const; + void syncFromBoxes(); + void syncFromText(); void save(); void saveAs(); @@ -73,9 +77,20 @@ signals: private slots: void deleteClicked(); void addClicked(); + void boxesChanged(); void textChanged(); + void contentsChanged(); + void blockUpdates() + { + block = true; + QTimer::singleShot(20, this, SLOT(unblockUpdates())); + } + void unblockUpdates(){ block = false; } + void buttonChecked(); private: + void addRow(QString key, QString value); + Ui::ConfigDocument *ui; QList containers; QList keys; @@ -89,7 +104,9 @@ private: QString filePath; QString saved; - void addRow(QString key, QString value); + CodeEditor* editor; + + bool block; }; #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,29 +15,74 @@ - - - true + + + Qt::Vertical - - - - 0 - 0 - 402 - 244 - + + + true - - - - - + + + + 0 + 0 + 402 + 244 + + + + + + + + + + + + + + + + :/resources/resources/cursor.png:/resources/resources/cursor.png + + + true + + + true + + + true + + + + + + + + + + + :/resources/resources/lines.png:/resources/resources/lines.png + + + true + + + false + + + true + + + @@ -74,6 +119,8 @@ - + + + diff --git a/utils/themeeditor/models/projectmodel.cpp b/utils/themeeditor/models/projectmodel.cpp index 632e0aa075..2663e8b426 100644 --- a/utils/themeeditor/models/projectmodel.cpp +++ b/utils/themeeditor/models/projectmodel.cpp @@ -39,6 +39,8 @@ ProjectModel::ProjectModel(QString config, EditorWindow* mainWindow, if(!cfg.isReadable()) return; + settings.insert("configfile", config); + QTextStream fin(&cfg); /* Storing the base directory */ diff --git a/utils/themeeditor/resources.qrc b/utils/themeeditor/resources.qrc index 87211b95e9..bad8edcb20 100644 --- a/utils/themeeditor/resources.qrc +++ b/utils/themeeditor/resources.qrc @@ -13,6 +13,8 @@ resources/ffwd.png resources/pause.png resources/rwnd.png + resources/cursor.png + resources/lines.png resources/render/scenebg.png diff --git a/utils/themeeditor/resources/cursor.png b/utils/themeeditor/resources/cursor.png new file mode 100644 index 0000000000000000000000000000000000000000..d1bcef26fb8659d77d4c23b517120491595cb765 GIT binary patch literal 235 zcmeAS@N?(olHy`uVBq!ia0vp^8X(NU1|)m_?Z^dEjKx9jP7LeL$-D$|*pj^6T^Rm@ z;DWu&Cj&(|3p^r=85p>QL70(Y)*K0-AbW|YuPgg4c0P7K)?*qU{eVJ}C9V-A&iT2y zsd*&~&PAz-C8;S2<(VZJ3hti10pX2&;y^`io-U3d5r^O2aO7f8;9zik`@ephyhxl% z(l;5CCCimmWKTc)Ics0}-hWLEm#uHyJa3ZZfCTKh-TqhxTw2OoaEjSV*RsnCXd;8B LtDnm{r-UW|$___G literal 0 HcmV?d00001 diff --git a/utils/themeeditor/resources/cursor.xcf b/utils/themeeditor/resources/cursor.xcf new file mode 100644 index 0000000000000000000000000000000000000000..97db8743df0437ee86a62216f41c3ac30c246ee4 GIT binary patch literal 1096 zcmcIjJ5Iwu6kI0=!YAU7geX{=C=^D4hL(f^Q6SN90OPF9ir7ZB5m0djYAQ~^5vVu> zB|S%=Ff(SIEFzRVX?Dl+=Iwi4C!vn64` ztnhIeX!IV0AP_6S1h5aR8BQ|}ahM}#aBrN&u@|X6pIb&FXE0xR*@uHT-BTeB-oX$S zw{@rcW_d>3)}8K?r{!LhVn_YRnjzhUy^@4aePBfZ(9qU}` z*uPL2>yseJR6ZP#)xV{0%DqbQ0`0({EKRsWQ#KT`EaER1Sg%u|22=w?F^@ literal 0 HcmV?d00001 diff --git a/utils/themeeditor/resources/lines.png b/utils/themeeditor/resources/lines.png new file mode 100644 index 0000000000000000000000000000000000000000..fda23beb2728754098b13278bba3be186ed699b3 GIT binary patch literal 231 zcmeAS@N?(olHy`uVBq!ia0vp^8X(NU1|)m_?Z^dEjKx9jP7LeL$-D$|*pj^6T^Rm@ z;DWu&Cj&(|3p^r=85p>QL70(Y)*K0-AbW|YuPgg4c0P6q&dY2Zn}9-+C9V-A&iT2y zsd*&~&PAz-C8;S2<(VZJ3hti10pX2&;y^`Co-U3d5r^Mi+sMVBz`^S9_W%Ez*D|;l zDZNW`Eu0|ESpGDrcJ92}ar+mrCVrkhv%0v#{^^_s6XmlEARqU-P(WPc7qR5euTPyfbVv^B#LyL^B^9+c9?26*Aw;4xICa(TyWP^}ka4xOgVNJErS-mg zny~aTJ9j-32WnjRf_ODgtTg8$Hn}pfccwGeC%&KQd^RAf|CjESb}8?sGW%1_5cy6% z0KC!V1K0Z+q{&5GUR(V~7qHa@ra-UaOn+W+1X*hE