Commit 1a23c057 authored by Volker Krause's avatar Volker Krause
Browse files

Remove old date/time input controls

Those were copied from an ancient kirigami-addons version, use the current
ones instead.
parent 7e58952c
// 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.17 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 {
}
}
}
......@@ -4,55 +4,56 @@
SPDX-License-Identifier: LGPL-2.0-or-later
*/
import QtQuick 2.7
import QtQuick.Layouts 1.1
import QtQuick.Controls 2.1 as QQC2
import QtQuick 2.15
import QtQuick.Layouts 1.15
import QtQuick.Controls 2.15 as QQC2
import org.kde.kirigami 2.17 as Kirigami
import org.kde.itinerary.kirigamiaddons.dateandtime 0.1 as Addon
import org.kde.kitinerary 1.0
import org.kde.itinerary 1.0
import "." as App
MouseArea {
RowLayout {
id: root
property variant obj
property string propertyName
property date value: Util.dateTimeStripTimezone(obj, propertyName)
readonly property bool hasValue: !isNaN(value.getTime())
property bool isModified: Util.dateTimeStripTimezone(obj, propertyName).getTime() != value.getTime()
implicitHeight: layout.implicitHeight
implicitWidth: layout.implicitWidth
RowLayout {
id: layout
QQC2.Label {
text: isModified ? value.toLocaleString(Qt.locale(), Locale.ShortFormat) : Localizer.formatDateTime(obj, propertyName)
}
Kirigami.Icon {
source: "document-edit"
width: Kirigami.Units.iconSizes.smallMedium
height: width
Addon.DateInput {
id: dateInput
selectedDate: root.value
onSelectedDateChanged: root.updateValue()
visible: root.hasValue
}
Addon.TimeInput {
id: timeInput
value: root.value
onValueChanged: root.updateValue()
visible: root.hasValue
}
QQC2.ToolButton {
icon.name: "document-edit"
visible: !root.hasValue
onClicked: {
dateInput.item.selectedDate = new Date();
timeInput.value = new Date();
}
}
// FIXME super ugly, we reference stuff from our parent here
onClicked: {
dateTimeEditSheet.value = isNaN(root.value.getTime()) ? new Date() : root.value;
dateTimeEditSheet.sheetOpen = true;
conn.enabled = true;
Connections {
target: dateInput
onSelectedDateChanged: root.updateValue()
}
Connections {
id: conn
enabled: false
target: dateTimeEditSheet
onSheetOpenChanged: {
console.log(root.value, dateTimeEditSheet.value);
root.value = dateTimeEditSheet.value;
root.value.setSeconds(0, 0);
enabled = false;
}
function updateValue() {
const MSECS_PER_DAY = 24 * 60 * 60 * 1000;
let dt = new Date();
dt.setTime(dateInput.selectedDate.getTime() - (dateInput.selectedDate.getTime() % MSECS_PER_DAY) + (timeInput.value.getTime() % MSECS_PER_DAY));
dt.setSeconds(0, 0);
console.log(dt, dateInput.selectedDate, timeInput.value);
root.value = dt;
}
}
......@@ -19,8 +19,6 @@ Kirigami.ScrollablePage {
property var resIds: ReservationManager.reservationsForBatch(root.batchId)
readonly property var reservation: ReservationManager.reservation(root.batchId);
property alias dateTimeEditSheet: _dateTimeEditSheet
/** Returns the country we are assumed to be in at the given time. */
function countryAtTime(dt) {
const place = TimelineModel.locationAtTime(dt);
......@@ -39,38 +37,4 @@ Kirigami.ScrollablePage {
}
}
}
Kirigami.OverlaySheet {
id: _dateTimeEditSheet
property date value
parent: root
header: Kirigami.Heading { text: i18nc("@title:window", "Edit date/time") }
ColumnLayout {
App.DateInput {
id: dateInput
value: _dateTimeEditSheet.value
}
App.TimeInput {
id: timeInput
value: _dateTimeEditSheet.value
}
QQC2.Button {
Layout.alignment: Qt.AlignHCenter
text: i18n("Ok")
onClicked: {
var dt = new Date();
dt.setFullYear(dateInput.value.getFullYear());
dt.setMonth(dateInput.value.getMonth());
dt.setDate(dateInput.value.getDate());
dt.setHours(timeInput.value.getHours());
dt.setMinutes(timeInput.value.getMinutes(), 0, 0);
_dateTimeEditSheet.value = dt;
_dateTimeEditSheet.sheetOpen = false;
}
}
}
}
}
/*
SPDX-FileCopyrightText: 2018 Volker Krause <vkrause@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
import QtQuick 2.3
import QtQuick.Layouts 1.2
import QtQuick.Controls 2.3
import org.kde.kirigami 2.17 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;
}
}
}
......@@ -19,7 +19,6 @@
<file>CarRentalDelegate.qml</file>
<file>CarRentalPage.qml</file>
<file>CountryComboBox.qml</file>
<file>DateInput.qml</file>
<file>DateTimeEdit.qml</file>
<file>DepartureQueryPage.qml</file>
<file>DetailsPage.qml</file>
......@@ -76,7 +75,6 @@
<file>StopPickerPage.qml</file>
<file>TicketPage.qml</file>
<file>TicketTokenDelegate.qml</file>
<file>TimeInput.qml</file>
<file>TimelineDelegate.qml</file>
<file>TimelinePage.qml</file>
<file>TimelineSectionDelegate.qml</file>
......
Supports Markdown
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