mirror of
https://github.com/YACReader/yacreader
synced 2025-06-04 01:28:55 -04:00
fixed adaptative wheel step size in the grid view using a private property of ScrollView __wheelAreaScrollSpeed
This commit is contained in:
parent
135f2432f1
commit
7c98ebc346
@ -314,10 +314,10 @@ Rectangle {
|
|||||||
}
|
}
|
||||||
|
|
||||||
YACReaderScrollView {
|
YACReaderScrollView {
|
||||||
|
__wheelAreaScrollSpeed: grid.cellHeight * 0.30
|
||||||
id: scrollView
|
id: scrollView
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
anchors.margins: 0
|
anchors.margins: 0
|
||||||
|
|
||||||
//QTBUG-39453
|
//QTBUG-39453
|
||||||
//Another fu%$·#& bug in Qt
|
//Another fu%$·#& bug in Qt
|
||||||
//https://bugreports.qt.io/browse/QTBUG-39453
|
//https://bugreports.qt.io/browse/QTBUG-39453
|
||||||
|
@ -1,38 +1,34 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
**
|
**
|
||||||
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
** Copyright (C) 2015 The Qt Company Ltd.
|
||||||
** Contact: http://www.qt-project.org/legal
|
** Contact: http://www.qt.io/licensing/
|
||||||
**
|
**
|
||||||
** This file is part of the Qt Quick Controls module of the Qt Toolkit.
|
** This file is part of the Qt Quick Controls module of the Qt Toolkit.
|
||||||
**
|
**
|
||||||
** $QT_BEGIN_LICENSE:BSD$
|
** $QT_BEGIN_LICENSE:LGPL3$
|
||||||
** You may use this file under the terms of the BSD license as follows:
|
** Commercial License Usage
|
||||||
|
** Licensees holding valid commercial Qt licenses may use this file in
|
||||||
|
** accordance with the commercial license agreement provided with the
|
||||||
|
** Software or, alternatively, in accordance with the terms contained in
|
||||||
|
** a written agreement between you and The Qt Company. For licensing terms
|
||||||
|
** and conditions see http://www.qt.io/terms-conditions. For further
|
||||||
|
** information use the contact form at http://www.qt.io/contact-us.
|
||||||
**
|
**
|
||||||
** "Redistribution and use in source and binary forms, with or without
|
** GNU Lesser General Public License Usage
|
||||||
** modification, are permitted provided that the following conditions are
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||||
** met:
|
** General Public License version 3 as published by the Free Software
|
||||||
** * Redistributions of source code must retain the above copyright
|
** Foundation and appearing in the file LICENSE.LGPLv3 included in the
|
||||||
** notice, this list of conditions and the following disclaimer.
|
** packaging of this file. Please review the following information to
|
||||||
** * Redistributions in binary form must reproduce the above copyright
|
** ensure the GNU Lesser General Public License version 3 requirements
|
||||||
** notice, this list of conditions and the following disclaimer in
|
** will be met: https://www.gnu.org/licenses/lgpl.html.
|
||||||
** the documentation and/or other materials provided with the
|
|
||||||
** distribution.
|
|
||||||
** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
|
|
||||||
** of its contributors may be used to endorse or promote products derived
|
|
||||||
** from this software without specific prior written permission.
|
|
||||||
**
|
**
|
||||||
**
|
** GNU General Public License Usage
|
||||||
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
** Alternatively, this file may be used under the terms of the GNU
|
||||||
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
** General Public License version 2.0 or later as published by the Free
|
||||||
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
** Software Foundation and appearing in the file LICENSE.GPL included in
|
||||||
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
** the packaging of this file. Please review the following information to
|
||||||
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
** ensure the GNU General Public License version 2.0 requirements will be
|
||||||
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
** met: http://www.gnu.org/licenses/gpl-2.0.html.
|
||||||
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
|
||||||
**
|
**
|
||||||
** $QT_END_LICENSE$
|
** $QT_END_LICENSE$
|
||||||
**
|
**
|
||||||
@ -50,6 +46,8 @@ import QtQuick.Controls.Styles 1.1
|
|||||||
\ingroup views
|
\ingroup views
|
||||||
\brief Provides a scrolling view within another Item.
|
\brief Provides a scrolling view within another Item.
|
||||||
|
|
||||||
|
\image scrollview.png
|
||||||
|
|
||||||
A ScrollView can be used either to replace a \l Flickable or decorate an
|
A ScrollView can be used either to replace a \l Flickable or decorate an
|
||||||
existing \l Flickable. Depending on the platform, it will add scroll bars and
|
existing \l Flickable. Depending on the platform, it will add scroll bars and
|
||||||
a content frame.
|
a content frame.
|
||||||
@ -81,7 +79,7 @@ import QtQuick.Controls.Styles 1.1
|
|||||||
\l flickableItem.
|
\l flickableItem.
|
||||||
|
|
||||||
You can create a custom appearance for a ScrollView by
|
You can create a custom appearance for a ScrollView by
|
||||||
assigning a \l {QtQuick.Controls.Styles::ScrollViewStyle}{ScrollViewStyle}.
|
assigning a \l {ScrollViewStyle}.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
FocusScope {
|
FocusScope {
|
||||||
@ -98,6 +96,36 @@ FocusScope {
|
|||||||
*/
|
*/
|
||||||
property bool frameVisible: false
|
property bool frameVisible: false
|
||||||
|
|
||||||
|
/*! \qmlproperty enumeration ScrollView::horizontalScrollBarPolicy
|
||||||
|
\since QtQuick.Controls 1.3
|
||||||
|
|
||||||
|
This property holds the policy for showing the horizontal scrollbar.
|
||||||
|
It can be any of the following values:
|
||||||
|
\list
|
||||||
|
\li Qt.ScrollBarAsNeeded
|
||||||
|
\li Qt.ScrollBarAlwaysOff
|
||||||
|
\li Qt.ScrollBarAlwaysOn
|
||||||
|
\endlist
|
||||||
|
|
||||||
|
The default policy is \c Qt.ScrollBarAsNeeded.
|
||||||
|
*/
|
||||||
|
property alias horizontalScrollBarPolicy: scroller.horizontalScrollBarPolicy
|
||||||
|
|
||||||
|
/*! \qmlproperty enumeration ScrollView::verticalScrollBarPolicy
|
||||||
|
\since QtQuick.Controls 1.3
|
||||||
|
|
||||||
|
This property holds the policy for showing the vertical scrollbar.
|
||||||
|
It can be any of the following values:
|
||||||
|
\list
|
||||||
|
\li Qt.ScrollBarAsNeeded
|
||||||
|
\li Qt.ScrollBarAlwaysOff
|
||||||
|
\li Qt.ScrollBarAlwaysOn
|
||||||
|
\endlist
|
||||||
|
|
||||||
|
The default policy is \c Qt.ScrollBarAsNeeded.
|
||||||
|
*/
|
||||||
|
property alias verticalScrollBarPolicy: scroller.verticalScrollBarPolicy
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
This property controls if there should be a highlight
|
This property controls if there should be a highlight
|
||||||
around the frame when the ScrollView has input focus.
|
around the frame when the ScrollView has input focus.
|
||||||
@ -152,7 +180,7 @@ FocusScope {
|
|||||||
\sa {Qt Quick Controls Styles QML Types}
|
\sa {Qt Quick Controls Styles QML Types}
|
||||||
|
|
||||||
*/
|
*/
|
||||||
property Component style: Qt.createComponent(Settings.style + "/ScrollViewStyle.qml", root)
|
property Component style: Settings.styleComponent(Settings.style, "ScrollViewStyle.qml", root)
|
||||||
|
|
||||||
/*! \internal */
|
/*! \internal */
|
||||||
property Style __style: styleLoader.item
|
property Style __style: styleLoader.item
|
||||||
@ -160,7 +188,7 @@ FocusScope {
|
|||||||
activeFocusOnTab: true
|
activeFocusOnTab: true
|
||||||
|
|
||||||
onContentItemChanged: {
|
onContentItemChanged: {
|
||||||
//console.log("onContentItemChanged");
|
|
||||||
if (contentItem.hasOwnProperty("contentY") && // Check if flickable
|
if (contentItem.hasOwnProperty("contentY") && // Check if flickable
|
||||||
contentItem.hasOwnProperty("contentHeight")) {
|
contentItem.hasOwnProperty("contentHeight")) {
|
||||||
internal.flickableItem = contentItem // "Use content if it is a flickable
|
internal.flickableItem = contentItem // "Use content if it is a flickable
|
||||||
@ -208,14 +236,12 @@ FocusScope {
|
|||||||
target: flickableItem
|
target: flickableItem
|
||||||
|
|
||||||
onContentYChanged: {
|
onContentYChanged: {
|
||||||
//console.log("onContentYChanged2");
|
|
||||||
scroller.blockUpdates = true
|
scroller.blockUpdates = true
|
||||||
scroller.verticalScrollBar.value = flickableItem.contentY
|
scroller.verticalScrollBar.value = flickableItem.contentY
|
||||||
scroller.blockUpdates = false
|
scroller.blockUpdates = false
|
||||||
}
|
}
|
||||||
|
|
||||||
onContentXChanged: {
|
onContentXChanged: {
|
||||||
//console.log("onContentXChanged2");
|
|
||||||
scroller.blockUpdates = true
|
scroller.blockUpdates = true
|
||||||
scroller.horizontalScrollBar.value = flickableItem.contentX
|
scroller.horizontalScrollBar.value = flickableItem.contentX
|
||||||
scroller.blockUpdates = false
|
scroller.blockUpdates = false
|
||||||
@ -233,13 +259,11 @@ FocusScope {
|
|||||||
WheelArea {
|
WheelArea {
|
||||||
id: wheelArea
|
id: wheelArea
|
||||||
parent: flickableItem
|
parent: flickableItem
|
||||||
|
z: -1
|
||||||
// ### Note this is needed due to broken mousewheel behavior in Flickable.
|
// ### Note this is needed due to broken mousewheel behavior in Flickable.
|
||||||
|
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
|
|
||||||
property int stepSize: 295
|
|
||||||
|
|
||||||
property int acceleration: 40
|
property int acceleration: 40
|
||||||
property int flickThreshold: Settings.dragThreshold
|
property int flickThreshold: Settings.dragThreshold
|
||||||
property real speedThreshold: 3
|
property real speedThreshold: 3
|
||||||
@ -255,17 +279,21 @@ FocusScope {
|
|||||||
verticalMinimumValue: flickableItem ? flickableItem.originY : 0
|
verticalMinimumValue: flickableItem ? flickableItem.originY : 0
|
||||||
verticalMaximumValue: flickableItem ? flickableItem.originY + flickableItem.contentHeight - viewport.height + __viewTopMargin : 0
|
verticalMaximumValue: flickableItem ? flickableItem.originY + flickableItem.contentHeight - viewport.height + __viewTopMargin : 0
|
||||||
|
|
||||||
|
// The default scroll speed for typical angle-based mouse wheels. The value
|
||||||
|
// comes originally from QTextEdit, which sets 20px steps by default, as well as
|
||||||
|
// QQuickWheelArea.
|
||||||
|
// TODO: centralize somewhere, QPlatformTheme?
|
||||||
|
scrollSpeed: 20 * (__style.__wheelScrollLines || 1)
|
||||||
|
|
||||||
Connections {
|
Connections {
|
||||||
target: flickableItem
|
target: flickableItem
|
||||||
|
|
||||||
onContentYChanged: {
|
onContentYChanged: {
|
||||||
//console.log("onContentYChanged");
|
|
||||||
wheelArea.verticalRecursionGuard = true
|
wheelArea.verticalRecursionGuard = true
|
||||||
wheelArea.verticalValue = flickableItem.contentY
|
wheelArea.verticalValue = flickableItem.contentY
|
||||||
wheelArea.verticalRecursionGuard = false
|
wheelArea.verticalRecursionGuard = false
|
||||||
}
|
}
|
||||||
onContentXChanged: {
|
onContentXChanged: {
|
||||||
//console.log("onContentXChanged");
|
|
||||||
wheelArea.horizontalRecursionGuard = true
|
wheelArea.horizontalRecursionGuard = true
|
||||||
wheelArea.horizontalValue = flickableItem.contentX
|
wheelArea.horizontalValue = flickableItem.contentX
|
||||||
wheelArea.horizontalRecursionGuard = false
|
wheelArea.horizontalRecursionGuard = false
|
||||||
@ -280,14 +308,8 @@ FocusScope {
|
|||||||
- flickThreshold - viewport.height && verticalDelta < -speedThreshold) {
|
- flickThreshold - viewport.height && verticalDelta < -speedThreshold) {
|
||||||
flickableItem.flick(ignored, Math.max(-maxFlick, acceleration * verticalDelta))
|
flickableItem.flick(ignored, Math.max(-maxFlick, acceleration * verticalDelta))
|
||||||
} else {
|
} else {
|
||||||
var absDelta = Math.abs(verticalDelta);
|
flickableItem.contentY = verticalValue
|
||||||
|
|
||||||
if(verticalDelta < 0)
|
|
||||||
flickableItem.contentY = Math.min(verticalMaximumValue, verticalValue + Math.min(98,0.93*absDelta+4.5));
|
|
||||||
else
|
|
||||||
flickableItem.contentY = Math.max(0, verticalValue - Math.min(98,0.93*absDelta+4.5));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
flickableItem.contentY = Math.min(verticalMaximumValue, Math.max(0, flickableItem.contentY));
|
flickableItem.contentY = Math.min(verticalMaximumValue, Math.max(0, flickableItem.contentY));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user