osd: animate scrolling (#316)

* refactor: make the animation smooth when scrolling the mouse wheel

* fix: can't drag

* format

* fix cursor

---------

Co-authored-by: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>
This commit is contained in:
PFiS 2025-08-02 14:19:59 +08:00 committed by GitHub
parent 32126e761f
commit a89a401087
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 44 additions and 21 deletions

View file

@ -15,7 +15,20 @@ Column {
spacing: Appearance.spacing.normal spacing: Appearance.spacing.normal
CustomMouseArea {
implicitWidth: Config.osd.sizes.sliderWidth
implicitHeight: Config.osd.sizes.sliderHeight
onWheel: event => {
if (event.angleDelta.y > 0)
Audio.setVolume(Audio.volume + 0.1);
else if (event.angleDelta.y < 0)
Audio.setVolume(Audio.volume - 0.1);
}
VerticalSlider { VerticalSlider {
anchors.fill: parent
icon: { icon: {
if (Audio.muted) if (Audio.muted)
return "no_sound"; return "no_sound";
@ -27,17 +40,29 @@ Column {
} }
value: Audio.volume value: Audio.volume
onMoved: Audio.setVolume(value) onMoved: Audio.setVolume(value)
}
}
CustomMouseArea {
implicitWidth: Config.osd.sizes.sliderWidth implicitWidth: Config.osd.sizes.sliderWidth
implicitHeight: Config.osd.sizes.sliderHeight implicitHeight: Config.osd.sizes.sliderHeight
onWheel: event => {
const monitor = root.monitor;
if (!monitor)
return;
if (event.angleDelta.y > 0)
monitor.setBrightness(monitor.brightness + 0.1);
else if (event.angleDelta.y < 0)
monitor.setBrightness(monitor.brightness - 0.1);
} }
VerticalSlider { VerticalSlider {
anchors.fill: parent
icon: `brightness_${(Math.round(value * 6) + 1)}` icon: `brightness_${(Math.round(value * 6) + 1)}`
value: root.monitor?.brightness ?? 0 value: root.monitor?.brightness ?? 0
onMoved: root.monitor?.setBrightness(value) onMoved: root.monitor?.setBrightness(value)
}
implicitWidth: Config.osd.sizes.sliderWidth
implicitHeight: Config.osd.sizes.sliderHeight
} }
} }

View file

@ -11,8 +11,6 @@ Slider {
required property string icon required property string icon
property real oldValue property real oldValue
wheelEnabled: true
orientation: Qt.Vertical orientation: Qt.Vertical
background: StyledRect { background: StyledRect {
@ -59,7 +57,7 @@ Slider {
MouseArea { MouseArea {
anchors.fill: parent anchors.fill: parent
cursorShape: Qt.PointingHandCursor cursorShape: Qt.PointingHandCursor
onPressed: event => event.accepted = false acceptedButtons: Qt.NoButton
} }
MaterialIcon { MaterialIcon {