TodoEditor.qml 7.89 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24

/*
 *   Copyright 2018 Dimitris Kardarakos <dimkard@gmail.com>
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU Library General Public License as
 *   published by the Free Software Foundation; either version 2 or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU Library General Public License for more details
 *
 *   You should have received a copy of the GNU Library General Public
 *   License along with this program; if not, write to the
 *   Free Software Foundation, Inc.,
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

import QtQuick 2.0
import QtQuick.Controls 2.4 as Controls2
import QtQuick.Layouts 1.11
import org.kde.kirigami 2.4 as Kirigami
25
import org.kde.phone.calindori 0.1 as Calindori
26 27 28

Kirigami.Page {
    id: root
29

30 31 32 33 34 35
    property date startdt
    property string uid
    property alias summary: summary.text
    property alias description: description.text
    property alias startHour: startTimeSelector.startHour
    property alias startMinute: startTimeSelector.startMinutes
36
    property alias startPm: startTimeSelector.startPm
37 38
    property alias allDay: allDaySelector.checked
    property alias location: location.text
39
    property alias completed: completed.checked
40 41
    property var calendar
    property var todoData
42

43
    signal taskeditcompleted
44

45
    title: qsTr("Task")
46

47
    ColumnLayout {
48

49
        anchors.centerIn: parent
50

51
        Controls2.Label {
52
            visible: root.startdt != undefined && !isNaN(root.startdt)
53 54 55
            Layout.fillWidth: true
            horizontalAlignment: Text.AlignHCenter
            font.pointSize: Kirigami.Units.fontMetrics.font.pointSize * 1.2
56
            text: todoData && !isNaN(todoData.dtstart) ? todoData.dtstart.toLocaleDateString(Qt.locale()) : (!isNaN(root.startdt) ? root.startdt.toLocaleDateString(Qt.locale()) : "")
57 58
        }

59
        Kirigami.FormLayout {
60
            id: todoCard
61

62
            enabled: !root.completed
63

64 65 66 67 68 69 70 71 72 73 74 75
            Kirigami.Separator {
                Kirigami.FormData.isSection: true
            }

            Controls2.Label {
                id: calendarName

                Kirigami.FormData.label: qsTr("Calendar:")
                Layout.fillWidth: true
                text: root.calendar.name
            }

76 77 78
            Kirigami.Separator {
                Kirigami.FormData.isSection: true
            }
79

80 81
            Controls2.TextField {
                id: summary
82

83 84 85
                Layout.fillWidth: true
                Kirigami.FormData.label: qsTr("Summary:")
                text: todoData ? todoData.summary : ""
86 87 88

            }

89 90
            RowLayout {
                Kirigami.FormData.label: qsTr("Start time:")
91 92
                enabled: root.startdt != undefined && !isNaN(root.startdt)

93 94
                Controls2.ToolButton {
                    id: startTimeSelector
95

96 97 98
                    property int startHour : root.todoData ? root.todoData.dtstart.toLocaleTimeString(Qt.locale(), "hh") % 12 : 0
                    property int startMinutes: root.todoData ? root.todoData.dtstart.toLocaleTimeString(Qt.locale(), "mm") : 0
                    property bool startPm: (root.todoData && root.todoData.dtstart.toLocaleTimeString(Qt.locale("en_US"), "AP")  == "PM") ? true : false
99 100
                    property date startTime: root.startdt

101
                    text: !isNaN(root.startdt) ? (new Date(root.startdt.getFullYear(), root.startdt.getMonth() , root.startdt.getDate(), startHour + (startPm ? 12 : 0), startMinutes)).toLocaleTimeString(Qt.locale(), "hh:mm AP"): "00:00"
102

103
                    enabled: !allDaySelector.checked
104

105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
                    onClicked: {
                        startTimePickerSheet.hours = startTimeSelector.startHour
                        startTimePickerSheet.minutes = startTimeSelector.startMinutes
                        startTimePickerSheet.pm = startTimeSelector.startPm

                        startTimePickerSheet.open()
                    }

                    Connections {
                        target: startTimePickerSheet

                        onDatePicked: {
                            startTimeSelector.startHour = startTimePickerSheet.hours
                            startTimeSelector.startMinutes = startTimePickerSheet.minutes
                            startTimeSelector.startPm = startTimePickerSheet.pm
                        }
                    }
122
                }
123
            }
124

125 126
            Controls2.CheckBox {
                id: allDaySelector
127 128

                enabled: !isNaN(root.startdt)
129 130 131
                checked: todoData ? todoData.allday: false
                text: qsTr("All day")
            }
132

133 134
            Kirigami.Separator {
                Kirigami.FormData.isSection: true
135 136
            }

137 138
            Controls2.TextField {
                id: location
139

140 141 142
                Layout.fillWidth: true
                Kirigami.FormData.label: qsTr("Location:")
                text: todoData ? todoData.location : ""
143
            }
144

Dimitris Kardarakos's avatar
Dimitris Kardarakos committed
145
        }
146

Dimitris Kardarakos's avatar
Dimitris Kardarakos committed
147
        Kirigami.Separator {
148
            Layout.fillWidth: true
149 150 151
        }


152 153
        Controls2.TextArea {
            id: description
154

155
            enabled: !root.completed
156 157 158
            Layout.fillWidth: true
            Layout.minimumWidth: Kirigami.Units.gridUnit * 4
            Layout.minimumHeight: Kirigami.Units.gridUnit * 4
159
            wrapMode: Controls2.TextArea.WordWrap
160
            text: todoData ? todoData.description : ""
161 162
            placeholderText:  qsTr("Description")
        }
163 164 165 166 167 168 169 170 171 172 173

        Kirigami.Separator {
            Layout.fillWidth: true
        }

        Controls2.CheckBox {
            id: completed

            text: qsTr("Completed")
            checked: todoData ? todoData.completed: false
        }
174
    }
175

176
    actions {
177

178 179
        left: Kirigami.Action {
            id: cancelAction
180

181 182
            text: qsTr("Cancel")
            icon.name : "dialog-cancel"
183

184 185 186
            onTriggered: {
                taskeditcompleted();
            }
Dimitris Kardarakos's avatar
Dimitris Kardarakos committed
187
        }
188 189


190 191
        main: Kirigami.Action {
            id: info
192

193
            text: qsTr("Info")
194
            icon.name : "documentinfo"
195

196 197
            onTriggered: {
                showPassiveNotification("Please save or cancel this task");
Dimitris Kardarakos's avatar
Dimitris Kardarakos committed
198
            }
199
        }
200

201 202
        right: Kirigami.Action {
            id: saveAction
203 204

            text: qsTr("Save")
205
            icon.name : "dialog-ok"
206

207 208 209
            onTriggered: {
                if(summary.text) {
                    console.log("Saving task");
210 211 212
                    var controller = todoController.createObject(parent, { calendar: root.calendar });
                    controller.vtodo = { "uid": root.uid, "summary":root.summary, "startDate": root.startdt , "startHour": root.startHour + (root.startPm ? 12 : 0), "startMinute": root.startMinute, "allDay": root.allDay, "description":  root.description,"location":  root.location, "completed": root.completed};
                    controller.addEdit();
Dimitris Kardarakos's avatar
Dimitris Kardarakos committed
213
                    taskeditcompleted();
214
                }
215 216
                else {
                    showPassiveNotification("Summary should not be empty");
217
                }
218
            }
219
        }
220

221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
        //TODO
//         contextualActions: [
//             Kirigami.Action {
//                 iconName:"editor"
//                 text: "Edit Start Date"
//
//                 onTriggered: showPassiveNotification("Edit start date")
//
//             }
//             ,
//             Kirigami.Action { //TODO: Do we needed it?
//                 iconName:"delete"
//                 text: "Clear Start Date"
//
//                 onTriggered: {
//                     root.startdt = new Date("No Date");
//                 }
//             }
//         ]
240
    }
241

242 243
    TimePickerSheet {
        id: startTimePickerSheet
244
    }
245 246 247 248 249 250 251

    Component {
        id: todoController

        Calindori.TodoController {}
    }

252
}