Fix Home shelf slider interactions
This commit is contained in:
@@ -9,8 +9,10 @@ Item {
|
||||
|
||||
property int value: 0
|
||||
property int previewValue: 0
|
||||
property bool interactionActive: false
|
||||
property string accessibleName: "Brightness"
|
||||
|
||||
readonly property bool pressed: drag.pressed
|
||||
readonly property bool pressed: root.interactionActive
|
||||
|
||||
signal previewChanged(int value)
|
||||
signal committed(int value)
|
||||
@@ -20,8 +22,18 @@ Item {
|
||||
activeFocusOnTab: root.enabled
|
||||
opacity: root.enabled ? 1 : 0.42
|
||||
|
||||
Accessible.role: Accessible.Slider
|
||||
Accessible.name: root.accessibleName
|
||||
// Qt 6.11's installed Accessible attached type has no structured value or
|
||||
// range properties, so expose both in the supported live description.
|
||||
Accessible.description: root.previewValue + " percent, range 0 to 100"
|
||||
Accessible.focusable: root.enabled
|
||||
Accessible.focused: root.activeFocus
|
||||
Accessible.onIncreaseAction: root.commitStep(5)
|
||||
Accessible.onDecreaseAction: root.commitStep(-5)
|
||||
|
||||
onValueChanged: {
|
||||
if (!drag.pressed)
|
||||
if (!root.interactionActive)
|
||||
root.updatePreview(root.value, false);
|
||||
}
|
||||
|
||||
@@ -53,7 +65,7 @@ Item {
|
||||
color: Theme.warn
|
||||
|
||||
Behavior on width {
|
||||
enabled: !drag.pressed
|
||||
enabled: !root.interactionActive
|
||||
NumberAnimation {
|
||||
duration: Theme.durFast
|
||||
easing.type: Easing.OutQuad
|
||||
@@ -82,26 +94,21 @@ Item {
|
||||
anchors.fill: parent
|
||||
enabled: root.enabled
|
||||
hoverEnabled: true
|
||||
preventStealing: true
|
||||
cursorShape: enabled ? Qt.PointingHandCursor : Qt.ArrowCursor
|
||||
|
||||
onPressed: event => {
|
||||
root.forceActiveFocus();
|
||||
root.previewAt(event.x);
|
||||
root.beginPointerInteraction(event.x);
|
||||
event.accepted = true;
|
||||
}
|
||||
onPositionChanged: event => {
|
||||
if (pressed)
|
||||
root.previewAt(event.x);
|
||||
}
|
||||
onPositionChanged: event => root.movePointerInteraction(event.x)
|
||||
onReleased: event => {
|
||||
root.committed(root.previewValue);
|
||||
root.releasePointerInteraction();
|
||||
event.accepted = true;
|
||||
}
|
||||
onCanceled: root.updatePreview(root.value, false)
|
||||
onCanceled: root.cancelPointerInteraction()
|
||||
onWheel: event => {
|
||||
const direction = event.angleDelta.y >= 0 ? 5 : -5;
|
||||
root.commitStep(direction);
|
||||
root.commitWheel(event.angleDelta.y);
|
||||
event.accepted = true;
|
||||
}
|
||||
}
|
||||
@@ -123,6 +130,36 @@ Item {
|
||||
root.updatePreview(pointerX / Math.max(1, drag.width) * 100, true);
|
||||
}
|
||||
|
||||
function beginPointerInteraction(pointerX: real): void {
|
||||
if (!root.enabled)
|
||||
return;
|
||||
root.interactionActive = true;
|
||||
root.previewAt(pointerX);
|
||||
}
|
||||
|
||||
function movePointerInteraction(pointerX: real): void {
|
||||
if (root.interactionActive)
|
||||
root.previewAt(pointerX);
|
||||
}
|
||||
|
||||
function releasePointerInteraction(): void {
|
||||
if (!root.interactionActive)
|
||||
return;
|
||||
root.interactionActive = false;
|
||||
root.committed(root.previewValue);
|
||||
}
|
||||
|
||||
function cancelPointerInteraction(): void {
|
||||
root.interactionActive = false;
|
||||
root.updatePreview(root.value, false);
|
||||
}
|
||||
|
||||
function commitWheel(delta: int): void {
|
||||
if (delta === 0)
|
||||
return;
|
||||
root.commitStep(delta > 0 ? 5 : -5);
|
||||
}
|
||||
|
||||
function commitStep(delta: int): void {
|
||||
if (!root.enabled)
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user