diff options
author | Robert Bieber <robby@bieberphoto.com> | 2010-06-25 05:14:13 +0000 |
---|---|---|
committer | Robert Bieber <robby@bieberphoto.com> | 2010-06-25 05:14:13 +0000 |
commit | 273b9d60502eb5b6c13cc773403fd51d9c7adf75 (patch) | |
tree | dd99f1e4afc17829210643744d1817fba632423c /utils/themeeditor | |
parent | 691d049177d646861a52e96146ad880d9dc18bbe (diff) | |
download | rockbox-273b9d60502eb5b6c13cc773403fd51d9c7adf75.tar.gz rockbox-273b9d60502eb5b6c13cc773403fd51d9c7adf75.zip |
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/themeeditor')
-rw-r--r-- | utils/themeeditor/graphics/rbfont.cpp | 15 | ||||
-rw-r--r-- | utils/themeeditor/graphics/rbfont.h | 5 | ||||
-rw-r--r-- | utils/themeeditor/graphics/rbscreen.cpp | 6 | ||||
-rw-r--r-- | utils/themeeditor/graphics/rbscreen.h | 4 | ||||
-rw-r--r-- | utils/themeeditor/graphics/rbviewport.cpp | 28 | ||||
-rw-r--r-- | utils/themeeditor/graphics/rbviewport.h | 10 | ||||
-rw-r--r-- | utils/themeeditor/gui/devicestate.cpp | 4 | ||||
-rw-r--r-- | utils/themeeditor/gui/editorwindow.cpp | 5 | ||||
-rw-r--r-- | 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 48e0f304be..71c6ff3fc1 100644 --- a/utils/themeeditor/graphics/rbfont.cpp +++ b/utils/themeeditor/graphics/rbfont.cpp | |||
@@ -21,6 +21,9 @@ | |||
21 | 21 | ||
22 | #include "rbfont.h" | 22 | #include "rbfont.h" |
23 | 23 | ||
24 | #include <QFont> | ||
25 | #include <QBrush> | ||
26 | |||
24 | RBFont::RBFont(QString file): filename(file) | 27 | RBFont::RBFont(QString file): filename(file) |
25 | { | 28 | { |
26 | } | 29 | } |
@@ -28,3 +31,15 @@ RBFont::RBFont(QString file): filename(file) | |||
28 | RBFont::~RBFont() | 31 | RBFont::~RBFont() |
29 | { | 32 | { |
30 | } | 33 | } |
34 | |||
35 | QGraphicsSimpleTextItem* RBFont::renderText(QString text, QColor color, | ||
36 | QGraphicsItem *parent) | ||
37 | { | ||
38 | QGraphicsSimpleTextItem* retval = new QGraphicsSimpleTextItem(text, parent); | ||
39 | QFont font; | ||
40 | font.setFixedPitch(true); | ||
41 | font.setPixelSize(8); | ||
42 | retval->setFont(font); | ||
43 | retval->setBrush(QBrush(color)); | ||
44 | return retval; | ||
45 | } | ||
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 @@ | |||
24 | 24 | ||
25 | #include <QString> | 25 | #include <QString> |
26 | #include <QFile> | 26 | #include <QFile> |
27 | #include <QGraphicsSimpleTextItem> | ||
27 | 28 | ||
28 | class RBFont | 29 | class RBFont |
29 | { | 30 | { |
@@ -31,6 +32,10 @@ public: | |||
31 | RBFont(QString file); | 32 | RBFont(QString file); |
32 | virtual ~RBFont(); | 33 | virtual ~RBFont(); |
33 | 34 | ||
35 | QGraphicsSimpleTextItem* renderText(QString text, QColor color, | ||
36 | QGraphicsItem* parent = 0); | ||
37 | int lineHeight(){ return 8; } | ||
38 | |||
34 | private: | 39 | private: |
35 | QString filename; | 40 | QString filename; |
36 | }; | 41 | }; |
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) : | |||
32 | width = info.settings()->value("#screenwidth", "300").toInt(); | 32 | width = info.settings()->value("#screenwidth", "300").toInt(); |
33 | height = info.settings()->value("#screenheight", "200").toInt(); | 33 | height = info.settings()->value("#screenheight", "200").toInt(); |
34 | 34 | ||
35 | QString bg = info.settings()->value("background color", "000000"); | 35 | QString bg = info.settings()->value("background color", "FFFFFF"); |
36 | bgColor = stringToColor(bg, Qt::white); | 36 | bgColor = stringToColor(bg, Qt::white); |
37 | 37 | ||
38 | QString fg = info.settings()->value("foreground color", "FFFFFF"); | 38 | QString fg = info.settings()->value("foreground color", "000000"); |
39 | fgColor = stringToColor(fg, Qt::black); | 39 | fgColor = stringToColor(fg, Qt::black); |
40 | 40 | ||
41 | settings = info.settings(); | 41 | settings = info.settings(); |
@@ -61,6 +61,8 @@ RBScreen::RBScreen(const RBRenderInfo& info, QGraphicsItem *parent) : | |||
61 | backdrop = 0; | 61 | backdrop = 0; |
62 | } | 62 | } |
63 | } | 63 | } |
64 | |||
65 | fonts.insert(0, new RBFont("Nothin'")); | ||
64 | } | 66 | } |
65 | 67 | ||
66 | RBScreen::~RBScreen() | 68 | 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: | |||
60 | RBFont* getFont(int id); | 60 | RBFont* getFont(int id); |
61 | 61 | ||
62 | void setBackdrop(QString filename); | 62 | void setBackdrop(QString filename); |
63 | bool hasBackdrop(){ return backdrop != 0; } | ||
63 | void makeCustomUI(QString id); | 64 | void makeCustomUI(QString id); |
64 | 65 | ||
65 | static QColor stringToColor(QString str, QColor fallback); | 66 | static QColor stringToColor(QString str, QColor fallback); |
66 | 67 | ||
68 | QColor foreground(){ return fgColor; } | ||
69 | QColor background(){ return bgColor; } | ||
70 | |||
67 | 71 | ||
68 | private: | 72 | private: |
69 | int width; | 73 | 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 @@ | |||
30 | #include "skin_parser.h" | 30 | #include "skin_parser.h" |
31 | 31 | ||
32 | RBViewport::RBViewport(skin_element* node, const RBRenderInfo& info) | 32 | RBViewport::RBViewport(skin_element* node, const RBRenderInfo& info) |
33 | : QGraphicsItem(info.screen()) | 33 | : QGraphicsItem(info.screen()), font(info.screen()->getFont(0)), |
34 | foreground(info.screen()->foreground()), | ||
35 | background(info.screen()->background()), textOffset(0,0), | ||
36 | screen(info.screen()) | ||
34 | { | 37 | { |
35 | if(!node->tag) | 38 | if(!node->tag) |
36 | { | 39 | { |
@@ -51,7 +54,7 @@ RBViewport::RBViewport(skin_element* node, const RBRenderInfo& info) | |||
51 | } | 54 | } |
52 | else | 55 | else |
53 | { | 56 | { |
54 | int param; | 57 | int param = 0; |
55 | QString ident; | 58 | QString ident; |
56 | int x,y,w,h; | 59 | int x,y,w,h; |
57 | /* Rendering one of the other types of viewport */ | 60 | /* Rendering one of the other types of viewport */ |
@@ -102,6 +105,7 @@ RBViewport::RBViewport(skin_element* node, const RBRenderInfo& info) | |||
102 | 105 | ||
103 | setPos(x, y); | 106 | setPos(x, y); |
104 | size = QRectF(0, 0, w, h); | 107 | size = QRectF(0, 0, w, h); |
108 | |||
105 | } | 109 | } |
106 | } | 110 | } |
107 | 111 | ||
@@ -124,13 +128,29 @@ QRectF RBViewport::boundingRect() const | |||
124 | void RBViewport::paint(QPainter *painter, | 128 | void RBViewport::paint(QPainter *painter, |
125 | const QStyleOptionGraphicsItem *option, QWidget *widget) | 129 | const QStyleOptionGraphicsItem *option, QWidget *widget) |
126 | { | 130 | { |
131 | if(!screen->hasBackdrop() && background != screen->background()) | ||
132 | { | ||
133 | painter->fillRect(size, QBrush(background)); | ||
134 | } | ||
135 | |||
127 | painter->setBrush(Qt::NoBrush); | 136 | painter->setBrush(Qt::NoBrush); |
128 | painter->setPen(customUI ? Qt::blue : Qt::red); | 137 | painter->setPen(customUI ? Qt::blue : Qt::red); |
129 | painter->drawRect(size); | 138 | painter->drawRect(size); |
130 | } | 139 | } |
131 | 140 | ||
132 | /* Called at the end of a logical line */ | 141 | void RBViewport::newLine() |
133 | void RBViewport::newline() | ||
134 | { | 142 | { |
143 | if(textOffset.x() > 0) | ||
144 | { | ||
145 | textOffset.setY(textOffset.y() + lineHeight); | ||
146 | textOffset.setX(0); | ||
147 | } | ||
148 | } | ||
135 | 149 | ||
150 | void RBViewport::write(QString text) | ||
151 | { | ||
152 | QGraphicsItem* graphic = font->renderText(text, foreground, this); | ||
153 | graphic->setPos(textOffset.x(), textOffset.y()); | ||
154 | textOffset.setX(textOffset.x() + graphic->boundingRect().width()); | ||
155 | lineHeight = font->lineHeight(); | ||
136 | } | 156 | } |
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 @@ | |||
23 | #define RBVIEWPORT_H | 23 | #define RBVIEWPORT_H |
24 | 24 | ||
25 | #include "skin_parser.h" | 25 | #include "skin_parser.h" |
26 | #include "rbfont.h" | ||
26 | 27 | ||
27 | class RBScreen; | 28 | class RBScreen; |
28 | class RBRenderInfo; | 29 | class RBRenderInfo; |
@@ -45,16 +46,21 @@ public: | |||
45 | void makeCustomUI(){ customUI = true; } | 46 | void makeCustomUI(){ customUI = true; } |
46 | void clearCustomUI(){ customUI = false; } | 47 | void clearCustomUI(){ customUI = false; } |
47 | 48 | ||
48 | 49 | void newLine(); | |
49 | void newline(); | 50 | void write(QString text); |
50 | 51 | ||
51 | private: | 52 | private: |
53 | |||
52 | QRectF size; | 54 | QRectF size; |
53 | QColor background; | 55 | QColor background; |
54 | QColor foreground; | 56 | QColor foreground; |
57 | RBFont* font; | ||
55 | 58 | ||
56 | bool customUI; | 59 | bool customUI; |
60 | QPoint textOffset; | ||
61 | int lineHeight; | ||
57 | 62 | ||
63 | RBScreen* screen; | ||
58 | }; | 64 | }; |
59 | 65 | ||
60 | #endif // RBVIEWPORT_H | 66 | #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) : | |||
44 | this->setLayout(layout); | 44 | this->setLayout(layout); |
45 | 45 | ||
46 | /* Loading the tabs */ | 46 | /* Loading the tabs */ |
47 | QScrollArea* currentArea; | 47 | QScrollArea* currentArea = 0; |
48 | QHBoxLayout* subLayout; | 48 | QHBoxLayout* subLayout; |
49 | QWidget* panel; | 49 | QWidget* panel; |
50 | 50 | ||
@@ -176,7 +176,7 @@ DeviceState::DeviceState(QWidget *parent) : | |||
176 | { | 176 | { |
177 | elements = elements[1].trimmed().split(","); | 177 | elements = elements[1].trimmed().split(","); |
178 | 178 | ||
179 | int defIndex; | 179 | int defIndex = 0; |
180 | QComboBox* temp = new QComboBox(currentArea); | 180 | QComboBox* temp = new QComboBox(currentArea); |
181 | for(int i = 0; i < elements.count(); i++) | 181 | for(int i = 0; i < elements.count(); i++) |
182 | { | 182 | { |
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 @@ | |||
31 | 31 | ||
32 | EditorWindow::EditorWindow(QWidget *parent) : | 32 | EditorWindow::EditorWindow(QWidget *parent) : |
33 | QMainWindow(parent), | 33 | QMainWindow(parent), |
34 | ui(new Ui::EditorWindow) | 34 | ui(new Ui::EditorWindow), |
35 | parseTreeSelection(0) | ||
35 | { | 36 | { |
36 | ui->setupUi(this); | 37 | ui->setupUi(this); |
37 | prefs = new PreferencesDialog(this); | 38 | prefs = new PreferencesDialog(this); |
@@ -438,8 +439,6 @@ void EditorWindow::updateCurrent() | |||
438 | void EditorWindow::lineChanged(int line) | 439 | void EditorWindow::lineChanged(int line) |
439 | { | 440 | { |
440 | ui->parseTree->collapseAll(); | 441 | ui->parseTree->collapseAll(); |
441 | if(parseTreeSelection) | ||
442 | parseTreeSelection->deleteLater(); | ||
443 | ParseTreeModel* model = dynamic_cast<ParseTreeModel*> | 442 | ParseTreeModel* model = dynamic_cast<ParseTreeModel*> |
444 | (ui->parseTree->model()); | 443 | (ui->parseTree->model()); |
445 | parseTreeSelection = new QItemSelectionModel(model); | 444 | 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) | |||
516 | { | 516 | { |
517 | for(int i = 0; i < children.count(); i++) | 517 | for(int i = 0; i < children.count(); i++) |
518 | children[i]->render(info, viewport); | 518 | children[i]->render(info, viewport); |
519 | viewport->newline(); | 519 | viewport->newLine(); |
520 | } | ||
521 | else if(element->type == TEXT) | ||
522 | { | ||
523 | viewport->write(QString(static_cast<char*>(element->data))); | ||
520 | } | 524 | } |
521 | else if(element->type == TAG) | 525 | else if(element->type == TAG) |
522 | { | 526 | { |