From f9ef314531944ebc6ae054eb0010a02fb504eaa3 Mon Sep 17 00:00:00 2001 From: bieber Date: Tue, 1 Jun 2010 21:25:02 +0000 Subject: [PATCH] Theme Editor: Put together a simple GUI to test going back and forth between a tree view and a text edit box git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26455 a1c6a512-1295-4272-9138-f99709370657 --- utils/themeeditor/{main.cpp => editorwindow.cpp} | 66 +++++++++--------- utils/themeeditor/{main.cpp => editorwindow.h} | 56 ++++++--------- utils/themeeditor/editorwindow.ui | 87 ++++++++++++++++++++++++ utils/themeeditor/main.cpp | 14 +--- utils/themeeditor/parsetreemodel.cpp | 2 +- utils/themeeditor/parsetreemodel.h | 2 +- utils/themeeditor/parsetreenode.cpp | 5 -- utils/themeeditor/skin_parser.c | 16 +++-- utils/themeeditor/skin_parser.h | 2 +- utils/themeeditor/themeeditor.pro | 7 +- 10 files changed, 157 insertions(+), 100 deletions(-) copy utils/themeeditor/{main.cpp => editorwindow.cpp} (52%) copy utils/themeeditor/{main.cpp => editorwindow.h} (53%) create mode 100644 utils/themeeditor/editorwindow.ui diff --git a/utils/themeeditor/main.cpp b/utils/themeeditor/editorwindow.cpp similarity index 52% copy from utils/themeeditor/main.cpp copy to utils/themeeditor/editorwindow.cpp index 87d38b861..42ca22cec 100644 --- a/utils/themeeditor/main.cpp +++ b/utils/themeeditor/editorwindow.cpp @@ -19,49 +19,45 @@ * ****************************************************************************/ -#include "skin_parser.h" -#include "skin_debug.h" +#include "editorwindow.h" +#include "ui_editorwindow.h" -#include -#include #include -#include -#include - -#include "parsetreemodel.h" - -int main(int argc, char* argv[]) +EditorWindow::EditorWindow(QWidget *parent) : + QMainWindow(parent), + ui(new Ui::EditorWindow) { - QApplication app(argc, argv); - - char doc[] = "#Comment\n" - "%Vd(U);Hey\n" - "%?bl(test,3,5,2,1)\n" - "%V(1,2,3,4,5)%pS(5)\n" - "Some more stuff here"; - - ParseTreeModel tree(doc); - - QTreeView view; - view.setModel(&tree); - view.show(); - - return app.exec(); + ui->setupUi(this); - /* - struct skin_element* test = skin_parse(doc); + tree = 0; - ParseTreeModel tree(doc); - std::cout << "----" << std::endl; - if(std::string(doc) == tree.genCode().toStdString()) - std::cout << "Code in/out matches" << std::endl; - else - std::cout << "Match error" << std::endl; + /* Connecting the buttons */ + QObject::connect(ui->code, SIGNAL(cursorPositionChanged()), + this, SLOT(updateTree())); + QObject::connect(ui->fromTree, SIGNAL(pressed()), + this, SLOT(updateCode())); +} +void EditorWindow::updateTree() +{ + if(tree) + delete tree; - skin_free_tree(test); - */ + tree = new ParseTreeModel(ui->code->document()->toPlainText().toAscii()); + ui->parseTree->setModel(tree); + ui->parseTree->expandAll(); +} +void EditorWindow::updateCode() +{ + tree->genCode(); + ui->code->setDocument(new QTextDocument(tree->genCode())); } +EditorWindow::~EditorWindow() +{ + delete ui; + if(tree) + delete tree; +} diff --git a/utils/themeeditor/main.cpp b/utils/themeeditor/editorwindow.h similarity index 53% copy from utils/themeeditor/main.cpp copy to utils/themeeditor/editorwindow.h index 87d38b861..03cdf66ca 100644 --- a/utils/themeeditor/main.cpp +++ b/utils/themeeditor/editorwindow.h @@ -19,49 +19,31 @@ * ****************************************************************************/ -#include "skin_parser.h" -#include "skin_debug.h" +#ifndef EDITORWINDOW_H +#define EDITORWINDOW_H -#include -#include -#include - -#include -#include +#include #include "parsetreemodel.h" -int main(int argc, char* argv[]) -{ - QApplication app(argc, argv); - - char doc[] = "#Comment\n" - "%Vd(U);Hey\n" - "%?bl(test,3,5,2,1)\n" - "%V(1,2,3,4,5)%pS(5)\n" - "Some more stuff here"; - - ParseTreeModel tree(doc); - - QTreeView view; - view.setModel(&tree); - view.show(); - - return app.exec(); - - /* - struct skin_element* test = skin_parse(doc); +namespace Ui { + class EditorWindow; +} - ParseTreeModel tree(doc); - std::cout << "----" << std::endl; - if(std::string(doc) == tree.genCode().toStdString()) - std::cout << "Code in/out matches" << std::endl; - else - std::cout << "Match error" << std::endl; +class EditorWindow : public QMainWindow { + Q_OBJECT +public: + EditorWindow(QWidget *parent = 0); + ~EditorWindow(); +private slots: + void updateCode(); + void updateTree(); - skin_free_tree(test); - */ +private: + Ui::EditorWindow *ui; + ParseTreeModel* tree; -} +}; +#endif // EDITORWINDOW_H diff --git a/utils/themeeditor/editorwindow.ui b/utils/themeeditor/editorwindow.ui new file mode 100644 index 000000000..35ff3738c --- /dev/null +++ b/utils/themeeditor/editorwindow.ui @@ -0,0 +1,87 @@ + + + EditorWindow + + + + 0 + 0 + 800 + 400 + + + + MainWindow + + + + + + + + + + + + Update Code + + + + + + + + + + + + + + + + + + 0 + 0 + 800 + 25 + + + + + File + + + + + + + + + Quit + + + Ctrl+Q + + + + + + + actionQuit + activated() + EditorWindow + close() + + + 65 + 57 + + + 299 + 199 + + + + + diff --git a/utils/themeeditor/main.cpp b/utils/themeeditor/main.cpp index 87d38b861..3f7379e0d 100644 --- a/utils/themeeditor/main.cpp +++ b/utils/themeeditor/main.cpp @@ -21,6 +21,7 @@ #include "skin_parser.h" #include "skin_debug.h" +#include "editorwindow.h" #include #include @@ -35,17 +36,8 @@ int main(int argc, char* argv[]) { QApplication app(argc, argv); - char doc[] = "#Comment\n" - "%Vd(U);Hey\n" - "%?bl(test,3,5,2,1)\n" - "%V(1,2,3,4,5)%pS(5)\n" - "Some more stuff here"; - - ParseTreeModel tree(doc); - - QTreeView view; - view.setModel(&tree); - view.show(); + EditorWindow mainWindow; + mainWindow.show(); return app.exec(); diff --git a/utils/themeeditor/parsetreemodel.cpp b/utils/themeeditor/parsetreemodel.cpp index 24eebac8d..9faa9ea56 100644 --- a/utils/themeeditor/parsetreemodel.cpp +++ b/utils/themeeditor/parsetreemodel.cpp @@ -27,7 +27,7 @@ #include -ParseTreeModel::ParseTreeModel(char* document, QObject* parent): +ParseTreeModel::ParseTreeModel(const char* document, QObject* parent): QAbstractItemModel(parent) { this->tree = skin_parse(document); diff --git a/utils/themeeditor/parsetreemodel.h b/utils/themeeditor/parsetreemodel.h index 6d1f153d2..4c448ce55 100644 --- a/utils/themeeditor/parsetreemodel.h +++ b/utils/themeeditor/parsetreemodel.h @@ -43,7 +43,7 @@ public: static const int valueColumn = 2; /* Initializes a tree with a skin document in a string */ - ParseTreeModel(char* document, QObject* parent = 0); + ParseTreeModel(const char* document, QObject* parent = 0); virtual ~ParseTreeModel(); QString genCode(); diff --git a/utils/themeeditor/parsetreenode.cpp b/utils/themeeditor/parsetreenode.cpp index 22db94da8..41cdf3ca2 100644 --- a/utils/themeeditor/parsetreenode.cpp +++ b/utils/themeeditor/parsetreenode.cpp @@ -19,11 +19,8 @@ * ****************************************************************************/ -extern "C" -{ #include "symbols.h" #include "tag_table.h" -} #include "parsetreenode.h" #include "parsetreemodel.h" @@ -100,8 +97,6 @@ QString ParseTreeNode::genCode() const { case VIEWPORT: - buffer.append(children[0]->genCode()); - case LINE: for(int i = 0; i < children.count(); i++) { diff --git a/utils/themeeditor/skin_parser.c b/utils/themeeditor/skin_parser.c index c0f184952..8e4bc88e9 100644 --- a/utils/themeeditor/skin_parser.c +++ b/utils/themeeditor/skin_parser.c @@ -53,7 +53,7 @@ int skin_parse_newline(struct skin_element* element, char** document); int skin_parse_comment(struct skin_element* element, char** document); struct skin_element* skin_parse_code_as_arg(char** document); -struct skin_element* skin_parse(char* document) +struct skin_element* skin_parse(const char* document) { struct skin_element* root = NULL; @@ -61,7 +61,7 @@ struct skin_element* skin_parse(char* document) struct skin_element** to_write = 0; - char* cursor = document; /* Keeps track of location in the document */ + char* cursor = (char*)document; /*Keeps track of location in the document*/ skin_line = 1; @@ -738,18 +738,20 @@ int skin_parse_comment(struct skin_element* element, char** document) */ for(length = 0; cursor[length] != '\n' && cursor[length] != '\0'; length++); - length--; element->type = COMMENT; element->line = skin_line; element->text = skin_alloc_string(length); /* We copy from one char past cursor to leave out the # */ - memcpy((void*)(element->text), (void*)(cursor + 1), sizeof(char) * length); - element->text[length] = '\0'; + memcpy((void*)(element->text), (void*)(cursor + 1), + sizeof(char) * (length-1)); + element->text[length - 1] = '\0'; - if(cursor[length + 1] == '\n') + if(cursor[length] == '\n') skin_line++; - *document += (length + 2); /* Move cursor up past # and all text */ + *document += (length); /* Move cursor up past # and all text */ + if(**document == '\n') + (*document)++; return 1; } diff --git a/utils/themeeditor/skin_parser.h b/utils/themeeditor/skin_parser.h index cd50b996c..ca2d7bc54 100644 --- a/utils/themeeditor/skin_parser.h +++ b/utils/themeeditor/skin_parser.h @@ -123,7 +123,7 @@ struct skin_element /* Parses a WPS document and returns a list of skin_element structures. */ -struct skin_element* skin_parse(char* document); +struct skin_element* skin_parse(const char* document); /* Memory management functions */ struct skin_element* skin_alloc_element(); diff --git a/utils/themeeditor/themeeditor.pro b/utils/themeeditor/themeeditor.pro index b1c768813..5b1ab34ca 100644 --- a/utils/themeeditor/themeeditor.pro +++ b/utils/themeeditor/themeeditor.pro @@ -4,12 +4,15 @@ HEADERS += tag_table.h \ skin_scan.h \ skin_debug.h \ parsetreemodel.h \ - parsetreenode.h + parsetreenode.h \ + editorwindow.h SOURCES += tag_table.c \ skin_parser.c \ skin_scan.c \ skin_debug.c \ main.cpp \ parsetreemodel.cpp \ - parsetreenode.cpp + parsetreenode.cpp \ + editorwindow.cpp OTHER_FILES += README +FORMS += editorwindow.ui -- 2.11.4.GIT