volume number when slider pressed

This commit is contained in:
Zacharias-Brohn
2025-10-15 15:15:51 +02:00
parent 38a4f7633e
commit aa7479b466
+62 -22
View File
@@ -82,7 +82,7 @@ Item {
bottom: parent.bottom bottom: parent.bottom
} }
implicitWidth: parent.width * (Pipewire.defaultAudioSink?.audio.volume ?? 0) implicitWidth: parent.width * ( Pipewire.defaultAudioSink?.audio.volume ?? 0 )
radius: parent.radius radius: parent.radius
color: "#ffffff" color: "#ffffff"
} }
@@ -91,8 +91,8 @@ Item {
id: sinkGrabber id: sinkGrabber
visible: root.expanded visible: root.expanded
opacity: root.expanded ? 1 : 0 opacity: root.expanded ? 1 : 0
width: 12 width: sinkVolumeMouseArea.pressed ? 25 : 12
height: 12 height: sinkVolumeMouseArea.pressed ? 25 : 12
radius: width / 2 radius: width / 2
color: sinkVolumeMouseArea.containsMouse || sinkVolumeMouseArea.pressed ? "#ffffff" : "#aaaaaa" color: sinkVolumeMouseArea.containsMouse || sinkVolumeMouseArea.pressed ? "#ffffff" : "#aaaaaa"
border.color: "#40000000" border.color: "#40000000"
@@ -100,6 +100,26 @@ Item {
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
x: sinkVolumeBar.width - width / 2 x: sinkVolumeBar.width - width / 2
Text {
anchors.centerIn: parent
anchors.verticalCenterOffset: text.length === 3 ? -0.5 : 0
visible: sinkVolumeMouseArea.pressed
font.pixelSize: text.length === 3 ? 10 : 12
text: Math.round(( Pipewire.defaultAudioSink?.audio.volume ?? 0 ) * 100 ).toString()
}
Behavior on width {
NumberAnimation {
duration: 50
}
}
Behavior on height {
NumberAnimation {
duration: 50
}
}
Behavior on opacity { Behavior on opacity {
NumberAnimation { NumberAnimation {
duration: 300 duration: 300
@@ -125,17 +145,17 @@ Item {
cursorShape: Qt.PointingHandCursor cursorShape: Qt.PointingHandCursor
hoverEnabled: true hoverEnabled: true
onPressed: function(mouse) { onPressed: function( mouse ) {
var newVolume = Math.max(0, Math.min(1, mouse.x / width)) var newVolume = Math.max( 0, Math.min( 1, mouse.x / width ))
if (Pipewire.defaultAudioSink?.audio) { if ( Pipewire.defaultAudioSink?.audio ) {
Pipewire.defaultAudioSink.audio.volume = newVolume Pipewire.defaultAudioSink.audio.volume = newVolume
} }
} }
onPositionChanged: function(mouse) { onPositionChanged: function( mouse ) {
if (pressed) { if ( pressed ) {
var newVolume = Math.max(0, Math.min(1, mouse.x / width)) var newVolume = Math.max( 0, Math.min( 1, mouse.x / width ))
if (Pipewire.defaultAudioSink?.audio) { if ( Pipewire.defaultAudioSink?.audio ) {
Pipewire.defaultAudioSink.audio.volume = newVolume Pipewire.defaultAudioSink.audio.volume = newVolume
} }
} }
@@ -148,7 +168,7 @@ Item {
font.family: "Material Symbols Rounded" font.family: "Material Symbols Rounded"
font.pixelSize: 18 font.pixelSize: 18
text: "\ue029" text: "\ue029"
color: (Pipewire.defaultAudioSource?.audio.muted ?? false) ? "#ff4444" : "#ffffff" color: ( Pipewire.defaultAudioSource?.audio.muted ?? false ) ? "#ff4444" : "#ffffff"
} }
Rectangle { Rectangle {
@@ -166,17 +186,17 @@ Item {
bottom: parent.bottom bottom: parent.bottom
} }
implicitWidth: parent.width * (Pipewire.defaultAudioSource?.audio.volume ?? 0) implicitWidth: parent.width * ( Pipewire.defaultAudioSource?.audio.volume ?? 0 )
radius: parent.radius radius: parent.radius
color: (Pipewire.defaultAudioSource?.audio.muted ?? false) ? "#ff4444" : "#ffffff" color: ( Pipewire.defaultAudioSource?.audio.muted ?? false ) ? "#ff4444" : "#ffffff"
} }
Rectangle { Rectangle {
id: sourceGrabber id: sourceGrabber
visible: root.expanded visible: root.expanded
opacity: root.expanded ? 1 : 0 opacity: root.expanded ? 1 : 0
width: 12 width: sourceVolumeMouseArea.pressed ? 25 : 12
height: 12 height: sourceVolumeMouseArea.pressed ? 25 : 12
radius: width / 2 radius: width / 2
color: sourceVolumeMouseArea.containsMouse || sourceVolumeMouseArea.pressed ? "#ffffff" : "#aaaaaa" color: sourceVolumeMouseArea.containsMouse || sourceVolumeMouseArea.pressed ? "#ffffff" : "#aaaaaa"
border.color: "#40000000" border.color: "#40000000"
@@ -184,6 +204,26 @@ Item {
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
x: sourceVolumeBar.width - width / 2 x: sourceVolumeBar.width - width / 2
Text {
anchors.centerIn: parent
anchors.verticalCenterOffset: text.length === 3 ? -0.5 : 0
visible: sourceVolumeMouseArea.pressed
font.pixelSize: text.length === 3 ? 10 : 12
text: Math.round(( Pipewire.defaultAudioSource?.audio.volume ?? 0 ) * 100 ).toString()
}
Behavior on width {
NumberAnimation {
duration: 50
}
}
Behavior on height {
NumberAnimation {
duration: 50
}
}
Behavior on opacity { Behavior on opacity {
NumberAnimation { NumberAnimation {
duration: 300 duration: 300
@@ -209,17 +249,17 @@ Item {
cursorShape: Qt.PointingHandCursor cursorShape: Qt.PointingHandCursor
hoverEnabled: true hoverEnabled: true
onPressed: function(mouse) { onPressed: function( mouse ) {
var newVolume = Math.max(0, Math.min(1, mouse.x / width)) var newVolume = Math.max( 0, Math.min( 1, mouse.x / width ))
if (Pipewire.defaultAudioSource?.audio) { if ( Pipewire.defaultAudioSource?.audio ) {
Pipewire.defaultAudioSource.audio.volume = newVolume Pipewire.defaultAudioSource.audio.volume = newVolume
} }
} }
onPositionChanged: function(mouse) { onPositionChanged: function( mouse ) {
if (pressed) { if ( pressed ) {
var newVolume = Math.max(0, Math.min(1, mouse.x / width)) var newVolume = Math.max( 0, Math.min( 1, mouse.x / width ))
if (Pipewire.defaultAudioSource?.audio) { if ( Pipewire.defaultAudioSource?.audio ) {
Pipewire.defaultAudioSource.audio.volume = newVolume Pipewire.defaultAudioSource.audio.volume = newVolume
} }
} }