Warning, /pim/kube/views/todo/qml/View.qml is written in an unsupported language. File is not indexed.
0001 /*
0002 * Copyright (C) 2017 Michael Bohlender, <michael.bohlender@kdemail.net>
0003 * Copyright (C) 2017 Christian Mollekopf, <mollekopf@kolabsys.com>
0004 *
0005 * This program is free software; you can redistribute it and/or modify
0006 * it under the terms of the GNU General Public License as published by
0007 * the Free Software Foundation; either version 2 of the License, or
0008 * (at your option) any later version.
0009 *
0010 * This program is distributed in the hope that it will be useful,
0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0013 * GNU General Public License for more details.
0014 *
0015 * You should have received a copy of the GNU General Public License along
0016 * with this program; if not, write to the Free Software Foundation, Inc.,
0017 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
0018 */
0019
0020
0021 import QtQuick 2.9
0022 import QtQuick.Controls 1.3 as Controls1
0023 import QtQuick.Controls 2
0024 import QtQuick.Layouts 1.1
0025
0026 import org.kube.framework 1.0 as Kube
0027
0028 Kube.View {
0029 id: root
0030 property string currentAccount: Kube.Context.currentAccountId
0031 property var currentFolder: null
0032 property var currentFolderIdentifier: null
0033
0034 //We have to hardcode because all the mapToItem/mapFromItem functions are garbage
0035 searchArea: Qt.rect(ApplicationWindow.window.sidebarWidth + todoView.parent.x, 0, todoView.parent.width + todoDetails.parent.width, height)
0036
0037 onRefresh: {
0038 if (!!root.currentFolder) {
0039 Kube.Fabric.postMessage(Kube.Messages.synchronize, {"folder": root.currentFolder});
0040 Kube.Fabric.postMessage(Kube.Messages.synchronize, {"accountId": root.currentAccount, "type": "folder"})
0041 } else {
0042 Kube.Fabric.postMessage(Kube.Messages.synchronize, {"accountId": root.currentAccount})
0043 }
0044 }
0045
0046 states: [
0047 State {
0048 name: "inbox"
0049 PropertyChanges {target: root; currentFolder: null}
0050 PropertyChanges {target: root; currentFolderIdentifier: null}
0051 StateChangeScript {script: accountSwitcher.clearSelection()}
0052 PropertyChanges {target: todoModel; filter: {
0053 "account": accountSwitcher.currentAccount,
0054 "calendars": accountSwitcher.enabledEntities,
0055 "inbox": true,
0056 "string": root.filter
0057 }}
0058 },
0059 State {
0060 name: "doing"
0061 PropertyChanges {target: root; currentFolder: null}
0062 PropertyChanges {target: root; currentFolderIdentifier: null}
0063 StateChangeScript {script: accountSwitcher.clearSelection()}
0064 PropertyChanges {target: todoModel; filter: {
0065 "account": accountSwitcher.currentAccount,
0066 "calendars": accountSwitcher.enabledEntities,
0067 "doing": true,
0068 "string": root.filter
0069 }}
0070 },
0071 State {
0072 name: "all"
0073 PropertyChanges {target: root; currentFolder: null}
0074 PropertyChanges {target: root; currentFolderIdentifier: null}
0075 StateChangeScript {script: accountSwitcher.clearSelection()}
0076 PropertyChanges {target: todoModel; filter: {
0077 "account": accountSwitcher.currentAccount,
0078 "calendars": accountSwitcher.enabledEntities,
0079 "string": root.filter
0080 }}
0081 },
0082 State {
0083 name: "calendar"
0084 PropertyChanges {target: root; currentFolder: accountSwitcher.currentEntity}
0085 PropertyChanges {target: root; currentFolderIdentifier: accountSwitcher.currentEntityIdentifier}
0086 PropertyChanges {target: todoModel; filter: {
0087 "account": accountSwitcher.currentAccount,
0088 "calendars": [accountSwitcher.currentEntityIdentifier],
0089 "string": root.filter
0090 }}
0091 }
0092 ]
0093 state: "doing"
0094
0095 Kube.Listener {
0096 filter: Kube.Messages.search
0097 onMessageReceived: root.triggerSearch()
0098 }
0099
0100 helpViewComponent: Kube.HelpPopup {
0101 ListModel {
0102 ListElement { description: qsTr("Go to top of list:"); shortcut: "t" }
0103 ListElement { description: qsTr("Go to bottom of list:"); shortcut: "b" }
0104 ListElement { description: qsTr("Go to next todo:"); shortcut: "j" }
0105 ListElement { description: qsTr("Go to previous todo:"); shortcut: "k" }
0106 ListElement { description: qsTr("Create new todo:"); shortcut: "c" }
0107 ListElement { description: qsTr("Edit todo:"); shortcut: "e" }
0108 ListElement { description: qsTr("Show this help text:"); shortcut: "?" }
0109 }
0110 }
0111 Shortcut {
0112 enabled: root.isCurrentView
0113 sequences: ['t']
0114 onActivated: todoView.currentIndex = 0
0115 }
0116 Shortcut {
0117 enabled: root.isCurrentView
0118 sequences: ['b']
0119 onActivated: todoView.currentIndex = todoView.count - 1
0120 }
0121 Shortcut {
0122 enabled: root.isCurrentView
0123 sequences: ['j']
0124 onActivated: todoView.incrementCurrentIndex()
0125 }
0126 Shortcut {
0127 enabled: root.isCurrentView
0128 sequences: ['k']
0129 onActivated: todoView.decrementCurrentIndex()
0130 }
0131 Shortcut {
0132 enabled: root.isCurrentView
0133 sequences: ['c']
0134 onActivated: editorPopup.createObject(root, {}).open()
0135 }
0136 Shortcut {
0137 enabled: root.isCurrentView
0138 sequences: ['e']
0139 onActivated: todoDetails.edit()
0140 }
0141 Shortcut {
0142 enabled: root.isCurrentView
0143 sequence: "?"
0144 onActivated: root.showHelp()
0145 }
0146
0147 Kube.Listener {
0148 filter: Kube.Messages.todoEditor
0149 onMessageReceived: editorPopup.createObject(root, message).open()
0150 }
0151
0152 ButtonGroup { id: viewButtonGroup }
0153
0154 Controls1.SplitView {
0155 Layout.fillWidth: true
0156 Layout.fillHeight: true
0157
0158 Kube.LeftSidebar {
0159 Layout.fillHeight: parent.height
0160 buttons: [
0161 Kube.PositiveButton {
0162 id: newMailButton
0163 objectName: "newMailButton"
0164
0165 Layout.fillWidth: true
0166 focus: true
0167 text: qsTr("New Todo")
0168 onClicked: editorPopup.createObject(root, {}).open()
0169 },
0170
0171 ColumnLayout {
0172 Kube.TextButton {
0173 id: inboxViewButton
0174 Layout.fillWidth: true
0175 text: qsTr("Inbox")
0176 textColor: Kube.Colors.highlightedTextColor
0177 checkable: true
0178 checked: root.state == "inbox"
0179 horizontalAlignment: Text.AlignHLeft
0180 ButtonGroup.group: viewButtonGroup
0181 onClicked: root.state = "inbox"
0182 }
0183 Kube.TextButton {
0184 id: doingViewButton
0185 Layout.fillWidth: true
0186 text: qsTr("Doing")
0187 textColor: Kube.Colors.highlightedTextColor
0188 checkable: true
0189 checked: root.state == "doing"
0190 horizontalAlignment: Text.AlignHLeft
0191 ButtonGroup.group: viewButtonGroup
0192 onClicked: root.state = "doing"
0193 }
0194 Kube.TextButton {
0195 id: allViewButton
0196 Layout.fillWidth: true
0197 text: qsTr("All")
0198 textColor: Kube.Colors.highlightedTextColor
0199 checkable: true
0200 checked: root.state == "all"
0201 horizontalAlignment: Text.AlignHLeft
0202 ButtonGroup.group: viewButtonGroup
0203 onClicked: root.state = "all"
0204 }
0205 }
0206 ]
0207
0208 Kube.CalendarSelector {
0209 id: accountSwitcher
0210 Layout.fillWidth: true
0211 Layout.fillHeight: true
0212 activeFocusOnTab: true
0213 selectionEnabled: true
0214 contentType: "todo"
0215 onCurrentEntityChanged: {
0216 if (currentEntity) {
0217 root.state = "calendar"
0218 }
0219 }
0220 }
0221 }
0222 Kube.ListView {
0223 id: todoView
0224 Layout.fillHeight: true
0225 Layout.minimumWidth: Kube.Units.gridUnit * 10
0226
0227 onCurrentItemChanged: {
0228 if (currentItem) {
0229 var currentData = currentItem.currentData;
0230 todoDetails.controller = controllerComponent.createObject(parent, {"todo": currentData.domainObject})
0231 }
0232 }
0233
0234 Keys.onPressed: {
0235 //Not implemented as a shortcut because we want it only to apply if we have the focus
0236 if (event.text == "d" || event.key == Qt.Key_Delete) {
0237 todoDetails.controller.remove()
0238 } else if (event.key == Qt.Key_Return) {
0239 todoDetails.controller.complete = !todoDetails.controller.complete;
0240 todoDetails.controller.saveAction.execute();
0241 } else if (event.key == Qt.Key_Home) {
0242 todoView.currentIndex = 0
0243 }
0244 }
0245
0246 Column {
0247 anchors.centerIn: parent
0248 visible: todoView.count === 0
0249 Kube.Label {
0250 text: qsTr("Nothing here yet...")
0251 }
0252 Kube.PositiveButton {
0253 visible: doingViewButton.checked
0254 text: qsTr("Pick some tasks")
0255 onClicked: {
0256 allViewButton.checked = true
0257 allViewButton.clicked()
0258 }
0259 }
0260 Kube.PositiveButton {
0261 visible: allViewButton.checked
0262 text: qsTr("Add a new task")
0263 onClicked: editorPopup.createObject(root, {}).open()
0264 }
0265 }
0266
0267 model: Kube.TodoModel {
0268 id: todoModel
0269 }
0270
0271 footerPositioning: ListView.OverlayFooter
0272 footer: Rectangle {
0273 property int taskLimit: 5
0274 visible: doingViewButton.checked && todoView.count > taskLimit
0275 color: Kube.Colors.warningColor
0276 height: Kube.Units.gridUnit * 2
0277 width: parent. width
0278 Label {
0279 anchors.centerIn: parent
0280 text: qsTr("This list is longer than %1 tasks. Focus on the top %1?").arg(taskLimit)
0281 }
0282 }
0283
0284 delegate: Kube.TodoListDelegate {
0285 summary: model.summary
0286 complete: model.complete
0287 doing: model.doing
0288 important: model.important
0289 calendar: model.calendar
0290 date: model.date
0291 dueDate: model.dueDate
0292 domainObject: model.domainObject
0293 dotColor: model.color
0294 bold: model.doing && root.state != "doing"
0295
0296 currentDate: Kube.Context.currentDate
0297 }
0298 }
0299 Rectangle {
0300 Layout.fillHeight: parent.height
0301 Layout.fillWidth: true
0302
0303 color: Kube.Colors.paperWhite
0304
0305 TodoEditor {
0306 id: todoDetails
0307 anchors.fill: parent
0308 editMode: true
0309 // onDone: popup.close()
0310 }
0311 }
0312 Component {
0313 id: controllerComponent
0314 Kube.TodoController {
0315 }
0316 }
0317
0318 }
0319
0320 Component {
0321 id: editorPopup
0322 Kube.Popup {
0323 id: popup
0324
0325 property alias parentUid: editor.parentUid
0326
0327 x: root.width * 0.15
0328 y: root.height * 0.15
0329
0330 width: root.width * 0.7
0331 height: root.height * 0.7
0332 padding: 0
0333 closePolicy: Popup.NoAutoClose
0334 Rectangle {
0335 anchors.fill: parent
0336 color: Kube.Colors.paperWhite
0337 TodoEditor {
0338 id: editor
0339 focus: true
0340 anchors.fill: parent
0341 accountId: root.currentAccount
0342 currentFolder: root.currentFolderIdentifier
0343 doing: doingViewButton.checked
0344 onDone: popup.close()
0345 }
0346 }
0347 }
0348 }
0349
0350 }