1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2025-12-06 05:25:41 -05:00

better fuzzy search, sweeping clean and qmlfmt of Widgets

This commit is contained in:
bbedward
2025-09-03 12:52:03 -04:00
parent 886c6877d5
commit d4db8a01fe
50 changed files with 2112 additions and 2010 deletions

View File

@@ -1,17 +1,14 @@
import QtQuick
import QtQuick.Controls
import qs.Widgets
ListView {
id: listView
property real mouseWheelSpeed: 60
// Simple position preservation
property real savedY: 0
property bool justChanged: false
property bool isUserScrolling: false
// Kinetic scrolling momentum properties
property real momentumVelocity: 0
property bool isMomentumActive: false
property real friction: 0.95
@@ -25,8 +22,15 @@ ListView {
pressDelay: 0
flickableDirection: Flickable.VerticalFlick
onMovementStarted: isUserScrolling = true
onMovementEnded: isUserScrolling = false
onMovementStarted: {
isUserScrolling = true
vbar._scrollBarActive = true
vbar.hideTimer.stop()
}
onMovementEnded: {
isUserScrolling = false
vbar.hideTimer.restart()
}
onContentYChanged: {
if (!justChanged && isUserScrolling) {
@@ -35,7 +39,6 @@ ListView {
justChanged = false
}
// Restore position when model changes
onModelChanged: {
justChanged = true
contentY = savedY
@@ -43,10 +46,7 @@ ListView {
WheelHandler {
id: wheelHandler
// Tunable parameters for responsive scrolling
property real touchpadSpeed: 1.8 // Touchpad sensitivity
property real momentumRetention: 0.92
property real touchpadSpeed: 1.8
property real lastWheelTime: 0
property real momentum: 0
property var velocitySamples: []
@@ -59,16 +59,16 @@ ListView {
acceptedDevices: PointerDevice.Mouse | PointerDevice.TouchPad
onWheel: event => {
isUserScrolling = true // Mark as user interaction
isUserScrolling = true
vbar._scrollBarActive = true
vbar.hideTimer.restart()
let currentTime = Date.now()
let timeDelta = currentTime - lastWheelTime
const currentTime = Date.now()
const timeDelta = currentTime - lastWheelTime
lastWheelTime = currentTime
// Detect mouse wheel vs touchpad, seems like assuming based on the increments is the only way in QT
const deltaY = event.angleDelta.y
const isMouseWheel = Math.abs(deltaY) >= 120
&& (Math.abs(deltaY) % 120) === 0
const isMouseWheel = Math.abs(deltaY) >= 120 && (Math.abs(deltaY) % 120) === 0
if (isMouseWheel) {
momentumTimer.stop()
@@ -79,13 +79,11 @@ ListView {
const lines = Math.floor(Math.abs(deltaY) / 120)
const scrollAmount = (deltaY > 0 ? -lines : lines) * mouseWheelSpeed
let newY = listView.contentY + scrollAmount
newY = Math.max(
0,
Math.min(listView.contentHeight - listView.height,
newY))
newY = Math.max(0, Math.min(listView.contentHeight - listView.height, newY))
if (listView.flicking)
listView.cancelFlick()
if (listView.flicking) {
listView.cancelFlick()
}
listView.contentY = newY
savedY = newY
@@ -93,61 +91,43 @@ ListView {
momentumTimer.stop()
isMomentumActive = false
// Calculate scroll delta based on input type
let delta = 0
if (event.pixelDelta.y !== 0) {
// Touchpad with pixel precision
delta = event.pixelDelta.y * touchpadSpeed
} else {
// Fallback for touchpad without pixel delta
delta = event.angleDelta.y / 8 * touchpadSpeed
}
// Track velocity for momentum
velocitySamples.push({
"delta": delta,
"time": currentTime
})
velocitySamples = velocitySamples.filter(s => {
return currentTime
- s.time < 100
})
velocitySamples = velocitySamples.filter(s => currentTime - s.time < 100)
// Calculate momentum velocity from samples
if (velocitySamples.length > 1) {
let totalDelta = velocitySamples.reduce(
(sum, s) => {
return sum + s.delta
}, 0)
let timeSpan = currentTime - velocitySamples[0].time
if (timeSpan > 0)
momentumVelocity = Math.max(
-maxMomentumVelocity,
Math.min(maxMomentumVelocity,
totalDelta / timeSpan * 1000))
const totalDelta = velocitySamples.reduce((sum, s) => sum + s.delta, 0)
const timeSpan = currentTime - velocitySamples[0].time
if (timeSpan > 0) {
momentumVelocity = Math.max(-maxMomentumVelocity, Math.min(maxMomentumVelocity, totalDelta / timeSpan * 1000))
}
}
// Apply momentum for touchpad (smooth continuous scrolling)
if (event.pixelDelta.y !== 0 && timeDelta < 50) {
momentum = momentum * momentumRetention + delta * 0.15
momentum = momentum * 0.92 + delta * 0.15
delta += momentum
} else {
momentum = 0
}
// Apply scrolling with proper bounds checking
let newY = listView.contentY - delta
newY = Math.max(
0,
Math.min(listView.contentHeight - listView.height,
newY))
newY = Math.max(0, Math.min(listView.contentHeight - listView.height, newY))
// Cancel any conflicting flicks and apply new position
if (listView.flicking)
listView.cancelFlick()
if (listView.flicking) {
listView.cancelFlick()
}
listView.contentY = newY
savedY = newY // Update saved position
savedY = newY
}
event.accepted = true
@@ -156,8 +136,6 @@ ListView {
onActiveChanged: {
if (!active) {
isUserScrolling = false
// Start momentum if applicable (touchpad only)
if (Math.abs(momentumVelocity) >= minMomentumVelocity) {
startMomentum()
} else {
@@ -168,28 +146,18 @@ ListView {
}
}
// Physics-based momentum timer for kinetic scrolling (touchpad only)
Timer {
id: momentumTimer
interval: 16 // ~60 FPS
interval: 16
repeat: true
onTriggered: {
// Apply velocity to position
let newY = contentY - momentumVelocity * 0.016
let maxY = Math.max(0, contentHeight - height)
const newY = contentY - momentumVelocity * 0.016
const maxY = Math.max(0, contentHeight - height)
// Stop momentum at boundaries instead of bouncing
if (newY < 0) {
contentY = 0
savedY = 0
stop()
isMomentumActive = false
momentumVelocity = 0
return
} else if (newY > maxY) {
contentY = maxY
savedY = maxY
if (newY < 0 || newY > maxY) {
contentY = newY < 0 ? 0 : maxY
savedY = contentY
stop()
isMomentumActive = false
momentumVelocity = 0
@@ -197,12 +165,9 @@ ListView {
}
contentY = newY
savedY = newY // Keep updating saved position during momentum
// Apply friction
savedY = newY
momentumVelocity *= friction
// Stop if velocity too low
if (Math.abs(momentumVelocity) < 5) {
stop()
isMomentumActive = false
@@ -211,12 +176,7 @@ ListView {
}
}
// Smooth return to bounds animation
NumberAnimation {
id: returnToBoundsAnimation
target: listView
property: "contentY"
duration: 300
easing.type: Easing.OutQuad
ScrollBar.vertical: DankScrollbar {
id: vbar
}
}