Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/widgets/widgets/qscrollbar.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||||||||||||||
2 | ** | - | ||||||||||||||||||
3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||||||||||||||
4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||||||||||||||
5 | ** | - | ||||||||||||||||||
6 | ** This file is part of the QtWidgets module of the Qt Toolkit. | - | ||||||||||||||||||
7 | ** | - | ||||||||||||||||||
8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||||||||||||||
9 | ** Commercial License Usage | - | ||||||||||||||||||
10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||||||||
11 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||||||||
12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||||||||
13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||||||||
14 | ** and conditions see http://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||
15 | ** information use the contact form at http://www.qt.io/contact-us. | - | ||||||||||||||||||
16 | ** | - | ||||||||||||||||||
17 | ** GNU Lesser General Public License Usage | - | ||||||||||||||||||
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||||||||
19 | ** General Public License version 2.1 or version 3 as published by the Free | - | ||||||||||||||||||
20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||||||||||||||
21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||||||||||||||
22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||||||||||||||
23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||||||||||||||
24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||||||||||||||
25 | ** | - | ||||||||||||||||||
26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||||||||||||||
27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||||||||||||||
28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||||||||||||||
29 | ** | - | ||||||||||||||||||
30 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||
31 | ** | - | ||||||||||||||||||
32 | ****************************************************************************/ | - | ||||||||||||||||||
33 | - | |||||||||||||||||||
34 | #include "qapplication.h" | - | ||||||||||||||||||
35 | #include "qcursor.h" | - | ||||||||||||||||||
36 | #include "qevent.h" | - | ||||||||||||||||||
37 | #include "qpainter.h" | - | ||||||||||||||||||
38 | #include "qscrollbar.h" | - | ||||||||||||||||||
39 | #include "qstyle.h" | - | ||||||||||||||||||
40 | #include "qstyleoption.h" | - | ||||||||||||||||||
41 | #include "qmenu.h" | - | ||||||||||||||||||
42 | #include <QtCore/qelapsedtimer.h> | - | ||||||||||||||||||
43 | - | |||||||||||||||||||
44 | #ifndef QT_NO_SCROLLBAR | - | ||||||||||||||||||
45 | - | |||||||||||||||||||
46 | #ifndef QT_NO_ACCESSIBILITY | - | ||||||||||||||||||
47 | #include "qaccessible.h" | - | ||||||||||||||||||
48 | #endif | - | ||||||||||||||||||
49 | #include <limits.h> | - | ||||||||||||||||||
50 | #include "qscrollbar_p.h" | - | ||||||||||||||||||
51 | - | |||||||||||||||||||
52 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||
53 | - | |||||||||||||||||||
54 | /*! | - | ||||||||||||||||||
55 | \class QScrollBar | - | ||||||||||||||||||
56 | \brief The QScrollBar widget provides a vertical or horizontal scroll bar. | - | ||||||||||||||||||
57 | - | |||||||||||||||||||
58 | \ingroup basicwidgets | - | ||||||||||||||||||
59 | \inmodule QtWidgets | - | ||||||||||||||||||
60 | - | |||||||||||||||||||
61 | A scroll bar is a control that enables the user to access parts of a | - | ||||||||||||||||||
62 | document that is larger than the widget used to display it. It provides | - | ||||||||||||||||||
63 | a visual indication of the user's current position within the document | - | ||||||||||||||||||
64 | and the amount of the document that is visible. Scroll bars are usually | - | ||||||||||||||||||
65 | equipped with other controls that enable more accurate navigation. | - | ||||||||||||||||||
66 | Qt displays scroll bars in a way that is appropriate for each platform. | - | ||||||||||||||||||
67 | - | |||||||||||||||||||
68 | If you need to provide a scrolling view onto another widget, it may be | - | ||||||||||||||||||
69 | more convenient to use the QScrollArea class because this provides a | - | ||||||||||||||||||
70 | viewport widget and scroll bars. QScrollBar is useful if you need to | - | ||||||||||||||||||
71 | implement similar functionality for specialized widgets using QAbstractScrollArea; | - | ||||||||||||||||||
72 | for example, if you decide to subclass QAbstractItemView. | - | ||||||||||||||||||
73 | For most other situations where a slider control is used to obtain a value | - | ||||||||||||||||||
74 | within a given range, the QSlider class may be more appropriate for your | - | ||||||||||||||||||
75 | needs. | - | ||||||||||||||||||
76 | - | |||||||||||||||||||
77 | \table | - | ||||||||||||||||||
78 | \row \li \image qscrollbar-picture.png | - | ||||||||||||||||||
79 | \li Scroll bars typically include four separate controls: a slider, | - | ||||||||||||||||||
80 | scroll arrows, and a page control. | - | ||||||||||||||||||
81 | - | |||||||||||||||||||
82 | \list | - | ||||||||||||||||||
83 | \li a. The slider provides a way to quickly go to any part of the | - | ||||||||||||||||||
84 | document, but does not support accurate navigation within large | - | ||||||||||||||||||
85 | documents. | - | ||||||||||||||||||
86 | \li b. The scroll arrows are push buttons which can be used to accurately | - | ||||||||||||||||||
87 | navigate to a particular place in a document. For a vertical scroll bar | - | ||||||||||||||||||
88 | connected to a text editor, these typically move the current position one | - | ||||||||||||||||||
89 | "line" up or down, and adjust the position of the slider by a small | - | ||||||||||||||||||
90 | amount. In editors and list boxes a "line" might mean one line of text; | - | ||||||||||||||||||
91 | in an image viewer it might mean 20 pixels. | - | ||||||||||||||||||
92 | \li c. The page control is the area over which the slider is dragged (the | - | ||||||||||||||||||
93 | scroll bar's background). Clicking here moves the scroll bar towards | - | ||||||||||||||||||
94 | the click by one "page". This value is usually the same as the length of | - | ||||||||||||||||||
95 | the slider. | - | ||||||||||||||||||
96 | \endlist | - | ||||||||||||||||||
97 | \endtable | - | ||||||||||||||||||
98 | - | |||||||||||||||||||
99 | Each scroll bar has a value that indicates how far the slider is from | - | ||||||||||||||||||
100 | the start of the scroll bar; this is obtained with value() and set | - | ||||||||||||||||||
101 | with setValue(). This value always lies within the range of values | - | ||||||||||||||||||
102 | defined for the scroll bar, from \l{QAbstractSlider::minimum()}{minimum()} | - | ||||||||||||||||||
103 | to \l{QAbstractSlider::minimum()}{maximum()} inclusive. The range of | - | ||||||||||||||||||
104 | acceptable values can be set with setMinimum() and setMaximum(). | - | ||||||||||||||||||
105 | At the minimum value, the top edge of the slider (for a vertical scroll | - | ||||||||||||||||||
106 | bar) or left edge (for a horizontal scroll bar) will be at the top (or | - | ||||||||||||||||||
107 | left) end of the scroll bar. At the maximum value, the bottom (or right) | - | ||||||||||||||||||
108 | edge of the slider will be at the bottom (or right) end of the scroll bar. | - | ||||||||||||||||||
109 | - | |||||||||||||||||||
110 | The length of the slider is usually related to the value of the page step, | - | ||||||||||||||||||
111 | and typically represents the proportion of the document area shown in a | - | ||||||||||||||||||
112 | scrolling view. The page step is the amount that the value changes by | - | ||||||||||||||||||
113 | when the user presses the \uicontrol{Page Up} and \uicontrol{Page Down} keys, and is | - | ||||||||||||||||||
114 | set with setPageStep(). Smaller changes to the value defined by the | - | ||||||||||||||||||
115 | line step are made using the cursor keys, and this quantity is set with | - | ||||||||||||||||||
116 | \l{QAbstractSlider::}{setSingleStep()}. | - | ||||||||||||||||||
117 | - | |||||||||||||||||||
118 | Note that the range of values used is independent of the actual size | - | ||||||||||||||||||
119 | of the scroll bar widget. You do not need to take this into account when | - | ||||||||||||||||||
120 | you choose values for the range and the page step. | - | ||||||||||||||||||
121 | - | |||||||||||||||||||
122 | The range of values specified for the scroll bar are often determined | - | ||||||||||||||||||
123 | differently to those for a QSlider because the length of the slider | - | ||||||||||||||||||
124 | needs to be taken into account. If we have a document with 100 lines, | - | ||||||||||||||||||
125 | and we can only show 20 lines in a widget, we may wish to construct a | - | ||||||||||||||||||
126 | scroll bar with a page step of 20, a minimum value of 0, and a maximum | - | ||||||||||||||||||
127 | value of 80. This would give us a scroll bar with five "pages". | - | ||||||||||||||||||
128 | - | |||||||||||||||||||
129 | \table | - | ||||||||||||||||||
130 | \row \li \inlineimage qscrollbar-values.png | - | ||||||||||||||||||
131 | \li The relationship between a document length, the range of values used | - | ||||||||||||||||||
132 | in a scroll bar, and the page step is simple in many common situations. | - | ||||||||||||||||||
133 | The scroll bar's range of values is determined by subtracting a | - | ||||||||||||||||||
134 | chosen page step from some value representing the length of the document. | - | ||||||||||||||||||
135 | In such cases, the following equation is useful: | - | ||||||||||||||||||
136 | \e{document length} = maximum() - minimum() + pageStep(). | - | ||||||||||||||||||
137 | \endtable | - | ||||||||||||||||||
138 | - | |||||||||||||||||||
139 | QScrollBar only provides integer ranges. Note that although | - | ||||||||||||||||||
140 | QScrollBar handles very large numbers, scroll bars on current | - | ||||||||||||||||||
141 | screens cannot usefully represent ranges above about 100,000 pixels. | - | ||||||||||||||||||
142 | Beyond that, it becomes difficult for the user to control the | - | ||||||||||||||||||
143 | slider using either the keyboard or the mouse, and the scroll | - | ||||||||||||||||||
144 | arrows will have limited use. | - | ||||||||||||||||||
145 | - | |||||||||||||||||||
146 | ScrollBar inherits a comprehensive set of signals from QAbstractSlider: | - | ||||||||||||||||||
147 | \list | - | ||||||||||||||||||
148 | \li \l{QAbstractSlider::valueChanged()}{valueChanged()} is emitted when the | - | ||||||||||||||||||
149 | scroll bar's value has changed. The tracking() determines whether this | - | ||||||||||||||||||
150 | signal is emitted during user interaction. | - | ||||||||||||||||||
151 | \li \l{QAbstractSlider::rangeChanged()}{rangeChanged()} is emitted when the | - | ||||||||||||||||||
152 | scroll bar's range of values has changed. | - | ||||||||||||||||||
153 | \li \l{QAbstractSlider::sliderPressed()}{sliderPressed()} is emitted when | - | ||||||||||||||||||
154 | the user starts to drag the slider. | - | ||||||||||||||||||
155 | \li \l{QAbstractSlider::sliderMoved()}{sliderMoved()} is emitted when the user | - | ||||||||||||||||||
156 | drags the slider. | - | ||||||||||||||||||
157 | \li \l{QAbstractSlider::sliderReleased()}{sliderReleased()} is emitted when | - | ||||||||||||||||||
158 | the user releases the slider. | - | ||||||||||||||||||
159 | \li \l{QAbstractSlider::actionTriggered()}{actionTriggered()} is emitted | - | ||||||||||||||||||
160 | when the scroll bar is changed by user interaction or via the | - | ||||||||||||||||||
161 | \l{QAbstractSlider::triggerAction()}{triggerAction()} function. | - | ||||||||||||||||||
162 | \endlist | - | ||||||||||||||||||
163 | - | |||||||||||||||||||
164 | A scroll bar can be controlled by the keyboard, but it has a | - | ||||||||||||||||||
165 | default focusPolicy() of Qt::NoFocus. Use setFocusPolicy() to | - | ||||||||||||||||||
166 | enable keyboard interaction with the scroll bar: | - | ||||||||||||||||||
167 | \list | - | ||||||||||||||||||
168 | \li Left/Right move a horizontal scroll bar by one single step. | - | ||||||||||||||||||
169 | \li Up/Down move a vertical scroll bar by one single step. | - | ||||||||||||||||||
170 | \li PageUp moves up one page. | - | ||||||||||||||||||
171 | \li PageDown moves down one page. | - | ||||||||||||||||||
172 | \li Home moves to the start (mininum). | - | ||||||||||||||||||
173 | \li End moves to the end (maximum). | - | ||||||||||||||||||
174 | \endlist | - | ||||||||||||||||||
175 | - | |||||||||||||||||||
176 | The slider itself can be controlled by using the | - | ||||||||||||||||||
177 | \l{QAbstractSlider::triggerAction()}{triggerAction()} function to simulate | - | ||||||||||||||||||
178 | user interaction with the scroll bar controls. This is useful if you have | - | ||||||||||||||||||
179 | many different widgets that use a common range of values. | - | ||||||||||||||||||
180 | - | |||||||||||||||||||
181 | Most GUI styles use the pageStep() value to calculate the size of the | - | ||||||||||||||||||
182 | slider. | - | ||||||||||||||||||
183 | - | |||||||||||||||||||
184 | \table 100% | - | ||||||||||||||||||
185 | \row \li \inlineimage macintosh-horizontalscrollbar.png Screenshot of a Macintosh style scroll bar | - | ||||||||||||||||||
186 | \li A scroll bar shown in the \l{Macintosh Style Widget Gallery}{Macintosh widget style}. | - | ||||||||||||||||||
187 | \row \li \inlineimage windowsvista-horizontalscrollbar.png Screenshot of a Windows Vista style scroll bar | - | ||||||||||||||||||
188 | \li A scroll bar shown in the \l{Windows Vista Style Widget Gallery}{Windows Vista widget style}. | - | ||||||||||||||||||
189 | \row \li \inlineimage fusion-horizontalscrollbar.png Screenshot of a Fusion style scroll bar | - | ||||||||||||||||||
190 | \li A scroll bar shown in the \l{Fusion Style Widget Gallery}{Fusion widget style}. | - | ||||||||||||||||||
191 | \endtable | - | ||||||||||||||||||
192 | - | |||||||||||||||||||
193 | \sa QScrollArea, QSlider, QDial, QSpinBox, {fowler}{GUI Design Handbook: Scroll Bar}, {Sliders Example} | - | ||||||||||||||||||
194 | */ | - | ||||||||||||||||||
195 | - | |||||||||||||||||||
196 | bool QScrollBarPrivate::updateHoverControl(const QPoint &pos) | - | ||||||||||||||||||
197 | { | - | ||||||||||||||||||
198 | Q_Q(QScrollBar); | - | ||||||||||||||||||
199 | QRect lastHoverRect = hoverRect; | - | ||||||||||||||||||
200 | QStyle::SubControl lastHoverControl = hoverControl; | - | ||||||||||||||||||
201 | bool doesHover = q->testAttribute(Qt::WA_Hover); | - | ||||||||||||||||||
202 | if (lastHoverControl != newHoverControl(pos) && doesHover) {
| 0 | ||||||||||||||||||
203 | q->update(lastHoverRect); | - | ||||||||||||||||||
204 | q->update(hoverRect); | - | ||||||||||||||||||
205 | return true; never executed: return true; | 0 | ||||||||||||||||||
206 | } | - | ||||||||||||||||||
207 | return !doesHover; never executed: return !doesHover; | 0 | ||||||||||||||||||
208 | } | - | ||||||||||||||||||
209 | - | |||||||||||||||||||
210 | QStyle::SubControl QScrollBarPrivate::newHoverControl(const QPoint &pos) | - | ||||||||||||||||||
211 | { | - | ||||||||||||||||||
212 | Q_Q(QScrollBar); | - | ||||||||||||||||||
213 | QStyleOptionSlider opt; | - | ||||||||||||||||||
214 | q->initStyleOption(&opt); | - | ||||||||||||||||||
215 | opt.subControls = QStyle::SC_All; | - | ||||||||||||||||||
216 | hoverControl = q->style()->hitTestComplexControl(QStyle::CC_ScrollBar, &opt, pos, q); | - | ||||||||||||||||||
217 | if (hoverControl == QStyle::SC_None)
| 0 | ||||||||||||||||||
218 | hoverRect = QRect(); never executed: hoverRect = QRect(); | 0 | ||||||||||||||||||
219 | else | - | ||||||||||||||||||
220 | hoverRect = q->style()->subControlRect(QStyle::CC_ScrollBar, &opt, hoverControl, q); never executed: hoverRect = q->style()->subControlRect(QStyle::CC_ScrollBar, &opt, hoverControl, q); | 0 | ||||||||||||||||||
221 | return hoverControl; never executed: return hoverControl; | 0 | ||||||||||||||||||
222 | } | - | ||||||||||||||||||
223 | - | |||||||||||||||||||
224 | void QScrollBarPrivate::setTransient(bool value) | - | ||||||||||||||||||
225 | { | - | ||||||||||||||||||
226 | Q_Q(QScrollBar); | - | ||||||||||||||||||
227 | if (transient != value) {
| 0 | ||||||||||||||||||
228 | transient = value; | - | ||||||||||||||||||
229 | if (q->isVisible()) {
| 0 | ||||||||||||||||||
230 | if (q->style()->styleHint(QStyle::SH_ScrollBar_Transient, 0, q))
| 0 | ||||||||||||||||||
231 | q->update(); never executed: q->update(); | 0 | ||||||||||||||||||
232 | } else if (!transient) { never executed: end of block
| 0 | ||||||||||||||||||
233 | q->show(); | - | ||||||||||||||||||
234 | } never executed: end of block | 0 | ||||||||||||||||||
235 | } never executed: end of block | 0 | ||||||||||||||||||
236 | } never executed: end of block | 0 | ||||||||||||||||||
237 | - | |||||||||||||||||||
238 | void QScrollBarPrivate::flash() | - | ||||||||||||||||||
239 | { | - | ||||||||||||||||||
240 | Q_Q(QScrollBar); | - | ||||||||||||||||||
241 | if (!flashed && q->style()->styleHint(QStyle::SH_ScrollBar_Transient, 0, q)) {
| 0 | ||||||||||||||||||
242 | flashed = true; | - | ||||||||||||||||||
243 | if (!q->isVisible())
| 0 | ||||||||||||||||||
244 | q->show(); never executed: q->show(); | 0 | ||||||||||||||||||
245 | else | - | ||||||||||||||||||
246 | q->update(); never executed: q->update(); | 0 | ||||||||||||||||||
247 | } | - | ||||||||||||||||||
248 | if (!flashTimer)
| 0 | ||||||||||||||||||
249 | flashTimer = q->startTimer(0); never executed: flashTimer = q->startTimer(0); | 0 | ||||||||||||||||||
250 | } never executed: end of block | 0 | ||||||||||||||||||
251 | - | |||||||||||||||||||
252 | void QScrollBarPrivate::activateControl(uint control, int threshold) | - | ||||||||||||||||||
253 | { | - | ||||||||||||||||||
254 | QAbstractSlider::SliderAction action = QAbstractSlider::SliderNoAction; | - | ||||||||||||||||||
255 | switch (control) { | - | ||||||||||||||||||
256 | case QStyle::SC_ScrollBarAddPage: never executed: case QStyle::SC_ScrollBarAddPage: | 0 | ||||||||||||||||||
257 | action = QAbstractSlider::SliderPageStepAdd; | - | ||||||||||||||||||
258 | break; never executed: break; | 0 | ||||||||||||||||||
259 | case QStyle::SC_ScrollBarSubPage: never executed: case QStyle::SC_ScrollBarSubPage: | 0 | ||||||||||||||||||
260 | action = QAbstractSlider::SliderPageStepSub; | - | ||||||||||||||||||
261 | break; never executed: break; | 0 | ||||||||||||||||||
262 | case QStyle::SC_ScrollBarAddLine: never executed: case QStyle::SC_ScrollBarAddLine: | 0 | ||||||||||||||||||
263 | action = QAbstractSlider::SliderSingleStepAdd; | - | ||||||||||||||||||
264 | break; never executed: break; | 0 | ||||||||||||||||||
265 | case QStyle::SC_ScrollBarSubLine: never executed: case QStyle::SC_ScrollBarSubLine: | 0 | ||||||||||||||||||
266 | action = QAbstractSlider::SliderSingleStepSub; | - | ||||||||||||||||||
267 | break; never executed: break; | 0 | ||||||||||||||||||
268 | case QStyle::SC_ScrollBarFirst: never executed: case QStyle::SC_ScrollBarFirst: | 0 | ||||||||||||||||||
269 | action = QAbstractSlider::SliderToMinimum; | - | ||||||||||||||||||
270 | break; never executed: break; | 0 | ||||||||||||||||||
271 | case QStyle::SC_ScrollBarLast: never executed: case QStyle::SC_ScrollBarLast: | 0 | ||||||||||||||||||
272 | action = QAbstractSlider::SliderToMaximum; | - | ||||||||||||||||||
273 | break; never executed: break; | 0 | ||||||||||||||||||
274 | default: never executed: default: | 0 | ||||||||||||||||||
275 | break; never executed: break; | 0 | ||||||||||||||||||
276 | } | - | ||||||||||||||||||
277 | - | |||||||||||||||||||
278 | if (action) {
| 0 | ||||||||||||||||||
279 | q_func()->setRepeatAction(action, threshold); | - | ||||||||||||||||||
280 | q_func()->triggerAction(action); | - | ||||||||||||||||||
281 | } never executed: end of block | 0 | ||||||||||||||||||
282 | } never executed: end of block | 0 | ||||||||||||||||||
283 | - | |||||||||||||||||||
284 | void QScrollBarPrivate::stopRepeatAction() | - | ||||||||||||||||||
285 | { | - | ||||||||||||||||||
286 | Q_Q(QScrollBar); | - | ||||||||||||||||||
287 | QStyle::SubControl tmp = pressedControl; | - | ||||||||||||||||||
288 | q->setRepeatAction(QAbstractSlider::SliderNoAction); | - | ||||||||||||||||||
289 | pressedControl = QStyle::SC_None; | - | ||||||||||||||||||
290 | - | |||||||||||||||||||
291 | if (tmp == QStyle::SC_ScrollBarSlider)
| 0 | ||||||||||||||||||
292 | q->setSliderDown(false); never executed: q->setSliderDown(false); | 0 | ||||||||||||||||||
293 | - | |||||||||||||||||||
294 | QStyleOptionSlider opt; | - | ||||||||||||||||||
295 | q->initStyleOption(&opt); | - | ||||||||||||||||||
296 | q->repaint(q->style()->subControlRect(QStyle::CC_ScrollBar, &opt, tmp, q)); | - | ||||||||||||||||||
297 | } never executed: end of block | 0 | ||||||||||||||||||
298 | - | |||||||||||||||||||
299 | /*! | - | ||||||||||||||||||
300 | Initialize \a option with the values from this QScrollBar. This method | - | ||||||||||||||||||
301 | is useful for subclasses when they need a QStyleOptionSlider, but don't want | - | ||||||||||||||||||
302 | to fill in all the information themselves. | - | ||||||||||||||||||
303 | - | |||||||||||||||||||
304 | \sa QStyleOption::initFrom() | - | ||||||||||||||||||
305 | */ | - | ||||||||||||||||||
306 | void QScrollBar::initStyleOption(QStyleOptionSlider *option) const | - | ||||||||||||||||||
307 | { | - | ||||||||||||||||||
308 | if (!option)
| 0 | ||||||||||||||||||
309 | return; never executed: return; | 0 | ||||||||||||||||||
310 | - | |||||||||||||||||||
311 | Q_D(const QScrollBar); | - | ||||||||||||||||||
312 | option->initFrom(this); | - | ||||||||||||||||||
313 | option->subControls = QStyle::SC_None; | - | ||||||||||||||||||
314 | option->activeSubControls = QStyle::SC_None; | - | ||||||||||||||||||
315 | option->orientation = d->orientation; | - | ||||||||||||||||||
316 | option->minimum = d->minimum; | - | ||||||||||||||||||
317 | option->maximum = d->maximum; | - | ||||||||||||||||||
318 | option->sliderPosition = d->position; | - | ||||||||||||||||||
319 | option->sliderValue = d->value; | - | ||||||||||||||||||
320 | option->singleStep = d->singleStep; | - | ||||||||||||||||||
321 | option->pageStep = d->pageStep; | - | ||||||||||||||||||
322 | option->upsideDown = d->invertedAppearance; | - | ||||||||||||||||||
323 | if (d->orientation == Qt::Horizontal)
| 0 | ||||||||||||||||||
324 | option->state |= QStyle::State_Horizontal; never executed: option->state |= QStyle::State_Horizontal; | 0 | ||||||||||||||||||
325 | if ((d->flashed || !d->transient) && style()->styleHint(QStyle::SH_ScrollBar_Transient, 0, this))
| 0 | ||||||||||||||||||
326 | option->state |= QStyle::State_On; never executed: option->state |= QStyle::State_On; | 0 | ||||||||||||||||||
327 | } never executed: end of block | 0 | ||||||||||||||||||
328 | - | |||||||||||||||||||
329 | - | |||||||||||||||||||
330 | #define HORIZONTAL (d_func()->orientation == Qt::Horizontal) | - | ||||||||||||||||||
331 | #define VERTICAL !HORIZONTAL | - | ||||||||||||||||||
332 | - | |||||||||||||||||||
333 | /*! | - | ||||||||||||||||||
334 | Constructs a vertical scroll bar. | - | ||||||||||||||||||
335 | - | |||||||||||||||||||
336 | The \a parent argument is sent to the QWidget constructor. | - | ||||||||||||||||||
337 | - | |||||||||||||||||||
338 | The \l {QAbstractSlider::minimum} {minimum} defaults to 0, the | - | ||||||||||||||||||
339 | \l {QAbstractSlider::maximum} {maximum} to 99, with a | - | ||||||||||||||||||
340 | \l {QAbstractSlider::singleStep} {singleStep} size of 1 and a | - | ||||||||||||||||||
341 | \l {QAbstractSlider::pageStep} {pageStep} size of 10, and an | - | ||||||||||||||||||
342 | initial \l {QAbstractSlider::value} {value} of 0. | - | ||||||||||||||||||
343 | */ | - | ||||||||||||||||||
344 | QScrollBar::QScrollBar(QWidget *parent) | - | ||||||||||||||||||
345 | : QAbstractSlider(*new QScrollBarPrivate, parent) | - | ||||||||||||||||||
346 | { | - | ||||||||||||||||||
347 | d_func()->orientation = Qt::Vertical; | - | ||||||||||||||||||
348 | d_func()->init(); | - | ||||||||||||||||||
349 | } never executed: end of block | 0 | ||||||||||||||||||
350 | - | |||||||||||||||||||
351 | /*! | - | ||||||||||||||||||
352 | Constructs a scroll bar with the given \a orientation. | - | ||||||||||||||||||
353 | - | |||||||||||||||||||
354 | The \a parent argument is passed to the QWidget constructor. | - | ||||||||||||||||||
355 | - | |||||||||||||||||||
356 | The \l {QAbstractSlider::minimum} {minimum} defaults to 0, the | - | ||||||||||||||||||
357 | \l {QAbstractSlider::maximum} {maximum} to 99, with a | - | ||||||||||||||||||
358 | \l {QAbstractSlider::singleStep} {singleStep} size of 1 and a | - | ||||||||||||||||||
359 | \l {QAbstractSlider::pageStep} {pageStep} size of 10, and an | - | ||||||||||||||||||
360 | initial \l {QAbstractSlider::value} {value} of 0. | - | ||||||||||||||||||
361 | */ | - | ||||||||||||||||||
362 | QScrollBar::QScrollBar(Qt::Orientation orientation, QWidget *parent) | - | ||||||||||||||||||
363 | : QAbstractSlider(*new QScrollBarPrivate, parent) | - | ||||||||||||||||||
364 | { | - | ||||||||||||||||||
365 | d_func()->orientation = orientation; | - | ||||||||||||||||||
366 | d_func()->init(); | - | ||||||||||||||||||
367 | } never executed: end of block | 0 | ||||||||||||||||||
368 | - | |||||||||||||||||||
369 | - | |||||||||||||||||||
370 | - | |||||||||||||||||||
371 | /*! | - | ||||||||||||||||||
372 | Destroys the scroll bar. | - | ||||||||||||||||||
373 | */ | - | ||||||||||||||||||
374 | QScrollBar::~QScrollBar() | - | ||||||||||||||||||
375 | { | - | ||||||||||||||||||
376 | } | - | ||||||||||||||||||
377 | - | |||||||||||||||||||
378 | void QScrollBarPrivate::init() | - | ||||||||||||||||||
379 | { | - | ||||||||||||||||||
380 | Q_Q(QScrollBar); | - | ||||||||||||||||||
381 | invertedControls = true; | - | ||||||||||||||||||
382 | pressedControl = hoverControl = QStyle::SC_None; | - | ||||||||||||||||||
383 | pointerOutsidePressedControl = false; | - | ||||||||||||||||||
384 | transient = q->style()->styleHint(QStyle::SH_ScrollBar_Transient, 0, q); | - | ||||||||||||||||||
385 | flashed = false; | - | ||||||||||||||||||
386 | flashTimer = 0; | - | ||||||||||||||||||
387 | q->setFocusPolicy(Qt::NoFocus); | - | ||||||||||||||||||
388 | QSizePolicy sp(QSizePolicy::Minimum, QSizePolicy::Fixed, QSizePolicy::Slider); | - | ||||||||||||||||||
389 | if (orientation == Qt::Vertical)
| 0 | ||||||||||||||||||
390 | sp.transpose(); never executed: sp.transpose(); | 0 | ||||||||||||||||||
391 | q->setSizePolicy(sp); | - | ||||||||||||||||||
392 | q->setAttribute(Qt::WA_WState_OwnSizePolicy, false); | - | ||||||||||||||||||
393 | q->setAttribute(Qt::WA_OpaquePaintEvent); | - | ||||||||||||||||||
394 | - | |||||||||||||||||||
395 | #if !defined(QT_NO_CONTEXTMENU) && defined(Q_OS_WINCE) | - | ||||||||||||||||||
396 | if (!q->style()->styleHint(QStyle::SH_ScrollBar_ContextMenu, 0, q)) { | - | ||||||||||||||||||
397 | q->setContextMenuPolicy(Qt::PreventContextMenu); | - | ||||||||||||||||||
398 | } | - | ||||||||||||||||||
399 | #endif | - | ||||||||||||||||||
400 | } never executed: end of block | 0 | ||||||||||||||||||
401 | - | |||||||||||||||||||
402 | #ifndef QT_NO_CONTEXTMENU | - | ||||||||||||||||||
403 | /*! \reimp */ | - | ||||||||||||||||||
404 | void QScrollBar::contextMenuEvent(QContextMenuEvent *event) | - | ||||||||||||||||||
405 | { | - | ||||||||||||||||||
406 | if (!style()->styleHint(QStyle::SH_ScrollBar_ContextMenu, 0, this)) {
| 0 | ||||||||||||||||||
407 | QAbstractSlider::contextMenuEvent(event); | - | ||||||||||||||||||
408 | return ; never executed: return ; | 0 | ||||||||||||||||||
409 | } | - | ||||||||||||||||||
410 | - | |||||||||||||||||||
411 | #ifndef QT_NO_MENU | - | ||||||||||||||||||
412 | bool horiz = HORIZONTAL; | - | ||||||||||||||||||
413 | QPointer<QMenu> menu = new QMenu(this); | - | ||||||||||||||||||
414 | QAction *actScrollHere = menu->addAction(tr("Scroll here")); | - | ||||||||||||||||||
415 | menu->addSeparator(); | - | ||||||||||||||||||
416 | QAction *actScrollTop = menu->addAction(horiz ? tr("Left edge") : tr("Top")); | - | ||||||||||||||||||
417 | QAction *actScrollBottom = menu->addAction(horiz ? tr("Right edge") : tr("Bottom")); | - | ||||||||||||||||||
418 | menu->addSeparator(); | - | ||||||||||||||||||
419 | QAction *actPageUp = menu->addAction(horiz ? tr("Page left") : tr("Page up")); | - | ||||||||||||||||||
420 | QAction *actPageDn = menu->addAction(horiz ? tr("Page right") : tr("Page down")); | - | ||||||||||||||||||
421 | menu->addSeparator(); | - | ||||||||||||||||||
422 | QAction *actScrollUp = menu->addAction(horiz ? tr("Scroll left") : tr("Scroll up")); | - | ||||||||||||||||||
423 | QAction *actScrollDn = menu->addAction(horiz ? tr("Scroll right") : tr("Scroll down")); | - | ||||||||||||||||||
424 | QAction *actionSelected = menu->exec(event->globalPos()); | - | ||||||||||||||||||
425 | delete menu; | - | ||||||||||||||||||
426 | if (actionSelected == 0)
| 0 | ||||||||||||||||||
427 | /* do nothing */ ; never executed: ; | 0 | ||||||||||||||||||
428 | else if (actionSelected == actScrollHere)
| 0 | ||||||||||||||||||
429 | setValue(d_func()->pixelPosToRangeValue(horiz ? event->pos().x() : event->pos().y())); never executed: setValue(d_func()->pixelPosToRangeValue(horiz ? event->pos().x() : event->pos().y())); | 0 | ||||||||||||||||||
430 | else if (actionSelected == actScrollTop)
| 0 | ||||||||||||||||||
431 | triggerAction(QAbstractSlider::SliderToMinimum); never executed: triggerAction(QAbstractSlider::SliderToMinimum); | 0 | ||||||||||||||||||
432 | else if (actionSelected == actScrollBottom)
| 0 | ||||||||||||||||||
433 | triggerAction(QAbstractSlider::SliderToMaximum); never executed: triggerAction(QAbstractSlider::SliderToMaximum); | 0 | ||||||||||||||||||
434 | else if (actionSelected == actPageUp)
| 0 | ||||||||||||||||||
435 | triggerAction(QAbstractSlider::SliderPageStepSub); never executed: triggerAction(QAbstractSlider::SliderPageStepSub); | 0 | ||||||||||||||||||
436 | else if (actionSelected == actPageDn)
| 0 | ||||||||||||||||||
437 | triggerAction(QAbstractSlider::SliderPageStepAdd); never executed: triggerAction(QAbstractSlider::SliderPageStepAdd); | 0 | ||||||||||||||||||
438 | else if (actionSelected == actScrollUp)
| 0 | ||||||||||||||||||
439 | triggerAction(QAbstractSlider::SliderSingleStepSub); never executed: triggerAction(QAbstractSlider::SliderSingleStepSub); | 0 | ||||||||||||||||||
440 | else if (actionSelected == actScrollDn)
| 0 | ||||||||||||||||||
441 | triggerAction(QAbstractSlider::SliderSingleStepAdd); never executed: triggerAction(QAbstractSlider::SliderSingleStepAdd); | 0 | ||||||||||||||||||
442 | #endif // QT_NO_MENU | - | ||||||||||||||||||
443 | } never executed: end of block | 0 | ||||||||||||||||||
444 | #endif // QT_NO_CONTEXTMENU | - | ||||||||||||||||||
445 | - | |||||||||||||||||||
446 | - | |||||||||||||||||||
447 | /*! \reimp */ | - | ||||||||||||||||||
448 | QSize QScrollBar::sizeHint() const | - | ||||||||||||||||||
449 | { | - | ||||||||||||||||||
450 | ensurePolished(); | - | ||||||||||||||||||
451 | QStyleOptionSlider opt; | - | ||||||||||||||||||
452 | initStyleOption(&opt); | - | ||||||||||||||||||
453 | - | |||||||||||||||||||
454 | int scrollBarExtent = style()->pixelMetric(QStyle::PM_ScrollBarExtent, &opt, this); | - | ||||||||||||||||||
455 | int scrollBarSliderMin = style()->pixelMetric(QStyle::PM_ScrollBarSliderMin, &opt, this); | - | ||||||||||||||||||
456 | QSize size; | - | ||||||||||||||||||
457 | if (opt.orientation == Qt::Horizontal)
| 0 | ||||||||||||||||||
458 | size = QSize(scrollBarExtent * 2 + scrollBarSliderMin, scrollBarExtent); never executed: size = QSize(scrollBarExtent * 2 + scrollBarSliderMin, scrollBarExtent); | 0 | ||||||||||||||||||
459 | else | - | ||||||||||||||||||
460 | size = QSize(scrollBarExtent, scrollBarExtent * 2 + scrollBarSliderMin); never executed: size = QSize(scrollBarExtent, scrollBarExtent * 2 + scrollBarSliderMin); | 0 | ||||||||||||||||||
461 | - | |||||||||||||||||||
462 | return style()->sizeFromContents(QStyle::CT_ScrollBar, &opt, size, this) never executed: return style()->sizeFromContents(QStyle::CT_ScrollBar, &opt, size, this) .expandedTo(QApplication::globalStrut()); | 0 | ||||||||||||||||||
463 | .expandedTo(QApplication::globalStrut()); never executed: return style()->sizeFromContents(QStyle::CT_ScrollBar, &opt, size, this) .expandedTo(QApplication::globalStrut()); | 0 | ||||||||||||||||||
464 | } | - | ||||||||||||||||||
465 | - | |||||||||||||||||||
466 | /*!\reimp */ | - | ||||||||||||||||||
467 | void QScrollBar::sliderChange(SliderChange change) | - | ||||||||||||||||||
468 | { | - | ||||||||||||||||||
469 | QAbstractSlider::sliderChange(change); | - | ||||||||||||||||||
470 | } never executed: end of block | 0 | ||||||||||||||||||
471 | - | |||||||||||||||||||
472 | /*! | - | ||||||||||||||||||
473 | \reimp | - | ||||||||||||||||||
474 | */ | - | ||||||||||||||||||
475 | bool QScrollBar::event(QEvent *event) | - | ||||||||||||||||||
476 | { | - | ||||||||||||||||||
477 | Q_D(QScrollBar); | - | ||||||||||||||||||
478 | switch(event->type()) { | - | ||||||||||||||||||
479 | case QEvent::HoverEnter: never executed: case QEvent::HoverEnter: | 0 | ||||||||||||||||||
480 | case QEvent::HoverLeave: never executed: case QEvent::HoverLeave: | 0 | ||||||||||||||||||
481 | case QEvent::HoverMove: never executed: case QEvent::HoverMove: | 0 | ||||||||||||||||||
482 | if (const QHoverEvent *he = static_cast<const QHoverEvent *>(event))
| 0 | ||||||||||||||||||
483 | d_func()->updateHoverControl(he->pos()); never executed: d_func()->updateHoverControl(he->pos()); | 0 | ||||||||||||||||||
484 | break; never executed: break; | 0 | ||||||||||||||||||
485 | case QEvent::StyleChange: never executed: case QEvent::StyleChange: | 0 | ||||||||||||||||||
486 | d_func()->setTransient(style()->styleHint(QStyle::SH_ScrollBar_Transient, 0, this)); | - | ||||||||||||||||||
487 | break; never executed: break; | 0 | ||||||||||||||||||
488 | case QEvent::Timer: never executed: case QEvent::Timer: | 0 | ||||||||||||||||||
489 | if (static_cast<QTimerEvent *>(event)->timerId() == d->flashTimer) {
| 0 | ||||||||||||||||||
490 | if (d->flashed && style()->styleHint(QStyle::SH_ScrollBar_Transient, 0, this)) {
| 0 | ||||||||||||||||||
491 | d->flashed = false; | - | ||||||||||||||||||
492 | update(); | - | ||||||||||||||||||
493 | } never executed: end of block | 0 | ||||||||||||||||||
494 | killTimer(d->flashTimer); | - | ||||||||||||||||||
495 | d->flashTimer = 0; | - | ||||||||||||||||||
496 | } never executed: end of block | 0 | ||||||||||||||||||
497 | break; never executed: break; | 0 | ||||||||||||||||||
498 | default: never executed: default: | 0 | ||||||||||||||||||
499 | break; never executed: break; | 0 | ||||||||||||||||||
500 | } | - | ||||||||||||||||||
501 | return QAbstractSlider::event(event); never executed: return QAbstractSlider::event(event); | 0 | ||||||||||||||||||
502 | } | - | ||||||||||||||||||
503 | - | |||||||||||||||||||
504 | /*! | - | ||||||||||||||||||
505 | \reimp | - | ||||||||||||||||||
506 | */ | - | ||||||||||||||||||
507 | #ifndef QT_NO_WHEELEVENT | - | ||||||||||||||||||
508 | void QScrollBar::wheelEvent(QWheelEvent *event) | - | ||||||||||||||||||
509 | { | - | ||||||||||||||||||
510 | event->ignore(); | - | ||||||||||||||||||
511 | int delta = event->delta(); | - | ||||||||||||||||||
512 | // scrollbar is a special case - in vertical mode it reaches minimum | - | ||||||||||||||||||
513 | // value in the upper position, however QSlider's minimum value is on | - | ||||||||||||||||||
514 | // the bottom. So we need to invert a value, but since the scrollbar is | - | ||||||||||||||||||
515 | // inverted by default, we need to inverse the delta value for the | - | ||||||||||||||||||
516 | // horizontal orientation. | - | ||||||||||||||||||
517 | if (event->orientation() == Qt::Horizontal)
| 0 | ||||||||||||||||||
518 | delta = -delta; never executed: delta = -delta; | 0 | ||||||||||||||||||
519 | Q_D(QScrollBar); | - | ||||||||||||||||||
520 | if (d->scrollByDelta(event->orientation(), event->modifiers(), delta))
| 0 | ||||||||||||||||||
521 | event->accept(); never executed: event->accept(); | 0 | ||||||||||||||||||
522 | - | |||||||||||||||||||
523 | if (event->phase() == Qt::ScrollBegin)
| 0 | ||||||||||||||||||
524 | d->setTransient(false); never executed: d->setTransient(false); | 0 | ||||||||||||||||||
525 | else if (event->phase() == Qt::ScrollEnd)
| 0 | ||||||||||||||||||
526 | d->setTransient(true); never executed: d->setTransient(true); | 0 | ||||||||||||||||||
527 | } never executed: end of block | 0 | ||||||||||||||||||
528 | #endif | - | ||||||||||||||||||
529 | - | |||||||||||||||||||
530 | /*! | - | ||||||||||||||||||
531 | \reimp | - | ||||||||||||||||||
532 | */ | - | ||||||||||||||||||
533 | void QScrollBar::paintEvent(QPaintEvent *) | - | ||||||||||||||||||
534 | { | - | ||||||||||||||||||
535 | Q_D(QScrollBar); | - | ||||||||||||||||||
536 | QPainter p(this); | - | ||||||||||||||||||
537 | QStyleOptionSlider opt; | - | ||||||||||||||||||
538 | initStyleOption(&opt); | - | ||||||||||||||||||
539 | opt.subControls = QStyle::SC_All; | - | ||||||||||||||||||
540 | if (d->pressedControl) {
| 0 | ||||||||||||||||||
541 | opt.activeSubControls = (QStyle::SubControl)d->pressedControl; | - | ||||||||||||||||||
542 | if (!d->pointerOutsidePressedControl)
| 0 | ||||||||||||||||||
543 | opt.state |= QStyle::State_Sunken; never executed: opt.state |= QStyle::State_Sunken; | 0 | ||||||||||||||||||
544 | } else { never executed: end of block | 0 | ||||||||||||||||||
545 | opt.activeSubControls = (QStyle::SubControl)d->hoverControl; | - | ||||||||||||||||||
546 | } never executed: end of block | 0 | ||||||||||||||||||
547 | style()->drawComplexControl(QStyle::CC_ScrollBar, &opt, &p, this); | - | ||||||||||||||||||
548 | } never executed: end of block | 0 | ||||||||||||||||||
549 | - | |||||||||||||||||||
550 | /*! | - | ||||||||||||||||||
551 | \reimp | - | ||||||||||||||||||
552 | */ | - | ||||||||||||||||||
553 | void QScrollBar::mousePressEvent(QMouseEvent *e) | - | ||||||||||||||||||
554 | { | - | ||||||||||||||||||
555 | Q_D(QScrollBar); | - | ||||||||||||||||||
556 | - | |||||||||||||||||||
557 | if (d->repeatActionTimer.isActive())
| 0 | ||||||||||||||||||
558 | d->stopRepeatAction(); never executed: d->stopRepeatAction(); | 0 | ||||||||||||||||||
559 | - | |||||||||||||||||||
560 | bool midButtonAbsPos = style()->styleHint(QStyle::SH_ScrollBar_MiddleClickAbsolutePosition, | - | ||||||||||||||||||
561 | 0, this); | - | ||||||||||||||||||
562 | QStyleOptionSlider opt; | - | ||||||||||||||||||
563 | initStyleOption(&opt); | - | ||||||||||||||||||
564 | - | |||||||||||||||||||
565 | if (d->maximum == d->minimum // no range
| 0 | ||||||||||||||||||
566 | || (e->buttons() & (~e->button())) // another button was clicked before
| 0 | ||||||||||||||||||
567 | || !(e->button() == Qt::LeftButton || (midButtonAbsPos && e->button() == Qt::MidButton)))
| 0 | ||||||||||||||||||
568 | return; never executed: return; | 0 | ||||||||||||||||||
569 | - | |||||||||||||||||||
570 | d->pressedControl = style()->hitTestComplexControl(QStyle::CC_ScrollBar, &opt, e->pos(), this); | - | ||||||||||||||||||
571 | d->pointerOutsidePressedControl = false; | - | ||||||||||||||||||
572 | - | |||||||||||||||||||
573 | QRect sr = style()->subControlRect(QStyle::CC_ScrollBar, &opt, | - | ||||||||||||||||||
574 | QStyle::SC_ScrollBarSlider, this); | - | ||||||||||||||||||
575 | QPoint click = e->pos(); | - | ||||||||||||||||||
576 | QPoint pressValue = click - sr.center() + sr.topLeft(); | - | ||||||||||||||||||
577 | d->pressValue = d->orientation == Qt::Horizontal ? d->pixelPosToRangeValue(pressValue.x()) :
| 0 | ||||||||||||||||||
578 | d->pixelPosToRangeValue(pressValue.y()); | - | ||||||||||||||||||
579 | if (d->pressedControl == QStyle::SC_ScrollBarSlider) {
| 0 | ||||||||||||||||||
580 | d->clickOffset = HORIZONTAL ? (click.x()-sr.x()) : (click.y()-sr.y());
| 0 | ||||||||||||||||||
581 | d->snapBackPosition = d->position; | - | ||||||||||||||||||
582 | } never executed: end of block | 0 | ||||||||||||||||||
583 | - | |||||||||||||||||||
584 | if ((d->pressedControl == QStyle::SC_ScrollBarAddPage
| 0 | ||||||||||||||||||
585 | || d->pressedControl == QStyle::SC_ScrollBarSubPage)
| 0 | ||||||||||||||||||
586 | && ((midButtonAbsPos && e->button() == Qt::MidButton)
| 0 | ||||||||||||||||||
587 | || (style()->styleHint(QStyle::SH_ScrollBar_LeftClickAbsolutePosition, &opt, this)
| 0 | ||||||||||||||||||
588 | && e->button() == Qt::LeftButton))) {
| 0 | ||||||||||||||||||
589 | int sliderLength = HORIZONTAL ? sr.width() : sr.height();
| 0 | ||||||||||||||||||
590 | setSliderPosition(d->pixelPosToRangeValue((HORIZONTAL ? e->pos().x() | - | ||||||||||||||||||
591 | : e->pos().y()) - sliderLength / 2)); | - | ||||||||||||||||||
592 | d->pressedControl = QStyle::SC_ScrollBarSlider; | - | ||||||||||||||||||
593 | d->clickOffset = sliderLength / 2; | - | ||||||||||||||||||
594 | } never executed: end of block | 0 | ||||||||||||||||||
595 | const int initialDelay = 500; // default threshold | - | ||||||||||||||||||
596 | QElapsedTimer time; | - | ||||||||||||||||||
597 | time.start(); | - | ||||||||||||||||||
598 | d->activateControl(d->pressedControl, initialDelay); | - | ||||||||||||||||||
599 | repaint(style()->subControlRect(QStyle::CC_ScrollBar, &opt, d->pressedControl, this)); | - | ||||||||||||||||||
600 | if (time.elapsed() >= initialDelay && d->repeatActionTimer.isActive()) {
| 0 | ||||||||||||||||||
601 | // It took more than 500ms (the initial timer delay) to process | - | ||||||||||||||||||
602 | // the control activation and repaint(), we therefore need | - | ||||||||||||||||||
603 | // to restart the timer in case we have a pending mouse release event; | - | ||||||||||||||||||
604 | // otherwise we'll get a timer event right before the release event, | - | ||||||||||||||||||
605 | // causing the repeat action to be invoked twice on a single mouse click. | - | ||||||||||||||||||
606 | // 50ms is the default repeat time (see activateControl/setRepeatAction). | - | ||||||||||||||||||
607 | d->repeatActionTimer.start(50, this); | - | ||||||||||||||||||
608 | } never executed: end of block | 0 | ||||||||||||||||||
609 | if (d->pressedControl == QStyle::SC_ScrollBarSlider)
| 0 | ||||||||||||||||||
610 | setSliderDown(true); never executed: setSliderDown(true); | 0 | ||||||||||||||||||
611 | } never executed: end of block | 0 | ||||||||||||||||||
612 | - | |||||||||||||||||||
613 | - | |||||||||||||||||||
614 | /*! | - | ||||||||||||||||||
615 | \reimp | - | ||||||||||||||||||
616 | */ | - | ||||||||||||||||||
617 | void QScrollBar::mouseReleaseEvent(QMouseEvent *e) | - | ||||||||||||||||||
618 | { | - | ||||||||||||||||||
619 | Q_D(QScrollBar); | - | ||||||||||||||||||
620 | if (!d->pressedControl)
| 0 | ||||||||||||||||||
621 | return; never executed: return; | 0 | ||||||||||||||||||
622 | - | |||||||||||||||||||
623 | if (e->buttons() & (~e->button())) // some other button is still pressed
| 0 | ||||||||||||||||||
624 | return; never executed: return; | 0 | ||||||||||||||||||
625 | - | |||||||||||||||||||
626 | d->stopRepeatAction(); | - | ||||||||||||||||||
627 | } never executed: end of block | 0 | ||||||||||||||||||
628 | - | |||||||||||||||||||
629 | - | |||||||||||||||||||
630 | /*! | - | ||||||||||||||||||
631 | \reimp | - | ||||||||||||||||||
632 | */ | - | ||||||||||||||||||
633 | void QScrollBar::mouseMoveEvent(QMouseEvent *e) | - | ||||||||||||||||||
634 | { | - | ||||||||||||||||||
635 | Q_D(QScrollBar); | - | ||||||||||||||||||
636 | if (!d->pressedControl)
| 0 | ||||||||||||||||||
637 | return; never executed: return; | 0 | ||||||||||||||||||
638 | - | |||||||||||||||||||
639 | QStyleOptionSlider opt; | - | ||||||||||||||||||
640 | initStyleOption(&opt); | - | ||||||||||||||||||
641 | if (!(e->buttons() & Qt::LeftButton
| 0 | ||||||||||||||||||
642 | || ((e->buttons() & Qt::MidButton)
| 0 | ||||||||||||||||||
643 | && style()->styleHint(QStyle::SH_ScrollBar_MiddleClickAbsolutePosition, &opt, this))))
| 0 | ||||||||||||||||||
644 | return; never executed: return; | 0 | ||||||||||||||||||
645 | - | |||||||||||||||||||
646 | if (d->pressedControl == QStyle::SC_ScrollBarSlider) {
| 0 | ||||||||||||||||||
647 | QPoint click = e->pos(); | - | ||||||||||||||||||
648 | int newPosition = d->pixelPosToRangeValue((HORIZONTAL ? click.x() : click.y()) -d->clickOffset); | - | ||||||||||||||||||
649 | int m = style()->pixelMetric(QStyle::PM_MaximumDragDistance, &opt, this); | - | ||||||||||||||||||
650 | if (m >= 0) {
| 0 | ||||||||||||||||||
651 | QRect r = rect(); | - | ||||||||||||||||||
652 | r.adjust(-m, -m, m, m); | - | ||||||||||||||||||
653 | if (! r.contains(e->pos()))
| 0 | ||||||||||||||||||
654 | newPosition = d->snapBackPosition; never executed: newPosition = d->snapBackPosition; | 0 | ||||||||||||||||||
655 | } never executed: end of block | 0 | ||||||||||||||||||
656 | setSliderPosition(newPosition); | - | ||||||||||||||||||
657 | } else if (!style()->styleHint(QStyle::SH_ScrollBar_ScrollWhenPointerLeavesControl, &opt, this)) { never executed: end of block
| 0 | ||||||||||||||||||
658 | - | |||||||||||||||||||
659 | if (style()->styleHint(QStyle::SH_ScrollBar_RollBetweenButtons, &opt, this)
| 0 | ||||||||||||||||||
660 | && d->pressedControl & (QStyle::SC_ScrollBarAddLine | QStyle::SC_ScrollBarSubLine)) {
| 0 | ||||||||||||||||||
661 | QStyle::SubControl newSc = style()->hitTestComplexControl(QStyle::CC_ScrollBar, &opt, e->pos(), this); | - | ||||||||||||||||||
662 | if (newSc == d->pressedControl && !d->pointerOutsidePressedControl)
| 0 | ||||||||||||||||||
663 | return; // nothing to do never executed: return; | 0 | ||||||||||||||||||
664 | if (newSc & (QStyle::SC_ScrollBarAddLine | QStyle::SC_ScrollBarSubLine)) {
| 0 | ||||||||||||||||||
665 | d->pointerOutsidePressedControl = false; | - | ||||||||||||||||||
666 | QRect scRect = style()->subControlRect(QStyle::CC_ScrollBar, &opt, newSc, this); | - | ||||||||||||||||||
667 | scRect |= style()->subControlRect(QStyle::CC_ScrollBar, &opt, d->pressedControl, this); | - | ||||||||||||||||||
668 | d->pressedControl = newSc; | - | ||||||||||||||||||
669 | d->activateControl(d->pressedControl, 0); | - | ||||||||||||||||||
670 | update(scRect); | - | ||||||||||||||||||
671 | return; never executed: return; | 0 | ||||||||||||||||||
672 | } | - | ||||||||||||||||||
673 | } never executed: end of block | 0 | ||||||||||||||||||
674 | - | |||||||||||||||||||
675 | // stop scrolling when the mouse pointer leaves a control | - | ||||||||||||||||||
676 | // similar to push buttons | - | ||||||||||||||||||
677 | QRect pr = style()->subControlRect(QStyle::CC_ScrollBar, &opt, d->pressedControl, this); | - | ||||||||||||||||||
678 | if (pr.contains(e->pos()) == d->pointerOutsidePressedControl) {
| 0 | ||||||||||||||||||
679 | if ((d->pointerOutsidePressedControl = !d->pointerOutsidePressedControl)) {
| 0 | ||||||||||||||||||
680 | d->pointerOutsidePressedControl = true; | - | ||||||||||||||||||
681 | setRepeatAction(SliderNoAction); | - | ||||||||||||||||||
682 | repaint(pr); | - | ||||||||||||||||||
683 | } else { never executed: end of block | 0 | ||||||||||||||||||
684 | d->activateControl(d->pressedControl); | - | ||||||||||||||||||
685 | } never executed: end of block | 0 | ||||||||||||||||||
686 | } | - | ||||||||||||||||||
687 | } never executed: end of block | 0 | ||||||||||||||||||
688 | } never executed: end of block | 0 | ||||||||||||||||||
689 | - | |||||||||||||||||||
690 | - | |||||||||||||||||||
691 | int QScrollBarPrivate::pixelPosToRangeValue(int pos) const | - | ||||||||||||||||||
692 | { | - | ||||||||||||||||||
693 | Q_Q(const QScrollBar); | - | ||||||||||||||||||
694 | QStyleOptionSlider opt; | - | ||||||||||||||||||
695 | q->initStyleOption(&opt); | - | ||||||||||||||||||
696 | QRect gr = q->style()->subControlRect(QStyle::CC_ScrollBar, &opt, | - | ||||||||||||||||||
697 | QStyle::SC_ScrollBarGroove, q); | - | ||||||||||||||||||
698 | QRect sr = q->style()->subControlRect(QStyle::CC_ScrollBar, &opt, | - | ||||||||||||||||||
699 | QStyle::SC_ScrollBarSlider, q); | - | ||||||||||||||||||
700 | int sliderMin, sliderMax, sliderLength; | - | ||||||||||||||||||
701 | - | |||||||||||||||||||
702 | if (orientation == Qt::Horizontal) {
| 0 | ||||||||||||||||||
703 | sliderLength = sr.width(); | - | ||||||||||||||||||
704 | sliderMin = gr.x(); | - | ||||||||||||||||||
705 | sliderMax = gr.right() - sliderLength + 1; | - | ||||||||||||||||||
706 | if (q->layoutDirection() == Qt::RightToLeft)
| 0 | ||||||||||||||||||
707 | opt.upsideDown = !opt.upsideDown; never executed: opt.upsideDown = !opt.upsideDown; | 0 | ||||||||||||||||||
708 | } else { never executed: end of block | 0 | ||||||||||||||||||
709 | sliderLength = sr.height(); | - | ||||||||||||||||||
710 | sliderMin = gr.y(); | - | ||||||||||||||||||
711 | sliderMax = gr.bottom() - sliderLength + 1; | - | ||||||||||||||||||
712 | } never executed: end of block | 0 | ||||||||||||||||||
713 | - | |||||||||||||||||||
714 | return QStyle::sliderValueFromPosition(minimum, maximum, pos - sliderMin, never executed: return QStyle::sliderValueFromPosition(minimum, maximum, pos - sliderMin, sliderMax - sliderMin, opt.upsideDown); | 0 | ||||||||||||||||||
715 | sliderMax - sliderMin, opt.upsideDown); never executed: return QStyle::sliderValueFromPosition(minimum, maximum, pos - sliderMin, sliderMax - sliderMin, opt.upsideDown); | 0 | ||||||||||||||||||
716 | } | - | ||||||||||||||||||
717 | - | |||||||||||||||||||
718 | /*! \reimp | - | ||||||||||||||||||
719 | */ | - | ||||||||||||||||||
720 | void QScrollBar::hideEvent(QHideEvent *) | - | ||||||||||||||||||
721 | { | - | ||||||||||||||||||
722 | Q_D(QScrollBar); | - | ||||||||||||||||||
723 | if (d->pressedControl) {
| 0 | ||||||||||||||||||
724 | d->pressedControl = QStyle::SC_None; | - | ||||||||||||||||||
725 | setRepeatAction(SliderNoAction); | - | ||||||||||||||||||
726 | } never executed: end of block | 0 | ||||||||||||||||||
727 | } never executed: end of block | 0 | ||||||||||||||||||
728 | - | |||||||||||||||||||
729 | /*! \internal | - | ||||||||||||||||||
730 | Returns the style option for scroll bar. | - | ||||||||||||||||||
731 | */ | - | ||||||||||||||||||
732 | Q_WIDGETS_EXPORT QStyleOptionSlider qt_qscrollbarStyleOption(QScrollBar *scrollbar) | - | ||||||||||||||||||
733 | { | - | ||||||||||||||||||
734 | QStyleOptionSlider opt; | - | ||||||||||||||||||
735 | scrollbar->initStyleOption(&opt); | - | ||||||||||||||||||
736 | return opt; never executed: return opt; | 0 | ||||||||||||||||||
737 | } | - | ||||||||||||||||||
738 | - | |||||||||||||||||||
739 | QT_END_NAMESPACE | - | ||||||||||||||||||
740 | - | |||||||||||||||||||
741 | #include "moc_qscrollbar.cpp" | - | ||||||||||||||||||
742 | - | |||||||||||||||||||
743 | #endif // QT_NO_SCROLLBAR | - | ||||||||||||||||||
Source code | Switch to Preprocessed file |