c5b88b3afdd95090ab8b60e66a0d495fb52ff12a
[kugel-rb.git] / utils / themeeditor / graphics / rbviewport.cpp
blobc5b88b3afdd95090ab8b60e66a0d495fb52ff12a
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());
40 customUI = false;
42 if(info.model()->rowCount(QModelIndex()) > 1)
44 /* If there is more than one viewport in the document */
45 setVisible(false);
47 else
49 setVisible(true);
52 else
54 int param;
55 QString ident;
56 int x,y,w,h;
57 /* Rendering one of the other types of viewport */
58 switch(node->tag->name[1])
60 case '\0':
61 customUI = false;
62 param = 0;
63 break;
65 case 'l':
66 /* A preloaded viewport definition */
67 ident = node->params[0].data.text;
68 customUI = false;
69 hide();
70 info.screen()->loadViewport(ident, this);
71 param = 1;
72 break;
74 case 'i':
75 /* Custom UI Viewport */
76 customUI = true;
77 param = 1;
78 if(node->params[0].type == skin_tag_parameter::DEFAULT)
80 setVisible(true);
82 else
84 hide();
85 info.screen()->loadViewport(ident, this);
87 break;
89 /* Now we grab the info common to all viewports */
90 x = node->params[param++].data.numeric;
91 y = node->params[param++].data.numeric;
93 if(node->params[param].type == skin_tag_parameter::DEFAULT)
94 w = info.screen()->getWidth() - x;
95 else
96 w = node->params[param].data.numeric;
98 if(node->params[++param].type == skin_tag_parameter::DEFAULT)
99 h = info.screen()->getHeight() - y;
100 else
101 h = node->params[param].data.numeric;
103 setPos(x, y);
104 size = QRectF(0, 0, w, h);
108 RBViewport::~RBViewport()
112 QPainterPath RBViewport::shape() const
114 QPainterPath retval;
115 retval.addRect(size);
116 return retval;
119 QRectF RBViewport::boundingRect() const
121 return size;
124 void RBViewport::paint(QPainter *painter,
125 const QStyleOptionGraphicsItem *option, QWidget *widget)
127 painter->setBrush(Qt::NoBrush);
128 painter->setPen(customUI ? Qt::blue : Qt::red);
129 painter->drawRect(size);
132 /* Called at the end of a logical line */
133 void RBViewport::newline()