[TechDraw] Fix uncentered balloon label
This commit is contained in:
committed by
WandererFan
parent
e6e6b1b1e5
commit
fa6c81d23e
@@ -218,6 +218,28 @@ QPointF QGCustomText::tightBoundingAdjust() const
|
||||
return QPointF(tight.x()-original.x(), tight.y()-original.y());
|
||||
}
|
||||
|
||||
// TODO: when setting position, it doesn't take into account the tight bounding rect
|
||||
// Meaning top left corner has distance to pos(0, 0)
|
||||
// Here is a sketch for a fix
|
||||
// Note that the position adjustment will have to carried out every time the font changes
|
||||
// void QGCustomText::setPos(const QPointF &pos) {
|
||||
// if(tightBounding) {
|
||||
// QGraphicsTextItem::setPos(pos.x() - tightBoundingAdjust().x(), pos.y() - tightBoundingAdjust().y());
|
||||
// return;
|
||||
// }
|
||||
// QGraphicsTextItem::setPos(pos);
|
||||
// }
|
||||
|
||||
// void QGCustomText::setPos(qreal x, qreal y) {
|
||||
// setPos(QPointF(x, y));
|
||||
// }
|
||||
|
||||
// QPointF QGCustomText::pos() const
|
||||
// {
|
||||
// // Native Qt pos function doesn't take into account the tight bounding rect
|
||||
// return boundingRect().topLeft();
|
||||
// }
|
||||
|
||||
QColor QGCustomText::getNormalColor() //preference!
|
||||
{
|
||||
return PreferencesGui::normalQColor();
|
||||
|
||||
@@ -52,6 +52,9 @@ public:
|
||||
QRectF boundingRect() const override;
|
||||
QRectF tightBoundingRect() const;
|
||||
QPointF tightBoundingAdjust() const;
|
||||
// void setPos(const QPointF &pos);
|
||||
// void setPos(qreal x, qreal y);
|
||||
// QPointF pos() const;
|
||||
|
||||
void setHighlighted(bool state);
|
||||
virtual void setPrettyNormal();
|
||||
|
||||
@@ -66,8 +66,6 @@ using DGU = DrawGuiUtil;
|
||||
|
||||
QGIBalloonLabel::QGIBalloonLabel()
|
||||
{
|
||||
posX = 0;
|
||||
posY = 0;
|
||||
m_ctrl = false;
|
||||
m_drag = false;
|
||||
|
||||
@@ -78,6 +76,7 @@ QGIBalloonLabel::QGIBalloonLabel()
|
||||
setAcceptHoverEvents(true);
|
||||
|
||||
m_labelText = new QGCustomText();
|
||||
m_labelText->setTightBounding(true);
|
||||
m_labelText->setParentItem(this);
|
||||
|
||||
verticalSep = false;
|
||||
@@ -99,7 +98,6 @@ QVariant QGIBalloonLabel::itemChange(GraphicsItemChange change, const QVariant&
|
||||
update();
|
||||
}
|
||||
else if (change == ItemPositionHasChanged && scene()) {
|
||||
setLabelCenter();
|
||||
if (m_drag) {
|
||||
Q_EMIT dragging(m_ctrl);
|
||||
}
|
||||
@@ -195,20 +193,13 @@ void QGIBalloonLabel::paint(QPainter* painter, const QStyleOptionGraphicsItem* o
|
||||
void QGIBalloonLabel::setPosFromCenter(const double& xCenter, const double& yCenter)
|
||||
{
|
||||
//set label's Qt position(top, left) given boundingRect center point
|
||||
setPos(xCenter - m_labelText->boundingRect().width() / 2.,
|
||||
yCenter - m_labelText->boundingRect().height() / 2.);
|
||||
}
|
||||
|
||||
void QGIBalloonLabel::setLabelCenter()
|
||||
{
|
||||
//save label's bRect center (posX, posY) given Qt position (top, left)
|
||||
posX = x() + m_labelText->boundingRect().width() / 2.;
|
||||
posY = y() + m_labelText->boundingRect().height() / 2.;
|
||||
setPos(xCenter - m_labelText->boundingRect().center().x(),
|
||||
yCenter - m_labelText->boundingRect().center().y());
|
||||
}
|
||||
|
||||
Base::Vector3d QGIBalloonLabel::getLabelCenter() const
|
||||
{
|
||||
return Base::Vector3d(posX, posY, 0.0);
|
||||
return Base::Vector3d(getCenterX(), getCenterY(), 0.0);
|
||||
}
|
||||
|
||||
void QGIBalloonLabel::setFont(QFont font) { m_labelText->setFont(font); }
|
||||
@@ -504,8 +495,8 @@ void QGIViewBalloon::balloonLabelDragFinished()
|
||||
scale = balloonParent->getScale();
|
||||
|
||||
//set feature position (x, y) from graphic position
|
||||
double x = Rez::appX(balloonLabel->X() / scale);
|
||||
double y = Rez::appX(balloonLabel->Y() / scale);
|
||||
double x = Rez::appX(balloonLabel->getCenterX() / scale);
|
||||
double y = Rez::appX(balloonLabel->getCenterY() / scale);
|
||||
Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Drag Balloon"));
|
||||
Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.%s.X = %f",
|
||||
dvb->getNameInDocument(), x);
|
||||
@@ -1002,8 +993,8 @@ void QGIViewBalloon::getBalloonPoints(TechDraw::DrawViewBalloon* balloon, DrawVi
|
||||
arrowTipPosInParent = DGU::toGuiPoint(refObj, originApp);
|
||||
}
|
||||
else {
|
||||
x = balloonLabel->X();
|
||||
y = -balloonLabel->Y(); // invert from Qt scene units to R2 mm
|
||||
x = balloonLabel->getCenterX();
|
||||
y = -balloonLabel->getCenterY(); // invert from Qt scene units to R2 mm
|
||||
if (m_originDragged) {
|
||||
// moving the whole bubble object. do not adjust origin point.
|
||||
arrowTipPosInParent = arrowPosInDrag();
|
||||
|
||||
@@ -80,14 +80,15 @@ public:
|
||||
void setLabelCenter();
|
||||
Base::Vector3d getLabelCenter() const;
|
||||
void setPosFromCenter(const double& xCenter, const double& yCenter);
|
||||
double X() const
|
||||
|
||||
double getCenterX() const
|
||||
{
|
||||
return posX;
|
||||
return mapToParent(m_labelText->boundingRect().center()).x();
|
||||
}
|
||||
double Y() const
|
||||
double getCenterY() const
|
||||
{
|
||||
return posY;
|
||||
}//minus posY?
|
||||
return mapToParent(m_labelText->boundingRect().center()).y();
|
||||
}
|
||||
|
||||
void setFont(QFont font);
|
||||
QFont getFont()
|
||||
@@ -114,6 +115,7 @@ public:
|
||||
|
||||
void setDimText(QGCustomText* newText)
|
||||
{
|
||||
newText->setTightBounding(true);
|
||||
m_labelText = newText;
|
||||
}
|
||||
bool getVerticalSep() const
|
||||
@@ -132,6 +134,7 @@ public:
|
||||
{
|
||||
seps = newSeps;
|
||||
}
|
||||
QGCustomText* m_labelText;
|
||||
|
||||
Q_SIGNALS:
|
||||
void dragging(bool state);
|
||||
@@ -153,11 +156,8 @@ private:
|
||||
bool verticalSep;
|
||||
std::vector<int> seps;
|
||||
|
||||
QGCustomText* m_labelText;
|
||||
QColor m_colNormal;
|
||||
|
||||
double posX;
|
||||
double posY;
|
||||
bool m_ctrl;
|
||||
bool m_drag;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user