diff options
Diffstat (limited to 'utils')
-rw-r--r-- | utils/themeeditor/graphics/rbfont.cpp | 19 | ||||
-rw-r--r-- | utils/themeeditor/graphics/rbfontcache.cpp | 21 | ||||
-rw-r--r-- | utils/themeeditor/graphics/rbfontcache.h | 2 | ||||
-rw-r--r-- | utils/themeeditor/graphics/rbtext.cpp | 14 | ||||
-rw-r--r-- | utils/themeeditor/graphics/rbtext.h | 4 | ||||
-rw-r--r-- | utils/themeeditor/graphics/rbtextcache.cpp | 35 | ||||
-rw-r--r-- | utils/themeeditor/graphics/rbtextcache.h | 39 | ||||
-rw-r--r-- | utils/themeeditor/gui/editorwindow.cpp | 5 | ||||
-rw-r--r-- | utils/themeeditor/gui/skindocument.cpp | 21 | ||||
-rw-r--r-- | utils/themeeditor/gui/skindocument.h | 6 | ||||
-rw-r--r-- | utils/themeeditor/themeeditor.pro | 10 |
11 files changed, 158 insertions, 18 deletions
diff --git a/utils/themeeditor/graphics/rbfont.cpp b/utils/themeeditor/graphics/rbfont.cpp index cd68af99fe..3b7397283c 100644 --- a/utils/themeeditor/graphics/rbfont.cpp +++ b/utils/themeeditor/graphics/rbfont.cpp | |||
@@ -21,6 +21,7 @@ | |||
21 | 21 | ||
22 | #include "rbfont.h" | 22 | #include "rbfont.h" |
23 | #include "rbfontcache.h" | 23 | #include "rbfontcache.h" |
24 | #include "rbtextcache.h" | ||
24 | 25 | ||
25 | #include <QFont> | 26 | #include <QFont> |
26 | #include <QBrush> | 27 | #include <QBrush> |
@@ -166,6 +167,13 @@ RBFont::~RBFont() | |||
166 | RBText* RBFont::renderText(QString text, QColor color, int viewWidth, | 167 | RBText* RBFont::renderText(QString text, QColor color, int viewWidth, |
167 | QGraphicsItem *parent) | 168 | QGraphicsItem *parent) |
168 | { | 169 | { |
170 | |||
171 | /* Checking for a cache hit first */ | ||
172 | QImage* image = RBTextCache::lookup(header.value("filename").toString() | ||
173 | + text); | ||
174 | if(image) | ||
175 | return new RBText(image, viewWidth, parent); | ||
176 | |||
169 | int firstChar = header.value("firstchar").toInt(); | 177 | int firstChar = header.value("firstchar").toInt(); |
170 | int height = header.value("height").toInt(); | 178 | int height = header.value("height").toInt(); |
171 | int maxWidth = header.value("maxwidth").toInt(); | 179 | int maxWidth = header.value("maxwidth").toInt(); |
@@ -184,10 +192,10 @@ RBText* RBFont::renderText(QString text, QColor color, int viewWidth, | |||
184 | for(int i = 0; i < widths.count(); i++) | 192 | for(int i = 0; i < widths.count(); i++) |
185 | totalWidth += widths[i]; | 193 | totalWidth += widths[i]; |
186 | 194 | ||
187 | QImage image(totalWidth, height, QImage::Format_Indexed8); | 195 | image = new QImage(totalWidth, height, QImage::Format_Indexed8); |
188 | 196 | ||
189 | image.setColor(0, qRgba(0,0,0,0)); | 197 | image->setColor(0, qRgba(0,0,0,0)); |
190 | image.setColor(1, color.rgb()); | 198 | image->setColor(1, color.rgb()); |
191 | 199 | ||
192 | /* Drawing the text */ | 200 | /* Drawing the text */ |
193 | int startX = 0; | 201 | int startX = 0; |
@@ -214,9 +222,9 @@ RBText* RBFont::renderText(QString text, QColor color, int viewWidth, | |||
214 | for(int bit = 0; bit < 8; bit++) | 222 | for(int bit = 0; bit < 8; bit++) |
215 | { | 223 | { |
216 | if(mask & data) | 224 | if(mask & data) |
217 | image.setPixel(x, y, 1); | 225 | image->setPixel(x, y, 1); |
218 | else | 226 | else |
219 | image.setPixel(x, y, 0); | 227 | image->setPixel(x, y, 0); |
220 | 228 | ||
221 | y++; | 229 | y++; |
222 | mask <<= 1; | 230 | mask <<= 1; |
@@ -230,6 +238,7 @@ RBText* RBFont::renderText(QString text, QColor color, int viewWidth, | |||
230 | startX += widths[i]; | 238 | startX += widths[i]; |
231 | } | 239 | } |
232 | 240 | ||
241 | RBTextCache::insert(header.value("filename").toString() + text, image); | ||
233 | return new RBText(image, viewWidth, parent); | 242 | return new RBText(image, viewWidth, parent); |
234 | 243 | ||
235 | } | 244 | } |
diff --git a/utils/themeeditor/graphics/rbfontcache.cpp b/utils/themeeditor/graphics/rbfontcache.cpp index 3b6d56fd58..7ec77e11a1 100644 --- a/utils/themeeditor/graphics/rbfontcache.cpp +++ b/utils/themeeditor/graphics/rbfontcache.cpp | |||
@@ -22,3 +22,24 @@ | |||
22 | #include "rbfontcache.h" | 22 | #include "rbfontcache.h" |
23 | 23 | ||
24 | QHash<QString, RBFontCache::CacheInfo*> RBFontCache::cache; | 24 | QHash<QString, RBFontCache::CacheInfo*> RBFontCache::cache; |
25 | |||
26 | void RBFontCache::clearCache() | ||
27 | { | ||
28 | QHash<QString, CacheInfo*>::iterator i; | ||
29 | for(i = cache.begin(); i != cache.end(); i++) | ||
30 | { | ||
31 | CacheInfo* c = *i; | ||
32 | if(c->imageData) | ||
33 | delete c->imageData; | ||
34 | |||
35 | if(c->offsetData) | ||
36 | delete c->offsetData; | ||
37 | |||
38 | if(c->widthData) | ||
39 | delete c->widthData; | ||
40 | |||
41 | delete c; | ||
42 | } | ||
43 | |||
44 | cache.clear(); | ||
45 | } | ||
diff --git a/utils/themeeditor/graphics/rbfontcache.h b/utils/themeeditor/graphics/rbfontcache.h index 50a6d2ec48..62d82b7188 100644 --- a/utils/themeeditor/graphics/rbfontcache.h +++ b/utils/themeeditor/graphics/rbfontcache.h | |||
@@ -23,6 +23,7 @@ | |||
23 | #define RBFONTCACHE_H | 23 | #define RBFONTCACHE_H |
24 | 24 | ||
25 | #include <QHash> | 25 | #include <QHash> |
26 | #include <QVariant> | ||
26 | 27 | ||
27 | class RBFontCache | 28 | class RBFontCache |
28 | { | 29 | { |
@@ -39,6 +40,7 @@ public: | |||
39 | 40 | ||
40 | static CacheInfo* lookup(QString key){ return cache.value(key, 0); } | 41 | static CacheInfo* lookup(QString key){ return cache.value(key, 0); } |
41 | static void insert(QString key, CacheInfo* data){ cache.insert(key, data); } | 42 | static void insert(QString key, CacheInfo* data){ cache.insert(key, data); } |
43 | static void clearCache(); | ||
42 | 44 | ||
43 | private: | 45 | private: |
44 | static QHash<QString, CacheInfo*> cache; | 46 | static QHash<QString, CacheInfo*> cache; |
diff --git a/utils/themeeditor/graphics/rbtext.cpp b/utils/themeeditor/graphics/rbtext.cpp index d7fe542ab1..4666f9ae99 100644 --- a/utils/themeeditor/graphics/rbtext.cpp +++ b/utils/themeeditor/graphics/rbtext.cpp | |||
@@ -23,24 +23,24 @@ | |||
23 | 23 | ||
24 | #include <QPainter> | 24 | #include <QPainter> |
25 | 25 | ||
26 | RBText::RBText(const QImage &image, int maxWidth, QGraphicsItem *parent) | 26 | RBText::RBText(QImage* image, int maxWidth, QGraphicsItem *parent) |
27 | :QGraphicsItem(parent), image(image), maxWidth(maxWidth) | 27 | :QGraphicsItem(parent), image(image), maxWidth(maxWidth) |
28 | { | 28 | { |
29 | } | 29 | } |
30 | 30 | ||
31 | QRectF RBText::boundingRect() const | 31 | QRectF RBText::boundingRect() const |
32 | { | 32 | { |
33 | if(image.width() < maxWidth) | 33 | if(image->width() < maxWidth) |
34 | return QRectF(0, 0, image.width(), image.height()); | 34 | return QRectF(0, 0, image->width(), image->height()); |
35 | else | 35 | else |
36 | return QRectF(0, 0, maxWidth, image.height()); | 36 | return QRectF(0, 0, maxWidth, image->height()); |
37 | } | 37 | } |
38 | 38 | ||
39 | void RBText::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, | 39 | void RBText::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, |
40 | QWidget *widget) | 40 | QWidget *widget) |
41 | { | 41 | { |
42 | if(image.width() < maxWidth) | 42 | if(image->width() < maxWidth) |
43 | painter->drawImage(0, 0, image, 0, 0, image.width(), image.height()); | 43 | painter->drawImage(0, 0, *image, 0, 0, image->width(), image->height()); |
44 | else | 44 | else |
45 | painter->drawImage(0, 0, image, 0, 0, maxWidth, image.height()); | 45 | painter->drawImage(0, 0, *image, 0, 0, maxWidth, image->height()); |
46 | } | 46 | } |
diff --git a/utils/themeeditor/graphics/rbtext.h b/utils/themeeditor/graphics/rbtext.h index d03505491e..936a809f6c 100644 --- a/utils/themeeditor/graphics/rbtext.h +++ b/utils/themeeditor/graphics/rbtext.h | |||
@@ -28,14 +28,14 @@ | |||
28 | class RBText : public QGraphicsItem | 28 | class RBText : public QGraphicsItem |
29 | { | 29 | { |
30 | public: | 30 | public: |
31 | RBText(const QImage& image, int maxWidth, QGraphicsItem* parent); | 31 | RBText(QImage* image, int maxWidth, QGraphicsItem* parent); |
32 | 32 | ||
33 | QRectF boundingRect() const; | 33 | QRectF boundingRect() const; |
34 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, | 34 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, |
35 | QWidget *widget); | 35 | QWidget *widget); |
36 | 36 | ||
37 | private: | 37 | private: |
38 | QImage image; | 38 | QImage* image; |
39 | int maxWidth; | 39 | int maxWidth; |
40 | 40 | ||
41 | }; | 41 | }; |
diff --git a/utils/themeeditor/graphics/rbtextcache.cpp b/utils/themeeditor/graphics/rbtextcache.cpp new file mode 100644 index 0000000000..0116b80311 --- /dev/null +++ b/utils/themeeditor/graphics/rbtextcache.cpp | |||
@@ -0,0 +1,35 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2010 Robert Bieber | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | #include "rbtextcache.h" | ||
23 | |||
24 | QHash<QString, QImage*> RBTextCache::cache; | ||
25 | |||
26 | void RBTextCache::clearCache() | ||
27 | { | ||
28 | QHash<QString, QImage*>::iterator i; | ||
29 | for(i = cache.begin(); i != cache.end(); i++) | ||
30 | { | ||
31 | delete (*i); | ||
32 | } | ||
33 | |||
34 | cache.clear(); | ||
35 | } | ||
diff --git a/utils/themeeditor/graphics/rbtextcache.h b/utils/themeeditor/graphics/rbtextcache.h new file mode 100644 index 0000000000..a0c0e42e8d --- /dev/null +++ b/utils/themeeditor/graphics/rbtextcache.h | |||
@@ -0,0 +1,39 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2010 Robert Bieber | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | #ifndef RBTEXTCACHE_H | ||
23 | #define RBTEXTCACHE_H | ||
24 | |||
25 | #include <QHash> | ||
26 | #include <QImage> | ||
27 | |||
28 | class RBTextCache | ||
29 | { | ||
30 | public: | ||
31 | static QImage* lookup(QString key){ return cache.value(key, 0); } | ||
32 | static void insert(QString key, QImage* im){ cache.insert(key, im); } | ||
33 | static void clearCache(); | ||
34 | |||
35 | private: | ||
36 | static QHash<QString, QImage*> cache; | ||
37 | }; | ||
38 | |||
39 | #endif // RBTEXTCACHE_H | ||
diff --git a/utils/themeeditor/gui/editorwindow.cpp b/utils/themeeditor/gui/editorwindow.cpp index 4c073b9e0b..171e7b7019 100644 --- a/utils/themeeditor/gui/editorwindow.cpp +++ b/utils/themeeditor/gui/editorwindow.cpp | |||
@@ -22,6 +22,8 @@ | |||
22 | #include "editorwindow.h" | 22 | #include "editorwindow.h" |
23 | #include "projectmodel.h" | 23 | #include "projectmodel.h" |
24 | #include "ui_editorwindow.h" | 24 | #include "ui_editorwindow.h" |
25 | #include "rbfontcache.h" | ||
26 | #include "rbtextcache.h" | ||
25 | 27 | ||
26 | #include <QDesktopWidget> | 28 | #include <QDesktopWidget> |
27 | #include <QFileSystemModel> | 29 | #include <QFileSystemModel> |
@@ -49,6 +51,9 @@ EditorWindow::~EditorWindow() | |||
49 | delete project; | 51 | delete project; |
50 | delete deviceConfig; | 52 | delete deviceConfig; |
51 | delete deviceDock; | 53 | delete deviceDock; |
54 | |||
55 | RBFontCache::clearCache(); | ||
56 | RBTextCache::clearCache(); | ||
52 | } | 57 | } |
53 | 58 | ||
54 | void EditorWindow::loadTabFromSkinFile(QString fileName) | 59 | void EditorWindow::loadTabFromSkinFile(QString fileName) |
diff --git a/utils/themeeditor/gui/skindocument.cpp b/utils/themeeditor/gui/skindocument.cpp index 9a381a9589..f04c12d213 100644 --- a/utils/themeeditor/gui/skindocument.cpp +++ b/utils/themeeditor/gui/skindocument.cpp | |||
@@ -31,6 +31,8 @@ | |||
31 | 31 | ||
32 | #include <QDebug> | 32 | #include <QDebug> |
33 | 33 | ||
34 | const int SkinDocument::updateInterval = 500; | ||
35 | |||
34 | SkinDocument::SkinDocument(QLabel* statusLabel, ProjectModel* project, | 36 | SkinDocument::SkinDocument(QLabel* statusLabel, ProjectModel* project, |
35 | DeviceState* device, QWidget *parent) | 37 | DeviceState* device, QWidget *parent) |
36 | :TabContent(parent), statusLabel(statusLabel), | 38 | :TabContent(parent), statusLabel(statusLabel), |
@@ -70,6 +72,8 @@ SkinDocument::SkinDocument(QLabel* statusLabel, QString file, | |||
70 | /* Setting the title */ | 72 | /* Setting the title */ |
71 | QStringList decomposed = fileName.split('/'); | 73 | QStringList decomposed = fileName.split('/'); |
72 | titleText = decomposed.last(); | 74 | titleText = decomposed.last(); |
75 | |||
76 | lastUpdate = QTime::currentTime(); | ||
73 | } | 77 | } |
74 | 78 | ||
75 | SkinDocument::~SkinDocument() | 79 | SkinDocument::~SkinDocument() |
@@ -161,6 +165,11 @@ void SkinDocument::setupUI() | |||
161 | findReplace->hide(); | 165 | findReplace->hide(); |
162 | 166 | ||
163 | settingsChanged(); | 167 | settingsChanged(); |
168 | |||
169 | /* Setting up a timer to check for updates */ | ||
170 | checkUpdate.setInterval(500); | ||
171 | QObject::connect(&checkUpdate, SIGNAL(timeout()), | ||
172 | this, SLOT(codeChanged())); | ||
164 | } | 173 | } |
165 | 174 | ||
166 | void SkinDocument::settingsChanged() | 175 | void SkinDocument::settingsChanged() |
@@ -273,8 +282,16 @@ void SkinDocument::codeChanged() | |||
273 | else | 282 | else |
274 | emit titleChanged(titleText); | 283 | emit titleChanged(titleText); |
275 | 284 | ||
276 | model->render(project, device, &fileName); | 285 | if(lastUpdate.msecsTo(QTime::currentTime()) >= updateInterval) |
277 | 286 | { | |
287 | model->render(project, device, &fileName); | ||
288 | checkUpdate.stop(); | ||
289 | lastUpdate = QTime::currentTime(); | ||
290 | } | ||
291 | else | ||
292 | { | ||
293 | checkUpdate.start(); | ||
294 | } | ||
278 | cursorChanged(); | 295 | cursorChanged(); |
279 | 296 | ||
280 | } | 297 | } |
diff --git a/utils/themeeditor/gui/skindocument.h b/utils/themeeditor/gui/skindocument.h index 7563b3cb53..f7ac2bbc2c 100644 --- a/utils/themeeditor/gui/skindocument.h +++ b/utils/themeeditor/gui/skindocument.h | |||
@@ -26,6 +26,8 @@ | |||
26 | #include <QLabel> | 26 | #include <QLabel> |
27 | #include <QHBoxLayout> | 27 | #include <QHBoxLayout> |
28 | #include <QGraphicsScene> | 28 | #include <QGraphicsScene> |
29 | #include <QTime> | ||
30 | #include <QTimer> | ||
29 | 31 | ||
30 | #include "findreplacedialog.h" | 32 | #include "findreplacedialog.h" |
31 | 33 | ||
@@ -113,6 +115,10 @@ private: | |||
113 | DeviceState* device; | 115 | DeviceState* device; |
114 | 116 | ||
115 | FindReplaceDialog* findReplace; | 117 | FindReplaceDialog* findReplace; |
118 | |||
119 | QTime lastUpdate; | ||
120 | static const int updateInterval; | ||
121 | QTimer checkUpdate; | ||
116 | }; | 122 | }; |
117 | 123 | ||
118 | #endif // SKINDOCUMENT_H | 124 | #endif // SKINDOCUMENT_H |
diff --git a/utils/themeeditor/themeeditor.pro b/utils/themeeditor/themeeditor.pro index b0824cfe84..904adf239b 100644 --- a/utils/themeeditor/themeeditor.pro +++ b/utils/themeeditor/themeeditor.pro | |||
@@ -1,3 +1,7 @@ | |||
1 | # Enabling profiling | ||
2 | QMAKE_CXXFLAGS_DEBUG += -pg | ||
3 | QMAKE_LFLAGS_DEBUG += -pg | ||
4 | |||
1 | # build in a separate folder. | 5 | # build in a separate folder. |
2 | MYBUILDDIR = $$OUT_PWD/build/ | 6 | MYBUILDDIR = $$OUT_PWD/build/ |
3 | OBJECTS_DIR = $$MYBUILDDIR/o | 7 | OBJECTS_DIR = $$MYBUILDDIR/o |
@@ -47,7 +51,8 @@ HEADERS += models/parsetreemodel.h \ | |||
47 | graphics/rbprogressbar.h \ | 51 | graphics/rbprogressbar.h \ |
48 | gui/findreplacedialog.h \ | 52 | gui/findreplacedialog.h \ |
49 | graphics/rbtext.h \ | 53 | graphics/rbtext.h \ |
50 | graphics/rbfontcache.h | 54 | graphics/rbfontcache.h \ |
55 | graphics/rbtextcache.h | ||
51 | SOURCES += main.cpp \ | 56 | SOURCES += main.cpp \ |
52 | models/parsetreemodel.cpp \ | 57 | models/parsetreemodel.cpp \ |
53 | models/parsetreenode.cpp \ | 58 | models/parsetreenode.cpp \ |
@@ -69,7 +74,8 @@ SOURCES += main.cpp \ | |||
69 | graphics/rbprogressbar.cpp \ | 74 | graphics/rbprogressbar.cpp \ |
70 | gui/findreplacedialog.cpp \ | 75 | gui/findreplacedialog.cpp \ |
71 | graphics/rbtext.cpp \ | 76 | graphics/rbtext.cpp \ |
72 | graphics/rbfontcache.cpp | 77 | graphics/rbfontcache.cpp \ |
78 | graphics/rbtextcache.cpp | ||
73 | OTHER_FILES += README \ | 79 | OTHER_FILES += README \ |
74 | resources/windowicon.png \ | 80 | resources/windowicon.png \ |
75 | resources/appicon.xcf \ | 81 | resources/appicon.xcf \ |