1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

tweaked layout calculation

This commit is contained in:
krepa098 2015-02-09 17:45:48 +01:00
parent 535757670b
commit 3f6e68db95

View File

@ -185,11 +185,11 @@ void ChatLine::layout(qreal w, QPointF scenePos)
qreal maxVOffset = 0.0; qreal maxVOffset = 0.0;
qreal xOffset = 0.0; qreal xOffset = 0.0;
qreal xPos[content.size()];
for(int i = 0; i < static_cast<int>(content.size()); ++i) for(int i = 0; i < static_cast<int>(content.size()); ++i)
{ {
maxVOffset = qMax(maxVOffset, content[i]->getAscent());
// calculate the effective width of the current column // calculate the effective width of the current column
qreal width; qreal width;
if(format[i].policy == ColumnFormat::FixedSize) if(format[i].policy == ColumnFormat::FixedSize)
@ -216,21 +216,20 @@ void ChatLine::layout(qreal w, QPointF scenePos)
} }
// reposition // reposition
content[i]->setPos(scenePos.x() + xOffset + xAlign, scenePos.y()); xPos[i] = scenePos.x() + xOffset + xAlign;
xOffset += width + columnSpacing; xOffset += width + columnSpacing;
maxVOffset = qMax(maxVOffset, content[i]->getAscent());
} }
for(int i = 0; i < static_cast<int>(content.size()); ++i) for(int i = 0; i < static_cast<int>(content.size()); ++i)
{ {
// calculate vertical alignment // calculate vertical alignment
// vertical alignment may depend on width, so we do it in a second pass // vertical alignment may depend on width, so we do it in a second pass
qreal yOffset = 0.0; qreal yOffset = maxVOffset - content[i]->getAscent();
yOffset = maxVOffset - content[i]->getAscent();
// reposition // reposition
content[i]->setPos(content[i]->pos().x(), content[i]->pos().y() + yOffset); content[i]->setPos(xPos[i], scenePos.y() + yOffset);
} }
updateBBox(); updateBBox();