Commit 78a699bb authored by Volker Krause's avatar Volker Krause

Add temporary date/time input controls

This is not pretty (to say the least), but it unblocks working on the
adding/editing code.

David is working on proper controls for this that will hopefully end up
in Kirigami eventually.
parent e0127ff5
// David Edmundson's DateInput (with some "fixes"), presumably LGPLv2, copied here until it's in Kirigami
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 choosing dates where a gridview might work better
*/
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.getDate();
onValueChanged: {
if (isNaN(layout.value.getTime()))
return;
var dt = layout.value;
dt.setDate(value);
layout.value = dt;
}
}
}
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() + 1;
onValueChanged: {
if (isNaN(layout.value.getTime()))
return;
var dt = layout.value;
dt.setMonth(value - 1);
layout.value = dt;
}
}
}
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.getFullYear();
onValueChanged: {
if (isNaN(layout.value.getTime()))
return;
var dt = layout.value;
dt.setFullYear(value);
layout.value = dt;
}
}
}
Component {
id: yearSelectTouchComponent
Tumbler {
model: 12
}
}
Component {
id: labelComponent
Label {
}
}
}
/*
Copyright (C) 2018 Volker Krause <vkrause@kde.org>
This program 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 program 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 General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import QtQuick 2.3
import QtQuick.Layouts 1.2
import QtQuick.Controls 2.3
import org.kde.kirigami 2.4 as Kirigami
// temporary time input until we have that in Kirigami and David's prototype in
// plasma-desktop depends on Plasma which we don't have on Android
RowLayout {
id: layout
property date value
SpinBox {
from: 0
to: 23
editable: true
wrap: true
value: layout.value.getHours()
onValueChanged: {
if (isNaN(layout.value.getTime()))
return;
var dt = layout.value;
dt.setHours(value);
layout.value = dt;
}
}
Label { text: ':' }
SpinBox {
from: 0
to: 59
editable: true
wrap: true
value: layout.value.getMinutes()
onValueChanged: {
if (isNaN(layout.value.getTime()))
return;
var dt = layout.value;
dt.setMinutes(value);
layout.value = dt;
}
}
}
......@@ -8,6 +8,7 @@
<file>BusDelegate.qml</file>
<file>BusPage.qml</file>
<file>CountryInfoDelegate.qml</file>
<file>DateInput.qml</file>
<file>DetailsPage.qml</file>
<file>EditorPage.qml</file>
<file>FlightDelegate.qml</file>
......@@ -24,6 +25,7 @@
<file>RestaurantPage.qml</file>
<file>SettingsPage.qml</file>
<file>TicketTokenDelegate.qml</file>
<file>TimeInput.qml</file>
<file>TimelineDelegate.qml</file>
<file>TimelinePage.qml</file>
<file>TouristAttractionDelegate.qml</file>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment