TodoEditor.qml 7.39 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: i18n("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
            Kirigami.Separator {
                Kirigami.FormData.isSection: true
            }

            Controls2.Label {
                id: calendarName

71
                Kirigami.FormData.label: i18n("Calendar:")
72 73 74 75
                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
                Layout.fillWidth: true
84
                Kirigami.FormData.label: i18n("Summary:")
85
                text: todoData ? todoData.summary : ""
86 87 88

            }

89
            RowLayout {
90
                Kirigami.FormData.label: i18n("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
                    onClicked: {
106 107 108 109
                        startTimePickerSheet.hours = startTimeSelector.startHour;
                        startTimePickerSheet.minutes = startTimeSelector.startMinutes;
                        startTimePickerSheet.pm = startTimeSelector.startPm;
                        startTimePickerSheet.open();
110 111 112 113 114 115
                    }

                    Connections {
                        target: startTimePickerSheet

                        onDatePicked: {
116 117 118
                            startTimeSelector.startHour = startTimePickerSheet.hours;
                            startTimeSelector.startMinutes = startTimePickerSheet.minutes;
                            startTimeSelector.startPm = startTimePickerSheet.pm;
119 120
                        }
                    }
121
                }
122
            }
123

124 125
            Controls2.CheckBox {
                id: allDaySelector
126 127

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

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

136 137
            Controls2.TextField {
                id: location
138

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

Dimitris Kardarakos's avatar
Dimitris Kardarakos committed
144
        }
145

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


151 152
        Controls2.TextArea {
            id: description
153

154
            enabled: !root.completed
155 156 157
            Layout.fillWidth: true
            Layout.minimumWidth: Kirigami.Units.gridUnit * 4
            Layout.minimumHeight: Kirigami.Units.gridUnit * 4
158 159
            Layout.maximumWidth: todoCard.width
            wrapMode: Text.WrapAnywhere
160
            text: todoData ? todoData.description : ""
161
            placeholderText: i18n("Description")
162
        }
163 164 165 166 167 168 169 170

        Kirigami.Separator {
            Layout.fillWidth: true
        }

        Controls2.CheckBox {
            id: completed

171
            text: i18n("Completed")
172 173
            checked: todoData ? todoData.completed: false
        }
174
    }
175

176
    actions {
177

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

181
            text: i18n("Cancel")
182
            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: i18n("Info")
194
            icon.name : "documentinfo"
195

196
            onTriggered: {
197
                showPassiveNotification(i18n("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: i18n("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
    TimePickerSheet {
        id: startTimePickerSheet
225
    }
226 227 228 229 230 231 232

    Component {
        id: todoController

        Calindori.TodoController {}
    }

233
}