Warning, /education/kstars/kstars/kstarslite/qml/modules/TimePage.qml is written in an unsupported language. File is not indexed.
0001 // SPDX-FileCopyrightText: 2016 Artem Fedoskin <afedoskin3@gmail.com> 0002 // SPDX-License-Identifier: GPL-2.0-or-later 0003 0004 import QtQuick.Controls 2.0 0005 import QtQuick 2.6 0006 import QtQuick.Layouts 1.1 0007 import Qt.labs.calendar 1.0 0008 import "../constants" 1.0 0009 0010 KSPage { 0011 //Change it to Popup when it will become more stable 0012 id: timePopup 0013 title: xi18n("Set Time") 0014 0015 property date currentDate: new Date() 0016 0017 property int userYear: tumblerYear.model[tumblerYear.currentIndex] 0018 property int userMonth: tumblerMonth.currentIndex 0019 property int userDay: tumblerDay.currentIndex + 1 0020 property int userHour: tumblerHour.currentIndex 0021 property int userMinutes: tumblerMinute.currentIndex 0022 //property int userWeek: 0023 signal updateCalendar() 0024 signal updateTumblers() 0025 0026 function range(start, end) { 0027 var list = []; 0028 for (var i = start; i <= end; i++) { 0029 list.push(i); 0030 } 0031 return list 0032 } 0033 0034 function getWeekNumber(year,month,day) { 0035 var d = new Date(year,month,day); 0036 d.setHours(0,0,0); 0037 // Set to nearest Thursday: current date + 4 - current day number 0038 // Make Sunday's day number 7 0039 d.setDate(d.getDate() + 4 - (d.getDay()||7)); 0040 // Get first day of year 0041 var yearStart = new Date(d.getFullYear(),0,1); 0042 // Calculate full weeks to nearest Thursday 0043 var weekNo = Math.ceil(( ( (d - yearStart) / 86400000) + 1)/7) 0044 // Return array of year and week number 0045 return weekNo; 0046 } 0047 0048 function weeksInYear(year) { 0049 var d = new Date(year, 11, 31); 0050 var week = getWeekNumber(d)[1]; 0051 return week == 1? getWeekNumber(d.setDate(24))[1] : week; 0052 } 0053 0054 function daysInMonth(month, year) { 0055 return new Date(year, month, 0).getDate(); 0056 } 0057 0058 function setCurrentDate() { 0059 currentDate = new Date() 0060 tumblerYear.setYear(currentDate.getFullYear()) 0061 tumblerMonth.setMonth(currentDate.getMonth()) 0062 tumblerDay.setDay(currentDate.getDate()) 0063 tumblerHour.setHour(currentDate.getHours()) 0064 tumblerMinute.setMinute(currentDate.getMinutes()) 0065 tumblerWeek.setWeek(currentDate.getFullYear(), currentDate.getMonth(), currentDate.getDate()) 0066 } 0067 0068 GridLayout { 0069 anchors.centerIn: parent 0070 id: timeGrid 0071 columnSpacing: 10 0072 0073 flow: !window.isPortrait ? GridLayout.LeftToRight : GridLayout.TopToBottom 0074 0075 ColumnLayout { 0076 Layout.fillHeight: true 0077 Layout.fillWidth: true 0078 spacing: 0 0079 RowLayout { 0080 anchors { 0081 left: parent.left 0082 right: parent.right 0083 } 0084 0085 Button { 0086 text: "<" 0087 anchors{ 0088 left: parent.left 0089 verticalCenter: parent.verticalCenter 0090 } 0091 onClicked: { 0092 if(userMonth - 1 == -1) { 0093 tumblerMonth.setMonth(11) 0094 tumblerYear.setYear(userYear - 1) 0095 } else { 0096 tumblerMonth.setMonth(userMonth - 1) 0097 } 0098 } 0099 } 0100 0101 KSText { 0102 font.pointSize: 14 0103 text: Qt.locale().standaloneMonthName(userMonth) + " " + monthGrid.year 0104 anchors.centerIn: parent 0105 } 0106 0107 Button { 0108 text: ">" 0109 anchors{ 0110 verticalCenter: parent.verticalCenter 0111 right: parent.right 0112 } 0113 onClicked: { 0114 if(userMonth + 1 == 12) { 0115 tumblerMonth.setMonth(0) 0116 tumblerYear.setYear(userYear + 1) 0117 } else { 0118 tumblerMonth.setMonth(userMonth + 1) 0119 } 0120 } 0121 } 0122 } 0123 0124 GridLayout { 0125 id: calendar 0126 columns: 2 0127 /*Layout.fillHeight: true 0128 Layout.fillWidth: true*/ 0129 Layout.minimumHeight: 150 0130 Layout.minimumWidth: 150 0131 /*Layout.maximumHeight: 250 0132 Layout.maximumWidth: 250*/ 0133 0134 DayOfWeekRow { 0135 Layout.column: 1 0136 Layout.fillWidth: true 0137 } 0138 0139 WeekNumberColumn { 0140 id: weeks 0141 month: monthGrid.month 0142 year: monthGrid.year 0143 locale: monthGrid.locale 0144 Layout.fillHeight: true 0145 } 0146 0147 MonthGrid { 0148 id: monthGrid 0149 spacing: 0 0150 month: userMonth 0151 year: userYear 0152 property int day: userDay 0153 Layout.fillWidth: true 0154 Layout.fillHeight: true 0155 0156 delegate: Rectangle { 0157 id: rect 0158 height: 30 0159 width: 30 0160 color: "#00FFFFFF" 0161 property color highlightColor: Num.sysPalette.highlight 0162 property int selectedDay // Initialize with userDay 0163 0164 Connections { 0165 target: timePopup 0166 onUserDayChanged: { 0167 if(timePopup.userDay == model.day && model.month === monthGrid.month) 0168 rect.color = highlightColor 0169 else rect.color = "#00FFFFFF" 0170 } 0171 } 0172 0173 border { 0174 width: 1 0175 color: "#DCDCDC" 0176 } 0177 0178 KSText { 0179 anchors.centerIn: parent 0180 horizontalAlignment: Text.AlignHCenter 0181 verticalAlignment: Text.AlignVCenter 0182 opacity: model.month === monthGrid.month ? 1 : 0.5 0183 text: model.day 0184 font: monthGrid.font 0185 } 0186 0187 MouseArea { 0188 anchors.fill: parent 0189 0190 onClicked: { 0191 if(model.month != monthGrid.month) { 0192 monthGrid.month = model.month 0193 userMonth = model.month 0194 } else { 0195 rect.color = highlightColor 0196 userDay = model.day 0197 } 0198 updateTumblers() 0199 } 0200 } 0201 } 0202 0203 } 0204 } 0205 } 0206 0207 ColumnLayout { 0208 id: tumblersCol 0209 0210 GridLayout { 0211 id: tumblersGrid 0212 //FIX IT: Didn't find a better way to make tumblers smaller 0213 property int tumblerWidth: 35 0214 property int tumblerHeight: 50 0215 Layout.fillWidth: true 0216 flow: window.isPortrait ? Flow.LeftToRight : Flow.TopToBottom 0217 0218 GroupBox { 0219 id: dateGB 0220 Layout.fillWidth: true 0221 0222 RowLayout { 0223 anchors { 0224 left: parent.left 0225 right: parent.right 0226 } 0227 0228 Layout.fillWidth: true 0229 0230 ColumnLayout { 0231 KSLabel { 0232 id:labelYear 0233 text: xi18n("Year") 0234 } 0235 Tumbler { 0236 id: tumblerYear 0237 implicitHeight: tumblersGrid.tumblerHeight 0238 implicitWidth: tumblersGrid.tumblerWidth 0239 0240 model: range(1616,2500) 0241 anchors.horizontalCenter: labelYear.horizontalCenter 0242 property bool setByCalendar: false 0243 Connections { 0244 target: timePopup 0245 onUpdateTumblers: { 0246 tumblerYear.setByCalendar = true 0247 tumblerYear.setYear(userYear) 0248 } 0249 } 0250 0251 Component.onCompleted: { 0252 setYear(currentDate.getFullYear()) 0253 } 0254 0255 onCurrentIndexChanged: { 0256 if(!setByCalendar) { 0257 //userDate.setFullYear(model[currentIndex]) 0258 updateCalendar() 0259 } 0260 setByCalendar = false 0261 tumblerMonth.checkDays() 0262 } 0263 0264 function setYear(year) { 0265 var index = model.indexOf(year) 0266 if(index != -1) currentIndex = index 0267 } 0268 } 0269 } 0270 0271 ColumnLayout { 0272 Layout.fillHeight: true 0273 KSLabel { 0274 id:labelMonth 0275 text: xi18n("Month") 0276 } 0277 0278 Tumbler { 0279 id: tumblerMonth 0280 model: range(1,12) 0281 implicitHeight: tumblersGrid.tumblerHeight 0282 implicitWidth: tumblersGrid.tumblerWidth 0283 0284 anchors.horizontalCenter: labelMonth.horizontalCenter 0285 property bool setByCalendar: false 0286 //implicitWidth: labelMonth.width 0287 0288 Component.onCompleted: { 0289 setMonth(currentDate.getMonth()) 0290 } 0291 0292 Connections { 0293 target: timePopup 0294 onUpdateTumblers: { 0295 tumblerMonth.setByCalendar = true 0296 tumblerMonth.setMonth(userMonth)//userDate.getMonth()) 0297 } 0298 } 0299 0300 onCurrentIndexChanged: { 0301 userMonth = currentIndex 0302 checkDays() 0303 } 0304 0305 //Called whenever we change month or year. Handles number of days in month 0306 function rangeDays() { 0307 var month = currentIndex+1 0308 var year = tumblerYear.model[tumblerYear.currentIndex] 0309 0310 return range(1,daysInMonth(month,year)) 0311 } 0312 0313 function setMonth(month) { 0314 if(month >= 0 && month <= 11) 0315 currentIndex = month 0316 } 0317 0318 function checkDays() { 0319 tumblerDay.changeModel(rangeDays()) 0320 } 0321 } 0322 } 0323 0324 ColumnLayout { 0325 visible: false 0326 KSLabel { 0327 id:labelWeek 0328 text: xi18n("Week") 0329 } 0330 0331 Tumbler { 0332 id: tumblerWeek 0333 model: range(1,52) 0334 anchors.horizontalCenter: labelWeek.horizontalCenter 0335 implicitHeight: tumblersGrid.tumblerHeight 0336 implicitWidth: tumblersGrid.tumblerWidth 0337 property bool setByCalendar: false 0338 0339 onCurrentIndexChanged: { 0340 if(!setByCalendar) { 0341 //Start counting weeks from the beginning of year 0342 /*var day = userDay 0343 day.setMonth(0) 0344 day.setDate(1) 0345 0346 day.setDate((currentIndex+1)*7) 0347 tumblerMonth.setMonth(day.getMonth()) 0348 tumblerDay.setDay(day.getDate()) 0349 0350 userDate = day 0351 0352 updateCalendar()*/ 0353 } 0354 setByCalendar = false 0355 } 0356 0357 Connections { 0358 target: timePopup 0359 onUpdateTumblers: { 0360 tumblerWeek.setByCalendar = true 0361 tumblerWeek.setWeek(userYear, userMonth + 1, userDay) 0362 } 0363 } 0364 0365 function setWeek(year, month, day) { 0366 currentIndex = getWeekNumber(year, month, day) - 1 0367 } 0368 } 0369 } 0370 0371 ColumnLayout { 0372 KSLabel { 0373 id:labelDay 0374 text: xi18n("Day") 0375 } 0376 0377 Tumbler { 0378 id: tumblerDay 0379 implicitHeight: tumblersGrid.tumblerHeight 0380 implicitWidth: tumblersGrid.tumblerWidth 0381 anchors.horizontalCenter: labelDay.horizontalCenter 0382 0383 model: range(1,daysInMonth(currentDate.getMonth() + 1,currentDate.getFullYear())) 0384 property bool setByCalendar: false 0385 0386 function changeModel(newModel) { 0387 var prevIndex = currentIndex 0388 if(!model || model.length !== newModel.length) { 0389 model = newModel 0390 if(prevIndex >= 0 && prevIndex < model.length) currentIndex = prevIndex 0391 } 0392 } 0393 0394 Connections { 0395 target: timePopup 0396 onUpdateTumblers: { 0397 tumblerDay.setByCalendar = true 0398 tumblerDay.setDay(userDay) 0399 } 0400 } 0401 0402 onCurrentIndexChanged: { 0403 userDay = currentIndex + 1 0404 } 0405 0406 Component.onCompleted: { 0407 setDay(currentDate.getDate()) 0408 } 0409 0410 function setDay(day) { 0411 if(day > 0 && day <= model.length) 0412 currentIndex = day - 1 0413 } 0414 } 0415 } 0416 } 0417 } 0418 0419 RowLayout { 0420 anchors { 0421 left: parent.left 0422 right: parent.right 0423 } 0424 0425 Button { 0426 visible: !window.isPortrait 0427 anchors { 0428 left: parent.left 0429 bottom: parent.bottom 0430 } 0431 0432 onClicked: { 0433 setCurrentDate() 0434 } 0435 0436 text: xi18n("Now") 0437 } 0438 0439 GroupBox { 0440 id: timeGB 0441 anchors.right: parent.right 0442 0443 RowLayout { 0444 Layout.fillWidth: true 0445 ColumnLayout { 0446 KSLabel { 0447 id: labelHour 0448 text: xi18n("Hour") 0449 } 0450 0451 Tumbler { 0452 id: tumblerHour 0453 model: 24 0454 implicitHeight: tumblersGrid.tumblerHeight 0455 implicitWidth: tumblersGrid.tumblerWidth 0456 anchors.horizontalCenter: labelHour.horizontalCenter 0457 0458 delegate: KSText { 0459 text: modelData < 10 ? "0" + modelData : modelData 0460 font: tumblerHour.font 0461 horizontalAlignment: Text.AlignHCenter 0462 verticalAlignment: Text.AlignVCenter 0463 opacity: 1.0 - Math.abs(Tumbler.displacement) / (tumblerHour.visibleItemCount / 2) 0464 } 0465 0466 Component.onCompleted: { 0467 setHour(currentDate.getHours()) 0468 } 0469 0470 function setHour(hour) { 0471 currentIndex = hour 0472 } 0473 } 0474 } 0475 0476 ColumnLayout { 0477 KSLabel { 0478 id:labelMinute 0479 text: xi18n("Min.") 0480 } 0481 0482 Tumbler { 0483 id: tumblerMinute 0484 model: 60 0485 implicitHeight: tumblersGrid.tumblerHeight 0486 implicitWidth: tumblersGrid.tumblerWidth 0487 anchors.horizontalCenter: labelMinute.horizontalCenter 0488 0489 delegate: KSText { 0490 text: modelData < 10 ? "0" + modelData : modelData 0491 font: tumblerHour.font 0492 horizontalAlignment: Text.AlignHCenter 0493 verticalAlignment: Text.AlignVCenter 0494 opacity: 1.0 - Math.abs(Tumbler.displacement) / (tumblerHour.visibleItemCount / 2) 0495 } 0496 0497 Component.onCompleted: { 0498 setMinute(currentDate.getMinutes()) 0499 } 0500 0501 function setMinute(minutes) { 0502 currentIndex = minutes 0503 } 0504 } 0505 } 0506 } 0507 } 0508 } 0509 } 0510 0511 RowLayout { 0512 //height: childrenRect.height 0513 Layout.fillWidth: true 0514 anchors { 0515 left: parent.left 0516 right: parent.right 0517 } 0518 0519 Button { 0520 visible: window.isPortrait 0521 anchors { 0522 left: parent.left 0523 } 0524 0525 onClicked: { 0526 setCurrentDate() 0527 console.log(Projector) 0528 } 0529 0530 text: xi18n("Now") 0531 } 0532 0533 Button { 0534 visible: !window.isPortrait 0535 text: xi18n("Ok") 0536 anchors { 0537 left: parent.left 0538 } 0539 onClicked: { 0540 var date = new Date(userYear, userMonth, userDay, userHour, userMinutes) 0541 KStarsLite.slotSetTime(date) 0542 skyMapLite.notification.showNotification("Setting time to " + date) 0543 stackView.pop() 0544 } 0545 } 0546 0547 Row { 0548 anchors.right: parent.right 0549 spacing: 5 0550 0551 Button { 0552 visible: window.isPortrait 0553 text: xi18n("Ok") 0554 onClicked: { 0555 var date = new Date(userYear, userMonth, userDay, userHour, userMinutes) 0556 KStarsLite.slotSetTime(date) 0557 skyMapLite.notification.showNotification("Setting time to " + date) 0558 stackView.pop() 0559 } 0560 } 0561 0562 Button { 0563 text: xi18n("Cancel") 0564 onClicked: { 0565 stackView.pop() 0566 } 0567 } 0568 } 0569 } 0570 0571 } 0572 } 0573 }