summaryrefslogtreecommitdiff
path: root/utils/themeeditor/graphics/rbscreen.cpp
diff options
context:
space:
mode:
authorRobert Bieber <robby@bieberphoto.com>2010-06-17 20:44:11 +0000
committerRobert Bieber <robby@bieberphoto.com>2010-06-17 20:44:11 +0000
commit02c377469a00ae0634b3269935ce5fa186e0ee58 (patch)
treebf60f59b02160e153171c4877699c4c54fea30cd /utils/themeeditor/graphics/rbscreen.cpp
parent60200755512e0b2c0758ac3697f06194e9809f40 (diff)
downloadrockbox-02c377469a00ae0634b3269935ce5fa186e0ee58.tar.gz
rockbox-02c377469a00ae0634b3269935ce5fa186e0ee58.zip
Theme Editor: Continuing work on rendering, skin preview will now show backdrop or background color depending on config file
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26900 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'utils/themeeditor/graphics/rbscreen.cpp')
-rw-r--r--utils/themeeditor/graphics/rbscreen.cpp137
1 files changed, 137 insertions, 0 deletions
diff --git a/utils/themeeditor/graphics/rbscreen.cpp b/utils/themeeditor/graphics/rbscreen.cpp
new file mode 100644
index 0000000000..865bde2cef
--- /dev/null
+++ b/utils/themeeditor/graphics/rbscreen.cpp
@@ -0,0 +1,137 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2010 Robert Bieber
11 *
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.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#include "rbscreen.h"
23
24#include <QPainter>
25#include <QFile>
26
27RBScreen::RBScreen(ProjectModel* project, QGraphicsItem *parent) :
28 QGraphicsItem(parent), project(project), backdrop(0)
29{
30
31 width = safeSetting(project, "#screenwidth", "300").toInt();
32 height = safeSetting(project, "#screenheight", "200").toInt();
33
34 QString bg = safeSetting(project, "background color", "FFFFFF");
35 bgColor = stringToColor(bg, Qt::white);
36
37 QString fg = safeSetting(project, "foreground color", "FFFFFF");
38 fgColor = stringToColor(fg, Qt::black);
39
40 /* Loading backdrop if available */
41 if(project)
42 {
43 QString base = project->getSetting("themebase", "");
44 QString backdropFile = project->getSetting("backdrop", "");
45
46 if(QFile::exists(base + "/backdrops/" + backdropFile))
47 {
48 backdrop = new QPixmap(base + "/backdrops/" + backdropFile);
49
50 /* If a backdrop has been found, use its width and height */
51 if(!backdrop->isNull())
52 {
53 width = backdrop->width();
54 height = backdrop->height();
55 }
56 else
57 {
58 delete backdrop;
59 backdrop = 0;
60 }
61 }
62 }
63}
64
65RBScreen::~RBScreen()
66{
67 if(backdrop)
68 delete backdrop;
69}
70
71QPainterPath RBScreen::shape() const
72{
73 QPainterPath retval;
74 retval.addRect(0, 0, width, height);
75 return retval;
76}
77
78QRectF RBScreen::boundingRect() const
79{
80 return QRectF(0, 0, width, height);
81}
82
83void RBScreen::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
84 QWidget *widget)
85{
86 if(backdrop)
87 {
88 painter->drawPixmap(0, 0, width, height, *backdrop);
89 }
90 else
91 {
92 painter->fillRect(0, 0, width, height, bgColor);
93 }
94}
95
96QColor RBScreen::stringToColor(QString str, QColor fallback)
97{
98
99 QColor retval;
100
101 if(str.length() == 6)
102 {
103 for(int i = 0; i < 6; i++)
104 {
105 char c = str[i].toAscii();
106 if(!((c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F') ||
107 isdigit(c)))
108 {
109 str = "";
110 break;
111 }
112 }
113 if(str != "")
114 retval = QColor("#" + str);
115 else
116 retval = fallback;
117 }
118 else if(str.length() == 1)
119 {
120 if(isdigit(str[0].toAscii()) && str[0].toAscii() <= '3')
121 {
122 int shade = 255 * (str[0].toAscii() - '0') / 3;
123 retval = QColor(shade, shade, shade);
124 }
125 else
126 {
127 retval = fallback;
128 }
129 }
130 else
131 {
132 retval = fallback;
133 }
134
135 return retval;
136
137}