diff options
Diffstat (limited to 'utils/themeeditor')
-rw-r--r-- | utils/themeeditor/graphics/rbscreen.cpp | 137 | ||||
-rw-r--r-- | utils/themeeditor/graphics/rbscreen.h | 63 | ||||
-rw-r--r-- | utils/themeeditor/models/parsetreemodel.cpp | 12 | ||||
-rw-r--r-- | utils/themeeditor/resources.qrc | 3 | ||||
-rw-r--r-- | utils/themeeditor/resources/render/scenebg.png | bin | 0 -> 213 bytes | |||
-rw-r--r-- | utils/themeeditor/themeeditor.pro | 22 |
6 files changed, 223 insertions, 14 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 | |||
27 | RBScreen::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 | |||
65 | RBScreen::~RBScreen() | ||
66 | { | ||
67 | if(backdrop) | ||
68 | delete backdrop; | ||
69 | } | ||
70 | |||
71 | QPainterPath RBScreen::shape() const | ||
72 | { | ||
73 | QPainterPath retval; | ||
74 | retval.addRect(0, 0, width, height); | ||
75 | return retval; | ||
76 | } | ||
77 | |||
78 | QRectF RBScreen::boundingRect() const | ||
79 | { | ||
80 | return QRectF(0, 0, width, height); | ||
81 | } | ||
82 | |||
83 | void 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 | |||
96 | QColor 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 | } | ||
diff --git a/utils/themeeditor/graphics/rbscreen.h b/utils/themeeditor/graphics/rbscreen.h new file mode 100644 index 0000000000..f244089b2d --- /dev/null +++ b/utils/themeeditor/graphics/rbscreen.h | |||
@@ -0,0 +1,63 @@ | |||
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 | #ifndef RBSCREEN_H | ||
23 | #define RBSCREEN_H | ||
24 | |||
25 | #include <QGraphicsItem> | ||
26 | |||
27 | #include "projectmodel.h" | ||
28 | |||
29 | class RBScreen : public QGraphicsItem | ||
30 | { | ||
31 | |||
32 | public: | ||
33 | RBScreen(ProjectModel* project = 0, QGraphicsItem *parent = 0); | ||
34 | virtual ~RBScreen(); | ||
35 | |||
36 | QPainterPath shape() const; | ||
37 | QRectF boundingRect() const; | ||
38 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, | ||
39 | QWidget *widget); | ||
40 | |||
41 | static QString safeSetting(ProjectModel* project, QString key, | ||
42 | QString fallback) | ||
43 | { | ||
44 | if(project) | ||
45 | return project->getSetting(key, fallback); | ||
46 | else | ||
47 | return fallback; | ||
48 | } | ||
49 | |||
50 | static QColor stringToColor(QString str, QColor fallback); | ||
51 | |||
52 | private: | ||
53 | int width; | ||
54 | int height; | ||
55 | QColor bgColor; | ||
56 | QColor fgColor; | ||
57 | QPixmap* backdrop; | ||
58 | |||
59 | ProjectModel* project; | ||
60 | |||
61 | }; | ||
62 | |||
63 | #endif // RBSCREEN_H | ||
diff --git a/utils/themeeditor/models/parsetreemodel.cpp b/utils/themeeditor/models/parsetreemodel.cpp index 0b80416d3a..762443f4a5 100644 --- a/utils/themeeditor/models/parsetreemodel.cpp +++ b/utils/themeeditor/models/parsetreemodel.cpp | |||
@@ -22,10 +22,12 @@ | |||
22 | 22 | ||
23 | #include "parsetreemodel.h" | 23 | #include "parsetreemodel.h" |
24 | #include "symbols.h" | 24 | #include "symbols.h" |
25 | #include "rbscreen.h" | ||
25 | 26 | ||
26 | #include <cstdlib> | 27 | #include <cstdlib> |
27 | 28 | ||
28 | #include <QObject> | 29 | #include <QObject> |
30 | #include <QPixmap> | ||
29 | 31 | ||
30 | ParseTreeModel::ParseTreeModel(const char* document, QObject* parent): | 32 | ParseTreeModel::ParseTreeModel(const char* document, QObject* parent): |
31 | QAbstractItemModel(parent) | 33 | QAbstractItemModel(parent) |
@@ -271,10 +273,12 @@ QGraphicsScene* ParseTreeModel::render(ProjectModel* project) | |||
271 | { | 273 | { |
272 | scene->clear(); | 274 | scene->clear(); |
273 | 275 | ||
274 | /* First we set the screen size */ | 276 | /* Setting the background */ |
275 | int screenWidth = safeSetting(project, "#screenwidth", "300").toInt(); | 277 | scene->setBackgroundBrush(QBrush(QPixmap(":/render/scenebg.png"))); |
276 | int screenHeight = safeSetting(project, "#screenheight", "200").toInt(); | 278 | |
277 | scene->addRect(0, 0, screenWidth, screenHeight); | 279 | /* Adding the screen */ |
280 | RBScreen* screen = new RBScreen(project); | ||
281 | scene->addItem(screen); | ||
278 | 282 | ||
279 | return scene; | 283 | return scene; |
280 | } | 284 | } |
diff --git a/utils/themeeditor/resources.qrc b/utils/themeeditor/resources.qrc index bba483f210..6815ccf8ea 100644 --- a/utils/themeeditor/resources.qrc +++ b/utils/themeeditor/resources.qrc | |||
@@ -6,4 +6,7 @@ | |||
6 | <file>resources/document-save.png</file> | 6 | <file>resources/document-save.png</file> |
7 | <file alias="configkeys">resources/configkeys</file> | 7 | <file alias="configkeys">resources/configkeys</file> |
8 | </qresource> | 8 | </qresource> |
9 | <qresource prefix="/render"> | ||
10 | <file alias="scenebg.png">resources/render/scenebg.png</file> | ||
11 | </qresource> | ||
9 | </RCC> | 12 | </RCC> |
diff --git a/utils/themeeditor/resources/render/scenebg.png b/utils/themeeditor/resources/render/scenebg.png new file mode 100644 index 0000000000..79b2ed9f7c --- /dev/null +++ b/utils/themeeditor/resources/render/scenebg.png | |||
Binary files differ | |||
diff --git a/utils/themeeditor/themeeditor.pro b/utils/themeeditor/themeeditor.pro index bf48bda7f2..157433ef55 100644 --- a/utils/themeeditor/themeeditor.pro +++ b/utils/themeeditor/themeeditor.pro | |||
@@ -4,26 +4,26 @@ OBJECTS_DIR = $$MYBUILDDIR/o | |||
4 | UI_DIR = $$MYBUILDDIR/ui | 4 | UI_DIR = $$MYBUILDDIR/ui |
5 | MOC_DIR = $$MYBUILDDIR/moc | 5 | MOC_DIR = $$MYBUILDDIR/moc |
6 | RCC_DIR = $$MYBUILDDIR/rcc | 6 | RCC_DIR = $$MYBUILDDIR/rcc |
7 | |||
8 | RBBASE_DIR = $$_PRO_FILE_PWD_ | 7 | RBBASE_DIR = $$_PRO_FILE_PWD_ |
9 | RBBASE_DIR = $$replace(RBBASE_DIR,/utils/themeeditor,) | 8 | RBBASE_DIR = $$replace(RBBASE_DIR,/utils/themeeditor,) |
10 | 9 | ||
11 | #Include directories | 10 | # Include directories |
12 | INCLUDEPATH += gui | 11 | INCLUDEPATH += gui |
13 | INCLUDEPATH += models | 12 | INCLUDEPATH += models |
14 | 13 | INCLUDEPATH += graphics | |
15 | 14 | ||
16 | # Stuff for the parse lib | 15 | # Stuff for the parse lib |
17 | libskin_parser.commands = @$(MAKE) \ | 16 | libskin_parser.commands = @$(MAKE) \ |
18 | BUILDDIR=$$OBJECTS_DIR -C $$RBBASE_DIR/lib/skin_parser CC=\"$$QMAKE_CC\" | 17 | BUILDDIR=$$OBJECTS_DIR \ |
18 | -C \ | ||
19 | $$RBBASE_DIR/lib/skin_parser \ | ||
20 | CC=\"$$QMAKE_CC\" | ||
19 | QMAKE_EXTRA_TARGETS += libskin_parser | 21 | QMAKE_EXTRA_TARGETS += libskin_parser |
20 | PRE_TARGETDEPS += libskin_parser | 22 | PRE_TARGETDEPS += libskin_parser |
21 | INCLUDEPATH += $$RBBASE_DIR/lib/skin_parser | 23 | INCLUDEPATH += $$RBBASE_DIR/lib/skin_parser |
22 | LIBS += -L$$OBJECTS_DIR -lskin_parser | 24 | LIBS += -L$$OBJECTS_DIR \ |
23 | 25 | -lskin_parser | |
24 | |||
25 | DEPENDPATH = $$INCLUDEPATH | 26 | DEPENDPATH = $$INCLUDEPATH |
26 | |||
27 | HEADERS += models/parsetreemodel.h \ | 27 | HEADERS += models/parsetreemodel.h \ |
28 | models/parsetreenode.h \ | 28 | models/parsetreenode.h \ |
29 | gui/editorwindow.h \ | 29 | gui/editorwindow.h \ |
@@ -34,7 +34,8 @@ HEADERS += models/parsetreemodel.h \ | |||
34 | models/projectmodel.h \ | 34 | models/projectmodel.h \ |
35 | gui/tabcontent.h \ | 35 | gui/tabcontent.h \ |
36 | gui/configdocument.h \ | 36 | gui/configdocument.h \ |
37 | gui/skinviewer.h | 37 | gui/skinviewer.h \ |
38 | graphics/rbscreen.h | ||
38 | SOURCES += main.cpp \ | 39 | SOURCES += main.cpp \ |
39 | models/parsetreemodel.cpp \ | 40 | models/parsetreemodel.cpp \ |
40 | models/parsetreenode.cpp \ | 41 | models/parsetreenode.cpp \ |
@@ -45,7 +46,8 @@ SOURCES += main.cpp \ | |||
45 | gui/codeeditor.cpp \ | 46 | gui/codeeditor.cpp \ |
46 | models/projectmodel.cpp \ | 47 | models/projectmodel.cpp \ |
47 | gui/configdocument.cpp \ | 48 | gui/configdocument.cpp \ |
48 | gui/skinviewer.cpp | 49 | gui/skinviewer.cpp \ |
50 | graphics/rbscreen.cpp | ||
49 | OTHER_FILES += README \ | 51 | OTHER_FILES += README \ |
50 | resources/windowicon.png \ | 52 | resources/windowicon.png \ |
51 | resources/appicon.xcf \ | 53 | resources/appicon.xcf \ |