diff --git a/kcms/dateandtime/package/contents/ui/DateInput.qml b/kcms/dateandtime/package/contents/ui/DateInput.qml new file mode 100644 index 000000000..3f6ae309f --- /dev/null +++ b/kcms/dateandtime/package/contents/ui/DateInput.qml @@ -0,0 +1,125 @@ +import QtQuick 2.3 +import QtQuick.Layouts 1.2 +import QtQuick.Controls 2.3 + +import org.kde.kirigami 2.4 as Kirigami + +/** + * This Item provides an entry box for inputting a date. + * It is represented in a form suitable for entering a known date (i.e date of birth, current date) + * rather than date selection where a user might want a grid view. + */ +RowLayout { + id: layout + + //DAVE - if I'm in an RTL country are my date formats pre-reversed? + //i.e Wikipedia says afghan is d/m/yyyy should year go on the left or the right? + + property date value + + property string dateFormat: Qt.locale().dateFormat(Locale.ShortFormat) + + //date formats can be in big endian (china), little endian (Europe), or absolutely mental endian + //separators are also different + Component.onCompleted: { + value = new Date(); + + //dave, some idiot could have added children externally, maybe would be safer to make RowLayout internal? + for (var i in layout.children) { + layout.children[i].destroy(); + } + + var tabletMode = Kirigami.Settings.tabletMode + + var parse = /([^dMy]*)([dMy]+)([^dMy]*)([dMy]+)([^dMy]*)([dMy]+)([^dMy]*)/ + var parts = parse.exec(dateFormat); + for(var i=1; i < parts.length; i++) { + var part = parts[i]; + + if (!part) { + continue; + } + + if (part.startsWith("d")) { + if (tabletMode) { + daySelectTouchComponent.createObject(layout); + } else { + daySelectComponent.createObject(layout); + } + } + else if (part.startsWith("M")) { + if (tabletMode) { + monthSelectTouchComponent.createObject(layout); + } else { + monthSelectComponent.createObject(layout); + } } + else if (part.startsWith("y")) { + if (tabletMode) { + yearSelectTouchComponent.createObject(layout); + } else { + yearSelectComponent.createObject(layout); + } } + else { + labelComponent.createObject(layout, {"text": part}) + } + } + } + + Component { + id: daySelectComponent + SpinBox { + from: 1 + to: 31 + editable: true + value: layout.value.getDay(); + onValueModified: layout.value.setDay(value); + } + } + Component { + id: daySelectTouchComponent + Tumbler { + model: 31 + } + //Tumbler doesn't have a separate user modified signal...booooooo!!!!! + } + + Component { + id: monthSelectComponent + SpinBox { + from: 1 + to: 12 + editable: true + value: layout.value.getMonth(); + onValueModified: layout.value.setMonth(value); + } + } + Component { + id: monthSelectTouchComponent + Tumbler { + model: 12 + } + } + Component { + id: yearSelectComponent + SpinBox { + from: 1970 + to: 2100 //I assume we'll have a new LTS release by then + editable: true + textFromValue: function(value) {return value} //default implementation does toLocaleString which looks super weird + value: layout.value.getYear(); + onValueModified: layout.value.setYear(value); + } + } + Component { + id: yearSelectTouchComponent + Tumbler { + model: 12 + } + } + + Component { + id: labelComponent + Label { + } + } +} diff --git a/kcms/dateandtime/package/contents/ui/TimezoneTable.qml b/kcms/dateandtime/package/contents/ui/TimezoneTable.qml new file mode 100644 index 000000000..a5c62e978 --- /dev/null +++ b/kcms/dateandtime/package/contents/ui/TimezoneTable.qml @@ -0,0 +1,55 @@ +import QtQuick 2.0 +import QtQuick.Controls 1.2 as QtControls +import QtQuick.Layouts 1.0 +import QtQuick.Dialogs 1.1 + +import org.kde.plasma.private.digitalclock 1.0 + +ColumnLayout { + QtControls.TextField { + id: filter + Layout.fillWidth: true + placeholderText: i18n("Search Time Zones") + } + + QtControls.TableView { + id: timeZoneView + + signal toggleCurrent + + Layout.fillWidth: true + Layout.fillHeight: true + + Keys.onSpacePressed: toggleCurrent() + + TimeZoneModel { + id: timeZones + + onSelectedTimeZonesChanged: { + if (selectedTimeZones.length == 0) { + messageWidget.visible = true; + + timeZones.selectLocalTimeZone(); + } + } + } + + model: TimeZoneFilterProxy { + sourceModel: timeZones + filterString: filter.text + } + + QtControls.TableViewColumn { + role: "city" + title: i18n("City") + } + QtControls.TableViewColumn { + role: "region" + title: i18n("Region") + } + QtControls.TableViewColumn { + role: "comment" + title: i18n("Comment") + } + } +} diff --git a/kcms/dateandtime/package/contents/ui/main.qml b/kcms/dateandtime/package/contents/ui/main.qml index 37866650a..f76cbe4e0 100644 --- a/kcms/dateandtime/package/contents/ui/main.qml +++ b/kcms/dateandtime/package/contents/ui/main.qml @@ -1,151 +1,131 @@ /* * Copyright (C) 2015 Marco Martin * Copyright (C) 2018 Eike Hein * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ import QtQuick 2.1 import QtQuick.Layouts 1.1 import QtQuick.Controls 1.4 as QtControls1 import QtQuick.Controls 2.3 as QtControls import org.kde.kirigami 2.4 as Kirigami import org.kde.kcm 1.2 Kirigami.Page { id: root implicitWidth: 500 implicitHeight: 500 Kirigami.OverlaySheet { id: addLanguagesSheet parent: root header: Kirigami.Heading { text: i18nc("@title:window", "Select time")} RowLayout { - - QtControls.SpinBox { - value: 2 - } - QtControls.Label {text:"/"} - - QtControls.SpinBox { - value: 0 - textFromValue: function() {return "March"} - } - QtControls.Label {text:"/"} - QtControls.SpinBox { - value: 2017 - } - - QtControls.Label {text: " "} - - QtControls.SpinBox {} - QtControls.Label {text:":"} - QtControls.SpinBox {} - + DateInput {} } } ColumnLayout { anchors.fill: parent QtControls.CheckBox { id: useNtp checked: true text: "Set date and time automatically" } // RowLayout { // QtControls1.Calendar { // } // Item { // Layout.fillWidth: true // } // ColumnLayout { // ClockFace { // implicitWidth: 200 // implicitHeight: 200 // } // //spin box with textFromValue + valueFromText nearly works, but // //the lack of input mask means that the user has to put ":" in the right place and the cursor isn't very good // //maybe 3 tumblers would be better? Maybe switch on context? or when you touch the clock face? // QtControls.TextField { // //time represented as seconds after midnight. No date // property int value // Layout.alignment: Qt.AlignHCenter // inputMethodHints: Qt.ImredhTime // enabled: !useNtp.checked // function formatTime(time) { // var hours = 13; // var minutes = 3 // var seconds = 2; // var text; // if (hours < 10) // text += "0"; // text += hours; // text += ":"; // if (minutes < 10) // text += "0" // text += minutes; // text += ":"; // if (seconds < 10) // text += "0"; // text += seconds; // return text; // } // onValueChanged: { // text = formatTime(text) // } // text: "10:04:03" // inputMask: "09:09:09" //optional digit + mandatory digit * 3 // } // } // } TimezoneTable { Layout.fillHeight: true } RowLayout { QtControls.Label { font.bold: true text: "14th April 2017 14:34" Layout.fillWidth: true } QtControls.Button { text: i18n("Set") onClicked: addLanguagesSheet.sheetOpen = !addLanguagesSheet.sheetOpen } } } }