shift-shell/containments/homescreens/halcyon/qml/FavoritesView.qml

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

210 lines
5.8 KiB
QML
Raw Normal View History

// SPDX-FileCopyrightText: 2022 Devin Lin <devin@kde.org>
// SPDX-License-Identifier: LGPL-2.0-or-later
import QtQuick 2.12
import QtQuick.Controls 2.15 as QQC2
import QtQuick.Layouts 1.1
import QtQml.Models 2.15
import org.kde.plasma.components 3.0 as PC3
import org.kde.draganddrop 2.0 as DragDrop
import org.kde.kirigami as Kirigami
import org.kde.plasma.private.mobileshell as MobileShell
import org.kde.plasma.private.mobileshell.shellsettingsplugin as ShellSettings
Item {
id: root
layer.enabled: true
property MobileShell.MaskManager maskManager
required property bool interactive
required property var searchWidget
2024-07-27 03:47:44 +00:00
readonly property real twoColumnThreshold: Kirigami.Units.gridUnit * 16
readonly property bool twoColumn: root.width / 2 > twoColumnThreshold
2024-07-27 03:47:44 +00:00
readonly property real cellWidth: twoColumn ? (root.width - leftMargin - rightMargin) / 2 : (root.width - leftMargin - rightMargin)
readonly property real cellHeight: delegateHeight
2024-07-27 03:47:44 +00:00
readonly property real leftMargin: Math.round(width * 0.1)
readonly property real rightMargin: Math.round(width * 0.1)
readonly property real delegateHeight: Math.round(Kirigami.Units.gridUnit * 3)
2024-07-27 03:47:44 +00:00
property bool folderShown: false
2024-07-27 03:47:44 +00:00
signal openConfigureRequested()
signal pageForwardRequested();
2024-07-27 03:47:44 +00:00
Connections {
target: parent
function onFocusRequested() {
favoritesGrid.forceActiveFocus();
}
}
function goToBeginning() {
goToBeginningAnim.restart();
}
2024-07-27 03:47:44 +00:00
function closeFolder() {
folderShown = false;
closeFolderAnim.restart()
}
2024-07-27 03:47:44 +00:00
function openFolder() {
folderShown = true;
openFolderAnim.restart()
}
function resetHighlight() {
favoritesGrid.currentIndex = -1;
}
2024-07-27 03:47:44 +00:00
FavoritesGrid {
id: favoritesGrid
2024-07-27 03:47:44 +00:00
property real openFolderProgress: 0
anchors.fill: parent
2024-07-27 03:47:44 +00:00
maskManager: root.maskManager
interactive: root.interactive
searchWidget: root.searchWidget
2024-07-27 03:47:44 +00:00
cellWidth: root.cellWidth
cellHeight: root.cellHeight
2024-07-27 03:47:44 +00:00
leftMargin: root.leftMargin
rightMargin: root.rightMargin
twoColumn: root.twoColumn
2024-07-27 03:47:44 +00:00
onOpenConfigureRequested: root.openConfigureRequested()
onRequestOpenFolder: (folder) => {
folderGrid.folder = folder;
root.openFolder();
}
2024-07-27 03:47:44 +00:00
property real translateX: openFolderProgress * -Kirigami.Units.gridUnit
transform: Translate { x: favoritesGrid.translateX }
opacity: 1 - openFolderProgress
visible: opacity !== 0
rightEdgeCallback: () => {
pageForwardRequested();
}
}
2024-07-27 03:47:44 +00:00
FolderGrid {
id: folderGrid
2024-07-27 03:47:44 +00:00
property real openProgress: 0
anchors.fill: parent
2024-07-27 03:47:44 +00:00
folder: null
2024-07-27 03:47:44 +00:00
interactive: root.interactive
2024-07-27 03:47:44 +00:00
cellWidth: root.cellWidth
cellHeight: root.cellHeight
2024-07-27 03:47:44 +00:00
leftMargin: root.leftMargin
rightMargin: root.rightMargin
twoColumn: root.twoColumn
2024-07-27 03:47:44 +00:00
onOpenConfigureRequested: root.openConfigureRequested()
onCloseRequested: root.closeFolder()
2024-07-27 03:47:44 +00:00
property real translateX: (1 - openProgress) * Kirigami.Units.gridUnit
transform: Translate { x: folderGrid.translateX }
opacity: openProgress
visible: opacity !== 0
}
2024-07-27 03:47:44 +00:00
// handle horizontal dragging in a folder
DragHandler {
id: dragHandler
target: folderGrid
enabled: folderGrid.visible
2024-07-27 03:47:44 +00:00
yAxis.enabled: false
xAxis.enabled: true
grabPermissions: PointerHandler.TakeOverForbidden
2024-07-27 03:47:44 +00:00
property real oldTranslationX
property bool isClosing: false
2024-07-27 03:47:44 +00:00
// when dragged
onTranslationChanged: {
let moveAmount = Math.max(0, translation.x) / (Kirigami.Units.gridUnit * 5);
folderGrid.openProgress = 1 - Math.min(1, Math.max(0, moveAmount));
isClosing = translation.x > oldTranslationX;
oldTranslationX = translation.x;
}
2024-07-27 03:47:44 +00:00
// when drag is let go
onActiveChanged: {
if (!active) {
isClosing ? closeFolder() : openFolder();
}
}
}
2024-07-27 03:47:44 +00:00
NumberAnimation {
id: goToBeginningAnim
target: favoritesGrid
properties: 'contentY'
to: favoritesGrid.originY
duration: Kirigami.Units.longDuration
easing.type: Easing.InOutQuad
}
2024-07-27 03:47:44 +00:00
SequentialAnimation {
id: openFolderAnim
2024-07-27 03:47:44 +00:00
ParallelAnimation {
NumberAnimation {
target: favoritesGrid
properties: 'openFolderProgress'
duration: ShellSettings.Settings.animationsEnabled ? Kirigami.Units.longDuration : 0
to: 1
easing.type: Easing.InOutQuad
}
}
2024-07-27 03:47:44 +00:00
ParallelAnimation {
NumberAnimation {
target: folderGrid
properties: 'openProgress'
duration: ShellSettings.Settings.animationsEnabled ? Kirigami.Units.longDuration : 0
to: 1
easing.type: Easing.InOutQuad
}
}
}
2024-07-27 03:47:44 +00:00
SequentialAnimation {
id: closeFolderAnim
2024-07-27 03:47:44 +00:00
ParallelAnimation {
NumberAnimation {
target: folderGrid
properties: 'openProgress'
duration: ShellSettings.Settings.animationsEnabled ? Kirigami.Units.longDuration : 0
to: 0
easing.type: Easing.InOutQuad
}
}
2024-07-27 03:47:44 +00:00
ParallelAnimation {
NumberAnimation {
target: favoritesGrid
properties: 'openFolderProgress'
duration: ShellSettings.Settings.animationsEnabled ? Kirigami.Units.longDuration : 0
to: 0
easing.type: Easing.InOutQuad
}
}
}
}