Warning, /office/klevernotes/src/contents/ui/todoEditor/ToDoView.qml is written in an unsupported language. File is not indexed.
0001 // SPDX-License-Identifier: GPL-2.0-or-later 0002 // SPDX-FileCopyrightText: 2023 Louis Schul <schul9louis@gmail.com> 0003 0004 import QtQuick 2.15 0005 import QtQuick.Layouts 1.15 0006 import QtQuick.Controls 2.15 as Controls 0007 0008 import org.kde.kirigami 2.19 as Kirigami 0009 import org.kde.kirigamiaddons.formcard 1.0 as FormCard 0010 0011 import org.kde.Klever 1.0 0012 0013 import "qrc:/contents/ui/dialogs/todoDialog" 0014 0015 ColumnLayout { 0016 id: root 0017 0018 property list<Kirigami.Action> actions: [ 0019 Kirigami.Action { 0020 id: clearTodosAction 0021 0022 icon.name: "edit-clear-history" 0023 text: i18nc("@label:button, checked as in 'the todos that are checked'", "Clear checked") 0024 0025 onTriggered: clearCheckedTodos() 0026 } 0027 ] 0028 property string path 0029 property int alreadySavedCount: 0 0030 0031 onPathChanged: { 0032 todoModel.clear() 0033 setTodos() 0034 } 0035 0036 ToDoDialog { 0037 id: todoDialog 0038 0039 onAccepted: { 0040 if (name.length > 0) { 0041 if (callerModelIndex < 0) { 0042 todoModel.append({ 0043 "todoTitle": name, 0044 "todoDesc": description.trim(), 0045 "todoChecked": false 0046 }) 0047 } else { 0048 todoModel.setProperty(callerModelIndex, "todoTitle", name) 0049 todoModel.setProperty(callerModelIndex, "todoDesc", description) 0050 } 0051 } 0052 saveTodos() 0053 name = "" 0054 description = "" 0055 callerModelIndex = -1 0056 } 0057 } 0058 0059 Kirigami.Card { 0060 Layout.fillWidth: true 0061 Layout.fillHeight: true 0062 0063 Kirigami.CardsListView { 0064 id: cardsView 0065 0066 anchors.fill: parent 0067 0068 model: todoModel 0069 delegate: TodoDelegate {} 0070 } 0071 0072 ListModel { 0073 id: todoModel 0074 } 0075 } 0076 0077 FormCard.AbstractFormDelegate { 0078 Layout.fillWidth: true 0079 0080 contentItem: RowLayout { 0081 spacing: 0 0082 0083 Kirigami.Icon { 0084 width: Kirigami.Units.iconSizes.medium 0085 height: Kirigami.Units.iconSizes.medium 0086 0087 source: "list-add-symbolic" 0088 0089 Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter 0090 } 0091 } 0092 0093 onClicked: { 0094 todoDialog.open() 0095 } 0096 } 0097 0098 function clearCheckedTodos() { 0099 for (var idx = todoModel.count-1 ; idx >= 0 ; idx--){ 0100 const model = todoModel.get(idx) 0101 if (model.todoChecked) { 0102 todoModel.remove(idx,1) 0103 } 0104 } 0105 saveTodos() 0106 } 0107 0108 function setTodos() { 0109 const todos = DocumentHandler.getJson(root.path).todos 0110 if (!todos) return 0111 root.alreadySavedCount = todos.length 0112 0113 todos.forEach(todo => todoModel.append(todo)) 0114 } 0115 0116 function saveTodos() { 0117 let json = {"todos":[]} 0118 0119 for (var idx = 0 ; idx < todoModel.count ; idx++){ 0120 const model = todoModel.get(idx) 0121 json.todos.push(model) 0122 } 0123 DocumentHandler.saveJson(json, root.path) 0124 } 0125 }