4import QtQuick.Controls 2.0
6import QtQuick.Layouts 1.1
7import Qt.labs.calendar 1.0
8import "../constants" 1.0
13 title:
xi18n(
"Set Time")
15 property date currentDate: new Date()
17 property
int userYear: tumblerYear.model[tumblerYear.currentIndex]
18 property
int userMonth: tumblerMonth.currentIndex
19 property
int userDay: tumblerDay.currentIndex + 1
20 property
int userHour: tumblerHour.currentIndex
21 property
int userMinutes: tumblerMinute.currentIndex
23 signal updateCalendar()
24 signal updateTumblers()
26 function range(start, end) {
28 for (var i = start; i <=
end; i++) {
34 function getWeekNumber(year,month,day) {
35 var d =
new Date(year,month,day);
39 d.setDate(d.getDate() + 4 - (d.getDay()||7));
41 var yearStart =
new Date(d.getFullYear(),0,1);
43 var weekNo = Math.ceil(( ( (d - yearStart) / 86400000) + 1)/7)
48 function weeksInYear(year) {
49 var d =
new Date(year, 11, 31);
50 var week = getWeekNumber(d)[1];
51 return week == 1? getWeekNumber(d.setDate(24))[1] : week;
54 function daysInMonth(month, year) {
55 return new Date(year, month, 0).getDate();
58 function setCurrentDate() {
59 currentDate =
new Date()
60 tumblerYear.setYear(currentDate.getFullYear())
61 tumblerMonth.setMonth(currentDate.getMonth())
62 tumblerDay.setDay(currentDate.getDate())
63 tumblerHour.setHour(currentDate.getHours())
64 tumblerMinute.setMinute(currentDate.getMinutes())
65 tumblerWeek.setWeek(currentDate.getFullYear(), currentDate.getMonth(), currentDate.getDate())
69 anchors.centerIn: parent
73 flow: !
window.isPortrait ? GridLayout.LeftToRight : GridLayout.TopToBottom
76 Layout.fillHeight:
true
77 Layout.fillWidth:
true
89 verticalCenter: parent.verticalCenter
92 if(userMonth - 1 == -1) {
93 tumblerMonth.setMonth(11)
94 tumblerYear.setYear(userYear - 1)
96 tumblerMonth.setMonth(userMonth - 1)
103 text:
Qt.locale().standaloneMonthName(userMonth) +
" " + monthGrid.year
104 anchors.centerIn: parent
110 verticalCenter: parent.verticalCenter
114 if(userMonth + 1 == 12) {
115 tumblerMonth.setMonth(0)
116 tumblerYear.setYear(userYear + 1)
118 tumblerMonth.setMonth(userMonth + 1)
129 Layout.minimumHeight: 150
130 Layout.minimumWidth: 150
136 Layout.fillWidth:
true
141 month: monthGrid.month
143 locale: monthGrid.locale
144 Layout.fillHeight:
true
152 property int day: userDay
153 Layout.fillWidth:
true
154 Layout.fillHeight:
true
156 delegate: Rectangle {
161 property color highlightColor: Num.sysPalette.highlight
162 property int selectedDay
167 if(timePopup.userDay == model.day && model.month === monthGrid.month)
168 rect.color = highlightColor
169 else rect.color =
"#00FFFFFF"
179 anchors.centerIn: parent
180 horizontalAlignment: Text.AlignHCenter
181 verticalAlignment: Text.AlignVCenter
182 opacity: model.month === monthGrid.month ? 1 : 0.5
191 if(model.month != monthGrid.month) {
192 monthGrid.month = model.month
193 userMonth = model.month
195 rect.color = highlightColor
213 property int tumblerWidth: 35
214 property int tumblerHeight: 50
215 Layout.fillWidth:
true
216 flow:
window.isPortrait ? Flow.LeftToRight : Flow.TopToBottom
220 Layout.fillWidth:
true
228 Layout.fillWidth:
true
237 implicitHeight: tumblersGrid.tumblerHeight
238 implicitWidth: tumblersGrid.tumblerWidth
240 model: range(1616,2500)
241 anchors.horizontalCenter: labelYear.horizontalCenter
242 property
bool setByCalendar: false
246 tumblerYear.setByCalendar =
true
247 tumblerYear.setYear(userYear)
251 Component.onCompleted: {
252 setYear(currentDate.getFullYear())
255 onCurrentIndexChanged: {
260 setByCalendar =
false
261 tumblerMonth.checkDays()
264 function setYear(year) {
265 var index = model.indexOf(year)
266 if(index != -1) currentIndex = index
272 Layout.fillHeight:
true
281 implicitHeight: tumblersGrid.tumblerHeight
282 implicitWidth: tumblersGrid.tumblerWidth
284 anchors.horizontalCenter: labelMonth.horizontalCenter
285 property
bool setByCalendar: false
288 Component.onCompleted: {
289 setMonth(currentDate.getMonth())
295 tumblerMonth.setByCalendar =
true
296 tumblerMonth.setMonth(userMonth)
300 onCurrentIndexChanged: {
301 userMonth = currentIndex
306 function rangeDays() {
307 var month = currentIndex+1
308 var year = tumblerYear.model[tumblerYear.currentIndex]
310 return range(1,daysInMonth(month,year))
313 function setMonth(month) {
314 if(month >= 0 && month <= 11)
318 function checkDays() {
319 tumblerDay.changeModel(rangeDays())
334 anchors.horizontalCenter: labelWeek.horizontalCenter
335 implicitHeight: tumblersGrid.tumblerHeight
336 implicitWidth: tumblersGrid.tumblerWidth
337 property
bool setByCalendar: false
339 onCurrentIndexChanged: {
354 setByCalendar =
false
360 tumblerWeek.setByCalendar =
true
361 tumblerWeek.setWeek(userYear, userMonth + 1, userDay)
365 function setWeek(year, month, day) {
366 currentIndex = getWeekNumber(year, month, day) - 1
379 implicitHeight: tumblersGrid.tumblerHeight
380 implicitWidth: tumblersGrid.tumblerWidth
381 anchors.horizontalCenter: labelDay.horizontalCenter
383 model: range(1,daysInMonth(currentDate.getMonth() + 1,currentDate.getFullYear()))
384 property
bool setByCalendar: false
386 function changeModel(newModel) {
387 var prevIndex = currentIndex
388 if(!model || model.length !== newModel.length) {
390 if(prevIndex >= 0 && prevIndex < model.length) currentIndex = prevIndex
397 tumblerDay.setByCalendar =
true
398 tumblerDay.setDay(userDay)
402 onCurrentIndexChanged: {
403 userDay = currentIndex + 1
406 Component.onCompleted: {
407 setDay(currentDate.getDate())
410 function setDay(day) {
411 if(day > 0 && day <= model.length)
412 currentIndex = day - 1
426 visible: !
window.isPortrait
429 bottom: parent.bottom
441 anchors.right: parent.right
444 Layout.fillWidth:
true
454 implicitHeight: tumblersGrid.tumblerHeight
455 implicitWidth: tumblersGrid.tumblerWidth
456 anchors.horizontalCenter: labelHour.horizontalCenter
459 text: modelData < 10 ?
"0" + modelData : modelData
460 font: tumblerHour.font
461 horizontalAlignment: Text.AlignHCenter
462 verticalAlignment: Text.AlignVCenter
463 opacity: 1.0 - Math.abs(Tumbler.displacement) / (tumblerHour.visibleItemCount / 2)
466 Component.onCompleted: {
467 setHour(currentDate.getHours())
470 function setHour(hour) {
485 implicitHeight: tumblersGrid.tumblerHeight
486 implicitWidth: tumblersGrid.tumblerWidth
487 anchors.horizontalCenter: labelMinute.horizontalCenter
490 text: modelData < 10 ?
"0" + modelData : modelData
491 font: tumblerHour.font
492 horizontalAlignment: Text.AlignHCenter
493 verticalAlignment: Text.AlignVCenter
494 opacity: 1.0 - Math.abs(Tumbler.displacement) / (tumblerHour.visibleItemCount / 2)
497 Component.onCompleted: {
498 setMinute(currentDate.getMinutes())
501 function setMinute(minutes) {
502 currentIndex = minutes
513 Layout.fillWidth:
true
520 visible:
window.isPortrait
534 visible: !
window.isPortrait
540 var date =
new Date(userYear, userMonth, userDay, userHour, userMinutes)
542 skyMapLite.notification.showNotification(
"Setting time to " + date)
548 anchors.right: parent.right
552 visible:
window.isPortrait
555 var date =
new Date(userYear, userMonth, userDay, userHour, userMinutes)
557 skyMapLite.notification.showNotification(
"Setting time to " + date)
563 text:
xi18n(
"Cancel")
This class loads QML files and connects SkyMapLite and KStarsData Unlike KStars class it is not a mai...
void slotSetTime(QDateTime time)
sets time and date according to parameter time
The Projector class is the primary class that serves as an interface to handle projections.
QString xi18n(const char *text, const TYPE &arg...)
KGUIADDONS_EXPORT QWindow * window(QObject *job)
KIOCORE_EXPORT QStringList list(const QString &fileClass)
const QList< QKeySequence > & end()
QTextStream & left(QTextStream &stream)
QTextStream & right(QTextStream &stream)