| 1 | /**************************************************************************** | 
|---|
| 2 | ** | 
|---|
| 3 | ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). | 
|---|
| 4 | ** All rights reserved. | 
|---|
| 5 | ** Contact: Nokia Corporation (qt-info@nokia.com) | 
|---|
| 6 | ** | 
|---|
| 7 | ** This file is part of the QtGui module of the Qt Toolkit. | 
|---|
| 8 | ** | 
|---|
| 9 | ** $QT_BEGIN_LICENSE:LGPL$ | 
|---|
| 10 | ** Commercial Usage | 
|---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in | 
|---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the | 
|---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in | 
|---|
| 14 | ** a written agreement between you and Nokia. | 
|---|
| 15 | ** | 
|---|
| 16 | ** GNU Lesser General Public License Usage | 
|---|
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser | 
|---|
| 18 | ** General Public License version 2.1 as published by the Free Software | 
|---|
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the | 
|---|
| 20 | ** packaging of this file.  Please review the following information to | 
|---|
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements | 
|---|
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | 
|---|
| 23 | ** | 
|---|
| 24 | ** In addition, as a special exception, Nokia gives you certain additional | 
|---|
| 25 | ** rights.  These rights are described in the Nokia Qt LGPL Exception | 
|---|
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this 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 have questions regarding the use of this file, please contact | 
|---|
| 37 | ** Nokia at qt-info@nokia.com. | 
|---|
| 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 | #ifdef QT_KEYPAD_NAVIGATION | 
|---|
| 51 | #include "qtabwidget.h" // Needed in inTabWidget() | 
|---|
| 52 | #endif // QT_KEYPAD_NAVIGATION | 
|---|
| 53 | #include <limits.h> | 
|---|
| 54 |  | 
|---|
| 55 | QT_BEGIN_NAMESPACE | 
|---|
| 56 |  | 
|---|
| 57 | /*! | 
|---|
| 58 | \class QAbstractSlider | 
|---|
| 59 | \brief The QAbstractSlider class provides an integer value within a range. | 
|---|
| 60 |  | 
|---|
| 61 | \ingroup abstractwidgets | 
|---|
| 62 |  | 
|---|
| 63 | The class is designed as a common super class for widgets like | 
|---|
| 64 | QScrollBar, QSlider and QDial. | 
|---|
| 65 |  | 
|---|
| 66 | Here are the main properties of the class: | 
|---|
| 67 |  | 
|---|
| 68 | \list 1 | 
|---|
| 69 |  | 
|---|
| 70 | \i \l value: The bounded integer that QAbstractSlider maintains. | 
|---|
| 71 |  | 
|---|
| 72 | \i \l minimum: The lowest possible value. | 
|---|
| 73 |  | 
|---|
| 74 | \i \l maximum: The highest possible value. | 
|---|
| 75 |  | 
|---|
| 76 | \i \l singleStep: The smaller of two natural steps that an | 
|---|
| 77 | abstract sliders provides and typically corresponds to the user | 
|---|
| 78 | pressing an arrow key. | 
|---|
| 79 |  | 
|---|
| 80 | \i \l pageStep: The larger of two natural steps that an abstract | 
|---|
| 81 | slider provides and typically corresponds to the user pressing | 
|---|
| 82 | PageUp or PageDown. | 
|---|
| 83 |  | 
|---|
| 84 | \i \l tracking: Whether slider tracking is enabled. | 
|---|
| 85 |  | 
|---|
| 86 | \i \l sliderPosition: The current position of the slider. If \l | 
|---|
| 87 | tracking is enabled (the default), this is identical to \l value. | 
|---|
| 88 |  | 
|---|
| 89 | \endlist | 
|---|
| 90 |  | 
|---|
| 91 | Unity (1) may be viewed as a third step size. setValue() lets you | 
|---|
| 92 | set the current value to any integer in the allowed range, not | 
|---|
| 93 | just minimum() + \e n * singleStep() for integer values of \e n. | 
|---|
| 94 | Some widgets may allow the user to set any value at all; others | 
|---|
| 95 | may just provide multiples of singleStep() or pageStep(). | 
|---|
| 96 |  | 
|---|
| 97 | QAbstractSlider emits a comprehensive set of signals: | 
|---|
| 98 |  | 
|---|
| 99 | \table | 
|---|
| 100 | \header \i Signal \i Emitted when | 
|---|
| 101 | \row \i \l valueChanged() | 
|---|
| 102 | \i the value has changed. The \l tracking | 
|---|
| 103 | determines whether this signal is emitted during user | 
|---|
| 104 | interaction. | 
|---|
| 105 | \row \i \l sliderPressed() | 
|---|
| 106 | \i the user starts to drag the slider. | 
|---|
| 107 | \row \i \l sliderMoved() | 
|---|
| 108 | \i the user drags the slider. | 
|---|
| 109 | \row \i \l sliderReleased() | 
|---|
| 110 | \i the user releases the slider. | 
|---|
| 111 | \row \i \l actionTriggered() | 
|---|
| 112 | \i a slider action was triggerd. | 
|---|
| 113 | \row \i \l rangeChanged() | 
|---|
| 114 | \i a the range has changed. | 
|---|
| 115 | \endtable | 
|---|
| 116 |  | 
|---|
| 117 | QAbstractSlider provides a virtual sliderChange() function that is | 
|---|
| 118 | well suited for updating the on-screen representation of | 
|---|
| 119 | sliders. By calling triggerAction(), subclasses trigger slider | 
|---|
| 120 | actions. Two helper functions QStyle::sliderPositionFromValue() and | 
|---|
| 121 | QStyle::sliderValueFromPosition() help subclasses and styles to map | 
|---|
| 122 | screen coordinates to logical range values. | 
|---|
| 123 |  | 
|---|
| 124 | \sa QAbstractSpinBox, QSlider, QDial, QScrollBar, {Sliders Example} | 
|---|
| 125 | */ | 
|---|
| 126 |  | 
|---|
| 127 | /*! | 
|---|
| 128 | \enum QAbstractSlider::SliderAction | 
|---|
| 129 |  | 
|---|
| 130 | \value SliderNoAction | 
|---|
| 131 | \value SliderSingleStepAdd | 
|---|
| 132 | \value SliderSingleStepSub | 
|---|
| 133 | \value SliderPageStepAdd | 
|---|
| 134 | \value SliderPageStepSub | 
|---|
| 135 | \value SliderToMinimum | 
|---|
| 136 | \value SliderToMaximum | 
|---|
| 137 | \value SliderMove | 
|---|
| 138 |  | 
|---|
| 139 | */ | 
|---|
| 140 |  | 
|---|
| 141 | /*! | 
|---|
| 142 | \fn void QAbstractSlider::valueChanged(int value) | 
|---|
| 143 |  | 
|---|
| 144 | This signal is emitted when the slider value has changed, with the | 
|---|
| 145 | new slider \a value as argument. | 
|---|
| 146 | */ | 
|---|
| 147 |  | 
|---|
| 148 | /*! | 
|---|
| 149 | \fn void QAbstractSlider::sliderPressed() | 
|---|
| 150 |  | 
|---|
| 151 | This signal is emitted when the user presses the slider with the | 
|---|
| 152 | mouse, or programmatically when setSliderDown(true) is called. | 
|---|
| 153 |  | 
|---|
| 154 | \sa sliderReleased(), sliderMoved(), isSliderDown() | 
|---|
| 155 | */ | 
|---|
| 156 |  | 
|---|
| 157 | /*! | 
|---|
| 158 | \fn void QAbstractSlider::sliderMoved(int value) | 
|---|
| 159 |  | 
|---|
| 160 | This signal is emitted when sliderDown is true and the slider moves. This | 
|---|
| 161 | usually happens when the user is dragging the slider. The \a value | 
|---|
| 162 | is the new slider position. | 
|---|
| 163 |  | 
|---|
| 164 | This signal is emitted even when tracking is turned off. | 
|---|
| 165 |  | 
|---|
| 166 | \sa setTracking(), valueChanged(), isSliderDown(), | 
|---|
| 167 | sliderPressed(), sliderReleased() | 
|---|
| 168 | */ | 
|---|
| 169 |  | 
|---|
| 170 | /*! | 
|---|
| 171 | \fn void QAbstractSlider::sliderReleased() | 
|---|
| 172 |  | 
|---|
| 173 | This signal is emitted when the user releases the slider with the | 
|---|
| 174 | mouse, or programmatically when setSliderDown(false) is called. | 
|---|
| 175 |  | 
|---|
| 176 | \sa sliderPressed() sliderMoved() sliderDown | 
|---|
| 177 | */ | 
|---|
| 178 |  | 
|---|
| 179 | /*! | 
|---|
| 180 | \fn void QAbstractSlider::rangeChanged(int min, int max) | 
|---|
| 181 |  | 
|---|
| 182 | This signal is emitted when the slider range has changed, with \a | 
|---|
| 183 | min being the new minimum, and \a max being the new maximum. | 
|---|
| 184 |  | 
|---|
| 185 | \sa minimum, maximum | 
|---|
| 186 | */ | 
|---|
| 187 |  | 
|---|
| 188 | /*! | 
|---|
| 189 | \fn void QAbstractSlider::actionTriggered(int action) | 
|---|
| 190 |  | 
|---|
| 191 | This signal is emitted when the slider action \a action is | 
|---|
| 192 | triggered. Actions are \l SliderSingleStepAdd, \l | 
|---|
| 193 | SliderSingleStepSub, \l SliderPageStepAdd, \l SliderPageStepSub, | 
|---|
| 194 | \l SliderToMinimum, \l SliderToMaximum, and \l SliderMove. | 
|---|
| 195 |  | 
|---|
| 196 | When the signal is emitted, the \l sliderPosition has been | 
|---|
| 197 | adjusted according to the action, but the \l value has not yet | 
|---|
| 198 | been propagated (meaning the valueChanged() signal was not yet | 
|---|
| 199 | emitted), and the visual display has not been updated. In slots | 
|---|
| 200 | connected to this signal you can thus safely adjust any action by | 
|---|
| 201 | calling setSliderPosition() yourself, based on both the action and | 
|---|
| 202 | the slider's value. | 
|---|
| 203 |  | 
|---|
| 204 | \sa triggerAction() | 
|---|
| 205 | */ | 
|---|
| 206 |  | 
|---|
| 207 | /*! | 
|---|
| 208 | \enum QAbstractSlider::SliderChange | 
|---|
| 209 |  | 
|---|
| 210 | \value SliderRangeChange | 
|---|
| 211 | \value SliderOrientationChange | 
|---|
| 212 | \value SliderStepsChange | 
|---|
| 213 | \value SliderValueChange | 
|---|
| 214 | */ | 
|---|
| 215 |  | 
|---|
| 216 | QAbstractSliderPrivate::QAbstractSliderPrivate() | 
|---|
| 217 | : minimum(0), maximum(99), singleStep(1), pageStep(10), | 
|---|
| 218 | value(0), position(0), pressValue(-1), offset_accumulated(0), tracking(true), | 
|---|
| 219 | blocktracking(false), pressed(false), | 
|---|
| 220 | invertedAppearance(false), invertedControls(false), | 
|---|
| 221 | orientation(Qt::Horizontal), repeatAction(QAbstractSlider::SliderNoAction) | 
|---|
| 222 | #ifdef QT_KEYPAD_NAVIGATION | 
|---|
| 223 | , isAutoRepeating(false) | 
|---|
| 224 | , repeatMultiplier(1) | 
|---|
| 225 | #endif | 
|---|
| 226 | { | 
|---|
| 227 | } | 
|---|
| 228 |  | 
|---|
| 229 | QAbstractSliderPrivate::~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 | */ | 
|---|
| 241 | void 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) { | 
|---|
| 249 | sliderChange(SliderRangeChange); | 
|---|
| 250 | emit rangeChanged(d->minimum, d->maximum); | 
|---|
| 251 | setValue(d->value); // re-bound | 
|---|
| 252 | } | 
|---|
| 253 | } | 
|---|
| 254 |  | 
|---|
| 255 |  | 
|---|
| 256 | void 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 | } | 
|---|
| 263 |  | 
|---|
| 264 | /*! | 
|---|
| 265 | Constructs an abstract slider. | 
|---|
| 266 |  | 
|---|
| 267 | The \a parent arguments 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 | */ | 
|---|
| 273 | QAbstractSlider::QAbstractSlider(QWidget *parent) | 
|---|
| 274 | :QWidget(*new QAbstractSliderPrivate, parent, 0) | 
|---|
| 275 | { | 
|---|
| 276 | } | 
|---|
| 277 |  | 
|---|
| 278 | /*! \internal */ | 
|---|
| 279 | QAbstractSlider::QAbstractSlider(QAbstractSliderPrivate &dd, QWidget *parent) | 
|---|
| 280 | :QWidget(dd, parent, 0) | 
|---|
| 281 | { | 
|---|
| 282 | } | 
|---|
| 283 |  | 
|---|
| 284 | /*! | 
|---|
| 285 | Destroys the slider. | 
|---|
| 286 | */ | 
|---|
| 287 | QAbstractSlider::~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 | */ | 
|---|
| 298 | void QAbstractSlider::setOrientation(Qt::Orientation orientation) | 
|---|
| 299 | { | 
|---|
| 300 | Q_D(QAbstractSlider); | 
|---|
| 301 | if (d->orientation == orientation) | 
|---|
| 302 | return; | 
|---|
| 303 |  | 
|---|
| 304 | d->orientation = orientation; | 
|---|
| 305 | if (!testAttribute(Qt::WA_WState_OwnSizePolicy)) { | 
|---|
| 306 | QSizePolicy sp = sizePolicy(); | 
|---|
| 307 | sp.transpose(); | 
|---|
| 308 | setSizePolicy(sp); | 
|---|
| 309 | setAttribute(Qt::WA_WState_OwnSizePolicy, false); | 
|---|
| 310 | } | 
|---|
| 311 | update(); | 
|---|
| 312 | updateGeometry(); | 
|---|
| 313 | } | 
|---|
| 314 |  | 
|---|
| 315 | Qt::Orientation QAbstractSlider::orientation() const | 
|---|
| 316 | { | 
|---|
| 317 | Q_D(const QAbstractSlider); | 
|---|
| 318 | return d->orientation; | 
|---|
| 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 |  | 
|---|
| 332 | void QAbstractSlider::setMinimum(int min) | 
|---|
| 333 | { | 
|---|
| 334 | Q_D(QAbstractSlider); | 
|---|
| 335 | setRange(min, qMax(d->maximum, min)); | 
|---|
| 336 | } | 
|---|
| 337 |  | 
|---|
| 338 | int QAbstractSlider::minimum() const | 
|---|
| 339 | { | 
|---|
| 340 | Q_D(const QAbstractSlider); | 
|---|
| 341 | return d->minimum; | 
|---|
| 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 |  | 
|---|
| 356 | void QAbstractSlider::setMaximum(int max) | 
|---|
| 357 | { | 
|---|
| 358 | Q_D(QAbstractSlider); | 
|---|
| 359 | setRange(qMin(d->minimum, max), max); | 
|---|
| 360 | } | 
|---|
| 361 |  | 
|---|
| 362 | int QAbstractSlider::maximum() const | 
|---|
| 363 | { | 
|---|
| 364 | Q_D(const QAbstractSlider); | 
|---|
| 365 | return d->maximum; | 
|---|
| 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 |  | 
|---|
| 384 | void QAbstractSlider::setSingleStep(int step) | 
|---|
| 385 | { | 
|---|
| 386 | Q_D(QAbstractSlider); | 
|---|
| 387 | if (step != d->singleStep) | 
|---|
| 388 | d->setSteps(step, d->pageStep); | 
|---|
| 389 | } | 
|---|
| 390 |  | 
|---|
| 391 | int QAbstractSlider::singleStep() const | 
|---|
| 392 | { | 
|---|
| 393 | Q_D(const QAbstractSlider); | 
|---|
| 394 | return d->singleStep; | 
|---|
| 395 | } | 
|---|
| 396 |  | 
|---|
| 397 |  | 
|---|
| 398 | /*! | 
|---|
| 399 | \property QAbstractSlider::pageStep | 
|---|
| 400 | \brief the page step. | 
|---|
| 401 |  | 
|---|
| 402 | The larger of two natural steps that an abstract slider provides | 
|---|
| 403 | and typically corresponds to the user pressing PageUp or PageDown. | 
|---|
| 404 |  | 
|---|
| 405 | \sa singleStep | 
|---|
| 406 | */ | 
|---|
| 407 |  | 
|---|
| 408 | void QAbstractSlider::setPageStep(int step) | 
|---|
| 409 | { | 
|---|
| 410 | Q_D(QAbstractSlider); | 
|---|
| 411 | if (step != d->pageStep) | 
|---|
| 412 | d->setSteps(d->singleStep, step); | 
|---|
| 413 | } | 
|---|
| 414 |  | 
|---|
| 415 | int QAbstractSlider::pageStep() const | 
|---|
| 416 | { | 
|---|
| 417 | Q_D(const QAbstractSlider); | 
|---|
| 418 | return d->pageStep; | 
|---|
| 419 | } | 
|---|
| 420 |  | 
|---|
| 421 | /*! | 
|---|
| 422 | \property QAbstractSlider::tracking | 
|---|
| 423 | \brief whether slider tracking is enabled | 
|---|
| 424 |  | 
|---|
| 425 | If tracking is enabled (the default), the slider emits the | 
|---|
| 426 | valueChanged() signal while the slider is being dragged. If | 
|---|
| 427 | tracking is disabled, the slider emits the valueChanged() signal | 
|---|
| 428 | only when the user releases the slider. | 
|---|
| 429 |  | 
|---|
| 430 | \sa sliderDown | 
|---|
| 431 | */ | 
|---|
| 432 | void QAbstractSlider::setTracking(bool enable) | 
|---|
| 433 | { | 
|---|
| 434 | Q_D(QAbstractSlider); | 
|---|
| 435 | d->tracking = enable; | 
|---|
| 436 | } | 
|---|
| 437 |  | 
|---|
| 438 | bool QAbstractSlider::hasTracking() const | 
|---|
| 439 | { | 
|---|
| 440 | Q_D(const QAbstractSlider); | 
|---|
| 441 | return d->tracking; | 
|---|
| 442 | } | 
|---|
| 443 |  | 
|---|
| 444 |  | 
|---|
| 445 | /*! | 
|---|
| 446 | \property QAbstractSlider::sliderDown | 
|---|
| 447 | \brief whether the slider is pressed down. | 
|---|
| 448 |  | 
|---|
| 449 | The property is set by subclasses in order to let the abstract | 
|---|
| 450 | slider know whether or not \l tracking has any effect. | 
|---|
| 451 |  | 
|---|
| 452 | Changing the slider down property emits the sliderPressed() and | 
|---|
| 453 | sliderReleased() signals. | 
|---|
| 454 |  | 
|---|
| 455 | */ | 
|---|
| 456 | void QAbstractSlider::setSliderDown(bool down) | 
|---|
| 457 | { | 
|---|
| 458 | Q_D(QAbstractSlider); | 
|---|
| 459 | bool doEmit = d->pressed != down; | 
|---|
| 460 |  | 
|---|
| 461 | d->pressed = down; | 
|---|
| 462 |  | 
|---|
| 463 | if (doEmit) { | 
|---|
| 464 | if (down) | 
|---|
| 465 | emit sliderPressed(); | 
|---|
| 466 | else | 
|---|
| 467 | emit sliderReleased(); | 
|---|
| 468 | } | 
|---|
| 469 |  | 
|---|
| 470 | if (!down && d->position != d->value) | 
|---|
| 471 | triggerAction(SliderMove); | 
|---|
| 472 | } | 
|---|
| 473 |  | 
|---|
| 474 | bool QAbstractSlider::isSliderDown() const | 
|---|
| 475 | { | 
|---|
| 476 | Q_D(const QAbstractSlider); | 
|---|
| 477 | return d->pressed; | 
|---|
| 478 | } | 
|---|
| 479 |  | 
|---|
| 480 |  | 
|---|
| 481 | /*! | 
|---|
| 482 | \property QAbstractSlider::sliderPosition | 
|---|
| 483 | \brief the current slider position | 
|---|
| 484 |  | 
|---|
| 485 | If \l tracking is enabled (the default), this is identical to \l value. | 
|---|
| 486 | */ | 
|---|
| 487 | void QAbstractSlider::setSliderPosition(int position) | 
|---|
| 488 | { | 
|---|
| 489 | Q_D(QAbstractSlider); | 
|---|
| 490 | position = d->bound(position); | 
|---|
| 491 | if (position == d->position) | 
|---|
| 492 | return; | 
|---|
| 493 | d->position = position; | 
|---|
| 494 | if (!d->tracking) | 
|---|
| 495 | update(); | 
|---|
| 496 | if (d->pressed) | 
|---|
| 497 | emit sliderMoved(position); | 
|---|
| 498 | if (d->tracking && !d->blocktracking) | 
|---|
| 499 | triggerAction(SliderMove); | 
|---|
| 500 | } | 
|---|
| 501 |  | 
|---|
| 502 | int QAbstractSlider::sliderPosition() const | 
|---|
| 503 | { | 
|---|
| 504 | Q_D(const QAbstractSlider); | 
|---|
| 505 | return d->position; | 
|---|
| 506 | } | 
|---|
| 507 |  | 
|---|
| 508 |  | 
|---|
| 509 | /*! | 
|---|
| 510 | \property QAbstractSlider::value | 
|---|
| 511 | \brief the slider's current value | 
|---|
| 512 |  | 
|---|
| 513 | The slider forces the value to be within the legal range: \l | 
|---|
| 514 | minimum <= \c value <= \l maximum. | 
|---|
| 515 |  | 
|---|
| 516 | Changing the value also changes the \l sliderPosition. | 
|---|
| 517 | */ | 
|---|
| 518 |  | 
|---|
| 519 |  | 
|---|
| 520 | int QAbstractSlider::value() const | 
|---|
| 521 | { | 
|---|
| 522 | Q_D(const QAbstractSlider); | 
|---|
| 523 | return d->value; | 
|---|
| 524 | } | 
|---|
| 525 |  | 
|---|
| 526 | void QAbstractSlider::setValue(int value) | 
|---|
| 527 | { | 
|---|
| 528 | Q_D(QAbstractSlider); | 
|---|
| 529 | value = d->bound(value); | 
|---|
| 530 | if (d->value == value && d->position == value) | 
|---|
| 531 | return; | 
|---|
| 532 | d->value = value; | 
|---|
| 533 | if (d->position != value) { | 
|---|
| 534 | d->position = value; | 
|---|
| 535 | if (d->pressed) | 
|---|
| 536 | emit sliderMoved((d->position = value)); | 
|---|
| 537 | } | 
|---|
| 538 | #ifndef QT_NO_ACCESSIBILITY | 
|---|
| 539 | QAccessible::updateAccessibility(this, 0, QAccessible::ValueChanged); | 
|---|
| 540 | #endif | 
|---|
| 541 | sliderChange(SliderValueChange); | 
|---|
| 542 | emit valueChanged(value); | 
|---|
| 543 | } | 
|---|
| 544 |  | 
|---|
| 545 | /*! | 
|---|
| 546 | \property QAbstractSlider::invertedAppearance | 
|---|
| 547 | \brief whether or not a slider shows its values inverted. | 
|---|
| 548 |  | 
|---|
| 549 | If this property is false (the default), the minimum and maximum will | 
|---|
| 550 | be shown in its classic position for the inherited widget. If the | 
|---|
| 551 | value is true, the minimum and maximum appear at their opposite location. | 
|---|
| 552 |  | 
|---|
| 553 | Note: This property makes most sense for sliders and dials. For | 
|---|
| 554 | scroll bars, the visual effect of the scroll bar subcontrols depends on | 
|---|
| 555 | whether or not the styles understand inverted appearance; most styles | 
|---|
| 556 | ignore this property for scroll bars. | 
|---|
| 557 | */ | 
|---|
| 558 |  | 
|---|
| 559 | bool QAbstractSlider::invertedAppearance() const | 
|---|
| 560 | { | 
|---|
| 561 | Q_D(const QAbstractSlider); | 
|---|
| 562 | return d->invertedAppearance; | 
|---|
| 563 | } | 
|---|
| 564 |  | 
|---|
| 565 | void QAbstractSlider::setInvertedAppearance(bool invert) | 
|---|
| 566 | { | 
|---|
| 567 | Q_D(QAbstractSlider); | 
|---|
| 568 | d->invertedAppearance = invert; | 
|---|
| 569 | update(); | 
|---|
| 570 | } | 
|---|
| 571 |  | 
|---|
| 572 |  | 
|---|
| 573 | /*! | 
|---|
| 574 | \property QAbstractSlider::invertedControls | 
|---|
| 575 | \brief whether or not the slider inverts its wheel and key events. | 
|---|
| 576 |  | 
|---|
| 577 | If this property is false, scrolling the mouse wheel "up" and using keys | 
|---|
| 578 | like page up will increase the slider's value towards its maximum. Otherwise | 
|---|
| 579 | pressing page up will move value towards the slider's minimum. | 
|---|
| 580 | */ | 
|---|
| 581 |  | 
|---|
| 582 |  | 
|---|
| 583 | bool QAbstractSlider::invertedControls() const | 
|---|
| 584 | { | 
|---|
| 585 | Q_D(const QAbstractSlider); | 
|---|
| 586 | return d->invertedControls; | 
|---|
| 587 | } | 
|---|
| 588 |  | 
|---|
| 589 | void QAbstractSlider::setInvertedControls(bool invert) | 
|---|
| 590 | { | 
|---|
| 591 | Q_D(QAbstractSlider); | 
|---|
| 592 | d->invertedControls = invert; | 
|---|
| 593 | } | 
|---|
| 594 |  | 
|---|
| 595 | /*!  Triggers a slider \a action.  Possible actions are \l | 
|---|
| 596 | SliderSingleStepAdd, \l SliderSingleStepSub, \l SliderPageStepAdd, | 
|---|
| 597 | \l SliderPageStepSub, \l SliderToMinimum, \l SliderToMaximum, and \l | 
|---|
| 598 | SliderMove. | 
|---|
| 599 |  | 
|---|
| 600 | \sa actionTriggered() | 
|---|
| 601 | */ | 
|---|
| 602 | void QAbstractSlider::triggerAction(SliderAction action) | 
|---|
| 603 | { | 
|---|
| 604 | Q_D(QAbstractSlider); | 
|---|
| 605 | d->blocktracking = true; | 
|---|
| 606 | switch (action) { | 
|---|
| 607 | case SliderSingleStepAdd: | 
|---|
| 608 | setSliderPosition(d->overflowSafeAdd(d->effectiveSingleStep())); | 
|---|
| 609 | break; | 
|---|
| 610 | case SliderSingleStepSub: | 
|---|
| 611 | setSliderPosition(d->overflowSafeAdd(-d->effectiveSingleStep())); | 
|---|
| 612 | break; | 
|---|
| 613 | case SliderPageStepAdd: | 
|---|
| 614 | setSliderPosition(d->overflowSafeAdd(d->pageStep)); | 
|---|
| 615 | break; | 
|---|
| 616 | case SliderPageStepSub: | 
|---|
| 617 | setSliderPosition(d->overflowSafeAdd(-d->pageStep)); | 
|---|
| 618 | break; | 
|---|
| 619 | case SliderToMinimum: | 
|---|
| 620 | setSliderPosition(d->minimum); | 
|---|
| 621 | break; | 
|---|
| 622 | case SliderToMaximum: | 
|---|
| 623 | setSliderPosition(d->maximum); | 
|---|
| 624 | break; | 
|---|
| 625 | case SliderMove: | 
|---|
| 626 | case SliderNoAction: | 
|---|
| 627 | break; | 
|---|
| 628 | }; | 
|---|
| 629 | emit actionTriggered(action); | 
|---|
| 630 | d->blocktracking = false; | 
|---|
| 631 | setValue(d->position); | 
|---|
| 632 | } | 
|---|
| 633 |  | 
|---|
| 634 | /*!  Sets action \a action to be triggered repetitively in intervals | 
|---|
| 635 | of \a repeatTime, after an initial delay of \a thresholdTime. | 
|---|
| 636 |  | 
|---|
| 637 | \sa triggerAction() repeatAction() | 
|---|
| 638 | */ | 
|---|
| 639 | void QAbstractSlider::setRepeatAction(SliderAction action, int thresholdTime, int repeatTime) | 
|---|
| 640 | { | 
|---|
| 641 | Q_D(QAbstractSlider); | 
|---|
| 642 | if ((d->repeatAction = action) == SliderNoAction) { | 
|---|
| 643 | d->repeatActionTimer.stop(); | 
|---|
| 644 | } else { | 
|---|
| 645 | d->repeatActionTime = repeatTime; | 
|---|
| 646 | d->repeatActionTimer.start(thresholdTime, this); | 
|---|
| 647 | } | 
|---|
| 648 | } | 
|---|
| 649 |  | 
|---|
| 650 | /*! | 
|---|
| 651 | Returns the current repeat action. | 
|---|
| 652 | \sa setRepeatAction() | 
|---|
| 653 | */ | 
|---|
| 654 | QAbstractSlider::SliderAction QAbstractSlider::repeatAction() const | 
|---|
| 655 | { | 
|---|
| 656 | Q_D(const QAbstractSlider); | 
|---|
| 657 | return d->repeatAction; | 
|---|
| 658 | } | 
|---|
| 659 |  | 
|---|
| 660 | /*!\reimp | 
|---|
| 661 | */ | 
|---|
| 662 | void QAbstractSlider::timerEvent(QTimerEvent *e) | 
|---|
| 663 | { | 
|---|
| 664 | Q_D(QAbstractSlider); | 
|---|
| 665 | if (e->timerId() == d->repeatActionTimer.timerId()) { | 
|---|
| 666 | if (d->repeatActionTime) { // was threshold time, use repeat time next time | 
|---|
| 667 | d->repeatActionTimer.start(d->repeatActionTime, this); | 
|---|
| 668 | d->repeatActionTime = 0; | 
|---|
| 669 | } | 
|---|
| 670 | if (d->repeatAction == SliderPageStepAdd) | 
|---|
| 671 | d->setAdjustedSliderPosition(d->overflowSafeAdd(d->pageStep)); | 
|---|
| 672 | else if (d->repeatAction == SliderPageStepSub) | 
|---|
| 673 | d->setAdjustedSliderPosition(d->overflowSafeAdd(-d->pageStep)); | 
|---|
| 674 | else | 
|---|
| 675 | triggerAction(d->repeatAction); | 
|---|
| 676 | } | 
|---|
| 677 | } | 
|---|
| 678 |  | 
|---|
| 679 | /*! | 
|---|
| 680 | Reimplement this virtual function to track slider changes such as | 
|---|
| 681 | \l SliderRangeChange, \l SliderOrientationChange, \l | 
|---|
| 682 | SliderStepsChange, or \l SliderValueChange. The default | 
|---|
| 683 | implementation only updates the display and ignores the \a change | 
|---|
| 684 | parameter. | 
|---|
| 685 | */ | 
|---|
| 686 | void QAbstractSlider::sliderChange(SliderChange) | 
|---|
| 687 | { | 
|---|
| 688 | update(); | 
|---|
| 689 | } | 
|---|
| 690 |  | 
|---|
| 691 |  | 
|---|
| 692 | /*! | 
|---|
| 693 | \reimp | 
|---|
| 694 | */ | 
|---|
| 695 | #ifndef QT_NO_WHEELEVENT | 
|---|
| 696 | void QAbstractSlider::wheelEvent(QWheelEvent * e) | 
|---|
| 697 | { | 
|---|
| 698 | Q_D(QAbstractSlider); | 
|---|
| 699 | e->ignore(); | 
|---|
| 700 | if (e->orientation() != d->orientation && !rect().contains(e->pos())) | 
|---|
| 701 | return; | 
|---|
| 702 |  | 
|---|
| 703 | int stepsToScroll = 0; | 
|---|
| 704 | qreal offset = qreal(e->delta()) / 120; | 
|---|
| 705 |  | 
|---|
| 706 | if ((e->modifiers() & Qt::ControlModifier) || (e->modifiers() & Qt::ShiftModifier)) { | 
|---|
| 707 | // Scroll one page regardless of delta: | 
|---|
| 708 | stepsToScroll = qBound(-d->pageStep, int(offset * d->pageStep), d->pageStep); | 
|---|
| 709 | d->offset_accumulated = 0; | 
|---|
| 710 | } else { | 
|---|
| 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 = offset * QApplication::wheelScrollLines() * d->effectiveSingleStep(); | 
|---|
| 715 | // Check if wheel changed direction since last event: | 
|---|
| 716 | if (d->offset_accumulated != 0 && (offset / d->offset_accumulated) < 0) | 
|---|
| 717 | d->offset_accumulated = 0; | 
|---|
| 718 |  | 
|---|
| 719 | d->offset_accumulated += stepsToScrollF; | 
|---|
| 720 | stepsToScroll = qBound(-d->pageStep, int(d->offset_accumulated), d->pageStep); | 
|---|
| 721 | d->offset_accumulated -= int(d->offset_accumulated); | 
|---|
| 722 | if (stepsToScroll == 0) | 
|---|
| 723 | return; | 
|---|
| 724 | } | 
|---|
| 725 |  | 
|---|
| 726 | if (d->invertedControls) | 
|---|
| 727 | stepsToScroll = -stepsToScroll; | 
|---|
| 728 |  | 
|---|
| 729 | int prevValue = d->value; | 
|---|
| 730 | d->position = d->overflowSafeAdd(stepsToScroll); // value will be updated by triggerAction() | 
|---|
| 731 | triggerAction(SliderMove); | 
|---|
| 732 |  | 
|---|
| 733 | if (prevValue == d->value) | 
|---|
| 734 | d->offset_accumulated = 0; | 
|---|
| 735 | else | 
|---|
| 736 | e->accept(); | 
|---|
| 737 | } | 
|---|
| 738 | #endif | 
|---|
| 739 | #ifdef QT_KEYPAD_NAVIGATION | 
|---|
| 740 | /*! | 
|---|
| 741 | \internal | 
|---|
| 742 |  | 
|---|
| 743 | Tells us if it there is currently a reachable widget by keypad navigation in | 
|---|
| 744 | a certain \a orientation. | 
|---|
| 745 | If no navigation is possible, occuring key events in that \a orientation may | 
|---|
| 746 | be used to interact with the value in the focussed widget, even though it | 
|---|
| 747 | currently has not the editFocus. | 
|---|
| 748 |  | 
|---|
| 749 | \sa QWidgetPrivate::widgetInNavigationDirection(), QWidget::hasEditFocus() | 
|---|
| 750 | */ | 
|---|
| 751 | inline static bool canKeypadNavigate(Qt::Orientation orientation) | 
|---|
| 752 | { | 
|---|
| 753 | return orientation == Qt::Horizontal? | 
|---|
| 754 | (QWidgetPrivate::widgetInNavigationDirection(QWidgetPrivate::DirectionEast) | 
|---|
| 755 | || QWidgetPrivate::widgetInNavigationDirection(QWidgetPrivate::DirectionWest)) | 
|---|
| 756 | :(QWidgetPrivate::widgetInNavigationDirection(QWidgetPrivate::DirectionNorth) | 
|---|
| 757 | || QWidgetPrivate::widgetInNavigationDirection(QWidgetPrivate::DirectionSouth)); | 
|---|
| 758 | } | 
|---|
| 759 | /*! | 
|---|
| 760 | \internal | 
|---|
| 761 |  | 
|---|
| 762 | Checks, if the \a widget is inside a QTabWidget. If is is inside | 
|---|
| 763 | one, left/right key events will be used to switch between tabs in keypad | 
|---|
| 764 | navigation. If there is no QTabWidget, the horizontal key events can be used to | 
|---|
| 765 | interact with the value in the focussed widget, even though it currently has | 
|---|
| 766 | not the editFocus. | 
|---|
| 767 |  | 
|---|
| 768 | \sa QWidget::hasEditFocus() | 
|---|
| 769 | */ | 
|---|
| 770 | inline static bool inTabWidget(QWidget *widget) | 
|---|
| 771 | { | 
|---|
| 772 | for (QWidget *tabWidget = widget; tabWidget; tabWidget = tabWidget->parentWidget()) | 
|---|
| 773 | if (qobject_cast<const QTabWidget*>(tabWidget)) | 
|---|
| 774 | return true; | 
|---|
| 775 | return false; | 
|---|
| 776 | } | 
|---|
| 777 | #endif // QT_KEYPAD_NAVIGATION | 
|---|
| 778 | /*! | 
|---|
| 779 | \reimp | 
|---|
| 780 | */ | 
|---|
| 781 | void 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.isNull()) | 
|---|
| 788 | d->firstRepeat = QTime::currentTime(); | 
|---|
| 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.msecsTo(QTime::currentTime()); | 
|---|
| 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.isNull()) { | 
|---|
| 811 | d->firstRepeat = QTime(); | 
|---|
| 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: | 
|---|
| 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() && (canKeypadNavigate(Qt::Horizontal) || inTabWidget(this)))) { | 
|---|
| 844 | ev->ignore(); | 
|---|
| 845 | return; | 
|---|
| 846 | } | 
|---|
| 847 | if (QApplication::keypadNavigationEnabled() && d->orientation == Qt::Vertical) | 
|---|
| 848 | action = d->invertedControls ? SliderSingleStepSub : SliderSingleStepAdd; | 
|---|
| 849 | else | 
|---|
| 850 | #endif | 
|---|
| 851 | if (isRightToLeft()) | 
|---|
| 852 | action = d->invertedAppearance ? SliderSingleStepSub : SliderSingleStepAdd; | 
|---|
| 853 | else | 
|---|
| 854 | action = !d->invertedAppearance ? SliderSingleStepSub : SliderSingleStepAdd; | 
|---|
| 855 | break; | 
|---|
| 856 | case Qt::Key_Right: | 
|---|
| 857 | #ifdef QT_KEYPAD_NAVIGATION | 
|---|
| 858 | // Same logic as in Qt::Key_Left | 
|---|
| 859 | if (QApplication::keypadNavigationEnabled() | 
|---|
| 860 | && (!hasEditFocus() && QApplication::navigationMode() == Qt::NavigationModeKeypadTabOrder | 
|---|
| 861 | || d->orientation == Qt::Vertical | 
|---|
| 862 | || !hasEditFocus() && (canKeypadNavigate(Qt::Horizontal) || inTabWidget(this)))) { | 
|---|
| 863 | ev->ignore(); | 
|---|
| 864 | return; | 
|---|
| 865 | } | 
|---|
| 866 | if (QApplication::keypadNavigationEnabled() && d->orientation == Qt::Vertical) | 
|---|
| 867 | action = d->invertedControls ? SliderSingleStepAdd : SliderSingleStepSub; | 
|---|
| 868 | else | 
|---|
| 869 | #endif | 
|---|
| 870 | if (isRightToLeft()) | 
|---|
| 871 | action = d->invertedAppearance ? SliderSingleStepAdd : SliderSingleStepSub; | 
|---|
| 872 | else | 
|---|
| 873 | action = !d->invertedAppearance ? SliderSingleStepAdd : SliderSingleStepSub; | 
|---|
| 874 | break; | 
|---|
| 875 | case Qt::Key_Up: | 
|---|
| 876 | #ifdef QT_KEYPAD_NAVIGATION | 
|---|
| 877 | // In QApplication::KeypadNavigationDirectional, we want to change the slider | 
|---|
| 878 | // value if there is no up/down navigation possible. | 
|---|
| 879 | if (QApplication::keypadNavigationEnabled() | 
|---|
| 880 | && (QApplication::navigationMode() == Qt::NavigationModeKeypadTabOrder | 
|---|
| 881 | || d->orientation == Qt::Horizontal | 
|---|
| 882 | || !hasEditFocus() && canKeypadNavigate(Qt::Vertical))) { | 
|---|
| 883 | ev->ignore(); | 
|---|
| 884 | break; | 
|---|
| 885 | } | 
|---|
| 886 | #endif | 
|---|
| 887 | action = d->invertedControls ? SliderSingleStepSub : SliderSingleStepAdd; | 
|---|
| 888 | break; | 
|---|
| 889 | case Qt::Key_Down: | 
|---|
| 890 | #ifdef QT_KEYPAD_NAVIGATION | 
|---|
| 891 | // Same logic as in Qt::Key_Up | 
|---|
| 892 | if (QApplication::keypadNavigationEnabled() | 
|---|
| 893 | && (QApplication::navigationMode() == Qt::NavigationModeKeypadTabOrder | 
|---|
| 894 | || d->orientation == Qt::Horizontal | 
|---|
| 895 | || !hasEditFocus() && canKeypadNavigate(Qt::Vertical))) { | 
|---|
| 896 | ev->ignore(); | 
|---|
| 897 | break; | 
|---|
| 898 | } | 
|---|
| 899 | #endif | 
|---|
| 900 | action = d->invertedControls ? SliderSingleStepAdd : SliderSingleStepSub; | 
|---|
| 901 | break; | 
|---|
| 902 | case Qt::Key_PageUp: | 
|---|
| 903 | action = d->invertedControls ? SliderPageStepSub : SliderPageStepAdd; | 
|---|
| 904 | break; | 
|---|
| 905 | case Qt::Key_PageDown: | 
|---|
| 906 | action = d->invertedControls ? SliderPageStepAdd : SliderPageStepSub; | 
|---|
| 907 | break; | 
|---|
| 908 | case Qt::Key_Home: | 
|---|
| 909 | action = SliderToMinimum; | 
|---|
| 910 | break; | 
|---|
| 911 | case Qt::Key_End: | 
|---|
| 912 | action = SliderToMaximum; | 
|---|
| 913 | break; | 
|---|
| 914 | default: | 
|---|
| 915 | ev->ignore(); | 
|---|
| 916 | break; | 
|---|
| 917 | } | 
|---|
| 918 | if (action) | 
|---|
| 919 | triggerAction(action); | 
|---|
| 920 | } | 
|---|
| 921 |  | 
|---|
| 922 | /*! | 
|---|
| 923 | \reimp | 
|---|
| 924 | */ | 
|---|
| 925 | void QAbstractSlider::changeEvent(QEvent *ev) | 
|---|
| 926 | { | 
|---|
| 927 | Q_D(QAbstractSlider); | 
|---|
| 928 | switch (ev->type()) { | 
|---|
| 929 | case QEvent::EnabledChange: | 
|---|
| 930 | if (!isEnabled()) { | 
|---|
| 931 | d->repeatActionTimer.stop(); | 
|---|
| 932 | setSliderDown(false); | 
|---|
| 933 | } | 
|---|
| 934 | // fall through... | 
|---|
| 935 | default: | 
|---|
| 936 | QWidget::changeEvent(ev); | 
|---|
| 937 | } | 
|---|
| 938 | } | 
|---|
| 939 |  | 
|---|
| 940 | /*! | 
|---|
| 941 | \reimp | 
|---|
| 942 | */ | 
|---|
| 943 | bool QAbstractSlider::event(QEvent *e) | 
|---|
| 944 | { | 
|---|
| 945 | #ifdef QT_KEYPAD_NAVIGATION | 
|---|
| 946 | Q_D(QAbstractSlider); | 
|---|
| 947 | switch (e->type()) { | 
|---|
| 948 | case QEvent::FocusIn: | 
|---|
| 949 | d->origValue = d->value; | 
|---|
| 950 | break; | 
|---|
| 951 | default: | 
|---|
| 952 | break; | 
|---|
| 953 | } | 
|---|
| 954 | #endif | 
|---|
| 955 |  | 
|---|
| 956 | return QWidget::event(e); | 
|---|
| 957 | } | 
|---|
| 958 |  | 
|---|
| 959 | /*! \fn int QAbstractSlider::minValue() const | 
|---|
| 960 |  | 
|---|
| 961 | Use minimum() instead. | 
|---|
| 962 | */ | 
|---|
| 963 |  | 
|---|
| 964 | /*! \fn int QAbstractSlider::maxValue() const | 
|---|
| 965 |  | 
|---|
| 966 | Use maximum() instead. | 
|---|
| 967 | */ | 
|---|
| 968 |  | 
|---|
| 969 | /*! \fn int QAbstractSlider::lineStep() const | 
|---|
| 970 |  | 
|---|
| 971 | Use singleStep() instead. | 
|---|
| 972 | */ | 
|---|
| 973 |  | 
|---|
| 974 | /*! \fn void QAbstractSlider::setMinValue(int v) | 
|---|
| 975 |  | 
|---|
| 976 | Use setMinimum() instead. | 
|---|
| 977 | */ | 
|---|
| 978 |  | 
|---|
| 979 | /*! \fn void QAbstractSlider::setMaxValue(int v) | 
|---|
| 980 |  | 
|---|
| 981 | Use setMaximum() instead. | 
|---|
| 982 | */ | 
|---|
| 983 |  | 
|---|
| 984 | /*! \fn void QAbstractSlider::setLineStep(int v) | 
|---|
| 985 |  | 
|---|
| 986 | Use setSingleStep() instead. | 
|---|
| 987 | */ | 
|---|
| 988 |  | 
|---|
| 989 | /*! \fn void QAbstractSlider::addPage() | 
|---|
| 990 |  | 
|---|
| 991 | Use triggerAction(QAbstractSlider::SliderPageStepAdd) instead. | 
|---|
| 992 | */ | 
|---|
| 993 |  | 
|---|
| 994 | /*! \fn void QAbstractSlider::subtractPage() | 
|---|
| 995 |  | 
|---|
| 996 | Use triggerAction(QAbstractSlider::SliderPageStepSub) instead. | 
|---|
| 997 | */ | 
|---|
| 998 |  | 
|---|
| 999 | /*! \fn void QAbstractSlider::addLine() | 
|---|
| 1000 |  | 
|---|
| 1001 | Use triggerAction(QAbstractSlider::SliderSingleStepAdd) instead. | 
|---|
| 1002 | */ | 
|---|
| 1003 |  | 
|---|
| 1004 | /*! \fn void QAbstractSlider::subtractLine() | 
|---|
| 1005 |  | 
|---|
| 1006 | Use triggerAction(QAbstractSlider::SliderSingleStepSub) instead. | 
|---|
| 1007 | */ | 
|---|
| 1008 |  | 
|---|
| 1009 | /*! \fn void QAbstractSlider::setSteps(int single, int page) | 
|---|
| 1010 |  | 
|---|
| 1011 | Use setSingleStep(\a single) followed by setPageStep(\a page) | 
|---|
| 1012 | instead. | 
|---|
| 1013 | */ | 
|---|
| 1014 |  | 
|---|
| 1015 | QT_END_NAMESPACE | 
|---|