9d949670ee8038e31c2c3bfef3c2ee653f78c5d1
[kugel-rb.git] / utils / themeeditor / graphics / rbviewport.cpp
blob9d949670ee8038e31c2c3bfef3c2ee653f78c5d1
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>
23 #include <QPainterPath>
25 #include "rbviewport.h"
26 #include "rbscreen.h"
27 #include "rbrenderinfo.h"
28 #include "parsetreemodel.h"
29 #include "tag_table.h"
30 #include "skin_parser.h"
32 RBViewport::RBViewport(skin_element* node, const RBRenderInfo& info)
33 : QGraphicsItem(info.screen())
35 if(!node->tag)
37 /* Default viewport takes up the entire screen */
38 size = QRectF(0, 0, info.screen()->getWidth(),
39 info.screen()->getHeight());
41 if(info.model()->rowCount(QModelIndex()) > 1)
43 /* If there is more than one viewport in the document */
44 setVisible(false);
46 else
48 setVisible(true);
51 else
53 int param;
54 QString ident;
55 int x,y,w,h;
56 /* Rendering one of the other types of viewport */
57 switch(node->tag->name[1])
59 case '\0':
60 customUI = false;
61 param = 0;
62 break;
64 case 'l':
65 /* A preloaded viewport definition */
66 ident = node->params[0].data.text;
67 customUI = false;
68 hide();
69 info.screen()->loadViewport(ident, this);
70 param = 1;
71 break;
73 case 'i':
74 /* Custom UI Viewport */
75 customUI = true;
76 param = 1;
77 if(node->params[0].type == skin_tag_parameter::DEFAULT)
79 setVisible(true);
81 else
83 hide();
84 info.screen()->loadViewport(ident, this);
86 break;
88 /* Now we grab the info common to all viewports */
89 x = node->params[param++].data.numeric;
90 y = node->params[param++].data.numeric;
92 if(node->params[param].type == skin_tag_parameter::DEFAULT)
93 w = info.screen()->getWidth() - x;
94 else
95 w = node->params[param].data.numeric;
97 if(node->params[++param].type == skin_tag_parameter::DEFAULT)
98 h = info.screen()->getHeight() - y;
99 else
100 h = node->params[param].data.numeric;
102 size = QRectF(x, y, w, h);
106 RBViewport::~RBViewport()
110 QPainterPath RBViewport::shape() const
112 QPainterPath retval;
113 retval.addRect(size);
114 return retval;
117 QRectF RBViewport::boundingRect() const
119 return size;
122 void RBViewport::paint(QPainter *painter,
123 const QStyleOptionGraphicsItem *option, QWidget *widget)
125 QColor color = customUI ? Qt::blue : Qt::red;
126 painter->fillRect(size, color);
129 /* Called at the end of a logical line */
130 void RBViewport::newline()