Theme Editor: Began integrating device configuration panel with renderer
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27135 a1c6a512-1295-4272-9138-f99709370657
diff --git a/utils/themeeditor/graphics/rbrenderinfo.cpp b/utils/themeeditor/graphics/rbrenderinfo.cpp
index ca9f2b6..289d730 100644
--- a/utils/themeeditor/graphics/rbrenderinfo.cpp
+++ b/utils/themeeditor/graphics/rbrenderinfo.cpp
@@ -22,9 +22,10 @@
#include "rbrenderinfo.h"
RBRenderInfo::RBRenderInfo(ParseTreeModel* model, ProjectModel* project,
- QMap<QString, QString>* settings, RBScreen* screen)
+ QMap<QString, QString>* settings,
+ DeviceState* device, RBScreen* screen)
:mProject(project), mSettings(settings),
- mScreen(screen), mModel(model)
+ mDevice(device), mScreen(screen), mModel(model)
{
}
@@ -32,6 +33,7 @@
{
mProject = other.mProject;
mSettings = other.mSettings;
+ mDevice = other.mDevice;
mScreen = other.mScreen;
mModel = other.mModel;
}
@@ -40,6 +42,7 @@
{
mProject = other.mProject;
mSettings = other.mSettings;
+ mDevice = other.mDevice;
mScreen = other.mScreen;
mModel = other.mModel;
diff --git a/utils/themeeditor/graphics/rbrenderinfo.h b/utils/themeeditor/graphics/rbrenderinfo.h
index c80cb00..c65c4de 100644
--- a/utils/themeeditor/graphics/rbrenderinfo.h
+++ b/utils/themeeditor/graphics/rbrenderinfo.h
@@ -27,18 +27,21 @@
class RBScreen;
class ProjectModel;
class ParseTreeModel;
+class DeviceState;
class RBRenderInfo
{
public:
RBRenderInfo(ParseTreeModel* model, ProjectModel* project,
- QMap<QString, QString>* settings, RBScreen* screen);
+ QMap<QString, QString>* settings, DeviceState* device,
+ RBScreen* screen);
RBRenderInfo(const RBRenderInfo& other);
virtual ~RBRenderInfo();
const RBRenderInfo& operator=(const RBRenderInfo& other);
ProjectModel* project() const{ return mProject; }
+ DeviceState* device() const{ return mDevice; }
QMap<QString, QString>* settings() const{ return mSettings; }
RBScreen* screen() const{ return mScreen; }
ParseTreeModel* model() const{ return mModel; }
@@ -46,6 +49,7 @@
private:
ProjectModel* mProject;
QMap<QString, QString>* mSettings;
+ DeviceState* mDevice;
RBScreen* mScreen;
ParseTreeModel* mModel;
};
diff --git a/utils/themeeditor/graphics/rbscreen.cpp b/utils/themeeditor/graphics/rbscreen.cpp
index d6a9aa6..da6d20b 100644
--- a/utils/themeeditor/graphics/rbscreen.cpp
+++ b/utils/themeeditor/graphics/rbscreen.cpp
@@ -21,6 +21,7 @@
#include "rbscreen.h"
#include "rbviewport.h"
+#include "devicestate.h"
#include <QPainter>
#include <QFile>
@@ -29,8 +30,13 @@
QGraphicsItem(parent), backdrop(0), project(project)
{
+ /*
width = info.settings()->value("#screenwidth", "300").toInt();
height = info.settings()->value("#screenheight", "200").toInt();
+*/
+
+ width = info.device()->data("screenwidth").toInt();
+ height = info.device()->data("screenheight").toInt();
QString bg = info.settings()->value("background color", "FFFFFF");
bgColor = stringToColor(bg, Qt::white);
diff --git a/utils/themeeditor/graphics/rbviewport.h b/utils/themeeditor/graphics/rbviewport.h
index 5726c5c..1ee85f2 100644
--- a/utils/themeeditor/graphics/rbviewport.h
+++ b/utils/themeeditor/graphics/rbviewport.h
@@ -52,9 +52,9 @@
private:
QRectF size;
- QColor background;
- QColor foreground;
RBFont* font;
+ QColor foreground;
+ QColor background;
bool customUI;
QPoint textOffset;
diff --git a/utils/themeeditor/gui/configdocument.h b/utils/themeeditor/gui/configdocument.h
index 0057ac1..e91c5cc 100644
--- a/utils/themeeditor/gui/configdocument.h
+++ b/utils/themeeditor/gui/configdocument.h
@@ -75,7 +75,6 @@
void addClicked();
void textChanged();
-
private:
Ui::ConfigDocument *ui;
QList<QHBoxLayout*> containers;
diff --git a/utils/themeeditor/gui/devicestate.cpp b/utils/themeeditor/gui/devicestate.cpp
index 3933926..80efd4d 100644
--- a/utils/themeeditor/gui/devicestate.cpp
+++ b/utils/themeeditor/gui/devicestate.cpp
@@ -234,6 +234,47 @@
return QVariant();
}
+void DeviceState::setData(QString tag, QVariant data)
+{
+ QPair<InputType, QWidget*> found =
+ inputs.value(tag, QPair<InputType, QWidget*>(Slide, 0));
+
+ if(found.second == 0)
+ return;
+
+ switch(found.first)
+ {
+ case Text:
+ dynamic_cast<QLineEdit*>(found.second)->setText(data.toString());
+ break;
+
+ case Slide:
+ dynamic_cast<QSlider*>(found.second)->setValue(data.toInt());
+ break;
+
+ case Spin:
+ dynamic_cast<QSpinBox*>(found.second)->setValue(data.toInt());
+ break;
+
+ case DSpin:
+ dynamic_cast<QDoubleSpinBox*>(found.second)->setValue(data.toDouble());
+ break;
+
+ case Combo:
+ dynamic_cast<QComboBox*>
+ (found.second)->
+ setCurrentIndex(dynamic_cast<QComboBox*>
+ (found.second)->findText(data.toString()));
+ break;
+
+ case Check:
+ dynamic_cast<QCheckBox*>(found.second)->setChecked(data.toBool());
+ break;
+ }
+
+ emit settingsChanged();
+}
+
void DeviceState::input()
{
emit settingsChanged();
diff --git a/utils/themeeditor/gui/devicestate.h b/utils/themeeditor/gui/devicestate.h
index c680e2c..cae3cef 100644
--- a/utils/themeeditor/gui/devicestate.h
+++ b/utils/themeeditor/gui/devicestate.h
@@ -47,6 +47,7 @@
virtual ~DeviceState();
QVariant data(QString tag);
+ void setData(QString tag, QVariant data);
signals:
void settingsChanged();
diff --git a/utils/themeeditor/gui/editorwindow.cpp b/utils/themeeditor/gui/editorwindow.cpp
index 94e744e..b778a1f 100644
--- a/utils/themeeditor/gui/editorwindow.cpp
+++ b/utils/themeeditor/gui/editorwindow.cpp
@@ -66,7 +66,8 @@
}
/* Adding a new document*/
- SkinDocument* doc = new SkinDocument(parseStatus, fileName, project);
+ SkinDocument* doc = new SkinDocument(parseStatus, fileName, project,
+ deviceConfig);
addTab(doc);
ui->editorTabs->setCurrentWidget(doc);
@@ -219,7 +220,7 @@
void EditorWindow::newTab()
{
- SkinDocument* doc = new SkinDocument(parseStatus, project);
+ SkinDocument* doc = new SkinDocument(parseStatus, project, deviceConfig);
addTab(doc);
ui->editorTabs->setCurrentWidget(doc);
}
@@ -345,6 +346,13 @@
project = new ProjectModel(fileName, this);
ui->projectTree->setModel(project);
+ if(project->getSetting("#screenwidth") != "")
+ deviceConfig->setData("screenwidth",
+ project->getSetting("#screenwidth"));
+ if(project->getSetting("#screenheight") != "")
+ deviceConfig->setData("screenheight",
+ project->getSetting("#screenheight"));
+
QObject::connect(ui->projectTree, SIGNAL(activated(QModelIndex)),
project, SLOT(activated(QModelIndex)));
diff --git a/utils/themeeditor/gui/skindocument.cpp b/utils/themeeditor/gui/skindocument.cpp
index 8c98255..4f48d34 100644
--- a/utils/themeeditor/gui/skindocument.cpp
+++ b/utils/themeeditor/gui/skindocument.cpp
@@ -30,9 +30,9 @@
#include <iostream>
SkinDocument::SkinDocument(QLabel* statusLabel, ProjectModel* project,
- QWidget *parent)
+ DeviceState* device, QWidget *parent)
:TabContent(parent), statusLabel(statusLabel),
- project(project)
+ project(project), device(device)
{
setupUI();
@@ -44,9 +44,11 @@
}
SkinDocument::SkinDocument(QLabel* statusLabel, QString file,
- ProjectModel* project, QWidget *parent)
+ ProjectModel* project, DeviceState* device,
+ QWidget *parent)
:TabContent(parent), fileName(file),
- statusLabel(statusLabel), project(project)
+ statusLabel(statusLabel), project(project),
+ device(device)
{
setupUI();
blockUpdate = false;
@@ -145,6 +147,10 @@
QObject::connect(editor, SIGNAL(cursorPositionChanged()),
this, SLOT(cursorChanged()));
+ /* Connecting to device setting changes */
+ QObject::connect(device, SIGNAL(settingsChanged()),
+ this, SLOT(deviceChanged()));
+
settingsChanged();
}
@@ -257,7 +263,7 @@
else
emit titleChanged(titleText);
- model->render(project, &fileName);
+ model->render(project, device, &fileName);
cursorChanged();
diff --git a/utils/themeeditor/gui/skindocument.h b/utils/themeeditor/gui/skindocument.h
index f6ceb73..c6b3687 100644
--- a/utils/themeeditor/gui/skindocument.h
+++ b/utils/themeeditor/gui/skindocument.h
@@ -33,6 +33,7 @@
#include "codeeditor.h"
#include "tabcontent.h"
#include "projectmodel.h"
+#include "devicestate.h"
class SkinDocument : public TabContent
{
@@ -49,9 +50,9 @@
}
SkinDocument(QLabel* statusLabel, ProjectModel* project = 0,
- QWidget *parent = 0);
+ DeviceState* device = 0, QWidget *parent = 0);
SkinDocument(QLabel* statusLabel, QString file, ProjectModel* project = 0,
- QWidget* parent = 0);
+ DeviceState* device = 0, QWidget* parent = 0);
virtual ~SkinDocument();
void connectPrefs(PreferencesDialog* prefs);
@@ -70,7 +71,7 @@
TabType type() const{ return Skin; }
- QGraphicsScene* scene(){ return model->render(project, &fileName); }
+ QGraphicsScene* scene(){ return model->render(project, device, &fileName); }
signals:
@@ -80,6 +81,7 @@
private slots:
void codeChanged();
+ void deviceChanged(){ scene(); }
private:
void setupUI();
@@ -101,6 +103,7 @@
bool blockUpdate;
ProjectModel* project;
+ DeviceState* device;
};
#endif // SKINDOCUMENT_H
diff --git a/utils/themeeditor/models/parsetreemodel.cpp b/utils/themeeditor/models/parsetreemodel.cpp
index 830a646..ff8a27c 100644
--- a/utils/themeeditor/models/parsetreemodel.cpp
+++ b/utils/themeeditor/models/parsetreemodel.cpp
@@ -275,7 +275,7 @@
}
QGraphicsScene* ParseTreeModel::render(ProjectModel* project,
- const QString* file)
+ DeviceState* device, const QString* file)
{
scene->clear();
@@ -306,13 +306,13 @@
}
RBScreen* screen = 0;
- RBRenderInfo info(this, project, &settings, screen);
+ RBRenderInfo info(this, project, &settings, device, screen);
/* Adding the screen */
screen = new RBScreen(info);
scene->addItem(screen);
- info = RBRenderInfo(this, project, &settings, screen);
+ info = RBRenderInfo(this, project, &settings, device, screen);
/* Rendering the tree */
diff --git a/utils/themeeditor/models/parsetreemodel.h b/utils/themeeditor/models/parsetreemodel.h
index df64403..463f6ca 100644
--- a/utils/themeeditor/models/parsetreemodel.h
+++ b/utils/themeeditor/models/parsetreemodel.h
@@ -22,6 +22,7 @@
#include "skin_parser.h"
#include "skin_debug.h"
#include "projectmodel.h"
+#include "devicestate.h"
#ifndef PARSETREEMODEL_H
#define PARSETREEMODEL_H
@@ -31,6 +32,7 @@
#include <QGraphicsScene>
#include "parsetreenode.h"
+#include "devicestate.h"
class ParseTreeModel : public QAbstractItemModel
{
@@ -60,7 +62,8 @@
Qt::ItemFlags flags(const QModelIndex &index) const;
bool setData(const QModelIndex &index, const QVariant &value, int role);
- QGraphicsScene* render(ProjectModel* project, const QString* file = 0);
+ QGraphicsScene* render(ProjectModel* project, DeviceState* device,
+ const QString* file = 0);
static QString safeSetting(ProjectModel* project, QString key,
QString fallback)