widgets/qslider.cpp

Switch to Source codePreprocessed file
LineSource CodeCoverage
1 -
2 -
3 -
4 -
5 -
6 -
7class QSliderPrivate : public QAbstractSliderPrivate -
8{ -
9 inline QSlider* q_func() { return static_cast<QSlider *>(q_ptr); } inline const QSlider* q_func() const { return static_cast<const QSlider *>(q_ptr); } friend class QSlider; -
10public: -
11 QStyle::SubControl pressedControl; -
12 int tickInterval; -
13 QSlider::TickPosition tickPosition; -
14 int clickOffset; -
15 void init(); -
16 void resetLayoutItemMargins(); -
17 int pixelPosToRangeValue(int pos) const; -
18 inline int pick(const QPoint &pt) const; -
19 -
20 QStyle::SubControl newHoverControl(const QPoint &pos); -
21 bool updateHoverControl(const QPoint &pos); -
22 QStyle::SubControl hoverControl; -
23 QRect hoverRect; -
24}; -
25 -
26void QSliderPrivate::init() -
27{ -
28 QSlider * const q = q_func(); -
29 pressedControl = QStyle::SC_None; -
30 tickInterval = 0; -
31 tickPosition = QSlider::NoTicks; -
32 hoverControl = QStyle::SC_None; -
33 q->setFocusPolicy(Qt::FocusPolicy(q->style()->styleHint(QStyle::SH_Button_FocusPolicy))); -
34 QSizePolicy sp(QSizePolicy::Expanding, QSizePolicy::Fixed, QSizePolicy::Slider); -
35 if (orientation == Qt::Vertical)
partially evaluated: orientation == Qt::Vertical
TRUEFALSE
yes
Evaluation Count:12
no
Evaluation Count:0
0-12
36 sp.transpose();
executed: sp.transpose();
Execution Count:12
12
37 q->setSizePolicy(sp); -
38 q->setAttribute(Qt::WA_WState_OwnSizePolicy, false); -
39 resetLayoutItemMargins(); -
40}
executed: }
Execution Count:12
12
41 -
42void QSliderPrivate::resetLayoutItemMargins() -
43{ -
44 QSlider * const q = q_func(); -
45 QStyleOptionSlider opt; -
46 q->initStyleOption(&opt); -
47 setLayoutItemMargins(QStyle::SE_SliderLayoutItem, &opt); -
48}
executed: }
Execution Count:16
16
49 -
50int QSliderPrivate::pixelPosToRangeValue(int pos) const -
51{ -
52 const QSlider * const q = q_func(); -
53 QStyleOptionSlider opt; -
54 q->initStyleOption(&opt); -
55 QRect gr = q->style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderGroove, q); -
56 QRect sr = q->style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderHandle, q); -
57 int sliderMin, sliderMax, sliderLength; -
58 -
59 if (orientation == Qt::Horizontal) {
partially evaluated: orientation == Qt::Horizontal
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1
0-1
60 sliderLength = sr.width(); -
61 sliderMin = gr.x(); -
62 sliderMax = gr.right() - sliderLength + 1; -
63 } else {
never executed: }
0
64 sliderLength = sr.height(); -
65 sliderMin = gr.y(); -
66 sliderMax = gr.bottom() - sliderLength + 1; -
67 }
executed: }
Execution Count:1
1
68 return QStyle::sliderValueFromPosition(minimum, maximum, pos - sliderMin, 1
69 sliderMax - sliderMin, opt.upsideDown);
executed: return QStyle::sliderValueFromPosition(minimum, maximum, pos - sliderMin, sliderMax - sliderMin, opt.upsideDown);
Execution Count:1
1
70} -
71 -
72inline int QSliderPrivate::pick(const QPoint &pt) const -
73{ -
74 return orientation == Qt::Horizontal ? pt.x() : pt.y();
executed: return orientation == Qt::Horizontal ? pt.x() : pt.y();
Execution Count:2
2
75} -
76void QSlider::initStyleOption(QStyleOptionSlider *option) const -
77{ -
78 if (!option)
partially evaluated: !option
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:31
0-31
79 return;
never executed: return;
0
80 -
81 const QSliderPrivate * const d = d_func(); -
82 option->initFrom(this); -
83 option->subControls = QStyle::SC_None; -
84 option->activeSubControls = QStyle::SC_None; -
85 option->orientation = d->orientation; -
86 option->maximum = d->maximum; -
87 option->minimum = d->minimum; -
88 option->tickPosition = (QSlider::TickPosition)d->tickPosition; -
89 option->tickInterval = d->tickInterval; -
90 option->upsideDown = (d->orientation == Qt::Horizontal) ?
partially evaluated: (d->orientation == Qt::Horizontal)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:31
0-31
91 (d->invertedAppearance != (option->direction == Qt::RightToLeft)) -
92 : (!d->invertedAppearance); -
93 option->direction = Qt::LeftToRight; -
94 option->sliderPosition = d->position; -
95 option->sliderValue = d->value; -
96 option->singleStep = d->singleStep; -
97 option->pageStep = d->pageStep; -
98 if (d->orientation == Qt::Horizontal)
partially evaluated: d->orientation == Qt::Horizontal
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:31
0-31
99 option->state |= QStyle::State_Horizontal;
never executed: option->state |= QStyle::State_Horizontal;
0
100}
executed: }
Execution Count:31
31
101 -
102bool QSliderPrivate::updateHoverControl(const QPoint &pos) -
103{ -
104 QSlider * const q = q_func(); -
105 QRect lastHoverRect = hoverRect; -
106 QStyle::SubControl lastHoverControl = hoverControl; -
107 bool doesHover = q->testAttribute(Qt::WA_Hover); -
108 if (lastHoverControl != newHoverControl(pos) && doesHover) {
never evaluated: lastHoverControl != newHoverControl(pos)
never evaluated: doesHover
0
109 q->update(lastHoverRect); -
110 q->update(hoverRect); -
111 return true;
never executed: return true;
0
112 } -
113 return !doesHover;
never executed: return !doesHover;
0
114} -
115 -
116QStyle::SubControl QSliderPrivate::newHoverControl(const QPoint &pos) -
117{ -
118 QSlider * const q = q_func(); -
119 QStyleOptionSlider opt; -
120 q->initStyleOption(&opt); -
121 opt.subControls = QStyle::SC_All; -
122 QRect handleRect = q->style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderHandle, q); -
123 QRect grooveRect = q->style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderGroove, q); -
124 QRect tickmarksRect = q->style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderTickmarks, q); -
125 -
126 if (handleRect.contains(pos)) {
never evaluated: handleRect.contains(pos)
0
127 hoverRect = handleRect; -
128 hoverControl = QStyle::SC_SliderHandle; -
129 } else if (grooveRect.contains(pos)) {
never executed: }
never evaluated: grooveRect.contains(pos)
0
130 hoverRect = grooveRect; -
131 hoverControl = QStyle::SC_SliderGroove; -
132 } else if (tickmarksRect.contains(pos)) {
never executed: }
never evaluated: tickmarksRect.contains(pos)
0
133 hoverRect = tickmarksRect; -
134 hoverControl = QStyle::SC_SliderTickmarks; -
135 } else {
never executed: }
0
136 hoverRect = QRect(); -
137 hoverControl = QStyle::SC_None; -
138 }
never executed: }
0
139 -
140 return hoverControl;
never executed: return hoverControl;
0
141} -
142QSlider::QSlider(QWidget *parent) -
143 : QAbstractSlider(*new QSliderPrivate, parent) -
144{ -
145 d_func()->orientation = Qt::Vertical; -
146 d_func()->init(); -
147}
executed: }
Execution Count:12
12
148 -
149 -
150 -
151 -
152 -
153 -
154 -
155QSlider::QSlider(Qt::Orientation orientation, QWidget *parent) -
156 : QAbstractSlider(*new QSliderPrivate, parent) -
157{ -
158 d_func()->orientation = orientation; -
159 d_func()->init(); -
160}
never executed: }
0
161 -
162 -
163 -
164 -
165 -
166QSlider::~QSlider() -
167{ -
168} -
169 -
170 -
171 -
172 -
173void QSlider::paintEvent(QPaintEvent *) -
174{ -
175 QSliderPrivate * const d = d_func(); -
176 QPainter p(this); -
177 QStyleOptionSlider opt; -
178 initStyleOption(&opt); -
179 -
180 opt.subControls = QStyle::SC_SliderGroove | QStyle::SC_SliderHandle; -
181 if (d->tickPosition != NoTicks)
partially evaluated: d->tickPosition != NoTicks
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1
0-1
182 opt.subControls |= QStyle::SC_SliderTickmarks;
never executed: opt.subControls |= QStyle::SC_SliderTickmarks;
0
183 if (d->pressedControl) {
partially evaluated: d->pressedControl
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1
0-1
184 opt.activeSubControls = d->pressedControl; -
185 opt.state |= QStyle::State_Sunken; -
186 } else {
never executed: }
0
187 opt.activeSubControls = d->hoverControl; -
188 }
executed: }
Execution Count:1
1
189 -
190 style()->drawComplexControl(QStyle::CC_Slider, &opt, &p, this); -
191}
executed: }
Execution Count:1
1
192 -
193 -
194 -
195 -
196 -
197bool QSlider::event(QEvent *event) -
198{ -
199 QSliderPrivate * const d = d_func(); -
200 -
201 switch(event->type()) { -
202 case QEvent::HoverEnter: -
203 case QEvent::HoverLeave: -
204 case QEvent::HoverMove: -
205 if (const QHoverEvent *he = static_cast<const QHoverEvent *>(event))
never evaluated: const QHoverEvent *he = static_cast<const QHoverEvent *>(event)
0
206 d->updateHoverControl(he->pos());
never executed: d->updateHoverControl(he->pos());
0
207 break;
never executed: break;
0
208 case QEvent::StyleChange: -
209 case QEvent::MacSizeChange: -
210 d->resetLayoutItemMargins(); -
211 break;
never executed: break;
0
212 default: -
213 break;
executed: break;
Execution Count:33
33
214 } -
215 return QAbstractSlider::event(event);
executed: return QAbstractSlider::event(event);
Execution Count:33
33
216} -
217 -
218 -
219 -
220 -
221void QSlider::mousePressEvent(QMouseEvent *ev) -
222{ -
223 QSliderPrivate * const d = d_func(); -
224 if (d->maximum == d->minimum || (ev->buttons() ^ ev->button())) {
partially evaluated: d->maximum == d->minimum
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2
partially evaluated: (ev->buttons() ^ ev->button())
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2
0-2
225 ev->ignore(); -
226 return;
never executed: return;
0
227 } -
228 -
229 -
230 -
231 -
232 ev->accept(); -
233 if ((ev->button() & style()->styleHint(QStyle::SH_Slider_AbsoluteSetButtons)) == ev->button()) {
partially evaluated: (ev->button() & style()->styleHint(QStyle::SH_Slider_AbsoluteSetButtons)) == ev->button()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2
0-2
234 QStyleOptionSlider opt; -
235 initStyleOption(&opt); -
236 const QRect sliderRect = style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderHandle, this); -
237 const QPoint center = sliderRect.center() - sliderRect.topLeft(); -
238 -
239 -
240 setSliderPosition(d->pixelPosToRangeValue(d->pick(ev->pos() - center))); -
241 triggerAction(SliderMove); -
242 setRepeatAction(SliderNoAction); -
243 d->pressedControl = QStyle::SC_SliderHandle; -
244 update(); -
245 } else if ((ev->button() & style()->styleHint(QStyle::SH_Slider_PageSetButtons)) == ev->button()) {
never executed: }
partially evaluated: (ev->button() & style()->styleHint(QStyle::SH_Slider_PageSetButtons)) == ev->button()
TRUEFALSE
yes
Evaluation Count:2
no
Evaluation Count:0
0-2
246 QStyleOptionSlider opt; -
247 initStyleOption(&opt); -
248 d->pressedControl = style()->hitTestComplexControl(QStyle::CC_Slider, -
249 &opt, ev->pos(), this); -
250 SliderAction action = SliderNoAction; -
251 if (d->pressedControl == QStyle::SC_SliderGroove) {
evaluated: d->pressedControl == QStyle::SC_SliderGroove
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:1
1
252 const QRect sliderRect = style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderHandle, this); -
253 int pressValue = d->pixelPosToRangeValue(d->pick(ev->pos() - sliderRect.center() + sliderRect.topLeft())); -
254 d->pressValue = pressValue; -
255 if (pressValue > d->value)
partially evaluated: pressValue > d->value
TRUEFALSE
yes
Evaluation Count:1
no
Evaluation Count:0
0-1
256 action = SliderPageStepAdd;
executed: action = SliderPageStepAdd;
Execution Count:1
1
257 else if (pressValue < d->value)
never evaluated: pressValue < d->value
0
258 action = SliderPageStepSub;
never executed: action = SliderPageStepSub;
0
259 if (action) {
partially evaluated: action
TRUEFALSE
yes
Evaluation Count:1
no
Evaluation Count:0
0-1
260 triggerAction(action); -
261 setRepeatAction(action); -
262 }
executed: }
Execution Count:1
1
263 }
executed: }
Execution Count:1
1
264 } else {
executed: }
Execution Count:2
2
265 ev->ignore(); -
266 return;
never executed: return;
0
267 } -
268 -
269 if (d->pressedControl == QStyle::SC_SliderHandle) {
evaluated: d->pressedControl == QStyle::SC_SliderHandle
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:1
1
270 QStyleOptionSlider opt; -
271 initStyleOption(&opt); -
272 setRepeatAction(SliderNoAction); -
273 QRect sr = style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderHandle, this); -
274 d->clickOffset = d->pick(ev->pos() - sr.topLeft()); -
275 update(sr); -
276 setSliderDown(true); -
277 }
executed: }
Execution Count:1
1
278}
executed: }
Execution Count:2
2
279 -
280 -
281 -
282 -
283void QSlider::mouseMoveEvent(QMouseEvent *ev) -
284{ -
285 QSliderPrivate * const d = d_func(); -
286 if (d->pressedControl != QStyle::SC_SliderHandle) {
never evaluated: d->pressedControl != QStyle::SC_SliderHandle
0
287 ev->ignore(); -
288 return;
never executed: return;
0
289 } -
290 ev->accept(); -
291 int newPosition = d->pixelPosToRangeValue(d->pick(ev->pos()) - d->clickOffset); -
292 QStyleOptionSlider opt; -
293 initStyleOption(&opt); -
294 setSliderPosition(newPosition); -
295}
never executed: }
0
296 -
297 -
298 -
299 -
300 -
301void QSlider::mouseReleaseEvent(QMouseEvent *ev) -
302{ -
303 QSliderPrivate * const d = d_func(); -
304 if (d->pressedControl == QStyle::SC_None || ev->buttons()) {
partially evaluated: d->pressedControl == QStyle::SC_None
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2
partially evaluated: ev->buttons()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2
0-2
305 ev->ignore(); -
306 return;
never executed: return;
0
307 } -
308 ev->accept(); -
309 QStyle::SubControl oldPressed = QStyle::SubControl(d->pressedControl); -
310 d->pressedControl = QStyle::SC_None; -
311 setRepeatAction(SliderNoAction); -
312 if (oldPressed == QStyle::SC_SliderHandle)
evaluated: oldPressed == QStyle::SC_SliderHandle
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:1
1
313 setSliderDown(false);
executed: setSliderDown(false);
Execution Count:1
1
314 QStyleOptionSlider opt; -
315 initStyleOption(&opt); -
316 opt.subControls = oldPressed; -
317 update(style()->subControlRect(QStyle::CC_Slider, &opt, oldPressed, this)); -
318}
executed: }
Execution Count:2
2
319 -
320 -
321 -
322 -
323QSize QSlider::sizeHint() const -
324{ -
325 const QSliderPrivate * const d = d_func(); -
326 ensurePolished(); -
327 const int SliderLength = 84, TickSpace = 5; -
328 QStyleOptionSlider opt; -
329 initStyleOption(&opt); -
330 int thick = style()->pixelMetric(QStyle::PM_SliderThickness, &opt, this); -
331 if (d->tickPosition & TicksAbove)
partially evaluated: d->tickPosition & TicksAbove
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:7
0-7
332 thick += TickSpace;
never executed: thick += TickSpace;
0
333 if (d->tickPosition & TicksBelow)
partially evaluated: d->tickPosition & TicksBelow
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:7
0-7
334 thick += TickSpace;
never executed: thick += TickSpace;
0
335 int w = thick, h = SliderLength; -
336 if (d->orientation == Qt::Horizontal) {
partially evaluated: d->orientation == Qt::Horizontal
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:7
0-7
337 w = SliderLength; -
338 h = thick; -
339 }
never executed: }
0
340 return style()->sizeFromContents(QStyle::CT_Slider, &opt, QSize(w, h), this).expandedTo(QApplication::globalStrut());
executed: return style()->sizeFromContents(QStyle::CT_Slider, &opt, QSize(w, h), this).expandedTo(QApplication::globalStrut());
Execution Count:7
7
341} -
342 -
343 -
344 -
345 -
346QSize QSlider::minimumSizeHint() const -
347{ -
348 const QSliderPrivate * const d = d_func(); -
349 QSize s = sizeHint(); -
350 QStyleOptionSlider opt; -
351 initStyleOption(&opt); -
352 int length = style()->pixelMetric(QStyle::PM_SliderLength, &opt, this); -
353 if (d->orientation == Qt::Horizontal)
partially evaluated: d->orientation == Qt::Horizontal
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1
0-1
354 s.setWidth(length);
never executed: s.setWidth(length);
0
355 else -
356 s.setHeight(length);
executed: s.setHeight(length);
Execution Count:1
1
357 return s;
executed: return s;
Execution Count:1
1
358} -
359void QSlider::setTickPosition(TickPosition position) -
360{ -
361 QSliderPrivate * const d = d_func(); -
362 d->tickPosition = position; -
363 d->resetLayoutItemMargins(); -
364 update(); -
365 updateGeometry(); -
366}
executed: }
Execution Count:4
4
367 -
368QSlider::TickPosition QSlider::tickPosition() const -
369{ -
370 return d_func()->tickPosition;
executed: return d_func()->tickPosition;
Execution Count:4
4
371} -
372void QSlider::setTickInterval(int ts) -
373{ -
374 d_func()->tickInterval = qMax(0, ts); -
375 update(); -
376}
executed: }
Execution Count:3
3
377 -
378int QSlider::tickInterval() const -
379{ -
380 return d_func()->tickInterval;
executed: return d_func()->tickInterval;
Execution Count:3
3
381} -
382 -
383__attribute__((visibility("default"))) QStyleOptionSlider qt_qsliderStyleOption(QSlider *slider) -
384{ -
385 QStyleOptionSlider sliderOption; -
386 slider->initStyleOption(&sliderOption); -
387 return sliderOption;
never executed: return sliderOption;
0
388} -
389 -
390 -
391 -
392 -
393 -
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial