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 <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();
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -15,29 +15,74 @@
|
|||
</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">
|
||||
|
@ -74,6 +119,8 @@
|
|||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<resources>
|
||||
<include location="../resources.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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>
|
||||
|
|
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.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 \
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue