forked from len0rd/rockbox
Theme Editor: Working on renderer infrastructure
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26878 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
36b934d241
commit
75560845aa
8 changed files with 118 additions and 25 deletions
|
@ -100,7 +100,7 @@ void ConfigDocument::save()
|
||||||
|
|
||||||
saved = toPlainText();
|
saved = toPlainText();
|
||||||
emit titleChanged(title());
|
emit titleChanged(title());
|
||||||
|
emit configFileChanged(file());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigDocument::saveAs()
|
void ConfigDocument::saveAs()
|
||||||
|
|
|
@ -56,7 +56,7 @@ void EditorWindow::loadTabFromSkinFile(QString fileName)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Adding a new document*/
|
/* Adding a new document*/
|
||||||
SkinDocument* doc = new SkinDocument(parseStatus, fileName);
|
SkinDocument* doc = new SkinDocument(parseStatus, fileName, project);
|
||||||
addTab(doc);
|
addTab(doc);
|
||||||
ui->editorTabs->setCurrentWidget(doc);
|
ui->editorTabs->setCurrentWidget(doc);
|
||||||
|
|
||||||
|
@ -144,11 +144,6 @@ void EditorWindow::setupUI()
|
||||||
viewer = new SkinViewer(this);
|
viewer = new SkinViewer(this);
|
||||||
ui->skinPreviewLayout->addWidget(viewer);
|
ui->skinPreviewLayout->addWidget(viewer);
|
||||||
|
|
||||||
//TODO: Remove this test code
|
|
||||||
QGraphicsScene* test = new QGraphicsScene();
|
|
||||||
test->addRect(0,0,50,50);
|
|
||||||
|
|
||||||
viewer->setScene(test);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorWindow::setupMenus()
|
void EditorWindow::setupMenus()
|
||||||
|
@ -204,7 +199,7 @@ void EditorWindow::addTab(TabContent *doc)
|
||||||
|
|
||||||
void EditorWindow::newTab()
|
void EditorWindow::newTab()
|
||||||
{
|
{
|
||||||
SkinDocument* doc = new SkinDocument(parseStatus);
|
SkinDocument* doc = new SkinDocument(parseStatus, project);
|
||||||
addTab(doc);
|
addTab(doc);
|
||||||
ui->editorTabs->setCurrentWidget(doc);
|
ui->editorTabs->setCurrentWidget(doc);
|
||||||
}
|
}
|
||||||
|
@ -221,6 +216,7 @@ void EditorWindow::shiftTab(int index)
|
||||||
ui->actionClose_Document->setEnabled(false);
|
ui->actionClose_Document->setEnabled(false);
|
||||||
ui->actionToolbarSave->setEnabled(false);
|
ui->actionToolbarSave->setEnabled(false);
|
||||||
ui->fromTree->setEnabled(false);
|
ui->fromTree->setEnabled(false);
|
||||||
|
viewer->setScene(0);
|
||||||
}
|
}
|
||||||
else if(widget->type() == TabContent::Config)
|
else if(widget->type() == TabContent::Config)
|
||||||
{
|
{
|
||||||
|
@ -228,8 +224,9 @@ void EditorWindow::shiftTab(int index)
|
||||||
ui->actionSave_Document_As->setEnabled(true);
|
ui->actionSave_Document_As->setEnabled(true);
|
||||||
ui->actionClose_Document->setEnabled(true);
|
ui->actionClose_Document->setEnabled(true);
|
||||||
ui->actionToolbarSave->setEnabled(true);
|
ui->actionToolbarSave->setEnabled(true);
|
||||||
|
viewer->setScene(0);
|
||||||
}
|
}
|
||||||
else
|
else if(widget->type() == TabContent::Skin)
|
||||||
{
|
{
|
||||||
/* Syncing the tree view and the status bar */
|
/* Syncing the tree view and the status bar */
|
||||||
SkinDocument* doc = dynamic_cast<SkinDocument*>(widget);
|
SkinDocument* doc = dynamic_cast<SkinDocument*>(widget);
|
||||||
|
@ -244,6 +241,9 @@ void EditorWindow::shiftTab(int index)
|
||||||
|
|
||||||
sizeColumns();
|
sizeColumns();
|
||||||
|
|
||||||
|
/* Syncing the preview */
|
||||||
|
viewer->setScene(doc->scene());
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -331,6 +331,20 @@ void EditorWindow::openProject()
|
||||||
fileName.chop(fileName.length() - fileName.lastIndexOf('/') - 1);
|
fileName.chop(fileName.length() - fileName.lastIndexOf('/') - 1);
|
||||||
settings.setValue("defaultDirectory", fileName);
|
settings.setValue("defaultDirectory", fileName);
|
||||||
|
|
||||||
|
for(int i = 0; i < ui->editorTabs->count(); i++)
|
||||||
|
{
|
||||||
|
TabContent* doc = dynamic_cast<TabContent*>
|
||||||
|
(ui->editorTabs->widget(i));
|
||||||
|
if(doc->type() == TabContent::Skin)
|
||||||
|
{
|
||||||
|
dynamic_cast<SkinDocument*>(doc)->setProject(project);
|
||||||
|
if(i == ui->editorTabs->currentIndex())
|
||||||
|
{
|
||||||
|
viewer->setScene(dynamic_cast<SkinDocument*>(doc)->scene());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
|
@ -340,10 +354,6 @@ void EditorWindow::openProject()
|
||||||
void EditorWindow::configFileChanged(QString configFile)
|
void EditorWindow::configFileChanged(QString configFile)
|
||||||
{
|
{
|
||||||
|
|
||||||
QSettings settings;
|
|
||||||
|
|
||||||
settings.beginGroup("ProjectModel");
|
|
||||||
|
|
||||||
if(QFile::exists(configFile))
|
if(QFile::exists(configFile))
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -356,12 +366,22 @@ void EditorWindow::configFileChanged(QString configFile)
|
||||||
QObject::connect(ui->projectTree, SIGNAL(activated(QModelIndex)),
|
QObject::connect(ui->projectTree, SIGNAL(activated(QModelIndex)),
|
||||||
project, SLOT(activated(QModelIndex)));
|
project, SLOT(activated(QModelIndex)));
|
||||||
|
|
||||||
configFile.chop(configFile.length() - configFile.lastIndexOf('/') - 1);
|
for(int i = 0; i < ui->editorTabs->count(); i++)
|
||||||
settings.setValue("defaultDirectory", configFile);
|
{
|
||||||
|
TabContent* doc = dynamic_cast<TabContent*>
|
||||||
|
(ui->editorTabs->widget(i));
|
||||||
|
if(doc->type() == TabContent::Skin)
|
||||||
|
{
|
||||||
|
dynamic_cast<SkinDocument*>(doc)->setProject(project);
|
||||||
|
if(i == ui->editorTabs->currentIndex())
|
||||||
|
{
|
||||||
|
viewer->setScene(dynamic_cast<SkinDocument*>(doc)->scene());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
settings.endGroup();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,8 +29,10 @@
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
SkinDocument::SkinDocument(QLabel* statusLabel, QWidget *parent) :
|
SkinDocument::SkinDocument(QLabel* statusLabel, ProjectModel* project,
|
||||||
TabContent(parent), statusLabel(statusLabel)
|
QWidget *parent)
|
||||||
|
:TabContent(parent), statusLabel(statusLabel),
|
||||||
|
project(project)
|
||||||
{
|
{
|
||||||
setupUI();
|
setupUI();
|
||||||
|
|
||||||
|
@ -41,8 +43,10 @@ SkinDocument::SkinDocument(QLabel* statusLabel, QWidget *parent) :
|
||||||
blockUpdate = false;
|
blockUpdate = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
SkinDocument::SkinDocument(QLabel* statusLabel, QString file, QWidget *parent):
|
SkinDocument::SkinDocument(QLabel* statusLabel, QString file,
|
||||||
TabContent(parent), fileName(file), statusLabel(statusLabel)
|
ProjectModel* project, QWidget *parent)
|
||||||
|
:TabContent(parent), fileName(file),
|
||||||
|
statusLabel(statusLabel), project(project)
|
||||||
{
|
{
|
||||||
setupUI();
|
setupUI();
|
||||||
blockUpdate = false;
|
blockUpdate = false;
|
||||||
|
@ -65,8 +69,8 @@ SkinDocument::SkinDocument(QLabel* statusLabel, QString file, QWidget *parent):
|
||||||
|
|
||||||
SkinDocument::~SkinDocument()
|
SkinDocument::~SkinDocument()
|
||||||
{
|
{
|
||||||
delete highlighter;
|
highlighter->deleteLater();
|
||||||
delete model;
|
model->deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SkinDocument::connectPrefs(PreferencesDialog* prefs)
|
void SkinDocument::connectPrefs(PreferencesDialog* prefs)
|
||||||
|
@ -309,3 +313,11 @@ void SkinDocument::saveAs()
|
||||||
emit titleChanged(titleText);
|
emit titleChanged(titleText);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString SkinDocument::findSetting(QString key, QString fallback)
|
||||||
|
{
|
||||||
|
if(!project)
|
||||||
|
return fallback;
|
||||||
|
else
|
||||||
|
return project->getSetting(key, fallback);
|
||||||
|
}
|
||||||
|
|
|
@ -25,12 +25,14 @@
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
|
#include <QGraphicsScene>
|
||||||
|
|
||||||
#include "skinhighlighter.h"
|
#include "skinhighlighter.h"
|
||||||
#include "parsetreemodel.h"
|
#include "parsetreemodel.h"
|
||||||
#include "preferencesdialog.h"
|
#include "preferencesdialog.h"
|
||||||
#include "codeeditor.h"
|
#include "codeeditor.h"
|
||||||
#include "tabcontent.h"
|
#include "tabcontent.h"
|
||||||
|
#include "projectmodel.h"
|
||||||
|
|
||||||
class SkinDocument : public TabContent
|
class SkinDocument : public TabContent
|
||||||
{
|
{
|
||||||
|
@ -46,8 +48,10 @@ public:
|
||||||
"All Files (*.*)");
|
"All Files (*.*)");
|
||||||
}
|
}
|
||||||
|
|
||||||
SkinDocument(QLabel* statusLabel, QWidget *parent = 0);
|
SkinDocument(QLabel* statusLabel, ProjectModel* project = 0,
|
||||||
SkinDocument(QLabel* statusLabel, QString file, QWidget* parent = 0);
|
QWidget *parent = 0);
|
||||||
|
SkinDocument(QLabel* statusLabel, QString file, ProjectModel* project = 0,
|
||||||
|
QWidget* parent = 0);
|
||||||
virtual ~SkinDocument();
|
virtual ~SkinDocument();
|
||||||
|
|
||||||
void connectPrefs(PreferencesDialog* prefs);
|
void connectPrefs(PreferencesDialog* prefs);
|
||||||
|
@ -57,6 +61,7 @@ public:
|
||||||
QString title() const{ return titleText; }
|
QString title() const{ return titleText; }
|
||||||
QString getStatus(){ return parseStatus; }
|
QString getStatus(){ return parseStatus; }
|
||||||
void genCode(){ editor->document()->setPlainText(model->genCode()); }
|
void genCode(){ editor->document()->setPlainText(model->genCode()); }
|
||||||
|
void setProject(ProjectModel* project){ this->project = project; }
|
||||||
|
|
||||||
void save();
|
void save();
|
||||||
void saveAs();
|
void saveAs();
|
||||||
|
@ -65,6 +70,8 @@ public:
|
||||||
|
|
||||||
TabType type() const{ return Skin; }
|
TabType type() const{ return Skin; }
|
||||||
|
|
||||||
|
QGraphicsScene* scene(){ return model->render(project); }
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
@ -76,6 +83,7 @@ private slots:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setupUI();
|
void setupUI();
|
||||||
|
QString findSetting(QString key, QString fallback);
|
||||||
|
|
||||||
QString titleText;
|
QString titleText;
|
||||||
QString fileName;
|
QString fileName;
|
||||||
|
@ -91,6 +99,8 @@ private:
|
||||||
QLabel* statusLabel;
|
QLabel* statusLabel;
|
||||||
|
|
||||||
bool blockUpdate;
|
bool blockUpdate;
|
||||||
|
|
||||||
|
ProjectModel* project;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SKINDOCUMENT_H
|
#endif // SKINDOCUMENT_H
|
||||||
|
|
|
@ -19,11 +19,27 @@
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
|
<item>
|
||||||
|
<spacer name="horizontalSpacer">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QToolButton" name="zoomInButton">
|
<widget class="QToolButton" name="zoomInButton">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Zoom In</string>
|
<string>Zoom In</string>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="autoRepeat">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
|
@ -31,6 +47,9 @@
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Zoom Out</string>
|
<string>Zoom Out</string>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="autoRepeat">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
|
|
|
@ -36,6 +36,8 @@ ParseTreeModel::ParseTreeModel(const char* document, QObject* parent):
|
||||||
this->root = new ParseTreeNode(tree);
|
this->root = new ParseTreeNode(tree);
|
||||||
else
|
else
|
||||||
this->root = 0;
|
this->root = 0;
|
||||||
|
|
||||||
|
scene = new QGraphicsScene();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -264,3 +266,15 @@ bool ParseTreeModel::setData(const QModelIndex &index, const QVariant &value,
|
||||||
emit dataChanged(index, index);
|
emit dataChanged(index, index);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QGraphicsScene* ParseTreeModel::render(ProjectModel* project)
|
||||||
|
{
|
||||||
|
scene->clear();
|
||||||
|
|
||||||
|
/* First we set the screen size */
|
||||||
|
int screenWidth = safeSetting(project, "#screenwidth", "300").toInt();
|
||||||
|
int screenHeight = safeSetting(project, "#screenheight", "200").toInt();
|
||||||
|
scene->addRect(0, 0, screenWidth, screenHeight);
|
||||||
|
|
||||||
|
return scene;
|
||||||
|
}
|
||||||
|
|
|
@ -21,12 +21,14 @@
|
||||||
|
|
||||||
#include "skin_parser.h"
|
#include "skin_parser.h"
|
||||||
#include "skin_debug.h"
|
#include "skin_debug.h"
|
||||||
|
#include "projectmodel.h"
|
||||||
|
|
||||||
#ifndef PARSETREEMODEL_H
|
#ifndef PARSETREEMODEL_H
|
||||||
#define PARSETREEMODEL_H
|
#define PARSETREEMODEL_H
|
||||||
|
|
||||||
#include <QAbstractItemModel>
|
#include <QAbstractItemModel>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
|
#include <QGraphicsScene>
|
||||||
|
|
||||||
#include "parsetreenode.h"
|
#include "parsetreenode.h"
|
||||||
|
|
||||||
|
@ -58,9 +60,22 @@ public:
|
||||||
Qt::ItemFlags flags(const QModelIndex &index) const;
|
Qt::ItemFlags flags(const QModelIndex &index) const;
|
||||||
bool setData(const QModelIndex &index, const QVariant &value, int role);
|
bool setData(const QModelIndex &index, const QVariant &value, int role);
|
||||||
|
|
||||||
|
QGraphicsScene* render(ProjectModel* project);
|
||||||
|
|
||||||
|
static QString safeSetting(ProjectModel* project, QString key,
|
||||||
|
QString fallback)
|
||||||
|
{
|
||||||
|
if(project)
|
||||||
|
return project->getSetting(key, fallback);
|
||||||
|
else
|
||||||
|
return fallback;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ParseTreeNode* root;
|
ParseTreeNode* root;
|
||||||
struct skin_element* tree;
|
struct skin_element* tree;
|
||||||
|
QGraphicsScene* scene;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,10 @@ public:
|
||||||
int rowCount(const QModelIndex& parent) const;
|
int rowCount(const QModelIndex& parent) const;
|
||||||
QVariant data(const QModelIndex &index, int role) const;
|
QVariant data(const QModelIndex &index, int role) const;
|
||||||
|
|
||||||
QString getSetting(QString key){ return settings.value(key, ""); }
|
QString getSetting(QString key, QString fallback = "")
|
||||||
|
{
|
||||||
|
return settings.value(key, fallback);
|
||||||
|
}
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue