Enable wheel events on Slider {}

Summary:
So far PC3 version of the slider doesn't react to events, this change
enables it.

Test Plan: Used it with a test.

Reviewers: #plasma, broulik, davidedmundson

Reviewed By: #plasma, davidedmundson

Subscribers: davidedmundson, kde-frameworks-devel

Tags: #frameworks

Differential Revision: https://phabricator.kde.org/D26055
This commit is contained in:
Aleix Pol 2019-12-16 17:42:44 +01:00
parent 6f183b4ce4
commit 66122410a1
2 changed files with 59 additions and 3 deletions

View File

@ -28,7 +28,7 @@ T.Slider {
implicitWidth: control.orientation === Qt.Horizontal ? units.gridUnit * 12 : units.gridUnit * 1.6
implicitHeight: control.orientation === Qt.Horizontal ? units.gridUnit * 1.6 : units.gridUnit * 12
wheelEnabled: true
snapMode: T.Slider.SnapOnRelease
PlasmaCore.Svg {
@ -94,14 +94,16 @@ T.Slider {
Repeater {
id: repeater
model: control.stepSize > 0 ? 1 + (control.to - control.from) / control.stepSize : 0
readonly property int stepCount: (control.to - control.from) / control.stepSize
model: control.stepSize && stepCount < 20 ? 1 + stepCount : 0
anchors.fill: parent
Rectangle {
color: PlasmaCore.ColorScope.textColor
opacity: 0.3
width: background.horizontal ? units.devicePixelRatio : units.gridUnit/2
height: background.horizontal ? units.gridUnit/2 : units.devicePixelRatio
y: background.horizontal ? background.height : handle.height / 2 + index * ((repeater.height - handle.height) / (repeater.count > 1 ? repeater.count - 1 : 1))
y: background.horizontal ? background.height + units.devicePixelRatio : handle.height / 2 + index * ((repeater.height - handle.height) / (repeater.count > 1 ? repeater.count - 1 : 1))
x: background.horizontal ? handle.width / 2 + index * ((repeater.width - handle.width) / (repeater.count > 1 ? repeater.count - 1 : 1)) : background.width
}
}

View File

@ -0,0 +1,54 @@
import QtQuick 2.0
import QtQuick.Layouts 1.3
import org.kde.kirigami 2.5 as Kirigami
import org.kde.plasma.components 3.0
import QtQuick.Controls 2.5 as QQC2
import org.kde.plasma.components 2.0 as PC2
// Run with qmlscene to use qqc2-desktop-style
Kirigami.ApplicationWindow {
pageStack.initialPage: Kirigami.Page {
Kirigami.FormLayout {
anchors.fill: parent
PC2.Slider {
Layout.fillWidth: true
Kirigami.FormData.label: "PC2 slider"
maximumValue: slider.to
stepSize: slider.stepSize
}
QQC2.Slider {
Layout.fillWidth: true
Kirigami.FormData.label: "QQC2 slider"
to: slider.to
stepSize: slider.stepSize
}
Slider {
id: slider
Kirigami.FormData.label: "PC3 slider"
to: max.text
stepSize: 1
clip: true
}
TextField {
id: max
Kirigami.FormData.label: "maximumValue: "
text: "100"
}
Label {
Kirigami.FormData.label: "value: "
text: slider.value
}
Slider {
Kirigami.FormData.label: "Choose step size: "
to: slider.to * 2
onMoved: slider.stepSize = value
}
Label {
Kirigami.FormData.label: "Step size: "
text: slider.stepSize
}
}
}
}