1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2026-01-30 00:12:50 -05:00

Slider improvements

This commit is contained in:
bbedward
2025-07-15 15:37:37 -04:00
parent 9035cb750b
commit 6010b964d8
5 changed files with 311 additions and 141 deletions

View File

@@ -173,10 +173,19 @@ Singleton {
deviceObj.type = deviceType deviceObj.type = deviceType
deviceObj.paired = nativeDevice.paired deviceObj.paired = nativeDevice.paired
// If device connected state changed, clear connecting/failed states // If device connected state changed, clear connecting/failed states and refresh audio
if (deviceObj.connected !== nativeDevice.connected) { if (deviceObj.connected !== nativeDevice.connected) {
deviceObj.connecting = false deviceObj.connecting = false
deviceObj.connectionFailed = false deviceObj.connectionFailed = false
// Refresh audio devices when bluetooth audio device connects/disconnects
if (deviceType === "headset" || deviceType === "speaker") {
Qt.callLater(() => {
if (typeof AudioService !== 'undefined') {
AudioService.updateDevices()
}
})
}
} }
deviceObj.connected = nativeDevice.connected deviceObj.connected = nativeDevice.connected

View File

@@ -186,6 +186,11 @@ Rectangle {
} }
// Progress bar // Progress bar
Item {
id: progressBarContainer
width: parent.width
height: 32
Rectangle { Rectangle {
id: progressBarBackground id: progressBarBackground
width: parent.width width: parent.width
@@ -193,6 +198,7 @@ Rectangle {
radius: 3 radius: 3
color: Qt.rgba(theme.surfaceVariant.r, theme.surfaceVariant.g, theme.surfaceVariant.b, 0.3) color: Qt.rgba(theme.surfaceVariant.r, theme.surfaceVariant.g, theme.surfaceVariant.b, 0.3)
visible: activePlayer !== null visible: activePlayer !== null
anchors.verticalCenter: parent.verticalCenter
Rectangle { Rectangle {
id: progressFill id: progressFill
@@ -227,6 +233,7 @@ Rectangle {
NumberAnimation { duration: 150 } NumberAnimation { duration: 150 }
} }
} }
}
MouseArea { MouseArea {
id: progressMouseArea id: progressMouseArea
@@ -234,22 +241,14 @@ Rectangle {
hoverEnabled: true hoverEnabled: true
cursorShape: Qt.PointingHandCursor cursorShape: Qt.PointingHandCursor
enabled: activePlayer && activePlayer.length > 0 && activePlayer.canSeek enabled: activePlayer && activePlayer.length > 0 && activePlayer.canSeek
preventStealing: true
property bool isSeeking: false property bool isSeeking: false
onClicked: function(mouse) {
if (activePlayer && activePlayer.length > 0) {
let ratio = mouse.x / width
let seekPosition = ratio * activePlayer.length
activePlayer.position = seekPosition
currentPosition = seekPosition
}
}
onPressed: function(mouse) { onPressed: function(mouse) {
isSeeking = true isSeeking = true
if (activePlayer && activePlayer.length > 0) { if (activePlayer && activePlayer.length > 0) {
let ratio = Math.max(0, Math.min(1, mouse.x / width)) let ratio = Math.max(0, Math.min(1, mouse.x / progressBarBackground.width))
let seekPosition = ratio * activePlayer.length let seekPosition = ratio * activePlayer.length
activePlayer.position = seekPosition activePlayer.position = seekPosition
currentPosition = seekPosition currentPosition = seekPosition
@@ -261,13 +260,45 @@ Rectangle {
} }
onPositionChanged: function(mouse) { onPositionChanged: function(mouse) {
if (pressed && activePlayer && activePlayer.length > 0) { if (pressed && isSeeking && activePlayer && activePlayer.length > 0) {
let ratio = Math.max(0, Math.min(1, mouse.x / width)) let ratio = Math.max(0, Math.min(1, mouse.x / progressBarBackground.width))
let seekPosition = ratio * activePlayer.length let seekPosition = ratio * activePlayer.length
activePlayer.position = seekPosition activePlayer.position = seekPosition
currentPosition = seekPosition currentPosition = seekPosition
} }
} }
onClicked: function(mouse) {
if (activePlayer && activePlayer.length > 0) {
let ratio = Math.max(0, Math.min(1, mouse.x / progressBarBackground.width))
let seekPosition = ratio * activePlayer.length
activePlayer.position = seekPosition
currentPosition = seekPosition
}
}
}
// Global mouse area for drag tracking
MouseArea {
id: progressGlobalMouseArea
anchors.fill: parent.parent.parent // Fill the entire media player widget
enabled: progressMouseArea.isSeeking
visible: false
preventStealing: true
onPositionChanged: function(mouse) {
if (progressMouseArea.isSeeking && activePlayer && activePlayer.length > 0) {
let globalPos = mapToItem(progressBarBackground, mouse.x, mouse.y)
let ratio = Math.max(0, Math.min(1, globalPos.x / progressBarBackground.width))
let seekPosition = ratio * activePlayer.length
activePlayer.position = seekPosition
currentPosition = seekPosition
}
}
onReleased: {
progressMouseArea.isSeeking = false
}
} }
} }

View File

@@ -117,9 +117,15 @@ Item {
} }
} }
Item {
id: volumeSliderContainer
width: parent.width - 80
height: 32
anchors.verticalCenter: parent.verticalCenter
Rectangle { Rectangle {
id: volumeSliderTrack id: volumeSliderTrack
width: parent.width - 80 width: parent.width
height: 8 height: 8
radius: 4 radius: 4
color: Qt.rgba(Theme.surfaceVariant.r, Theme.surfaceVariant.g, Theme.surfaceVariant.b, 0.3) color: Qt.rgba(Theme.surfaceVariant.r, Theme.surfaceVariant.g, Theme.surfaceVariant.b, 0.3)
@@ -156,26 +162,63 @@ Item {
NumberAnimation { duration: 150 } NumberAnimation { duration: 150 }
} }
} }
}
MouseArea { MouseArea {
id: volumeMouseArea id: volumeMouseArea
anchors.fill: parent anchors.fill: parent
hoverEnabled: true hoverEnabled: true
cursorShape: Qt.PointingHandCursor cursorShape: Qt.PointingHandCursor
preventStealing: true
onClicked: (mouse) => { property bool isDragging: false
let ratio = Math.max(0, Math.min(1, mouse.x / width))
onPressed: (mouse) => {
isDragging = true
let ratio = Math.max(0, Math.min(1, mouse.x / volumeSliderTrack.width))
let newVolume = Math.round(ratio * 100) let newVolume = Math.round(ratio * 100)
AudioService.setVolume(newVolume) AudioService.setVolume(newVolume)
} }
onReleased: {
isDragging = false
}
onPositionChanged: (mouse) => { onPositionChanged: (mouse) => {
if (pressed) { if (pressed && isDragging) {
let ratio = Math.max(0, Math.min(1, mouse.x / width)) let ratio = Math.max(0, Math.min(1, mouse.x / volumeSliderTrack.width))
let newVolume = Math.round(ratio * 100) let newVolume = Math.round(ratio * 100)
AudioService.setVolume(newVolume) AudioService.setVolume(newVolume)
} }
} }
onClicked: (mouse) => {
let ratio = Math.max(0, Math.min(1, mouse.x / volumeSliderTrack.width))
let newVolume = Math.round(ratio * 100)
AudioService.setVolume(newVolume)
}
}
// Global mouse area for drag tracking
MouseArea {
id: volumeGlobalMouseArea
anchors.fill: parent.parent.parent.parent.parent // Fill the entire control center
enabled: volumeMouseArea.isDragging
visible: false
preventStealing: true
onPositionChanged: (mouse) => {
if (volumeMouseArea.isDragging) {
let globalPos = mapToItem(volumeSliderTrack, mouse.x, mouse.y)
let ratio = Math.max(0, Math.min(1, globalPos.x / volumeSliderTrack.width))
let newVolume = Math.round(ratio * 100)
AudioService.setVolume(newVolume)
}
}
onReleased: {
volumeMouseArea.isDragging = false
}
} }
} }
@@ -349,9 +392,15 @@ Item {
} }
} }
Item {
id: micSliderContainer
width: parent.width - 80
height: 32
anchors.verticalCenter: parent.verticalCenter
Rectangle { Rectangle {
id: micSliderTrack id: micSliderTrack
width: parent.width - 80 width: parent.width
height: 8 height: 8
radius: 4 radius: 4
color: Qt.rgba(Theme.surfaceVariant.r, Theme.surfaceVariant.g, Theme.surfaceVariant.b, 0.3) color: Qt.rgba(Theme.surfaceVariant.r, Theme.surfaceVariant.g, Theme.surfaceVariant.b, 0.3)
@@ -388,26 +437,63 @@ Item {
NumberAnimation { duration: 150 } NumberAnimation { duration: 150 }
} }
} }
}
MouseArea { MouseArea {
id: micMouseArea id: micMouseArea
anchors.fill: parent anchors.fill: parent
hoverEnabled: true hoverEnabled: true
cursorShape: Qt.PointingHandCursor cursorShape: Qt.PointingHandCursor
preventStealing: true
onClicked: (mouse) => { property bool isDragging: false
let ratio = Math.max(0, Math.min(1, mouse.x / width))
onPressed: (mouse) => {
isDragging = true
let ratio = Math.max(0, Math.min(1, mouse.x / micSliderTrack.width))
let newMicLevel = Math.round(ratio * 100) let newMicLevel = Math.round(ratio * 100)
AudioService.setMicLevel(newMicLevel) AudioService.setMicLevel(newMicLevel)
} }
onReleased: {
isDragging = false
}
onPositionChanged: (mouse) => { onPositionChanged: (mouse) => {
if (pressed) { if (pressed && isDragging) {
let ratio = Math.max(0, Math.min(1, mouse.x / width)) let ratio = Math.max(0, Math.min(1, mouse.x / micSliderTrack.width))
let newMicLevel = Math.round(ratio * 100) let newMicLevel = Math.round(ratio * 100)
AudioService.setMicLevel(newMicLevel) AudioService.setMicLevel(newMicLevel)
} }
} }
onClicked: (mouse) => {
let ratio = Math.max(0, Math.min(1, mouse.x / micSliderTrack.width))
let newMicLevel = Math.round(ratio * 100)
AudioService.setMicLevel(newMicLevel)
}
}
// Global mouse area for drag tracking
MouseArea {
id: micGlobalMouseArea
anchors.fill: parent.parent.parent.parent.parent // Fill the entire control center
enabled: micMouseArea.isDragging
visible: false
preventStealing: true
onPositionChanged: (mouse) => {
if (micMouseArea.isDragging) {
let globalPos = mapToItem(micSliderTrack, mouse.x, mouse.y)
let ratio = Math.max(0, Math.min(1, globalPos.x / micSliderTrack.width))
let newMicLevel = Math.round(ratio * 100)
AudioService.setMicLevel(newMicLevel)
}
}
onReleased: {
micMouseArea.isDragging = false
}
} }
} }

View File

@@ -110,24 +110,23 @@ Item {
} }
} }
Item {
id: sliderContainer
anchors.fill: parent
MouseArea { MouseArea {
id: sliderMouseArea id: sliderMouseArea
anchors.fill: parent anchors.fill: parent
hoverEnabled: true hoverEnabled: true
cursorShape: slider.enabled ? Qt.PointingHandCursor : Qt.ArrowCursor cursorShape: slider.enabled ? Qt.PointingHandCursor : Qt.ArrowCursor
enabled: slider.enabled enabled: slider.enabled
preventStealing: true
onClicked: (mouse) => { property bool isDragging: false
onPressed: (mouse) => {
if (slider.enabled) { if (slider.enabled) {
let ratio = Math.max(0, Math.min(1, mouse.x / width)) isDragging = true
let newValue = Math.round(slider.minimum + ratio * (slider.maximum - slider.minimum))
slider.value = newValue
slider.sliderValueChanged(newValue)
}
}
onPositionChanged: (mouse) => {
if (pressed && slider.enabled) {
let ratio = Math.max(0, Math.min(1, mouse.x / width)) let ratio = Math.max(0, Math.min(1, mouse.x / width))
let newValue = Math.round(slider.minimum + ratio * (slider.maximum - slider.minimum)) let newValue = Math.round(slider.minimum + ratio * (slider.maximum - slider.minimum))
slider.value = newValue slider.value = newValue
@@ -137,9 +136,55 @@ Item {
onReleased: { onReleased: {
if (slider.enabled) { if (slider.enabled) {
isDragging = false
slider.sliderDragFinished(slider.value) slider.sliderDragFinished(slider.value)
} }
} }
onPositionChanged: (mouse) => {
if (pressed && isDragging && slider.enabled) {
let ratio = Math.max(0, Math.min(1, mouse.x / width))
let newValue = Math.round(slider.minimum + ratio * (slider.maximum - slider.minimum))
slider.value = newValue
slider.sliderValueChanged(newValue)
}
}
onClicked: (mouse) => {
if (slider.enabled) {
let ratio = Math.max(0, Math.min(1, mouse.x / width))
let newValue = Math.round(slider.minimum + ratio * (slider.maximum - slider.minimum))
slider.value = newValue
slider.sliderValueChanged(newValue)
}
}
}
// Global mouse area for drag tracking
MouseArea {
id: sliderGlobalMouseArea
anchors.fill: slider.parent // Fill the entire settings popup
enabled: sliderMouseArea.isDragging
visible: false
preventStealing: true
onPositionChanged: (mouse) => {
if (sliderMouseArea.isDragging && slider.enabled) {
let globalPos = mapToItem(sliderTrack, mouse.x, mouse.y)
let ratio = Math.max(0, Math.min(1, globalPos.x / sliderTrack.width))
let newValue = Math.round(slider.minimum + ratio * (slider.maximum - slider.minimum))
slider.value = newValue
slider.sliderValueChanged(newValue)
}
}
onReleased: {
if (sliderMouseArea.isDragging && slider.enabled) {
sliderMouseArea.isDragging = false
slider.sliderDragFinished(slider.value)
}
}
}
} }
} }

View File

@@ -27,7 +27,7 @@ ShellRoot {
// Initialize service monitoring states based on preferences // Initialize service monitoring states based on preferences
SystemMonitorService.enableTopBarMonitoring(Prefs.showSystemResources) SystemMonitorService.enableTopBarMonitoring(Prefs.showSystemResources)
ProcessMonitorService.enableMonitoring(false) // Start disabled, enable when process dropdown is opened ProcessMonitorService.enableMonitoring(false) // Start disabled, enable when process dropdown is opened
AudioService.enableDeviceScanning(false) // Start disabled, enable when control center is opened // Audio service auto-updates devices, no manual scanning needed
} }
property bool calendarVisible: false property bool calendarVisible: false
@@ -46,14 +46,13 @@ ShellRoot {
property bool hasActiveMedia: activePlayer && (activePlayer.trackTitle || activePlayer.trackArtist) property bool hasActiveMedia: activePlayer && (activePlayer.trackTitle || activePlayer.trackArtist)
property bool controlCenterVisible: false property bool controlCenterVisible: false
// Monitor control center visibility to enable/disable audio device scanning // Monitor control center visibility to enable/disable bluetooth scanning
onControlCenterVisibleChanged: { onControlCenterVisibleChanged: {
console.log("Control center", controlCenterVisible ? "opened" : "closed") console.log("Control center", controlCenterVisible ? "opened" : "closed")
AudioService.enableDeviceScanning(controlCenterVisible)
BluetoothService.enableMonitoring(controlCenterVisible) BluetoothService.enableMonitoring(controlCenterVisible)
if (controlCenterVisible) { if (controlCenterVisible) {
// Immediately refresh devices when opening control center // Refresh devices when opening control center
AudioService.refreshDevices() AudioService.updateDevices()
} }
} }
property bool batteryPopupVisible: false property bool batteryPopupVisible: false