mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-17 12:40:35 +01:00
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:
@@ -345,38 +345,52 @@ void DiagramTextItem::applyRotation(const qreal &angle) {
|
||||
*/
|
||||
void DiagramTextItem::prepareAlignment()
|
||||
{
|
||||
m_alignment_rect = mapToParent(boundingRect()).boundingRect();
|
||||
m_alignment_rect = boundingRect();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DiagramTextItem::finishAlignment
|
||||
* 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()
|
||||
{
|
||||
if(m_block_alignment)
|
||||
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)
|
||||
pos.setX(m_alignment_rect.right() - boundingRect().width());
|
||||
{
|
||||
x = m_alignment_rect.right();
|
||||
xa = boundingRect().right();
|
||||
}
|
||||
else if(m_alignment &Qt::AlignHCenter)
|
||||
{
|
||||
qreal x = m_alignment_rect.x() + (m_alignment_rect.width()/2);
|
||||
pos.setX(x - boundingRect().width()/2);
|
||||
x = m_alignment_rect.center().x();
|
||||
xa = boundingRect().center().x();
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
qreal y = m_alignment_rect.y() + (m_alignment_rect.height()/2);
|
||||
pos.setY(y - boundingRect().height()/2);
|
||||
y = m_alignment_rect.center().y();
|
||||
ya = boundingRect().center().y();
|
||||
}
|
||||
|
||||
QPointF p = transform.map(QPointF(x,y));
|
||||
QPointF pa = transform.map(QPointF(xa,ya));
|
||||
QPointF diff = pa-p;
|
||||
|
||||
setPos(pos);
|
||||
setPos(this->pos() - diff);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1314,6 +1314,9 @@ void DynamicElementTextItem::updateXref()
|
||||
|
||||
void DynamicElementTextItem::setPlainText(const QString &text)
|
||||
{
|
||||
if(toPlainText() == text)
|
||||
return;
|
||||
|
||||
prepareAlignment();
|
||||
|
||||
DiagramTextItem::setPlainText(text);
|
||||
|
||||
Reference in New Issue
Block a user