diff options
| author | Robert Bieber <robby@bieberphoto.com> | 2010-08-05 00:43:33 +0000 |
|---|---|---|
| committer | Robert Bieber <robby@bieberphoto.com> | 2010-08-05 00:43:33 +0000 |
| commit | 054a85fdca651844f969f44755b8531ab2e962d7 (patch) | |
| tree | d424970a137d4bbdd57102961a46653e67589820 /utils/themeeditor/gui | |
| parent | 467451878726a3755eb3b2b472a3b33299cb9245 (diff) | |
| download | rockbox-054a85fdca651844f969f44755b8531ab2e962d7.zip rockbox-054a85fdca651844f969f44755b8531ab2e962d7.tar.gz rockbox-054a85fdca651844f969f44755b8531ab2e962d7.tar.bz2 rockbox-054a85fdca651844f969f44755b8531ab2e962d7.tar.xz | |
Theme Editor: Added code generate/undo functionality to SkinViewer
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27704 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'utils/themeeditor/gui')
| -rw-r--r-- | utils/themeeditor/gui/editorwindow.cpp | 13 | ||||
| -rw-r--r-- | utils/themeeditor/gui/skindocument.cpp | 18 | ||||
| -rw-r--r-- | utils/themeeditor/gui/skindocument.h | 10 | ||||
| -rw-r--r-- | utils/themeeditor/gui/skinviewer.cpp | 33 | ||||
| -rw-r--r-- | utils/themeeditor/gui/skinviewer.h | 8 | ||||
| -rw-r--r-- | utils/themeeditor/gui/skinviewer.ui | 28 |
6 files changed, 98 insertions, 12 deletions
diff --git a/utils/themeeditor/gui/editorwindow.cpp b/utils/themeeditor/gui/editorwindow.cpp index 48ee76d..64443a1 100644 --- a/utils/themeeditor/gui/editorwindow.cpp +++ b/utils/themeeditor/gui/editorwindow.cpp @@ -428,7 +428,7 @@ void EditorWindow::shiftTab(int index) ui->actionCopy->setEnabled(false); ui->actionPaste->setEnabled(false); ui->actionFind_Replace->setEnabled(false); - viewer->setScene(0); + viewer->connectSkin(0); } else if(widget->type() == TabContent::Config) { @@ -441,7 +441,7 @@ void EditorWindow::shiftTab(int index) ui->actionCopy->setEnabled(false); ui->actionPaste->setEnabled(false); ui->actionFind_Replace->setEnabled(false); - viewer->setScene(0); + viewer->connectSkin(0); } else if(widget->type() == TabContent::Skin) { @@ -465,7 +465,8 @@ void EditorWindow::shiftTab(int index) sizeColumns(); /* Syncing the preview */ - viewer->setScene(doc->scene()); + viewer->connectSkin(doc); + } @@ -513,7 +514,7 @@ void EditorWindow::closeProject() dynamic_cast<SkinDocument*>(doc)->setProject(project); if(i == ui->editorTabs->currentIndex()) { - viewer->setScene(dynamic_cast<SkinDocument*>(doc)->scene()); + viewer->connectSkin(dynamic_cast<SkinDocument*>(doc)); } } } @@ -630,7 +631,7 @@ void EditorWindow::configFileChanged(QString configFile) dynamic_cast<SkinDocument*>(doc)->setProject(project); if(i == ui->editorTabs->currentIndex()) { - viewer->setScene(dynamic_cast<SkinDocument*>(doc)->scene()); + viewer->connectSkin(dynamic_cast<SkinDocument*>(doc)); } } } @@ -858,7 +859,7 @@ void EditorWindow::loadProjectFile(QString fileName) dynamic_cast<SkinDocument*>(doc)->setProject(project); if(i == ui->editorTabs->currentIndex()) { - viewer->setScene(dynamic_cast<SkinDocument*>(doc)->scene()); + viewer->connectSkin(dynamic_cast<SkinDocument*>(doc)); } } } diff --git a/utils/themeeditor/gui/skindocument.cpp b/utils/themeeditor/gui/skindocument.cpp index bd52685..1ee6b6e 100644 --- a/utils/themeeditor/gui/skindocument.cpp +++ b/utils/themeeditor/gui/skindocument.cpp @@ -36,7 +36,8 @@ const int SkinDocument::updateInterval = 500; SkinDocument::SkinDocument(QLabel* statusLabel, ProjectModel* project, DeviceState* device, QWidget *parent) :TabContent(parent), statusLabel(statusLabel), - project(project), device(device) + project(project), device(device), + treeInSync(true) { setupUI(); @@ -53,7 +54,7 @@ SkinDocument::SkinDocument(QLabel* statusLabel, QString file, QWidget *parent) :TabContent(parent), fileName(file), statusLabel(statusLabel), project(project), - device(device) + device(device), treeInSync(true) { setupUI(); blockUpdate = false; @@ -163,6 +164,9 @@ void SkinDocument::setupUI() /* Setting up the model */ model = new ParseTreeModel(""); + QObject::connect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), + this, SLOT(modelChanged())); + /* Connecting the editor's signal */ QObject::connect(editor, SIGNAL(textChanged()), this, SLOT(codeChanged())); @@ -260,6 +264,10 @@ void SkinDocument::codeChanged() editor->clearErrors(); parseStatus = model->changeTree(editor->document()-> toPlainText().toAscii()); + + treeInSync = true; + emit antiSync(false); + if(skin_error_line() > 0) parseStatus = tr("Errors in document"); statusLabel->setText(parseStatus); @@ -313,6 +321,12 @@ void SkinDocument::codeChanged() } +void SkinDocument::modelChanged() +{ + treeInSync = false; + emit antiSync(true); +} + void SkinDocument::save() { QFile fout(fileName); diff --git a/utils/themeeditor/gui/skindocument.h b/utils/themeeditor/gui/skindocument.h index 10c9e3f..5e72e29 100644 --- a/utils/themeeditor/gui/skindocument.h +++ b/utils/themeeditor/gui/skindocument.h @@ -66,7 +66,6 @@ public: QString title() const{ return titleText; } QString getStatus(){ return parseStatus; } CodeEditor* getEditor(){ return editor; } - void genCode(){ editor->document()->setPlainText(model->genCode()); } void setProject(ProjectModel* project){ this->project = project; } void save(); @@ -84,14 +83,21 @@ public: void showFind(){ findReplace->show(); } void hideFind(){ findReplace->hide(); } + bool isSynced(){ return treeInSync; } + + signals: + void antiSync(bool outOfSync); public slots: void settingsChanged(); void cursorChanged(); + void parseCode(){ codeChanged(); } + void genCode(){ editor->document()->setPlainText(model->genCode()); } private slots: void codeChanged(); + void modelChanged(); void deviceChanged(){ scene(); } private: @@ -122,6 +128,8 @@ private: QTime lastUpdate; static const int updateInterval; QTimer checkUpdate; + + bool treeInSync; }; #endif // SKINDOCUMENT_H diff --git a/utils/themeeditor/gui/skinviewer.cpp b/utils/themeeditor/gui/skinviewer.cpp index 1d5c84c..f1f3af9 100644 --- a/utils/themeeditor/gui/skinviewer.cpp +++ b/utils/themeeditor/gui/skinviewer.cpp @@ -54,9 +54,38 @@ void SkinViewer::changeEvent(QEvent *e) } } -void SkinViewer::setScene(QGraphicsScene *scene) +void SkinViewer::connectSkin(SkinDocument *skin) { - ui->viewer->setScene(scene); + if(skin) + { + ui->viewer->setScene(skin->scene()); + QObject::connect(skin, SIGNAL(antiSync(bool)), + ui->codeGenButton, SLOT(setEnabled(bool))); + QObject::connect(skin, SIGNAL(antiSync(bool)), + ui->codeUndoButton, SLOT(setEnabled(bool))); + + QObject::connect(ui->codeGenButton, SIGNAL(pressed()), + skin, SLOT(genCode())); + QObject::connect(ui->codeUndoButton, SIGNAL(pressed()), + skin, SLOT(parseCode())); + + doc = skin; + } + else + { + ui->viewer->setScene(0); + + doc = 0; + } + + bool antiSync; + if(skin && !skin->isSynced()) + antiSync = true; + else + antiSync = false; + + ui->codeGenButton->setEnabled(antiSync); + ui->codeUndoButton->setEnabled(antiSync); } void SkinViewer::zoomIn() diff --git a/utils/themeeditor/gui/skinviewer.h b/utils/themeeditor/gui/skinviewer.h index 64ad219..c1b978c 100644 --- a/utils/themeeditor/gui/skinviewer.h +++ b/utils/themeeditor/gui/skinviewer.h @@ -25,6 +25,8 @@ #include <QWidget> #include <QGraphicsScene> +#include "skindocument.h" + namespace Ui { class SkinViewer; } @@ -35,18 +37,22 @@ public: SkinViewer(QWidget *parent = 0); ~SkinViewer(); - void setScene(QGraphicsScene* scene); + void connectSkin(SkinDocument* skin); public slots: void zoomIn(); void zoomOut(); void zoomEven(); +private slots: + protected: void changeEvent(QEvent *e); private: Ui::SkinViewer *ui; + + SkinDocument* doc; }; #endif // SKINVIEWER_H diff --git a/utils/themeeditor/gui/skinviewer.ui b/utils/themeeditor/gui/skinviewer.ui index 333eeef..dc4a786 100644 --- a/utils/themeeditor/gui/skinviewer.ui +++ b/utils/themeeditor/gui/skinviewer.ui @@ -27,6 +27,34 @@ <item> <layout class="QHBoxLayout" name="horizontalLayout"> <item> + <widget class="QToolButton" name="codeGenButton"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="text"> + <string/> + </property> + <property name="icon"> + <iconset resource="../resources.qrc"> + <normaloff>:/resources/resources/applications-system.png</normaloff>:/resources/resources/applications-system.png</iconset> + </property> + </widget> + </item> + <item> + <widget class="QToolButton" name="codeUndoButton"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="text"> + <string/> + </property> + <property name="icon"> + <iconset resource="../resources.qrc"> + <normaloff>:/resources/resources/edit-undo.png</normaloff>:/resources/resources/edit-undo.png</iconset> + </property> + </widget> + </item> + <item> <spacer name="horizontalSpacer"> <property name="orientation"> <enum>Qt::Horizontal</enum> |