From c40381a3ca0cfeb0b42e42970c5c5c733322a82b Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Thu, 21 Oct 2021 17:34:11 +0200 Subject: [PATCH 1/2] Time pickers now respond to mouse scroll, making them more intuitive to use on desktop --- src/contents/ui/TimeCombo.qml | 7 ++++--- src/contents/ui/TimePicker.qml | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/contents/ui/TimeCombo.qml b/src/contents/ui/TimeCombo.qml index 0c731791..880e25ae 100644 --- a/src/contents/ui/TimeCombo.qml +++ b/src/contents/ui/TimeCombo.qml @@ -33,7 +33,7 @@ QQC2.ComboBox { property alias timePicker: popupTimePicker editable: true - editText: activeFocus ? editText : DateUtils.adjustDateTimeToLocalTimeZone(dateTime, timeZoneOffset).toLocaleTimeString(Qt.locale(), "HH:mm") + editText: activeFocus && !popupTimePicker.visible ? editText : DateUtils.adjustDateTimeToLocalTimeZone(dateTime, timeZoneOffset).toLocaleTimeString(Qt.locale(), "HH:mm") inputMethodHints: Qt.ImhTime validator: activeFocus ? inputValidator : timeValidator @@ -42,7 +42,7 @@ QQC2.ComboBox { if(!isNaN(dateTime.getTime())) { popupTimePicker.setToTimeFromString(editText) } - if (acceptableInput && activeFocus) { // Need to check for activeFocus or on load the text gets reset to 00:00 + if (acceptableInput && activeFocus && !popupTimePicker.visible) { // Need to check for activeFocus or on load the text gets reset to 00:00 newTimeChosen(new Date(DateUtils.adjustDateTimeToLocalTimeZone(dateTime, timeZoneOffset).setHours(popupTimePicker.hours, popupTimePicker.minutes))); } } @@ -61,7 +61,8 @@ QQC2.ComboBox { Connections { target: root function onDateTimeChanged() { - popupTimePicker.setToTimeFromString(root.editText); + if(!popupTimePicker.visible) + popupTimePicker.setToTimeFromString(root.editText); } } diff --git a/src/contents/ui/TimePicker.qml b/src/contents/ui/TimePicker.qml index 4d91b24d..91b7092f 100644 --- a/src/contents/ui/TimePicker.qml +++ b/src/contents/ui/TimePicker.qml @@ -126,6 +126,11 @@ Item { opacity: hourView.currentIndex == thisIndex ? 1 : 0.7 text: modelData < 10 ? String(modelData).padStart(2, "0") : modelData } + + MouseArea { + anchors.fill: parent + onWheel: wheel.angleDelta.y < 0 ? hourView.currentIndex += 1 : hourView.currentIndex -= 1; + } } Kirigami.Heading { @@ -162,6 +167,11 @@ Item { opacity: minuteView.currentIndex == thisIndex ? 1 : 0.7 text: minuteToDisplay < 10 ? String(minuteToDisplay).padStart(2, "0") : minuteToDisplay } + + MouseArea { + anchors.fill: parent + onWheel: wheel.angleDelta.y < 0 ? minuteView.currentIndex += 1 : minuteView.currentIndex -= 1; + } } @@ -195,6 +205,11 @@ Item { opacity: secondsView.currentIndex == thisIndex ? 1 : 0.7 text: modelData < 10 ? String(modelData).padStart(2, "0") : modelData } + + MouseArea { + anchors.fill: parent + onWheel: wheel.angleDelta.y < 0 ? secondsView.currentIndex += 1 : secondsView.currentIndex -= 1; + } } QQC2.ToolButton { -- GitLab From 1a862f9e96d97f36e7e66e3616d166463e5e7b24 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Thu, 21 Oct 2021 18:09:35 +0200 Subject: [PATCH 2/2] Scrolling with wheel now wraps too --- src/contents/ui/TimeCombo.qml | 2 +- src/contents/ui/TimePicker.qml | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/contents/ui/TimeCombo.qml b/src/contents/ui/TimeCombo.qml index 880e25ae..9995d62d 100644 --- a/src/contents/ui/TimeCombo.qml +++ b/src/contents/ui/TimeCombo.qml @@ -50,7 +50,7 @@ QQC2.ComboBox { popup: QQC2.Popup { id: timePopup width: parent.width - height: parent.width * 2 + height: parent.width * 1.5 y: parent.y + parent.height z: 1000 diff --git a/src/contents/ui/TimePicker.qml b/src/contents/ui/TimePicker.qml index 91b7092f..f1492933 100644 --- a/src/contents/ui/TimePicker.qml +++ b/src/contents/ui/TimePicker.qml @@ -59,6 +59,16 @@ Item { } } + function wheelHandler(parent, wheel) { + if(parent.currentIndex == parent.count - 1) { + wheel.angleDelta.y < 0 ? parent.currentIndex = 0 : parent.currentIndex -= 1; + } else if(parent.currentIndex == 0) { + wheel.angleDelta.y < 0 ? parent.currentIndex += 1 : parent.currentIndex = parent.count - 1; + } else { + wheel.angleDelta.y < 0 ? parent.currentIndex += 1 : parent.currentIndex -= 1; + } + } + GridLayout { anchors.fill: parent columns: timePicker.secondsPicker ? 5 : 3 @@ -111,8 +121,10 @@ Item { QQC2.Tumbler { id: hourView Layout.fillWidth: true + Layout.fillHeight: true Layout.row: 2 Layout.column: 0 + wrap: true model: 24 @@ -129,7 +141,7 @@ Item { MouseArea { anchors.fill: parent - onWheel: wheel.angleDelta.y < 0 ? hourView.currentIndex += 1 : hourView.currentIndex -= 1; + onWheel: timePicker.wheelHandler(parent, wheel) } } @@ -144,6 +156,7 @@ Item { QQC2.Tumbler { id: minuteView Layout.fillWidth: true + Layout.fillHeight: true wrap: true property int selectedIndex: 0 @@ -170,7 +183,7 @@ Item { MouseArea { anchors.fill: parent - onWheel: wheel.angleDelta.y < 0 ? minuteView.currentIndex += 1 : minuteView.currentIndex -= 1; + onWheel: timePicker.wheelHandler(parent, wheel) } } @@ -208,7 +221,7 @@ Item { MouseArea { anchors.fill: parent - onWheel: wheel.angleDelta.y < 0 ? secondsView.currentIndex += 1 : secondsView.currentIndex -= 1; + onWheel: timePicker.wheelHandler(parent, wheel) } } -- GitLab