Theme Editor: Fixed some compiler warnings and a segfault. Got some basic text rende...
authorbieber <bieber@a1c6a512-1295-4272-9138-f99709370657>
Fri, 25 Jun 2010 05:14:13 +0000 (25 05:14 +0000)
committerbieber <bieber@a1c6a512-1295-4272-9138-f99709370657>
Fri, 25 Jun 2010 05:14:13 +0000 (25 05:14 +0000)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27126 a1c6a512-1295-4272-9138-f99709370657

utils/themeeditor/graphics/rbfont.cpp
utils/themeeditor/graphics/rbfont.h
utils/themeeditor/graphics/rbscreen.cpp
utils/themeeditor/graphics/rbscreen.h
utils/themeeditor/graphics/rbviewport.cpp
utils/themeeditor/graphics/rbviewport.h
utils/themeeditor/gui/devicestate.cpp
utils/themeeditor/gui/editorwindow.cpp
utils/themeeditor/models/parsetreenode.cpp

index 48e0f30..71c6ff3 100644 (file)
@@ -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;
+}
index a1d66f2..61a171e 100644 (file)
@@ -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;
 };
index d37050b..d6a9aa6 100644 (file)
@@ -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()
index f35aef6..8b5f2f4 100644 (file)
@@ -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;
index c5b88b3..03a7604 100644 (file)
 #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();
 }
index 29d0b0a..5726c5c 100644 (file)
@@ -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
index ef9d666..3933926 100644 (file)
@@ -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++)
             {
index 1aec46a..81d05c8 100644 (file)
@@ -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);
index 3696a66..5e298be 100644 (file)
@@ -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)
     {