summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorRobert Bieber <robby@bieberphoto.com>2010-06-25 05:14:13 +0000
committerRobert Bieber <robby@bieberphoto.com>2010-06-25 05:14:13 +0000
commit273b9d60502eb5b6c13cc773403fd51d9c7adf75 (patch)
treedd99f1e4afc17829210643744d1817fba632423c /utils
parent691d049177d646861a52e96146ad880d9dc18bbe (diff)
Theme Editor: Fixed some compiler warnings and a segfault. Got some basic text rendering working (only with plaintext elements, no font support yet) as well as Viewport background color support
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27126 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'utils')
-rw-r--r--utils/themeeditor/graphics/rbfont.cpp15
-rw-r--r--utils/themeeditor/graphics/rbfont.h5
-rw-r--r--utils/themeeditor/graphics/rbscreen.cpp6
-rw-r--r--utils/themeeditor/graphics/rbscreen.h4
-rw-r--r--utils/themeeditor/graphics/rbviewport.cpp28
-rw-r--r--utils/themeeditor/graphics/rbviewport.h10
-rw-r--r--utils/themeeditor/gui/devicestate.cpp4
-rw-r--r--utils/themeeditor/gui/editorwindow.cpp5
-rw-r--r--utils/themeeditor/models/parsetreenode.cpp6
9 files changed, 69 insertions, 14 deletions
diff --git a/utils/themeeditor/graphics/rbfont.cpp b/utils/themeeditor/graphics/rbfont.cpp
index 48e0f304be..71c6ff3fc1 100644
--- a/utils/themeeditor/graphics/rbfont.cpp
+++ b/utils/themeeditor/graphics/rbfont.cpp
@@ -21,6 +21,9 @@
#include "rbfont.h"
+#include <QFont>
+#include <QBrush>
+
RBFont::RBFont(QString file): filename(file)
{
}
@@ -28,3 +31,15 @@ RBFont::RBFont(QString file): filename(file)
RBFont::~RBFont()
{
}
+
+QGraphicsSimpleTextItem* RBFont::renderText(QString text, QColor color,
+ QGraphicsItem *parent)
+{
+ QGraphicsSimpleTextItem* retval = new QGraphicsSimpleTextItem(text, parent);
+ QFont font;
+ font.setFixedPitch(true);
+ font.setPixelSize(8);
+ retval->setFont(font);
+ retval->setBrush(QBrush(color));
+ return retval;
+}
diff --git a/utils/themeeditor/graphics/rbfont.h b/utils/themeeditor/graphics/rbfont.h
index a1d66f22d4..61a171e081 100644
--- a/utils/themeeditor/graphics/rbfont.h
+++ b/utils/themeeditor/graphics/rbfont.h
@@ -24,6 +24,7 @@
#include <QString>
#include <QFile>
+#include <QGraphicsSimpleTextItem>
class RBFont
{
@@ -31,6 +32,10 @@ public:
RBFont(QString file);
virtual ~RBFont();
+ QGraphicsSimpleTextItem* renderText(QString text, QColor color,
+ QGraphicsItem* parent = 0);
+ int lineHeight(){ return 8; }
+
private:
QString filename;
};
diff --git a/utils/themeeditor/graphics/rbscreen.cpp b/utils/themeeditor/graphics/rbscreen.cpp
index d37050b0b5..d6a9aa6240 100644
--- a/utils/themeeditor/graphics/rbscreen.cpp
+++ b/utils/themeeditor/graphics/rbscreen.cpp
@@ -32,10 +32,10 @@ RBScreen::RBScreen(const RBRenderInfo& info, QGraphicsItem *parent) :
width = info.settings()->value("#screenwidth", "300").toInt();
height = info.settings()->value("#screenheight", "200").toInt();
- QString bg = info.settings()->value("background color", "000000");
+ QString bg = info.settings()->value("background color", "FFFFFF");
bgColor = stringToColor(bg, Qt::white);
- QString fg = info.settings()->value("foreground color", "FFFFFF");
+ QString fg = info.settings()->value("foreground color", "000000");
fgColor = stringToColor(fg, Qt::black);
settings = info.settings();
@@ -61,6 +61,8 @@ RBScreen::RBScreen(const RBRenderInfo& info, QGraphicsItem *parent) :
backdrop = 0;
}
}
+
+ fonts.insert(0, new RBFont("Nothin'"));
}
RBScreen::~RBScreen()
diff --git a/utils/themeeditor/graphics/rbscreen.h b/utils/themeeditor/graphics/rbscreen.h
index f35aef680b..8b5f2f4a16 100644
--- a/utils/themeeditor/graphics/rbscreen.h
+++ b/utils/themeeditor/graphics/rbscreen.h
@@ -60,10 +60,14 @@ public:
RBFont* getFont(int id);
void setBackdrop(QString filename);
+ bool hasBackdrop(){ return backdrop != 0; }
void makeCustomUI(QString id);
static QColor stringToColor(QString str, QColor fallback);
+ QColor foreground(){ return fgColor; }
+ QColor background(){ return bgColor; }
+
private:
int width;
diff --git a/utils/themeeditor/graphics/rbviewport.cpp b/utils/themeeditor/graphics/rbviewport.cpp
index c5b88b3afd..03a7604804 100644
--- a/utils/themeeditor/graphics/rbviewport.cpp
+++ b/utils/themeeditor/graphics/rbviewport.cpp
@@ -30,7 +30,10 @@
#include "skin_parser.h"
RBViewport::RBViewport(skin_element* node, const RBRenderInfo& info)
- : QGraphicsItem(info.screen())
+ : QGraphicsItem(info.screen()), font(info.screen()->getFont(0)),
+ foreground(info.screen()->foreground()),
+ background(info.screen()->background()), textOffset(0,0),
+ screen(info.screen())
{
if(!node->tag)
{
@@ -51,7 +54,7 @@ RBViewport::RBViewport(skin_element* node, const RBRenderInfo& info)
}
else
{
- int param;
+ int param = 0;
QString ident;
int x,y,w,h;
/* Rendering one of the other types of viewport */
@@ -102,6 +105,7 @@ RBViewport::RBViewport(skin_element* node, const RBRenderInfo& info)
setPos(x, y);
size = QRectF(0, 0, w, h);
+
}
}
@@ -124,13 +128,29 @@ QRectF RBViewport::boundingRect() const
void RBViewport::paint(QPainter *painter,
const QStyleOptionGraphicsItem *option, QWidget *widget)
{
+ if(!screen->hasBackdrop() && background != screen->background())
+ {
+ painter->fillRect(size, QBrush(background));
+ }
+
painter->setBrush(Qt::NoBrush);
painter->setPen(customUI ? Qt::blue : Qt::red);
painter->drawRect(size);
}
-/* Called at the end of a logical line */
-void RBViewport::newline()
+void RBViewport::newLine()
{
+ if(textOffset.x() > 0)
+ {
+ textOffset.setY(textOffset.y() + lineHeight);
+ textOffset.setX(0);
+ }
+}
+void RBViewport::write(QString text)
+{
+ QGraphicsItem* graphic = font->renderText(text, foreground, this);
+ graphic->setPos(textOffset.x(), textOffset.y());
+ textOffset.setX(textOffset.x() + graphic->boundingRect().width());
+ lineHeight = font->lineHeight();
}
diff --git a/utils/themeeditor/graphics/rbviewport.h b/utils/themeeditor/graphics/rbviewport.h
index 29d0b0a373..5726c5c256 100644
--- a/utils/themeeditor/graphics/rbviewport.h
+++ b/utils/themeeditor/graphics/rbviewport.h
@@ -23,6 +23,7 @@
#define RBVIEWPORT_H
#include "skin_parser.h"
+#include "rbfont.h"
class RBScreen;
class RBRenderInfo;
@@ -45,16 +46,21 @@ public:
void makeCustomUI(){ customUI = true; }
void clearCustomUI(){ customUI = false; }
-
- void newline();
+ void newLine();
+ void write(QString text);
private:
+
QRectF size;
QColor background;
QColor foreground;
+ RBFont* font;
bool customUI;
+ QPoint textOffset;
+ int lineHeight;
+ RBScreen* screen;
};
#endif // RBVIEWPORT_H
diff --git a/utils/themeeditor/gui/devicestate.cpp b/utils/themeeditor/gui/devicestate.cpp
index ef9d666eb2..3933926a48 100644
--- a/utils/themeeditor/gui/devicestate.cpp
+++ b/utils/themeeditor/gui/devicestate.cpp
@@ -44,7 +44,7 @@ DeviceState::DeviceState(QWidget *parent) :
this->setLayout(layout);
/* Loading the tabs */
- QScrollArea* currentArea;
+ QScrollArea* currentArea = 0;
QHBoxLayout* subLayout;
QWidget* panel;
@@ -176,7 +176,7 @@ DeviceState::DeviceState(QWidget *parent) :
{
elements = elements[1].trimmed().split(",");
- int defIndex;
+ int defIndex = 0;
QComboBox* temp = new QComboBox(currentArea);
for(int i = 0; i < elements.count(); i++)
{
diff --git a/utils/themeeditor/gui/editorwindow.cpp b/utils/themeeditor/gui/editorwindow.cpp
index 1aec46a7cc..81d05c8ed4 100644
--- a/utils/themeeditor/gui/editorwindow.cpp
+++ b/utils/themeeditor/gui/editorwindow.cpp
@@ -31,7 +31,8 @@
EditorWindow::EditorWindow(QWidget *parent) :
QMainWindow(parent),
- ui(new Ui::EditorWindow)
+ ui(new Ui::EditorWindow),
+ parseTreeSelection(0)
{
ui->setupUi(this);
prefs = new PreferencesDialog(this);
@@ -438,8 +439,6 @@ void EditorWindow::updateCurrent()
void EditorWindow::lineChanged(int line)
{
ui->parseTree->collapseAll();
- if(parseTreeSelection)
- parseTreeSelection->deleteLater();
ParseTreeModel* model = dynamic_cast<ParseTreeModel*>
(ui->parseTree->model());
parseTreeSelection = new QItemSelectionModel(model);
diff --git a/utils/themeeditor/models/parsetreenode.cpp b/utils/themeeditor/models/parsetreenode.cpp
index 3696a661a8..5e298be255 100644
--- a/utils/themeeditor/models/parsetreenode.cpp
+++ b/utils/themeeditor/models/parsetreenode.cpp
@@ -516,7 +516,11 @@ void ParseTreeNode::render(const RBRenderInfo &info, RBViewport* viewport)
{
for(int i = 0; i < children.count(); i++)
children[i]->render(info, viewport);
- viewport->newline();
+ viewport->newLine();
+ }
+ else if(element->type == TEXT)
+ {
+ viewport->write(QString(static_cast<char*>(element->data)));
}
else if(element->type == TAG)
{