53
53
// Property to retrieve and store the time format setting of the user
54
54
property string timeFormat: appSetting.contents.timeFormat
55
property bool isMilitaryFormat: timeFormat === "24-hour" ? true : false
55
property bool isMilitaryFormat: timeFormat === "24-hour"
102
// Function to show default time when creating new alarm ("00:00" or "12:00")
103
function showDefaultTime() {
104
hourLabel.text = isMilitaryFormat ? "00" : "12"
105
minuteLabel.text = "00"
99
108
// Function to set the correct alarm time depending on AM/PM setting
100
109
function setAlarmTime(alarmTime) {
101
if(Math.round(addAlarmFace.minutes) === 60)
102
addAlarmFace.minutes = 0
110
var hour = Number(hourLabel.text)
111
var minute = Number(minuteLabel.text)
105
alarmTime.setHours(Utils.hourstoCirclePosition(addAlarmFace.hours, timeFormat),Math.round(addAlarmFace.minutes), 0)
113
if(isPm && !isMilitaryFormat && hourLabel.text != "12"){
114
alarmTime.setHours(hour + 12, minute, 0)
116
else if(!isPm && !isMilitaryFormat && hourLabel.text == "12"){
117
alarmTime.setHours(0, minute, 0)
108
if(Utils.hourstoCirclePosition(addAlarmFace.hours, timeFormat) === 0)
109
alarmTime.setHours(12,Math.round(addAlarmFace.minutes), 0)
111
alarmTime.setHours(Utils.hourstoCirclePosition(addAlarmFace.hours, timeFormat),Math.round(addAlarmFace.minutes), 0)
114
if((Utils.hourstoCirclePosition(addAlarmFace.hours, timeFormat)+12) === 24 || Utils.hourstoCirclePosition(addAlarmFace.hours, timeFormat)+12 === 12)
115
alarmTime.setHours(0,Math.round(addAlarmFace.minutes), 0)
117
alarmTime.setHours(Utils.hourstoCirclePosition(addAlarmFace.hours, timeFormat)+12,Math.round(addAlarmFace.minutes), 0)
120
alarmTime.setHours(hour, minute, 0)
142
144
alarm.date = temp_alarm.date
144
146
// Determining if the alarm read is set to trigger in the morning or evening
145
isPm = Qt.formatTime(alarm.date, "hh AP").split(" ")[1] === "AM" ? false : true
146
addAlarmFace.hours = isMilitaryFormat ? Utils.circlePositiontoHours(Qt.formatTime(alarm.date, "hh"), timeFormat) : Utils.circlePositiontoHours(Qt.formatTime(alarm.date, "hh AP").split(" ")[0], timeFormat)
147
addAlarmFace.minutes = Qt.formatTime(alarm.date, "mm")
147
isPm = Qt.formatTime(alarm.date, "AP") === "PM"
148
hourLabel.text = isMilitaryFormat ? Qt.formatTime(alarm.date, "hh") : Qt.formatTime(alarm.date, "h AP").split(" ")[0]
149
minuteLabel.text = Qt.formatTime(alarm.date, "mm")
150
addAlarmFace.hours = Number(hourLabel.text) // Set hour hand
150
153
// Function to update an existing alarm
170
// Function to print hour label
171
function setHoursLabel(hours, maxValue) {
173
if (maxValue === 24){
175
if (addAlarmFace.hours > (maxValue - 1)) {
181
if (addAlarmFace.hours < 1){
185
addAlarmFace.hours = Math.round(hours)
187
return Utils.zeroleft(hours, z);
190
// Function to print minute label
191
function setMinutesLabel(minutes) {
192
if (addAlarmFace.minutes > 59) {
195
addAlarmFace.minutes = Math.round(minutes)
197
return Utils.zeroleft(minutes, 2);
200
// Function to update hour on minute hand rotation
201
function updateHoursOnMinuteRotation(){
202
var hour = Number(hourLabel.text)
203
var minute = Number(minuteLabel.text)
204
var maxHourValue = isMilitaryFormat ? 23 : 12
205
var baseHourValue = isMilitaryFormat ? 0 : 12
207
if (minute === 0 && addAlarmFace.valueWas >= 58){
208
if(hour === baseHourValue - 1 && !isMilitaryFormat){
211
if (hour > maxHourValue - 1){
212
hourLabel.text = isMilitaryFormat ? "00" : "12"
214
if (hour === baseHourValue && !isMilitaryFormat){
219
hourLabel.text = isMilitaryFormat ? ("0" + (hour + 1)).slice(-2) : hour + 1
222
else if (minute >= 58 && addAlarmFace.valueWas === 0){
223
if (hour === baseHourValue && !isMilitaryFormat){
227
hourLabel.text = isMilitaryFormat ? "00" : "12"
228
if (hour === baseHourValue && isMilitaryFormat){
229
hourLabel.text = "23"
233
hourLabel.text = isMilitaryFormat ? ("0" + (hour - 1)).slice(-2) : hour - 1
236
addAlarmFace.valueWas = minute
239
// Function to update AM/PM indicator on the hour hands rotation
240
function updateAmPmOnRotation(){
241
var hour = Number(hourLabel.text)
242
if (((hour === 11 && addAlarmFace.valueWas === 12) || (hour === 12 && addAlarmFace.valueWas === 11)) && !isMilitaryFormat ){
245
addAlarmFace.valueWas = hour
167
248
// Timer to show the error message for one second and then automatically hiding it
192
272
enableMouseArea: false
193
273
showSecondHand: false
194
274
showMinuteHand: false
195
275
innerLabel.visible: false
196
276
anchors.horizontalCenter: parent.horizontalCenter
277
maximumValue: isMilitaryFormat ? 24 : 12
279
onMinutesChanged: minuteLabel.text = setMinutesLabel(minutes)
280
onHoursChanged: {hourLabel.text = setHoursLabel(hours, maximumValue); updateAmPmOnRotation() }
200
284
name: "minuteMode"
201
PropertyChanges { target: hourLabel; font.pixelSize: units.dp(41) }
202
PropertyChanges { target: hourLabel; color: "White" }
203
PropertyChanges { target: addAlarmFace; showHourHand: false }
204
PropertyChanges { target: minuteLabel; font.pixelSize: units.dp(55) }
205
PropertyChanges { target: minuteLabel; color: "LightGreen" }
206
PropertyChanges { target: addAlarmFace; showMinuteHand: true }
285
PropertyChanges { target: addAlarmFace; maximumValue: 60; showHourHand: false; showMinuteHand: true }
286
PropertyChanges { target: hourLabel; font.pixelSize: units.dp(41); color: "White" }
287
PropertyChanges { target: minuteLabel; font.pixelSize: units.dp(55); color: "LightGreen" }
232
313
color: "LightGreen"
233
314
font.pixelSize: units.dp(55)
234
315
anchors.verticalCenter: parent.verticalCenter
236
if(isMilitaryFormat) {
237
// In the 24 hour mode, if the hour is 24, show it as 00 since that's what it essentially is.
238
if(Utils.hourstoCirclePosition(addAlarmFace.hours, timeFormat) === 24)
241
return Utils.zeroleft(Utils.hourstoCirclePosition(addAlarmFace.hours, timeFormat), 2)
244
// In the 12 hour mode, hours cannot be 0, hence show it as 12
245
if(Utils.hourstoCirclePosition(addAlarmFace.hours, timeFormat) === 0)
248
return Utils.zeroleft(Utils.hourstoCirclePosition(addAlarmFace.hours, timeFormat), 2)
252
318
anchors.fill: parent
253
319
preventStealing: true
254
onClicked: addAlarmFace.state = ""
321
addAlarmFace.state = "";
322
addAlarmFace.hours = Number(hourLabel.text)
256
326
Behavior on font.pixelSize {
257
327
UbuntuNumberAnimation { duration: UbuntuAnimation.BriskDuration }
269
339
font.pixelSize: units.dp(41)
270
340
anchors.verticalCenter: parent.verticalCenter
271
text: Utils.zeroleft(addAlarmFace.minutes, 2) === "60" ? "00" : Utils.zeroleft(addAlarmFace.minutes, 2)
341
onTextChanged: if(addAlarmFace.state == "minuteMode") updateHoursOnMinuteRotation()
273
344
id: minuteMouseArea
274
345
anchors.fill: parent
275
onClicked: addAlarmFace.state = "minuteMode"
347
addAlarmFace.state = "minuteMode";
348
addAlarmFace.minutes = Number(minuteLabel.text)
277
352
Behavior on font.pixelSize {
278
353
UbuntuNumberAnimation { duration: UbuntuAnimation.BriskDuration }