1
0
Fork 0
forked from len0rd/rockbox

Theme Editor: Began integrating device configuration panel with renderer

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27135 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Robert Bieber 2010-06-26 05:18:21 +00:00
parent d93164d6c9
commit c32728c91c
12 changed files with 94 additions and 20 deletions

View file

@ -22,9 +22,10 @@
#include "rbrenderinfo.h" #include "rbrenderinfo.h"
RBRenderInfo::RBRenderInfo(ParseTreeModel* model, ProjectModel* project, RBRenderInfo::RBRenderInfo(ParseTreeModel* model, ProjectModel* project,
QMap<QString, QString>* settings, RBScreen* screen) QMap<QString, QString>* settings,
DeviceState* device, RBScreen* screen)
:mProject(project), mSettings(settings), :mProject(project), mSettings(settings),
mScreen(screen), mModel(model) mDevice(device), mScreen(screen), mModel(model)
{ {
} }
@ -32,6 +33,7 @@ RBRenderInfo::RBRenderInfo(const RBRenderInfo &other)
{ {
mProject = other.mProject; mProject = other.mProject;
mSettings = other.mSettings; mSettings = other.mSettings;
mDevice = other.mDevice;
mScreen = other.mScreen; mScreen = other.mScreen;
mModel = other.mModel; mModel = other.mModel;
} }
@ -40,6 +42,7 @@ const RBRenderInfo& RBRenderInfo::operator=(const RBRenderInfo& other)
{ {
mProject = other.mProject; mProject = other.mProject;
mSettings = other.mSettings; mSettings = other.mSettings;
mDevice = other.mDevice;
mScreen = other.mScreen; mScreen = other.mScreen;
mModel = other.mModel; mModel = other.mModel;

View file

@ -27,18 +27,21 @@
class RBScreen; class RBScreen;
class ProjectModel; class ProjectModel;
class ParseTreeModel; class ParseTreeModel;
class DeviceState;
class RBRenderInfo class RBRenderInfo
{ {
public: public:
RBRenderInfo(ParseTreeModel* model, ProjectModel* project, RBRenderInfo(ParseTreeModel* model, ProjectModel* project,
QMap<QString, QString>* settings, RBScreen* screen); QMap<QString, QString>* settings, DeviceState* device,
RBScreen* screen);
RBRenderInfo(const RBRenderInfo& other); RBRenderInfo(const RBRenderInfo& other);
virtual ~RBRenderInfo(); virtual ~RBRenderInfo();
const RBRenderInfo& operator=(const RBRenderInfo& other); const RBRenderInfo& operator=(const RBRenderInfo& other);
ProjectModel* project() const{ return mProject; } ProjectModel* project() const{ return mProject; }
DeviceState* device() const{ return mDevice; }
QMap<QString, QString>* settings() const{ return mSettings; } QMap<QString, QString>* settings() const{ return mSettings; }
RBScreen* screen() const{ return mScreen; } RBScreen* screen() const{ return mScreen; }
ParseTreeModel* model() const{ return mModel; } ParseTreeModel* model() const{ return mModel; }
@ -46,6 +49,7 @@ public:
private: private:
ProjectModel* mProject; ProjectModel* mProject;
QMap<QString, QString>* mSettings; QMap<QString, QString>* mSettings;
DeviceState* mDevice;
RBScreen* mScreen; RBScreen* mScreen;
ParseTreeModel* mModel; ParseTreeModel* mModel;
}; };

View file

@ -21,6 +21,7 @@
#include "rbscreen.h" #include "rbscreen.h"
#include "rbviewport.h" #include "rbviewport.h"
#include "devicestate.h"
#include <QPainter> #include <QPainter>
#include <QFile> #include <QFile>
@ -29,8 +30,13 @@ RBScreen::RBScreen(const RBRenderInfo& info, QGraphicsItem *parent) :
QGraphicsItem(parent), backdrop(0), project(project) QGraphicsItem(parent), backdrop(0), project(project)
{ {
/*
width = info.settings()->value("#screenwidth", "300").toInt(); width = info.settings()->value("#screenwidth", "300").toInt();
height = info.settings()->value("#screenheight", "200").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"); QString bg = info.settings()->value("background color", "FFFFFF");
bgColor = stringToColor(bg, Qt::white); bgColor = stringToColor(bg, Qt::white);

View file

@ -52,9 +52,9 @@ public:
private: private:
QRectF size; QRectF size;
QColor background;
QColor foreground;
RBFont* font; RBFont* font;
QColor foreground;
QColor background;
bool customUI; bool customUI;
QPoint textOffset; QPoint textOffset;

View file

@ -75,7 +75,6 @@ private slots:
void addClicked(); void addClicked();
void textChanged(); void textChanged();
private: private:
Ui::ConfigDocument *ui; Ui::ConfigDocument *ui;
QList<QHBoxLayout*> containers; QList<QHBoxLayout*> containers;

View file

@ -234,6 +234,47 @@ QVariant DeviceState::data(QString tag)
return QVariant(); 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() void DeviceState::input()
{ {
emit settingsChanged(); emit settingsChanged();

View file

@ -47,6 +47,7 @@ public:
virtual ~DeviceState(); virtual ~DeviceState();
QVariant data(QString tag); QVariant data(QString tag);
void setData(QString tag, QVariant data);
signals: signals:
void settingsChanged(); void settingsChanged();

View file

@ -66,7 +66,8 @@ void EditorWindow::loadTabFromSkinFile(QString fileName)
} }
/* Adding a new document*/ /* Adding a new document*/
SkinDocument* doc = new SkinDocument(parseStatus, fileName, project); SkinDocument* doc = new SkinDocument(parseStatus, fileName, project,
deviceConfig);
addTab(doc); addTab(doc);
ui->editorTabs->setCurrentWidget(doc); ui->editorTabs->setCurrentWidget(doc);
@ -219,7 +220,7 @@ void EditorWindow::addTab(TabContent *doc)
void EditorWindow::newTab() void EditorWindow::newTab()
{ {
SkinDocument* doc = new SkinDocument(parseStatus, project); SkinDocument* doc = new SkinDocument(parseStatus, project, deviceConfig);
addTab(doc); addTab(doc);
ui->editorTabs->setCurrentWidget(doc); ui->editorTabs->setCurrentWidget(doc);
} }
@ -345,6 +346,13 @@ void EditorWindow::openProject()
project = new ProjectModel(fileName, this); project = new ProjectModel(fileName, this);
ui->projectTree->setModel(project); 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)), QObject::connect(ui->projectTree, SIGNAL(activated(QModelIndex)),
project, SLOT(activated(QModelIndex))); project, SLOT(activated(QModelIndex)));

View file

@ -30,9 +30,9 @@
#include <iostream> #include <iostream>
SkinDocument::SkinDocument(QLabel* statusLabel, ProjectModel* project, SkinDocument::SkinDocument(QLabel* statusLabel, ProjectModel* project,
QWidget *parent) DeviceState* device, QWidget *parent)
:TabContent(parent), statusLabel(statusLabel), :TabContent(parent), statusLabel(statusLabel),
project(project) project(project), device(device)
{ {
setupUI(); setupUI();
@ -44,9 +44,11 @@ SkinDocument::SkinDocument(QLabel* statusLabel, ProjectModel* project,
} }
SkinDocument::SkinDocument(QLabel* statusLabel, QString file, SkinDocument::SkinDocument(QLabel* statusLabel, QString file,
ProjectModel* project, QWidget *parent) ProjectModel* project, DeviceState* device,
QWidget *parent)
:TabContent(parent), fileName(file), :TabContent(parent), fileName(file),
statusLabel(statusLabel), project(project) statusLabel(statusLabel), project(project),
device(device)
{ {
setupUI(); setupUI();
blockUpdate = false; blockUpdate = false;
@ -145,6 +147,10 @@ void SkinDocument::setupUI()
QObject::connect(editor, SIGNAL(cursorPositionChanged()), QObject::connect(editor, SIGNAL(cursorPositionChanged()),
this, SLOT(cursorChanged())); this, SLOT(cursorChanged()));
/* Connecting to device setting changes */
QObject::connect(device, SIGNAL(settingsChanged()),
this, SLOT(deviceChanged()));
settingsChanged(); settingsChanged();
} }
@ -257,7 +263,7 @@ void SkinDocument::codeChanged()
else else
emit titleChanged(titleText); emit titleChanged(titleText);
model->render(project, &fileName); model->render(project, device, &fileName);
cursorChanged(); cursorChanged();

View file

@ -33,6 +33,7 @@
#include "codeeditor.h" #include "codeeditor.h"
#include "tabcontent.h" #include "tabcontent.h"
#include "projectmodel.h" #include "projectmodel.h"
#include "devicestate.h"
class SkinDocument : public TabContent class SkinDocument : public TabContent
{ {
@ -49,9 +50,9 @@ public:
} }
SkinDocument(QLabel* statusLabel, ProjectModel* project = 0, SkinDocument(QLabel* statusLabel, ProjectModel* project = 0,
QWidget *parent = 0); DeviceState* device = 0, QWidget *parent = 0);
SkinDocument(QLabel* statusLabel, QString file, ProjectModel* project = 0, SkinDocument(QLabel* statusLabel, QString file, ProjectModel* project = 0,
QWidget* parent = 0); DeviceState* device = 0, QWidget* parent = 0);
virtual ~SkinDocument(); virtual ~SkinDocument();
void connectPrefs(PreferencesDialog* prefs); void connectPrefs(PreferencesDialog* prefs);
@ -70,7 +71,7 @@ public:
TabType type() const{ return Skin; } TabType type() const{ return Skin; }
QGraphicsScene* scene(){ return model->render(project, &fileName); } QGraphicsScene* scene(){ return model->render(project, device, &fileName); }
signals: signals:
@ -80,6 +81,7 @@ public slots:
private slots: private slots:
void codeChanged(); void codeChanged();
void deviceChanged(){ scene(); }
private: private:
void setupUI(); void setupUI();
@ -101,6 +103,7 @@ private:
bool blockUpdate; bool blockUpdate;
ProjectModel* project; ProjectModel* project;
DeviceState* device;
}; };
#endif // SKINDOCUMENT_H #endif // SKINDOCUMENT_H

