aboutsummaryrefslogtreecommitdiffstats
path: root/src/imports/nativestyle/items
diff options
context:
space:
mode:
authorRichard Moe Gustavsen <richard.gustavsen@qt.io>2020-06-03 10:29:35 +0200
committerRichard Moe Gustavsen <richard.gustavsen@qt.io>2020-06-03 09:39:59 +0000
commit6dd92ec5d3d91c0d946453c2c420817a23300c4c (patch)
tree819530508146d35fe0dc3b843cd87f8857ab3d9c /src/imports/nativestyle/items
parent09d35ba20553f27ba4183781ca9dc8dfa2e16f3f (diff)
Native style: remove insets, and use layoutRect
We have so far used insets to ensure that the controls end up aligned inside a layout. But this is most likely wrong, since insets in QtQuickControls2 is supposed to only move the background, and not the whole control (including contents, which we used to move as well in Button.qml). So after looking at this one more time, I think the right solution is to leave insets alone, and instead provide a layoutRect from QQuickStyleItem. This rect can later be used by layouts to align the controls correctly. Change-Id: I3cd97d34ca6f629dedef3e2afd2ae9e257f9df22 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src/imports/nativestyle/items')
-rw-r--r--src/imports/nativestyle/items/qquickstyleitem.cpp21
-rw-r--r--src/imports/nativestyle/items/qquickstyleitem.h8
2 files changed, 16 insertions, 13 deletions
diff --git a/src/imports/nativestyle/items/qquickstyleitem.cpp b/src/imports/nativestyle/items/qquickstyleitem.cpp
index a7bce506..35e0f2ed 100644
--- a/src/imports/nativestyle/items/qquickstyleitem.cpp
+++ b/src/imports/nativestyle/items/qquickstyleitem.cpp
@@ -196,7 +196,7 @@ void QQuickStyleItem::updateGeometry()
m_dirty.setFlag(DirtyFlag::Geometry, false);
const QQuickStyleMargins oldContentPadding = contentPadding();
- const QQuickStyleMargins oldInsets = insets();
+ const QRectF oldLayoutRect = layoutRect();
m_styleItemGeometry = calculateGeometry();
@@ -214,8 +214,8 @@ void QQuickStyleItem::updateGeometry()
if (contentPadding() != oldContentPadding)
emit contentPaddingChanged();
- if (insets() != oldInsets)
- emit insetsChanged();
+ if (layoutRect() != oldLayoutRect)
+ emit layoutRectChanged();
setImplicitSize(m_styleItemGeometry.implicitSize.width(), m_styleItemGeometry.implicitSize.height());
// Clear the dirty flag after setting implicit size, since the following call
@@ -227,8 +227,8 @@ void QQuickStyleItem::updateGeometry()
qqc2Debug() << m_styleItemGeometry
<< "bounding rect:" << boundingRect()
+ << "layout rect:" << layoutRect()
<< "content padding:" << contentPadding()
- << "insets:" << insets()
<< "input content size:" << m_contentSize;
}
@@ -329,12 +329,15 @@ QQuickStyleMargins QQuickStyleItem::contentPadding() const
return QQuickStyleMargins(outerRect, m_styleItemGeometry.contentRect);
}
-QQuickStyleMargins QQuickStyleItem::insets() const
+QRectF QQuickStyleItem::layoutRect() const
{
- if (m_styleItemGeometry.layoutRect.isEmpty())
- return QQuickStyleMargins();
- const QRect innerRect(QPoint(0, 0), m_styleItemGeometry.implicitSize);
- return QQuickStyleMargins(m_styleItemGeometry.layoutRect, innerRect);
+ // ### TODO: layoutRect is currently not being used for anything. But
+ // eventually this information will be needed by layouts to align the controls
+ // correctly. This because the images drawn by QStyle are usually a bit bigger
+ // 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;
}
QFont QQuickStyleItem::styleFont(QQuickItem *control)
diff --git a/src/imports/nativestyle/items/qquickstyleitem.h b/src/imports/nativestyle/items/qquickstyleitem.h
index 5d0b6671..a85e1c4d 100644
--- a/src/imports/nativestyle/items/qquickstyleitem.h
+++ b/src/imports/nativestyle/items/qquickstyleitem.h
@@ -153,14 +153,14 @@ class QQuickStyleItem : public QQuickItem
Q_OBJECT
// Input
+ Q_PROPERTY(QQuickItem *control MEMBER m_control)
Q_PROPERTY(qreal contentWidth READ contentWidth WRITE setContentWidth)
Q_PROPERTY(qreal contentHeight READ contentHeight WRITE setContentHeight)
Q_PROPERTY(bool useNinePatchImage MEMBER m_useNinePatchImage)
// Output
- Q_PROPERTY(QQuickItem *control MEMBER m_control)
Q_PROPERTY(QQuickStyleMargins contentPadding READ contentPadding() NOTIFY contentPaddingChanged)
- Q_PROPERTY(QQuickStyleMargins insets READ insets() NOTIFY insetsChanged)
+ Q_PROPERTY(QRectF layoutRect READ layoutRect() NOTIFY layoutRectChanged)
QML_NAMED_ELEMENT(StyleItem)
QML_UNCREATABLE("StyleItem is an abstract base class.")
@@ -183,7 +183,7 @@ public:
void setContentHeight(qreal contentHeight);
QQuickStyleMargins contentPadding() const;
- QQuickStyleMargins insets() const;
+ QRectF layoutRect() const;
Q_INVOKABLE virtual QFont styleFont(QQuickItem *control);
@@ -192,7 +192,7 @@ public:
signals:
void contentPaddingChanged();
- void insetsChanged();
+ void layoutRectChanged();
void fontChanged();
protected: