Warning, /pim/kube/framework/qml/ScrollHelper.qml is written in an unsupported language. File is not indexed.
0001 /*
0002 * Copyright (C) 2016 Michael Bohlender, <michael.bohlender@kdemail.net>
0003 * Copyright (C) 2017 Christian Mollekopf, <mollekopf@kolabsystems.com>
0004 *
0005 * This program is free software; you can redistribute it and/or modify
0006 * it under the terms of the GNU General Public License as published by
0007 * the Free Software Foundation; either version 2 of the License, or
0008 * (at your option) any later version.
0009 *
0010 * This program is distributed in the hope that it will be useful,
0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0013 * GNU General Public License for more details.
0014 *
0015 * You should have received a copy of the GNU General Public License along
0016 * with this program; if not, write to the Free Software Foundation, Inc.,
0017 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
0018 */
0019
0020 import QtQuick 2.7
0021 import QtQuick.Controls 2
0022
0023 /*
0024 * The MouseArea + interactive: false + maximumFlickVelocity are required
0025 * to fix scrolling for desktop systems where we don't want flicking behaviour.
0026 *
0027 * See also:
0028 * ScrollView.qml in qtquickcontrols
0029 * qquickwheelarea.cpp in qtquickcontrols
0030 */
0031 MouseArea {
0032 id: root
0033 propagateComposedEvents: true
0034
0035 property Flickable flickable
0036
0037 //Place the mouse area under the flickable
0038 z: -1
0039 onFlickableChanged: {
0040 flickable.interactive = false
0041 flickable.maximumFlickVelocity = 100000
0042 flickable.boundsBehavior = Flickable.StopAtBounds
0043 root.parent = flickable
0044 }
0045
0046 function scrollByPixelDelta(flickableItem, pixelDelta) {
0047 if (!pixelDelta) {
0048 return flickableItem.contentY;
0049 }
0050
0051 var minYExtent = flickableItem.originY + flickableItem.topMargin;
0052 var maxYExtent = (flickableItem.contentHeight + flickableItem.bottomMargin + flickableItem.originY) - flickableItem.height;
0053
0054 if (typeof(flickableItem.headerItem) !== "undefined" && flickableItem.headerItem) {
0055 minYExtent += flickableItem.headerItem.height
0056 }
0057
0058 //Avoid overscrolling
0059 return Math.max(minYExtent, Math.min(maxYExtent, flickableItem.contentY - pixelDelta));
0060 }
0061
0062 function calculateNewPosition(flickableItem, wheel) {
0063 //Nothing to scroll
0064 if (flickableItem.contentHeight < flickableItem.height) {
0065 return flickableItem.contentY;
0066 }
0067 //Ignore 0 events (happens at least with Christians trackpad)
0068 if (wheel.pixelDelta.y == 0 && wheel.angleDelta.y == 0) {
0069 return flickableItem.contentY;
0070 }
0071 //pixelDelta seems to be the same as angleDelta/8
0072 var pixelDelta = 0
0073 //The pixelDelta is a smaller number if both are provided, so pixelDelta can be 0 while angleDelta is still something. So we check the angleDelta
0074 if (wheel.angleDelta.y) {
0075 var wheelScrollLines = 3 //Default value of QApplication wheelScrollLines property
0076 var pixelPerLine = 20 //Default value in Qt, originally comes from QTextEdit
0077 var ticks = (wheel.angleDelta.y / 8) / 15.0 //Divide by 8 gives us pixels typically come in 15pixel steps.
0078 pixelDelta = ticks * pixelPerLine * wheelScrollLines
0079 } else {
0080 pixelDelta = wheel.pixelDelta.y
0081 }
0082
0083 return scrollByPixelDelta(flickableItem, pixelDelta);
0084 }
0085
0086 function scrollDown() {
0087 flickable.flick(0, 0);
0088 flickable.contentY = scrollByPixelDelta(flickable, -60); //3 lines * 20 pixels
0089 }
0090
0091 function scrollUp() {
0092 flickable.flick(0, 0);
0093 flickable.contentY = scrollByPixelDelta(flickable, 60); //3 lines * 20 pixels
0094 }
0095
0096 onWheel: {
0097 var newPos = calculateNewPosition(flickable, wheel);
0098 // console.warn("Delta: ", wheel.pixelDelta.y);
0099 // console.warn("Old position: ", flickable.contentY);
0100 // console.warn("New position: ", newPos);
0101
0102 // Show the scrollbars
0103 flickable.flick(0, 0);
0104 //Workaround because we seem to break this but rely on it in ConversationListView
0105 flickable.movementStarted();
0106 flickable.contentY = newPos;
0107 cancelFlickStateTimer.start()
0108 }
0109
0110
0111 Timer {
0112 id: cancelFlickStateTimer
0113 //How long the scrollbar will remain visible
0114 interval: 500
0115 // Hide the scrollbars
0116 onTriggered: flickable.cancelFlick();
0117 }
0118 }
0119