1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
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 ****************************************************************************/
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 */
37 color
= parent
->getFGColor();
39 int y
= parent
->getTextOffset();
40 int w
= parent
->boundingRect().width();
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
);
76 size
= QRectF(0, 0, w
, h
);
78 /* Finally, we scale the width according to the amount played */
82 percent
= (info
.device()->data("pv").toInt() + 50) * 100 / 56;
86 percent
= info
.device()->data("px").toInt();
93 w
= w
* percent
/ 100;
95 renderSize
= QRectF(0, 0, w
, h
);
97 parent
->addTextOffset(h
);
100 RBProgressBar::~RBProgressBar()
106 void RBProgressBar::paint(QPainter
*painter
,
107 const QStyleOptionGraphicsItem
*option
,
110 renderSize
.setHeight(size
.height());
112 if(bitmap
&& !bitmap
->isNull())
114 painter
->drawPixmap(renderSize
, *bitmap
, renderSize
);
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);
135 node
->modParam(QVariant(), 4);