diff options
author | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2020-06-11 15:08:36 +0200 |
---|---|---|
committer | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2020-06-11 13:52:11 +0000 |
commit | 4013c4eef4857363274f0bec7176d7f313e0f83f (patch) | |
tree | 0384d9268ca153b95b45bd2c8f3c5ca26e5fb4ff | |
parent | 5c48daa014171e0c40a2511750a9d9a27d057399 (diff) |
Native style: offer layoutMargins to QML, not layoutRect
The layoutRect are, similar to contentRect, calculated based
on the minimumSize of the control. Since we don't know what
the actual layoutRect will be until a control is resized, we
use it instead to calculate what the margins should be between
the boundingRect() and layoutRect. We do the same for content
rect. This will allows us to calculate the correct margins
early on, before knowing what the end size of the control will be.
Change-Id: I26b0aedee28533a70fd8dc4918f962f41c4f5185
Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io>
-rw-r--r-- | src/imports/nativestyle/items/qquickstyleitem.cpp | 21 | ||||
-rw-r--r-- | src/imports/nativestyle/items/qquickstyleitem.h | 6 |
2 files changed, 16 insertions, 11 deletions
diff --git a/src/imports/nativestyle/items/qquickstyleitem.cpp b/src/imports/nativestyle/items/qquickstyleitem.cpp index c3aaa9a9..03de717e 100644 --- a/src/imports/nativestyle/items/qquickstyleitem.cpp +++ b/src/imports/nativestyle/items/qquickstyleitem.cpp @@ -211,7 +211,7 @@ void QQuickStyleItem::updateGeometry() m_dirty.setFlag(DirtyFlag::Geometry, false); const QQuickStyleMargins oldContentPadding = contentPadding(); - const QRectF oldLayoutRect = layoutRect(); + const QQuickStyleMargins oldLayoutMargins = layoutMargins(); m_styleItemGeometry = calculateGeometry(); @@ -229,8 +229,8 @@ void QQuickStyleItem::updateGeometry() if (contentPadding() != oldContentPadding) emit contentPaddingChanged(); - if (layoutRect() != oldLayoutRect) - emit layoutRectChanged(); + if (layoutMargins() != oldLayoutMargins) + emit layoutMarginsChanged(); setImplicitSize(m_styleItemGeometry.implicitSize.width(), m_styleItemGeometry.implicitSize.height()); @@ -239,7 +239,7 @@ void QQuickStyleItem::updateGeometry() qqc2Debug() << m_styleItemGeometry << "bounding rect:" << boundingRect() - << "layout rect:" << layoutRect() + << "layout margins:" << layoutMargins() << "content padding:" << contentPadding() << "input content size:" << m_contentSize; } @@ -264,8 +264,12 @@ void QQuickStyleItem::paintControlToImage() painter.setPen(QColor(255, 0, 0, 255)); if (m_debugFlags.testFlag(ShowImageRect)) painter.drawRect(QRect(QPoint(0, 0), m_paintedImage.size() / scale)); - if (m_debugFlags.testFlag(ShowLayoutRect)) - painter.drawRect(m_styleItemGeometry.layoutRect); + if (m_debugFlags.testFlag(ShowLayoutRect)) { + const auto m = layoutMargins(); + QRect rect = QRect(QPoint(0, 0), m_paintedImage.size() / scale); + rect.adjust(m.left(), m.top(), -m.right(), -m.bottom()); + painter.drawRect(rect); + } if (m_debugFlags.testFlag(ShowContentRect)) painter.drawRect(m_styleItemGeometry.contentRect); if (m_debugFlags.testFlag(ShowInputContentSize)) { @@ -382,7 +386,7 @@ QQuickStyleMargins QQuickStyleItem::contentPadding() const return QQuickStyleMargins(outerRect, m_styleItemGeometry.contentRect); } -QRectF QQuickStyleItem::layoutRect() const +QQuickStyleMargins QQuickStyleItem::layoutMargins() const { // ### TODO: layoutRect is currently not being used for anything. But // eventually this information will be needed by layouts to align the controls @@ -390,7 +394,8 @@ QRectF QQuickStyleItem::layoutRect() const // than the control(frame) itself, to e.g make room for shadow effects // or focus rects/glow. And this will differ from control to control. The // layoutRect will then inform where the frame of the control is. - return m_styleItemGeometry.layoutRect; + const QRect outerRect(QPoint(0, 0), m_styleItemGeometry.implicitSize); + return QQuickStyleMargins(outerRect, m_styleItemGeometry.layoutRect); } QFont QQuickStyleItem::styleFont(QQuickItem *control) diff --git a/src/imports/nativestyle/items/qquickstyleitem.h b/src/imports/nativestyle/items/qquickstyleitem.h index 20c6133f..bf77c800 100644 --- a/src/imports/nativestyle/items/qquickstyleitem.h +++ b/src/imports/nativestyle/items/qquickstyleitem.h @@ -161,7 +161,7 @@ class QQuickStyleItem : public QQuickItem // Output Q_PROPERTY(QQuickStyleMargins contentPadding READ contentPadding() NOTIFY contentPaddingChanged) - Q_PROPERTY(QRectF layoutRect READ layoutRect() NOTIFY layoutRectChanged) + Q_PROPERTY(QQuickStyleMargins layoutMargins READ layoutMargins() NOTIFY layoutMarginsChanged) QML_NAMED_ELEMENT(StyleItem) QML_UNCREATABLE("StyleItem is an abstract base class.") @@ -199,7 +199,7 @@ public: void setContentHeight(qreal contentHeight); QQuickStyleMargins contentPadding() const; - QRectF layoutRect() const; + QQuickStyleMargins layoutMargins() const; Q_INVOKABLE virtual QFont styleFont(QQuickItem *control); @@ -208,7 +208,7 @@ public: signals: void contentPaddingChanged(); - void layoutRectChanged(); + void layoutMarginsChanged(); void fontChanged(); protected: |