source: trunk/src/gui/widgets/qabstractslider.cpp@ 348

Last change on this file since 348 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

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