2023-10-22 03:59:27 +00:00
|
|
|
/*
|
|
|
|
|
* SPDX-FileCopyrightText: 2014 Aaron Seigo <aseigo@kde.org>
|
|
|
|
|
* SPDX-FileCopyrightText: 2015 Marco Martin <notmart@gmail.com>
|
|
|
|
|
* SPDX-FileCopyrightText: 2021-2023 Devin Lin <devin@kde.org>
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: LGPL-2.0-or-later
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import QtQuick
|
|
|
|
|
import QtQuick.Effects
|
2024-11-11 07:27:38 +00:00
|
|
|
import QtQuick.Controls as QQC2
|
2023-10-22 03:59:27 +00:00
|
|
|
import QtQuick.Layouts
|
|
|
|
|
|
|
|
|
|
import org.kde.plasma.core as PlasmaCore
|
|
|
|
|
import org.kde.plasma.components 3.0 as PlasmaComponents
|
|
|
|
|
import org.kde.plasma.extras 2.0 as PlasmaExtras
|
|
|
|
|
|
|
|
|
|
import org.kde.milou as Milou
|
|
|
|
|
import org.kde.kirigami 2.19 as Kirigami
|
|
|
|
|
|
2024-11-11 07:27:38 +00:00
|
|
|
MouseArea {
|
2023-10-22 03:59:27 +00:00
|
|
|
id: root
|
2024-11-11 07:27:38 +00:00
|
|
|
onClicked: root.requestedClose()
|
2023-10-22 03:59:27 +00:00
|
|
|
|
|
|
|
|
function requestFocus() {
|
|
|
|
|
queryField.forceActiveFocus();
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-16 07:11:03 +00:00
|
|
|
function clearField() {
|
|
|
|
|
queryField.text = "";
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-22 03:59:27 +00:00
|
|
|
signal requestedClose()
|
|
|
|
|
|
2024-11-11 07:27:38 +00:00
|
|
|
Keys.onPressed: (event) => {
|
|
|
|
|
if (event.key === Qt.Key_Escape) {
|
|
|
|
|
root.requestedClose();
|
|
|
|
|
event.accepted = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-22 03:59:27 +00:00
|
|
|
ColumnLayout {
|
|
|
|
|
id: column
|
|
|
|
|
anchors.fill: parent
|
|
|
|
|
|
2024-11-11 07:27:38 +00:00
|
|
|
Kirigami.SearchField {
|
|
|
|
|
id: queryField
|
2023-10-22 03:59:27 +00:00
|
|
|
Layout.maximumWidth: Kirigami.Units.gridUnit * 30
|
2024-11-11 07:27:38 +00:00
|
|
|
Layout.fillWidth: true
|
2023-10-22 03:59:27 +00:00
|
|
|
Layout.alignment: Qt.AlignHCenter
|
|
|
|
|
Layout.topMargin: Kirigami.Units.gridUnit
|
|
|
|
|
Layout.leftMargin: Kirigami.Units.gridUnit
|
|
|
|
|
Layout.rightMargin: Kirigami.Units.gridUnit
|
|
|
|
|
|
2024-11-11 07:27:38 +00:00
|
|
|
background: Rectangle {
|
|
|
|
|
radius: Kirigami.Units.cornerRadius
|
|
|
|
|
color: Qt.rgba(255, 255, 255, (queryField.hovered || queryField.focus) ? 0.2 : 0.1)
|
2023-10-22 03:59:27 +00:00
|
|
|
|
2024-11-11 07:27:38 +00:00
|
|
|
Behavior on color { ColorAnimation {} }
|
2023-10-22 03:59:27 +00:00
|
|
|
}
|
|
|
|
|
|
2024-11-11 07:27:38 +00:00
|
|
|
Kirigami.Theme.inherit: false
|
|
|
|
|
Kirigami.Theme.colorSet: Kirigami.Theme.Complementary
|
|
|
|
|
|
|
|
|
|
topPadding: Kirigami.Units.largeSpacing + Kirigami.Units.smallSpacing
|
|
|
|
|
bottomPadding: Kirigami.Units.largeSpacing + Kirigami.Units.smallSpacing
|
|
|
|
|
|
|
|
|
|
placeholderText: i18nc("@info:placeholder", "Search…")
|
|
|
|
|
placeholderTextColor: Qt.rgba(255, 255, 255, 0.8)
|
|
|
|
|
color: 'white'
|
|
|
|
|
inputMethodHints: Qt.ImhNoPredictiveText // don't need to press "enter" to update text
|
|
|
|
|
|
|
|
|
|
font.weight: Font.Bold
|
|
|
|
|
|
|
|
|
|
KeyNavigation.down: listView
|
2023-10-22 03:59:27 +00:00
|
|
|
}
|
|
|
|
|
|
2024-11-11 07:27:38 +00:00
|
|
|
QQC2.ScrollView {
|
2023-10-22 03:59:27 +00:00
|
|
|
Layout.fillWidth: true
|
|
|
|
|
Layout.fillHeight: listView.contentHeight > availableHeight
|
|
|
|
|
|
2024-11-11 07:27:38 +00:00
|
|
|
Layout.maximumWidth: Kirigami.Units.gridUnit * 30
|
|
|
|
|
Layout.leftMargin: Kirigami.Units.gridUnit
|
|
|
|
|
Layout.rightMargin: Kirigami.Units.gridUnit
|
|
|
|
|
Layout.alignment: Qt.AlignHCenter
|
|
|
|
|
|
2023-10-22 03:59:27 +00:00
|
|
|
Milou.ResultsListView {
|
|
|
|
|
id: listView
|
|
|
|
|
queryString: queryField.text
|
|
|
|
|
clip: true
|
|
|
|
|
|
|
|
|
|
highlight: activeFocus ? highlightComponent : null
|
|
|
|
|
Component {
|
|
|
|
|
id: highlightComponent
|
|
|
|
|
|
|
|
|
|
PlasmaExtras.Highlight {}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onActivated: {
|
|
|
|
|
root.requestedClose();
|
|
|
|
|
}
|
|
|
|
|
onUpdateQueryString: {
|
|
|
|
|
queryField.text = text
|
|
|
|
|
queryField.cursorPosition = cursorPosition
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-11 07:27:38 +00:00
|
|
|
section.delegate: QQC2.Control {
|
|
|
|
|
id: sectionHeader
|
|
|
|
|
required property string section
|
|
|
|
|
|
|
|
|
|
topPadding: Kirigami.Units.smallSpacing
|
|
|
|
|
bottomPadding: Kirigami.Units.smallSpacing
|
|
|
|
|
leftPadding: 0
|
|
|
|
|
rightPadding: 0
|
|
|
|
|
|
|
|
|
|
contentItem: Kirigami.Heading {
|
|
|
|
|
opacity: 0.7
|
|
|
|
|
level: 5
|
|
|
|
|
type: Kirigami.Heading.Primary
|
|
|
|
|
text: sectionHeader.section
|
|
|
|
|
elide: Text.ElideRight
|
|
|
|
|
color: 'white'
|
|
|
|
|
|
|
|
|
|
// we override the Primary type's font weight (DemiBold) for Bold for contrast with small text
|
|
|
|
|
font.weight: Font.Bold
|
|
|
|
|
Accessible.ignored: true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2023-10-22 03:59:27 +00:00
|
|
|
delegate: MouseArea {
|
|
|
|
|
id: delegate
|
|
|
|
|
height: rowLayout.height
|
|
|
|
|
width: listView.width
|
|
|
|
|
|
2024-11-11 07:27:38 +00:00
|
|
|
// Go to search bar if this we press up with the first item selected
|
|
|
|
|
KeyNavigation.up: model.index === 0 ? queryField : null
|
2023-10-22 03:59:27 +00:00
|
|
|
|
2024-11-11 07:27:38 +00:00
|
|
|
// Close search view if we press down with last item selected
|
|
|
|
|
Keys.onPressed: (event) => {
|
|
|
|
|
if (event.key === Qt.Key_Down && (model.index === listView.count - 1)) {
|
|
|
|
|
root.requestedClose();
|
|
|
|
|
event.accepted = true;
|
|
|
|
|
}
|
2023-10-22 03:59:27 +00:00
|
|
|
}
|
|
|
|
|
|
2024-11-11 07:27:38 +00:00
|
|
|
// Used by ResultsListView to determine next tab action
|
2023-10-22 03:59:27 +00:00
|
|
|
function activateNextAction() {
|
|
|
|
|
queryField.forceActiveFocus();
|
|
|
|
|
queryField.selectAll();
|
|
|
|
|
listView.currentIndex = -1;
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-11 07:27:38 +00:00
|
|
|
onClicked: {
|
|
|
|
|
listView.currentIndex = model.index;
|
|
|
|
|
listView.runCurrentIndex();
|
|
|
|
|
|
|
|
|
|
root.requestedClose();
|
|
|
|
|
}
|
|
|
|
|
hoverEnabled: true
|
|
|
|
|
|
2023-10-22 03:59:27 +00:00
|
|
|
Rectangle {
|
|
|
|
|
anchors.fill: parent
|
2024-11-11 07:27:38 +00:00
|
|
|
radius: Kirigami.Units.cornerRadius
|
|
|
|
|
color: delegate.pressed ? Qt.rgba(255, 255, 255, 0.3) : (delegate.containsMouse ? Qt.rgba(255, 255, 255, 0.1) : "transparent")
|
2023-10-22 03:59:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RowLayout {
|
|
|
|
|
id: rowLayout
|
|
|
|
|
height: Kirigami.Units.gridUnit * 3
|
|
|
|
|
anchors {
|
|
|
|
|
top: parent.top
|
|
|
|
|
left: parent.left
|
|
|
|
|
right: parent.right
|
2024-11-11 07:27:38 +00:00
|
|
|
leftMargin: Kirigami.Units.largeSpacing
|
|
|
|
|
rightMargin: Kirigami.Units.largeSpacing
|
2023-10-22 03:59:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Kirigami.Icon {
|
|
|
|
|
Layout.alignment: Qt.AlignVCenter
|
|
|
|
|
source: model.decoration
|
|
|
|
|
implicitWidth: Kirigami.Units.iconSizes.medium
|
|
|
|
|
implicitHeight: Kirigami.Units.iconSizes.medium
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ColumnLayout {
|
|
|
|
|
Layout.fillWidth: true
|
|
|
|
|
Layout.alignment: Qt.AlignVCenter
|
|
|
|
|
spacing: Kirigami.Units.smallSpacing
|
|
|
|
|
|
|
|
|
|
PlasmaComponents.Label {
|
|
|
|
|
id: title
|
|
|
|
|
Layout.fillWidth: true
|
|
|
|
|
Layout.leftMargin: Kirigami.Units.smallSpacing * 2
|
|
|
|
|
Layout.rightMargin: Kirigami.Units.gridUnit
|
|
|
|
|
|
|
|
|
|
maximumLineCount: 1
|
|
|
|
|
elide: Text.ElideRight
|
|
|
|
|
text: typeof modelData !== "undefined" ? modelData : model.display
|
|
|
|
|
color: "white"
|
|
|
|
|
|
|
|
|
|
font.pointSize: Kirigami.Theme.defaultFont.pointSize
|
|
|
|
|
}
|
|
|
|
|
PlasmaComponents.Label {
|
|
|
|
|
id: subtitle
|
|
|
|
|
Layout.fillWidth: true
|
|
|
|
|
Layout.leftMargin: Kirigami.Units.smallSpacing * 2
|
|
|
|
|
Layout.rightMargin: Kirigami.Units.gridUnit
|
|
|
|
|
|
|
|
|
|
maximumLineCount: 1
|
|
|
|
|
elide: Text.ElideRight
|
|
|
|
|
text: model.subtext || ""
|
|
|
|
|
color: "white"
|
|
|
|
|
opacity: 0.8
|
|
|
|
|
|
|
|
|
|
font.pointSize: Math.round(Kirigami.Theme.defaultFont.pointSize * 0.8)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-11 07:27:38 +00:00
|
|
|
Item {
|
2023-10-22 03:59:27 +00:00
|
|
|
Layout.fillWidth: true
|
|
|
|
|
Layout.fillHeight: true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|