diff options
author | Robert Bieber <robby@bieberphoto.com> | 2010-06-21 20:11:58 +0000 |
---|---|---|
committer | Robert Bieber <robby@bieberphoto.com> | 2010-06-21 20:11:58 +0000 |
commit | e1d8a3dc63391098f9381a3cb33d73e69b46c006 (patch) | |
tree | 0f503320d4fda330a003fe88ae7482537037db85 /utils | |
parent | bd380b399323d15a1572cdc017e0f95b1b9db151 (diff) |
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
Diffstat (limited to 'utils')
-rw-r--r-- | utils/themeeditor/graphics/rbrenderinfo.cpp | 9 | ||||
-rw-r--r-- | utils/themeeditor/graphics/rbrenderinfo.h | 8 | ||||
-rw-r--r-- | utils/themeeditor/graphics/rbscreen.cpp | 52 | ||||
-rw-r--r-- | utils/themeeditor/graphics/rbscreen.h | 16 | ||||
-rw-r--r-- | utils/themeeditor/graphics/rbviewport.cpp | 60 | ||||
-rw-r--r-- | utils/themeeditor/graphics/rbviewport.h | 1 | ||||
-rw-r--r-- | utils/themeeditor/gui/skindocument.h | 2 | ||||
-rw-r--r-- | utils/themeeditor/models/parsetreemodel.cpp | 27 | ||||
-rw-r--r-- | utils/themeeditor/models/parsetreemodel.h | 2 | ||||
-rw-r--r-- | utils/themeeditor/models/parsetreenode.cpp | 12 | ||||
-rw-r--r-- | utils/themeeditor/models/projectmodel.h | 2 |
11 files changed, 127 insertions, 64 deletions
diff --git a/utils/themeeditor/graphics/rbrenderinfo.cpp b/utils/themeeditor/graphics/rbrenderinfo.cpp index 468533628f..ca9f2b632d 100644 --- a/utils/themeeditor/graphics/rbrenderinfo.cpp +++ b/utils/themeeditor/graphics/rbrenderinfo.cpp @@ -21,15 +21,17 @@ #include "rbrenderinfo.h" -RBRenderInfo::RBRenderInfo(ParseTreeModel* model, - ProjectModel* project, RBScreen* screen) - :mProject(project), mScreen(screen), mModel(model) +RBRenderInfo::RBRenderInfo(ParseTreeModel* model, ProjectModel* project, + QMap<QString, QString>* settings, RBScreen* screen) + :mProject(project), mSettings(settings), + mScreen(screen), mModel(model) { } RBRenderInfo::RBRenderInfo(const RBRenderInfo &other) { mProject = other.mProject; + mSettings = other.mSettings; mScreen = other.mScreen; mModel = other.mModel; } @@ -37,6 +39,7 @@ RBRenderInfo::RBRenderInfo(const RBRenderInfo &other) const RBRenderInfo& RBRenderInfo::operator=(const RBRenderInfo& other) { mProject = other.mProject; + mSettings = other.mSettings; mScreen = other.mScreen; mModel = other.mModel; diff --git a/utils/themeeditor/graphics/rbrenderinfo.h b/utils/themeeditor/graphics/rbrenderinfo.h index c99de7beaa..c80cb00a9d 100644 --- a/utils/themeeditor/graphics/rbrenderinfo.h +++ b/utils/themeeditor/graphics/rbrenderinfo.h @@ -22,6 +22,8 @@ #ifndef RBRENDERINFO_H #define RBRENDERINFO_H +#include <QMap> + class RBScreen; class ProjectModel; class ParseTreeModel; @@ -29,19 +31,21 @@ class ParseTreeModel; class RBRenderInfo { public: - RBRenderInfo(ParseTreeModel* model, - ProjectModel* project, RBScreen* screen); + RBRenderInfo(ParseTreeModel* model, ProjectModel* project, + QMap<QString, QString>* settings, RBScreen* screen); RBRenderInfo(const RBRenderInfo& other); virtual ~RBRenderInfo(); const RBRenderInfo& operator=(const RBRenderInfo& other); ProjectModel* project() const{ return mProject; } + QMap<QString, QString>* settings() const{ return mSettings; } RBScreen* screen() const{ return mScreen; } ParseTreeModel* model() const{ return mModel; } private: ProjectModel* mProject; + QMap<QString, QString>* mSettings; RBScreen* mScreen; ParseTreeModel* mModel; }; diff --git a/utils/themeeditor/graphics/rbscreen.cpp b/utils/themeeditor/graphics/rbscreen.cpp index 8d3ef86ad0..065bea61cd 100644 --- a/utils/themeeditor/graphics/rbscreen.cpp +++ b/utils/themeeditor/graphics/rbscreen.cpp @@ -20,44 +20,42 @@ ****************************************************************************/ #include "rbscreen.h" +#include "rbviewport.h" #include <QPainter> #include <QFile> -RBScreen::RBScreen(ProjectModel* project, QGraphicsItem *parent) : +RBScreen::RBScreen(const RBRenderInfo& info, QGraphicsItem *parent) : QGraphicsItem(parent), backdrop(0), project(project) { - width = safeSetting(project, "#screenwidth", "300").toInt(); - height = safeSetting(project, "#screenheight", "200").toInt(); + width = info.settings()->value("#screenwidth", "300").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); - QString fg = safeSetting(project, "foreground color", "FFFFFF"); + QString fg = info.settings()->value("foreground color", "FFFFFF"); fgColor = stringToColor(fg, Qt::black); /* Loading backdrop if available */ - if(project) + QString base = info.settings()->value("themebase", ""); + QString backdropFile = info.settings()->value("backdrop", ""); + + if(QFile::exists(base + "/backdrops/" + backdropFile)) { - QString base = project->getSetting("themebase", ""); - QString backdropFile = project->getSetting("backdrop", ""); + backdrop = new QPixmap(base + "/backdrops/" + backdropFile); - if(QFile::exists(base + "/backdrops/" + backdropFile)) + /* If a backdrop has been found, use its width and height */ + if(!backdrop->isNull()) { - backdrop = new QPixmap(base + "/backdrops/" + backdropFile); - - /* If a backdrop has been found, use its width and height */ - if(!backdrop->isNull()) - { - width = backdrop->width(); - height = backdrop->height(); - } - else - { - delete backdrop; - backdrop = 0; - } + width = backdrop->width(); + height = backdrop->height(); + } + else + { + delete backdrop; + backdrop = 0; } } } @@ -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) { diff --git a/utils/themeeditor/graphics/rbscreen.h b/utils/themeeditor/graphics/rbscreen.h index 78bbcfd8b2..6a9da2fcda 100644 --- a/utils/themeeditor/graphics/rbscreen.h +++ b/utils/themeeditor/graphics/rbscreen.h @@ -25,12 +25,15 @@ #include <QGraphicsItem> #include "projectmodel.h" +#include "rbrenderinfo.h" + +class RBViewport; class RBScreen : public QGraphicsItem { public: - RBScreen(ProjectModel* project = 0, QGraphicsItem *parent = 0); + RBScreen(const RBRenderInfo& info, QGraphicsItem *parent = 0); virtual ~RBScreen(); QPainterPath shape() const; @@ -41,14 +44,11 @@ public: int getWidth() const{ return width; } int getHeight() const{ return height; } - static QString safeSetting(ProjectModel* project, QString key, - QString fallback) + void loadViewport(QString name, RBViewport* view) { - if(project) - return project->getSetting(key, fallback); - else - return fallback; + namedViewports.insert(name, view); } + void showViewport(QString name); static QColor stringToColor(QString str, QColor fallback); @@ -62,6 +62,8 @@ private: ProjectModel* project; + QMap<QString, RBViewport*> namedViewports; + }; #endif // RBSCREEN_H diff --git a/utils/themeeditor/graphics/rbviewport.cpp b/utils/themeeditor/graphics/rbviewport.cpp index 1f1f02ce55..9045016533 100644 --- a/utils/themeeditor/graphics/rbviewport.cpp +++ b/utils/themeeditor/graphics/rbviewport.cpp @@ -50,38 +50,57 @@ RBViewport::RBViewport(skin_element* node, const RBRenderInfo& info) } else { - int x, y, w, h; - /* Parsing one of the other types of viewport */ + int param; + QString ident; + int x,y,w,h; + /* Rendering one of the other types of viewport */ switch(node->tag->name[1]) { case '\0': - /* A normal viewport definition */ - 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); + customUI = false; displayed = true; + param = 0; break; 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; case 'i': /* Custom UI Viewport */ + 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, const QStyleOptionGraphicsItem *option, QWidget *widget) { + QColor color = customUI ? Qt::blue : Qt::red; if(displayed) - painter->fillRect(size, Qt::red); + painter->fillRect(size, color); } diff --git a/utils/themeeditor/graphics/rbviewport.h b/utils/themeeditor/graphics/rbviewport.h index 0ec377bc39..5d59ea4819 100644 --- a/utils/themeeditor/graphics/rbviewport.h +++ b/utils/themeeditor/graphics/rbviewport.h @@ -48,6 +48,7 @@ private: QColor foreground; bool displayed; + bool customUI; }; diff --git a/utils/themeeditor/gui/skindocument.h b/utils/themeeditor/gui/skindocument.h index 68bec43913..f6ceb73e92 100644 --- a/utils/themeeditor/gui/skindocument.h +++ b/utils/themeeditor/gui/skindocument.h @@ -70,7 +70,7 @@ public: TabType type() const{ return Skin; } - QGraphicsScene* scene(){ return model->render(project); } + QGraphicsScene* scene(){ return model->render(project, &fileName); } signals: diff --git a/utils/themeeditor/models/parsetreemodel.cpp b/utils/themeeditor/models/parsetreemodel.cpp index 41cecc4c20..4e94bfa0bf 100644 --- a/utils/themeeditor/models/parsetreemodel.cpp +++ b/utils/themeeditor/models/parsetreemodel.cpp @@ -29,6 +29,8 @@ #include <QObject> #include <QPixmap> +#include <QMap> +#include <QDir> ParseTreeModel::ParseTreeModel(const char* document, QObject* parent): QAbstractItemModel(parent) @@ -270,23 +272,40 @@ bool ParseTreeModel::setData(const QModelIndex &index, const QVariant &value, return true; } -QGraphicsScene* ParseTreeModel::render(ProjectModel* project) +QGraphicsScene* ParseTreeModel::render(ProjectModel* project, + const QString* file) { scene->clear(); /* Setting the background */ 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 */ - RBScreen* screen = new RBScreen(project); + screen = new RBScreen(info); scene->addItem(screen); - RBRenderInfo info(this, project, screen); + info = RBRenderInfo(this, project, &settings, screen); + /* Rendering the tree */ if(root) root->render(info); - return scene; } diff --git a/utils/themeeditor/models/parsetreemodel.h b/utils/themeeditor/models/parsetreemodel.h index 1f252a3f20..df64403bf5 100644 --- a/utils/themeeditor/models/parsetreemodel.h +++ b/utils/themeeditor/models/parsetreemodel.h @@ -60,7 +60,7 @@ public: Qt::ItemFlags flags(const QModelIndex &index) const; 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, QString fallback) diff --git a/utils/themeeditor/models/parsetreenode.cpp b/utils/themeeditor/models/parsetreenode.cpp index 97beca4c3d..a74dd2350b 100644 --- a/utils/themeeditor/models/parsetreenode.cpp +++ b/utils/themeeditor/models/parsetreenode.cpp @@ -25,6 +25,8 @@ #include "parsetreenode.h" #include "parsetreemodel.h" +#include <iostream> + int ParseTreeNode::openConditionals = 0; /* Root element constructor */ @@ -490,11 +492,13 @@ void ParseTreeNode::render(const RBRenderInfo& info) return; } - switch(element->type) + if(element->type != VIEWPORT) { - case VIEWPORT: - rendered = new RBViewport(element, info); - break; + std::cerr << QObject::tr("Error in parse tree").toStdString() + << std::endl; + return; } + + rendered = new RBViewport(element, info); } diff --git a/utils/themeeditor/models/projectmodel.h b/utils/themeeditor/models/projectmodel.h index 791c07ea2e..4cc531b88f 100644 --- a/utils/themeeditor/models/projectmodel.h +++ b/utils/themeeditor/models/projectmodel.h @@ -49,6 +49,8 @@ public: return settings.value(key, fallback); } + const QMap<QString, QString>& getSettings() const{ return settings; } + signals: public slots: |