update Chinese(Simplified) translation
[maemo-rb.git] / utils / themeeditor / graphics / rbprogressbar.cpp
blob678f3dd68bfa102668ecbe4e15ac67c37dc4ec28
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2010 Robert Bieber
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #include <QPainter>
24 #include "parsetreenode.h"
25 #include "rbprogressbar.h"
26 #include "projectmodel.h"
28 RBProgressBar::RBProgressBar(RBViewport *parent, const RBRenderInfo &info,
29 ParseTreeNode* node, bool pv)
30 :RBMovable(parent), node(node)
32 int paramCount = node->getElement()->params_count;
33 skin_tag_parameter* params = node->getElement()->params;
35 /* First we set everything to defaults */
36 bitmap = 0;
37 color = parent->getFGColor();
38 int x = 0;
39 int y = parent->getTextOffset();
40 int w = parent->boundingRect().width();
41 int h = 6;
43 /* Now we change defaults if the parameters are there */
45 if(paramCount > 0 && params[0].type != skin_tag_parameter::DEFAULT)
47 x = params[0].data.number;
50 if(paramCount > 1 && params[1].type != skin_tag_parameter::DEFAULT)
52 y = params[1].data.number;
55 if(paramCount > 2 && params[2].type != skin_tag_parameter::DEFAULT)
57 w = params[2].data.number;
60 if(paramCount > 3 && params[3].type != skin_tag_parameter::DEFAULT)
62 h = params[3].data.number;
65 if(paramCount > 4 && params[4].type != skin_tag_parameter::DEFAULT)
67 QString imPath(params[4].data.text);
68 imPath = info.settings()->value("imagepath", "") + "/" + imPath;
69 bitmap = new QPixmap(imPath);
70 if(bitmap->isNull())
72 delete bitmap;
73 bitmap = 0;
76 size = QRectF(0, 0, w, h);
78 /* Finally, we scale the width according to the amount played */
79 int percent;
80 if(pv)
82 percent = (info.device()->data("pv").toInt() + 50) * 100 / 56;
84 else
86 percent = info.device()->data("px").toInt();
88 if(percent > 100)
89 percent = 100;
90 if(percent < 0)
91 percent = 0;
93 w = w * percent / 100;
95 renderSize = QRectF(0, 0, w, h);
96 setPos(x, y);
97 parent->addTextOffset(h);
100 RBProgressBar::~RBProgressBar()
102 if(bitmap)
103 delete bitmap;
106 void RBProgressBar::paint(QPainter *painter,
107 const QStyleOptionGraphicsItem *option,
108 QWidget *widget)
110 renderSize.setHeight(size.height());
112 if(bitmap && !bitmap->isNull())
114 painter->drawPixmap(renderSize, *bitmap, renderSize);
116 else
118 painter->fillRect(renderSize, color);
121 RBMovable::paint(painter, option, widget);
124 void RBProgressBar::saveGeometry()
126 QPointF origin = pos();
127 QRectF bounds = boundingRect();
129 node->modParam(static_cast<int>(origin.x()), 0);
130 node->modParam(static_cast<int>(origin.y()), 1);
131 node->modParam(static_cast<int>(bounds.width()), 2);
132 node->modParam(static_cast<int>(bounds.height()), 3);
134 if(!bitmap)
135 node->modParam(QVariant(), 4);