From 0515a6d62902012a7eb152c19d289c235adf923c Mon Sep 17 00:00:00 2001 From: Joseph Donofry <rubberduckie3554@gmail.com> Date: Mon, 27 Dec 2021 22:49:40 -0500 Subject: [PATCH 1/6] Add scrolling to the completer and change max values from 7 to 70 --- resources/qml/Completer.qml | 10 +++++++++- src/CompletionProxyModel.h | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/resources/qml/Completer.qml b/resources/qml/Completer.qml index abaee3dff..b4061f8da 100644 --- a/resources/qml/Completer.qml +++ b/resources/qml/Completer.qml @@ -77,11 +77,19 @@ Popup { } padding: 1 onAboutToShow: currentIndex = -1 - height: listView.contentHeight + 2 // + 2 for the padding on top and bottom + // height: listView.contentHeight + 2 // + 2 for the padding on top and bottom + height: Math.min(listView.contentHeight + 2, 7*popup.avatarHeight + 2) ListView { id: listView + clip: true + ScrollHelper { + flickable: parent + anchors.fill: parent + enabled: !Settings.mobileMode + } + anchors.fill: parent implicitWidth: fullWidth ? parent.width : contentItem.childrenRect.width model: completer diff --git a/src/CompletionProxyModel.h b/src/CompletionProxyModel.h index 8a485aea9..5c34826b3 100644 --- a/src/CompletionProxyModel.h +++ b/src/CompletionProxyModel.h @@ -151,7 +151,7 @@ class CompletionProxyModel : public QAbstractProxyModel public: CompletionProxyModel(QAbstractItemModel *model, int max_mistakes = 2, - size_t max_completions = 7, + size_t max_completions = 70, QObject *parent = nullptr); void invalidate(); -- GitLab From add0e1e430b0d6275b125f9af739a643697c9aac Mon Sep 17 00:00:00 2001 From: Joseph Donofry <joedonofry@gmail.com> Date: Tue, 28 Dec 2021 18:48:42 -0500 Subject: [PATCH 2/6] Change completer limit to 30. Make up/down scroll listview --- resources/qml/Completer.qml | 3 ++- src/CompletionProxyModel.h | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/resources/qml/Completer.qml b/resources/qml/Completer.qml index b4061f8da..2fb083e8a 100644 --- a/resources/qml/Completer.qml +++ b/resources/qml/Completer.qml @@ -11,7 +11,7 @@ import im.nheko 1.0 Popup { id: popup - property int currentIndex: -1 + property alias currentIndex: listView.currentIndex property string completerName property var completer property bool bottomToTop: true @@ -96,6 +96,7 @@ Popup { verticalLayoutDirection: popup.bottomToTop ? ListView.BottomToTop : ListView.TopToBottom spacing: rowSpacing pixelAligned: true + highlightFollowsCurrentItem: true delegate: Rectangle { property variant modelData: model diff --git a/src/CompletionProxyModel.h b/src/CompletionProxyModel.h index 5c34826b3..a862176eb 100644 --- a/src/CompletionProxyModel.h +++ b/src/CompletionProxyModel.h @@ -151,7 +151,7 @@ class CompletionProxyModel : public QAbstractProxyModel public: CompletionProxyModel(QAbstractItemModel *model, int max_mistakes = 2, - size_t max_completions = 70, + size_t max_completions = 30, QObject *parent = nullptr); void invalidate(); -- GitLab From cc624098105cd9698ba00446ef059dc339e2e3a7 Mon Sep 17 00:00:00 2001 From: Joseph Donofry <rubberduckie3554@gmail.com> Date: Tue, 28 Dec 2021 20:16:43 -0500 Subject: [PATCH 3/6] Push some fixes for scrolling and item display --- resources/qml/Completer.qml | 51 ++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/resources/qml/Completer.qml b/resources/qml/Completer.qml index 2fb083e8a..7c3576298 100644 --- a/resources/qml/Completer.qml +++ b/resources/qml/Completer.qml @@ -3,9 +3,9 @@ // SPDX-License-Identifier: GPL-3.0-or-later import "./ui" -import QtQuick 2.9 -import QtQuick.Controls 2.3 -import QtQuick.Layouts 1.2 +import QtQuick 2.15 +import QtQuick.Controls 2.15 +import QtQuick.Layouts 1.15 import im.nheko 1.0 Popup { @@ -77,8 +77,12 @@ Popup { } padding: 1 onAboutToShow: currentIndex = -1 - // height: listView.contentHeight + 2 // + 2 for the padding on top and bottom - height: Math.min(listView.contentHeight + 2, 7*popup.avatarHeight + 2) + // If we have fewer than 7 items, just use the list view's content height. + // Otherwise, we want to show 7 items. Each item consists of row spacing between rows, row margins + // on each side of a row, 1px of padding above the first item and below the last item, and nominally + // some kind of content height. avatarHeight is used for just about every delegate, so we're using + // that until we find something better. Put is all together and you have the formula below! + height: Math.min(listView.contentHeight + 2, 6*rowSpacing + 7*(popup.avatarHeight + 2*rowMargin) + 2) ListView { id: listView @@ -90,6 +94,7 @@ Popup { enabled: !Settings.mobileMode } + reuseItems: true anchors.fill: parent implicitWidth: fullWidth ? parent.width : contentItem.childrenRect.width model: completer @@ -102,27 +107,24 @@ Popup { property variant modelData: model color: model.index == popup.currentIndex ? Nheko.colors.highlight : Nheko.colors.base - height: chooser.childrenRect.height + 2 * popup.rowMargin - implicitWidth: fullWidth ? popup.width : chooser.childrenRect.width + 4 - - MouseArea { - id: mouseArea - - anchors.fill: parent - hoverEnabled: true - onPositionChanged: popup.currentIndex = model.index - onClicked: { - popup.completionClicked(completer.completionAt(model.index)); - if (popup.completerName == "room") - popup.completionSelected(model.roomid); - - } - - Ripple { - rippleTarget: mouseArea - color: Qt.rgba(Nheko.colors.base.r, Nheko.colors.base.g, Nheko.colors.base.b, 0.5) + height: chooser.child.implicitHeight + 2 * popup.rowMargin + implicitWidth: fullWidth ? popup.contentWidth : chooser.child.implicitWidth + 4 + border.color: 'orange' + border.width: 1 + + HoverHandler { + id: hover + onHoveredChanged: { + if (hovered) popup.currentIndex = model.index; } + } + TapHandler { + onSingleTapped: { + popup.completionClicked(completer.completionAt(model.index)); + if (popup.completerName == "room") + popup.completionSelected(model.roomid); + } } DelegateChooser { @@ -131,6 +133,7 @@ Popup { roleValue: popup.completerName anchors.fill: parent anchors.margins: popup.rowMargin + enabled: false DelegateChoice { roleValue: "user" -- GitLab From 935cb9a5bacb4ab566d2c9273b3d03e1b2e0d8ab Mon Sep 17 00:00:00 2001 From: Joseph Donofry <rubberduckie3554@gmail.com> Date: Tue, 28 Dec 2021 20:19:34 -0500 Subject: [PATCH 4/6] Remove debug borders! --- resources/qml/Completer.qml | 2 -- 1 file changed, 2 deletions(-) diff --git a/resources/qml/Completer.qml b/resources/qml/Completer.qml index 7c3576298..8c2fba3f5 100644 --- a/resources/qml/Completer.qml +++ b/resources/qml/Completer.qml @@ -109,8 +109,6 @@ Popup { color: model.index == popup.currentIndex ? Nheko.colors.highlight : Nheko.colors.base height: chooser.child.implicitHeight + 2 * popup.rowMargin implicitWidth: fullWidth ? popup.contentWidth : chooser.child.implicitWidth + 4 - border.color: 'orange' - border.width: 1 HoverHandler { id: hover -- GitLab From 9f160fb52f799c6c0581c9d24967c086959fccb6 Mon Sep 17 00:00:00 2001 From: Joseph Donofry <rubberduckie3554@gmail.com> Date: Tue, 28 Dec 2021 20:32:55 -0500 Subject: [PATCH 5/6] Restore MouseArea --- resources/qml/Completer.qml | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/resources/qml/Completer.qml b/resources/qml/Completer.qml index 8c2fba3f5..2eb623994 100644 --- a/resources/qml/Completer.qml +++ b/resources/qml/Completer.qml @@ -110,20 +110,21 @@ Popup { height: chooser.child.implicitHeight + 2 * popup.rowMargin implicitWidth: fullWidth ? popup.contentWidth : chooser.child.implicitWidth + 4 - HoverHandler { - id: hover - onHoveredChanged: { - if (hovered) popup.currentIndex = model.index; - } - } + MouseArea { + id: mouseArea - TapHandler { - onSingleTapped: { + anchors.fill: parent + hoverEnabled: true + onPositionChanged: popup.currentIndex = model.index + onClicked: { popup.completionClicked(completer.completionAt(model.index)); if (popup.completerName == "room") popup.completionSelected(model.roomid); + } + Ripple { + rippleTarget: mouseArea + color: Qt.rgba(Nheko.colors.base.r, Nheko.colors.base.g, Nheko.colors.base.b, 0.5) } - } DelegateChooser { id: chooser -- GitLab From d35bbb351b1b86a8b24fa5b707304249ac6ca98b Mon Sep 17 00:00:00 2001 From: Joseph Donofry <rubberduckie3554@gmail.com> Date: Tue, 28 Dec 2021 21:12:58 -0500 Subject: [PATCH 6/6] Add timer for scrolling to avoid mouse movement conflicts --- resources/qml/Completer.qml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/resources/qml/Completer.qml b/resources/qml/Completer.qml index 2eb623994..5d3187577 100644 --- a/resources/qml/Completer.qml +++ b/resources/qml/Completer.qml @@ -94,6 +94,13 @@ Popup { enabled: !Settings.mobileMode } + Timer { + id: deadTimer + interval: 50 + } + + onContentYChanged: deadTimer.restart() + reuseItems: true anchors.fill: parent implicitWidth: fullWidth ? parent.width : contentItem.childrenRect.width @@ -115,7 +122,7 @@ Popup { anchors.fill: parent hoverEnabled: true - onPositionChanged: popup.currentIndex = model.index + onPositionChanged: if (!listView.moving && !deadTimer.running) popup.currentIndex = model.index onClicked: { popup.completionClicked(completer.completionAt(model.index)); if (popup.completerName == "room") @@ -125,6 +132,7 @@ Popup { rippleTarget: mouseArea color: Qt.rgba(Nheko.colors.base.r, Nheko.colors.base.g, Nheko.colors.base.b, 0.5) } + } DelegateChooser { id: chooser -- GitLab