139 lines
6.6 KiB
QML
139 lines
6.6 KiB
QML
pragma ComponentBehavior: Bound
|
|
import QtQuick
|
|
import QtQuick.Controls.Material
|
|
import QtQuick.Controls
|
|
import QtQuick.Layouts
|
|
import Quickshell
|
|
import "services"
|
|
import "services/Policy.js" as Policy
|
|
import "components"
|
|
|
|
FocusScope {
|
|
id: launcher
|
|
Material.theme: Theme.dark ? Material.Dark : Material.Light
|
|
Material.accent: Theme.primary
|
|
signal done()
|
|
property string category: "all"
|
|
readonly property bool desktop: width >= 400 && height >= 360
|
|
readonly property var categories: [
|
|
{ key: "all", label: "Все" },
|
|
{ key: "favorites", label: "Избранное" },
|
|
{ key: "recent", label: "Недавние" }
|
|
]
|
|
readonly property var rankedApps: Policy.rankApps(DesktopEntries.applications.values.filter(app => !app.noDisplay && (app.name + " " + app.genericName + " " + app.keywords.join(" ")).toLowerCase().includes(search.text.toLowerCase())), Preferences.data.favorites, Preferences.data.appHistory)
|
|
readonly property var apps: rankedApps.filter(app => category === "all" ||
|
|
(category === "favorites" && (Preferences.data.favorites || []).includes(app.id)) ||
|
|
(category === "recent" && (Preferences.data.appHistory || []).some(entry => (typeof entry === "string" ? entry : entry.id) === app.id)))
|
|
onVisibleChanged: if (visible) { search.forceActiveFocus(); grid.currentIndex = 0; }
|
|
function launch(app) {
|
|
if (app) {
|
|
app.execute();
|
|
Preferences.recordLaunch(app.id);
|
|
done();
|
|
}
|
|
}
|
|
Rectangle {
|
|
anchors.fill: parent
|
|
radius: 26
|
|
color: Theme.surfaceLow
|
|
}
|
|
ColumnLayout {
|
|
anchors.fill: parent
|
|
anchors.margins: launcher.desktop ? 12 : 0
|
|
spacing: 10
|
|
TextField {
|
|
id: search
|
|
Layout.fillWidth: true
|
|
placeholderText: "Поиск в приложениях и интернете"
|
|
font.pixelSize: 15
|
|
leftPadding: 18
|
|
background: Rectangle { radius: 24; color: Theme.surfaceHigh; border.color: Theme.outline; border.width: 1 }
|
|
focus: true
|
|
onTextChanged: grid.currentIndex = 0
|
|
onAccepted: launcher.launch(launcher.apps[Math.max(0, grid.currentIndex)])
|
|
Keys.onDownPressed: grid.forceActiveFocus()
|
|
}
|
|
RowLayout {
|
|
Layout.fillWidth: true
|
|
visible: launcher.desktop
|
|
spacing: 6
|
|
Repeater {
|
|
model: launcher.categories
|
|
delegate: Rectangle {
|
|
id: chip
|
|
required property var modelData
|
|
implicitWidth: chipLabel.implicitWidth + 30
|
|
implicitHeight: 36
|
|
radius: 18
|
|
color: launcher.category === modelData.key ? Theme.secondaryContainer : Theme.surfaceHigh
|
|
border.width: launcher.category === modelData.key ? 1 : 0
|
|
border.color: Theme.primary
|
|
Text {
|
|
id: chipLabel
|
|
anchors.centerIn: parent
|
|
text: chip.modelData.label
|
|
color: Theme.foreground
|
|
font.pixelSize: 13
|
|
font.weight: launcher.category === chip.modelData.key ? Font.DemiBold : Font.Normal
|
|
}
|
|
MouseArea {
|
|
anchors.fill: parent
|
|
cursorShape: Qt.PointingHandCursor
|
|
onClicked: { launcher.category = chip.modelData.key; grid.currentIndex = 0; }
|
|
}
|
|
}
|
|
}
|
|
Item { Layout.fillWidth: true }
|
|
Text {
|
|
text: launcher.apps.length + " приложений"
|
|
color: Theme.outline
|
|
font.pixelSize: 12
|
|
}
|
|
}
|
|
GridView {
|
|
id: grid
|
|
Layout.fillWidth: true
|
|
Layout.fillHeight: true
|
|
clip: true
|
|
model: launcher.visible ? launcher.apps : []
|
|
cellWidth: width / Math.max(1, Math.floor(width / (launcher.desktop ? 82 : 140)))
|
|
cellHeight: launcher.desktop ? 90 : 120
|
|
keyNavigationEnabled: true
|
|
highlight: Rectangle { color: Theme.surface; radius: 16; border.color: Theme.primary }
|
|
Keys.onSpacePressed: if (launcher.apps[currentIndex]) Preferences.toggleFavorite(launcher.apps[currentIndex].id)
|
|
Keys.onReturnPressed: launcher.launch(launcher.apps[currentIndex])
|
|
delegate: Item {
|
|
id: tile
|
|
required property var modelData
|
|
required property int index
|
|
width: grid.cellWidth
|
|
height: grid.cellHeight
|
|
Rectangle {
|
|
anchors.fill: parent
|
|
anchors.margins: 4
|
|
radius: 18
|
|
color: tile.index === grid.currentIndex ? Theme.secondaryContainer : "transparent"
|
|
Behavior on color { ColorAnimation { duration: Theme.duration } }
|
|
}
|
|
Column {
|
|
anchors.centerIn: parent
|
|
spacing: 8
|
|
Image { anchors.horizontalCenter: parent.horizontalCenter; width: launcher.desktop ? 40 : 48; height: launcher.desktop ? 40 : 48; fillMode: Image.PreserveAspectFit; source: Quickshell.iconPath(tile.modelData.icon, "application-x-executable") }
|
|
Text { width: grid.cellWidth - 16; text: tile.modelData.name; font.pixelSize: launcher.desktop ? 11 : 14; color: Theme.foreground; horizontalAlignment: Text.AlignHCenter; elide: Text.ElideRight; textFormat: Text.PlainText }
|
|
}
|
|
MouseArea { anchors.fill: parent; cursorShape: Qt.PointingHandCursor; onClicked: { grid.currentIndex = tile.index; launcher.launch(tile.modelData); } }
|
|
ActionButton {
|
|
anchors { top: parent.top; right: parent.right }
|
|
text: (Preferences.data.favorites || []).includes(tile.modelData.id) ? "★" : "☆"
|
|
enabled: Preferences.writable
|
|
Accessible.name: "Избранное: " + tile.modelData.name
|
|
onClicked: Preferences.toggleFavorite(tile.modelData.id)
|
|
}
|
|
}
|
|
ScrollBar.vertical: ScrollBar {}
|
|
}
|
|
Label { visible: !launcher.desktop; text: "★ — избранное · Пробел — закрепить выбранное приложение"; Layout.fillWidth: true; wrapMode: Text.Wrap; color: Theme.outline }
|
|
Label { visible: launcher.apps.length === 0; text: "Приложения не найдены"; color: Theme.foreground }
|
|
}
|
|
}
|