forked from len0rd/rockbox
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
This commit is contained in:
parent
f52c9aae3a
commit
a9848ce3fe
10 changed files with 219 additions and 28 deletions
63
utils/themeeditor/editorwindow.cpp
Normal file
63
utils/themeeditor/editorwindow.cpp
Normal file
|
@ -0,0 +1,63 @@
|
|||
/***************************************************************************
|
||||
* __________ __ ___.
|
||||
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
||||
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
||||
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
||||
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
||||
* \/ \/ \/ \/ \/
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (C) 2010 Robert Bieber
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
* KIND, either express or implied.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#include "editorwindow.h"
|
||||
#include "ui_editorwindow.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
EditorWindow::EditorWindow(QWidget *parent) :
|
||||
QMainWindow(parent),
|
||||
ui(new Ui::EditorWindow)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
tree = 0;
|
||||
|
||||
/* 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;
|
||||
|
||||
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;
|
||||
}
|
49
utils/themeeditor/editorwindow.h
Normal file
49
utils/themeeditor/editorwindow.h
Normal file
|
@ -0,0 +1,49 @@
|
|||
/***************************************************************************
|
||||
* __________ __ ___.
|
||||
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
||||
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
||||
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
||||
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
||||
* \/ \/ \/ \/ \/
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (C) 2010 Robert Bieber
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
* KIND, either express or implied.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef EDITORWINDOW_H
|
||||
#define EDITORWINDOW_H
|
||||
|
||||
#include <QMainWindow>
|
||||
|
||||
#include "parsetreemodel.h"
|
||||
|
||||
namespace Ui {
|
||||
class EditorWindow;
|
||||
}
|
||||
|
||||
class EditorWindow : public QMainWindow {
|
||||
Q_OBJECT
|
||||
public:
|
||||
EditorWindow(QWidget *parent = 0);
|
||||
~EditorWindow();
|
||||
|
||||
private slots:
|
||||
void updateCode();
|
||||
void updateTree();
|
||||
|
||||
private:
|
||||
Ui::EditorWindow *ui;
|
||||
ParseTreeModel* tree;
|
||||
|
||||
};
|
||||
|
||||
#endif // EDITORWINDOW_H
|
87
utils/themeeditor/editorwindow.ui
Normal file
87
utils/themeeditor/editorwindow.ui
Normal file
|
@ -0,0 +1,87 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>EditorWindow</class>
|
||||
<widget class="QMainWindow" name="EditorWindow">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>800</width>
|
||||
<height>400</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>MainWindow</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralwidget">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QTreeView" name="parseTree"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="fromTree">
|
||||
<property name="text">
|
||||
<string>Update Code</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QTextEdit" name="code"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QMenuBar" name="menubar">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>800</width>
|
||||
<height>25</height>
|
||||
</rect>
|
||||
</property>
|
||||
<widget class="QMenu" name="menuFile">
|
||||
<property name="title">
|
||||
<string>File</string>
|
||||
</property>
|
||||
<addaction name="actionQuit"/>
|
||||
</widget>
|
||||
<addaction name="menuFile"/>
|
||||
</widget>
|
||||
<widget class="QStatusBar" name="statusbar"/>
|
||||
<action name="actionQuit">
|
||||
<property name="text">
|
||||
<string>Quit</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>Ctrl+Q</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>actionQuit</sender>
|
||||
<signal>activated()</signal>
|
||||
<receiver>EditorWindow</receiver>
|
||||
<slot>close()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>65</x>
|
||||
<y>57</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>299</x>
|
||||
<y>199</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
|
@ -21,6 +21,7 @@
|
|||
|
||||
#include "skin_parser.h"
|
||||
#include "skin_debug.h"
|
||||
#include "editorwindow.h"
|
||||
|
||||
#include <cstdlib>
|
||||
#include <cstdio>
|
||||
|
@ -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)<param2|param3>\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();
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
|
||||
#include <QObject>
|
||||
|
||||
ParseTreeModel::ParseTreeModel(char* document, QObject* parent):
|
||||
ParseTreeModel::ParseTreeModel(const char* document, QObject* parent):
|
||||
QAbstractItemModel(parent)
|
||||
{
|
||||
this->tree = skin_parse(document);
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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++)
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue