~thomir-deactivatedaccount/ubuntu-calendar-app/trunk-fix-ugly-bits

« back to all changes in this revision

Viewing changes to NewEvent.qml

  • Committer: Riccardo Padovani
  • Date: 2013-07-11 13:17:04 UTC
  • mto: This revision was merged to the branch mainline in revision 68.
  • Revision ID: rpadovani@ubuntu-it.org-20130711131704-2uiia3n3yr9p4hpu
Implemented DatePicker. Thanks to Michael Zanetti

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
Popover {
9
9
    id: popover
10
10
    property var defaultDate;
11
 
    property string errorText;
 
11
    property alias errorText: errorPopupDialog.text;
 
12
    property var startDate: defaultDate;
 
13
    property var endDate: defaultDate;
12
14
 
13
15
    Column {
14
16
        id: containerLayout
59
61
                        }
60
62
                    }
61
63
                }
 
64
                Component {
 
65
                    id: timePicker
 
66
                    TimePicker {
 
67
                    }
 
68
                }
62
69
 
63
70
                Item {
64
71
                    id: timeContainer
65
72
                    width: parent.width
66
73
                    height: startTime.height
67
74
 
 
75
                    /*ListItem.Empty {
 
76
                        id: startTime
 
77
                        highlightWhenPressed: false
 
78
                        anchors.left: timeContainer.left
 
79
                        width: units.gu(12)
 
80
                        TextField {
 
81
                            objectName: "startTimeInput"
 
82
                            id: startTimeEdit
 
83
                            text: Qt.formatDateTime(defaultDate,"hh:mm")
 
84
                            anchors {
 
85
                                fill: parent
 
86
                                margins: units.gu(1)
 
87
                            }
 
88
                        }
 
89
                    }*/
 
90
 
68
91
                    ListItem.Empty {
69
92
                        id: startTime
70
 
                        highlightWhenPressed: false
71
93
                        anchors.left: timeContainer.left
72
94
                        width: units.gu(12)
73
 
                        TextField {
 
95
                        Button {
74
96
                            objectName: "startTimeInput"
75
97
                            id: startTimeEdit
76
 
                            text: Qt.formatDateTime(defaultDate,"hh:mm")
 
98
                            text: Qt.formatDateTime(startDate,"hh:mm")
77
99
                            anchors {
78
100
                                fill: parent
79
101
                                margins: units.gu(1)
80
102
                            }
 
103
                            onClicked: {
 
104
                                var popupObj = PopupUtils.open(timePicker);
 
105
                                popupObj.accepted.connect(function(hour, minute) {
 
106
                                    var newDate = startDate;
 
107
                                    newDate.setHours(hour, minute);
 
108
                                    startDate = newDate;
 
109
                                })
 
110
                            }
81
111
                        }
82
112
                    }
83
113
 
95
125
                        highlightWhenPressed: false
96
126
                        anchors.right: timeContainer.right
97
127
                        width: units.gu(12)
98
 
                        TextField {
 
128
                        Button {
99
129
                            objectName: "endTimeInput"
100
130
                            id: endTimeEdit
101
 
                            text: Qt.formatDateTime(defaultDate,"hh:mm")
 
131
                            text: Qt.formatDateTime(endDate,"hh:mm")
102
132
                            anchors {
103
133
                                fill: parent
104
134
                                margins: units.gu(1)
105
135
                            }
 
136
                            onClicked: {
 
137
                                var popupObj = PopupUtils.open(timePicker);
 
138
                                popupObj.accepted.connect(function(hour, minute) {
 
139
                                    var newDate = endDate;
 
140
                                    newDate.setHours(hour, minute);
 
141
                                    endDate = newDate;
 
142
                                })
 
143
                            }
106
144
                        }
107
145
                    }
108
146
                }
142
180
            Dialog {
143
181
                id: errorPopupDialog
144
182
                title: i18n.tr("Error")
145
 
                text: errorText
 
183
                text: ""
146
184
                Button {
147
185
                    text: i18n.tr("Ok")
148
186
                    onClicked: PopupUtils.close(errorPopupDialog)
182
220
                        DataService.addEvent(event);
183
221
                        errorPopupDialog.destroy();
184
222
                        PopupUtils.close(popover);
185
 
                    } else if (error === 1)
186
 
                        errorText = i18n.tr("Time format not valid");
187
 
                    else if (error === 2)
 
223
                    } else
188
224
                        errorText = i18n.tr("End time can't be before start time");
189
225
 
190
226
                    errorPopupDialog.show();
191
227
                    error = 0;
192
 
 
193
 
                    // Control time validity and return date with time
194
 
                    function setTime(time) {
195
 
                        var date = new Date(defaultDate);
196
 
                        if (time.length === 2 && time[0].length < 3 && time[1].length < 3) {
197
 
                            //HH:MM format
198
 
                            date.setHours(time[0]);
199
 
                            date.setMinutes(time[1]);
200
 
                        }
201
 
                        else if (time.length === 1 && time[0].length < 3) {
202
 
                            //HH format
203
 
                            date.setHours(time[0]);
204
 
                            date.setMinutes(0);
205
 
                        }
206
 
                        else
207
 
                            error = 1;
208
 
 
209
 
                        return date;
210
 
                    }
211
228
                }
212
229
            }
213
230
        }