View file

@ -275,7 +275,7 @@ bool ParseTreeModel::setData(const QModelIndex &index, const QVariant &value,
} }
QGraphicsScene* ParseTreeModel::render(ProjectModel* project, QGraphicsScene* ParseTreeModel::render(ProjectModel* project,
const QString* file) DeviceState* device, const QString* file)
{ {
scene->clear(); scene->clear();
@ -306,13 +306,13 @@ QGraphicsScene* ParseTreeModel::render(ProjectModel* project,
} }
RBScreen* screen = 0; RBScreen* screen = 0;
RBRenderInfo info(this, project, &settings, screen); RBRenderInfo info(this, project, &settings, device, screen);
/* Adding the screen */ /* Adding the screen */
screen = new RBScreen(info); screen = new RBScreen(info);
scene->addItem(screen); scene->addItem(screen);
info = RBRenderInfo(this, project, &settings, screen); info = RBRenderInfo(this, project, &settings, device, screen);
/* Rendering the tree */ /* Rendering the tree */

View file

@ -22,6 +22,7 @@
#include "skin_parser.h" #include "skin_parser.h"
#include "skin_debug.h" #include "skin_debug.h"
#include "projectmodel.h" #include "projectmodel.h"
#include "devicestate.h"
#ifndef PARSETREEMODEL_H #ifndef PARSETREEMODEL_H
#define PARSETREEMODEL_H #define PARSETREEMODEL_H
@ -31,6 +32,7 @@
#include <QGraphicsScene> #include <QGraphicsScene>
#include "parsetreenode.h" #include "parsetreenode.h"
#include "devicestate.h"
class ParseTreeModel : public QAbstractItemModel class ParseTreeModel : public QAbstractItemModel
{ {
@ -60,7 +62,8 @@ 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, const QString* file = 0); QGraphicsScene* render(ProjectModel* project, DeviceState* device,
const QString* file = 0);
static QString safeSetting(ProjectModel* project, QString key, static QString safeSetting(ProjectModel* project, QString key,
QString fallback) QString fallback)