From c7d0845fb34d7ccea3b754c6bc9cbbc391bfa12d Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Wed, 12 Jul 2017 03:56:53 +0200 Subject: A listview with sane scrolling --- framework/qml/ConversationView.qml | 8 ++---- framework/qml/ListView.qml | 51 ++++++++++++++++++++++++++++++++++++++ framework/qmldir | 1 + 3 files changed, 54 insertions(+), 6 deletions(-) create mode 100644 framework/qml/ListView.qml (limited to 'framework') diff --git a/framework/qml/ConversationView.qml b/framework/qml/ConversationView.qml index 2f499752..9c21b470 100644 --- a/framework/qml/ConversationView.qml +++ b/framework/qml/ConversationView.qml @@ -1,5 +1,6 @@ /* * Copyright (C) 2016 Michael Bohlender, + * Copyright (C) 2017 Christian Mollekopf, * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -59,7 +60,7 @@ Rectangle { color: Kube.Colors.backgroundColor - ListView { + Kube.ListView { id: listView anchors.fill: parent @@ -110,11 +111,6 @@ Rectangle { //Setting the currentIndex results in further lags. So we don't do that either. // currentIndex: root.currentIndex - boundsBehavior: Flickable.StopAtBounds - - //default is 1500, which is not usable with a mouse - flickDeceleration: 1500 - //Optimize for view quality pixelAligned: true diff --git a/framework/qml/ListView.qml b/framework/qml/ListView.qml new file mode 100644 index 00000000..7fbb5721 --- /dev/null +++ b/framework/qml/ListView.qml @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2016 Michael Bohlender, + * Copyright (C) 2017 Christian Mollekopf, + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +import QtQuick 2.7 +import QtQuick.Controls 2 + +ListView { + id: root + property var focusProxy: root + + /* + * The MouseArea + interactive: false + maximumFlickVelocity are required + * to fix scrolling for desktop systems where we don't want flicking behaviour. + * + * See also: + * ScrollView.qml in qtquickcontrols + * qquickwheelarea.cpp in qtquickcontrols + */ + MouseArea { + anchors.fill: root + propagateComposedEvents: true + + onWheel: { + //Some trackpads (mine) emit 0 events in between that we can safely ignore. + if (wheel.angleDelta.y) { + listView.flick(0, wheel.angleDelta.y * 40) + } + } + } + interactive: false + maximumFlickVelocity: 100000 + + boundsBehavior: Flickable.StopAtBounds +} + diff --git a/framework/qmldir b/framework/qmldir index 0e7768c4..b8e7345f 100644 --- a/framework/qmldir +++ b/framework/qmldir @@ -29,6 +29,7 @@ Heading 1.0 Heading.qml View 1.0 View.qml AutocompleteLineEdit 1.0 AutocompleteLineEdit.qml AttachmentDelegate 1.0 AttachmentDelegate.qml +ListView 1.0 ListView.qml singleton Messages 1.0 Messages.qml singleton Colors 1.0 Colors.qml singleton Icons 1.0 Icons.qml -- cgit v1.2.3