diff options
author | Robert Bieber <robby@bieberphoto.com> | 2010-06-30 07:00:05 +0000 |
---|---|---|
committer | Robert Bieber <robby@bieberphoto.com> | 2010-06-30 07:00:05 +0000 |
commit | d2ed594246d2840ee09445483a03bb4b5baaff4b (patch) | |
tree | 6450cfeb0d3ecc0fb391e601a1f2ba7998cf6e7e /utils/themeeditor/graphics | |
parent | ce4da595e15bf42eac03f0dc6cc7e513649a3f77 (diff) | |
download | rockbox-d2ed594246d2840ee09445483a03bb4b5baaff4b.tar.gz rockbox-d2ed594246d2840ee09445483a03bb4b5baaff4b.zip |
Theme Editor: Implemented text alignment
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27191 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'utils/themeeditor/graphics')
-rw-r--r-- | utils/themeeditor/graphics/rbviewport.cpp | 82 | ||||
-rw-r--r-- | utils/themeeditor/graphics/rbviewport.h | 17 |
2 files changed, 93 insertions, 6 deletions
diff --git a/utils/themeeditor/graphics/rbviewport.cpp b/utils/themeeditor/graphics/rbviewport.cpp index 80ab5dce0b..22b2ada158 100644 --- a/utils/themeeditor/graphics/rbviewport.cpp +++ b/utils/themeeditor/graphics/rbviewport.cpp | |||
@@ -33,7 +33,7 @@ RBViewport::RBViewport(skin_element* node, const RBRenderInfo& info) | |||
33 | : QGraphicsItem(info.screen()), font(info.screen()->getFont(0)), | 33 | : QGraphicsItem(info.screen()), font(info.screen()->getFont(0)), |
34 | foreground(info.screen()->foreground()), | 34 | foreground(info.screen()->foreground()), |
35 | background(info.screen()->background()), textOffset(0,0), | 35 | background(info.screen()->background()), textOffset(0,0), |
36 | screen(info.screen()) | 36 | screen(info.screen()), textAlign(Left) |
37 | { | 37 | { |
38 | if(!node->tag) | 38 | if(!node->tag) |
39 | { | 39 | { |
@@ -108,6 +108,8 @@ RBViewport::RBViewport(skin_element* node, const RBRenderInfo& info) | |||
108 | size = QRectF(0, 0, w, h); | 108 | size = QRectF(0, 0, w, h); |
109 | debug = info.device()->data("showviewports").toBool(); | 109 | debug = info.device()->data("showviewports").toBool(); |
110 | } | 110 | } |
111 | |||
112 | lineHeight = font->lineHeight(); | ||
111 | } | 113 | } |
112 | 114 | ||
113 | RBViewport::~RBViewport() | 115 | RBViewport::~RBViewport() |
@@ -142,17 +144,85 @@ void RBViewport::paint(QPainter *painter, | |||
142 | 144 | ||
143 | void RBViewport::newLine() | 145 | void RBViewport::newLine() |
144 | { | 146 | { |
145 | if(textOffset.x() > 0) | 147 | if(leftText.count() != 0 |
148 | || centerText.count() != 0 | ||
149 | || rightText.count() != 0) | ||
146 | { | 150 | { |
147 | textOffset.setY(textOffset.y() + lineHeight); | 151 | textOffset.setY(textOffset.y() + lineHeight); |
148 | textOffset.setX(0); | 152 | textOffset.setX(0); |
153 | textAlign = Left; | ||
154 | leftText.clear(); | ||
155 | rightText.clear(); | ||
156 | centerText.clear(); | ||
149 | } | 157 | } |
150 | } | 158 | } |
151 | 159 | ||
152 | void RBViewport::write(QString text) | 160 | void RBViewport::write(QString text) |
153 | { | 161 | { |
154 | QGraphicsItem* graphic = font->renderText(text, foreground, this); | 162 | if(textAlign == Left) |
155 | graphic->setPos(textOffset.x(), textOffset.y()); | 163 | { |
156 | textOffset.setX(textOffset.x() + graphic->boundingRect().width()); | 164 | leftText.append(font->renderText(text, foreground, this)); |
157 | lineHeight = font->lineHeight(); | 165 | alignLeft(); |
166 | } | ||
167 | else if(textAlign == Center) | ||
168 | { | ||
169 | centerText.append(font->renderText(text, foreground, this)); | ||
170 | alignCenter(); | ||
171 | } | ||
172 | else if(textAlign == Right) | ||
173 | { | ||
174 | rightText.append(font->renderText(text, foreground, this)); | ||
175 | alignRight(); | ||
176 | } | ||
177 | } | ||
178 | |||
179 | void RBViewport::alignLeft() | ||
180 | { | ||
181 | int y = textOffset.y(); | ||
182 | int x = 0; | ||
183 | |||
184 | for(int i = 0; i < leftText.count(); i++) | ||
185 | { | ||
186 | leftText[i]->setPos(x, y); | ||
187 | x += leftText[i]->boundingRect().width(); | ||
188 | } | ||
189 | } | ||
190 | |||
191 | void RBViewport::alignCenter() | ||
192 | { | ||
193 | int y = textOffset.y(); | ||
194 | int x = 0; | ||
195 | int width = 0; | ||
196 | |||
197 | for(int i = 0; i < centerText.count(); i++) | ||
198 | width += centerText[i]->boundingRect().width(); | ||
199 | |||
200 | x = (size.width() - width) / 2; | ||
201 | |||
202 | for(int i = 0; i < centerText.count(); i++) | ||
203 | { | ||
204 | centerText[i]->setPos(x, y); | ||
205 | x += centerText[i]->boundingRect().width(); | ||
206 | } | ||
158 | } | 207 | } |
208 | |||
209 | void RBViewport::alignRight() | ||
210 | { | ||
211 | |||
212 | int y = textOffset.y(); | ||
213 | int x = 0; | ||
214 | int width = 0; | ||
215 | |||
216 | for(int i = 0; i < rightText.count(); i++) | ||
217 | width += rightText[i]->boundingRect().width(); | ||
218 | |||
219 | x = size.width() - width; | ||
220 | |||
221 | for(int i = 0; i < rightText.count(); i++) | ||
222 | { | ||
223 | rightText[i]->setPos(x, y); | ||
224 | x += rightText[i]->boundingRect().width(); | ||
225 | } | ||
226 | |||
227 | } | ||
228 | |||
diff --git a/utils/themeeditor/graphics/rbviewport.h b/utils/themeeditor/graphics/rbviewport.h index c6f0c636c2..1d65eb8d56 100644 --- a/utils/themeeditor/graphics/rbviewport.h +++ b/utils/themeeditor/graphics/rbviewport.h | |||
@@ -33,6 +33,13 @@ class RBRenderInfo; | |||
33 | class RBViewport : public QGraphicsItem | 33 | class RBViewport : public QGraphicsItem |
34 | { | 34 | { |
35 | public: | 35 | public: |
36 | enum Alignment | ||
37 | { | ||
38 | Left, | ||
39 | Center, | ||
40 | Right | ||
41 | }; | ||
42 | |||
36 | RBViewport(skin_element* node, const RBRenderInfo& info); | 43 | RBViewport(skin_element* node, const RBRenderInfo& info); |
37 | virtual ~RBViewport(); | 44 | virtual ~RBViewport(); |
38 | 45 | ||
@@ -48,9 +55,14 @@ public: | |||
48 | 55 | ||
49 | void newLine(); | 56 | void newLine(); |
50 | void write(QString text); | 57 | void write(QString text); |
58 | void alignText(Alignment align){ textAlign = align; } | ||
51 | 59 | ||
52 | private: | 60 | private: |
53 | 61 | ||
62 | void alignLeft(); | ||
63 | void alignCenter(); | ||
64 | void alignRight(); | ||
65 | |||
54 | QRectF size; | 66 | QRectF size; |
55 | RBFont* font; | 67 | RBFont* font; |
56 | QColor foreground; | 68 | QColor foreground; |
@@ -62,6 +74,11 @@ private: | |||
62 | int lineHeight; | 74 | int lineHeight; |
63 | 75 | ||
64 | RBScreen* screen; | 76 | RBScreen* screen; |
77 | |||
78 | QList<QGraphicsItem*> leftText; | ||
79 | QList<QGraphicsItem*> centerText; | ||
80 | QList<QGraphicsItem*> rightText; | ||
81 | Alignment textAlign; | ||
65 | }; | 82 | }; |
66 | 83 | ||
67 | #endif // RBVIEWPORT_H | 84 | #endif // RBVIEWPORT_H |