Dynamic element text item : add new feature -> alignment

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@5353 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
blacksun
2018-05-11 18:14:41 +00:00
parent bf12d337c9
commit 609fcc351f
10 changed files with 480 additions and 6 deletions

View File

@@ -171,6 +171,17 @@ QColor DiagramTextItem::color() const {
return defaultTextColor();
}
void DiagramTextItem::setAlignment(const Qt::Alignment &alignment)
{
m_alignment = alignment;
emit alignmentChanged(alignment);
}
Qt::Alignment DiagramTextItem::alignment() const
{
return m_alignment;
}
/**
* @brief DiagramTextItem::paint
* Draw this text field. This method draw the text by calling QGraphicsTextItem::paint.
@@ -328,6 +339,46 @@ void DiagramTextItem::applyRotation(const qreal &angle) {
setRotation(QET::correctAngle(rotation()+angle));
}
/**
* @brief DiagramTextItem::prepareAlignment
* Call this function before changing the bounding rect of this text.
*/
void DiagramTextItem::prepareAlignment()
{
m_alignment_rect = mapToParent(boundingRect()).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.
*/
void DiagramTextItem::finishAlignment()
{
if(m_block_alignment)
return;
QPointF pos = this->pos();
if(m_alignment &Qt::AlignRight)
pos.setX(m_alignment_rect.right() - boundingRect().width());
else if(m_alignment &Qt::AlignHCenter)
{
qreal x = m_alignment_rect.x() + (m_alignment_rect.width()/2);
pos.setX(x - boundingRect().width()/2);
}
if(m_alignment &Qt::AlignBottom)
pos.setY(m_alignment_rect.bottom() - boundingRect().height());
else if(m_alignment &Qt::AlignVCenter)
{
qreal y = m_alignment_rect.y() + (m_alignment_rect.height()/2);
pos.setY(y - boundingRect().height()/2);
}
setPos(pos);
}
/**
* @brief Edit the text with HtmlEditor
*/