Warning, /utilities/toad/src/ui/main.qml is written in an unsupported language. File is not indexed.

0001 // SPDX-FileCopyrightText: 2022 Felipe Kinoshita <kinofhek@gmail.com>
0002 // SPDX-License-Identifier: GPL-3.0-or-later
0003 
0004 import QtQuick
0005 import QtQuick.Controls as QQC2
0006 import QtQuick.Layouts
0007 import org.kde.kirigami as Kirigami
0008 import org.kde.kirigamiaddons.delegates as Delegates
0009 import org.kde.kitemmodels
0010 
0011 import org.kde.tasks 1.0
0012 
0013 Kirigami.ApplicationWindow {
0014     id: root
0015 
0016     title: i18n("Tasks")
0017 
0018     required property TasksModel tasksModel
0019 
0020     width: Kirigami.Units.gridUnit * 26
0021     height: Kirigami.Units.gridUnit * 36
0022     minimumWidth: Kirigami.Units.gridUnit * 20
0023     minimumHeight: Kirigami.Units.gridUnit * 20
0024 
0025     Timer {
0026         id: saveWindowGeometryTimer
0027         interval: 1000
0028         onTriggered: Controller.saveWindowGeometry(root)
0029     }
0030 
0031     Connections {
0032         id: saveWindowGeometryConnections
0033         enabled: false // Disable on startup to avoid writing wrong values if the window is hidden
0034         target: root
0035 
0036         function onClosing() { Controller.saveWindowGeometry(root); }
0037         function onWidthChanged() { saveWindowGeometryTimer.restart(); }
0038         function onHeightChanged() { saveWindowGeometryTimer.restart(); }
0039         function onXChanged() { saveWindowGeometryTimer.restart(); }
0040         function onYChanged() { saveWindowGeometryTimer.restart(); }
0041     }
0042 
0043     Loader {
0044         active: !Kirigami.Settings.isMobile
0045         sourceComponent: GlobalMenu {
0046             tasksModel: root.tasksModel
0047         }
0048     }
0049 
0050     pageStack.initialPage: Kirigami.ScrollablePage {
0051         id: page
0052 
0053         property bool searching
0054         property string currentSearchText
0055 
0056         titleDelegate: PageHeader {
0057             tasksModel: root.tasksModel
0058         }
0059 
0060         ListView {
0061             id: list
0062 
0063             model: KSortFilterProxyModel {
0064                 id: filteredModel
0065                 sourceModel: root.tasksModel
0066                 filterRoleName: "title"
0067                 filterRegularExpression: {
0068                     if (page.currentSearchText === "") return new RegExp()
0069                     return new RegExp("%1".arg(page.currentSearchText.slice(1)), "i")
0070                 }
0071             }
0072 
0073             delegate: Delegates.RoundedItemDelegate {
0074                 id: taskItem
0075 
0076                 contentItem: RowLayout {
0077                     QQC2.CheckBox {
0078                         enabled: !titleField.visible
0079                         checked: model.checked
0080                         onToggled: model.checked = !model.checked
0081                     }
0082 
0083                     QQC2.Label {
0084                         id: titleLabel
0085                         Layout.fillWidth: true
0086                         Layout.preferredHeight: titleField.implicitHeight
0087                         Layout.alignment: Qt.AlignLeft | Qt.AlignVCenter
0088 
0089                         text: model.title
0090                         elide: Text.ElideRight
0091 
0092                         Behavior on opacity {
0093                             OpacityAnimator {
0094                                 duration: Kirigami.Units.longDuration
0095                                 easing.type: Easing.OutQuad
0096                             }
0097                         }
0098 
0099                         font.strikeout: model.checked
0100                         opacity: model.checked ? 0.5 : 1
0101                     }
0102 
0103                     QQC2.TextField {
0104                         id: titleField
0105                         visible: false
0106                         Layout.fillWidth: true
0107                         Layout.alignment: Qt.AlignLeft | Qt.AlignVCenter
0108 
0109                         text: model.title
0110 
0111                         horizontalAlignment: Text.AlignLeft
0112                         readOnly: model.checked
0113 
0114                         onEditingFinished: {
0115                             model.title = text
0116                             titleField.visible = false
0117                             titleLabel.visible = true
0118                         }
0119                     }
0120 
0121                     QQC2.ToolButton {
0122                         id: editButton
0123                         visible: !model.checked && !titleField.visible
0124 
0125                         Layout.preferredHeight: Math.round(Kirigami.Units.gridUnit * 1.5)
0126 
0127                         icon.name: "entry-edit"
0128                         opacity: taskItem.hovered ? 1 : 0
0129 
0130                         onClicked: {
0131                             titleField.visible = true
0132                             titleLabel.visible = false
0133                             titleField.forceActiveFocus()
0134                             titleField.selectAll()
0135                         }
0136                     }
0137                     QQC2.ToolButton {
0138                         id: removeButton
0139                         visible: !titleField.visible
0140 
0141                         Layout.preferredHeight: Math.round(Kirigami.Units.gridUnit * 1.5)
0142 
0143                         icon.name: "entry-delete"
0144                         opacity: taskItem.hovered ? 1 : 0
0145                         onClicked: {
0146                             const originalIndex = filteredModel.index(index, 0)
0147                             root.tasksModel.remove(filteredModel.mapToSource(originalIndex))
0148                         }
0149                     }
0150                 }
0151 
0152                 QQC2.ToolTip.visible: !titleField.visible && titleLabel.truncated && taskItem.hovered
0153                 QQC2.ToolTip.text: model.title
0154                 QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
0155             }
0156 
0157             add: Transition {
0158                 OpacityAnimator {
0159                     from: 0
0160                     to: 1
0161                     duration: Kirigami.Units.longDuration
0162                     easing.type: Easing.OutQuad
0163                 }
0164             }
0165             remove: Transition {
0166                 OpacityAnimator {
0167                     from: 1
0168                     to: 0
0169                     duration: Kirigami.Units.longDuration
0170                     easing.type: Easing.OutQuad
0171                 }
0172             }
0173 
0174             Kirigami.PlaceholderMessage {
0175                 visible: list.count <= 0
0176                 anchors.centerIn: parent
0177                 width: parent.width - (Kirigami.Units.gridUnit * 8)
0178                 text: page.searching ? i18n("Nothing Found") : i18n("All tasks completed!")
0179                 icon.name: page.searching ? "edit-none" : "checkmark"
0180                 explanation: page.searching ? i18n("Your search did not match any results") : i18n("Add some more by typing in the text field at the bottom of the window")
0181             }
0182         }
0183 
0184         footer: Footer {
0185             focus: !Kirigami.InputMethod.willShowOnActive
0186             tasksModel: root.tasksModel
0187         }
0188     }
0189 
0190     Component.onCompleted: {
0191         if (!Kirigami.Settings.isMobile) {
0192             saveWindowGeometryConnections.enabled = true
0193         }
0194     }
0195 }