summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorRobert Bieber <robby@bieberphoto.com>2010-07-14 07:38:09 +0000
committerRobert Bieber <robby@bieberphoto.com>2010-07-14 07:38:09 +0000
commit4b457d688b9b9c5b4b15babf93c04b8d2db489a9 (patch)
treeb2a3fa35fa6ac46d2ccf25c8d0018fe5c93b722f /utils
parent895e104603d3f8337a8d6f64e4c72e7583eff808 (diff)
Theme Editor: Added optional plaintext editing for config files
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27415 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'utils')
-rw-r--r--utils/themeeditor/gui/configdocument.cpp150
-rw-r--r--utils/themeeditor/gui/configdocument.h19
-rw-r--r--utils/themeeditor/gui/configdocument.ui81
-rw-r--r--utils/themeeditor/models/projectmodel.cpp2
-rw-r--r--utils/themeeditor/resources.qrc2
-rw-r--r--utils/themeeditor/resources/cursor.pngbin0 -> 235 bytes
-rw-r--r--utils/themeeditor/resources/cursor.xcfbin0 -> 1096 bytes
-rw-r--r--utils/themeeditor/resources/lines.pngbin0 -> 231 bytes
-rw-r--r--utils/themeeditor/resources/lines.xcfbin0 -> 918 bytes
-rw-r--r--utils/themeeditor/themeeditor.pro6
10 files changed, 232 insertions, 28 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 @@
#include <QFile>
#include <QSettings>
#include <QFileDialog>
+#include <QPair>
ConfigDocument::ConfigDocument(QMap<QString, QString>& 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<QString, QString>& settings, QString file,
container->append(current.trimmed());
}
- QMap<QString, QString>::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<QPair<QString, QString> > 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<QString, QString>(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 <QLabel>
#include <QMap>
#include <QWheelEvent>
+#include <QTimer>
#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<QHBoxLayout*> containers;
QList<NoScrollCombo*> 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,30 +15,75 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
- <widget class="QScrollArea" name="scrollArea">
- <property name="widgetResizable">
- <bool>true</bool>
+ <widget class="QSplitter" name="splitter">
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
</property>
- <widget class="QWidget" name="scrollAreaWidgetContents">
- <property name="geometry">
- <rect>
- <x>0</x>
- <y>0</y>
- <width>402</width>
- <height>244</height>
- </rect>
+ <widget class="QScrollArea" name="scrollArea">
+ <property name="widgetResizable">
+ <bool>true</bool>
</property>
- <layout class="QVBoxLayout" name="verticalLayout_3">
- <item>
- <layout class="QVBoxLayout" name="configBoxes"/>
- </item>
- </layout>
+ <widget class="QWidget" name="scrollAreaWidgetContents">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>402</width>
+ <height>244</height>
+ </rect>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout_3">
+ <item>
+ <layout class="QVBoxLayout" name="configBoxes"/>
+ </item>
+ </layout>
+ </widget>
</widget>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
+ <widget class="QToolButton" name="textButton">
+ <property name="text">
+ <string/>
+ </property>
+ <property name="icon">
+ <iconset resource="../resources.qrc">
+ <normaloff>:/resources/resources/cursor.png</normaloff>:/resources/resources/cursor.png</iconset>
+ </property>
+ <property name="checkable">
+ <bool>true</bool>
+ </property>
+ <property name="checked">
+ <bool>true</bool>
+ </property>
+ <property name="autoExclusive">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QToolButton" name="linesButton">
+ <property name="text">
+ <string/>
+ </property>
+ <property name="icon">
+ <iconset resource="../resources.qrc">
+ <normaloff>:/resources/resources/lines.png</normaloff>:/resources/resources/lines.png</iconset>
+ </property>
+ <property name="checkable">
+ <bool>true</bool>
+ </property>
+ <property name="checked">
+ <bool>false</bool>
+ </property>
+ <property name="autoExclusive">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
@@ -74,6 +119,8 @@
</item>
</layout>
</widget>
- <resources/>
+ <resources>
+ <include location="../resources.qrc"/>
+ </resources>
<connections/>
</ui>
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 @@
<file>resources/ffwd.png</file>
<file>resources/pause.png</file>
<file>resources/rwnd.png</file>
+ <file>resources/cursor.png</file>
+ <file>resources/lines.png</file>
</qresource>
<qresource prefix="/render">
<file alias="scenebg.png">resources/render/scenebg.png</file>
diff --git a/utils/themeeditor/resources/cursor.png b/utils/themeeditor/resources/cursor.png
new file mode 100644
index 0000000000..d1bcef26fb
--- /dev/null
+++ b/utils/themeeditor/resources/cursor.png
Binary files differ
diff --git a/utils/themeeditor/resources/cursor.xcf b/utils/themeeditor/resources/cursor.xcf
new file mode 100644
index 0000000000..97db8743df
--- /dev/null
+++ b/utils/themeeditor/resources/cursor.xcf
Binary files differ
diff --git a/utils/themeeditor/resources/lines.png b/utils/themeeditor/resources/lines.png
new file mode 100644
index 0000000000..fda23beb27
--- /dev/null
+++ b/utils/themeeditor/resources/lines.png
Binary files differ
diff --git a/utils/themeeditor/resources/lines.xcf b/utils/themeeditor/resources/lines.xcf
new file mode 100644
index 0000000000..2212fb2b3b
--- /dev/null
+++ b/utils/themeeditor/resources/lines.xcf
Binary files differ
diff --git a/utils/themeeditor/themeeditor.pro b/utils/themeeditor/themeeditor.pro
index 0805890db1..5d77d562a6 100644
--- a/utils/themeeditor/themeeditor.pro
+++ b/utils/themeeditor/themeeditor.pro
@@ -96,7 +96,11 @@ OTHER_FILES += README \
resources/pause.xcf \
resources/pause.png \
resources/ffwd.xcf \
- resources/ffwd.png
+ resources/ffwd.png \
+ resources/lines.xcf \
+ resources/lines.png \
+ resources/cursor.xcf \
+ resources/cursor.png
FORMS += gui/editorwindow.ui \
gui/preferencesdialog.ui \
gui/configdocument.ui \