[TD] Add comments and more transparent tolerance position adjustment calculation.

This commit is contained in:
Aapo
2020-11-28 02:03:37 +02:00
committed by wwmayer
parent 4ed3c99e3e
commit 4e06414552
3 changed files with 18 additions and 4 deletions

View File

@@ -210,11 +210,22 @@ QRectF QGCustomText::tightBoundingRect() const
qreal x_adj = (result.width() - tight.width())/4.0;
qreal y_adj = (result.height() - tight.height())/4.0;
// Adjust the bounding box 50% towards the Qt tightBoundingRect(),
// except chomp some extra empty space above the font (2*y_adj)
result.adjust(x_adj, 2*y_adj, -x_adj, -y_adj);
return result;
}
// Calculate the amount of difference between tight and relaxed bounding boxes
QPointF QGCustomText::tightBoundingAdjust() const
{
QRectF original = QGraphicsTextItem::boundingRect();
QRectF tight = tightBoundingRect();
return QPointF(tight.x()-original.x(), tight.y()-original.y());
}
QColor QGCustomText::getNormalColor() //preference!
{
return PreferencesGui::normalQColor();

View File

@@ -49,6 +49,7 @@ public:
virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0 );
virtual QRectF boundingRect() const override;
QRectF tightBoundingRect() const;
QPointF tightBoundingAdjust() const;
void setHighlighted(bool state);
virtual void setPrettyNormal();
@@ -83,7 +84,7 @@ protected:
Base::Reference<ParameterGrp> getParmGroup(void);
bool isHighlighted;
bool tightBounding;
bool tightBounding; // Option to use tighter boundingRect(), works only for plaintext QGCustomText
QColor m_colCurrent;
QColor m_colNormal;

View File

@@ -270,9 +270,11 @@ void QGIDatumLabel::setPosFromCenter(const double &xCenter, const double &yCente
}
double tolRight = unitRight + width;
m_tolTextOver->justifyRightAt(tolRight, middle - overBox.height() + underBox.height()/4, false);
m_tolTextUnder->justifyRightAt(tolRight, middle + underBox.height()/4, false);
// Adjust for difference in tight and original bounding box sizes, note the y-coord down system
QPointF tol_adj = m_tolTextOver->tightBoundingAdjust();
m_tolTextOver->justifyRightAt(tolRight + tol_adj.x(), middle - tol_adj.y(), false);
tol_adj = m_tolTextUnder->tightBoundingAdjust();
m_tolTextUnder->justifyRightAt(tolRight + tol_adj.x(), middle + overBox.height() - tol_adj.y(), false);
}
void QGIDatumLabel::setLabelCenter()