summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--utils/themeeditor/graphics/rbfont.cpp5
-rw-r--r--utils/themeeditor/graphics/rbfont.h2
-rw-r--r--utils/themeeditor/graphics/rbtext.cpp14
-rw-r--r--utils/themeeditor/graphics/rbtext.h3
-rw-r--r--utils/themeeditor/graphics/rbviewport.cpp63
-rw-r--r--utils/themeeditor/graphics/rbviewport.h10
6 files changed, 59 insertions, 38 deletions
diff --git a/utils/themeeditor/graphics/rbfont.cpp b/utils/themeeditor/graphics/rbfont.cpp
index 1c2739d118..e8bff40e13 100644
--- a/utils/themeeditor/graphics/rbfont.cpp
+++ b/utils/themeeditor/graphics/rbfont.cpp
@@ -155,7 +155,8 @@ RBFont::~RBFont()
155 delete[] widthData; 155 delete[] widthData;
156} 156}
157 157
158RBText* RBFont::renderText(QString text, QColor color, QGraphicsItem *parent) 158RBText* RBFont::renderText(QString text, QColor color, int viewWidth,
159 QGraphicsItem *parent)
159{ 160{
160 int firstChar = header.value("firstchar").toInt(); 161 int firstChar = header.value("firstchar").toInt();
161 int height = header.value("height").toInt(); 162 int height = header.value("height").toInt();
@@ -221,6 +222,6 @@ RBText* RBFont::renderText(QString text, QColor color, QGraphicsItem *parent)
221 startX += widths[i]; 222 startX += widths[i];
222 } 223 }
223 224
224 return new RBText(image, parent); 225 return new RBText(image, viewWidth, parent);
225 226
226} 227}
diff --git a/utils/themeeditor/graphics/rbfont.h b/utils/themeeditor/graphics/rbfont.h
index bc695a0709..6169d92940 100644
--- a/utils/themeeditor/graphics/rbfont.h
+++ b/utils/themeeditor/graphics/rbfont.h
@@ -35,7 +35,7 @@ public:
35 RBFont(QString file); 35 RBFont(QString file);
36 virtual ~RBFont(); 36 virtual ~RBFont();
37 37
38 RBText* renderText(QString text, QColor color, 38 RBText* renderText(QString text, QColor color, int maxWidth,
39 QGraphicsItem* parent = 0); 39 QGraphicsItem* parent = 0);
40 int lineHeight(){ return header.value("height", 0).toInt(); } 40 int lineHeight(){ return header.value("height", 0).toInt(); }
41 41
diff --git a/utils/themeeditor/graphics/rbtext.cpp b/utils/themeeditor/graphics/rbtext.cpp
index 76b817793e..d7fe542ab1 100644
--- a/utils/themeeditor/graphics/rbtext.cpp
+++ b/utils/themeeditor/graphics/rbtext.cpp
@@ -23,18 +23,24 @@
23 23
24#include <QPainter> 24#include <QPainter>
25 25
26RBText::RBText(const QImage &image, QGraphicsItem *parent) 26RBText::RBText(const QImage &image, int maxWidth, QGraphicsItem *parent)
27 :QGraphicsItem(parent), image(image) 27 :QGraphicsItem(parent), image(image), maxWidth(maxWidth)
28{ 28{
29} 29}
30 30
31QRectF RBText::boundingRect() const 31QRectF RBText::boundingRect() const
32{ 32{
33 return QRectF(0, 0, image.width(), image.height()); 33 if(image.width() < maxWidth)
34 return QRectF(0, 0, image.width(), image.height());
35 else
36 return QRectF(0, 0, maxWidth, image.height());
34} 37}
35 38
36void RBText::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, 39void RBText::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
37 QWidget *widget) 40 QWidget *widget)
38{ 41{
39 painter->drawImage(0, 0, image, 0, 0, image.width(), image.height()); 42 if(image.width() < maxWidth)
43 painter->drawImage(0, 0, image, 0, 0, image.width(), image.height());
44 else
45 painter->drawImage(0, 0, image, 0, 0, maxWidth, image.height());
40} 46}
diff --git a/utils/themeeditor/graphics/rbtext.h b/utils/themeeditor/graphics/rbtext.h
index 37b1747705..d03505491e 100644
--- a/utils/themeeditor/graphics/rbtext.h
+++ b/utils/themeeditor/graphics/rbtext.h
@@ -28,7 +28,7 @@
28class RBText : public QGraphicsItem 28class RBText : public QGraphicsItem
29{ 29{
30public: 30public:
31 RBText(const QImage& image, QGraphicsItem* parent); 31 RBText(const 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,
@@ -36,6 +36,7 @@ public:
36 36
37private: 37private:
38 QImage image; 38 QImage image;
39 int maxWidth;
39 40
40}; 41};
41 42
diff --git a/utils/themeeditor/graphics/rbviewport.cpp b/utils/themeeditor/graphics/rbviewport.cpp
index 3b8a02dd87..77fe346090 100644
--- a/utils/themeeditor/graphics/rbviewport.cpp
+++ b/utils/themeeditor/graphics/rbviewport.cpp
@@ -33,7 +33,8 @@ RBViewport::RBViewport(skin_element* node, const RBRenderInfo& info)
33 : QGraphicsItem(info.screen()), foreground(info.screen()->foreground()), 33 : QGraphicsItem(info.screen()), foreground(info.screen()->foreground()),
34 background(info.screen()->background()), textOffset(0,0), 34 background(info.screen()->background()), textOffset(0,0),
35 screen(info.screen()), textAlign(Left), showStatusBar(false), 35 screen(info.screen()), textAlign(Left), showStatusBar(false),
36 statusBarTexture(":/render/statusbar.png") 36 statusBarTexture(":/render/statusbar.png"),
37 leftGraphic(0), centerGraphic(0), rightGraphic(0)
37{ 38{
38 if(!node->tag) 39 if(!node->tag)
39 { 40 {
@@ -173,26 +174,31 @@ void RBViewport::newLine()
173 textOffset.setY(textOffset.y() + lineHeight); 174 textOffset.setY(textOffset.y() + lineHeight);
174 textOffset.setX(0); 175 textOffset.setX(0);
175 textAlign = Left; 176 textAlign = Left;
177
176 leftText.clear(); 178 leftText.clear();
177 rightText.clear(); 179 rightText.clear();
178 centerText.clear(); 180 centerText.clear();
181
182 leftGraphic = 0;
183 centerGraphic = 0;
184 rightGraphic = 0;
179} 185}
180 186
181void RBViewport::write(QString text) 187void RBViewport::write(QString text)
182{ 188{
183 if(textAlign == Left) 189 if(textAlign == Left)
184 { 190 {
185 leftText.append(font->renderText(text, foreground, this)); 191 leftText.append(text);
186 alignLeft(); 192 alignLeft();
187 } 193 }
188 else if(textAlign == Center) 194 else if(textAlign == Center)
189 { 195 {
190 centerText.append(font->renderText(text, foreground, this)); 196 centerText.append(text);
191 alignCenter(); 197 alignCenter();
192 } 198 }
193 else if(textAlign == Right) 199 else if(textAlign == Right)
194 { 200 {
195 rightText.append(font->renderText(text, foreground, this)); 201 rightText.append(text);
196 alignRight(); 202 alignRight();
197 } 203 }
198} 204}
@@ -269,50 +275,53 @@ void RBViewport::showPlaylist(const RBRenderInfo &info, int start,
269void RBViewport::alignLeft() 275void RBViewport::alignLeft()
270{ 276{
271 int y = textOffset.y(); 277 int y = textOffset.y();
272 int x = 0;
273 278
274 for(int i = 0; i < leftText.count(); i++) 279 if(leftGraphic)
275 { 280 delete leftGraphic;
276 leftText[i]->setPos(x, y); 281
277 x += leftText[i]->boundingRect().width(); 282 leftGraphic = font->renderText(leftText, foreground, size.width(), this);
278 } 283 leftGraphic->setPos(0, y);
279} 284}
280 285
281void RBViewport::alignCenter() 286void RBViewport::alignCenter()
282{ 287{
283 int y = textOffset.y(); 288 int y = textOffset.y();
284 int x = 0; 289 int x = 0;
285 int width = 0;
286 290
287 for(int i = 0; i < centerText.count(); i++) 291 if(centerGraphic)
288 width += centerText[i]->boundingRect().width(); 292 delete centerGraphic;
289 293
290 x = (size.width() - width) / 2; 294 centerGraphic = font->renderText(centerText, foreground, size.width(),
295 this);
291 296
292 for(int i = 0; i < centerText.count(); i++) 297 if(centerGraphic->boundingRect().width() < size.width())
298 {
299 x = size.width() - centerGraphic->boundingRect().width();
300 x /= 2;
301 }
302 else
293 { 303 {
294 centerText[i]->setPos(x, y); 304 x = 0;
295 x += centerText[i]->boundingRect().width();
296 } 305 }
306
307 centerGraphic->setPos(x, y);
297} 308}
298 309
299void RBViewport::alignRight() 310void RBViewport::alignRight()
300{ 311{
301
302 int y = textOffset.y(); 312 int y = textOffset.y();
303 int x = 0; 313 int x = 0;
304 int width = 0;
305 314
306 for(int i = 0; i < rightText.count(); i++) 315 if(rightGraphic)
307 width += rightText[i]->boundingRect().width(); 316 delete rightGraphic;
308 317
309 x = size.width() - width; 318 rightGraphic = font->renderText(rightText, foreground, size.width(), this);
310 319
311 for(int i = 0; i < rightText.count(); i++) 320 if(rightGraphic->boundingRect().width() < size.width())
312 { 321 x = size.width() - rightGraphic->boundingRect().width();
313 rightText[i]->setPos(x, y); 322 else
314 x += rightText[i]->boundingRect().width(); 323 x = 0;
315 }
316 324
325 rightGraphic->setPos(x, y);
317} 326}
318 327
diff --git a/utils/themeeditor/graphics/rbviewport.h b/utils/themeeditor/graphics/rbviewport.h
index 624a9686da..81841d5cfa 100644
--- a/utils/themeeditor/graphics/rbviewport.h
+++ b/utils/themeeditor/graphics/rbviewport.h
@@ -84,13 +84,17 @@ private:
84 84
85 RBScreen* screen; 85 RBScreen* screen;
86 86
87 QList<QGraphicsItem*> leftText; 87 QString leftText;
88 QList<QGraphicsItem*> centerText; 88 QString centerText;
89 QList<QGraphicsItem*> rightText; 89 QString rightText;
90 Alignment textAlign; 90 Alignment textAlign;
91 91
92 bool showStatusBar; 92 bool showStatusBar;
93 QPixmap statusBarTexture; 93 QPixmap statusBarTexture;
94
95 RBText* leftGraphic;
96 RBText* centerGraphic;
97 RBText* rightGraphic;
94}; 98};
95 99
96#endif // RBVIEWPORT_H 100#endif // RBVIEWPORT_H