forked from len0rd/rockbox
Theme Editor: Added optional plaintext editing for config files
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27415 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
895e104603
commit
4b457d688b
10 changed files with 232 additions and 28 deletions
|
@ -27,14 +27,50 @@
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
|
#include <QPair>
|
||||||
|
|
||||||
ConfigDocument::ConfigDocument(QMap<QString, QString>& settings, QString file,
|
ConfigDocument::ConfigDocument(QMap<QString, QString>& settings, QString file,
|
||||||
QWidget *parent)
|
QWidget *parent)
|
||||||
: TabContent(parent),
|
: TabContent(parent),
|
||||||
ui(new Ui::ConfigDocument),
|
ui(new Ui::ConfigDocument),
|
||||||
filePath(file)
|
filePath(file), block(false)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
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 */
|
/* Populating the known keys list */
|
||||||
QFile fin(":/resources/configkeys");
|
QFile fin(":/resources/configkeys");
|
||||||
|
@ -50,20 +86,29 @@ ConfigDocument::ConfigDocument(QMap<QString, QString>& settings, QString file,
|
||||||
container->append(current.trimmed());
|
container->append(current.trimmed());
|
||||||
}
|
}
|
||||||
|
|
||||||
QMap<QString, QString>::iterator i;
|
/* Loading the text file */
|
||||||
for(i = settings.begin(); i != settings.end(); i++)
|
QFile finT(settings.value("configfile", ""));
|
||||||
if(i.key() != "themebase")
|
if(finT.open(QFile::Text | QFile::ReadOnly))
|
||||||
addRow(i.key(), i.value());
|
{
|
||||||
|
editor->setPlainText(QString(finT.readAll()));
|
||||||
|
finT.close();
|
||||||
|
}
|
||||||
|
|
||||||
saved = toPlainText();
|
saved = toPlainText();
|
||||||
|
|
||||||
QObject::connect(ui->addKeyButton, SIGNAL(pressed()),
|
QObject::connect(ui->addKeyButton, SIGNAL(pressed()),
|
||||||
this, SLOT(addClicked()));
|
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()
|
ConfigDocument::~ConfigDocument()
|
||||||
{
|
{
|
||||||
delete ui;
|
delete ui;
|
||||||
|
editor->deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigDocument::changeEvent(QEvent *e)
|
void ConfigDocument::changeEvent(QEvent *e)
|
||||||
|
@ -171,6 +216,15 @@ bool ConfigDocument::requestClose()
|
||||||
|
|
||||||
QString ConfigDocument::toPlainText() const
|
QString ConfigDocument::toPlainText() const
|
||||||
{
|
{
|
||||||
|
return editor->toPlainText();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConfigDocument::syncFromBoxes()
|
||||||
|
{
|
||||||
|
if(block)
|
||||||
|
return;
|
||||||
|
blockUpdates();
|
||||||
|
|
||||||
QString buffer = "";
|
QString buffer = "";
|
||||||
|
|
||||||
for(int i = 0; i < keys.count(); i++)
|
for(int i = 0; i < keys.count(); i++)
|
||||||
|
@ -181,7 +235,61 @@ QString ConfigDocument::toPlainText() const
|
||||||
buffer += "\n";
|
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)
|
void ConfigDocument::addRow(QString key, QString value)
|
||||||
|
@ -215,11 +323,11 @@ void ConfigDocument::addRow(QString key, QString value)
|
||||||
QObject::connect(delButton, SIGNAL(clicked()),
|
QObject::connect(delButton, SIGNAL(clicked()),
|
||||||
this, SLOT(deleteClicked()));
|
this, SLOT(deleteClicked()));
|
||||||
QObject::connect(keyEdit, SIGNAL(currentIndexChanged(QString)),
|
QObject::connect(keyEdit, SIGNAL(currentIndexChanged(QString)),
|
||||||
this, SLOT(textChanged()));
|
this, SLOT(boxesChanged()));
|
||||||
QObject::connect(keyEdit, SIGNAL(textChanged(QString)),
|
QObject::connect(keyEdit, SIGNAL(textChanged(QString)),
|
||||||
this, SLOT(textChanged()));
|
this, SLOT(boxesChanged()));
|
||||||
QObject::connect(valueEdit, SIGNAL(textChanged(QString)),
|
QObject::connect(valueEdit, SIGNAL(textChanged(QString)),
|
||||||
this, SLOT(textChanged()));
|
this, SLOT(boxesChanged()));
|
||||||
|
|
||||||
ui->configBoxes->addLayout(layout);
|
ui->configBoxes->addLayout(layout);
|
||||||
|
|
||||||
|
@ -259,10 +367,34 @@ void ConfigDocument::addClicked()
|
||||||
addRow(tr("Key"), tr("Value"));
|
addRow(tr("Key"), tr("Value"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ConfigDocument::boxesChanged()
|
||||||
|
{
|
||||||
|
syncFromBoxes();
|
||||||
|
contentsChanged();
|
||||||
|
}
|
||||||
|
|
||||||
void ConfigDocument::textChanged()
|
void ConfigDocument::textChanged()
|
||||||
|
{
|
||||||
|
syncFromText();
|
||||||
|
contentsChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConfigDocument::contentsChanged()
|
||||||
{
|
{
|
||||||
if(toPlainText() != saved)
|
if(toPlainText() != saved)
|
||||||
emit titleChanged(title() + "*");
|
emit titleChanged(title() + "*");
|
||||||
else
|
else
|
||||||
emit titleChanged(title());
|
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();
|
||||||
|
}
|
||||||
|
|
|
@ -30,8 +30,10 @@
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
#include <QWheelEvent>
|
#include <QWheelEvent>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
#include "tabcontent.h"
|
#include "tabcontent.h"
|
||||||
|
#include "codeeditor.h"
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class ConfigDocument;
|
class ConfigDocument;
|
||||||
|
@ -58,6 +60,8 @@ public:
|
||||||
QString title() const;
|
QString title() const;
|
||||||
|
|
||||||
QString toPlainText() const;
|
QString toPlainText() const;
|
||||||
|
void syncFromBoxes();
|
||||||
|
void syncFromText();
|
||||||
|
|
||||||
void save();
|
void save();
|
||||||
void saveAs();
|
void saveAs();
|
||||||
|
@ -73,9 +77,20 @@ signals:
|
||||||
private slots:
|
private slots:
|
||||||
void deleteClicked();
|
void deleteClicked();
|
||||||
void addClicked();
|
void addClicked();
|
||||||
|
void boxesChanged();
|
||||||
void textChanged();
|
void textChanged();
|
||||||
|
void contentsChanged();
|
||||||
|
void blockUpdates()
|
||||||
|
{
|
||||||
|
block = true;
|
||||||
|
QTimer::singleShot(20, this, SLOT(unblockUpdates()));
|
||||||
|
}
|
||||||
|
void unblockUpdates(){ block = false; }
|
||||||
|
void buttonChecked();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void addRow(QString key, QString value);
|
||||||
|
|
||||||
Ui::ConfigDocument *ui;
|
Ui::ConfigDocument *ui;
|
||||||
QList<QHBoxLayout*> containers;
|
QList<QHBoxLayout*> containers;
|
||||||
QList<NoScrollCombo*> keys;
|
QList<NoScrollCombo*> keys;
|
||||||
|
@ -89,7 +104,9 @@ private:
|
||||||
QString filePath;
|
QString filePath;
|
||||||
QString saved;
|
QString saved;
|
||||||
|
|
||||||
void addRow(QString key, QString value);
|
CodeEditor* editor;
|
||||||
|
|
||||||
|
bool block;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CONFIGDOCUMENT_H
|
#endif // CONFIGDOCUMENT_H
|
||||||
|
|
|
@ -15,29 +15,74 @@
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout">
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QScrollArea" name="scrollArea">
|
<widget class="QSplitter" name="splitter">
|
||||||
<property name="widgetResizable">
|
<property name="orientation">
|
||||||
<bool>true</bool>
|
<enum>Qt::Vertical</enum>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QWidget" name="scrollAreaWidgetContents">
|
<widget class="QScrollArea" name="scrollArea">
|
||||||
<property name="geometry">
|
<property name="widgetResizable">
|
||||||
<rect>
|
<bool>true</bool>
|
||||||
<x>0</x>
|
|
||||||
<y>0</y>
|
|
||||||
<width>402</width>
|
|
||||||
<height>244</height>
|
|
||||||
</rect>
|
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
<widget class="QWidget" name="scrollAreaWidgetContents">
|
||||||
<item>
|
<property name="geometry">
|
||||||
<layout class="QVBoxLayout" name="configBoxes"/>
|
<rect>
|
||||||
</item>
|
<x>0</x>
|
||||||
</layout>
|
<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>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
<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>
|
<item>
|
||||||
<spacer name="horizontalSpacer">
|
<spacer name="horizontalSpacer">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
|
@ -74,6 +119,8 @@
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<resources/>
|
<resources>
|
||||||
|
<include location="../resources.qrc"/>
|
||||||
|
</resources>
|
||||||
<connections/>
|
<connections/>
|
||||||
</ui>
|
</ui>
|
||||||
|
|
|
@ -39,6 +39,8 @@ ProjectModel::ProjectModel(QString config, EditorWindow* mainWindow,
|
||||||
if(!cfg.isReadable())
|
if(!cfg.isReadable())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
settings.insert("configfile", config);
|
||||||
|
|
||||||
QTextStream fin(&cfg);
|
QTextStream fin(&cfg);
|
||||||
|
|
||||||
/* Storing the base directory */
|
/* Storing the base directory */
|
||||||
|
|
|
@ -13,6 +13,8 @@
|
||||||
<file>resources/ffwd.png</file>
|
<file>resources/ffwd.png</file>
|
||||||
<file>resources/pause.png</file>
|
<file>resources/pause.png</file>
|
||||||
<file>resources/rwnd.png</file>
|
<file>resources/rwnd.png</file>
|
||||||
|
<file>resources/cursor.png</file>
|
||||||
|
<file>resources/lines.png</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
<qresource prefix="/render">
|
<qresource prefix="/render">
|
||||||
<file alias="scenebg.png">resources/render/scenebg.png</file>
|
<file alias="scenebg.png">resources/render/scenebg.png</file>
|
||||||
|
|
BIN
utils/themeeditor/resources/cursor.png
Normal file
BIN
utils/themeeditor/resources/cursor.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 235 B |
BIN
utils/themeeditor/resources/cursor.xcf
Normal file
BIN
utils/themeeditor/resources/cursor.xcf
Normal file
Binary file not shown.
BIN
utils/themeeditor/resources/lines.png
Normal file
BIN
utils/themeeditor/resources/lines.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 231 B |
BIN
utils/themeeditor/resources/lines.xcf
Normal file
BIN
utils/themeeditor/resources/lines.xcf
Normal file
Binary file not shown.
|
@ -96,7 +96,11 @@ OTHER_FILES += README \
|
||||||
resources/pause.xcf \
|
resources/pause.xcf \
|
||||||
resources/pause.png \
|
resources/pause.png \
|
||||||
resources/ffwd.xcf \
|
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 \
|
FORMS += gui/editorwindow.ui \
|
||||||
gui/preferencesdialog.ui \
|
gui/preferencesdialog.ui \
|
||||||
gui/configdocument.ui \
|
gui/configdocument.ui \
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue