From 09f3e6738c1a37ef07980ed3242af0a9944e7e25 Mon Sep 17 00:00:00 2001 From: wandererfan Date: Mon, 1 Sep 2025 23:00:44 -0400 Subject: [PATCH] [TD]shrink selection frame --- src/Mod/TechDraw/Gui/QGIRichAnno.h | 1 - src/Mod/TechDraw/Gui/QGIView.cpp | 61 ++++++++++++++++++++++++------ src/Mod/TechDraw/Gui/QGIView.h | 1 + 3 files changed, 50 insertions(+), 13 deletions(-) diff --git a/src/Mod/TechDraw/Gui/QGIRichAnno.h b/src/Mod/TechDraw/Gui/QGIRichAnno.h index 0c5b994bca..13c8d4dde5 100644 --- a/src/Mod/TechDraw/Gui/QGIRichAnno.h +++ b/src/Mod/TechDraw/Gui/QGIRichAnno.h @@ -66,7 +66,6 @@ public: const QStyleOptionGraphicsItem * option, QWidget * widget = nullptr ) override; QRectF boundingRect() const override; - QRectF frameRect() const; void drawBorder() override; void updateView(bool update = false) override; diff --git a/src/Mod/TechDraw/Gui/QGIView.cpp b/src/Mod/TechDraw/Gui/QGIView.cpp index 8a9e85db65..5d62918318 100644 --- a/src/Mod/TechDraw/Gui/QGIView.cpp +++ b/src/Mod/TechDraw/Gui/QGIView.cpp @@ -714,23 +714,27 @@ void QGIView::layoutDecorations(const QRectF& contentArea, QPointF& outLabelPos, QPointF& outLockPos) const { - const qreal padding = 100.0; + constexpr double padding{10}; QRectF paddedContentArea = contentArea.adjusted(-padding, -padding, padding, padding); double frameWidth = qMax(paddedContentArea.width(), labelRect.width()); - double frameHeight = paddedContentArea.height() + (captionRect.height() / 2) + labelRect.height(); + double frameHeight = paddedContentArea.height(); outFrameRect = QRectF(paddedContentArea.center().x() - (frameWidth / 2), paddedContentArea.top(), frameWidth, - frameHeight); + frameHeight).adjusted(-padding, - padding, padding, padding); - outLabelPos = QPointF(outFrameRect.center().x() - (labelRect.width() / 2), - outFrameRect.bottom() - labelRect.height()); - - double view_width = getViewObject()->getRect().x(); - outCaptionPos = QPointF(view_width - (captionRect.width() / 2), - outLabelPos.y() - captionRect.height()); + double firstTextVerticalPos = outFrameRect.bottom(); + if (m_caption->toPlainText().isEmpty()) { + outLabelPos = QPointF(outFrameRect.center().x() - (labelRect.width() / 2), + firstTextVerticalPos); + } else { + outCaptionPos = QPointF(outFrameRect.center().x() - (captionRect.width() / 2), + firstTextVerticalPos); + outLabelPos = QPointF(outFrameRect.center().x() - (labelRect.width() / 2), + firstTextVerticalPos + captionRect.height()); + } outLockPos = QPointF(outFrameRect.left(), outFrameRect.bottom() - m_lockHeight); } @@ -754,7 +758,7 @@ void QGIView::drawBorder() QString labelStr = QString::fromStdString(getViewObject()->Label.getValue()); m_label->setPlainText(labelStr); - QRectF contentArea = customChildrenBoundingRect(); + QRectF contentArea = frameRect(); QRectF captionRect = m_caption->boundingRect(); QRectF labelRect = m_label->boundingRect(); @@ -775,8 +779,7 @@ void QGIView::drawBorder() m_decorPen.setColor(m_colCurrent); m_border->setPen(m_decorPen); m_border->setPos(0., 0.); - // Adjust the final border to make space for the label - m_border->setRect(finalFrameRect.adjusted(-2, -2, 2, -labelRect.height() + 2)); + m_border->setRect(finalFrameRect); prepareGeometryChange(); } @@ -792,6 +795,40 @@ void QGIView::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, Q QGraphicsItemGroup::paint(painter, &myOption, widget); } + +//! this is a specialized version of customChildrenBoundingRect used only for calculating the size +//! of the frame around selected views. +//! we could reduce code duplication here, but would incur an execution time cost to make a second +//! pass through the child items to add/subtract to the result of customChildrenBoundingRect. +QRectF QGIView::frameRect() const +{ + QList children = childItems(); + // exceptions not to be included in determining the frame rectangle + QRectF result; + for (auto& child : children) { + if (!child->isVisible()) { + continue; + } + if ( + child->type() != UserType::QGIRichAnno && + child->type() != UserType::QGEPath && + child->type() != UserType::QGMText && + child->type() != UserType::QGCustomBorder && + child->type() != UserType::QGCustomLabel && + child->type() != UserType::QGICaption && + child->type() != UserType::QGIVertex && + child->type() != UserType::QGICMark && + child->type() != UserType::QGIViewDimension && + child->type() != UserType::QGIViewBalloon) { + QRectF childRect = mapFromItem(child, child->boundingRect()).boundingRect(); + result = result.united(childRect); + } + } + return result; +} + +//! this is the original customChildrenBoundingRect - used for calculating the bounding rect of +//! all the items that have to move with this view. QRectF QGIView::customChildrenBoundingRect() const { QList children = childItems(); diff --git a/src/Mod/TechDraw/Gui/QGIView.h b/src/Mod/TechDraw/Gui/QGIView.h index 8d1a40ef32..d1a3cdb8c7 100644 --- a/src/Mod/TechDraw/Gui/QGIView.h +++ b/src/Mod/TechDraw/Gui/QGIView.h @@ -184,6 +184,7 @@ protected: void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override; void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override; virtual QRectF customChildrenBoundingRect() const; + virtual QRectF frameRect() const; void dumpRect(const char* text, QRectF rect); bool m_isHovered;