aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Moe Gustavsen <richard.gustavsen@qt.io>2020-10-09 16:38:02 +0200
committerRichard Moe Gustavsen <richard.gustavsen@qt.io>2020-10-12 14:48:56 +0200
commitd956d1062479d0af914c96ac615d2aa2a35be4cd (patch)
tree84d0791e078e795e9b4aedc853595fb254b79bc5
parent3a9f84fb3750f200d0817ed8b44ac2844cd04dda (diff)
Native style: add a function imageSize() rather than overriding minimumSize
When not using nine patch scaling, we used to override minimumSize to instead be the actual size of the item, since we use minimumSize to also be the size of the image we draw. But this turns out to be confusing, especially while debugging. So introduce a more explicit imageSize() function instead, and leave minimumSize unchanged. Change-Id: I8d3ec25603d430a94b124713fad01bf6d277bbe5 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
-rw-r--r--src/imports/nativestyle/items/qquickstyleitem.cpp20
-rw-r--r--src/imports/nativestyle/items/qquickstyleitem.h3
2 files changed, 14 insertions, 9 deletions
diff --git a/src/imports/nativestyle/items/qquickstyleitem.cpp b/src/imports/nativestyle/items/qquickstyleitem.cpp
index 643b190e..5899e3ce 100644
--- a/src/imports/nativestyle/items/qquickstyleitem.cpp
+++ b/src/imports/nativestyle/items/qquickstyleitem.cpp
@@ -133,7 +133,7 @@ QSGNode *QQuickStyleItem::updatePaintNode(QSGNode *oldNode, QQuickItem::UpdatePa
bounds.setWidth(ninePatchImageSize.width());
padding.setLeft(0);
padding.setRight(0);
- } else if (boundingRect().width() < m_styleItemGeometry.minimumSize.width()) {
+ } else if (boundingRect().width() < imageSize().width()) {
// If the item size is smaller that the image, using nine-patch scaling
// ends up wrapping it. In that case we scale the whole image instead.
padding.setLeft(0);
@@ -143,7 +143,7 @@ QSGNode *QQuickStyleItem::updatePaintNode(QSGNode *oldNode, QQuickItem::UpdatePa
bounds.setHeight(ninePatchImageSize.height());
padding.setTop(0);
padding.setBottom(0);
- } else if (boundingRect().height() < m_styleItemGeometry.minimumSize.height()) {
+ } else if (boundingRect().height() < imageSize().height()) {
padding.setTop(0);
padding.setBottom(0);
}
@@ -174,7 +174,7 @@ void QQuickStyleItem::initStyleOptionBase(QStyleOption &styleOption)
styleOption.control = const_cast<QQuickItem *>(control<QQuickItem>());
styleOption.window = window();
styleOption.palette = QQuickItemPrivate::get(m_control)->palette()->toQPalette();
- styleOption.rect = QRect(QPoint(0, 0), m_styleItemGeometry.minimumSize);
+ styleOption.rect = QRect(QPoint(0, 0), imageSize());
styleOption.state = QStyle::State_None;
styleOption.state |= controlSize(styleOption.control);
@@ -251,9 +251,6 @@ void QQuickStyleItem::updateGeometry()
setImplicitSize(m_styleItemGeometry.implicitSize.width(), m_styleItemGeometry.implicitSize.height());
- if (!m_useNinePatchImage)
- m_styleItemGeometry.minimumSize = size().toSize();
-
qqc2Debug() << m_styleItemGeometry
<< "bounding rect:" << boundingRect()
<< "layout margins:" << layoutMargins()
@@ -269,7 +266,7 @@ void QQuickStyleItem::paintControlToImage()
m_dirty.setFlag(DirtyFlag::Image, false);
const qreal scale = window()->devicePixelRatio();
- m_paintedImage = QImage(m_styleItemGeometry.minimumSize * scale, QImage::Format_ARGB32_Premultiplied);
+ m_paintedImage = QImage(imageSize() * scale, QImage::Format_ARGB32_Premultiplied);
m_paintedImage.setDevicePixelRatio(scale);
m_paintedImage.fill(Qt::transparent);
@@ -440,13 +437,20 @@ QQuickStyleMargins QQuickStyleItem::layoutMargins() const
return QQuickStyleMargins(outerRect, m_styleItemGeometry.layoutRect);
}
-QSize QQuickStyleItem::minimumSize()
+QSize QQuickStyleItem::minimumSize() const
{
// The style item should not be scaled below this size.
// Otherwise the image will be truncated.
return m_styleItemGeometry.minimumSize;
}
+QSize QQuickStyleItem::imageSize() const
+{
+ // Returns the size of the QImage (unscaled) that
+ // is used to draw the control from QStyle.
+ return m_useNinePatchImage ? m_styleItemGeometry.minimumSize : size().toSize();
+}
+
qreal QQuickStyleItem::focusFrameRadius() const
{
return m_styleItemGeometry.focusFrameRadius;
diff --git a/src/imports/nativestyle/items/qquickstyleitem.h b/src/imports/nativestyle/items/qquickstyleitem.h
index ece2572d..0834662c 100644
--- a/src/imports/nativestyle/items/qquickstyleitem.h
+++ b/src/imports/nativestyle/items/qquickstyleitem.h
@@ -215,7 +215,8 @@ public:
QQuickStyleMargins contentPadding() const;
QQuickStyleMargins layoutMargins() const;
- QSize minimumSize();
+ QSize minimumSize() const;
+ QSize imageSize() const;
qreal focusFrameRadius() const;
Q_INVOKABLE virtual QFont styleFont(QQuickItem *control);