qscrollerproperties.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/widgets/util/qscrollerproperties.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2016 The Qt Company Ltd.-
4** Contact: https://www.qt.io/licensing/-
5**-
6** This file is part of the QtWidgets module of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL$-
9** Commercial License Usage-
10** Licensees holding valid commercial Qt licenses may use this file in-
11** accordance with the commercial license agreement provided with the-
12** Software or, alternatively, in accordance with the terms contained in-
13** a written agreement between you and The Qt Company. For licensing terms-
14** and conditions see https://www.qt.io/terms-conditions. For further-
15** information use the contact form at https://www.qt.io/contact-us.-
16**-
17** GNU Lesser General Public License Usage-
18** Alternatively, this file may be used under the terms of the GNU Lesser-
19** General Public License version 3 as published by the Free Software-
20** Foundation and appearing in the file LICENSE.LGPL3 included in the-
21** packaging of this file. Please review the following information to-
22** ensure the GNU Lesser General Public License version 3 requirements-
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.-
24**-
25** GNU General Public License Usage-
26** Alternatively, this file may be used under the terms of the GNU-
27** General Public License version 2.0 or (at your option) the GNU General-
28** Public license version 3 or any later version approved by the KDE Free-
29** Qt Foundation. The licenses are as published by the Free Software-
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3-
31** included in the packaging of this file. Please review the following-
32** information to ensure the GNU General Public License requirements will-
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and-
34** https://www.gnu.org/licenses/gpl-3.0.html.-
35**-
36** $QT_END_LICENSE$-
37**-
38****************************************************************************/-
39-
40#include <QPointer>-
41#include <QObject>-
42#include <QtCore/qmath.h>-
43#ifdef Q_DEAD_CODE_FROM_QT4_WIN-
44# include <QLibrary>-
45#endif-
46-
47#include "qscrollerproperties.h"-
48#include "private/qscrollerproperties_p.h"-
49-
50QT_BEGIN_NAMESPACE-
51-
52static QScrollerPropertiesPrivate *userDefaults = 0;-
53static QScrollerPropertiesPrivate *systemDefaults = 0;-
54-
55QScrollerPropertiesPrivate *QScrollerPropertiesPrivate::defaults()-
56{-
57 if (!systemDefaults) {
!systemDefaultsDescription
TRUEnever evaluated
FALSEnever evaluated
0
58 QScrollerPropertiesPrivate spp;-
59 spp.mousePressEventDelay = qreal(0.25);-
60 spp.dragStartDistance = qreal(5.0 / 1000);-
61 spp.dragVelocitySmoothingFactor = qreal(0.8);-
62 spp.axisLockThreshold = qreal(0);-
63 spp.scrollingCurve.setType(QEasingCurve::OutQuad);-
64 spp.decelerationFactor = qreal(0.125);-
65 spp.minimumVelocity = qreal(50.0 / 1000);-
66 spp.maximumVelocity = qreal(500.0 / 1000);-
67 spp.maximumClickThroughVelocity = qreal(66.5 / 1000);-
68 spp.acceleratingFlickMaximumTime = qreal(1.25);-
69 spp.acceleratingFlickSpeedupFactor = qreal(3.0);-
70 spp.snapPositionRatio = qreal(0.5);-
71 spp.snapTime = qreal(0.3);-
72 spp.overshootDragResistanceFactor = qreal(0.5);-
73 spp.overshootDragDistanceFactor = qreal(1);-
74 spp.overshootScrollDistanceFactor = qreal(0.5);-
75 spp.overshootScrollTime = qreal(0.7);-
76# ifdef Q_DEAD_CODE_FROM_QT4_WIN-
77 if (QLibrary::resolve(QLatin1String("UxTheme"), "BeginPanningFeedback"))-
78 spp.overshootScrollTime = qreal(0.35);-
79# endif-
80 spp.hOvershootPolicy = QScrollerProperties::OvershootWhenScrollable;-
81 spp.vOvershootPolicy = QScrollerProperties::OvershootWhenScrollable;-
82 spp.frameRate = QScrollerProperties::Standard;-
83-
84 systemDefaults = new QScrollerPropertiesPrivate(spp);-
85 }
never executed: end of block
0
86 return new QScrollerPropertiesPrivate(userDefaults ? *userDefaults : *systemDefaults);
never executed: return new QScrollerPropertiesPrivate(userDefaults ? *userDefaults : *systemDefaults);
0
87}-
88-
89/*!-
90 \class QScrollerProperties-
91 \brief The QScrollerProperties class stores the settings for a QScroller.-
92 \since 4.8-
93-
94 \inmodule QtWidgets-
95-
96 The QScrollerProperties class stores the parameters used by QScroller.-
97-
98 The default settings are platform dependent so that Qt emulates the-
99 platform behaviour for kinetic scrolling.-
100-
101 As a convention the QScrollerProperties are in physical units (meter,-
102 seconds) and are converted by QScroller using the current DPI.-
103-
104 \sa QScroller-
105*/-
106-
107/*!-
108 Constructs new scroller properties.-
109*/-
110QScrollerProperties::QScrollerProperties()-
111 : d(QScrollerPropertiesPrivate::defaults())-
112{-
113}
never executed: end of block
0
114-
115/*!-
116 Constructs a copy of \a sp.-
117*/-
118QScrollerProperties::QScrollerProperties(const QScrollerProperties &sp)-
119 : d(new QScrollerPropertiesPrivate(*sp.d))-
120{-
121}
never executed: end of block
0
122-
123/*!-
124 Assigns \a sp to these scroller properties and returns a reference to these scroller properties.-
125*/-
126QScrollerProperties &QScrollerProperties::operator=(const QScrollerProperties &sp)-
127{-
128 *d.data() = *sp.d.data();-
129 return *this;
never executed: return *this;
0
130}-
131-
132/*!-
133 Destroys the scroller properties.-
134*/-
135QScrollerProperties::~QScrollerProperties()-
136{-
137}-
138-
139/*!-
140 Returns \c true if these scroller properties are equal to \a sp; otherwise returns \c false.-
141*/-
142bool QScrollerProperties::operator==(const QScrollerProperties &sp) const-
143{-
144 return *d.data() == *sp.d.data();
never executed: return *d.data() == *sp.d.data();
0
145}-
146-
147/*!-
148 Returns \c true if these scroller properties are different from \a sp; otherwise returns \c false.-
149*/-
150bool QScrollerProperties::operator!=(const QScrollerProperties &sp) const-
151{-
152 return !(*d.data() == *sp.d.data());
never executed: return !(*d.data() == *sp.d.data());
0
153}-
154-
155bool QScrollerPropertiesPrivate::operator==(const QScrollerPropertiesPrivate &p) const-
156{-
157 bool same = true;-
158 same &= (mousePressEventDelay == p.mousePressEventDelay);-
159 same &= (dragStartDistance == p.dragStartDistance);-
160 same &= (dragVelocitySmoothingFactor == p.dragVelocitySmoothingFactor);-
161 same &= (axisLockThreshold == p.axisLockThreshold);-
162 same &= (scrollingCurve == p.scrollingCurve);-
163 same &= (decelerationFactor == p.decelerationFactor);-
164 same &= (minimumVelocity == p.minimumVelocity);-
165 same &= (maximumVelocity == p.maximumVelocity);-
166 same &= (maximumClickThroughVelocity == p.maximumClickThroughVelocity);-
167 same &= (acceleratingFlickMaximumTime == p.acceleratingFlickMaximumTime);-
168 same &= (acceleratingFlickSpeedupFactor == p.acceleratingFlickSpeedupFactor);-
169 same &= (snapPositionRatio == p.snapPositionRatio);-
170 same &= (snapTime == p.snapTime);-
171 same &= (overshootDragResistanceFactor == p.overshootDragResistanceFactor);-
172 same &= (overshootDragDistanceFactor == p.overshootDragDistanceFactor);-
173 same &= (overshootScrollDistanceFactor == p.overshootScrollDistanceFactor);-
174 same &= (overshootScrollTime == p.overshootScrollTime);-
175 same &= (hOvershootPolicy == p.hOvershootPolicy);-
176 same &= (vOvershootPolicy == p.vOvershootPolicy);-
177 same &= (frameRate == p.frameRate);-
178 return same;
never executed: return same;
0
179}-
180-
181/*!-
182 Sets the scroller properties for all new QScrollerProperties objects to \a sp.-
183-
184 Use this function to override the platform default properties returned by the default-
185 constructor. If you only want to change the scroller properties of a single scroller, use-
186 QScroller::setScrollerProperties()-
187-
188 \note Calling this function will not change the content of already existing-
189 QScrollerProperties objects.-
190-
191 \sa unsetDefaultScrollerProperties()-
192*/-
193void QScrollerProperties::setDefaultScrollerProperties(const QScrollerProperties &sp)-
194{-
195 if (!userDefaults)
!userDefaultsDescription
TRUEnever evaluated
FALSEnever evaluated
0
196 userDefaults = new QScrollerPropertiesPrivate(*sp.d);
never executed: userDefaults = new QScrollerPropertiesPrivate(*sp.d);
0
197 else-
198 *userDefaults = *sp.d;
never executed: *userDefaults = *sp.d;
0
199}-
200-
201/*!-
202 Sets the scroller properties returned by the default constructor back to the platform default-
203 properties.-
204-
205 \sa setDefaultScrollerProperties()-
206*/-
207void QScrollerProperties::unsetDefaultScrollerProperties()-
208{-
209 delete userDefaults;-
210 userDefaults = 0;-
211}
never executed: end of block
0
212-
213/*!-
214 Query the \a metric value of the scroller properties.-
215-
216 \sa setScrollMetric(), ScrollMetric-
217*/-
218QVariant QScrollerProperties::scrollMetric(ScrollMetric metric) const-
219{-
220 switch (metric) {-
221 case MousePressEventDelay: return d->mousePressEventDelay;
never executed: return d->mousePressEventDelay;
never executed: case MousePressEventDelay:
0
222 case DragStartDistance: return d->dragStartDistance;
never executed: return d->dragStartDistance;
never executed: case DragStartDistance:
0
223 case DragVelocitySmoothingFactor: return d->dragVelocitySmoothingFactor;
never executed: return d->dragVelocitySmoothingFactor;
never executed: case DragVelocitySmoothingFactor:
0
224 case AxisLockThreshold: return d->axisLockThreshold;
never executed: return d->axisLockThreshold;
never executed: case AxisLockThreshold:
0
225 case ScrollingCurve: return d->scrollingCurve;
never executed: return d->scrollingCurve;
never executed: case ScrollingCurve:
0
226 case DecelerationFactor: return d->decelerationFactor;
never executed: return d->decelerationFactor;
never executed: case DecelerationFactor:
0
227 case MinimumVelocity: return d->minimumVelocity;
never executed: return d->minimumVelocity;
never executed: case MinimumVelocity:
0
228 case MaximumVelocity: return d->maximumVelocity;
never executed: return d->maximumVelocity;
never executed: case MaximumVelocity:
0
229 case MaximumClickThroughVelocity: return d->maximumClickThroughVelocity;
never executed: return d->maximumClickThroughVelocity;
never executed: case MaximumClickThroughVelocity:
0
230 case AcceleratingFlickMaximumTime: return d->acceleratingFlickMaximumTime;
never executed: return d->acceleratingFlickMaximumTime;
never executed: case AcceleratingFlickMaximumTime:
0
231 case AcceleratingFlickSpeedupFactor:return d->acceleratingFlickSpeedupFactor;
never executed: return d->acceleratingFlickSpeedupFactor;
never executed: case AcceleratingFlickSpeedupFactor:
0
232 case SnapPositionRatio: return d->snapPositionRatio;
never executed: return d->snapPositionRatio;
never executed: case SnapPositionRatio:
0
233 case SnapTime: return d->snapTime;
never executed: return d->snapTime;
never executed: case SnapTime:
0
234 case OvershootDragResistanceFactor: return d->overshootDragResistanceFactor;
never executed: return d->overshootDragResistanceFactor;
never executed: case OvershootDragResistanceFactor:
0
235 case OvershootDragDistanceFactor: return d->overshootDragDistanceFactor;
never executed: return d->overshootDragDistanceFactor;
never executed: case OvershootDragDistanceFactor:
0
236 case OvershootScrollDistanceFactor: return d->overshootScrollDistanceFactor;
never executed: return d->overshootScrollDistanceFactor;
never executed: case OvershootScrollDistanceFactor:
0
237 case OvershootScrollTime: return d->overshootScrollTime;
never executed: return d->overshootScrollTime;
never executed: case OvershootScrollTime:
0
238 case HorizontalOvershootPolicy: return QVariant::fromValue(d->hOvershootPolicy);
never executed: return QVariant::fromValue(d->hOvershootPolicy);
never executed: case HorizontalOvershootPolicy:
0
239 case VerticalOvershootPolicy: return QVariant::fromValue(d->vOvershootPolicy);
never executed: return QVariant::fromValue(d->vOvershootPolicy);
never executed: case VerticalOvershootPolicy:
0
240 case FrameRate: return QVariant::fromValue(d->frameRate);
never executed: return QVariant::fromValue(d->frameRate);
never executed: case FrameRate:
0
241 case ScrollMetricCount: break;
never executed: break;
never executed: case ScrollMetricCount:
0
242 }-
243 return QVariant();
never executed: return QVariant();
0
244}-
245-
246/*!-
247 Set a specific value of the \a metric ScrollerMetric to \a value.-
248-
249 \sa scrollMetric(), ScrollMetric-
250*/-
251void QScrollerProperties::setScrollMetric(ScrollMetric metric, const QVariant &value)-
252{-
253 switch (metric) {-
254 case MousePressEventDelay: d->mousePressEventDelay = value.toReal(); break;
never executed: break;
never executed: case MousePressEventDelay:
0
255 case DragStartDistance: d->dragStartDistance = value.toReal(); break;
never executed: break;
never executed: case DragStartDistance:
0
256 case DragVelocitySmoothingFactor: d->dragVelocitySmoothingFactor = qBound(qreal(0), value.toReal(), qreal(1)); break;
never executed: break;
never executed: case DragVelocitySmoothingFactor:
0
257 case AxisLockThreshold: d->axisLockThreshold = qBound(qreal(0), value.toReal(), qreal(1)); break;
never executed: break;
never executed: case AxisLockThreshold:
0
258 case ScrollingCurve: d->scrollingCurve = value.toEasingCurve(); break;
never executed: break;
never executed: case ScrollingCurve:
0
259 case DecelerationFactor: d->decelerationFactor = value.toReal(); break;
never executed: break;
never executed: case DecelerationFactor:
0
260 case MinimumVelocity: d->minimumVelocity = value.toReal(); break;
never executed: break;
never executed: case MinimumVelocity:
0
261 case MaximumVelocity: d->maximumVelocity = value.toReal(); break;
never executed: break;
never executed: case MaximumVelocity:
0
262 case MaximumClickThroughVelocity: d->maximumClickThroughVelocity = value.toReal(); break;
never executed: break;
never executed: case MaximumClickThroughVelocity:
0
263 case AcceleratingFlickMaximumTime: d->acceleratingFlickMaximumTime = value.toReal(); break;
never executed: break;
never executed: case AcceleratingFlickMaximumTime:
0
264 case AcceleratingFlickSpeedupFactor:d->acceleratingFlickSpeedupFactor = value.toReal(); break;
never executed: break;
never executed: case AcceleratingFlickSpeedupFactor:
0
265 case SnapPositionRatio: d->snapPositionRatio = qBound(qreal(0), value.toReal(), qreal(1)); break;
never executed: break;
never executed: case SnapPositionRatio:
0
266 case SnapTime: d->snapTime = value.toReal(); break;
never executed: break;
never executed: case SnapTime:
0
267 case OvershootDragResistanceFactor: d->overshootDragResistanceFactor = value.toReal(); break;
never executed: break;
never executed: case OvershootDragResistanceFactor:
0
268 case OvershootDragDistanceFactor: d->overshootDragDistanceFactor = qBound(qreal(0), value.toReal(), qreal(1)); break;
never executed: break;
never executed: case OvershootDragDistanceFactor:
0
269 case OvershootScrollDistanceFactor: d->overshootScrollDistanceFactor = qBound(qreal(0), value.toReal(), qreal(1)); break;
never executed: break;
never executed: case OvershootScrollDistanceFactor:
0
270 case OvershootScrollTime: d->overshootScrollTime = value.toReal(); break;
never executed: break;
never executed: case OvershootScrollTime:
0
271 case HorizontalOvershootPolicy: d->hOvershootPolicy = value.value<QScrollerProperties::OvershootPolicy>(); break;
never executed: break;
never executed: case HorizontalOvershootPolicy:
0
272 case VerticalOvershootPolicy: d->vOvershootPolicy = value.value<QScrollerProperties::OvershootPolicy>(); break;
never executed: break;
never executed: case VerticalOvershootPolicy:
0
273 case FrameRate: d->frameRate = value.value<QScrollerProperties::FrameRates>(); break;
never executed: break;
never executed: case FrameRate:
0
274 case ScrollMetricCount: break;
never executed: break;
never executed: case ScrollMetricCount:
0
275 }-
276}
never executed: end of block
0
277-
278/*!-
279 \enum QScrollerProperties::FrameRates-
280-
281 This enum describes the available frame rates used while dragging or scrolling.-
282-
283 \value Fps60 60 frames per second-
284 \value Fps30 30 frames per second-
285 \value Fps20 20 frames per second-
286 \value Standard the default value is 60 frames per second (which corresponds to QAbstractAnimation).-
287*/-
288-
289/*!-
290 \enum QScrollerProperties::OvershootPolicy-
291-
292 This enum describes the various modes of overshooting.-
293-
294 \value OvershootWhenScrollable Overshooting is possible when the content is scrollable. This is the-
295 default.-
296-
297 \value OvershootAlwaysOff Overshooting is never enabled, even when the content is scrollable.-
298-
299 \value OvershootAlwaysOn Overshooting is always enabled, even when the content is not-
300 scrollable.-
301*/-
302-
303/*!-
304 \enum QScrollerProperties::ScrollMetric-
305-
306 This enum contains the different scroll metric types. When not indicated otherwise the-
307 setScrollMetric function expects a QVariant of type qreal.-
308-
309 See the QScroller documentation for further details of the concepts behind the different-
310 values.-
311-
312 \value MousePressEventDelay This is the time a mouse press event is delayed when starting-
313 a flick gesture in \c{[s]}. If the gesture is triggered within that time, no mouse press or-
314 release is sent to the scrolled object. If it triggers after that delay the delayed-
315 mouse press plus a faked release event at global position \c{QPoint(-QWIDGETSIZE_MAX,-
316 -QWIDGETSIZE_MAX)} is sent. If the gesture is canceled, then both the delayed mouse-
317 press plus the real release event are delivered.-
318-
319 \value DragStartDistance This is the minimum distance the touch or mouse point needs to be-
320 moved before the flick gesture is triggered in \c m.-
321-
322 \value DragVelocitySmoothingFactor A value that describes to which extent new drag velocities are-
323 included in the final scrolling velocity. This value should be in the range between \c 0 and-
324 \c 1. The lower the value, the more smoothing is applied to the dragging velocity.-
325-
326 \value AxisLockThreshold Restricts the movement to one axis if the movement is inside an angle-
327 around the axis. The threshold must be in the range \c 0 to \c 1.-
328-
329 \value ScrollingCurve The QEasingCurve used when decelerating the scrolling velocity after an-
330 user initiated flick. Please note that this is the easing curve for the positions, \b{not}-
331 the velocity: the default is QEasingCurve::OutQuad, which results in a linear decrease in-
332 velocity (1st derivative) and a constant deceleration (2nd derivative).-
333-
334 \value DecelerationFactor This factor influences how long it takes the scroller to decelerate-
335 to 0 velocity. The actual value depends on the chosen ScrollingCurve. For most-
336 types the value should be in the range from \c 0.1 to \c 2.0-
337-
338 \value MinimumVelocity The minimum velocity that is needed after ending the touch or releasing-
339 the mouse to start scrolling in \c{m/s}.-
340-
341 \value MaximumVelocity This is the maximum velocity that can be reached in \c{m/s}.-
342-
343 \value MaximumClickThroughVelocity This is the maximum allowed scroll speed for a click-through-
344 in \c{m/s}. This means that a click on a currently (slowly) scrolling object will not only stop-
345 the scrolling but the click event will also be delivered to the UI control. This is-
346 useful when using exponential-type scrolling curves.-
347-
348 \value AcceleratingFlickMaximumTime This is the maximum time in \c seconds that a flick gesture-
349 can take to be recognized as an accelerating flick. If set to zero no such gesture is-
350 detected. An "accelerating flick" is a flick gesture executed on an already scrolling object.-
351 In such cases the scrolling speed is multiplied by AcceleratingFlickSpeedupFactor in order to-
352 accelerate it.-
353-
354 \value AcceleratingFlickSpeedupFactor The current speed is multiplied by this number if an-
355 accelerating flick is detected. Should be \c{>= 1}.-
356-
357 \value SnapPositionRatio This is the distance that the user must drag the area beween two snap-
358 points in order to snap it to the next position. \c{0.33} means that the scroll must only-
359 reach one third of the distance between two snap points to snap to the next one. The ratio must-
360 be between \c 0 and \c 1.-
361-
362 \value SnapTime This is the time factor for the scrolling curve. A lower value means that the-
363 scrolling will take longer. The scrolling distance is independet of this value.-
364-
365 \value OvershootDragResistanceFactor This value is the factor between the mouse dragging and-
366 the actual scroll area movement (during overshoot). The factor must be between \c 0 and \c 1.-
367-
368 \value OvershootDragDistanceFactor This is the maximum distance for overshoot movements while-
369 dragging. The actual overshoot distance is calculated by multiplying this value with the-
370 viewport size of the scrolled object. The factor must be between \c 0 and \c 1.-
371-
372 \value OvershootScrollDistanceFactor This is the maximum distance for overshoot movements while-
373 scrolling. The actual overshoot distance is calculated by multiplying this value with the-
374 viewport size of the scrolled object. The factor must be between \c 0 and \c 1.-
375-
376 \value OvershootScrollTime This is the time in \c seconds that is used to play the-
377 complete overshoot animation.-
378-
379 \value HorizontalOvershootPolicy This is the horizontal overshooting policy (see OvershootPolicy).-
380-
381 \value VerticalOvershootPolicy This is the horizontal overshooting policy (see OvershootPolicy).-
382-
383 \value FrameRate This is the frame rate which should be used while dragging or scrolling.-
384 QScroller uses a QAbstractAnimation timer internally to sync all scrolling operations to other-
385 animations that might be active at the same time. If the standard value of 60 frames per-
386 second is too fast, it can be lowered with this setting,-
387 while still being in-sync with QAbstractAnimation. Please note that only the values of the-
388 FrameRates enum are allowed here.-
389-
390 \value ScrollMetricCount This is always the last entry.-
391*/-
392-
393QT_END_NAMESPACE-
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9