A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita
audio
rust
zig
deno
mpris
rockbox
mpd
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2010 Robert Bieber
11 *
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.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#include <QPainter>
23
24#include "parsetreenode.h"
25#include "rbprogressbar.h"
26#include "projectmodel.h"
27
28RBProgressBar::RBProgressBar(RBViewport *parent, const RBRenderInfo &info,
29 ParseTreeNode* node, bool pv)
30 :RBMovable(parent), node(node)
31{
32 int paramCount = node->getElement()->params_count;
33 skin_tag_parameter* params = node->getElement()->params;
34
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;
42
43 /* Now we change defaults if the parameters are there */
44
45 if(paramCount > 0 && params[0].type != skin_tag_parameter::DEFAULT)
46 {
47 x = params[0].data.number;
48 }
49
50 if(paramCount > 1 && params[1].type != skin_tag_parameter::DEFAULT)
51 {
52 y = params[1].data.number;
53 }
54
55 if(paramCount > 2 && params[2].type != skin_tag_parameter::DEFAULT)
56 {
57 w = params[2].data.number;
58 }
59
60 if(paramCount > 3 && params[3].type != skin_tag_parameter::DEFAULT)
61 {
62 h = params[3].data.number;
63 }
64
65 if(paramCount > 4 && params[4].type != skin_tag_parameter::DEFAULT)
66 {
67 QString imPath(params[4].data.text);
68 imPath = info.settings()->value("imagepath", "") + "/" + imPath;
69 bitmap = new QPixmap(imPath);
70 if(bitmap->isNull())
71 {
72 delete bitmap;
73 bitmap = 0;
74 }
75 }
76 size = QRectF(0, 0, w, h);
77
78 /* Finally, we scale the width according to the amount played */
79 int percent;
80 if(pv)
81 {
82 percent = (info.device()->data("pv").toInt() + 50) * 100 / 56;
83 }
84 else
85 {
86 percent = info.device()->data("px").toInt();
87 }
88 if(percent > 100)
89 percent = 100;
90 if(percent < 0)
91 percent = 0;
92
93 w = w * percent / 100;
94
95 renderSize = QRectF(0, 0, w, h);
96 setPos(x, y);
97 parent->addTextOffset(h);
98}
99
100RBProgressBar::~RBProgressBar()
101{
102 if(bitmap)
103 delete bitmap;
104}
105
106void RBProgressBar::paint(QPainter *painter,
107 const QStyleOptionGraphicsItem *option,
108 QWidget *widget)
109{
110 renderSize.setHeight(size.height());
111
112 if(bitmap && !bitmap->isNull())
113 {
114 painter->drawPixmap(renderSize, *bitmap, renderSize);
115 }
116 else
117 {
118 painter->fillRect(renderSize, color);
119 }
120
121 RBMovable::paint(painter, option, widget);
122}
123
124void RBProgressBar::saveGeometry()
125{
126 QPointF origin = pos();
127 QRectF bounds = boundingRect();
128
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);
133
134 if(!bitmap)
135 node->modParam(QVariant(), 4);
136}