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 ****************************************************************************/
23 #include <QPainterPath>
25 #include "rbviewport.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()), font(info
.screen()->getFont(0)),
34 foreground(info
.screen()->foreground()),
35 background(info
.screen()->background()), textOffset(0,0),
40 /* Default viewport takes up the entire screen */
41 size
= QRectF(0, 0, info
.screen()->getWidth(),
42 info
.screen()->getHeight());
45 if(info
.model()->rowCount(QModelIndex()) > 1)
47 /* If there is more than one viewport in the document */
60 /* Rendering one of the other types of viewport */
61 switch(node
->tag
->name
[1])
69 /* A preloaded viewport definition */
70 ident
= node
->params
[0].data
.text
;
73 info
.screen()->loadViewport(ident
, this);
78 /* Custom UI Viewport */
81 if(node
->params
[0].type
== skin_tag_parameter::DEFAULT
)
88 info
.screen()->loadViewport(ident
, this);
92 /* Now we grab the info common to all viewports */
93 x
= node
->params
[param
++].data
.numeric
;
94 y
= node
->params
[param
++].data
.numeric
;
96 if(node
->params
[param
].type
== skin_tag_parameter::DEFAULT
)
97 w
= info
.screen()->getWidth() - x
;
99 w
= node
->params
[param
].data
.numeric
;
101 if(node
->params
[++param
].type
== skin_tag_parameter::DEFAULT
)
102 h
= info
.screen()->getHeight() - y
;
104 h
= node
->params
[param
].data
.numeric
;
107 size
= QRectF(0, 0, w
, h
);
112 RBViewport::~RBViewport()
116 QPainterPath
RBViewport::shape() const
119 retval
.addRect(size
);
123 QRectF
RBViewport::boundingRect() const
128 void RBViewport::paint(QPainter
*painter
,
129 const QStyleOptionGraphicsItem
*option
, QWidget
*widget
)
131 if(!screen
->hasBackdrop() && background
!= screen
->background())
133 painter
->fillRect(size
, QBrush(background
));
136 painter
->setBrush(Qt::NoBrush
);
137 painter
->setPen(customUI
? Qt::blue
: Qt::red
);
138 painter
->drawRect(size
);
141 void RBViewport::newLine()
143 if(textOffset
.x() > 0)
145 textOffset
.setY(textOffset
.y() + lineHeight
);
150 void RBViewport::write(QString text
)
152 QGraphicsItem
* graphic
= font
->renderText(text
, foreground
, this);
153 graphic
->setPos(textOffset
.x(), textOffset
.y());
154 textOffset
.setX(textOffset
.x() + graphic
->boundingRect().width());
155 lineHeight
= font
->lineHeight();