SpinBox: use control instead of parent in indicators

This avoids errors when users give an id to a customized indicator.

Fixes: QTBUG-97782
Pick-to: 6.2
Change-Id: I3af8139abf992152f27826dd34d499608c6558b9
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
This commit is contained in:
Mitch Curtis 2021-11-19 10:53:16 +01:00
parent 5d656b31eb
commit 3bb8ef28a7
6 changed files with 45 additions and 20 deletions

View File

@ -88,8 +88,8 @@ T.SpinBox {
} }
up.indicator: Rectangle { up.indicator: Rectangle {
x: control.mirrored ? 0 : parent.width - width x: control.mirrored ? 0 : control.width - width
height: parent.height height: control.height
implicitWidth: 40 implicitWidth: 40
implicitHeight: 40 implicitHeight: 40
color: control.up.pressed ? control.palette.mid : control.palette.button color: control.up.pressed ? control.palette.mid : control.palette.button
@ -112,7 +112,7 @@ T.SpinBox {
down.indicator: Rectangle { down.indicator: Rectangle {
x: control.mirrored ? parent.width - width : 0 x: control.mirrored ? parent.width - width : 0
height: parent.height height: control.height
implicitWidth: 40 implicitWidth: 40
implicitHeight: 40 implicitHeight: 40
color: control.down.pressed ? control.palette.mid : control.palette.button color: control.down.pressed ? control.palette.mid : control.palette.button

View File

@ -79,9 +79,9 @@ T.SpinBox {
} }
up.indicator: PaddedRectangle { up.indicator: PaddedRectangle {
x: control.mirrored ? 1 : parent.width - width - 1 x: control.mirrored ? 1 : control.width - width - 1
y: 1 y: 1
height: parent.height / 2 - 1 height: control.height / 2 - 1
implicitWidth: 16 implicitWidth: 16
implicitHeight: 10 implicitHeight: 10
@ -103,9 +103,9 @@ T.SpinBox {
} }
down.indicator: PaddedRectangle { down.indicator: PaddedRectangle {
x: control.mirrored ? 1 : parent.width - width - 1 x: control.mirrored ? 1 : control.width - width - 1
y: parent.height - height - 1 y: control.height - height - 1
height: parent.height / 2 - 1 height: control.height / 2 - 1
implicitWidth: 16 implicitWidth: 16
implicitHeight: 10 implicitHeight: 10

View File

@ -102,8 +102,8 @@ T.SpinBox {
} }
up.indicator: NinePatchImage { up.indicator: NinePatchImage {
x: control.mirrored ? 0 : parent.width - width x: control.mirrored ? 0 : control.width - width
height: parent.height height: control.height
source: Imagine.url + "spinbox-indicator" source: Imagine.url + "spinbox-indicator"
NinePatchImageSelector on source { NinePatchImageSelector on source {
@ -120,8 +120,8 @@ T.SpinBox {
} }
down.indicator: NinePatchImage { down.indicator: NinePatchImage {
x: control.mirrored ? parent.width - width : 0 x: control.mirrored ? control.width - width : 0
height: parent.height height: control.height
source: Imagine.url + "spinbox-indicator" source: Imagine.url + "spinbox-indicator"
NinePatchImageSelector on source { NinePatchImageSelector on source {

View File

@ -81,10 +81,10 @@ T.SpinBox {
} }
up.indicator: Item { up.indicator: Item {
x: control.mirrored ? 0 : parent.width - width x: control.mirrored ? 0 : control.width - width
implicitWidth: control.Material.touchTarget implicitWidth: control.Material.touchTarget
implicitHeight: control.Material.touchTarget implicitHeight: control.Material.touchTarget
height: parent.height height: control.height
width: height width: height
Ripple { Ripple {
@ -115,10 +115,10 @@ T.SpinBox {
} }
down.indicator: Item { down.indicator: Item {
x: control.mirrored ? parent.width - width : 0 x: control.mirrored ? control.width - width : 0
implicitWidth: control.Material.touchTarget implicitWidth: control.Material.touchTarget
implicitHeight: control.Material.touchTarget implicitHeight: control.Material.touchTarget
height: parent.height height: control.height
width: height width: height
Ripple { Ripple {

View File

@ -84,9 +84,9 @@ T.SpinBox {
up.indicator: Item { up.indicator: Item {
implicitWidth: 28 implicitWidth: 28
height: parent.height + 4 height: control.height + 4
y: -2 y: -2
x: control.mirrored ? 0 : parent.width - width x: control.mirrored ? 0 : control.width - width
Rectangle { Rectangle {
x: 2; y: 4 x: 2; y: 4
@ -110,9 +110,9 @@ T.SpinBox {
down.indicator: Item { down.indicator: Item {
implicitWidth: 28 implicitWidth: 28
height: parent.height + 4 height: control.height + 4
y: -2 y: -2
x: control.mirrored ? parent.width - width : 0 x: control.mirrored ? control.width - width : 0
Rectangle { Rectangle {
x: 2; y: 4 x: 2; y: 4

View File

@ -688,6 +688,31 @@ TestCase {
compare(control.up.indicator.s, "this is the one"); compare(control.up.indicator.s, "this is the one");
} }
Component {
id: overriddenSpinBoxWithIds
SpinBox {
value: 50
up.indicator: Rectangle {
id: uhOh1
property string s: "up"
}
down.indicator: Rectangle {
id: uhOh2
property string s: "down"
}
}
}
function test_indicatorOverriddenWithIds() {
var control = createTemporaryObject(overriddenSpinBoxWithIds, testCase)
verify(control)
// TODO: Use failOnWarning() here when it has been implemented
// Specifying an id will result in both the default indicator implementations
// and the custom ones being created, but it shouldn't result in any TypeErrors.
compare(control.up.indicator.s, "up");
compare(control.down.indicator.s, "down");
}
function test_valueEnterFromOutsideRange() { function test_valueEnterFromOutsideRange() {
// Check that changing from 2 to 99 goes to 98 then changing to 99 puts it back to 98 // Check that changing from 2 to 99 goes to 98 then changing to 99 puts it back to 98
var control = createTemporaryObject(spinBox, testCase, {from: 2, to: 98, value: 2, editable: true}) var control = createTemporaryObject(spinBox, testCase, {from: 2, to: 98, value: 2, editable: true})