From 054a85fdca651844f969f44755b8531ab2e962d7 Mon Sep 17 00:00:00 2001 From: Robert Bieber Date: Thu, 5 Aug 2010 00:43:33 +0000 Subject: [PATCH] Theme Editor: Added code generate/undo functionality to SkinViewer git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27704 a1c6a512-1295-4272-9138-f99709370657 --- utils/themeeditor/graphics/rbviewport.cpp | 2 - utils/themeeditor/gui/editorwindow.cpp | 13 ++++--- utils/themeeditor/gui/skindocument.cpp | 18 ++++++++- utils/themeeditor/gui/skindocument.h | 10 ++++- utils/themeeditor/gui/skinviewer.cpp | 33 ++++++++++++++++- utils/themeeditor/gui/skinviewer.h | 8 +++- utils/themeeditor/gui/skinviewer.ui | 28 ++++++++++++++ utils/themeeditor/models/parsetreemodel.cpp | 18 ++++++++- utils/themeeditor/models/parsetreemodel.h | 4 ++ utils/themeeditor/models/parsetreenode.cpp | 35 +++++++++++------- utils/themeeditor/models/parsetreenode.h | 10 +++-- utils/themeeditor/resources.qrc | 1 + utils/themeeditor/resources/COPYING | 10 ++--- .../resources/applications-system.png | Bin 0 -> 1488 bytes utils/themeeditor/themeeditor.pro | 3 +- 15 files changed, 154 insertions(+), 39 deletions(-) create mode 100644 utils/themeeditor/resources/applications-system.png diff --git a/utils/themeeditor/graphics/rbviewport.cpp b/utils/themeeditor/graphics/rbviewport.cpp index 33749fdb7f..274edd67fd 100644 --- a/utils/themeeditor/graphics/rbviewport.cpp +++ b/utils/themeeditor/graphics/rbviewport.cpp @@ -311,8 +311,6 @@ void RBViewport::saveGeometry() node->modParam(static_cast(origin.y()), baseParam + 1); node->modParam(static_cast(bounds.width()), baseParam + 2); node->modParam(static_cast(bounds.height()), baseParam + 3); - - doc->genCode(); } void RBViewport::alignLeft() diff --git a/utils/themeeditor/gui/editorwindow.cpp b/utils/themeeditor/gui/editorwindow.cpp index 48ee76d11c..64443a1fd1 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(doc)->setProject(project); if(i == ui->editorTabs->currentIndex()) { - viewer->setScene(dynamic_cast(doc)->scene()); + viewer->connectSkin(dynamic_cast(doc)); } } } @@ -630,7 +631,7 @@ void EditorWindow::configFileChanged(QString configFile) dynamic_cast(doc)->setProject(project); if(i == ui->editorTabs->currentIndex()) { - viewer->setScene(dynamic_cast(doc)->scene()); + viewer->connectSkin(dynamic_cast(doc)); } } } @@ -858,7 +859,7 @@ void EditorWindow::loadProjectFile(QString fileName) dynamic_cast(doc)->setProject(project); if(i == ui->editorTabs->currentIndex()) { - viewer->setScene(dynamic_cast(doc)->scene()); + viewer->connectSkin(dynamic_cast(doc)); } } } diff --git a/utils/themeeditor/gui/skindocument.cpp b/utils/themeeditor/gui/skindocument.cpp index bd52685c6b..1ee6b6e7ee 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 10c9e3ff11..5e72e29a8d 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 1d5c84c519..f1f3af9c8c 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 64ad219aae..c1b978c414 100644 --- a/utils/themeeditor/gui/skinviewer.h +++ b/utils/themeeditor/gui/skinviewer.h @@ -25,6 +25,8 @@ #include #include +#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 333eeefba5..dc4a786a33 100644 --- a/utils/themeeditor/gui/skinviewer.ui +++ b/utils/themeeditor/gui/skinviewer.ui @@ -26,6 +26,34 @@ + + + + false + + + + + + + :/resources/resources/applications-system.png:/resources/resources/applications-system.png + + + + + + + false + + + + + + + :/resources/resources/edit-undo.png:/resources/resources/edit-undo.png + + + diff --git a/utils/themeeditor/models/parsetreemodel.cpp b/utils/themeeditor/models/parsetreemodel.cpp index a7f04ffbf2..01d60c8775 100644 --- a/utils/themeeditor/models/parsetreemodel.cpp +++ b/utils/themeeditor/models/parsetreemodel.cpp @@ -40,7 +40,7 @@ ParseTreeModel::ParseTreeModel(const char* document, QObject* parent): this->tree = skin_parse(document); if(tree) - this->root = new ParseTreeNode(tree); + this->root = new ParseTreeNode(tree, this); else this->root = 0; @@ -77,7 +77,7 @@ QString ParseTreeModel::changeTree(const char *document) return error; } - ParseTreeNode* temp = new ParseTreeNode(test); + ParseTreeNode* temp = new ParseTreeNode(test, this); if(root) { @@ -364,3 +364,17 @@ QGraphicsScene* ParseTreeModel::render(ProjectModel* project, return scene; } + +void ParseTreeModel::paramChanged(ParseTreeNode *param) +{ + QModelIndex index = indexFromPointer(param); + emit dataChanged(index, index); +} + +QModelIndex ParseTreeModel::indexFromPointer(ParseTreeNode *p) +{ + /* Recursively finding an index for an arbitrary pointer within the tree */ + if(!p->getParent()) + return QModelIndex(); + return index(p->getRow(), 0, indexFromPointer(p->getParent())); +} diff --git a/utils/themeeditor/models/parsetreemodel.h b/utils/themeeditor/models/parsetreemodel.h index ec0a420a84..3c20a8ed3a 100644 --- a/utils/themeeditor/models/parsetreemodel.h +++ b/utils/themeeditor/models/parsetreemodel.h @@ -53,6 +53,8 @@ public: QString genCode(); /* Changes the parse tree to a new document */ QString changeTree(const char* document); + + /* Model implementation stuff */ QModelIndex index(int row, int column, const QModelIndex& parent) const; QModelIndex parent(const QModelIndex &child) const; int rowCount(const QModelIndex &parent) const; @@ -74,6 +76,8 @@ public: return fallback; } + void paramChanged(ParseTreeNode* param); + QModelIndex indexFromPointer(ParseTreeNode* p); private: ParseTreeNode* root; diff --git a/utils/themeeditor/models/parsetreenode.cpp b/utils/themeeditor/models/parsetreenode.cpp index 8d1fcc7d1a..1dedd4a689 100644 --- a/utils/themeeditor/models/parsetreenode.cpp +++ b/utils/themeeditor/models/parsetreenode.cpp @@ -36,19 +36,21 @@ int ParseTreeNode::openConditionals = 0; bool ParseTreeNode::breakFlag = false; /* Root element constructor */ -ParseTreeNode::ParseTreeNode(struct skin_element* data) - : parent(0), element(0), param(0), children() +ParseTreeNode::ParseTreeNode(struct skin_element* data, ParseTreeModel* model) + : parent(0), element(0), param(0), children(), model(model) { while(data) { - children.append(new ParseTreeNode(data, this)); + children.append(new ParseTreeNode(data, this, model)); data = data->next; } } /* Normal element constructor */ -ParseTreeNode::ParseTreeNode(struct skin_element* data, ParseTreeNode* parent) - : parent(parent), element(data), param(0), children() +ParseTreeNode::ParseTreeNode(struct skin_element* data, ParseTreeNode* parent, + ParseTreeModel* model) + : parent(parent), element(data), param(0), + children(), model(model) { switch(element->type) { @@ -58,29 +60,30 @@ ParseTreeNode::ParseTreeNode(struct skin_element* data, ParseTreeNode* parent) { if(element->params[i].type == skin_tag_parameter::CODE) children.append(new ParseTreeNode(element->params[i].data.code, - this)); + this, model)); else - children.append(new ParseTreeNode(&element->params[i], this)); + children.append(new ParseTreeNode(&element->params[i], this, + model)); } break; case CONDITIONAL: for(int i = 0; i < element->params_count; i++) - children.append(new ParseTreeNode(&data->params[i], this)); + children.append(new ParseTreeNode(&data->params[i], this, model)); for(int i = 0; i < element->children_count; i++) - children.append(new ParseTreeNode(data->children[i], this)); + children.append(new ParseTreeNode(data->children[i], this, model)); break; case LINE_ALTERNATOR: for(int i = 0; i < element->children_count; i++) { - children.append(new ParseTreeNode(data->children[i], this)); + children.append(new ParseTreeNode(data->children[i], this, model)); } break; case VIEWPORT: for(int i = 0; i < element->params_count; i++) - children.append(new ParseTreeNode(&data->params[i], this)); + children.append(new ParseTreeNode(&data->params[i], this, model)); /* Deliberate fall-through here */ case LINE: @@ -89,7 +92,7 @@ case VIEWPORT: for(struct skin_element* current = data->children[i]; current; current = current->next) { - children.append(new ParseTreeNode(current, this)); + children.append(new ParseTreeNode(current, this, model)); } } break; @@ -100,8 +103,10 @@ case VIEWPORT: } /* Parameter constructor */ -ParseTreeNode::ParseTreeNode(skin_tag_parameter *data, ParseTreeNode *parent) - : parent(parent), element(0), param(data), children() +ParseTreeNode::ParseTreeNode(skin_tag_parameter *data, ParseTreeNode *parent, + ParseTreeModel *model) + : parent(parent), element(0), param(data), + children(), model(model) { } @@ -1085,5 +1090,7 @@ void ParseTreeNode::modParam(QVariant value, int index) param->data.number = value.toInt(); } + model->paramChanged(this); + } } diff --git a/utils/themeeditor/models/parsetreenode.h b/utils/themeeditor/models/parsetreenode.h index 39f0dbdfcd..106907799e 100644 --- a/utils/themeeditor/models/parsetreenode.h +++ b/utils/themeeditor/models/parsetreenode.h @@ -34,9 +34,11 @@ class ParseTreeNode { public: - ParseTreeNode(struct skin_element* data); - ParseTreeNode(struct skin_element* data, ParseTreeNode* parent); - ParseTreeNode(struct skin_tag_parameter* data, ParseTreeNode* parent); + ParseTreeNode(struct skin_element* data, ParseTreeModel* model); + ParseTreeNode(struct skin_element* data, ParseTreeNode* parent, + ParseTreeModel* model); + ParseTreeNode(struct skin_tag_parameter* data, ParseTreeNode* parent, + ParseTreeModel* model); virtual ~ParseTreeNode(); QString genCode() const; @@ -84,6 +86,8 @@ private: static bool breakFlag; QGraphicsItem* rendered; + ParseTreeModel* model; + }; #endif // PARSETREENODE_H diff --git a/utils/themeeditor/resources.qrc b/utils/themeeditor/resources.qrc index 9290ca9b48..0d85172eb4 100644 --- a/utils/themeeditor/resources.qrc +++ b/utils/themeeditor/resources.qrc @@ -23,6 +23,7 @@ resources/edit-cut.png resources/edit-paste.png resources/edit-find-replace.png + resources/applications-system.png resources/render/scenebg.png diff --git a/utils/themeeditor/resources/COPYING b/utils/themeeditor/resources/COPYING index 14c27fa030..a8c779744f 100644 --- a/utils/themeeditor/resources/COPYING +++ b/utils/themeeditor/resources/COPYING @@ -1,8 +1,8 @@ -The files edit-cut.png, edit-copy.png, edit-paste.png, edit-find-replace.png, -edit-undo.png, edit-redo.png, ffwd.png, rwnd.png, play.png, pause.png, -document-new.png, document-open.png, document-save-as.png, and document-save.png -came from the Tango Desktop Project (http://www.tango.freedesktop.org) and are -in the public domain. +The files applications-system.png, edit-cut.png, edit-copy.png, edit-paste.png, +edit-find-replace.png, edit-undo.png, edit-redo.png, ffwd.png, rwnd.png, +play.png, pause.png, document-new.png, document-open.png, document-save-as.png, +and document-save.png came from the Tango Desktop Project +(http://www.tango.freedesktop.org) and are in the public domain. The files zoomin.png, zoomout.png, and zoomeven.png came from the Tango Project with modifications by Robert Bieber, also in the public domain. diff --git a/utils/themeeditor/resources/applications-system.png b/utils/themeeditor/resources/applications-system.png new file mode 100644 index 0000000000000000000000000000000000000000..4decc893f846ade39d9ff0592c6d206bc333a177 GIT binary patch literal 1488 zcmV;>1uy!EP)3;q{a$<5OZ>6KCN?#=B*DR6Ck-K((4=XV6g5OmrNm8(h^2n0 z=~MbvSxuhkQ&p*IB`dTpi_%tYAfYeC3KeZ?3alM4226tkn1%JO*SlWt_r1IK_945* zPOGZtX>?}J@BDSnoEgFYVLM;`Xn{}rQt))5*G_X9*mhbHSj-5qRx z>CtBL#S(f!XMC>I@|p8TfmhbX$aT=yj(ih6e{NH=>s)9!d|-V_lN-?_Mnzu*hK9of z!YKUZLBH7zoUDri5UbFGV*^bx`{5g}4%+6UaejGfVHNqs9qnuhD4aTbjfc86@TZH} zdwZRNP4@+eriz@ro?nTK4mGX^A2^)(`mT0wSI{p4J`ch&QKiMr*b1rTJdv4O2qDl^ zh2|zNxs??Dzy=b@EM09)w0P|tok|+1Lgn$u=+NZ7QmD4?|M~RQ^ah_3uvpHPNu*0m z&D>^s_6`nB!=Y(tQX!KmVhI=Nbdgqn1A4{c?K2Bz9lB2Or#1db`Nypb4lxi52vdCjLeWuE#t6hJl5NZL(@oQ3Jh*`3#ye@*0MxsIQ(~D7eG%( z6E6>TqF5%`T#0hILMD?m$4*DjR5kbWk

