Theme Editor: Implemented text alignment
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27191 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
ce4da595e1
commit
d2ed594246
3 changed files with 114 additions and 6 deletions
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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])
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue