Eliminate wrapper SpinBox for expire date field
authorClaudio Cambra <claudio.cambra@nextcloud.com>
Mon, 7 Aug 2023 08:47:58 +0000 (16:47 +0800)
committerbackportbot-nextcloud[bot] <backportbot-nextcloud[bot]@users.noreply.github.com>
Wed, 13 Sep 2023 08:47:53 +0000 (08:47 +0000)
Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
src/gui/filedetails/ShareDetailsPage.qml

index 527f48de8402e3ff8ac2d8a66a38aa1372874709..09c3855d12ea147482da64cea64740d66f8e5010 100644 (file)
@@ -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 ||