summaryrefslogtreecommitdiffstats
path: root/utils/themeeditor
diff options
context:
space:
mode:
authorRobert Bieber <robby@bieberphoto.com>2010-06-30 07:00:05 +0000
committerRobert Bieber <robby@bieberphoto.com>2010-06-30 07:00:05 +0000
commitd2ed594246d2840ee09445483a03bb4b5baaff4b (patch)
tree6450cfeb0d3ecc0fb391e601a1f2ba7998cf6e7e /utils/themeeditor
parentce4da595e15bf42eac03f0dc6cc7e513649a3f77 (diff)
downloadrockbox-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')
-rw-r--r--utils/themeeditor/graphics/rbviewport.cpp82
-rw-r--r--utils/themeeditor/graphics/rbviewport.h17
-rw-r--r--utils/themeeditor/models/parsetreenode.cpp21
3 files changed, 114 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)
: QGraphicsItem(info.screen()), font(info.screen()->getFont(0)),
foreground(info.screen()->foreground()),
background(info.screen()->background()), textOffset(0,0),
- screen(info.screen())
+ screen(info.screen()), textAlign(Left)
{
if(!node->tag)
{
@@ -108,6 +108,8 @@ RBViewport::RBViewport(skin_element* node, const RBRenderInfo& info)
size = QRectF(0, 0, w, h);
debug = info.device()->data("showviewports").toBool();
}
+
+ lineHeight = font->lineHeight();
}
RBViewport::~RBViewport()
@@ -142,17 +144,85 @@ void RBViewport::paint(QPainter *painter,
void RBViewport::newLine()
{
- if(textOffset.x() > 0)
+ if(leftText.count() != 0
+ || centerText.count() != 0
+ || rightText.count() != 0)
{
textOffset.setY(textOffset.y() + lineHeight);
textOffset.setX(0);
+ textAlign = Left;
+ leftText.clear();
+ rightText.clear();
+ centerText.clear();
}
}
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();
+ if(textAlign == Left)
+ {
+ leftText.append(font->renderText(text, foreground, this));
+ alignLeft();
+ }
+ else if(textAlign == Center)
+ {
+ centerText.append(font->renderText(text, foreground, this));
+ alignCenter();
+ }
+ else if(textAlign == Right)
+ {
+ rightText.append(font->renderText(text, foreground, this));
+ alignRight();
+ }
+}
+
+void RBViewport::alignLeft()
+{
+ int y = textOffset.y();
+ int x = 0;
+
+ for(int i = 0; i < leftText.count(); i++)
+ {
+ leftText[i]->setPos(x, y);
+ x += leftText[i]->boundingRect().width();
+ }
+}
+
+void RBViewport::alignCenter()
+{
+ int y = textOffset.y();
+ int x = 0;
+ int width = 0;
+
+ for(int i = 0; i < centerText.count(); i++)
+ width += centerText[i]->boundingRect().width();
+
+ x = (size.width() - width) / 2;
+
+ for(int i = 0; i < centerText.count(); i++)
+ {
+ centerText[i]->setPos(x, y);
+ x += centerText[i]->boundingRect().width();
+ }
}
+
+void RBViewport::alignRight()
+{
+
+ int y = textOffset.y();
+ int x = 0;
+ int width = 0;
+
+ for(int i = 0; i < rightText.count(); i++)
+ width += rightText[i]->boundingRect().width();
+
+ x = size.width() - width;
+
+ for(int i = 0; i < rightText.count(); i++)
+ {
+ rightText[i]->setPos(x, y);
+ x += rightText[i]->boundingRect().width();
+ }
+
+}
+
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;
class RBViewport : public QGraphicsItem
{
public:
+ enum Alignment
+ {
+ Left,
+ Center,
+ Right
+ };
+
RBViewport(skin_element* node, const RBRenderInfo& info);
virtual ~RBViewport();
@@ -48,9 +55,14 @@ public:
void newLine();
void write(QString text);
+ void alignText(Alignment align){ textAlign = align; }
private:
+ void alignLeft();
+ void alignCenter();
+ void alignRight();
+
QRectF size;
RBFont* font;
QColor foreground;
@@ -62,6 +74,11 @@ private:
int lineHeight;
RBScreen* screen;
+
+ QList<QGraphicsItem*> leftText;
+ QList<QGraphicsItem*> centerText;
+ QList<QGraphicsItem*> rightText;
+ Alignment textAlign;
};
#endif // RBVIEWPORT_H
diff --git a/utils/themeeditor/models/parsetreenode.cpp b/utils/themeeditor/models/parsetreenode.cpp
index 6c20a1d62e..c56592e2de 100644
--- a/utils/themeeditor/models/parsetreenode.cpp
+++ b/utils/themeeditor/models/parsetreenode.cpp
@@ -590,6 +590,27 @@ bool ParseTreeNode::execTag(const RBRenderInfo& info, RBViewport* viewport)
switch(element->tag->name[0])
{
+ case 'a':
+ switch(element->tag->name[1])
+ {
+ case 'c':
+ /* %ac */
+ viewport->alignText(RBViewport::Center);
+ return true;
+
+ case 'l':
+ /* %al */
+ viewport->alignText(RBViewport::Left);
+ return true;
+
+ case 'r':
+ /* %ar */
+ viewport->alignText(RBViewport::Right);
+ return true;
+ }
+
+ break;
+
case 'x':
switch(element->tag->name[1])
{