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 "rbviewport.h"
28 RBScreen::RBScreen(const RBRenderInfo
& info
, QGraphicsItem
*parent
) :
29 QGraphicsItem(parent
), backdrop(0), project(project
)
32 width
= info
.settings()->value("#screenwidth", "300").toInt();
33 height
= info
.settings()->value("#screenheight", "200").toInt();
35 QString bg
= info
.settings()->value("background color", "000000");
36 bgColor
= stringToColor(bg
, Qt::white
);
38 QString fg
= info
.settings()->value("foreground color", "FFFFFF");
39 fgColor
= stringToColor(fg
, Qt::black
);
41 settings
= info
.settings();
43 /* Loading backdrop if available */
44 themeBase
= info
.settings()->value("themebase", "");
45 QString backdropFile
= info
.settings()->value("backdrop", "");
46 backdropFile
.replace("/.rockbox/backdrops/", "");
48 if(QFile::exists(themeBase
+ "/backdrops/" + backdropFile
))
50 backdrop
= new QPixmap(themeBase
+ "/backdrops/" + backdropFile
);
52 /* If a backdrop has been found, use its width and height */
53 if(!backdrop
->isNull())
55 width
= backdrop
->width();
56 height
= backdrop
->height();
72 QPainterPath
RBScreen::shape() const
75 retval
.addRect(0, 0, width
, height
);
79 QRectF
RBScreen::boundingRect() const
81 return QRectF(0, 0, width
, height
);
84 void RBScreen::paint(QPainter
*painter
, const QStyleOptionGraphicsItem
*option
,
89 painter
->drawPixmap(0, 0, width
, height
, *backdrop
);
93 painter
->fillRect(0, 0, width
, height
, bgColor
);
97 void RBScreen::showViewport(QString name
)
99 if(namedViewports
.value(name
, 0) == 0)
102 namedViewports
.value(name
)->show();
106 void RBScreen::setBackdrop(QString filename
)
112 filename
= settings
->value("imagepath", "") + "/" + filename
;
114 if(QFile::exists(filename
))
115 backdrop
= new QPixmap(filename
);
120 void RBScreen::makeCustomUI(QString id
)
122 if(namedViewports
.value(id
, 0) != 0)
124 QMap
<QString
, RBViewport
*>::iterator i
;
125 for(i
= namedViewports
.begin(); i
!= namedViewports
.end(); i
++)
126 (*i
)->clearCustomUI();
127 namedViewports
.value(id
)->makeCustomUI();
128 namedViewports
.value(id
)->show();
132 QColor
RBScreen::stringToColor(QString str
, QColor fallback
)
137 if(str
.length() == 6)
139 for(int i
= 0; i
< 6; i
++)
141 char c
= str
[i
].toAscii();
142 if(!((c
>= 'a' && c
<= 'f') || (c
>= 'A' && c
<= 'F') ||
150 retval
= QColor("#" + str
);
154 else if(str
.length() == 1)
156 if(isdigit(str
[0].toAscii()) && str
[0].toAscii() <= '3')
158 int shade
= 255 * (str
[0].toAscii() - '0') / 3;
159 retval
= QColor(shade
, shade
, shade
);