| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/widgets/widgets/qslider.cpp | 
| Source code | Switch to Preprocessed file | 
| Line | Source | Count | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||||||||
| 2 | ** | - | ||||||||||||
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. | - | ||||||||||||
| 4 | ** Contact: https://www.qt.io/licensing/ | - | ||||||||||||
| 5 | ** | - | ||||||||||||
| 6 | ** This file is part of the QtWidgets module of the Qt Toolkit. | - | ||||||||||||
| 7 | ** | - | ||||||||||||
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ | - | ||||||||||||
| 9 | ** Commercial License Usage | - | ||||||||||||
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||
| 11 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||
| 12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||
| 13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further | - | ||||||||||||
| 15 | ** information use the contact form at https://www.qt.io/contact-us. | - | ||||||||||||
| 16 | ** | - | ||||||||||||
| 17 | ** GNU Lesser General Public License Usage | - | ||||||||||||
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||
| 19 | ** General Public License version 3 as published by the Free Software | - | ||||||||||||
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | - | ||||||||||||
| 21 | ** packaging of this file. Please review the following information to | - | ||||||||||||
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements | - | ||||||||||||
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | - | ||||||||||||
| 24 | ** | - | ||||||||||||
| 25 | ** GNU General Public License Usage | - | ||||||||||||
| 26 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||||||||
| 27 | ** General Public License version 2.0 or (at your option) the GNU General | - | ||||||||||||
| 28 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||||||||
| 29 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||||||||
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||||||||
| 31 | ** included in the packaging of this file. Please review the following | - | ||||||||||||
| 32 | ** information to ensure the GNU General Public License requirements will | - | ||||||||||||
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||||||||
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||||||||
| 35 | ** | - | ||||||||||||
| 36 | ** $QT_END_LICENSE$ | - | ||||||||||||
| 37 | ** | - | ||||||||||||
| 38 | ****************************************************************************/ | - | ||||||||||||
| 39 | - | |||||||||||||
| 40 | #include "qslider.h" | - | ||||||||||||
| 41 | #ifndef QT_NO_SLIDER | - | ||||||||||||
| 42 | #ifndef QT_NO_ACCESSIBILITY | - | ||||||||||||
| 43 | #include "qaccessible.h" | - | ||||||||||||
| 44 | #endif | - | ||||||||||||
| 45 | #include "qapplication.h" | - | ||||||||||||
| 46 | #include "qevent.h" | - | ||||||||||||
| 47 | #include "qpainter.h" | - | ||||||||||||
| 48 | #include "qstyle.h" | - | ||||||||||||
| 49 | #include "qstyleoption.h" | - | ||||||||||||
| 50 | #include "private/qabstractslider_p.h" | - | ||||||||||||
| 51 | #include "qdebug.h" | - | ||||||||||||
| 52 | - | |||||||||||||
| 53 | QT_BEGIN_NAMESPACE | - | ||||||||||||
| 54 | - | |||||||||||||
| 55 | class QSliderPrivate : public QAbstractSliderPrivate | - | ||||||||||||
| 56 | { | - | ||||||||||||
| 57 | Q_DECLARE_PUBLIC(QSlider) | - | ||||||||||||
| 58 | public: | - | ||||||||||||
| 59 | QStyle::SubControl pressedControl; | - | ||||||||||||
| 60 | int tickInterval; | - | ||||||||||||
| 61 | QSlider::TickPosition tickPosition; | - | ||||||||||||
| 62 | int clickOffset; | - | ||||||||||||
| 63 | void init(); | - | ||||||||||||
| 64 | void resetLayoutItemMargins(); | - | ||||||||||||
| 65 | int pixelPosToRangeValue(int pos) const; | - | ||||||||||||
| 66 | inline int pick(const QPoint &pt) const; | - | ||||||||||||
| 67 | - | |||||||||||||
| 68 | QStyle::SubControl newHoverControl(const QPoint &pos); | - | ||||||||||||
| 69 | bool updateHoverControl(const QPoint &pos); | - | ||||||||||||
| 70 | QStyle::SubControl hoverControl; | - | ||||||||||||
| 71 | QRect hoverRect; | - | ||||||||||||
| 72 | }; | - | ||||||||||||
| 73 | - | |||||||||||||
| 74 | void QSliderPrivate::init() | - | ||||||||||||
| 75 | { | - | ||||||||||||
| 76 | Q_Q(QSlider); | - | ||||||||||||
| 77 | pressedControl = QStyle::SC_None; | - | ||||||||||||
| 78 | tickInterval = 0; | - | ||||||||||||
| 79 | tickPosition = QSlider::NoTicks; | - | ||||||||||||
| 80 | hoverControl = QStyle::SC_None; | - | ||||||||||||
| 81 | q->setFocusPolicy(Qt::FocusPolicy(q->style()->styleHint(QStyle::SH_Button_FocusPolicy))); | - | ||||||||||||
| 82 | QSizePolicy sp(QSizePolicy::Expanding, QSizePolicy::Fixed, QSizePolicy::Slider); | - | ||||||||||||
| 83 | if (orientation == Qt::Vertical) 
 | 0 | ||||||||||||
| 84 | sp.transpose(); never executed:  sp.transpose(); | 0 | ||||||||||||
| 85 | q->setSizePolicy(sp); | - | ||||||||||||
| 86 | q->setAttribute(Qt::WA_WState_OwnSizePolicy, false); | - | ||||||||||||
| 87 | resetLayoutItemMargins(); | - | ||||||||||||
| 88 | } never executed:  end of block | 0 | ||||||||||||
| 89 | - | |||||||||||||
| 90 | void QSliderPrivate::resetLayoutItemMargins() | - | ||||||||||||
| 91 | { | - | ||||||||||||
| 92 | Q_Q(QSlider); | - | ||||||||||||
| 93 | QStyleOptionSlider opt; | - | ||||||||||||
| 94 | q->initStyleOption(&opt); | - | ||||||||||||
| 95 | setLayoutItemMargins(QStyle::SE_SliderLayoutItem, &opt); | - | ||||||||||||
| 96 | } never executed:  end of block | 0 | ||||||||||||
| 97 | - | |||||||||||||
| 98 | int QSliderPrivate::pixelPosToRangeValue(int pos) const | - | ||||||||||||
| 99 | { | - | ||||||||||||
| 100 | Q_Q(const QSlider); | - | ||||||||||||
| 101 | QStyleOptionSlider opt; | - | ||||||||||||
| 102 | q->initStyleOption(&opt); | - | ||||||||||||
| 103 | QRect gr = q->style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderGroove, q); | - | ||||||||||||
| 104 | QRect sr = q->style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderHandle, q); | - | ||||||||||||
| 105 | int sliderMin, sliderMax, sliderLength; | - | ||||||||||||
| 106 | - | |||||||||||||
| 107 | if (orientation == Qt::Horizontal) { 
 | 0 | ||||||||||||
| 108 | sliderLength = sr.width(); | - | ||||||||||||
| 109 | sliderMin = gr.x(); | - | ||||||||||||
| 110 | sliderMax = gr.right() - sliderLength + 1; | - | ||||||||||||
| 111 | } else { never executed:  end of block | 0 | ||||||||||||
| 112 | sliderLength = sr.height(); | - | ||||||||||||
| 113 | sliderMin = gr.y(); | - | ||||||||||||
| 114 | sliderMax = gr.bottom() - sliderLength + 1; | - | ||||||||||||
| 115 | } never executed:  end of block | 0 | ||||||||||||
| 116 | return QStyle::sliderValueFromPosition(minimum, maximum, pos - sliderMin, never executed:  return QStyle::sliderValueFromPosition(minimum, maximum, pos - sliderMin, sliderMax - sliderMin, opt.upsideDown); | 0 | ||||||||||||
| 117 | sliderMax - sliderMin, opt.upsideDown); never executed:  return QStyle::sliderValueFromPosition(minimum, maximum, pos - sliderMin, sliderMax - sliderMin, opt.upsideDown); | 0 | ||||||||||||
| 118 | } | - | ||||||||||||
| 119 | - | |||||||||||||
| 120 | inline int QSliderPrivate::pick(const QPoint &pt) const | - | ||||||||||||
| 121 | { | - | ||||||||||||
| 122 | return orientation == Qt::Horizontal ? pt.x() : pt.y(); never executed:  return orientation == Qt::Horizontal ? pt.x() : pt.y(); | 0 | ||||||||||||
| 123 | } | - | ||||||||||||
| 124 | - | |||||||||||||
| 125 | /*! | - | ||||||||||||
| 126 | Initialize \a option with the values from this QSlider. This method | - | ||||||||||||
| 127 | is useful for subclasses when they need a QStyleOptionSlider, but don't want | - | ||||||||||||
| 128 | to fill in all the information themselves. | - | ||||||||||||
| 129 | - | |||||||||||||
| 130 | \sa QStyleOption::initFrom() | - | ||||||||||||
| 131 | */ | - | ||||||||||||
| 132 | void QSlider::initStyleOption(QStyleOptionSlider *option) const | - | ||||||||||||
| 133 | { | - | ||||||||||||
| 134 | if (!option) 
 | 0 | ||||||||||||
| 135 | return; never executed:  return; | 0 | ||||||||||||
| 136 | - | |||||||||||||
| 137 | Q_D(const QSlider); | - | ||||||||||||
| 138 | option->initFrom(this); | - | ||||||||||||
| 139 | option->subControls = QStyle::SC_None; | - | ||||||||||||
| 140 | option->activeSubControls = QStyle::SC_None; | - | ||||||||||||
| 141 | option->orientation = d->orientation; | - | ||||||||||||
| 142 | option->maximum = d->maximum; | - | ||||||||||||
| 143 | option->minimum = d->minimum; | - | ||||||||||||
| 144 | option->tickPosition = (QSlider::TickPosition)d->tickPosition; | - | ||||||||||||
| 145 | option->tickInterval = d->tickInterval; | - | ||||||||||||
| 146 | option->upsideDown = (d->orientation == Qt::Horizontal) ? 
 | 0 | ||||||||||||
| 147 | (d->invertedAppearance != (option->direction == Qt::RightToLeft)) | - | ||||||||||||
| 148 | : (!d->invertedAppearance); | - | ||||||||||||
| 149 | option->direction = Qt::LeftToRight; // we use the upsideDown option instead | - | ||||||||||||
| 150 | option->sliderPosition = d->position; | - | ||||||||||||
| 151 | option->sliderValue = d->value; | - | ||||||||||||
| 152 | option->singleStep = d->singleStep; | - | ||||||||||||
| 153 | option->pageStep = d->pageStep; | - | ||||||||||||
| 154 | if (d->orientation == Qt::Horizontal) 
 | 0 | ||||||||||||
| 155 | option->state |= QStyle::State_Horizontal; never executed:  option->state |= QStyle::State_Horizontal; | 0 | ||||||||||||
| 156 | } never executed:  end of block | 0 | ||||||||||||
| 157 | - | |||||||||||||
| 158 | bool QSliderPrivate::updateHoverControl(const QPoint &pos) | - | ||||||||||||
| 159 | { | - | ||||||||||||
| 160 | Q_Q(QSlider); | - | ||||||||||||
| 161 | QRect lastHoverRect = hoverRect; | - | ||||||||||||
| 162 | QStyle::SubControl lastHoverControl = hoverControl; | - | ||||||||||||
| 163 | bool doesHover = q->testAttribute(Qt::WA_Hover); | - | ||||||||||||
| 164 | if (lastHoverControl != newHoverControl(pos) && doesHover) { 
 
 | 0 | ||||||||||||
| 165 | q->update(lastHoverRect); | - | ||||||||||||
| 166 | q->update(hoverRect); | - | ||||||||||||
| 167 | return true; never executed:  return true; | 0 | ||||||||||||
| 168 | } | - | ||||||||||||
| 169 | return !doesHover; never executed:  return !doesHover; | 0 | ||||||||||||
| 170 | } | - | ||||||||||||
| 171 | - | |||||||||||||
| 172 | QStyle::SubControl QSliderPrivate::newHoverControl(const QPoint &pos) | - | ||||||||||||
| 173 | { | - | ||||||||||||
| 174 | Q_Q(QSlider); | - | ||||||||||||
| 175 | QStyleOptionSlider opt; | - | ||||||||||||
| 176 | q->initStyleOption(&opt); | - | ||||||||||||
| 177 | opt.subControls = QStyle::SC_All; | - | ||||||||||||
| 178 | QRect handleRect = q->style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderHandle, q); | - | ||||||||||||
| 179 | QRect grooveRect = q->style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderGroove, q); | - | ||||||||||||
| 180 | QRect tickmarksRect = q->style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderTickmarks, q); | - | ||||||||||||
| 181 | - | |||||||||||||
| 182 | if (handleRect.contains(pos)) { 
 | 0 | ||||||||||||
| 183 | hoverRect = handleRect; | - | ||||||||||||
| 184 | hoverControl = QStyle::SC_SliderHandle; | - | ||||||||||||
| 185 | } else if (grooveRect.contains(pos)) { never executed:  end of block
 | 0 | ||||||||||||
| 186 | hoverRect = grooveRect; | - | ||||||||||||
| 187 | hoverControl = QStyle::SC_SliderGroove; | - | ||||||||||||
| 188 | } else if (tickmarksRect.contains(pos)) { never executed:  end of block
 | 0 | ||||||||||||
| 189 | hoverRect = tickmarksRect; | - | ||||||||||||
| 190 | hoverControl = QStyle::SC_SliderTickmarks; | - | ||||||||||||
| 191 | } else { never executed:  end of block | 0 | ||||||||||||
| 192 | hoverRect = QRect(); | - | ||||||||||||
| 193 | hoverControl = QStyle::SC_None; | - | ||||||||||||
| 194 | } never executed:  end of block | 0 | ||||||||||||
| 195 | - | |||||||||||||
| 196 | return hoverControl; never executed:  return hoverControl; | 0 | ||||||||||||
| 197 | } | - | ||||||||||||
| 198 | - | |||||||||||||
| 199 | /*! | - | ||||||||||||
| 200 | \class QSlider | - | ||||||||||||
| 201 | \brief The QSlider widget provides a vertical or horizontal slider. | - | ||||||||||||
| 202 | - | |||||||||||||
| 203 | \ingroup basicwidgets | - | ||||||||||||
| 204 | \inmodule QtWidgets | - | ||||||||||||
| 205 | - | |||||||||||||
| 206 | The slider is the classic widget for controlling a bounded value. | - | ||||||||||||
| 207 | It lets the user move a slider handle along a horizontal or vertical | - | ||||||||||||
| 208 | groove and translates the handle's position into an integer value | - | ||||||||||||
| 209 | within the legal range. | - | ||||||||||||
| 210 | - | |||||||||||||
| 211 | QSlider has very few of its own functions; most of the functionality is in | - | ||||||||||||
| 212 | QAbstractSlider. The most useful functions are setValue() to set | - | ||||||||||||
| 213 | the slider directly to some value; triggerAction() to simulate | - | ||||||||||||
| 214 | the effects of clicking (useful for shortcut keys); | - | ||||||||||||
| 215 | setSingleStep(), setPageStep() to set the steps; and setMinimum() | - | ||||||||||||
| 216 | and setMaximum() to define the range of the scroll bar. | - | ||||||||||||
| 217 | - | |||||||||||||
| 218 | QSlider provides methods for controlling tickmarks. You can use | - | ||||||||||||
| 219 | setTickPosition() to indicate where you want the tickmarks to be, | - | ||||||||||||
| 220 | setTickInterval() to indicate how many of them you want. the | - | ||||||||||||
| 221 | currently set tick position and interval can be queried using the | - | ||||||||||||
| 222 | tickPosition() and tickInterval() functions, respectively. | - | ||||||||||||
| 223 | - | |||||||||||||
| 224 | QSlider inherits a comprehensive set of signals: | - | ||||||||||||
| 225 | \table | - | ||||||||||||
| 226 | \header \li Signal \li Description | - | ||||||||||||
| 227 | \row \li \l valueChanged() | - | ||||||||||||
| 228 | \li Emitted when the slider's value has changed. The tracking() | - | ||||||||||||
| 229 | determines whether this signal is emitted during user | - | ||||||||||||
| 230 | interaction. | - | ||||||||||||
| 231 | \row \li \l sliderPressed() | - | ||||||||||||
| 232 | \li Emitted when the user starts to drag the slider. | - | ||||||||||||
| 233 | \row \li \l sliderMoved() | - | ||||||||||||
| 234 | \li Emitted when the user drags the slider. | - | ||||||||||||
| 235 | \row \li \l sliderReleased() | - | ||||||||||||
| 236 | \li Emitted when the user releases the slider. | - | ||||||||||||
| 237 | \endtable | - | ||||||||||||
| 238 | - | |||||||||||||
| 239 | QSlider only provides integer ranges. Note that although | - | ||||||||||||
| 240 | QSlider handles very large numbers, it becomes difficult for users | - | ||||||||||||
| 241 | to use a slider accurately for very large ranges. | - | ||||||||||||
| 242 | - | |||||||||||||
| 243 | A slider accepts focus on Tab and provides both a mouse wheel and a | - | ||||||||||||
| 244 | keyboard interface. The keyboard interface is the following: | - | ||||||||||||
| 245 | - | |||||||||||||
| 246 | \list | - | ||||||||||||
| 247 | \li Left/Right move a horizontal slider by one single step. | - | ||||||||||||
| 248 | \li Up/Down move a vertical slider by one single step. | - | ||||||||||||
| 249 | \li PageUp moves up one page. | - | ||||||||||||
| 250 | \li PageDown moves down one page. | - | ||||||||||||
| 251 | \li Home moves to the start (mininum). | - | ||||||||||||
| 252 | \li End moves to the end (maximum). | - | ||||||||||||
| 253 | \endlist | - | ||||||||||||
| 254 | - | |||||||||||||
| 255 | \table 100% | - | ||||||||||||
| 256 | \row \li \inlineimage macintosh-slider.png Screenshot of a Macintosh slider | - | ||||||||||||
| 257 | \li A slider shown in the \l{Macintosh Style Widget Gallery}{Macintosh widget style}. | - | ||||||||||||
| 258 | \row \li \inlineimage windowsvista-slider.png Screenshot of a Windows Vista slider | - | ||||||||||||
| 259 | \li A slider shown in the \l{Windows Vista Style Widget Gallery}{Windows Vista widget style}. | - | ||||||||||||
| 260 | \row \li \inlineimage fusion-slider.png Screenshot of a Fusion slider | - | ||||||||||||
| 261 | \li A slider shown in the \l{Fusion Style Widget Gallery}{Fusion widget style}. | - | ||||||||||||
| 262 | \endtable | - | ||||||||||||
| 263 | - | |||||||||||||
| 264 | \sa QScrollBar, QSpinBox, QDial, {fowler}{GUI Design Handbook: Slider}, {Sliders Example} | - | ||||||||||||
| 265 | */ | - | ||||||||||||
| 266 | - | |||||||||||||
| 267 | - | |||||||||||||
| 268 | /*! | - | ||||||||||||
| 269 | \enum QSlider::TickPosition | - | ||||||||||||
| 270 | - | |||||||||||||
| 271 | This enum specifies where the tick marks are to be drawn relative | - | ||||||||||||
| 272 | to the slider's groove and the handle the user moves. | - | ||||||||||||
| 273 | - | |||||||||||||
| 274 | \value NoTicks Do not draw any tick marks. | - | ||||||||||||
| 275 | \value TicksBothSides Draw tick marks on both sides of the groove. | - | ||||||||||||
| 276 | \value TicksAbove Draw tick marks above the (horizontal) slider | - | ||||||||||||
| 277 | \value TicksBelow Draw tick marks below the (horizontal) slider | - | ||||||||||||
| 278 | \value TicksLeft Draw tick marks to the left of the (vertical) slider | - | ||||||||||||
| 279 | \value TicksRight Draw tick marks to the right of the (vertical) slider | - | ||||||||||||
| 280 | */ | - | ||||||||||||
| 281 | - | |||||||||||||
| 282 | - | |||||||||||||
| 283 | /*! | - | ||||||||||||
| 284 | Constructs a vertical slider with the given \a parent. | - | ||||||||||||
| 285 | */ | - | ||||||||||||
| 286 | QSlider::QSlider(QWidget *parent) | - | ||||||||||||
| 287 | : QAbstractSlider(*new QSliderPrivate, parent) | - | ||||||||||||
| 288 | { | - | ||||||||||||
| 289 | d_func()->orientation = Qt::Vertical; | - | ||||||||||||
| 290 | d_func()->init(); | - | ||||||||||||
| 291 | } never executed:  end of block | 0 | ||||||||||||
| 292 | - | |||||||||||||
| 293 | /*! | - | ||||||||||||
| 294 | Constructs a slider with the given \a parent. The \a orientation | - | ||||||||||||
| 295 | parameter determines whether the slider is horizontal or vertical; | - | ||||||||||||
| 296 | the valid values are Qt::Vertical and Qt::Horizontal. | - | ||||||||||||
| 297 | */ | - | ||||||||||||
| 298 | - | |||||||||||||
| 299 | QSlider::QSlider(Qt::Orientation orientation, QWidget *parent) | - | ||||||||||||
| 300 | : QAbstractSlider(*new QSliderPrivate, parent) | - | ||||||||||||
| 301 | { | - | ||||||||||||
| 302 | d_func()->orientation = orientation; | - | ||||||||||||
| 303 | d_func()->init(); | - | ||||||||||||
| 304 | } never executed:  end of block | 0 | ||||||||||||
| 305 | - | |||||||||||||
| 306 | - | |||||||||||||
| 307 | /*! | - | ||||||||||||
| 308 | Destroys this slider. | - | ||||||||||||
| 309 | */ | - | ||||||||||||
| 310 | QSlider::~QSlider() | - | ||||||||||||
| 311 | { | - | ||||||||||||
| 312 | } | - | ||||||||||||
| 313 | - | |||||||||||||
| 314 | /*! | - | ||||||||||||
| 315 | \reimp | - | ||||||||||||
| 316 | */ | - | ||||||||||||
| 317 | void QSlider::paintEvent(QPaintEvent *) | - | ||||||||||||
| 318 | { | - | ||||||||||||
| 319 | Q_D(QSlider); | - | ||||||||||||
| 320 | QPainter p(this); | - | ||||||||||||
| 321 | QStyleOptionSlider opt; | - | ||||||||||||
| 322 | initStyleOption(&opt); | - | ||||||||||||
| 323 | - | |||||||||||||
| 324 | opt.subControls = QStyle::SC_SliderGroove | QStyle::SC_SliderHandle; | - | ||||||||||||
| 325 | if (d->tickPosition != NoTicks) 
 | 0 | ||||||||||||
| 326 | opt.subControls |= QStyle::SC_SliderTickmarks; never executed:  opt.subControls |= QStyle::SC_SliderTickmarks; | 0 | ||||||||||||
| 327 | if (d->pressedControl) { 
 | 0 | ||||||||||||
| 328 | opt.activeSubControls = d->pressedControl; | - | ||||||||||||
| 329 | opt.state |= QStyle::State_Sunken; | - | ||||||||||||
| 330 | } else { never executed:  end of block | 0 | ||||||||||||
| 331 | opt.activeSubControls = d->hoverControl; | - | ||||||||||||
| 332 | } never executed:  end of block | 0 | ||||||||||||
| 333 | - | |||||||||||||
| 334 | style()->drawComplexControl(QStyle::CC_Slider, &opt, &p, this); | - | ||||||||||||
| 335 | } never executed:  end of block | 0 | ||||||||||||
| 336 | - | |||||||||||||
| 337 | /*! | - | ||||||||||||
| 338 | \reimp | - | ||||||||||||
| 339 | */ | - | ||||||||||||
| 340 | - | |||||||||||||
| 341 | bool QSlider::event(QEvent *event) | - | ||||||||||||
| 342 | { | - | ||||||||||||
| 343 | Q_D(QSlider); | - | ||||||||||||
| 344 | - | |||||||||||||
| 345 | switch(event->type()) { | - | ||||||||||||
| 346 | case QEvent::HoverEnter: never executed:  case QEvent::HoverEnter: | 0 | ||||||||||||
| 347 | case QEvent::HoverLeave: never executed:  case QEvent::HoverLeave: | 0 | ||||||||||||
| 348 | case QEvent::HoverMove: never executed:  case QEvent::HoverMove: | 0 | ||||||||||||
| 349 | if (const QHoverEvent *he = static_cast<const QHoverEvent *>(event)) 
 | 0 | ||||||||||||
| 350 | d->updateHoverControl(he->pos()); never executed:  d->updateHoverControl(he->pos()); | 0 | ||||||||||||
| 351 | break; never executed:  break; | 0 | ||||||||||||
| 352 | case QEvent::StyleChange: never executed:  case QEvent::StyleChange: | 0 | ||||||||||||
| 353 | case QEvent::MacSizeChange: never executed:  case QEvent::MacSizeChange: | 0 | ||||||||||||
| 354 | d->resetLayoutItemMargins(); | - | ||||||||||||
| 355 | break; never executed:  break; | 0 | ||||||||||||
| 356 | default: never executed:  default: | 0 | ||||||||||||
| 357 | break; never executed:  break; | 0 | ||||||||||||
| 358 | } | - | ||||||||||||
| 359 | return QAbstractSlider::event(event); never executed:  return QAbstractSlider::event(event); | 0 | ||||||||||||
| 360 | } | - | ||||||||||||
| 361 | - | |||||||||||||
| 362 | /*! | - | ||||||||||||
| 363 | \reimp | - | ||||||||||||
| 364 | */ | - | ||||||||||||
| 365 | void QSlider::mousePressEvent(QMouseEvent *ev) | - | ||||||||||||
| 366 | { | - | ||||||||||||
| 367 | Q_D(QSlider); | - | ||||||||||||
| 368 | if (d->maximum == d->minimum || (ev->buttons() ^ ev->button())) { 
 
 | 0 | ||||||||||||
| 369 | ev->ignore(); | - | ||||||||||||
| 370 | return; never executed:  return; | 0 | ||||||||||||
| 371 | } | - | ||||||||||||
| 372 | #ifdef QT_KEYPAD_NAVIGATION | - | ||||||||||||
| 373 | if (QApplication::keypadNavigationEnabled()) | - | ||||||||||||
| 374 | setEditFocus(true); | - | ||||||||||||
| 375 | #endif | - | ||||||||||||
| 376 | ev->accept(); | - | ||||||||||||
| 377 | if ((ev->button() & style()->styleHint(QStyle::SH_Slider_AbsoluteSetButtons)) == ev->button()) { 
 | 0 | ||||||||||||
| 378 | QStyleOptionSlider opt; | - | ||||||||||||
| 379 | initStyleOption(&opt); | - | ||||||||||||
| 380 | const QRect sliderRect = style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderHandle, this); | - | ||||||||||||
| 381 | const QPoint center = sliderRect.center() - sliderRect.topLeft(); | - | ||||||||||||
| 382 | // to take half of the slider off for the setSliderPosition call we use the center - topLeft | - | ||||||||||||
| 383 | - | |||||||||||||
| 384 | setSliderPosition(d->pixelPosToRangeValue(d->pick(ev->pos() - center))); | - | ||||||||||||
| 385 | triggerAction(SliderMove); | - | ||||||||||||
| 386 | setRepeatAction(SliderNoAction); | - | ||||||||||||
| 387 | d->pressedControl = QStyle::SC_SliderHandle; | - | ||||||||||||
| 388 | update(); | - | ||||||||||||
| 389 | } else if ((ev->button() & style()->styleHint(QStyle::SH_Slider_PageSetButtons)) == ev->button()) { never executed:  end of block
 | 0 | ||||||||||||
| 390 | QStyleOptionSlider opt; | - | ||||||||||||
| 391 | initStyleOption(&opt); | - | ||||||||||||
| 392 | d->pressedControl = style()->hitTestComplexControl(QStyle::CC_Slider, | - | ||||||||||||
| 393 | &opt, ev->pos(), this); | - | ||||||||||||
| 394 | SliderAction action = SliderNoAction; | - | ||||||||||||
| 395 | if (d->pressedControl == QStyle::SC_SliderGroove) { 
 | 0 | ||||||||||||
| 396 | const QRect sliderRect = style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderHandle, this); | - | ||||||||||||
| 397 | int pressValue = d->pixelPosToRangeValue(d->pick(ev->pos() - sliderRect.center() + sliderRect.topLeft())); | - | ||||||||||||
| 398 | d->pressValue = pressValue; | - | ||||||||||||
| 399 | if (pressValue > d->value) 
 | 0 | ||||||||||||
| 400 | action = SliderPageStepAdd; never executed:  action = SliderPageStepAdd; | 0 | ||||||||||||
| 401 | else if (pressValue < d->value) 
 | 0 | ||||||||||||
| 402 | action = SliderPageStepSub; never executed:  action = SliderPageStepSub; | 0 | ||||||||||||
| 403 | if (action) { 
 | 0 | ||||||||||||
| 404 | triggerAction(action); | - | ||||||||||||
| 405 | setRepeatAction(action); | - | ||||||||||||
| 406 | } never executed:  end of block | 0 | ||||||||||||
| 407 | } never executed:  end of block | 0 | ||||||||||||
| 408 | } else { never executed:  end of block | 0 | ||||||||||||
| 409 | ev->ignore(); | - | ||||||||||||
| 410 | return; never executed:  return; | 0 | ||||||||||||
| 411 | } | - | ||||||||||||
| 412 | - | |||||||||||||
| 413 | if (d->pressedControl == QStyle::SC_SliderHandle) { 
 | 0 | ||||||||||||
| 414 | QStyleOptionSlider opt; | - | ||||||||||||
| 415 | initStyleOption(&opt); | - | ||||||||||||
| 416 | setRepeatAction(SliderNoAction); | - | ||||||||||||
| 417 | QRect sr = style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderHandle, this); | - | ||||||||||||
| 418 | d->clickOffset = d->pick(ev->pos() - sr.topLeft()); | - | ||||||||||||
| 419 | update(sr); | - | ||||||||||||
| 420 | setSliderDown(true); | - | ||||||||||||
| 421 | } never executed:  end of block | 0 | ||||||||||||
| 422 | } never executed:  end of block | 0 | ||||||||||||
| 423 | - | |||||||||||||
| 424 | /*! | - | ||||||||||||
| 425 | \reimp | - | ||||||||||||
| 426 | */ | - | ||||||||||||
| 427 | void QSlider::mouseMoveEvent(QMouseEvent *ev) | - | ||||||||||||
| 428 | { | - | ||||||||||||
| 429 | Q_D(QSlider); | - | ||||||||||||
| 430 | if (d->pressedControl != QStyle::SC_SliderHandle) { 
 | 0 | ||||||||||||
| 431 | ev->ignore(); | - | ||||||||||||
| 432 | return; never executed:  return; | 0 | ||||||||||||
| 433 | } | - | ||||||||||||
| 434 | ev->accept(); | - | ||||||||||||
| 435 | int newPosition = d->pixelPosToRangeValue(d->pick(ev->pos()) - d->clickOffset); | - | ||||||||||||
| 436 | QStyleOptionSlider opt; | - | ||||||||||||
| 437 | initStyleOption(&opt); | - | ||||||||||||
| 438 | setSliderPosition(newPosition); | - | ||||||||||||
| 439 | } never executed:  end of block | 0 | ||||||||||||
| 440 | - | |||||||||||||
| 441 | - | |||||||||||||
| 442 | /*! | - | ||||||||||||
| 443 | \reimp | - | ||||||||||||
| 444 | */ | - | ||||||||||||
| 445 | void QSlider::mouseReleaseEvent(QMouseEvent *ev) | - | ||||||||||||
| 446 | { | - | ||||||||||||
| 447 | Q_D(QSlider); | - | ||||||||||||
| 448 | if (d->pressedControl == QStyle::SC_None || ev->buttons()) { 
 
 | 0 | ||||||||||||
| 449 | ev->ignore(); | - | ||||||||||||
| 450 | return; never executed:  return; | 0 | ||||||||||||
| 451 | } | - | ||||||||||||
| 452 | ev->accept(); | - | ||||||||||||
| 453 | QStyle::SubControl oldPressed = QStyle::SubControl(d->pressedControl); | - | ||||||||||||
| 454 | d->pressedControl = QStyle::SC_None; | - | ||||||||||||
| 455 | setRepeatAction(SliderNoAction); | - | ||||||||||||
| 456 | if (oldPressed == QStyle::SC_SliderHandle) 
 | 0 | ||||||||||||
| 457 | setSliderDown(false); never executed:  setSliderDown(false); | 0 | ||||||||||||
| 458 | QStyleOptionSlider opt; | - | ||||||||||||
| 459 | initStyleOption(&opt); | - | ||||||||||||
| 460 | opt.subControls = oldPressed; | - | ||||||||||||
| 461 | update(style()->subControlRect(QStyle::CC_Slider, &opt, oldPressed, this)); | - | ||||||||||||
| 462 | } never executed:  end of block | 0 | ||||||||||||
| 463 | - | |||||||||||||
| 464 | /*! | - | ||||||||||||
| 465 | \reimp | - | ||||||||||||
| 466 | */ | - | ||||||||||||
| 467 | QSize QSlider::sizeHint() const | - | ||||||||||||
| 468 | { | - | ||||||||||||
| 469 | Q_D(const QSlider); | - | ||||||||||||
| 470 | ensurePolished(); | - | ||||||||||||
| 471 | const int SliderLength = 84, TickSpace = 5; | - | ||||||||||||
| 472 | QStyleOptionSlider opt; | - | ||||||||||||
| 473 | initStyleOption(&opt); | - | ||||||||||||
| 474 | int thick = style()->pixelMetric(QStyle::PM_SliderThickness, &opt, this); | - | ||||||||||||
| 475 | if (d->tickPosition & TicksAbove) 
 | 0 | ||||||||||||
| 476 | thick += TickSpace; never executed:  thick += TickSpace; | 0 | ||||||||||||
| 477 | if (d->tickPosition & TicksBelow) 
 | 0 | ||||||||||||
| 478 | thick += TickSpace; never executed:  thick += TickSpace; | 0 | ||||||||||||
| 479 | int w = thick, h = SliderLength; | - | ||||||||||||
| 480 | if (d->orientation == Qt::Horizontal) { 
 | 0 | ||||||||||||
| 481 | w = SliderLength; | - | ||||||||||||
| 482 | h = thick; | - | ||||||||||||
| 483 | } never executed:  end of block | 0 | ||||||||||||
| 484 | return style()->sizeFromContents(QStyle::CT_Slider, &opt, QSize(w, h), this).expandedTo(QApplication::globalStrut()); never executed:  return style()->sizeFromContents(QStyle::CT_Slider, &opt, QSize(w, h), this).expandedTo(QApplication::globalStrut()); | 0 | ||||||||||||
| 485 | } | - | ||||||||||||
| 486 | - | |||||||||||||
| 487 | /*! | - | ||||||||||||
| 488 | \reimp | - | ||||||||||||
| 489 | */ | - | ||||||||||||
| 490 | QSize QSlider::minimumSizeHint() const | - | ||||||||||||
| 491 | { | - | ||||||||||||
| 492 | Q_D(const QSlider); | - | ||||||||||||
| 493 | QSize s = sizeHint(); | - | ||||||||||||
| 494 | QStyleOptionSlider opt; | - | ||||||||||||
| 495 | initStyleOption(&opt); | - | ||||||||||||
| 496 | int length = style()->pixelMetric(QStyle::PM_SliderLength, &opt, this); | - | ||||||||||||
| 497 | if (d->orientation == Qt::Horizontal) 
 | 0 | ||||||||||||
| 498 | s.setWidth(length); never executed:  s.setWidth(length); | 0 | ||||||||||||
| 499 | else | - | ||||||||||||
| 500 | s.setHeight(length); never executed:  s.setHeight(length); | 0 | ||||||||||||
| 501 | return s; never executed:  return s; | 0 | ||||||||||||
| 502 | } | - | ||||||||||||
| 503 | - | |||||||||||||
| 504 | /*! | - | ||||||||||||
| 505 | \property QSlider::tickPosition | - | ||||||||||||
| 506 | \brief the tickmark position for this slider | - | ||||||||||||
| 507 | - | |||||||||||||
| 508 | The valid values are described by the QSlider::TickPosition enum. | - | ||||||||||||
| 509 | - | |||||||||||||
| 510 | The default value is \l QSlider::NoTicks. | - | ||||||||||||
| 511 | - | |||||||||||||
| 512 | \sa tickInterval | - | ||||||||||||
| 513 | */ | - | ||||||||||||
| 514 | - | |||||||||||||
| 515 | void QSlider::setTickPosition(TickPosition position) | - | ||||||||||||
| 516 | { | - | ||||||||||||
| 517 | Q_D(QSlider); | - | ||||||||||||
| 518 | d->tickPosition = position; | - | ||||||||||||
| 519 | d->resetLayoutItemMargins(); | - | ||||||||||||
| 520 | update(); | - | ||||||||||||
| 521 | updateGeometry(); | - | ||||||||||||
| 522 | } never executed:  end of block | 0 | ||||||||||||
| 523 | - | |||||||||||||
| 524 | QSlider::TickPosition QSlider::tickPosition() const | - | ||||||||||||
| 525 | { | - | ||||||||||||
| 526 | return d_func()->tickPosition; never executed:  return d_func()->tickPosition; | 0 | ||||||||||||
| 527 | } | - | ||||||||||||
| 528 | - | |||||||||||||
| 529 | /*! | - | ||||||||||||
| 530 | \property QSlider::tickInterval | - | ||||||||||||
| 531 | \brief the interval between tickmarks | - | ||||||||||||
| 532 | - | |||||||||||||
| 533 | This is a value interval, not a pixel interval. If it is 0, the | - | ||||||||||||
| 534 | slider will choose between singleStep and pageStep. | - | ||||||||||||
| 535 | - | |||||||||||||
| 536 | The default value is 0. | - | ||||||||||||
| 537 | - | |||||||||||||
| 538 | \sa tickPosition, singleStep, pageStep | - | ||||||||||||
| 539 | */ | - | ||||||||||||
| 540 | - | |||||||||||||
| 541 | void QSlider::setTickInterval(int ts) | - | ||||||||||||
| 542 | { | - | ||||||||||||
| 543 | d_func()->tickInterval = qMax(0, ts); | - | ||||||||||||
| 544 | update(); | - | ||||||||||||
| 545 | } never executed:  end of block | 0 | ||||||||||||
| 546 | - | |||||||||||||
| 547 | int QSlider::tickInterval() const | - | ||||||||||||
| 548 | { | - | ||||||||||||
| 549 | return d_func()->tickInterval; never executed:  return d_func()->tickInterval; | 0 | ||||||||||||
| 550 | } | - | ||||||||||||
| 551 | - | |||||||||||||
| 552 | Q_WIDGETS_EXPORT QStyleOptionSlider qt_qsliderStyleOption(QSlider *slider) | - | ||||||||||||
| 553 | { | - | ||||||||||||
| 554 | QStyleOptionSlider sliderOption; | - | ||||||||||||
| 555 | slider->initStyleOption(&sliderOption); | - | ||||||||||||
| 556 | return sliderOption; never executed:  return sliderOption; | 0 | ||||||||||||
| 557 | } | - | ||||||||||||
| 558 | - | |||||||||||||
| 559 | #endif | - | ||||||||||||
| 560 | - | |||||||||||||
| 561 | QT_END_NAMESPACE | - | ||||||||||||
| 562 | - | |||||||||||||
| 563 | #include "moc_qslider.cpp" | - | ||||||||||||
| Source code | Switch to Preprocessed file |