1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2026-01-29 07:52:50 -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

@@ -11,7 +11,6 @@ Item {
property string placeholderText: "Search for a location..."
property bool _internalChange: false
property bool isLoading: false
property string helperTextState: "default" // "default", "prompt", "searching", "found", "not_found"
property string currentSearchText: ""
signal locationSelected(string displayName, string coordinates)
@@ -21,10 +20,8 @@ Item {
dropdownHideTimer.stop()
if (locationSearcher.running)
locationSearcher.running = false
isLoading = false
searchResultsModel.clear()
helperTextState = "default"
}
width: parent.width
@@ -47,7 +44,6 @@ Item {
searchResultsModel.clear()
root.isLoading = true
root.helperTextState = "searching"
const searchLocation = locationInput.text
root.currentSearchText = searchLocation
const encodedLocation = encodeURIComponent(searchLocation)
@@ -79,7 +75,6 @@ Item {
root.isLoading = false
if (exitCode !== 0) {
searchResultsModel.clear()
root.helperTextState = "not_found"
}
}
@@ -92,19 +87,16 @@ Item {
root.isLoading = false
searchResultsModel.clear()
if (!raw || raw[0] !== "[") {
root.helperTextState = "not_found"
return
}
try {
const data = JSON.parse(raw)
if (data.length === 0) {
root.helperTextState = "not_found"
return
}
for (var i = 0; i < Math.min(data.length, 5); i++) {
const location = data[i]
if (location.display_name && location.lat
&& location.lon) {
if (location.display_name && location.lat && location.lon) {
const parts = location.display_name.split(', ')
let cleanName = parts[0]
if (parts.length > 1) {
@@ -119,9 +111,8 @@ Item {
})
}
}
root.helperTextState = "found"
} catch (e) {
root.helperTextState = "not_found"
}
}
}
@@ -147,23 +138,18 @@ Item {
onTextEdited: {
if (root._internalChange)
return
if (getActiveFocus()) {
if (text.length > 2) {
root.isLoading = true
root.helperTextState = "searching"
locationSearchTimer.restart()
} else {
root.resetSearchState()
root.helperTextState = "prompt"
}
}
}
onFocusStateChanged: hasFocus => {
if (hasFocus) {
dropdownHideTimer.stop()
if (text.length <= 2)
root.helperTextState = "prompt"
} else {
dropdownHideTimer.start()
}
@@ -171,38 +157,13 @@ Item {
}
DankIcon {
name: {
if (root.isLoading)
return "hourglass_empty"
if (searchResultsModel.count > 0)
return "check_circle"
if (locationInput.getActiveFocus()
&& locationInput.text.length > 2 && !root.isLoading)
return "error"
return ""
}
name: root.isLoading ? "hourglass_empty" : (searchResultsModel.count > 0 ? "check_circle" : "error")
size: Theme.iconSize - 4
color: {
if (root.isLoading)
return Theme.surfaceVariantText
if (searchResultsModel.count > 0)
return Theme.success || Theme.primary
if (locationInput.getActiveFocus()
&& locationInput.text.length > 2)
return Theme.error
return "transparent"
}
color: root.isLoading ? Theme.surfaceVariantText : (searchResultsModel.count > 0 ? Theme.primary : Theme.error)
anchors.right: parent.right
anchors.rightMargin: Theme.spacingM
anchors.verticalCenter: parent.verticalCenter
opacity: (locationInput.getActiveFocus()
&& locationInput.text.length > 2) ? 1 : 0
opacity: (locationInput.getActiveFocus() && locationInput.text.length > 2) ? 1 : 0
Behavior on opacity {
NumberAnimation {
@@ -219,17 +180,13 @@ Item {
property bool hovered: false
width: parent.width
height: Math.min(
Math.max(
searchResultsModel.count * 38 + Theme.spacingS * 2,
50), 200)
height: Math.min(Math.max(searchResultsModel.count * 38 + Theme.spacingS * 2, 50), 200)
y: searchInputField.height
radius: Theme.cornerRadius
color: Theme.popupBackground()
border.color: Theme.primarySelected
border.width: 1
visible: locationInput.getActiveFocus() && locationInput.text.length > 2
&& (searchResultsModel.count > 0 || root.isLoading)
visible: locationInput.getActiveFocus() && locationInput.text.length > 2 && (searchResultsModel.count > 0 || root.isLoading)
MouseArea {
anchors.fill: parent
@@ -258,40 +215,6 @@ Item {
model: searchResultsModel
spacing: 2
// Qt 6.9+ scrolling: flickDeceleration/maximumFlickVelocity only affect touch now
interactive: true
flickDeceleration: 1500
maximumFlickVelocity: 2000
boundsBehavior: Flickable.DragAndOvershootBounds
boundsMovement: Flickable.FollowBoundsBehavior
pressDelay: 0
flickableDirection: Flickable.VerticalFlick
// Custom wheel handler for Qt 6.9+ responsive mouse wheel scrolling
WheelHandler {
acceptedDevices: PointerDevice.Mouse | PointerDevice.TouchPad
property real momentum: 0
onWheel: event => {
if (event.pixelDelta.y !== 0) {
// Touchpad with pixel delta
momentum = event.pixelDelta.y * 1.8
} else {
// Mouse wheel with angle delta
momentum = (event.angleDelta.y / 120)
* ((36 + parent.spacing) * 2.5) // ~2.5 items per wheel step
}
let newY = parent.contentY - momentum
newY = Math.max(
0, Math.min(
parent.contentHeight - parent.height,
newY))
parent.contentY = newY
momentum *= 0.92 // Decay for smooth momentum
event.accepted = true
}
}
delegate: StyledRect {
width: searchResultsList.width
height: 36
@@ -345,8 +268,7 @@ Item {
text: root.isLoading ? "Searching..." : "No locations found"
font.pixelSize: Theme.fontSizeMedium
color: Theme.surfaceVariantText
visible: searchResultsList.count === 0
&& locationInput.text.length > 2
visible: searchResultsList.count === 0 && locationInput.text.length > 2
}
}
}