qabstractslider.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/widgets/widgets/qabstractslider.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 <qapplication.h>-
41#include "qabstractslider.h"-
42#include "qevent.h"-
43#include "qabstractslider_p.h"-
44#include "qdebug.h"-
45#ifndef QT_NO_ACCESSIBILITY-
46#include "qaccessible.h"-
47#endif-
48#include <limits.h>-
49-
50QT_BEGIN_NAMESPACE-
51-
52/*!-
53 \class QAbstractSlider-
54 \brief The QAbstractSlider class provides an integer value within a range.-
55-
56 \ingroup abstractwidgets-
57 \inmodule QtWidgets-
58-
59 The class is designed as a common super class for widgets like-
60 QScrollBar, QSlider and QDial.-
61-
62 Here are the main properties of the class:-
63-
64 \list 1-
65-
66 \li \l value: The bounded integer that QAbstractSlider maintains.-
67-
68 \li \l minimum: The lowest possible value.-
69-
70 \li \l maximum: The highest possible value.-
71-
72 \li \l singleStep: The smaller of two natural steps that an-
73 abstract sliders provides and typically corresponds to the user-
74 pressing an arrow key.-
75-
76 \li \l pageStep: The larger of two natural steps that an abstract-
77 slider provides and typically corresponds to the user pressing-
78 PageUp or PageDown.-
79-
80 \li \l tracking: Whether slider tracking is enabled.-
81-
82 \li \l sliderPosition: The current position of the slider. If \l-
83 tracking is enabled (the default), this is identical to \l value.-
84-
85 \endlist-
86-
87 Unity (1) may be viewed as a third step size. setValue() lets you-
88 set the current value to any integer in the allowed range, not-
89 just minimum() + \e n * singleStep() for integer values of \e n.-
90 Some widgets may allow the user to set any value at all; others-
91 may just provide multiples of singleStep() or pageStep().-
92-
93 QAbstractSlider emits a comprehensive set of signals:-
94-
95 \table-
96 \header \li Signal \li Emitted when-
97 \row \li \l valueChanged()-
98 \li the value has changed. The \l tracking-
99 determines whether this signal is emitted during user-
100 interaction.-
101 \row \li \l sliderPressed()-
102 \li the user starts to drag the slider.-
103 \row \li \l sliderMoved()-
104 \li the user drags the slider.-
105 \row \li \l sliderReleased()-
106 \li the user releases the slider.-
107 \row \li \l actionTriggered()-
108 \li a slider action was triggerd.-
109 \row \li \l rangeChanged()-
110 \li a the range has changed.-
111 \endtable-
112-
113 QAbstractSlider provides a virtual sliderChange() function that is-
114 well suited for updating the on-screen representation of-
115 sliders. By calling triggerAction(), subclasses trigger slider-
116 actions. Two helper functions QStyle::sliderPositionFromValue() and-
117 QStyle::sliderValueFromPosition() help subclasses and styles to map-
118 screen coordinates to logical range values.-
119-
120 \sa QAbstractSpinBox, QSlider, QDial, QScrollBar, {Sliders Example}-
121*/-
122-
123/*!-
124 \enum QAbstractSlider::SliderAction-
125-
126 \value SliderNoAction-
127 \value SliderSingleStepAdd-
128 \value SliderSingleStepSub-
129 \value SliderPageStepAdd-
130 \value SliderPageStepSub-
131 \value SliderToMinimum-
132 \value SliderToMaximum-
133 \value SliderMove-
134-
135*/-
136-
137/*!-
138 \fn void QAbstractSlider::valueChanged(int value)-
139-
140 This signal is emitted when the slider value has changed, with the-
141 new slider \a value as argument.-
142*/-
143-
144/*!-
145 \fn void QAbstractSlider::sliderPressed()-
146-
147 This signal is emitted when the user presses the slider with the-
148 mouse, or programmatically when setSliderDown(true) is called.-
149-
150 \sa sliderReleased(), sliderMoved(), isSliderDown()-
151*/-
152-
153/*!-
154 \fn void QAbstractSlider::sliderMoved(int value)-
155-
156 This signal is emitted when sliderDown is true and the slider moves. This-
157 usually happens when the user is dragging the slider. The \a value-
158 is the new slider position.-
159-
160 This signal is emitted even when tracking is turned off.-
161-
162 \sa setTracking(), valueChanged(), isSliderDown(),-
163 sliderPressed(), sliderReleased()-
164*/-
165-
166/*!-
167 \fn void QAbstractSlider::sliderReleased()-
168-
169 This signal is emitted when the user releases the slider with the-
170 mouse, or programmatically when setSliderDown(false) is called.-
171-
172 \sa sliderPressed(), sliderMoved(), sliderDown-
173*/-
174-
175/*!-
176 \fn void QAbstractSlider::rangeChanged(int min, int max)-
177-
178 This signal is emitted when the slider range has changed, with \a-
179 min being the new minimum, and \a max being the new maximum.-
180-
181 \sa minimum, maximum-
182*/-
183-
184/*!-
185 \fn void QAbstractSlider::actionTriggered(int action)-
186-
187 This signal is emitted when the slider action \a action is-
188 triggered. Actions are \l SliderSingleStepAdd, \l-
189 SliderSingleStepSub, \l SliderPageStepAdd, \l SliderPageStepSub,-
190 \l SliderToMinimum, \l SliderToMaximum, and \l SliderMove.-
191-
192 When the signal is emitted, the \l sliderPosition has been-
193 adjusted according to the action, but the \l value has not yet-
194 been propagated (meaning the valueChanged() signal was not yet-
195 emitted), and the visual display has not been updated. In slots-
196 connected to this signal you can thus safely adjust any action by-
197 calling setSliderPosition() yourself, based on both the action and-
198 the slider's value.-
199-
200 \sa triggerAction()-
201*/-
202-
203/*!-
204 \enum QAbstractSlider::SliderChange-
205-
206 \value SliderRangeChange-
207 \value SliderOrientationChange-
208 \value SliderStepsChange-
209 \value SliderValueChange-
210*/-
211-
212QAbstractSliderPrivate::QAbstractSliderPrivate()-
213 : minimum(0), maximum(99), pageStep(10), value(0), position(0), pressValue(-1),-
214 singleStep(1), singleStepFromItemView(-1), viewMayChangeSingleStep(true), offset_accumulated(0), tracking(true),-
215 blocktracking(false), pressed(false),-
216 invertedAppearance(false), invertedControls(false),-
217 orientation(Qt::Horizontal), repeatAction(QAbstractSlider::SliderNoAction)-
218#ifdef QT_KEYPAD_NAVIGATION-
219 , isAutoRepeating(false)-
220 , repeatMultiplier(1)-
221{-
222 firstRepeat.invalidate();-
223#else-
224{-
225#endif-
226-
227}
never executed: end of block
0
228-
229QAbstractSliderPrivate::~QAbstractSliderPrivate()-
230{-
231}-
232-
233/*!-
234 Sets the slider's minimum to \a min and its maximum to \a max.-
235-
236 If \a max is smaller than \a min, \a min becomes the only legal-
237 value.-
238-
239 \sa minimum, maximum-
240*/-
241void QAbstractSlider::setRange(int min, int max)-
242{-
243 Q_D(QAbstractSlider);-
244 int oldMin = d->minimum;-
245 int oldMax = d->maximum;-
246 d->minimum = min;-
247 d->maximum = qMax(min, max);-
248 if (oldMin != d->minimum || oldMax != d->maximum) {
oldMin != d->minimumDescription
TRUEnever evaluated
FALSEnever evaluated
oldMax != d->maximumDescription
TRUEnever evaluated
FALSEnever evaluated
0
249 sliderChange(SliderRangeChange);-
250 emit rangeChanged(d->minimum, d->maximum);-
251 setValue(d->value); // re-bound-
252 }
never executed: end of block
0
253}
never executed: end of block
0
254-
255-
256void QAbstractSliderPrivate::setSteps(int single, int page)-
257{-
258 Q_Q(QAbstractSlider);-
259 singleStep = qAbs(single);-
260 pageStep = qAbs(page);-
261 q->sliderChange(QAbstractSlider::SliderStepsChange);-
262}
never executed: end of block
0
263-
264/*!-
265 Constructs an abstract slider.-
266-
267 The \a parent argument is sent to the QWidget constructor.-
268-
269 The \l minimum defaults to 0, the \l maximum to 99, with a \l-
270 singleStep size of 1 and a \l pageStep size of 10, and an initial-
271 \l value of 0.-
272*/-
273QAbstractSlider::QAbstractSlider(QWidget *parent)-
274 :QWidget(*new QAbstractSliderPrivate, parent, 0)-
275{-
276}
never executed: end of block
0
277-
278/*! \internal */-
279QAbstractSlider::QAbstractSlider(QAbstractSliderPrivate &dd, QWidget *parent)-
280 :QWidget(dd, parent, 0)-
281{-
282}
never executed: end of block
0
283-
284/*!-
285 Destroys the slider.-
286*/-
287QAbstractSlider::~QAbstractSlider()-
288{-
289}-
290-
291/*!-
292 \property QAbstractSlider::orientation-
293 \brief the orientation of the slider-
294-
295 The orientation must be \l Qt::Vertical (the default) or \l-
296 Qt::Horizontal.-
297*/-
298void QAbstractSlider::setOrientation(Qt::Orientation orientation)-
299{-
300 Q_D(QAbstractSlider);-
301 if (d->orientation == orientation)
d->orientation == orientationDescription
TRUEnever evaluated
FALSEnever evaluated
0
302 return;
never executed: return;
0
303-
304 d->orientation = orientation;-
305 if (!testAttribute(Qt::WA_WState_OwnSizePolicy)) {
!testAttribute...OwnSizePolicy)Description
TRUEnever evaluated
FALSEnever evaluated
0
306 QSizePolicy sp = sizePolicy();-
307 sp.transpose();-
308 setSizePolicy(sp);-
309 setAttribute(Qt::WA_WState_OwnSizePolicy, false);-
310 }
never executed: end of block
0
311 update();-
312 updateGeometry();-
313}
never executed: end of block
0
314-
315Qt::Orientation QAbstractSlider::orientation() const-
316{-
317 Q_D(const QAbstractSlider);-
318 return d->orientation;
never executed: return d->orientation;
0
319}-
320-
321-
322/*!-
323 \property QAbstractSlider::minimum-
324 \brief the sliders's minimum value-
325-
326 When setting this property, the \l maximum is adjusted if-
327 necessary to ensure that the range remains valid. Also the-
328 slider's current value is adjusted to be within the new range.-
329-
330*/-
331-
332void QAbstractSlider::setMinimum(int min)-
333{-
334 Q_D(QAbstractSlider);-
335 setRange(min, qMax(d->maximum, min));-
336}
never executed: end of block
0
337-
338int QAbstractSlider::minimum() const-
339{-
340 Q_D(const QAbstractSlider);-
341 return d->minimum;
never executed: return d->minimum;
0
342}-
343-
344-
345/*!-
346 \property QAbstractSlider::maximum-
347 \brief the slider's maximum value-
348-
349 When setting this property, the \l minimum is adjusted if-
350 necessary to ensure that the range remains valid. Also the-
351 slider's current value is adjusted to be within the new range.-
352-
353-
354*/-
355-
356void QAbstractSlider::setMaximum(int max)-
357{-
358 Q_D(QAbstractSlider);-
359 setRange(qMin(d->minimum, max), max);-
360}
never executed: end of block
0
361-
362int QAbstractSlider::maximum() const-
363{-
364 Q_D(const QAbstractSlider);-
365 return d->maximum;
never executed: return d->maximum;
0
366}-
367-
368-
369-
370/*!-
371 \property QAbstractSlider::singleStep-
372 \brief the single step.-
373-
374 The smaller of two natural steps that an-
375 abstract sliders provides and typically corresponds to the user-
376 pressing an arrow key.-
377-
378 If the property is modified during an auto repeating key event, behavior-
379 is undefined.-
380-
381 \sa pageStep-
382*/-
383-
384void QAbstractSlider::setSingleStep(int step)-
385{-
386 Q_D(QAbstractSlider);-
387-
388 d->viewMayChangeSingleStep = (step < 0);-
389 if (step < 0 && d->singleStepFromItemView > 0)
step < 0Description
TRUEnever evaluated
FALSEnever evaluated
d->singleStepFromItemView > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
390 step = d->singleStepFromItemView;
never executed: step = d->singleStepFromItemView;
0
391-
392 if (step != d->singleStep)
step != d->singleStepDescription
TRUEnever evaluated
FALSEnever evaluated
0
393 d->setSteps(step, d->pageStep);
never executed: d->setSteps(step, d->pageStep);
0
394}
never executed: end of block
0
395-
396int QAbstractSlider::singleStep() const-
397{-
398 Q_D(const QAbstractSlider);-
399 return d->singleStep;
never executed: return d->singleStep;
0
400}-
401-
402-
403/*!-
404 \property QAbstractSlider::pageStep-
405 \brief the page step.-
406-
407 The larger of two natural steps that an abstract slider provides-
408 and typically corresponds to the user pressing PageUp or PageDown.-
409-
410 \sa singleStep-
411*/-
412-
413void QAbstractSlider::setPageStep(int step)-
414{-
415 Q_D(QAbstractSlider);-
416 if (step != d->pageStep)
step != d->pageStepDescription
TRUEnever evaluated
FALSEnever evaluated
0
417 d->setSteps(d->singleStep, step);
never executed: d->setSteps(d->singleStep, step);
0
418}
never executed: end of block
0
419-
420int QAbstractSlider::pageStep() const-
421{-
422 Q_D(const QAbstractSlider);-
423 return d->pageStep;
never executed: return d->pageStep;
0
424}-
425-
426/*!-
427 \property QAbstractSlider::tracking-
428 \brief whether slider tracking is enabled-
429-
430 If tracking is enabled (the default), the slider emits the-
431 valueChanged() signal while the slider is being dragged. If-
432 tracking is disabled, the slider emits the valueChanged() signal-
433 only when the user releases the slider.-
434-
435 \sa sliderDown-
436*/-
437void QAbstractSlider::setTracking(bool enable)-
438{-
439 Q_D(QAbstractSlider);-
440 d->tracking = enable;-
441}
never executed: end of block
0
442-
443bool QAbstractSlider::hasTracking() const-
444{-
445 Q_D(const QAbstractSlider);-
446 return d->tracking;
never executed: return d->tracking;
0
447}-
448-
449-
450/*!-
451 \property QAbstractSlider::sliderDown-
452 \brief whether the slider is pressed down.-
453-
454 The property is set by subclasses in order to let the abstract-
455 slider know whether or not \l tracking has any effect.-
456-
457 Changing the slider down property emits the sliderPressed() and-
458 sliderReleased() signals.-
459-
460*/-
461void QAbstractSlider::setSliderDown(bool down)-
462{-
463 Q_D(QAbstractSlider);-
464 bool doEmit = d->pressed != down;-
465-
466 d->pressed = down;-
467-
468 if (doEmit) {
doEmitDescription
TRUEnever evaluated
FALSEnever evaluated
0
469 if (down)
downDescription
TRUEnever evaluated
FALSEnever evaluated
0
470 emit sliderPressed();
never executed: sliderPressed();
0
471 else-
472 emit sliderReleased();
never executed: sliderReleased();
0
473 }-
474-
475 if (!down && d->position != d->value)
!downDescription
TRUEnever evaluated
FALSEnever evaluated
d->position != d->valueDescription
TRUEnever evaluated
FALSEnever evaluated
0
476 triggerAction(SliderMove);
never executed: triggerAction(SliderMove);
0
477}
never executed: end of block
0
478-
479bool QAbstractSlider::isSliderDown() const-
480{-
481 Q_D(const QAbstractSlider);-
482 return d->pressed;
never executed: return d->pressed;
0
483}-
484-
485-
486/*!-
487 \property QAbstractSlider::sliderPosition-
488 \brief the current slider position-
489-
490 If \l tracking is enabled (the default), this is identical to \l value.-
491*/-
492void QAbstractSlider::setSliderPosition(int position)-
493{-
494 Q_D(QAbstractSlider);-
495 position = d->bound(position);-
496 if (position == d->position)
position == d->positionDescription
TRUEnever evaluated
FALSEnever evaluated
0
497 return;
never executed: return;
0
498 d->position = position;-
499 if (!d->tracking)
!d->trackingDescription
TRUEnever evaluated
FALSEnever evaluated
0
500 update();
never executed: update();
0
501 if (d->pressed)
d->pressedDescription
TRUEnever evaluated
FALSEnever evaluated
0
502 emit sliderMoved(position);
never executed: sliderMoved(position);
0
503 if (d->tracking && !d->blocktracking)
d->trackingDescription
TRUEnever evaluated
FALSEnever evaluated
!d->blocktrackingDescription
TRUEnever evaluated
FALSEnever evaluated
0
504 triggerAction(SliderMove);
never executed: triggerAction(SliderMove);
0
505}
never executed: end of block
0
506-
507int QAbstractSlider::sliderPosition() const-
508{-
509 Q_D(const QAbstractSlider);-
510 return d->position;
never executed: return d->position;
0
511}-
512-
513-
514/*!-
515 \property QAbstractSlider::value-
516 \brief the slider's current value-
517-
518 The slider forces the value to be within the legal range: \l-
519 minimum <= \c value <= \l maximum.-
520-
521 Changing the value also changes the \l sliderPosition.-
522*/-
523-
524-
525int QAbstractSlider::value() const-
526{-
527 Q_D(const QAbstractSlider);-
528 return d->value;
never executed: return d->value;
0
529}-
530-
531void QAbstractSlider::setValue(int value)-
532{-
533 Q_D(QAbstractSlider);-
534 value = d->bound(value);-
535 if (d->value == value && d->position == value)
d->value == valueDescription
TRUEnever evaluated
FALSEnever evaluated
d->position == valueDescription
TRUEnever evaluated
FALSEnever evaluated
0
536 return;
never executed: return;
0
537 d->value = value;-
538 if (d->position != value) {
d->position != valueDescription
TRUEnever evaluated
FALSEnever evaluated
0
539 d->position = value;-
540 if (d->pressed)
d->pressedDescription
TRUEnever evaluated
FALSEnever evaluated
0
541 emit sliderMoved((d->position = value));
never executed: sliderMoved((d->position = value));
0
542 }
never executed: end of block
0
543#ifndef QT_NO_ACCESSIBILITY-
544 QAccessibleValueChangeEvent event(this, d->value);-
545 QAccessible::updateAccessibility(&event);-
546#endif-
547 sliderChange(SliderValueChange);-
548 emit valueChanged(value);-
549}
never executed: end of block
0
550-
551/*!-
552 \property QAbstractSlider::invertedAppearance-
553 \brief whether or not a slider shows its values inverted.-
554-
555 If this property is \c false (the default), the minimum and maximum will-
556 be shown in its classic position for the inherited widget. If the-
557 value is true, the minimum and maximum appear at their opposite location.-
558-
559 Note: This property makes most sense for sliders and dials. For-
560 scroll bars, the visual effect of the scroll bar subcontrols depends on-
561 whether or not the styles understand inverted appearance; most styles-
562 ignore this property for scroll bars.-
563*/-
564-
565bool QAbstractSlider::invertedAppearance() const-
566{-
567 Q_D(const QAbstractSlider);-
568 return d->invertedAppearance;
never executed: return d->invertedAppearance;
0
569}-
570-
571void QAbstractSlider::setInvertedAppearance(bool invert)-
572{-
573 Q_D(QAbstractSlider);-
574 d->invertedAppearance = invert;-
575 update();-
576}
never executed: end of block
0
577-
578-
579/*!-
580 \property QAbstractSlider::invertedControls-
581 \brief whether or not the slider inverts its wheel and key events.-
582-
583 If this property is \c false, scrolling the mouse wheel "up" and using keys-
584 like page up will increase the slider's value towards its maximum. Otherwise-
585 pressing page up will move value towards the slider's minimum.-
586*/-
587-
588-
589bool QAbstractSlider::invertedControls() const-
590{-
591 Q_D(const QAbstractSlider);-
592 return d->invertedControls;
never executed: return d->invertedControls;
0
593}-
594-
595void QAbstractSlider::setInvertedControls(bool invert)-
596{-
597 Q_D(QAbstractSlider);-
598 d->invertedControls = invert;-
599}
never executed: end of block
0
600-
601/*! Triggers a slider \a action. Possible actions are \l-
602 SliderSingleStepAdd, \l SliderSingleStepSub, \l SliderPageStepAdd,-
603 \l SliderPageStepSub, \l SliderToMinimum, \l SliderToMaximum, and \l-
604 SliderMove.-
605-
606 \sa actionTriggered()-
607 */-
608void QAbstractSlider::triggerAction(SliderAction action)-
609{-
610 Q_D(QAbstractSlider);-
611 d->blocktracking = true;-
612 switch (action) {-
613 case SliderSingleStepAdd:
never executed: case SliderSingleStepAdd:
0
614 setSliderPosition(d->overflowSafeAdd(d->effectiveSingleStep()));-
615 break;
never executed: break;
0
616 case SliderSingleStepSub:
never executed: case SliderSingleStepSub:
0
617 setSliderPosition(d->overflowSafeAdd(-d->effectiveSingleStep()));-
618 break;
never executed: break;
0
619 case SliderPageStepAdd:
never executed: case SliderPageStepAdd:
0
620 setSliderPosition(d->overflowSafeAdd(d->pageStep));-
621 break;
never executed: break;
0
622 case SliderPageStepSub:
never executed: case SliderPageStepSub:
0
623 setSliderPosition(d->overflowSafeAdd(-d->pageStep));-
624 break;
never executed: break;
0
625 case SliderToMinimum:
never executed: case SliderToMinimum:
0
626 setSliderPosition(d->minimum);-
627 break;
never executed: break;
0
628 case SliderToMaximum:
never executed: case SliderToMaximum:
0
629 setSliderPosition(d->maximum);-
630 break;
never executed: break;
0
631 case SliderMove:
never executed: case SliderMove:
0
632 case SliderNoAction:
never executed: case SliderNoAction:
0
633 break;
never executed: break;
0
634 };-
635 emit actionTriggered(action);-
636 d->blocktracking = false;-
637 setValue(d->position);-
638}
never executed: end of block
0
639-
640/*! Sets action \a action to be triggered repetitively in intervals-
641of \a repeatTime, after an initial delay of \a thresholdTime.-
642-
643\sa triggerAction(), repeatAction()-
644 */-
645void QAbstractSlider::setRepeatAction(SliderAction action, int thresholdTime, int repeatTime)-
646{-
647 Q_D(QAbstractSlider);-
648 if ((d->repeatAction = action) == SliderNoAction) {
(d->repeatActi...SliderNoActionDescription
TRUEnever evaluated
FALSEnever evaluated
0
649 d->repeatActionTimer.stop();-
650 } else {
never executed: end of block
0
651 d->repeatActionTime = repeatTime;-
652 d->repeatActionTimer.start(thresholdTime, this);-
653 }
never executed: end of block
0
654}-
655-
656/*!-
657 Returns the current repeat action.-
658 \sa setRepeatAction()-
659 */-
660QAbstractSlider::SliderAction QAbstractSlider::repeatAction() const-
661{-
662 Q_D(const QAbstractSlider);-
663 return d->repeatAction;
never executed: return d->repeatAction;
0
664}-
665-
666/*!\reimp-
667 */-
668void QAbstractSlider::timerEvent(QTimerEvent *e)-
669{-
670 Q_D(QAbstractSlider);-
671 if (e->timerId() == d->repeatActionTimer.timerId()) {
e->timerId() =...imer.timerId()Description
TRUEnever evaluated
FALSEnever evaluated
0
672 if (d->repeatActionTime) { // was threshold time, use repeat time next time
d->repeatActionTimeDescription
TRUEnever evaluated
FALSEnever evaluated
0
673 d->repeatActionTimer.start(d->repeatActionTime, this);-
674 d->repeatActionTime = 0;-
675 }
never executed: end of block
0
676 if (d->repeatAction == SliderPageStepAdd)
d->repeatActio...derPageStepAddDescription
TRUEnever evaluated
FALSEnever evaluated
0
677 d->setAdjustedSliderPosition(d->overflowSafeAdd(d->pageStep));
never executed: d->setAdjustedSliderPosition(d->overflowSafeAdd(d->pageStep));
0
678 else if (d->repeatAction == SliderPageStepSub)
d->repeatActio...derPageStepSubDescription
TRUEnever evaluated
FALSEnever evaluated
0
679 d->setAdjustedSliderPosition(d->overflowSafeAdd(-d->pageStep));
never executed: d->setAdjustedSliderPosition(d->overflowSafeAdd(-d->pageStep));
0
680 else-
681 triggerAction(d->repeatAction);
never executed: triggerAction(d->repeatAction);
0
682 }-
683}
never executed: end of block
0
684-
685/*!-
686 Reimplement this virtual function to track slider changes such as-
687 \l SliderRangeChange, \l SliderOrientationChange, \l-
688 SliderStepsChange, or \l SliderValueChange. The default-
689 implementation only updates the display and ignores the \a change-
690 parameter.-
691 */-
692void QAbstractSlider::sliderChange(SliderChange)-
693{-
694 update();-
695}
never executed: end of block
0
696-
697bool QAbstractSliderPrivate::scrollByDelta(Qt::Orientation orientation, Qt::KeyboardModifiers modifiers, int delta)-
698{-
699 Q_Q(QAbstractSlider);-
700 int stepsToScroll = 0;-
701 // in Qt scrolling to the right gives negative values.-
702 if (orientation == Qt::Horizontal)
orientation == Qt::HorizontalDescription
TRUEnever evaluated
FALSEnever evaluated
0
703 delta = -delta;
never executed: delta = -delta;
0
704 qreal offset = qreal(delta) / 120;-
705-
706 if ((modifiers & Qt::ControlModifier) || (modifiers & Qt::ShiftModifier)) {
(modifiers & Q...ntrolModifier)Description
TRUEnever evaluated
FALSEnever evaluated
(modifiers & Q...ShiftModifier)Description
TRUEnever evaluated
FALSEnever evaluated
0
707 // Scroll one page regardless of delta:-
708 stepsToScroll = qBound(-pageStep, int(offset * pageStep), pageStep);-
709 offset_accumulated = 0;-
710 } else {
never executed: end of block
0
711 // Calculate how many lines to scroll. Depending on what delta is (and-
712 // offset), we might end up with a fraction (e.g. scroll 1.3 lines). We can-
713 // only scroll whole lines, so we keep the reminder until next event.-
714 qreal stepsToScrollF =-
715#ifndef QT_NO_WHEELEVENT-
716 QApplication::wheelScrollLines() *-
717#endif-
718 offset * effectiveSingleStep();-
719 // Check if wheel changed direction since last event:-
720 if (offset_accumulated != 0 && (offset / offset_accumulated) < 0)
offset_accumulated != 0Description
TRUEnever evaluated
FALSEnever evaluated
(offset / offs...cumulated) < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
721 offset_accumulated = 0;
never executed: offset_accumulated = 0;
0
722-
723 offset_accumulated += stepsToScrollF;-
724#ifndef Q_DEAD_CODE_FROM_QT4_MAC-
725 // Don't scroll more than one page in any case:-
726 stepsToScroll = qBound(-pageStep, int(offset_accumulated), pageStep);-
727#else-
728 // Native UI-elements on Mac can scroll hundreds of lines at a time as-
729 // a result of acceleration. So keep the same behaviour in Qt, and-
730 // don't restrict stepsToScroll to certain maximum (pageStep):-
731 stepsToScroll = int(offset_accumulated);-
732#endif-
733 offset_accumulated -= int(offset_accumulated);-
734 if (stepsToScroll == 0) {
stepsToScroll == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
735 // We moved less than a line, but might still have accumulated partial scroll,-
736 // unless we already are at one of the ends.-
737 const float effective_offset = invertedControls ? -offset_accumulated : offset_accumulated;
invertedControlsDescription
TRUEnever evaluated
FALSEnever evaluated
0
738 if (effective_offset > 0.f && value < maximum)
effective_offset > 0.fDescription
TRUEnever evaluated
FALSEnever evaluated
value < maximumDescription
TRUEnever evaluated
FALSEnever evaluated
0
739 return true;
never executed: return true;
0
740 if (effective_offset < 0.f && value > minimum)
effective_offset < 0.fDescription
TRUEnever evaluated
FALSEnever evaluated
value > minimumDescription
TRUEnever evaluated
FALSEnever evaluated
0
741 return true;
never executed: return true;
0
742 offset_accumulated = 0;-
743 return false;
never executed: return false;
0
744 }-
745 }
never executed: end of block
0
746-
747 if (invertedControls)
invertedControlsDescription
TRUEnever evaluated
FALSEnever evaluated
0
748 stepsToScroll = -stepsToScroll;
never executed: stepsToScroll = -stepsToScroll;
0
749-
750 int prevValue = value;-
751 position = bound(overflowSafeAdd(stepsToScroll)); // value will be updated by triggerAction()-
752 q->triggerAction(QAbstractSlider::SliderMove);-
753-
754 if (prevValue == value) {
prevValue == valueDescription
TRUEnever evaluated
FALSEnever evaluated
0
755 offset_accumulated = 0;-
756 return false;
never executed: return false;
0
757 }-
758 return true;
never executed: return true;
0
759}-
760-
761/*!-
762 \reimp-
763*/-
764#ifndef QT_NO_WHEELEVENT-
765void QAbstractSlider::wheelEvent(QWheelEvent * e)-
766{-
767 Q_D(QAbstractSlider);-
768 e->ignore();-
769 int delta = e->delta();-
770 if (e->inverted())
e->inverted()Description
TRUEnever evaluated
FALSEnever evaluated
0
771 delta = -delta;
never executed: delta = -delta;
0
772 if (d->scrollByDelta(e->orientation(), e->modifiers(), delta))
d->scrollByDel...iers(), delta)Description
TRUEnever evaluated
FALSEnever evaluated
0
773 e->accept();
never executed: e->accept();
0
774}
never executed: end of block
0
775-
776#endif-
777-
778/*!-
779 \reimp-
780*/-
781void QAbstractSlider::keyPressEvent(QKeyEvent *ev)-
782{-
783 Q_D(QAbstractSlider);-
784 SliderAction action = SliderNoAction;-
785#ifdef QT_KEYPAD_NAVIGATION-
786 if (ev->isAutoRepeat()) {-
787 if (!d->firstRepeat.isValid())-
788 d->firstRepeat.start();-
789 else if (1 == d->repeatMultiplier) {-
790 // This is the interval in milli seconds which one key repetition-
791 // takes.-
792 const int repeatMSecs = d->firstRepeat.elapsed();-
793-
794 /**-
795 * The time it takes to currently navigate the whole slider.-
796 */-
797 const qreal currentTimeElapse = (qreal(maximum()) / singleStep()) * repeatMSecs;-
798-
799 /**-
800 * This is an arbitrarily determined constant in msecs that-
801 * specifies how long time it should take to navigate from the-
802 * start to the end(excluding starting key auto repeat).-
803 */-
804 const int SliderRepeatElapse = 2500;-
805-
806 d->repeatMultiplier = currentTimeElapse / SliderRepeatElapse;-
807 }-
808-
809 }-
810 else if (d->firstRepeat.isValid()) {-
811 d->firstRepeat.invalidate();-
812 d->repeatMultiplier = 1;-
813 }-
814-
815#endif-
816-
817 switch (ev->key()) {-
818#ifdef QT_KEYPAD_NAVIGATION-
819 case Qt::Key_Select:-
820 if (QApplication::keypadNavigationEnabled())-
821 setEditFocus(!hasEditFocus());-
822 else-
823 ev->ignore();-
824 break;-
825 case Qt::Key_Back:-
826 if (QApplication::keypadNavigationEnabled() && hasEditFocus()) {-
827 setValue(d->origValue);-
828 setEditFocus(false);-
829 } else-
830 ev->ignore();-
831 break;-
832#endif-
833-
834 // It seems we need to use invertedAppearance for Left and right, otherwise, things look weird.-
835 case Qt::Key_Left:
never executed: case Qt::Key_Left:
0
836#ifdef QT_KEYPAD_NAVIGATION-
837 // In QApplication::KeypadNavigationDirectional, we want to change the slider-
838 // value if there is no left/right navigation possible and if this slider is not-
839 // inside a tab widget.-
840 if (QApplication::keypadNavigationEnabled()-
841 && (!hasEditFocus() && QApplication::navigationMode() == Qt::NavigationModeKeypadTabOrder-
842 || d->orientation == Qt::Vertical-
843 || !hasEditFocus()-
844 && (QWidgetPrivate::canKeypadNavigate(Qt::Horizontal) || QWidgetPrivate::inTabWidget(this)))) {-
845 ev->ignore();-
846 return;-
847 }-
848 if (QApplication::keypadNavigationEnabled() && d->orientation == Qt::Vertical)-
849 action = d->invertedControls ? SliderSingleStepSub : SliderSingleStepAdd;-
850 else-
851#endif-
852 if (isRightToLeft())
isRightToLeft()Description
TRUEnever evaluated
FALSEnever evaluated
0
853 action = d->invertedAppearance ? SliderSingleStepSub : SliderSingleStepAdd;
never executed: action = d->invertedAppearance ? SliderSingleStepSub : SliderSingleStepAdd;
d->invertedAppearanceDescription
TRUEnever evaluated
FALSEnever evaluated
0
854 else-
855 action = !d->invertedAppearance ? SliderSingleStepSub : SliderSingleStepAdd;
never executed: action = !d->invertedAppearance ? SliderSingleStepSub : SliderSingleStepAdd;
!d->invertedAppearanceDescription
TRUEnever evaluated
FALSEnever evaluated
0
856 break;
never executed: break;
0
857 case Qt::Key_Right:
never executed: case Qt::Key_Right:
0
858#ifdef QT_KEYPAD_NAVIGATION-
859 // Same logic as in Qt::Key_Left-
860 if (QApplication::keypadNavigationEnabled()-
861 && (!hasEditFocus() && QApplication::navigationMode() == Qt::NavigationModeKeypadTabOrder-
862 || d->orientation == Qt::Vertical-
863 || !hasEditFocus()-
864 && (QWidgetPrivate::canKeypadNavigate(Qt::Horizontal) || QWidgetPrivate::inTabWidget(this)))) {-
865 ev->ignore();-
866 return;-
867 }-
868 if (QApplication::keypadNavigationEnabled() && d->orientation == Qt::Vertical)-
869 action = d->invertedControls ? SliderSingleStepAdd : SliderSingleStepSub;-
870 else-
871#endif-
872 if (isRightToLeft())
isRightToLeft()Description
TRUEnever evaluated
FALSEnever evaluated
0
873 action = d->invertedAppearance ? SliderSingleStepAdd : SliderSingleStepSub;
never executed: action = d->invertedAppearance ? SliderSingleStepAdd : SliderSingleStepSub;
d->invertedAppearanceDescription
TRUEnever evaluated
FALSEnever evaluated
0
874 else-
875 action = !d->invertedAppearance ? SliderSingleStepAdd : SliderSingleStepSub;
never executed: action = !d->invertedAppearance ? SliderSingleStepAdd : SliderSingleStepSub;
!d->invertedAppearanceDescription
TRUEnever evaluated
FALSEnever evaluated
0
876 break;
never executed: break;
0
877 case Qt::Key_Up:
never executed: case Qt::Key_Up:
0
878#ifdef QT_KEYPAD_NAVIGATION-
879 // In QApplication::KeypadNavigationDirectional, we want to change the slider-
880 // value if there is no up/down navigation possible.-
881 if (QApplication::keypadNavigationEnabled()-
882 && (QApplication::navigationMode() == Qt::NavigationModeKeypadTabOrder-
883 || d->orientation == Qt::Horizontal-
884 || !hasEditFocus() && QWidgetPrivate::canKeypadNavigate(Qt::Vertical))) {-
885 ev->ignore();-
886 break;-
887 }-
888#endif-
889 action = d->invertedControls ? SliderSingleStepSub : SliderSingleStepAdd;
d->invertedControlsDescription
TRUEnever evaluated
FALSEnever evaluated
0
890 break;
never executed: break;
0
891 case Qt::Key_Down:
never executed: case Qt::Key_Down:
0
892#ifdef QT_KEYPAD_NAVIGATION-
893 // Same logic as in Qt::Key_Up-
894 if (QApplication::keypadNavigationEnabled()-
895 && (QApplication::navigationMode() == Qt::NavigationModeKeypadTabOrder-
896 || d->orientation == Qt::Horizontal-
897 || !hasEditFocus() && QWidgetPrivate::canKeypadNavigate(Qt::Vertical))) {-
898 ev->ignore();-
899 break;-
900 }-
901#endif-
902 action = d->invertedControls ? SliderSingleStepAdd : SliderSingleStepSub;
d->invertedControlsDescription
TRUEnever evaluated
FALSEnever evaluated
0
903 break;
never executed: break;
0
904 case Qt::Key_PageUp:
never executed: case Qt::Key_PageUp:
0
905 action = d->invertedControls ? SliderPageStepSub : SliderPageStepAdd;
d->invertedControlsDescription
TRUEnever evaluated
FALSEnever evaluated
0
906 break;
never executed: break;
0
907 case Qt::Key_PageDown:
never executed: case Qt::Key_PageDown:
0
908 action = d->invertedControls ? SliderPageStepAdd : SliderPageStepSub;
d->invertedControlsDescription
TRUEnever evaluated
FALSEnever evaluated
0
909 break;
never executed: break;
0
910 case Qt::Key_Home:
never executed: case Qt::Key_Home:
0
911 action = SliderToMinimum;-
912 break;
never executed: break;
0
913 case Qt::Key_End:
never executed: case Qt::Key_End:
0
914 action = SliderToMaximum;-
915 break;
never executed: break;
0
916 default:
never executed: default:
0
917 ev->ignore();-
918 break;
never executed: break;
0
919 }-
920 if (action)
actionDescription
TRUEnever evaluated
FALSEnever evaluated
0
921 triggerAction(action);
never executed: triggerAction(action);
0
922}
never executed: end of block
0
923-
924/*!-
925 \reimp-
926*/-
927void QAbstractSlider::changeEvent(QEvent *ev)-
928{-
929 Q_D(QAbstractSlider);-
930 switch (ev->type()) {-
931 case QEvent::EnabledChange:
never executed: case QEvent::EnabledChange:
0
932 if (!isEnabled()) {
!isEnabled()Description
TRUEnever evaluated
FALSEnever evaluated
0
933 d->repeatActionTimer.stop();-
934 setSliderDown(false);-
935 }
never executed: end of block
0
936 // fall through...-
937 default:
code before this statement never executed: default:
never executed: default:
0
938 QWidget::changeEvent(ev);-
939 }
never executed: end of block
0
940}-
941-
942/*!-
943 \reimp-
944*/-
945bool QAbstractSlider::event(QEvent *e)-
946{-
947#ifdef QT_KEYPAD_NAVIGATION-
948 Q_D(QAbstractSlider);-
949 switch (e->type()) {-
950 case QEvent::FocusIn:-
951 d->origValue = d->value;-
952 break;-
953 default:-
954 break;-
955 }-
956#endif-
957-
958 return QWidget::event(e);
never executed: return QWidget::event(e);
0
959}-
960-
961// This function is called from itemviews when doing scroll per pixel (on updateGeometries())-
962// It will not have any effect if there has been a call to setSingleStep with-
963// a 'reasonable' value (since viewMayChangeSingleStep will be set to false).-
964// (If setSingleStep is called with -1 it will however allow the views to change singleStep.)-
965-
966void QAbstractSliderPrivate::itemviewChangeSingleStep(int step)-
967{-
968 singleStepFromItemView = step;-
969 if (viewMayChangeSingleStep && singleStep != step)
viewMayChangeSingleStepDescription
TRUEnever evaluated
FALSEnever evaluated
singleStep != stepDescription
TRUEnever evaluated
FALSEnever evaluated
0
970 setSteps(step, pageStep);
never executed: setSteps(step, pageStep);
0
971}
never executed: end of block
0
972-
973QT_END_NAMESPACE-
974-
975#include "moc_qabstractslider.cpp"-
Source codeSwitch to Preprocessed file

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