[TD] Make dimension number graphical layout more compact by making boundingRect() tighter for dimension number labels.

This commit is contained in:
Aapo
2020-11-26 14:07:38 +02:00
committed by wwmayer
parent a8728853d9
commit f2e91ec488
3 changed files with 44 additions and 3 deletions

View File

@@ -60,6 +60,7 @@ QGCustomText::QGCustomText(QGraphicsItem* parent) :
m_colCurrent = getNormalColor();
m_colNormal = m_colCurrent;
tightBounding = false;
}
void QGCustomText::centerAt(QPointF centerPos)
@@ -173,7 +174,12 @@ void QGCustomText::setColor(QColor c)
m_colNormal = c;
m_colCurrent = c;
QGraphicsTextItem::setDefaultTextColor(c);
}
}
void QGCustomText::setTightBounding(bool tight)
{
tightBounding = tight;
}
void QGCustomText::paint ( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget) {
QStyleOptionGraphicsItem myOption(*option);
@@ -185,6 +191,32 @@ void QGCustomText::paint ( QPainter * painter, const QStyleOptionGraphicsItem *
QGraphicsTextItem::paint (painter, &myOption, widget);
}
QRectF QGCustomText::boundingRect() const
{
if (toPlainText().isEmpty()) {
return QRectF();
}
if (tightBounding) {
return tightBoundingRect();
}
return QGraphicsTextItem::boundingRect();
}
QRectF QGCustomText::tightBoundingRect() const
{
QFontMetrics qfm(font());
QRectF result = QGraphicsTextItem::boundingRect();
QRectF tight = qfm.tightBoundingRect(toPlainText());
qreal x_adj = (result.width() - tight.width())/4.0;
qreal y_adj = (result.height() - tight.height())/4.0;
result.adjust(x_adj, 2*y_adj, -x_adj, -y_adj);
return result;
}
QColor QGCustomText::getNormalColor() //preference!
{
return PreferencesGui::normalQColor();