forked from len0rd/rockbox
Theme Editor: Reworked information passing among render functions, now loads all viewports and shows Custom UI viewport in blue
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27026 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
bd380b3993
commit
e1d8a3dc63
11 changed files with 127 additions and 64 deletions
|
@ -21,15 +21,17 @@
|
||||||
|
|
||||||
#include "rbrenderinfo.h"
|
#include "rbrenderinfo.h"
|
||||||
|
|
||||||
RBRenderInfo::RBRenderInfo(ParseTreeModel* model,
|
RBRenderInfo::RBRenderInfo(ParseTreeModel* model, ProjectModel* project,
|
||||||
ProjectModel* project, RBScreen* screen)
|
QMap<QString, QString>* settings, RBScreen* screen)
|
||||||
:mProject(project), mScreen(screen), mModel(model)
|
:mProject(project), mSettings(settings),
|
||||||
|
mScreen(screen), mModel(model)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
RBRenderInfo::RBRenderInfo(const RBRenderInfo &other)
|
RBRenderInfo::RBRenderInfo(const RBRenderInfo &other)
|
||||||
{
|
{
|
||||||
mProject = other.mProject;
|
mProject = other.mProject;
|
||||||
|
mSettings = other.mSettings;
|
||||||
mScreen = other.mScreen;
|
mScreen = other.mScreen;
|
||||||
mModel = other.mModel;
|
mModel = other.mModel;
|
||||||
}
|
}
|
||||||
|
@ -37,6 +39,7 @@ RBRenderInfo::RBRenderInfo(const RBRenderInfo &other)
|
||||||
const RBRenderInfo& RBRenderInfo::operator=(const RBRenderInfo& other)
|
const RBRenderInfo& RBRenderInfo::operator=(const RBRenderInfo& other)
|
||||||
{
|
{
|
||||||
mProject = other.mProject;
|
mProject = other.mProject;
|
||||||
|
mSettings = other.mSettings;
|
||||||
mScreen = other.mScreen;
|
mScreen = other.mScreen;
|
||||||
mModel = other.mModel;
|
mModel = other.mModel;
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,8 @@
|
||||||
#ifndef RBRENDERINFO_H
|
#ifndef RBRENDERINFO_H
|
||||||
#define RBRENDERINFO_H
|
#define RBRENDERINFO_H
|
||||||
|
|
||||||
|
#include <QMap>
|
||||||
|
|
||||||
class RBScreen;
|
class RBScreen;
|
||||||
class ProjectModel;
|
class ProjectModel;
|
||||||
class ParseTreeModel;
|
class ParseTreeModel;
|
||||||
|
@ -29,19 +31,21 @@ class ParseTreeModel;
|
||||||
class RBRenderInfo
|
class RBRenderInfo
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
RBRenderInfo(ParseTreeModel* model,
|
RBRenderInfo(ParseTreeModel* model, ProjectModel* project,
|
||||||
ProjectModel* project, RBScreen* screen);
|
QMap<QString, QString>* settings, 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; }
|
||||||
|
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; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ProjectModel* mProject;
|
ProjectModel* mProject;
|
||||||
|
QMap<QString, QString>* mSettings;
|
||||||
RBScreen* mScreen;
|
RBScreen* mScreen;
|
||||||
ParseTreeModel* mModel;
|
ParseTreeModel* mModel;
|
||||||
};
|
};
|
||||||
|
|
|
@ -20,28 +20,27 @@
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include "rbscreen.h"
|
#include "rbscreen.h"
|
||||||
|
#include "rbviewport.h"
|
||||||
|
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
|
|
||||||
RBScreen::RBScreen(ProjectModel* project, QGraphicsItem *parent) :
|
RBScreen::RBScreen(const RBRenderInfo& info, QGraphicsItem *parent) :
|
||||||
QGraphicsItem(parent), backdrop(0), project(project)
|
QGraphicsItem(parent), backdrop(0), project(project)
|
||||||
{
|
{
|
||||||
|
|
||||||
width = safeSetting(project, "#screenwidth", "300").toInt();
|
width = info.settings()->value("#screenwidth", "300").toInt();
|
||||||
height = safeSetting(project, "#screenheight", "200").toInt();
|
height = info.settings()->value("#screenheight", "200").toInt();
|
||||||
|
|
||||||
QString bg = safeSetting(project, "background color", "FFFFFF");
|
QString bg = info.settings()->value("background color", "000000");
|
||||||
bgColor = stringToColor(bg, Qt::white);
|
bgColor = stringToColor(bg, Qt::white);
|
||||||
|
|
||||||
QString fg = safeSetting(project, "foreground color", "FFFFFF");
|
QString fg = info.settings()->value("foreground color", "FFFFFF");
|
||||||
fgColor = stringToColor(fg, Qt::black);
|
fgColor = stringToColor(fg, Qt::black);
|
||||||
|
|
||||||
/* Loading backdrop if available */
|
/* Loading backdrop if available */
|
||||||
if(project)
|
QString base = info.settings()->value("themebase", "");
|
||||||
{
|
QString backdropFile = info.settings()->value("backdrop", "");
|
||||||
QString base = project->getSetting("themebase", "");
|
|
||||||
QString backdropFile = project->getSetting("backdrop", "");
|
|
||||||
|
|
||||||
if(QFile::exists(base + "/backdrops/" + backdropFile))
|
if(QFile::exists(base + "/backdrops/" + backdropFile))
|
||||||
{
|
{
|
||||||
|
@ -59,7 +58,6 @@ RBScreen::RBScreen(ProjectModel* project, QGraphicsItem *parent) :
|
||||||
backdrop = 0;
|
backdrop = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RBScreen::~RBScreen()
|
RBScreen::~RBScreen()
|
||||||
|
@ -93,6 +91,16 @@ void RBScreen::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RBScreen::showViewport(QString name)
|
||||||
|
{
|
||||||
|
if(namedViewports.value(name, 0) == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
namedViewports.value(name)->show();
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
QColor RBScreen::stringToColor(QString str, QColor fallback)
|
QColor RBScreen::stringToColor(QString str, QColor fallback)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
|
@ -25,12 +25,15 @@
|
||||||
#include <QGraphicsItem>
|
#include <QGraphicsItem>
|
||||||
|
|
||||||
#include "projectmodel.h"
|
#include "projectmodel.h"
|
||||||
|
#include "rbrenderinfo.h"
|
||||||
|
|
||||||
|
class RBViewport;
|
||||||
|
|
||||||
class RBScreen : public QGraphicsItem
|
class RBScreen : public QGraphicsItem
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
RBScreen(ProjectModel* project = 0, QGraphicsItem *parent = 0);
|
RBScreen(const RBRenderInfo& info, QGraphicsItem *parent = 0);
|
||||||
virtual ~RBScreen();
|
virtual ~RBScreen();
|
||||||
|
|
||||||
QPainterPath shape() const;
|
QPainterPath shape() const;
|
||||||
|
@ -41,14 +44,11 @@ public:
|
||||||
int getWidth() const{ return width; }
|
int getWidth() const{ return width; }
|
||||||
int getHeight() const{ return height; }
|
int getHeight() const{ return height; }
|
||||||
|
|
||||||
static QString safeSetting(ProjectModel* project, QString key,
|
void loadViewport(QString name, RBViewport* view)
|
||||||
QString fallback)
|
|
||||||
{
|
{
|
||||||
if(project)
|
namedViewports.insert(name, view);
|
||||||
return project->getSetting(key, fallback);
|
|
||||||
else
|
|
||||||
return fallback;
|
|
||||||
}
|
}
|
||||||
|
void showViewport(QString name);
|
||||||
|
|
||||||
static QColor stringToColor(QString str, QColor fallback);
|
static QColor stringToColor(QString str, QColor fallback);
|
||||||
|
|
||||||
|
@ -62,6 +62,8 @@ private:
|
||||||
|
|
||||||
ProjectModel* project;
|
ProjectModel* project;
|
||||||
|
|
||||||
|
QMap<QString, RBViewport*> namedViewports;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // RBSCREEN_H
|
#endif // RBSCREEN_H
|
||||||
|
|
|
@ -50,38 +50,57 @@ RBViewport::RBViewport(skin_element* node, const RBRenderInfo& info)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int x, y, w, h;
|
int param;
|
||||||
/* Parsing one of the other types of viewport */
|
QString ident;
|
||||||
|
int x,y,w,h;
|
||||||
|
/* Rendering one of the other types of viewport */
|
||||||
switch(node->tag->name[1])
|
switch(node->tag->name[1])
|
||||||
{
|
{
|
||||||
case '\0':
|
case '\0':
|
||||||
/* A normal viewport definition */
|
customUI = false;
|
||||||
x = node->params[0].data.numeric;
|
|
||||||
y = node->params[1].data.numeric;
|
|
||||||
|
|
||||||
if(node->params[2].type == skin_tag_parameter::DEFAULT)
|
|
||||||
w = info.screen()->getWidth() - x;
|
|
||||||
else
|
|
||||||
w = node->params[2].data.numeric;
|
|
||||||
|
|
||||||
if(node->params[3].type == skin_tag_parameter::DEFAULT)
|
|
||||||
h = info.screen()->getHeight() - y;
|
|
||||||
else
|
|
||||||
h = node->params[3].data.numeric;
|
|
||||||
|
|
||||||
size = QRectF(x, y, w, h);
|
|
||||||
displayed = true;
|
displayed = true;
|
||||||
|
param = 0;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'l':
|
case 'l':
|
||||||
/* Preloaded viewport */
|
/* A preloaded viewport definition */
|
||||||
|
ident = node->params[0].data.text;
|
||||||
|
customUI = false;
|
||||||
|
displayed = false;
|
||||||
|
info.screen()->loadViewport(ident, this);
|
||||||
|
param = 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'i':
|
case 'i':
|
||||||
/* Custom UI Viewport */
|
/* Custom UI Viewport */
|
||||||
break;
|
customUI = true;
|
||||||
|
param = 1;
|
||||||
|
if(node->params[0].type == skin_tag_parameter::DEFAULT)
|
||||||
|
{
|
||||||
|
displayed = true;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
displayed = false;
|
||||||
|
info.screen()->loadViewport(ident, this);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/* Now we grab the info common to all viewports */
|
||||||
|
x = node->params[param++].data.numeric;
|
||||||
|
y = node->params[param++].data.numeric;
|
||||||
|
|
||||||
|
if(node->params[param].type == skin_tag_parameter::DEFAULT)
|
||||||
|
w = info.screen()->getWidth() - x;
|
||||||
|
else
|
||||||
|
w = node->params[param].data.numeric;
|
||||||
|
|
||||||
|
if(node->params[++param].type == skin_tag_parameter::DEFAULT)
|
||||||
|
h = info.screen()->getHeight() - y;
|
||||||
|
else
|
||||||
|
h = node->params[param].data.numeric;
|
||||||
|
|
||||||
|
size = QRectF(x, y, w, h);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,7 +123,8 @@ QRectF RBViewport::boundingRect() const
|
||||||
void RBViewport::paint(QPainter *painter,
|
void RBViewport::paint(QPainter *painter,
|
||||||
const QStyleOptionGraphicsItem *option, QWidget *widget)
|
const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||||
{
|
{
|
||||||
|
QColor color = customUI ? Qt::blue : Qt::red;
|
||||||
if(displayed)
|
if(displayed)
|
||||||
painter->fillRect(size, Qt::red);
|
painter->fillRect(size, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,6 +48,7 @@ private:
|
||||||
QColor foreground;
|
QColor foreground;
|
||||||
|
|
||||||
bool displayed;
|
bool displayed;
|
||||||
|
bool customUI;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -70,7 +70,7 @@ public:
|
||||||
|
|
||||||
TabType type() const{ return Skin; }
|
TabType type() const{ return Skin; }
|
||||||
|
|
||||||
QGraphicsScene* scene(){ return model->render(project); }
|
QGraphicsScene* scene(){ return model->render(project, &fileName); }
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,8 @@
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
|
#include <QMap>
|
||||||
|
#include <QDir>
|
||||||
|
|
||||||
ParseTreeModel::ParseTreeModel(const char* document, QObject* parent):
|
ParseTreeModel::ParseTreeModel(const char* document, QObject* parent):
|
||||||
QAbstractItemModel(parent)
|
QAbstractItemModel(parent)
|
||||||
|
@ -270,23 +272,40 @@ bool ParseTreeModel::setData(const QModelIndex &index, const QVariant &value,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
QGraphicsScene* ParseTreeModel::render(ProjectModel* project)
|
QGraphicsScene* ParseTreeModel::render(ProjectModel* project,
|
||||||
|
const QString* file)
|
||||||
{
|
{
|
||||||
scene->clear();
|
scene->clear();
|
||||||
|
|
||||||
/* Setting the background */
|
/* Setting the background */
|
||||||
scene->setBackgroundBrush(QBrush(QPixmap(":/render/scenebg.png")));
|
scene->setBackgroundBrush(QBrush(QPixmap(":/render/scenebg.png")));
|
||||||
|
|
||||||
|
/* Preparing settings */
|
||||||
|
QMap<QString, QString> settings;
|
||||||
|
if(project)
|
||||||
|
settings = project->getSettings();
|
||||||
|
|
||||||
|
/* Setting themebase if it can't be derived from the project */
|
||||||
|
if(settings.value("themebase", "") == "" && file && QFile::exists(*file))
|
||||||
|
{
|
||||||
|
QDir base(*file);
|
||||||
|
base.cdUp();
|
||||||
|
settings.insert("themebase", base.canonicalPath());
|
||||||
|
}
|
||||||
|
|
||||||
|
RBScreen* screen = 0;
|
||||||
|
RBRenderInfo info(this, project, &settings, screen);
|
||||||
|
|
||||||
/* Adding the screen */
|
/* Adding the screen */
|
||||||
RBScreen* screen = new RBScreen(project);
|
screen = new RBScreen(info);
|
||||||
scene->addItem(screen);
|
scene->addItem(screen);
|
||||||
|
|
||||||
RBRenderInfo info(this, project, screen);
|
info = RBRenderInfo(this, project, &settings, screen);
|
||||||
|
|
||||||
|
|
||||||
/* Rendering the tree */
|
/* Rendering the tree */
|
||||||
if(root)
|
if(root)
|
||||||
root->render(info);
|
root->render(info);
|
||||||
|
|
||||||
|
|
||||||
return scene;
|
return scene;
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,7 +60,7 @@ 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);
|
QGraphicsScene* render(ProjectModel* project, const QString* file = 0);
|
||||||
|
|
||||||
static QString safeSetting(ProjectModel* project, QString key,
|
static QString safeSetting(ProjectModel* project, QString key,
|
||||||
QString fallback)
|
QString fallback)
|
||||||
|
|
|
@ -25,6 +25,8 @@
|
||||||
#include "parsetreenode.h"
|
#include "parsetreenode.h"
|
||||||
#include "parsetreemodel.h"
|
#include "parsetreemodel.h"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
int ParseTreeNode::openConditionals = 0;
|
int ParseTreeNode::openConditionals = 0;
|
||||||
|
|
||||||
/* Root element constructor */
|
/* Root element constructor */
|
||||||
|
@ -490,11 +492,13 @@ void ParseTreeNode::render(const RBRenderInfo& info)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(element->type)
|
if(element->type != VIEWPORT)
|
||||||
{
|
{
|
||||||
case VIEWPORT:
|
std::cerr << QObject::tr("Error in parse tree").toStdString()
|
||||||
rendered = new RBViewport(element, info);
|
<< std::endl;
|
||||||
break;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rendered = new RBViewport(element, info);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,6 +49,8 @@ public:
|
||||||
return settings.value(key, fallback);
|
return settings.value(key, fallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const QMap<QString, QString>& getSettings() const{ return settings; }
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue