Commit b738ebbb authored by Kai Uwe Broulik's avatar Kai Uwe Broulik 🍇

Fix sizing of CheckBox and RadioButton

KQuickStyleItem manages its implicit size internally. Overriding it on the QML side makes it non-deterministic
which assignment wins and might cause unexpected re-evaluation of the size causing it to change.

Moreover, the CheckIndicator implicit size is based on sizeFromContents for CT_CheckBox, which in case of Breeze
(but not the Qt built-in styles) already contains some extra padding on the side between checkbox and label.
Instead of using that for layouting our full checkbox (indicator + label), do what qqc1 did and use
PM_CheckBoxLabelSpacing for spacing and PM_IndicatorWidth as size hint for the indicator.

Also while at it for radio buttons use the appropriate (PM_RadioButtonLabelSpacing and PM_ExclusiveIndicatorWidth) hints.

This makes QQC2 CheckBox and RadioButton layouted pixel-perfect to their QWidget counterparts and also fixes
it randomly changing size hints as you switch between pages as demonstrated by the bug report.

BUG: 418447

Differential Revision: https://phabricator.kde.org/D28116
parent 1bb57b10
...@@ -37,15 +37,13 @@ T.CheckBox { ...@@ -37,15 +37,13 @@ T.CheckBox {
indicator ? indicator.implicitHeight : 0) + topPadding + bottomPadding) indicator ? indicator.implicitHeight : 0) + topPadding + bottomPadding)
baselineOffset: contentItem.y + contentItem.baselineOffset baselineOffset: contentItem.y + contentItem.baselineOffset
padding: 1 spacing: indicator && typeof indicator.pixelMetric === "function" ? indicator.pixelMetric("checkboxlabelspacing") : Kirigami.Units.smallSpacing
spacing: Kirigami.Units.smallSpacing
hoverEnabled: true hoverEnabled: true
indicator: CheckIndicator { indicator: CheckIndicator {
LayoutMirroring.enabled: controlRoot.mirrored LayoutMirroring.enabled: controlRoot.mirrored
LayoutMirroring.childrenInherit: true LayoutMirroring.childrenInherit: true
width: height
anchors { anchors {
left: parent.left left: parent.left
verticalCenter: parent.verticalCenter verticalCenter: parent.verticalCenter
...@@ -64,8 +62,11 @@ T.CheckBox { ...@@ -64,8 +62,11 @@ T.CheckBox {
} }
contentItem: Label { contentItem: Label {
leftPadding: controlRoot.indicator && !controlRoot.mirrored ? controlRoot.indicator.width + controlRoot.spacing : 0 readonly property int indicatorEffectiveWidth: controlRoot.indicator && typeof controlRoot.indicator.pixelMetric === "function"
rightPadding: controlRoot.indicator && controlRoot.mirrored ? controlRoot.indicator.width + controlRoot.spacing : 0 ? controlRoot.indicator.pixelMetric("indicatorwidth") : controlRoot.indicator.width
leftPadding: controlRoot.indicator && !controlRoot.mirrored ? indicatorEffectiveWidth + controlRoot.spacing : 0
rightPadding: controlRoot.indicator && controlRoot.mirrored ? indicatorEffectiveWidth + controlRoot.spacing : 0
opacity: controlRoot.enabled ? 1 : 0.6 opacity: controlRoot.enabled ? 1 : 0.6
text: controlRoot.Kirigami.MnemonicData.richTextLabel text: controlRoot.Kirigami.MnemonicData.richTextLabel
font: controlRoot.font font: controlRoot.font
......
...@@ -31,7 +31,4 @@ StylePrivate.StyleItem { ...@@ -31,7 +31,4 @@ StylePrivate.StyleItem {
hover: control.hovered hover: control.hovered
enabled: control.enabled enabled: control.enabled
properties: {"partiallyChecked": (control.checkState === Qt.PartiallyChecked) } properties: {"partiallyChecked": (control.checkState === Qt.PartiallyChecked) }
implicitWidth: pixelMetric("indicatorwidth")
implicitHeight : implicitWidth
} }
...@@ -37,15 +37,13 @@ T.RadioButton { ...@@ -37,15 +37,13 @@ T.RadioButton {
indicator ? indicator.implicitHeight : 0) + topPadding + bottomPadding) indicator ? indicator.implicitHeight : 0) + topPadding + bottomPadding)
baselineOffset: contentItem.y + contentItem.baselineOffset baselineOffset: contentItem.y + contentItem.baselineOffset
padding: 1 spacing: indicator && typeof indicator.pixelMetric === "function" ? indicator.pixelMetric("ratiobuttonlabelspacing") : Kirigami.Units.smallSpacing
spacing: Kirigami.Units.smallSpacing
hoverEnabled: true hoverEnabled: true
indicator: CheckIndicator { indicator: CheckIndicator {
LayoutMirroring.enabled: controlRoot.mirrored LayoutMirroring.enabled: controlRoot.mirrored
LayoutMirroring.childrenInherit: true LayoutMirroring.childrenInherit: true
width: height
anchors { anchors {
left: parent.left left: parent.left
verticalCenter: parent.verticalCenter verticalCenter: parent.verticalCenter
...@@ -64,8 +62,11 @@ T.RadioButton { ...@@ -64,8 +62,11 @@ T.RadioButton {
} }
contentItem: Label { contentItem: Label {
leftPadding: controlRoot.indicator && !controlRoot.mirrored ? controlRoot.indicator.width + controlRoot.spacing : 0 readonly property int indicatorEffectiveWidth: controlRoot.indicator && typeof controlRoot.indicator.pixelMetric === "function"
rightPadding: controlRoot.indicator && controlRoot.mirrored ? controlRoot.indicator.width + controlRoot.spacing : 0 ? controlRoot.indicator.pixelMetric("exclusiveindicatorwidth") : controlRoot.indicator.width
leftPadding: controlRoot.indicator && !controlRoot.mirrored ? indicatorEffectiveWidth + controlRoot.spacing : 0
rightPadding: controlRoot.indicator && controlRoot.mirrored ? indicatorEffectiveWidth + controlRoot.spacing : 0
opacity: controlRoot.enabled ? 1 : 0.6 opacity: controlRoot.enabled ? 1 : 0.6
text: controlRoot.Kirigami.MnemonicData.richTextLabel text: controlRoot.Kirigami.MnemonicData.richTextLabel
font: controlRoot.font font: controlRoot.font
......
...@@ -1177,7 +1177,13 @@ int KQuickStyleItem::pixelMetric(const QString &metric) ...@@ -1177,7 +1177,13 @@ int KQuickStyleItem::pixelMetric(const QString &metric)
else if (metric == QLatin1String("tabhspace")) else if (metric == QLatin1String("tabhspace"))
return KQuickStyleItem::style()->pixelMetric(QStyle::PM_TabBarTabHSpace, nullptr); return KQuickStyleItem::style()->pixelMetric(QStyle::PM_TabBarTabHSpace, nullptr);
else if (metric == QLatin1String("indicatorwidth")) else if (metric == QLatin1String("indicatorwidth"))
return KQuickStyleItem::style()->pixelMetric(QStyle::PM_IndicatorWidth, nullptr);
else if (metric == QLatin1String("exclusiveindicatorwidth"))
return KQuickStyleItem::style()->pixelMetric(QStyle::PM_ExclusiveIndicatorWidth, nullptr); return KQuickStyleItem::style()->pixelMetric(QStyle::PM_ExclusiveIndicatorWidth, nullptr);
else if (metric == QLatin1String("checkboxlabelspacing"))
return KQuickStyleItem::style()->pixelMetric(QStyle::PM_CheckBoxLabelSpacing, nullptr);
else if (metric == QLatin1String("ratiobuttonlabelspacing"))
return KQuickStyleItem::style()->pixelMetric(QStyle::PM_RadioButtonLabelSpacing, nullptr);
else if (metric == QLatin1String("tabvspace")) else if (metric == QLatin1String("tabvspace"))
return KQuickStyleItem::style()->pixelMetric(QStyle::PM_TabBarTabVSpace, nullptr); return KQuickStyleItem::style()->pixelMetric(QStyle::PM_TabBarTabVSpace, nullptr);
else if (metric == QLatin1String("tabbaseheight")) else if (metric == QLatin1String("tabbaseheight"))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment