Robert Bieber | 9742704 | 2010-07-02 00:20:36 +0000 | [diff] [blame] | 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 | |
Robert Bieber | c5025c7 | 2010-08-05 19:05:36 +0000 | [diff] [blame] | 24 | #include "parsetreenode.h" |
Robert Bieber | 9742704 | 2010-07-02 00:20:36 +0000 | [diff] [blame] | 25 | #include "rbprogressbar.h" |
| 26 | #include "projectmodel.h" |
| 27 | |
| 28 | RBProgressBar::RBProgressBar(RBViewport *parent, const RBRenderInfo &info, |
Robert Bieber | c5025c7 | 2010-08-05 19:05:36 +0000 | [diff] [blame] | 29 | ParseTreeNode* node, bool pv) |
| 30 | :RBMovable(parent), node(node) |
Robert Bieber | 9742704 | 2010-07-02 00:20:36 +0000 | [diff] [blame] | 31 | { |
Robert Bieber | c5025c7 | 2010-08-05 19:05:36 +0000 | [diff] [blame] | 32 | int paramCount = node->getElement()->params_count; |
| 33 | skin_tag_parameter* params = node->getElement()->params; |
| 34 | |
Robert Bieber | 9742704 | 2010-07-02 00:20:36 +0000 | [diff] [blame] | 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 | { |
Robert Bieber | 15488a0 | 2010-07-15 06:24:11 +0000 | [diff] [blame] | 47 | x = params[0].data.number; |
Robert Bieber | 9742704 | 2010-07-02 00:20:36 +0000 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | if(paramCount > 1 && params[1].type != skin_tag_parameter::DEFAULT) |
| 51 | { |
Robert Bieber | 15488a0 | 2010-07-15 06:24:11 +0000 | [diff] [blame] | 52 | y = params[1].data.number; |
Robert Bieber | 9742704 | 2010-07-02 00:20:36 +0000 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | if(paramCount > 2 && params[2].type != skin_tag_parameter::DEFAULT) |
| 56 | { |
Robert Bieber | 15488a0 | 2010-07-15 06:24:11 +0000 | [diff] [blame] | 57 | w = params[2].data.number; |
Robert Bieber | 9742704 | 2010-07-02 00:20:36 +0000 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | if(paramCount > 3 && params[3].type != skin_tag_parameter::DEFAULT) |
| 61 | { |
Robert Bieber | 15488a0 | 2010-07-15 06:24:11 +0000 | [diff] [blame] | 62 | h = params[3].data.number; |
Robert Bieber | 9742704 | 2010-07-02 00:20:36 +0000 | [diff] [blame] | 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 | } |
Robert Bieber | c5025c7 | 2010-08-05 19:05:36 +0000 | [diff] [blame] | 76 | size = QRectF(0, 0, w, h); |
Robert Bieber | 9742704 | 2010-07-02 00:20:36 +0000 | [diff] [blame] | 77 | |
| 78 | /* Finally, we scale the width according to the amount played */ |
Robert Bieber | 64af2b3 | 2010-07-12 06:07:50 +0000 | [diff] [blame] | 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 | |
Robert Bieber | 9742704 | 2010-07-02 00:20:36 +0000 | [diff] [blame] | 93 | w = w * percent / 100; |
| 94 | |
Robert Bieber | c5025c7 | 2010-08-05 19:05:36 +0000 | [diff] [blame] | 95 | renderSize = QRectF(0, 0, w, h); |
Robert Bieber | 9742704 | 2010-07-02 00:20:36 +0000 | [diff] [blame] | 96 | setPos(x, y); |
| 97 | parent->addTextOffset(h); |
| 98 | } |
| 99 | |
| 100 | RBProgressBar::~RBProgressBar() |
| 101 | { |
| 102 | if(bitmap) |
| 103 | delete bitmap; |
| 104 | } |
| 105 | |
Robert Bieber | 9742704 | 2010-07-02 00:20:36 +0000 | [diff] [blame] | 106 | void RBProgressBar::paint(QPainter *painter, |
| 107 | const QStyleOptionGraphicsItem *option, |
| 108 | QWidget *widget) |
| 109 | { |
Robert Bieber | 92882f2 | 2010-08-06 07:53:19 +0000 | [diff] [blame] | 110 | renderSize.setHeight(size.height()); |
| 111 | |
Robert Bieber | 9742704 | 2010-07-02 00:20:36 +0000 | [diff] [blame] | 112 | if(bitmap && !bitmap->isNull()) |
| 113 | { |
Robert Bieber | c5025c7 | 2010-08-05 19:05:36 +0000 | [diff] [blame] | 114 | painter->drawPixmap(renderSize, *bitmap, renderSize); |
Robert Bieber | 9742704 | 2010-07-02 00:20:36 +0000 | [diff] [blame] | 115 | } |
| 116 | else |
| 117 | { |
Robert Bieber | c5025c7 | 2010-08-05 19:05:36 +0000 | [diff] [blame] | 118 | painter->fillRect(renderSize, color); |
Robert Bieber | 9742704 | 2010-07-02 00:20:36 +0000 | [diff] [blame] | 119 | } |
Robert Bieber | f657e49 | 2010-08-05 08:49:34 +0000 | [diff] [blame] | 120 | |
| 121 | RBMovable::paint(painter, option, widget); |
| 122 | } |
| 123 | |
| 124 | void RBProgressBar::saveGeometry() |
| 125 | { |
Robert Bieber | c5025c7 | 2010-08-05 19:05:36 +0000 | [diff] [blame] | 126 | QPointF origin = pos(); |
| 127 | QRectF bounds = boundingRect(); |
Robert Bieber | f657e49 | 2010-08-05 08:49:34 +0000 | [diff] [blame] | 128 | |
Robert Bieber | c5025c7 | 2010-08-05 19:05:36 +0000 | [diff] [blame] | 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); |
Robert Bieber | 9742704 | 2010-07-02 00:20:36 +0000 | [diff] [blame] | 136 | } |