Files
dotfiles/quickshell/Home.qml
T
2026-11-17 18:15:16 +07:00

110 lines
4.7 KiB
QML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
pragma ComponentBehavior: Bound
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import Quickshell
import "services"
import "services/Policy.js" as Policy
Item {
id: home
signal launchRequested()
signal openLauncher()
property int pageIndex: 0
property bool editing: false
readonly property int pageSize: width < 600 ? 12 : 24
readonly property var installed: DesktopEntries.applications.values.filter(app => !app.noDisplay)
readonly property var favoriteIds: Preferences.data.favorites || []
readonly property var pages: Policy.homePages(favoriteIds, pageSize)
readonly property var currentIds: pages[Math.min(pageIndex, pages.length - 1)] || []
readonly property var currentApps: currentIds.map(id => installed.find(app => app.id === id)).filter(app => app !== undefined)
onPagesChanged: if (pageIndex >= pages.length) pageIndex = Math.max(0, pages.length - 1)
ColumnLayout {
anchors.fill: parent
anchors.margins: 16
spacing: 14
Item { Layout.fillHeight: true }
Label {
Layout.fillWidth: true
horizontalAlignment: Text.AlignHCenter
text: "Главный экран"
font.pixelSize: 28
font.weight: Font.DemiBold
color: Theme.foreground
}
GridView {
id: grid
Layout.fillWidth: true
Layout.preferredHeight: Math.min(540, Math.max(120, Math.ceil(home.currentApps.length / Math.max(1, Math.floor(width / 94))) * 112))
clip: true
model: home.currentApps
cellWidth: width / Math.max(1, Math.floor(width / 94))
cellHeight: 112
delegate: Item {
id: tile
required property var modelData
width: grid.cellWidth
height: grid.cellHeight
Column {
anchors.centerIn: parent
spacing: 7
Image {
anchors.horizontalCenter: parent.horizontalCenter
width: 52; height: 52
source: Quickshell.iconPath(tile.modelData.icon, "application-x-executable")
fillMode: Image.PreserveAspectFit
}
Label {
width: grid.cellWidth - 8
horizontalAlignment: Text.AlignHCenter
elide: Text.ElideRight
text: tile.modelData.name
color: Theme.foreground
}
}
MouseArea {
anchors.fill: parent
onPressAndHold: home.editing = true
onClicked: {
if (home.editing) return;
tile.modelData.execute();
Preferences.recordLaunch(tile.modelData.id);
home.launchRequested();
}
}
Row {
visible: home.editing
anchors.top: parent.top
anchors.horizontalCenter: parent.horizontalCenter
spacing: 2
Button { text: "←"; enabled: Preferences.writable; onClicked: Preferences.moveFavorite(tile.modelData.id, -1) }
Button { text: "×"; enabled: Preferences.writable; onClicked: Preferences.toggleFavorite(tile.modelData.id) }
Button { text: "→"; enabled: Preferences.writable; onClicked: Preferences.moveFavorite(tile.modelData.id, 1) }
}
}
}
RowLayout {
Layout.alignment: Qt.AlignHCenter
Button { text: "‹"; enabled: home.pageIndex > 0; onClicked: home.pageIndex-- }
Label { text: (home.pageIndex + 1) + " / " + home.pages.length; color: Theme.foreground }
Button { text: "›"; enabled: home.pageIndex + 1 < home.pages.length; onClicked: home.pageIndex++ }
}
RowLayout {
Layout.alignment: Qt.AlignHCenter
Button { text: "Все приложения"; onClicked: home.openLauncher() }
Button {
text: home.editing ? "Готово" : "Изменить"
onClicked: home.editing = !home.editing
}
}
Label {
visible: home.favoriteIds.length === 0
Layout.alignment: Qt.AlignHCenter
text: "Закрепите приложения через ☆ в списке приложений"
color: Theme.outline
wrapMode: Text.Wrap
}
Item { Layout.fillHeight: true }
}
}