From a73d2e3febfa1bbb206c4e23f112cdcc933f89cf Mon Sep 17 00:00:00 2001 From: bieber Date: Fri, 25 Jun 2010 05:14:13 +0000 Subject: [PATCH] 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 --- utils/themeeditor/graphics/rbfont.cpp | 15 +++++++++++++++ utils/themeeditor/graphics/rbfont.h | 5 +++++ utils/themeeditor/graphics/rbscreen.cpp | 6 ++++-- utils/themeeditor/graphics/rbscreen.h | 4 ++++ utils/themeeditor/graphics/rbviewport.cpp | 28 ++++++++++++++++++++++++---- utils/themeeditor/graphics/rbviewport.h | 10 ++++++++-- utils/themeeditor/gui/devicestate.cpp | 4 ++-- utils/themeeditor/gui/editorwindow.cpp | 5 ++--- utils/themeeditor/models/parsetreenode.cpp | 6 +++++- 9 files changed, 69 insertions(+), 14 deletions(-) diff --git a/utils/themeeditor/graphics/rbfont.cpp b/utils/themeeditor/graphics/rbfont.cpp index 48e0f304b..71c6ff3fc 100644 --- a/utils/themeeditor/graphics/rbfont.cpp +++ b/utils/themeeditor/graphics/rbfont.cpp @@ -21,6 +21,9 @@ #include "rbfont.h" +#include +#include + 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 a1d66f22d..61a171e08 100644 --- a/utils/themeeditor/graphics/rbfont.h +++ b/utils/themeeditor/graphics/rbfont.h @@ -24,6 +24,7 @@ #include #include +#include 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 d37050b0b..d6a9aa624 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 f35aef680..8b5f2f4a1 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 c5b88b3af..03a760480 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 29d0b0a37..5726c5c25 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 ef9d666eb..3933926a4 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 1aec46a7c..81d05c8ed 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 (ui->parseTree->model()); parseTreeSelection = new QItemSelectionModel(model); diff --git a/utils/themeeditor/models/parsetreenode.cpp b/utils/themeeditor/models/parsetreenode.cpp index 3696a661a..5e298be25 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(element->data))); } else if(element->type == TAG) { -- 2.11.4.GIT