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