Files
launcher/qt/qml/Drawer.qml
T
Claude e050f52417 Qt: fix the clear button in the search boxes
On Android the keyboard keeps the word being typed out of TextInput.text
until it is committed, so the clear button didn't show for it and clearing
left the composing word behind. The box now filters and shows the clear
button by displayText, and clearing resets the input method first. The
button is a 44px target that keeps its press.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DPL5hiQsCq11CwCPnKPp9D
2026-11-02 05:27:37 +00:00

148 lines
4.8 KiB
QML

import QtQuick
// Every app, with a search. It slides down over the home screen; swiping up past the
// end of the list (or Close, or back) puts it away. In pick mode a tap adds an app to
// the home screen or takes it off, and the keyboard stays down.
Item {
id: root
property bool open: false
property bool picking: false
property var apps: [] // [{label, component, system}]
property var homeSet: ({}) // component -> true: on the home screen
property bool loading: true
property int generation: 0
property real insetTop: 0
property real insetBottom: 0
property alias query: search.text
readonly property real edge: y + height // the drawer's bottom edge, for covering widgets
readonly property var shown: {
const q = search.shown.toLowerCase();
const out = [];
for (let i = 0; i < apps.length; i++)
if (!q || apps[i].label.toLowerCase().indexOf(q) >= 0) out.push(i);
return out;
}
signal openApp(int row)
signal toggleApp(int row)
signal appMenu(int row)
signal closeRequested()
width: parent.width
height: parent.height
y: open ? 0 : -height
visible: y > -height
Behavior on y { NumberAnimation { duration: 220; easing.type: Easing.OutCubic } }
function openFirst() {
if (shown.length > 0 && search.shown.length > 0) openApp(shown[0]);
}
onOpenChanged: {
if (open && !picking) search.focusNow();
if (!open) {
search.input.focus = false;
Qt.inputMethod.hide();
search.text = "";
grid.positionViewAtBeginning();
}
}
Rectangle {
anchors.fill: parent
color: Qt.rgba(10 / 255, 10 / 255, 14 / 255, .9)
}
MouseArea { anchors.fill: parent } // nothing under the drawer takes its touches
Column {
id: head
x: Math.max(16, (root.width - 560) / 2 + 16)
width: Math.min(root.width, 560) - 32
y: root.insetTop + 16
spacing: 16
Row {
width: parent.width
spacing: 8
SearchField {
id: search
width: parent.width - close.width - 8
placeholder: "Search apps"
onAccepted: root.openFirst()
onEscaped: text = ""
}
PillButton {
id: close
anchors.verticalCenter: search.verticalCenter
text: root.picking ? "Done" : "Close"
onClicked: root.closeRequested()
}
}
Text {
visible: root.picking
width: parent.width
text: "Tap apps to add them to the home screen or take them off."
color: "white"
opacity: .8
font.pixelSize: 14
wrapMode: Text.Wrap
horizontalAlignment: Text.AlignHCenter
}
}
GridView {
id: grid
objectName: "drawerGrid"
x: head.x
width: head.width
anchors.top: head.bottom
anchors.topMargin: 16
anchors.bottom: parent.bottom
readonly property int cols: root.width >= 480 ? 5 : 4
cellWidth: width / cols
cellHeight: 104
clip: true
bottomMargin: root.insetBottom + 24
boundsBehavior: Flickable.DragOverBounds
model: root.shown
// Swiping up once the list is at its end puts the drawer away.
onDragEnded: if (verticalOvershoot > 48) root.closeRequested()
delegate: Item {
id: cell
required property int index
required property var modelData
readonly property var app: root.apps[modelData] || ({})
width: grid.cellWidth
height: grid.cellHeight
Tile {
width: parent.width
height: 84
key: "a:" + (cell.app.component || "")
label: cell.app.label || ""
generation: root.generation
iconSize: 52
fontSize: 12
spacing: 6
checkable: root.picking
checked: root.picking && root.homeSet[cell.app.component] === true
pressed: area.pressed
}
MouseArea {
id: area
width: parent.width
height: 84
pressAndHoldInterval: 450
onClicked: root.picking ? root.toggleApp(cell.modelData) : root.openApp(cell.modelData)
onPressAndHold: if (!root.picking) root.appMenu(cell.modelData)
}
}
}
Text {
anchors.centerIn: grid
visible: root.loading || root.shown.length === 0
text: root.loading ? "Loading apps…" : "No apps match."
color: "white"
opacity: .85
font.pixelSize: 15
}
}