Fix : element text item alignment work well when text rotation != 0.

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@5357 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
blacksun
2018-05-12 12:59:49 +00:00
parent 748986ceec
commit f975cb4d3b
2 changed files with 27 additions and 10 deletions

View File

@@ -345,38 +345,52 @@ void DiagramTextItem::applyRotation(const qreal &angle) {
*/ */
void DiagramTextItem::prepareAlignment() void DiagramTextItem::prepareAlignment()
{ {
m_alignment_rect = mapToParent(boundingRect()).boundingRect(); m_alignment_rect = boundingRect();
} }
/** /**
* @brief DiagramTextItem::finishAlignment * @brief DiagramTextItem::finishAlignment
* Call this function after changing the bouding rect of this text * Call this function after changing the bouding rect of this text
* to set the position of this text according the alignment property. * to set the position of this text according to the alignment property.
*/ */
void DiagramTextItem::finishAlignment() void DiagramTextItem::finishAlignment()
{ {
if(m_block_alignment) if(m_block_alignment)
return; return;
QPointF pos = this->pos(); QTransform transform;
transform.rotate(this->rotation());
qreal x,xa, y,ya;
x=xa=0;
y=ya=0;
if(m_alignment &Qt::AlignRight) if(m_alignment &Qt::AlignRight)
pos.setX(m_alignment_rect.right() - boundingRect().width()); {
x = m_alignment_rect.right();
xa = boundingRect().right();
}
else if(m_alignment &Qt::AlignHCenter) else if(m_alignment &Qt::AlignHCenter)
{ {
qreal x = m_alignment_rect.x() + (m_alignment_rect.width()/2); x = m_alignment_rect.center().x();
pos.setX(x - boundingRect().width()/2); xa = boundingRect().center().x();
} }
if(m_alignment &Qt::AlignBottom) if(m_alignment &Qt::AlignBottom)
pos.setY(m_alignment_rect.bottom() - boundingRect().height()); {
y = m_alignment_rect.bottom();
ya = boundingRect().bottom();
}
else if(m_alignment &Qt::AlignVCenter) else if(m_alignment &Qt::AlignVCenter)
{ {
qreal y = m_alignment_rect.y() + (m_alignment_rect.height()/2); y = m_alignment_rect.center().y();
pos.setY(y - boundingRect().height()/2); ya = boundingRect().center().y();
} }
setPos(pos); QPointF p = transform.map(QPointF(x,y));
QPointF pa = transform.map(QPointF(xa,ya));
QPointF diff = pa-p;
setPos(this->pos() - diff);
} }
/** /**

View File

@@ -1314,6 +1314,9 @@ void DynamicElementTextItem::updateXref()
void DynamicElementTextItem::setPlainText(const QString &text) void DynamicElementTextItem::setPlainText(const QString &text)
{ {
if(toPlainText() == text)
return;
prepareAlignment(); prepareAlignment();
DiagramTextItem::setPlainText(text); DiagramTextItem::setPlainText(text);