summaryrefslogtreecommitdiff
path: root/utils/themeeditor
diff options
context:
space:
mode:
Diffstat (limited to 'utils/themeeditor')
-rw-r--r--utils/themeeditor/graphics/rbscreen.cpp137
-rw-r--r--utils/themeeditor/graphics/rbscreen.h63
-rw-r--r--utils/themeeditor/models/parsetreemodel.cpp12
-rw-r--r--utils/themeeditor/resources.qrc3
-rw-r--r--utils/themeeditor/resources/render/scenebg.pngbin0 -> 213 bytes
-rw-r--r--utils/themeeditor/themeeditor.pro22
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 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (C) 2010 Robert Bieber
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+
+#include "rbscreen.h"
+
+#include <QPainter>
+#include <QFile>
+
+RBScreen::RBScreen(ProjectModel* project, QGraphicsItem *parent) :
+ QGraphicsItem(parent), project(project), backdrop(0)
+{
+
+ width = safeSetting(project, "#screenwidth", "300").toInt();
+ height = safeSetting(project, "#screenheight", "200").toInt();
+
+ QString bg = safeSetting(project, "background color", "FFFFFF");
+ bgColor = stringToColor(bg, Qt::white);
+
+ QString fg = safeSetting(project, "foreground color", "FFFFFF");
+ fgColor = stringToColor(fg, Qt::black);
+
+ /* Loading backdrop if available */
+ if(project)
+ {
+ QString base = project->getSetting("themebase", "");
+ QString backdropFile = project->getSetting("backdrop", "");
+
+ if(QFile::exists(base + "/backdrops/" + backdropFile))
+ {
+ backdrop = new QPixmap(base + "/backdrops/" + backdropFile);
+
+ /* If a backdrop has been found, use its width and height */
+ if(!backdrop->isNull())
+ {
+ width = backdrop->width();
+ height = backdrop->height();
+ }
+ else
+ {
+ delete backdrop;
+ backdrop = 0;
+ }
+ }
+ }
+}
+
+RBScreen::~RBScreen()
+{
+ if(backdrop)
+ delete backdrop;
+}
+
+QPainterPath RBScreen::shape() const
+{
+ QPainterPath retval;
+ retval.addRect(0, 0, width, height);
+ return retval;
+}
+
+QRectF RBScreen::boundingRect() const
+{
+ return QRectF(0, 0, width, height);
+}
+
+void RBScreen::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
+ QWidget *widget)
+{
+ if(backdrop)
+ {
+ painter->drawPixmap(0, 0, width, height, *backdrop);
+ }
+ else
+ {
+ painter->fillRect(0, 0, width, height, bgColor);
+ }
+}
+
+QColor RBScreen::stringToColor(QString str, QColor fallback)
+{
+
+ QColor retval;
+
+ if(str.length() == 6)
+ {
+ for(int i = 0; i < 6; i++)
+ {
+ char c = str[i].toAscii();
+ if(!((c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F') ||
+ isdigit(c)))
+ {
+ str = "";
+ break;
+ }
+ }
+ if(str != "")
+ retval = QColor("#" + str);
+ else
+ retval = fallback;
+ }
+ else if(str.length() == 1)
+ {
+ if(isdigit(str[0].toAscii()) && str[0].toAscii() <= '3')
+ {
+ int shade = 255 * (str[0].toAscii() - '0') / 3;
+ retval = QColor(shade, shade, shade);
+ }
+ else
+ {
+ retval = fallback;
+ }
+ }
+ else
+ {
+ retval = fallback;
+ }
+
+ return retval;
+
+}
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 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (C) 2010 Robert Bieber
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+
+#ifndef RBSCREEN_H
+#define RBSCREEN_H
+
+#include <QGraphicsItem>
+
+#include "projectmodel.h"
+
+class RBScreen : public QGraphicsItem
+{
+
+public:
+ RBScreen(ProjectModel* project = 0, QGraphicsItem *parent = 0);
+ virtual ~RBScreen();
+
+ QPainterPath shape() const;
+ QRectF boundingRect() const;
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
+ QWidget *widget);
+
+ static QString safeSetting(ProjectModel* project, QString key,
+ QString fallback)
+ {
+ if(project)
+ return project->getSetting(key, fallback);
+ else
+ return fallback;
+ }
+
+ static QColor stringToColor(QString str, QColor fallback);
+
+private:
+ int width;
+ int height;
+ QColor bgColor;
+ QColor fgColor;
+ QPixmap* backdrop;
+
+ ProjectModel* project;
+
+};
+
+#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 @@
#include "parsetreemodel.h"
#include "symbols.h"
+#include "rbscreen.h"
#include <cstdlib>
#include <QObject>
+#include <QPixmap>
ParseTreeModel::ParseTreeModel(const char* document, QObject* parent):
QAbstractItemModel(parent)
@@ -271,10 +273,12 @@ QGraphicsScene* ParseTreeModel::render(ProjectModel* project)
{
scene->clear();
- /* First we set the screen size */
- int screenWidth = safeSetting(project, "#screenwidth", "300").toInt();
- int screenHeight = safeSetting(project, "#screenheight", "200").toInt();
- scene->addRect(0, 0, screenWidth, screenHeight);
+ /* Setting the background */
+ scene->setBackgroundBrush(QBrush(QPixmap(":/render/scenebg.png")));
+
+ /* Adding the screen */
+ RBScreen* screen = new RBScreen(project);
+ scene->addItem(screen);
return scene;
}
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 @@
<file>resources/document-save.png</file>
<file alias="configkeys">resources/configkeys</file>
</qresource>
+ <qresource prefix="/render">
+ <file alias="scenebg.png">resources/render/scenebg.png</file>
+ </qresource>
</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
UI_DIR = $$MYBUILDDIR/ui
MOC_DIR = $$MYBUILDDIR/moc
RCC_DIR = $$MYBUILDDIR/rcc
-
RBBASE_DIR = $$_PRO_FILE_PWD_
RBBASE_DIR = $$replace(RBBASE_DIR,/utils/themeeditor,)
-#Include directories
+# Include directories
INCLUDEPATH += gui
INCLUDEPATH += models
-
+INCLUDEPATH += graphics
# Stuff for the parse lib
libskin_parser.commands = @$(MAKE) \
- BUILDDIR=$$OBJECTS_DIR -C $$RBBASE_DIR/lib/skin_parser CC=\"$$QMAKE_CC\"
+ BUILDDIR=$$OBJECTS_DIR \
+ -C \
+ $$RBBASE_DIR/lib/skin_parser \
+ CC=\"$$QMAKE_CC\"
QMAKE_EXTRA_TARGETS += libskin_parser
PRE_TARGETDEPS += libskin_parser
INCLUDEPATH += $$RBBASE_DIR/lib/skin_parser
-LIBS += -L$$OBJECTS_DIR -lskin_parser
-
-
+LIBS += -L$$OBJECTS_DIR \
+ -lskin_parser
DEPENDPATH = $$INCLUDEPATH
-
HEADERS += models/parsetreemodel.h \
models/parsetreenode.h \
gui/editorwindow.h \
@@ -34,7 +34,8 @@ HEADERS += models/parsetreemodel.h \
models/projectmodel.h \
gui/tabcontent.h \
gui/configdocument.h \
- gui/skinviewer.h
+ gui/skinviewer.h \
+ graphics/rbscreen.h
SOURCES += main.cpp \
models/parsetreemodel.cpp \
models/parsetreenode.cpp \
@@ -45,7 +46,8 @@ SOURCES += main.cpp \
gui/codeeditor.cpp \
models/projectmodel.cpp \
gui/configdocument.cpp \
- gui/skinviewer.cpp
+ gui/skinviewer.cpp \
+ graphics/rbscreen.cpp
OTHER_FILES += README \
resources/windowicon.png \
resources/appicon.xcf \