From 96348408b0384a6835302524f00f0a6a238cde07 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Sat, 19 Aug 2017 10:10:35 -0600 Subject: Fixed mouse interaction with mail content Previously mouse interaction was blocked by the mouse area in the delegate. An additional problem was after that, that the listview lost focus when the textview got focus which was fixed by introducing a focus scope and aquiring the currentItem status via activeFocus. The downside is that the focus stealing of the webengineview now becomes apparent again, but that can be fixed in qt 5.9. Otherwise this seems to work as expected now. --- framework/qml/ConversationListView.qml | 130 +++++++++++++++++---------------- framework/qml/ConversationView.qml | 14 ++-- 2 files changed, 75 insertions(+), 69 deletions(-) (limited to 'framework') diff --git a/framework/qml/ConversationListView.qml b/framework/qml/ConversationListView.qml index fb91e14d..b00002b1 100644 --- a/framework/qml/ConversationListView.qml +++ b/framework/qml/ConversationListView.qml @@ -24,11 +24,11 @@ import org.kube.framework 1.0 as Kube import QtQml 2.2 as QtQml -Flickable { +FocusScope { id: root - focus: true property alias model: repeater.model property alias delegate: repeater.delegate + property alias contentHeight: flickable.contentHeight property int currentIndex: -1 property var currentItem: null @@ -56,83 +56,87 @@ Flickable { setCurrentItem() } - //Optimize for view quality - pixelAligned: true - - contentWidth: width - contentHeight: col.height + Flickable { + id: flickable + anchors.fill: parent - function scrollToIndex(index) { - var item = repeater.itemAt(index) - var pos = item.y - var scrollToEndPos = (root.contentHeight - root.height) - //Avoid scrolling past the end - if (pos < scrollToEndPos) { - root.contentY = pos - } else { - root.contentY = scrollToEndPos + //Optimize for view quality + pixelAligned: true + + contentWidth: width + contentHeight: col.height + + function scrollToIndex(index) { + var item = repeater.itemAt(index) + var pos = item.y + var scrollToEndPos = (flickable.contentHeight - flickable.height) + //Avoid scrolling past the end + if (pos < scrollToEndPos) { + flickable.contentY = pos + } else { + flickable.contentY = scrollToEndPos + } } - } - onContentHeightChanged: { - if (repeater.count) { - //Scroll to the last item - currentIndex = repeater.count - 1 - scrollToIndex(repeater.count - 1) + onContentHeightChanged: { + if (repeater.count) { + //Scroll to the last item + currentIndex = repeater.count - 1 + scrollToIndex(repeater.count - 1) + } } - } - property real span : contentY + height - Column { - id: col - width: parent.width - spacing: 2 - Repeater { - id: repeater - onCountChanged: { - for (var i = 0; i < count; i++) { - itemAt(i).index = i + Column { + id: col + width: parent.width + spacing: 2 + Repeater { + id: repeater + onCountChanged: { + for (var i = 0; i < count; i++) { + itemAt(i).index = i + } } } } - } - function incrementCurrentIndex() { - if (currentIndex < repeater.count - 1) { - currentIndex = currentIndex + 1 + function incrementCurrentIndex() { + if (currentIndex < repeater.count - 1) { + currentIndex = currentIndex + 1 + } } - } - function decrementCurrentIndex() { - if (currentIndex > 0) { - currentIndex = currentIndex - 1 + function decrementCurrentIndex() { + if (currentIndex > 0) { + currentIndex = currentIndex - 1 + } } - } - Keys.onDownPressed: { - incrementCurrentIndex() - scrollToIndex(currentIndex) - } + Keys.onDownPressed: { + incrementCurrentIndex() + scrollToIndex(currentIndex) + } - Keys.onUpPressed: { - decrementCurrentIndex() - scrollToIndex(currentIndex) - } + Keys.onUpPressed: { + decrementCurrentIndex() + scrollToIndex(currentIndex) + } - Kube.ScrollHelper { - id: scrollHelper - flickable: root - anchors.fill: parent - } + Kube.ScrollHelper { + id: scrollHelper + flickable: flickable + anchors.fill: parent + } - //Intercept all scroll events, - //necessary due to the webengineview - Kube.MouseProxy { - anchors.fill: parent - target: scrollHelper - forwardWheelEvents: true - } + //Intercept all scroll events, + //necessary due to the webengineview + Kube.MouseProxy { + anchors.fill: parent + target: scrollHelper + forwardWheelEvents: true + } - ScrollBar.vertical: ScrollBar {} + ScrollBar.vertical: ScrollBar {} + } } diff --git a/framework/qml/ConversationView.qml b/framework/qml/ConversationView.qml index 92b2a0c1..9eab9afa 100644 --- a/framework/qml/ConversationView.qml +++ b/framework/qml/ConversationView.qml @@ -74,8 +74,13 @@ FocusScope { property bool isCurrentItem: false property int index: -1 - focus: false + focus: true activeFocusOnTab: false + onActiveFocusChanged: { + if (activeFocus) { + listView.currentIndex = delegateRoot.index + } + } height: sheet.height + Kube.Units.gridUnit width: listView.width @@ -83,12 +88,9 @@ FocusScope { MouseArea { anchors.fill: parent + acceptedButtons: Qt.NoButton hoverEnabled: true - onEntered: listView.currentIndex = delegateRoot.index - onClicked: { - listView.currentIndex = delegateRoot.index - listView.forceActiveFocus(Qt.MouseFocusReason) - } + onEntered: delegateRoot.forceActiveFocus(Qt.MouseFocusReason) } MailViewer { -- cgit v1.2.3