/
EditAlarmDialog.qml
258 lines (231 loc) · 9.49 KB
/
EditAlarmDialog.qml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
import QtQuick 2.3
import QtQuick.Layouts 1.1
import Ubuntu.Components 1.3
import Ubuntu.Components.Popups 1.3
import Ubuntu.Components.ListItems 1.3
import Ubuntu.Components.Pickers 1.3
Page {
id: root
title: "Create Alarm"
property var lights: null
property var scenes: null
property var schedules: null
readonly property bool recurring: recurringSelector.selectedIndex == 1
readonly property string mode: modeSelector.selectedIndex == 0 ? "lights" : "scene"
head {
actions: [
Action {
iconName: "tick"
enabled: nameTextField.text
onTriggered: {
if (root.recurring) {
if (root.mode == "scene") {
root.schedules.createRecurringAlarmForScene(nameTextField.text, scenes.get(sceneSelector.selectedIndex).id, dateTime.date, recurrenceSelector.weekdays)
}
} else {
if (root.mode == "scene") {
root.schedules.createSingleAlarmForScene(nameTextField.text, scenes.get(sceneSelector.selectedIndex).id, dateTime.date)
}
}
pageStack.pop()
}
}
]
}
Column {
anchors {
fill: parent
topMargin: units.gu(1)
}
// anchors.margins: units.gu(1)
spacing: units.gu(1)
RowLayout {
anchors { left: parent.left; right: parent.right; margins: units.gu(2) }
spacing: units.gu(1)
Label {
text: i18n.tr("Name")
}
TextField {
id: nameTextField
Layout.fillWidth: true
}
}
Column {
width: parent.width
ItemSelector {
id: recurringSelector
width: parent.width
model: ["Single alarm", "Recurring alarm"]
}
Subtitled {
id: dateTime
text: root.recurring ? i18n.tr("Time") : i18n.tr("Date & Time")
subText: root.recurring ? date.toString("hh:mm") : date.toString(i18n.tr("YYYY-MM-dd hh:mm"))
property var date: new Date()
onClicked: {
var popup = PopupUtils.open(dateTimePicker, root, {date: date})
popup.closed.connect(function(date) {
dateTime.date = date
})
}
}
Component {
id: dateTimePicker
Dialog {
id: dtp
title: root.recurring ? i18n.tr("Time") : i18n.tr("Date & Time")
signal closed(var date)
property var date: new Date()
Component.onCompleted: {
// timePicker.date.setHours(hour)
// timePicker.date.setMinutes(minute)
// print("**************", timePicker.hours, hour)
}
DatePicker {
id: datePicker
date: dtp.date
visible: !root.recurring
}
DatePicker {
id: timePicker
mode: "Hours|Minutes"
date: dtp.date
}
Button {
text: i18n.tr("OK")
onClicked: {
var mixedDate = datePicker.date;
mixedDate.setHours(timePicker.date.getHours())
mixedDate.setMinutes(timePicker.date.getMinutes())
dtp.closed(mixedDate)
PopupUtils.close(dtp)
}
}
}
}
Subtitled {
id: recurrenceSelector
text: "Recurrence"
subText: {
var strings = new Array()
if (weekdays[1] == "1") strings.push("Mon")
if (weekdays[2] == "1") strings.push("Tue")
if (weekdays[3] == "1") strings.push("Wed")
if (weekdays[4] == "1") strings.push("Thu")
if (weekdays[5] == "1") strings.push("Fri")
if (weekdays[6] == "1") strings.push("Sat")
if (weekdays[7] == "1") strings.push("Sun")
return strings.join(", ")
}
visible: root.recurring
property string weekdays: "00000000"
onClicked: {
var popup = PopupUtils.open(recurrancePicker, root)
popup.closed.connect(function(weekdays) {
recurrenceSelector.weekdays = weekdays;
})
}
}
Component {
id: recurrancePicker
Dialog {
id: rp
title: i18n.tr("Days")
signal closed(string weekdays)
RowLayout { CheckBox { id: cbMonday; checked: recurrenceSelector.weekdays[1] == "1" } Label { Layout.fillWidth: true; text: "Monday"} }
RowLayout { CheckBox { id: cbTuesday; checked: recurrenceSelector.weekdays[2] == "1" } Label { Layout.fillWidth: true; text: "Tuesday"} }
RowLayout { CheckBox { id: cbWednesday; checked: recurrenceSelector.weekdays[3] == "1" } Label { Layout.fillWidth: true; text: "Wednesday"} }
RowLayout { CheckBox { id: cbThursday; checked: recurrenceSelector.weekdays[4] == "1" } Label { Layout.fillWidth: true; text: "Thursday"} }
RowLayout { CheckBox { id: cbFriday; checked: recurrenceSelector.weekdays[5] == "1" } Label { Layout.fillWidth: true; text: "Friday"} }
RowLayout { CheckBox { id: cbSaturday; checked: recurrenceSelector.weekdays[6] == "1" } Label { Layout.fillWidth: true; text: "Saturday"} }
RowLayout { CheckBox { id: cbSunday; checked: recurrenceSelector.weekdays[7] == "1" } Label { Layout.fillWidth: true; text: "Sunday"} }
Button {
text: i18n.tr("OK")
onClicked: {
var weekdays = "0";
weekdays += cbMonday.checked ? "1" : "0"
weekdays += cbTuesday.checked ? "1" : "0"
weekdays += cbWednesday.checked ? "1" : "0"
weekdays += cbThursday.checked ? "1" : "0"
weekdays += cbFriday.checked ? "1" : "0"
weekdays += cbSaturday.checked ? "1" : "0"
weekdays += cbSunday.checked ? "1" : "0"
rp.closed(weekdays)
PopupUtils.close(rp);
}
}
}
}
ItemSelector {
id: modeSelector
width: parent.width
model: ["Lights", "Scene"]
}
}
Label {
width: parent.width
text: root.mode == "lights" ?
i18n.tr("Check all the lights that should be controlled by this alarm. The current brightness and color values will be used.")
: i18n.tr("Select the scene to be enabled by the alarm")
wrapMode: Text.WordWrap
}
Repeater {
id: lightsCheckboxes
model: root.lights
delegate: Row {
visible: root.mode == "lights"
width: parent.width
spacing: units.gu(1)
property alias checked: checkBox.checked
CheckBox {
id: checkBox
checked: false
}
Label {
text: name
anchors.verticalCenter: parent.verticalCenter
}
}
}
ItemSelector {
id: sceneSelector
width: parent.width
visible: root.mode == "scene"
model: root.scenes
delegate: OptionSelectorDelegate {
text: model.name
}
}
}
// Button {
// text: "OK"
// color: UbuntuColors.green
// enabled: nameTextField.text.length > 0 || nameTextField.inputMethodComposing
// onClicked: {
// var lightsOrScene;
// if (root.mode == "lights") {
// var lightsList = new Array;
// for (var i = 0; i < lightsCheckboxes.count; ++i) {
// if (lightsCheckboxes.itemAt(i).checked) {
// print("adding light", i)
// lightsList.push(lights.get(i).id);
// print("list is now", lightsList.length)
// }
// }
// lightsOrScene = lightsList;
// } else {
// lightsOrScene = scenes.get(sceneSelector.selectedIndex).id
// }
// root.accepted(nameTextField.text, lightsOrScene)
// PopupUtils.close(root)
// }
// }
// Button {
// text: "Cancel"
// color: UbuntuColors.red
// onClicked: {
// root.rejected();
// PopupUtils.close(root)
// }
// }
}