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

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