shift-shell/applets/krunner/contents/ui/main.qml

214 lines
9.1 KiB
QML
Raw Normal View History

2020-02-05 18:57:44 +00:00
/*
2021-03-01 20:03:25 +00:00
* SPDX-FileCopyrightText: 2014 Aaron Seigo <aseigo@kde.org>
* SPDX-FileCopyrightText: 2015 Marco Martin <notmart@gmail.com>
2020-02-05 18:57:44 +00:00
*
2021-03-01 20:03:25 +00:00
* SPDX-License-Identifier: LGPL-2.0-or-later
2020-02-05 18:57:44 +00:00
*/
import QtQuick 2.1
import QtQuick.Window 2.1
import QtQuick.Controls 2.2 as Controls
import QtQuick.Layouts 1.1
2021-04-02 04:45:22 +00:00
import QtGraphicalEffects 1.12
2020-02-05 18:57:44 +00:00
import org.kde.plasma.plasmoid 2.0
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 3.0 as PlasmaComponents
2020-07-23 13:26:26 +00:00
import org.kde.plasma.extras 2.0 as PlasmaExtras
2020-02-05 18:57:44 +00:00
import org.kde.milou 0.1 as Milou
2020-07-23 13:26:26 +00:00
import org.kde.kirigami 2.14 as Kirigami
2020-02-05 18:57:44 +00:00
2020-02-05 19:25:52 +00:00
Item {
2020-02-05 18:57:44 +00:00
PlasmaCore.ColorScope.colorGroup: PlasmaCore.Theme.NormalColorGroup
Plasmoid.backgroundHints: PlasmaCore.Types.ShadowBackground | PlasmaCore.Types.ConfigurableBackground
2020-07-16 12:58:46 +00:00
Layout.minimumWidth: Math.min(plasmoid.availableScreenRect.width, plasmoid.availableScreenRect.height) - Kirigami.Units.gridUnit * 2
2020-02-05 19:25:52 +00:00
2020-07-23 13:26:26 +00:00
Rectangle {
id: background
2020-02-05 19:25:52 +00:00
anchors {
2020-07-23 13:26:26 +00:00
left: parent.left
right: parent.right
verticalCenter: parent.verticalCenter
2020-02-05 19:25:52 +00:00
margins: units.gridUnit
2020-02-05 18:57:44 +00:00
}
2020-07-23 13:26:26 +00:00
radius: height/2
2021-04-02 04:45:22 +00:00
height: layout.implicitHeight + PlasmaCore.Units.largeSpacing
2020-07-23 13:26:26 +00:00
color: Qt.rgba(1,1,1, 0.3)
RowLayout {
id: layout
anchors {
left: parent.left
2021-04-02 04:45:22 +00:00
right: parent.right
2020-07-23 13:26:26 +00:00
verticalCenter: parent.verticalCenter
margins: background.radius/2
}
2021-04-02 04:45:22 +00:00
spacing: PlasmaCore.Units.smallSpacing * 2
2020-07-23 13:26:26 +00:00
Kirigami.Icon {
2021-04-02 04:45:22 +00:00
source: "start-here-symbolic"
Layout.preferredHeight: PlasmaCore.Units.gridUnit * 1.5
2020-07-23 13:26:26 +00:00
Layout.preferredWidth: height
color: "white"
}
PlasmaExtras.Heading {
2021-04-02 04:45:22 +00:00
level: 3
2020-07-23 13:26:26 +00:00
text: i18n("Search...")
}
2021-04-02 04:45:22 +00:00
Item { Layout.fillWidth: true }
Kirigami.Icon {
source: "search"
Layout.preferredHeight: PlasmaCore.Units.gridUnit * 1.5
Layout.preferredWidth: height
color: "white"
}
2020-07-23 13:26:26 +00:00
}
2021-04-02 04:45:22 +00:00
2020-02-05 19:25:52 +00:00
MouseArea {
2020-02-05 18:57:44 +00:00
anchors.fill: parent
2020-02-05 19:25:52 +00:00
onClicked: window.showMaximized()
}
2021-04-02 04:45:22 +00:00
2020-02-05 19:25:52 +00:00
Kirigami.AbstractApplicationWindow {
id: window
visible: false
2021-04-02 04:45:22 +00:00
color: "transparent"
2020-02-05 19:25:52 +00:00
onVisibleChanged: {
if (!visible) {
2020-02-05 19:25:52 +00:00
queryField.forceActiveFocus();
}
}
2021-04-02 04:45:22 +00:00
MouseArea {
2020-02-05 19:25:52 +00:00
anchors.fill: parent
2021-04-02 04:45:22 +00:00
onClicked: window.close();
// shadow for search window
RectangularGlow {
anchors.topMargin: 1
anchors.fill: content
cached: true
glowRadius: 4
spread: 0.2
color: Qt.rgba(0, 0, 0, 0.15)
2020-07-27 15:18:50 +00:00
}
2021-04-02 04:45:22 +00:00
MouseArea {
id: content
// capture presses on the rectangle so that it doesn't close the window
anchors.top: parent.top
anchors.topMargin: Kirigami.Units.largeSpacing * 2
anchors.horizontalCenter: parent.horizontalCenter
implicitWidth: Math.min(Kirigami.Units.gridUnit * 30, parent.width - Kirigami.Units.largeSpacing * 4)
implicitHeight: Math.min(mainColumn.implicitHeight, parent.height - Kirigami.Units.largeSpacing * 4)
Behavior on implicitHeight {
NumberAnimation {
duration: Kirigami.Units.longDuration
easing: Easing.InOutQuad
2020-07-27 15:18:50 +00:00
}
2021-04-02 04:45:22 +00:00
}
Rectangle {
anchors.fill: parent
radius: Kirigami.Units.smallSpacing
Kirigami.Theme.inherit: false
Kirigami.Theme.colorSet: Kirigami.Theme.View
color: Kirigami.Theme.backgroundColor
ColumnLayout {
id: mainColumn
anchors.fill: parent
anchors.margins: Kirigami.Units.smallSpacing
RowLayout {
Layout.bottomMargin: Kirigami.Units.smallSpacing / 2
Item {
implicitHeight: queryField.height
implicitWidth: height
Kirigami.Icon {
anchors.fill: parent
anchors.margins: Math.round(Kirigami.Units.smallSpacing * 1.5)
source: "start-here-symbolic"
}
}
Kirigami.SearchField {
id: queryField
focus: true
Layout.fillWidth: true
}
2020-07-27 15:18:50 +00:00
}
2021-04-02 04:45:22 +00:00
Controls.ScrollView {
Layout.fillHeight: true
Layout.fillWidth: true
Milou.ResultsListView {
id: listView
queryString: queryField.text
highlight: null
PlasmaCore.ColorScope.colorGroup: PlasmaCore.Theme.NormalColorGroup
anchors.rightMargin: 10
onActivated: {
window.visible = false;
queryField.text = "";
}
onUpdateQueryString: {
queryField.text = text
queryField.cursorPosition = cursorPosition
}
delegate: Kirigami.BasicListItem {
id: resultDelegate
property var additionalActions: typeof actions !== "undefined" ? actions : []
icon: model.decoration
label: typeof modelData !== "undefined" ? modelData : model.display
subtitle: model.subtext || ""
onClicked: {
listView.currentIndex = model.index
listView.runCurrentIndex()
2020-07-27 15:18:50 +00:00
}
2021-04-02 04:45:22 +00:00
Row {
id: actionsRow
Repeater {
id: actionsRepeater
model: resultDelegate.additionalActions
Controls.ToolButton {
width: height
height: listItem.height
visible: modelData.visible || true
enabled: modelData.enabled || true
2020-02-05 18:57:44 +00:00
2021-04-02 04:45:22 +00:00
Accessible.role: Accessible.Button
Accessible.name: modelData.text
checkable: checked
checked: resultDelegate.activeAction === index
focus: resultDelegate.activeAction === index
Kirigami.Icon {
2021-04-02 04:45:22 +00:00
anchors.centerIn: parent
width: units.iconSizes.small
height: units.iconSizes.small
// ToolButton cannot cope with QIcon
source: modelData.icon || ""
active: parent.hovered || parent.checked
}
onClicked: resultDelegate.ListView.view.runAction(index)
}
}
}
2020-07-27 15:18:50 +00:00
}
}
}
}
2020-02-05 19:25:52 +00:00
}
2020-02-05 18:57:44 +00:00
}
}
}
}
}