From: Claudio Cambra Date: Mon, 7 Aug 2023 08:47:58 +0000 (+0800) Subject: Eliminate wrapper SpinBox for expire date field X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~92^2^2~7^2~25 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=7b8fb44d9a0339baf045b1de17ebb39f76fbac41;p=nextcloud-desktop.git Eliminate wrapper SpinBox for expire date field Signed-off-by: Claudio Cambra --- diff --git a/src/gui/filedetails/ShareDetailsPage.qml b/src/gui/filedetails/ShareDetailsPage.qml index 527f48de8..09c3855d1 100644 --- a/src/gui/filedetails/ShareDetailsPage.qml +++ b/src/gui/filedetails/ShareDetailsPage.qml @@ -734,11 +734,11 @@ Page { // QML dates are essentially JavaScript dates, which makes them very finicky and unreliable. // Instead, we exclusively deal with msecs from epoch time to make things less painful when editing. // We only use the QML Date when showing the nice string to the user. - SpinBox { - id: expireDateSpinBox + NCInputTextField { + id: expireDateField function updateText() { - expireDateSpinBoxTextField.text = textFromValue(value, locale); + text = textFromValue(value, locale); } // Work arounds the limitations of QML's 32 bit integer when handling msecs from epoch @@ -765,6 +765,10 @@ Page { return Math.floor(minDateUTC / dayInMSecs) // Start of day at 00:00:0000 UTC } + readonly property var from: minimumExpireDateReduced + readonly property var to: maximumExpireDateReduced + property var value: expireDateReduced + // Taken from Kalendar 22.08 // https://invent.kde.org/pim/kalendar/-/blob/release/22.08/src/contents/ui/KalendarUtils/dateutils.js function parseDateString(dateString) { @@ -820,63 +824,39 @@ Page { return new Date(Date.UTC(fixedYearNum, monthIndexNum, dayNum)); } - Layout.fillWidth: true - height: visible ? implicitHeight : 0 - - // We want all the internal benefits of the spinbox but don't actually want the - // buttons, so set an empty item as a dummy - up.indicator: Item {} - down.indicator: Item {} - - padding: 0 - background: null - contentItem: NCInputTextField { - id: expireDateSpinBoxTextField - - validInput: { - const value = expireDateSpinBox.valueFromText(text); - return value >= expireDateSpinBox.from && value <= expireDateSpinBox.to; - } - - text: expireDateSpinBox.textFromValue(expireDateSpinBox.value, expireDateSpinBox.locale) - readOnly: !expireDateSpinBox.editable - validator: expireDateSpinBox.validator - inputMethodHints: Qt.ImhFormattedNumbersOnly - onAccepted: { - expireDateSpinBox.value = expireDateSpinBox.valueFromText(text, expireDateSpinBox.locale); - expireDateSpinBox.valueModified(); - } - } - - value: expireDateReduced - from: minimumExpireDateReduced - to: maximumExpireDateReduced - - textFromValue: (value, locale) => { + function textFromValue(value, locale) { const dateFromValue = new Date(value * dayInMSecs); return dateFromValue.toLocaleDateString(Qt.locale(), Locale.NarrowFormat); } - valueFromText: (text, locale) => { + + function valueFromText(text, locale) { const dateFromText = parseDateString(text); return Math.floor(dateFromText.getTime() / dayInMSecs); } - editable: true - inputMethodHints: Qt.ImhDate | Qt.ImhFormattedNumbersOnly + Layout.fillWidth: true + height: visible ? implicitHeight : 0 - enabled: root.expireDateEnabled && - !root.waitingForExpireDateChange && - !root.waitingForExpireDateEnabledChange + validInput: { + const value = valueFromText(text); + return value >= from && value <= to; + } - onValueModified: { - if (!enabled || !activeFocus) { - return; - } + text: textFromValue(expireDateSpinBox.value, expireDateSpinBox.locale) + inputMethodHints: expireDateSpinBox.inputMethodHints + onAccepted: { + const value = valueFromText(text, expireDateSpinBox.locale); root.setExpireDate(value * dayInMSecs); root.waitingForExpireDateChange = true; } + inputMethodHints: Qt.ImhDate + + enabled: root.expireDateEnabled && + !root.waitingForExpireDateChange && + !root.waitingForExpireDateEnabledChange + NCBusyIndicator { anchors.fill: parent visible: root.waitingForExpireDateEnabledChange ||