[TD]shrink selection frame
This commit is contained in:
committed by
Chris Hennes
parent
3084c48c8e
commit
09f3e6738c
@@ -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;
|
||||
|
||||
@@ -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<QGraphicsItem*> 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<QGraphicsItem*> children = childItems();
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user