shift-shell/containments/homescreens/halcyon/package/contents/ui/FolderGrid.qml

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

232 lines
7 KiB
QML
Raw Normal View History

// SPDX-FileCopyrightText: 2022 Devin Lin <devin@kde.org>
// SPDX-License-Identifier: LGPL-2.0-or-later
2023-03-05 02:40:06 +00:00
import QtQuick
import QtQuick.Controls as QQC2
import QtQuick.Layouts
import QtQuick.Effects
2023-03-05 02:40:06 +00:00
import QtQml.Models
import org.kde.plasma.components 3.0 as PC3
2023-03-05 02:40:06 +00:00
import org.kde.draganddrop as DragDrop
2023-03-05 02:40:06 +00:00
import org.kde.kirigami as Kirigami
import org.kde.plasma.private.mobileshell as MobileShell
import org.kde.private.mobile.homescreen.halcyon as Halcyon
MobileShell.GridView {
id: root
property Halcyon.ApplicationFolder folder: null
2024-07-27 03:47:44 +00:00
property string folderName: folder ? folder.name : ""
property var folderModel: folder ? folder.applications : []
2024-07-27 03:47:44 +00:00
required property bool twoColumn
2024-07-27 03:47:44 +00:00
signal openConfigureRequested()
signal closeRequested()
2024-07-27 03:47:44 +00:00
property bool inFolderTitleEditMode: false
2024-07-27 03:47:44 +00:00
TapHandler {
onLongPressed: root.openConfigureRequested()
onTapped: root.closeRequested()
}
2024-07-27 03:47:44 +00:00
header: MobileShell.BaseItem {
topPadding: Math.round(root.height * 0.2)
bottomPadding: Kirigami.Units.gridUnit
leftPadding: 0
rightPadding: 0
implicitWidth: root.width
background: Rectangle {
color: 'transparent'
2024-07-27 03:47:44 +00:00
TapHandler {
onLongPressed: root.openConfigureRequested()
onTapped: root.closeRequested()
}
}
2024-07-27 03:47:44 +00:00
Component {
id: folderTitleEdit
2024-07-27 03:47:44 +00:00
TextEdit {
text: root.folderName
color: "white"
selectByMouse: true
wrapMode: TextEdit.Wrap
2024-07-27 03:47:44 +00:00
Component.onCompleted: forceActiveFocus()
2024-07-27 03:47:44 +00:00
font.weight: Font.Bold
font.pointSize: 18
layer.enabled: true
layer.effect: MobileShell.TextDropShadow {}
2024-07-27 03:47:44 +00:00
onTextChanged: {
if (text.includes('\n')) {
// exit text edit mode when new line is entered
root.inFolderTitleEditMode = false;
} else {
root.folder.name = text;
}
}
onEditingFinished: root.inFolderTitleEditMode = false
}
}
2024-07-27 03:47:44 +00:00
Component {
id: folderTitleLabel
2024-07-27 03:47:44 +00:00
QQC2.Label {
text: root.folderName
color: "white"
style: Text.Normal
styleColor: "transparent"
horizontalAlignment: Text.AlignLeft
textFormat: Text.MarkdownText
2024-07-27 03:47:44 +00:00
elide: Text.ElideRight
wrapMode: Text.Wrap
maximumLineCount: 2
font.weight: Font.Bold
font.pointSize: 18
layer.enabled: true
layer.effect: MobileShell.TextDropShadow {}
2024-07-27 03:47:44 +00:00
MouseArea {
anchors.fill: parent
onClicked: root.inFolderTitleEditMode = true
}
}
}
2024-07-27 03:47:44 +00:00
contentItem: RowLayout {
id: rowLayout
spacing: Kirigami.Units.smallSpacing * 2
2024-07-27 03:47:44 +00:00
// close folder button
MouseArea {
id: button
Layout.alignment: Qt.AlignVCenter
implicitHeight: Kirigami.Units.iconSizes.small + Kirigami.Units.gridUnit
implicitWidth: Kirigami.Units.iconSizes.small + Kirigami.Units.gridUnit
2024-07-27 03:47:44 +00:00
cursorShape: Qt.PointingHandCursor
onClicked: root.closeRequested()
2024-07-27 03:47:44 +00:00
// button background
Rectangle {
anchors.fill: parent
color: Qt.rgba(255, 255, 255, button.pressed ? 0.2 : 0)
radius: button.width / 2
}
2024-07-27 03:47:44 +00:00
// button icon
Kirigami.Icon {
anchors.centerIn: parent
implicitHeight: Kirigami.Units.iconSizes.small
implicitWidth: Kirigami.Units.iconSizes.small
isMask: true
color: 'white'
source: 'arrow-left'
layer.enabled: true
layer.effect: MultiEffect {
shadowEnabled: true
shadowVerticalOffset: 1
blurMax: 8
shadowOpacity: 0.6
}
}
}
2024-07-27 03:47:44 +00:00
// folder title
Loader {
Layout.alignment: Qt.AlignVCenter
Layout.fillWidth: true
Layout.maximumWidth: rowLayout.width - button.width - rowLayout.spacing
sourceComponent: root.inFolderTitleEditMode ? folderTitleEdit : folderTitleLabel
}
}
}
2024-07-27 03:47:44 +00:00
model: DelegateModel {
id: visualModel
model: root.folderModel
2024-07-27 03:47:44 +00:00
delegate: Item {
id: delegateRoot
width: root.cellWidth
height: root.cellHeight
2024-07-27 03:47:44 +00:00
property int visualIndex: DelegateModel.itemsIndex
2024-07-27 03:47:44 +00:00
DropArea {
anchors.fill: parent
onEntered: (drag) => {
let from = drag.source.visualIndex;
let to = appDelegate.visualIndex;
visualModel.items.move(from, to);
root.folder.moveEntry(from, to);
}
}
2024-07-27 03:47:44 +00:00
FavoritesAppDelegate {
id: appDelegate
visualIndex: delegateRoot.visualIndex
2024-07-27 03:47:44 +00:00
isFolder: false
application: model.application
2024-07-27 03:47:44 +00:00
menuActions: [
Kirigami.Action {
icon.name: "emblem-favorite"
text: i18n("Remove from favourites")
onTriggered: root.folder.removeApp(model.index)
},
Kirigami.Action {
icon.name: "document-open-folder"
text: i18n("Move out of folder")
onTriggered: root.folder.moveAppOut(model.index)
}
]
2024-07-27 03:47:44 +00:00
implicitWidth: root.cellWidth
implicitHeight: visible ? root.cellHeight : 0
2024-07-27 03:47:44 +00:00
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
2024-07-27 03:47:44 +00:00
states: [
State {
when: appDelegate.drag.active
ParentChange {
target: appDelegate
parent: root
}
2024-07-27 03:47:44 +00:00
AnchorChanges {
target: appDelegate
anchors.horizontalCenter: undefined
anchors.verticalCenter: undefined
}
}
]
}
}
}
2024-07-27 03:47:44 +00:00
// animations
displaced: Transition {
NumberAnimation {
properties: "x,y"
easing.type: Easing.OutQuad
}
}
}