From c5025c7c78b416f42f086138161d3126ad9482b9 Mon Sep 17 00:00:00 2001 From: Robert Bieber Date: Thu, 5 Aug 2010 19:05:36 +0000 Subject: [PATCH] Theme Editor: Made progress bars fully movable/savable from the preview panel git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27726 a1c6a512-1295-4272-9138-f99709370657 --- utils/themeeditor/graphics/rbprogressbar.cpp | 26 ++++++++++++++------ utils/themeeditor/graphics/rbprogressbar.h | 7 +++++- utils/themeeditor/models/parsetreenode.cpp | 24 ++++++++++++++---- utils/themeeditor/models/parsetreenode.h | 2 ++ 4 files changed, 46 insertions(+), 13 deletions(-) diff --git a/utils/themeeditor/graphics/rbprogressbar.cpp b/utils/themeeditor/graphics/rbprogressbar.cpp index 76cfe5601b..15515f8a18 100644 --- a/utils/themeeditor/graphics/rbprogressbar.cpp +++ b/utils/themeeditor/graphics/rbprogressbar.cpp @@ -21,14 +21,17 @@ #include +#include "parsetreenode.h" #include "rbprogressbar.h" #include "projectmodel.h" RBProgressBar::RBProgressBar(RBViewport *parent, const RBRenderInfo &info, - int paramCount, skin_tag_parameter *params, - bool pv) - :RBMovable(parent) + ParseTreeNode* node, bool pv) + :RBMovable(parent), node(node) { + int paramCount = node->getElement()->params_count; + skin_tag_parameter* params = node->getElement()->params; + /* First we set everything to defaults */ bitmap = 0; color = parent->getFGColor(); @@ -70,7 +73,7 @@ RBProgressBar::RBProgressBar(RBViewport *parent, const RBRenderInfo &info, bitmap = 0; } } - + size = QRectF(0, 0, w, h); /* Finally, we scale the width according to the amount played */ int percent; @@ -89,7 +92,7 @@ RBProgressBar::RBProgressBar(RBViewport *parent, const RBRenderInfo &info, w = w * percent / 100; - size = QRectF(0, 0, w, h); + renderSize = QRectF(0, 0, w, h); setPos(x, y); parent->addTextOffset(h); } @@ -111,11 +114,11 @@ void RBProgressBar::paint(QPainter *painter, { if(bitmap && !bitmap->isNull()) { - painter->drawPixmap(size, *bitmap, size); + painter->drawPixmap(renderSize, *bitmap, renderSize); } else { - painter->fillRect(size, color); + painter->fillRect(renderSize, color); } RBMovable::paint(painter, option, widget); @@ -123,5 +126,14 @@ void RBProgressBar::paint(QPainter *painter, void RBProgressBar::saveGeometry() { + QPointF origin = pos(); + QRectF bounds = boundingRect(); + node->modParam(static_cast(origin.x()), 0); + node->modParam(static_cast(origin.y()), 1); + node->modParam(static_cast(bounds.width()), 2); + node->modParam(static_cast(bounds.height()), 3); + + if(!bitmap) + node->modParam(QVariant(), 4); } diff --git a/utils/themeeditor/graphics/rbprogressbar.h b/utils/themeeditor/graphics/rbprogressbar.h index 817285653a..782d08e4f9 100644 --- a/utils/themeeditor/graphics/rbprogressbar.h +++ b/utils/themeeditor/graphics/rbprogressbar.h @@ -31,11 +31,13 @@ #include "devicestate.h" #include "skin_parser.h" +class ParseTreeNode; + class RBProgressBar : public RBMovable { public: RBProgressBar(RBViewport* parent, const RBRenderInfo& info, - int paramCount, skin_tag_parameter* params, bool pv = 0); + ParseTreeNode* node, bool pv = 0); virtual ~RBProgressBar(); QRectF boundingRect() const; @@ -49,6 +51,9 @@ private: QPixmap* bitmap; QColor color; QRectF size; + QRectF renderSize; + + ParseTreeNode* node; }; diff --git a/utils/themeeditor/models/parsetreenode.cpp b/utils/themeeditor/models/parsetreenode.cpp index 4afd04ab9d..779d236012 100644 --- a/utils/themeeditor/models/parsetreenode.cpp +++ b/utils/themeeditor/models/parsetreenode.cpp @@ -682,16 +682,14 @@ bool ParseTreeNode::execTag(const RBRenderInfo& info, RBViewport* viewport) { case 'b': /* %pb */ - new RBProgressBar(viewport, info, element->params_count, - element->params); + new RBProgressBar(viewport, info, this); return true; case 'v': /* %pv */ if(element->params_count > 0) { - new RBProgressBar(viewport, info, element->params_count, - element->params, true); + new RBProgressBar(viewport, info, this, true); return true; } else @@ -1075,8 +1073,24 @@ void ParseTreeNode::modParam(QVariant value, int index) { if(element) { - if(index < 0 || index >= children.count()) + if(index < 0) return; + while(index >= children.count()) + { + /* Padding children with defaults until we make the necessary + * parameter available + */ + skin_tag_parameter* newParam = new skin_tag_parameter; + newParam->type = skin_tag_parameter::DEFAULT; + /* We'll need to manually delete the extra parameters in the + * destructor + */ + extraParams.append(children.count()); + + children.append(new ParseTreeNode(newParam, this, model)); + element->params_count++; + } + children[index]->modParam(value); } else if(param) diff --git a/utils/themeeditor/models/parsetreenode.h b/utils/themeeditor/models/parsetreenode.h index 106907799e..af998faf11 100644 --- a/utils/themeeditor/models/parsetreenode.h +++ b/utils/themeeditor/models/parsetreenode.h @@ -88,6 +88,8 @@ private: ParseTreeModel* model; + QList extraParams; + }; #endif // PARSETREENODE_H