Warning, /plasma/plasma-bigscreen/kcms/bigscreen-settings/ui/DeviceTimeSettings.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 SPDX-FileCopyrightText: 2020 Aditya Mehra <aix.m@outlook.com> 0003 0004 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0005 0006 */ 0007 0008 import QtQuick.Layouts 1.14 0009 import QtQuick 2.14 0010 import QtQuick.Window 2.14 0011 import QtQuick.Controls 2.14 0012 import org.kde.plasma.plasma5support 2.0 as P5Support 0013 import org.kde.plasma.components 3.0 as PlasmaComponents 0014 import org.kde.plasma.extras 2.0 as PlasmaExtras 0015 import org.kde.kirigami as Kirigami 0016 import org.kde.kcmutils as KCM 0017 import org.kde.mycroft.bigscreen 1.0 as BigScreen 0018 import "delegates" as Delegates 0019 import org.kde.plasma.private.digitalclock 1.0 0020 0021 Rectangle { 0022 id: main 0023 color: Kirigami.Theme.backgroundColor 0024 property string timeFormat 0025 property date currentTime 0026 property date currentDate 0027 0028 onActiveFocusChanged: { 0029 if(activeFocus){ 0030 timeDisplayItemTwo.forceActiveFocus() 0031 } 0032 } 0033 0034 Keys.onBackPressed: { 0035 backBtnSettingsItem.clicked() 0036 } 0037 0038 TimeZoneModel { 0039 id: timeZones 0040 } 0041 0042 P5Support.DataSource { 0043 id: dataSource 0044 engine: "time" 0045 connectedSources: "Local" 0046 interval: 1000 0047 onDataChanged: { 0048 var date = new Date(data["Local"]["DateTime"]); 0049 var hours = date.getHours(); 0050 var minutes = date.getMinutes(); 0051 var seconds = date.getSeconds(); 0052 } 0053 Component.onCompleted: { 0054 onDataChanged(); 0055 } 0056 } 0057 0058 Component.onCompleted: { 0059 tzOffset = new Date().getTimezoneOffset(); 0060 dateTimeChanged(); 0061 dataSource.onDataChanged.connect(dateTimeChanged); 0062 } 0063 0064 function dateTimeChanged() 0065 { 0066 var currentTZOffset = dataSource.data["Local"]["Offset"] / 60; 0067 if (currentTZOffset !== tzOffset) { 0068 tzOffset = currentTZOffset; 0069 Date.timeZoneUpdated(); 0070 } 0071 } 0072 0073 0074 Item { 0075 id: emptyArea 0076 height: Kirigami.Units.gridUnit * 2 0077 width: parent.width 0078 anchors.top: parent.top 0079 } 0080 0081 Flickable { 0082 id: flickContentLayout 0083 clip: true 0084 anchors { 0085 top: emptyArea.bottom 0086 left: parent.left 0087 right: parent.right 0088 bottom: footerAreaSettingsSept.top 0089 margins: Kirigami.Units.largeSpacing * 2 0090 } 0091 contentWidth: width 0092 contentHeight: colLayoutSettingsItem.implicitHeight 0093 0094 function makeVisible(item) { 0095 var startArea = item.mapToItem(contentItem, 0, 0).y 0096 var endArea = item.height + startArea 0097 if ( startArea < contentY || startArea > contentY + height || endArea < contentY || endArea > contentY + height) { 0098 contentY = Math.max(0, Math.min(startArea - height + item.height, contentHeight - height)) 0099 } 0100 } 0101 0102 Behavior on contentY { 0103 NumberAnimation { 0104 duration: Kirigami.Units.longDuration * 2 0105 easing.type: Easing.InOutQuad 0106 } 0107 } 0108 0109 ColumnLayout { 0110 id: colLayoutSettingsItem 0111 width: parent.width 0112 anchors.top: parent.top 0113 0114 0115 Kirigami.Icon { 0116 id: dIcon 0117 Layout.alignment: Qt.AlignTop | Qt.AlignHCenter 0118 Layout.preferredWidth: parent.width 0119 Layout.preferredHeight: width / 3 0120 source: "preferences-system-time" 0121 } 0122 0123 Kirigami.Heading { 0124 id: label1 0125 Layout.fillWidth: true 0126 Layout.alignment: Qt.AlignTop | Qt.AlignHCenter 0127 Layout.topMargin: Kirigami.Units.largeSpacing 0128 horizontalAlignment: Text.AlignHCenter 0129 wrapMode: Text.WordWrap 0130 level: 2 0131 maximumLineCount: 2 0132 elide: Text.ElideRight 0133 color: Kirigami.Theme.textColor 0134 text: "Adjust Date & Time Settings" 0135 } 0136 0137 Kirigami.Separator { 0138 id: lblSept 0139 Layout.alignment: Qt.AlignTop | Qt.AlignHCenter 0140 Layout.topMargin: Kirigami.Units.largeSpacing 0141 Layout.preferredHeight: 1 0142 Layout.fillWidth: true 0143 } 0144 0145 Kirigami.ListSectionHeader { 0146 id: timeDisplaySectionHeader 0147 Layout.alignment: Qt.AlignTop 0148 Layout.topMargin: Kirigami.Units.largeSpacing 0149 label: i18n("Time Display") 0150 } 0151 0152 AbstractButton { 0153 id: timeDisplayItemTwo 0154 Layout.alignment: Qt.AlignTop 0155 Layout.topMargin: Kirigami.Units.largeSpacing 0156 text: i18n("Timezone:") 0157 onClicked: timeZonePickerSheet.open() 0158 Label { 0159 id: timeZoneButton 0160 text: dataSource.data["Local"]["Timezone"] 0161 } 0162 KeyNavigation.up: backBtnSettingsItem 0163 KeyNavigation.down: timeDisplayItemThree 0164 Keys.onReturnPressed: clicked() 0165 onActiveFocusChanged: { 0166 if(activeFocus){ 0167 flickContentLayout.makeVisible(timeDisplayItemTwo) 0168 } 0169 } 0170 } 0171 0172 AbstractButton { 0173 id: timeDisplayItemThree 0174 Layout.alignment: Qt.AlignTop 0175 Layout.topMargin: Kirigami.Units.largeSpacing 0176 text: i18n("Set time automatically:") 0177 KeyNavigation.up: timeDisplayItemTwo 0178 KeyNavigation.down: timeDisplayItemFour 0179 Keys.onReturnPressed: clicked() 0180 onActiveFocusChanged: { 0181 if(activeFocus){ 0182 flickContentLayout.makeVisible(timeDisplayItemThree) 0183 } 0184 } 0185 0186 onClicked: { 0187 ntpCheckBox.checked = !ntpCheckBox.checked 0188 ntpCheckBox.clicked() 0189 } 0190 0191 Switch { 0192 id: ntpCheckBox 0193 checked: kcm.useNtp 0194 onClicked: { 0195 kcm.useNtp = checked; 0196 if (!checked) { 0197 kcm.ntpServer = "" 0198 kcm.setCurrentTime(main.currentTime) 0199 kcm.setCurrentDate(main.currentDate) 0200 kcm.saveTime() 0201 } 0202 } 0203 } 0204 } 0205 0206 AbstractButton { 0207 id: timeDisplayItemFour 0208 Layout.alignment: Qt.AlignTop 0209 Layout.topMargin: Kirigami.Units.largeSpacing 0210 text: i18n("Time") 0211 icon.name: "clock" 0212 enabled: !ntpCheckBox.checked 0213 onClicked: timePickerSheet.open() 0214 KeyNavigation.up: timeDisplayItemThree 0215 KeyNavigation.down: timeDisplayItemFive 0216 Keys.onReturnPressed: clicked() 0217 onActiveFocusChanged: { 0218 if(activeFocus){ 0219 flickContentLayout.makeVisible(timeDisplayItemFour) 0220 } 0221 } 0222 0223 Label { 0224 text: { 0225 // get the time for the given timezone from the dataengine 0226 var now = dataSource.data["Local"]["DateTime"]; 0227 // get current UTC time 0228 var msUTC = now.getTime() + (now.getTimezoneOffset() * 60000); 0229 // add the dataengine TZ offset to it 0230 var currentTime = new Date(msUTC + (dataSource.data["Local"]["Offset"] * 1000)); 0231 0232 main.currentDate = currentTime 0233 return Qt.formatTime(currentTime,"hh:mm"); 0234 } 0235 } 0236 } 0237 0238 AbstractButton { 0239 id: timeDisplayItemFive 0240 Layout.alignment: Qt.AlignTop 0241 Layout.topMargin: Kirigami.Units.largeSpacing 0242 text: i18n("Date") 0243 icon.name: "view-calendar" 0244 enabled: !ntpCheckBox.checked 0245 onClicked: datePickerSheet.open() 0246 KeyNavigation.up: timeDisplayItemFour 0247 KeyNavigation.down: backBtnSettingsItem 0248 Keys.onReturnPressed: clicked() 0249 onActiveFocusChanged: { 0250 if(activeFocus){ 0251 flickContentLayout.makeVisible(timeDisplayItemFive) 0252 } 0253 } 0254 0255 Label { 0256 text: { 0257 // get the time for the given timezone from the dataengine 0258 var now = dataSource.data["Local"]["DateTime"]; 0259 // get current UTC time 0260 var msUTC = now.getTime() + (now.getTimezoneOffset() * 60000); 0261 // add the dataengine TZ offset to it 0262 var currentTime = new Date(msUTC + (dataSource.data["Local"]["Offset"] * 1000)); 0263 0264 main.currentDate = currentTime 0265 return Qt.formatDate(currentTime,"dd.MM.yyyy"); 0266 } 0267 } 0268 } 0269 } 0270 } 0271 0272 Kirigami.Separator { 0273 id: footerAreaSettingsSept 0274 anchors.bottom: footerAreaSettingsItem.top 0275 anchors.bottomMargin: Kirigami.Units.largeSpacing 0276 anchors.left: parent.left 0277 anchors.right: parent.right 0278 anchors.leftMargin: Kirigami.Units.largeSpacing * 2 0279 anchors.rightMargin: Kirigami.Units.largeSpacing * 2 0280 height: 1 0281 } 0282 0283 RowLayout { 0284 id: footerAreaSettingsItem 0285 anchors.bottom: parent.bottom 0286 anchors.left: parent.left 0287 anchors.right: parent.right 0288 anchors.margins: Kirigami.Units.largeSpacing * 2 0289 height: Kirigami.Units.gridUnit * 2 0290 0291 PlasmaComponents.Button { 0292 id: backBtnSettingsItem 0293 icon.name: "arrow-left" 0294 Layout.alignment: Qt.AlignLeft 0295 0296 PlasmaExtras.Highlight { 0297 z: -2 0298 anchors.fill: parent 0299 anchors.margins: -Kirigami.Units.gridUnit / 4 0300 visible: backBtnSettingsItem.activeFocus ? 1 : 0 0301 } 0302 0303 Keys.onReturnPressed: { 0304 clicked() 0305 } 0306 0307 onClicked: { 0308 deviceTimeSettingsArea.opened = false 0309 timeDateSettingsDelegate.forceActiveFocus() 0310 } 0311 } 0312 0313 Label { 0314 id: backbtnlabelHeading 0315 text: i18n("Press the [←] Back button to return to appearance settings") 0316 wrapMode: Text.WordWrap 0317 maximumLineCount: 2 0318 Layout.fillWidth: true 0319 Layout.alignment: Qt.AlignRight 0320 } 0321 } 0322 0323 Popup { 0324 id: timeZonePickerSheet 0325 width: parent.width / 2 0326 height: parent.height / 1.25 0327 x: (parent.width - width) / 2 0328 y: (parent.height - height) / 2 0329 parent: parent.parent 0330 0331 onOpenedChanged: { 0332 if(opened){ 0333 searchBoxItem.forceActiveFocus() 0334 } 0335 } 0336 0337 Keys.onBackPressed: { 0338 backBtnTZPItem.clicked() 0339 } 0340 0341 FocusScope { 0342 anchors.fill: parent 0343 0344 ColumnLayout { 0345 anchors.fill: parent 0346 0347 RowLayout { 0348 id: timeZonePickerSheetFooterItem 0349 Layout.fillWidth: true 0350 Layout.preferredHeight: parent.height * 0.10 0351 0352 0353 PlasmaComponents.Button { 0354 id: backBtnTZPItem 0355 icon.name: "arrow-left" 0356 Layout.alignment: Qt.AlignLeft 0357 KeyNavigation.down: searchBoxItem 0358 0359 PlasmaExtras.Highlight { 0360 z: -2 0361 anchors.fill: parent 0362 anchors.margins: -Kirigami.Units.gridUnit / 4 0363 visible: backBtnTZPItem.activeFocus ? 1 : 0 0364 } 0365 0366 Keys.onReturnPressed: { 0367 clicked() 0368 } 0369 0370 onClicked: { 0371 timeZonePickerSheet.close() 0372 timeDisplayItemTwo.forceActiveFocus() 0373 } 0374 } 0375 0376 Label { 0377 id: backbtnlabelTZPHeading 0378 text: i18n("Press the [←] Back button to save configuration and return to settings") 0379 wrapMode: Text.WordWrap 0380 maximumLineCount: 2 0381 Layout.fillWidth: true 0382 Layout.alignment: Qt.AlignRight 0383 } 0384 } 0385 0386 Rectangle { 0387 id: searchBoxItem 0388 color: "transparent" 0389 Layout.fillWidth: true 0390 Layout.preferredHeight: parent.height * 0.10 0391 border.color: Kirigami.Theme.linkColor 0392 border.width: searchBoxItem.focus ? 1 : 0 0393 KeyNavigation.up: backBtnTZPItem 0394 KeyNavigation.down: listView 0395 Keys.onReturnPressed: searchField.forceActiveFocus() 0396 0397 Kirigami.SearchField { 0398 id: searchField 0399 anchors.fill: parent 0400 placeholderText: "Search City / Region" 0401 } 0402 } 0403 0404 ListView { 0405 id: listView 0406 clip: true 0407 focus: false 0408 0409 Layout.fillWidth: true 0410 Layout.fillHeight: true 0411 0412 model: TimeZoneFilterProxy { 0413 sourceModel: timeZones 0414 filterString: searchField.text 0415 } 0416 0417 delegate: ItemDelegate { 0418 width: parent.width 0419 text: model.timeZoneId == "Local" ? i18n("Your local timezone is %1", city) : i18n("%1, %2", city, region) 0420 enabled: model.timeZoneId != "Local" ? 1 : 0 0421 0422 Keys.onReturnPressed: clicked() 0423 onClicked: { 0424 kcm.saveTimeZone(model.timeZoneId) 0425 } 0426 onFocusChanged: { 0427 if(focus && model.timeZoneId == "Local") { 0428 listView.currentIndex = index + 1 0429 } 0430 } 0431 } 0432 0433 Keys.onUpPressed: { 0434 if(listView.currentIndex == 0 || listView.currentIndex == 1) { 0435 searchBoxItem.forceActiveFocus() 0436 listView.focus = false 0437 } else { 0438 listView.decrementCurrentIndex() 0439 } 0440 } 0441 } 0442 } 0443 } 0444 } 0445 0446 0447 Popup { 0448 id: timePickerSheet 0449 width: parent.width / 2 0450 height: parent.height / 2 0451 x: (parent.width - width) / 2 0452 y: (parent.height - height) / 2 0453 parent: parent.parent 0454 0455 onOpenedChanged: { 0456 if(opened){ 0457 timePicker.forceActiveFocus() 0458 } 0459 } 0460 0461 onClosed: { 0462 timeDisplayItemThree.forceActiveFocus() 0463 } 0464 0465 Keys.onBackPressed: { 0466 backBtnTPItem.clicked() 0467 } 0468 0469 ColumnLayout { 0470 anchors.fill: parent 0471 0472 RowLayout { 0473 id: timePickerSheetFooterItem 0474 Layout.fillWidth: true 0475 Layout.preferredHeight: parent.height * 0.10 0476 0477 0478 PlasmaComponents.Button { 0479 id: backBtnTPItem 0480 icon.name: "arrow-left" 0481 Layout.alignment: Qt.AlignLeft 0482 KeyNavigation.down: timePicker 0483 0484 PlasmaExtras.Highlight { 0485 z: -2 0486 anchors.fill: parent 0487 anchors.margins: -Kirigami.Units.gridUnit / 4 0488 visible: backBtnTPItem.activeFocus ? 1 : 0 0489 } 0490 0491 Keys.onReturnPressed: { 0492 clicked() 0493 } 0494 0495 onClicked: { 0496 timePickerSheet.close() 0497 timeDisplayItemThree.forceActiveFocus() 0498 } 0499 } 0500 0501 Label { 0502 id: backbtnlabelTPHeading 0503 text: i18n("Press the [←] Back button to save configuration and return to settings") 0504 wrapMode: Text.WordWrap 0505 maximumLineCount: 2 0506 Layout.fillWidth: true 0507 Layout.alignment: Qt.AlignRight 0508 } 0509 } 0510 0511 Delegates.TimePicker { 0512 id: timePicker 0513 enabled: !ntpCheckBox.checked 0514 Layout.fillWidth: true 0515 Layout.fillHeight: true 0516 0517 Component.onCompleted: { 0518 var date = new Date(main.currentTime); 0519 timePicker.hours = date.getHours(); 0520 timePicker.minutes = date.getMinutes(); 0521 timePicker.seconds = date.getSeconds(); 0522 } 0523 0524 onUserConfiguringChanged: { 0525 var date = new Date(main.currentTime) 0526 date.setHours(timePicker.hours) 0527 date.setMinutes(timePicker.minutes) 0528 date.setSeconds(timePicker.seconds) 0529 0530 kcm.setCurrentTime(date) 0531 kcm.setCurrentDate(date) 0532 kcm.saveTime() 0533 } 0534 } 0535 0536 Keys.onReturnPressed: { 0537 timePickerSheet.close() 0538 timeDisplayItemThree.forceActiveFocus() 0539 } 0540 } 0541 } 0542 0543 Popup { 0544 id: datePickerSheet 0545 width: parent.width / 2 0546 height: parent.height / 2 0547 x: (parent.width - width) / 2 0548 y: (parent.height - height) / 2 0549 parent: parent.parent 0550 0551 onOpenedChanged: { 0552 if(opened){ 0553 datePicker.forceActiveFocus() 0554 } 0555 } 0556 0557 onClosed: { 0558 timeDisplayItemFour.forceActiveFocus() 0559 } 0560 0561 0562 Keys.onBackPressed: { 0563 backBtnDTItem.clicked() 0564 } 0565 0566 ColumnLayout { 0567 anchors.fill: parent 0568 0569 RowLayout { 0570 id: datePickerSheetFooterItem 0571 Layout.fillWidth: true 0572 Layout.preferredHeight: parent.height * 0.10 0573 0574 0575 PlasmaComponents.Button { 0576 id: backBtnDTItem 0577 icon.name: "arrow-left" 0578 Layout.alignment: Qt.AlignLeft 0579 KeyNavigation.down: datePicker 0580 0581 PlasmaExtras.Highlight { 0582 z: -2 0583 anchors.fill: parent 0584 anchors.margins: -Kirigami.Units.gridUnit / 4 0585 visible: backBtnDTItem.activeFocus ? 1 : 0 0586 } 0587 0588 Keys.onReturnPressed: { 0589 clicked() 0590 } 0591 0592 onClicked: { 0593 datePickerSheet.close() 0594 timeDisplayItemFour.forceActiveFocus() 0595 } 0596 } 0597 0598 Label { 0599 id: backbtnlabelDTHeading 0600 text: i18n("Press the [←] Back button to save configuration and return to settings") 0601 wrapMode: Text.WordWrap 0602 maximumLineCount: 2 0603 Layout.fillWidth: true 0604 Layout.alignment: Qt.AlignRight 0605 } 0606 } 0607 0608 Delegates.DatePicker { 0609 id: datePicker 0610 enabled: !ntpCheckBox.checked 0611 Layout.fillWidth: true 0612 Layout.fillHeight: true 0613 0614 Component.onCompleted: { 0615 var date = new Date(main.currentDate) 0616 datePicker.day = date.getDate() 0617 datePicker.month = date.getMonth()+1 0618 datePicker.year = date.getFullYear() 0619 } 0620 0621 onUserConfiguringChanged: { 0622 var date = new Date(main.currentDate) 0623 date.setDate(datePicker.day) 0624 date.setMonth(datePicker.month) 0625 date.setFullYear(datePicker.year) 0626 0627 kcm.setCurrentTime(date) 0628 kcm.setCurrentDate(date) 0629 kcm.saveTime() 0630 } 0631 0632 Keys.onReturnPressed: { 0633 datePickerSheet.close() 0634 timeDisplayItemFour.forceActiveFocus() 0635 } 0636 } 0637 } 0638 } 0639 }