[TD] Make dimension number graphical layout more compact by making boundingRect() tighter for dimension number labels.
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -47,6 +47,8 @@ public:
|
||||
enum {Type = QGraphicsItem::UserType + 130};
|
||||
int type() const { return Type;}
|
||||
virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0 );
|
||||
virtual QRectF boundingRect() const override;
|
||||
QRectF tightBoundingRect() const;
|
||||
|
||||
void setHighlighted(bool state);
|
||||
virtual void setPrettyNormal();
|
||||
@@ -68,6 +70,8 @@ public:
|
||||
virtual QColor getSelectColor(void);
|
||||
virtual void setColor(QColor c);
|
||||
|
||||
virtual void setTightBounding(bool tight);
|
||||
|
||||
void makeMark(double x, double y);
|
||||
void makeMark(Base::Vector3d v);
|
||||
|
||||
@@ -79,6 +83,7 @@ protected:
|
||||
Base::Reference<ParameterGrp> getParmGroup(void);
|
||||
|
||||
bool isHighlighted;
|
||||
bool tightBounding;
|
||||
QColor m_colCurrent;
|
||||
QColor m_colNormal;
|
||||
|
||||
|
||||
@@ -107,12 +107,16 @@ QGIDatumLabel::QGIDatumLabel()
|
||||
setFiltersChildEvents(true);
|
||||
|
||||
m_dimText = new QGCustomText();
|
||||
m_dimText->setTightBounding(true);
|
||||
m_dimText->setParentItem(this);
|
||||
m_tolTextOver = new QGCustomText();
|
||||
m_tolTextOver->setTightBounding(true);
|
||||
m_tolTextOver->setParentItem(this);
|
||||
m_tolTextUnder = new QGCustomText();
|
||||
m_tolTextUnder->setTightBounding(true);
|
||||
m_tolTextUnder->setParentItem(this);
|
||||
m_unitText = new QGCustomText();
|
||||
m_unitText->setTightBounding(true);
|
||||
m_unitText->setParentItem(this);
|
||||
|
||||
m_ctrl = false;
|
||||
@@ -266,8 +270,8 @@ void QGIDatumLabel::setPosFromCenter(const double &xCenter, const double &yCente
|
||||
}
|
||||
double tolRight = unitRight + width;
|
||||
|
||||
m_tolTextOver->justifyRightAt(tolRight, middle, false);
|
||||
m_tolTextUnder->justifyRightAt(tolRight, middle + underBox.height(), false);
|
||||
m_tolTextOver->justifyRightAt(tolRight, middle - overBox.height() + underBox.height()/4, false);
|
||||
m_tolTextUnder->justifyRightAt(tolRight, middle + underBox.height()/4, false);
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user