$z59On($~KFblB_hYlRRrbO0a+b;n%;kk!N~acxrnP0mR}N3WYLTIs^Rt_Y=jk%^!-44lM)RxOVok>bSr4 z(f;iN+qQ1R?X+XpG`6?6*b#KHBWPnXS{#%B9l;=mp%PCPxIUL)aWTun!U~pYl2;lX zb!gqPnWZCzLXO4;C#8bHwSUD~S<$IhRD6wrdo`ZAFl)tPi!7z`q|$k+6%)HnMM#0o zEE%EUux~Bc<@GZvqccFnquC->v3@Sz483t z;&$7`1ziAduDfo}z3}=z`{td;zr3wYNFk6y@JMev|CpNLEaY^g5C|c-zuix3OCwSW^0_kA ziU~mUb{b7nIDdJD_dc#^fDQas_ z70IT~03e9oN+E@yiq7;WQGPd_G0aN&iK$;7jHm$p2Y(Y1mbv>|Pjm>k=8=Y3!Q-hti&#yIM%r3sqK;Z?AB}X0!!)CM-yW|_+GB@A^v(x?|pHg3oL;^ za_qt#F*`Hyvn$6(4#mB_zDx6q-IwN*;psoTaVT+R{0301H&6lGKwHngksm$s>aWfN zgTOPuv!UUzHFrH>MNWTW&0SAeq2aIvJPSMx><0RP&jGDK17NFvO%_m5G-qk{{hz!8 zoB$kvy_OUJ|3=Tc0jw$0fjm$EN{3Ym9+cwJBpSgs{80Q2AQ5mth5AqzVI0000CNB( literal 0 HcmV?d00001 diff --git a/utils/themeeditor/themeeditor.pro b/utils/themeeditor/themeeditor.pro index d3d8b1d080..5418bbf555 100644 --- a/utils/themeeditor/themeeditor.pro +++ b/utils/themeeditor/themeeditor.pro @@ -182,7 +182,8 @@ OTHER_FILES += README \ resources/edit-paste.png \ resources/edit-cut.png \ resources/edit-copy.png \ - resources/edit-find-replace.png + resources/edit-find-replace.png \ + resources/applications-system.png FORMS += gui/editorwindow.ui \ gui/preferencesdialog.ui \ gui/configdocument.ui \