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 ****************************************************************************/
27 RBScreen::RBScreen(ProjectModel
* project
, QGraphicsItem
*parent
) :
28 QGraphicsItem(parent
), backdrop(0), project(project
)
31 width
= safeSetting(project
, "#screenwidth", "300").toInt();
32 height
= safeSetting(project
, "#screenheight", "200").toInt();
34 QString bg
= safeSetting(project
, "background color", "FFFFFF");
35 bgColor
= stringToColor(bg
, Qt::white
);
37 QString fg
= safeSetting(project
, "foreground color", "FFFFFF");
38 fgColor
= stringToColor(fg
, Qt::black
);
40 /* Loading backdrop if available */
43 QString base
= project
->getSetting("themebase", "");
44 QString backdropFile
= project
->getSetting("backdrop", "");
46 if(QFile::exists(base
+ "/backdrops/" + backdropFile
))
48 backdrop
= new QPixmap(base
+ "/backdrops/" + backdropFile
);
50 /* If a backdrop has been found, use its width and height */
51 if(!backdrop
->isNull())
53 width
= backdrop
->width();
54 height
= backdrop
->height();
71 QPainterPath
RBScreen::shape() const
74 retval
.addRect(0, 0, width
, height
);
78 QRectF
RBScreen::boundingRect() const
80 return QRectF(0, 0, width
, height
);
83 void RBScreen::paint(QPainter
*painter
, const QStyleOptionGraphicsItem
*option
,
88 painter
->drawPixmap(0, 0, width
, height
, *backdrop
);
92 painter
->fillRect(0, 0, width
, height
, bgColor
);
96 QColor
RBScreen::stringToColor(QString str
, QColor fallback
)
101 if(str
.length() == 6)
103 for(int i
= 0; i
< 6; i
++)
105 char c
= str
[i
].toAscii();
106 if(!((c
>= 'a' && c
<= 'f') || (c
>= 'A' && c
<= 'F') ||
114 retval
= QColor("#" + str
);
118 else if(str
.length() == 1)
120 if(isdigit(str
[0].toAscii()) && str
[0].toAscii() <= '3')
122 int shade
= 255 * (str
[0].toAscii() - '0') / 3;
123 retval
= QColor(shade
, shade
, shade
);