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 test suite of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL-EXCEPT$
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 General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 as published by the Free Software
20** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21** included in the packaging of this file. Please review the following
22** information to ensure the GNU General Public License requirements will
23** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24**
25** $QT_END_LICENSE$
26**
27****************************************************************************/
28
29
30#include <QtTest/QtTest>
31#include <QAbstractSlider>
32#include <QScrollBar>
33#include <QSlider>
34#include <QStyle>
35#include <QStyleOption>
36#include <QElapsedTimer>
37#include <QDebug>
38
39#include <QtTest/private/qtesthelpers_p.h>
40
41using namespace QTestPrivate;
42
43// defined to be 120 by the wheel mouse vendors according to the docs
44#define WHEEL_DELTA 120
45
46class Slider : public QAbstractSlider
47{
48 public:
49 Slider(QWidget *parent)
50 : QAbstractSlider(parent) {}
51 using QAbstractSlider::setRepeatAction;
52 using QAbstractSlider::repeatAction;
53};
54
55class tst_QAbstractSlider: public QObject
56{
57 Q_OBJECT
58public slots:
59 void initTestCase();
60 void cleanupTestCase();
61 void actionTriggered(int action);
62 void rangeChanged(int min, int max);
63 void valueChanged(int value);
64 void sliderMoved(int value);
65
66private slots:
67 void triggerAction_data();
68 void triggerAction();
69 void minimum_maximum_data();
70 void minimum_maximum();
71 void keyPressed_data();
72 void keyPressed();
73#if QT_CONFIG(wheelevent)
74 void wheelEvent_data();
75 void wheelEvent();
76 void fineGrainedWheelEvent_data();
77 void fineGrainedWheelEvent();
78#endif
79 void sliderPressedReleased_data();
80 void sliderPressedReleased();
81 void setOrientation();
82 void sliderMoved_data();
83 void sliderMoved();
84 void rangeChanged_data();
85 void rangeChanged();
86 void setSliderPosition_data();
87 void setSliderPosition();
88 void setValue_data();
89 void setValue();
90 void setRepeatAction();
91 void connectedSliders();
92
93private:
94 void waitUntilTimeElapsed(const QElapsedTimer &t, int ms);
95
96 QWidget *topLevel;
97 Slider *slider;
98 int previousAction;
99 int reportedMinimum;
100 int reportedMaximum;
101 int reportedValue;
102 int reportedSliderPosition;
103 qint64 timeStamp;
104 qint64 actionTriggeredTimeStamp;
105 qint64 valueChangedTimeStamp;
106 qint64 rangeChangedTimeStamp;
107 qint64 sliderMovedTimeStamp;
108};
109
110Q_DECLARE_METATYPE(QList<Qt::Key>)
111
112void tst_QAbstractSlider::initTestCase()
113{
114 topLevel = new QWidget;
115 slider = new Slider(topLevel);
116 slider->setObjectName("testWidget");
117 slider->resize(w: 100,h: 100);
118 slider->show();
119
120 previousAction = QAbstractSlider::SliderNoAction;
121 timeStamp = 0;
122
123 connect(sender: slider,SIGNAL(actionTriggered(int)),receiver: this,SLOT(actionTriggered(int)));
124 connect(sender: slider,SIGNAL(rangeChanged(int,int)),receiver: this,SLOT(rangeChanged(int,int)));
125 connect(sender: slider,SIGNAL(valueChanged(int)),receiver: this,SLOT(valueChanged(int)));
126 connect(sender: slider,SIGNAL(sliderMoved(int)),receiver: this,SLOT(sliderMoved(int)));
127}
128
129void tst_QAbstractSlider::cleanupTestCase()
130{
131 delete topLevel;
132}
133
134void tst_QAbstractSlider::actionTriggered(int action)
135{
136 previousAction = action;
137 actionTriggeredTimeStamp = timeStamp++;
138}
139
140void tst_QAbstractSlider::rangeChanged(int min,int max)
141{
142 reportedMinimum = min;
143 reportedMaximum = max;
144 rangeChangedTimeStamp = timeStamp++;
145}
146
147void tst_QAbstractSlider::valueChanged(int value)
148{
149 reportedValue = value;
150 valueChangedTimeStamp = timeStamp++;
151}
152
153void tst_QAbstractSlider::sliderMoved(int value)
154{
155 reportedSliderPosition = value;
156 sliderMovedTimeStamp = timeStamp++;
157}
158
159void tst_QAbstractSlider::triggerAction_data()
160{
161 QTest::addColumn<int>(name: "sliderAction");
162 QTest::addColumn<int>(name: "maximum");
163 QTest::addColumn<int>(name: "minimum");
164 QTest::addColumn<int>(name: "initialSliderPosition");
165 QTest::addColumn<int>(name: "singleStep");
166 QTest::addColumn<int>(name: "pageStep");
167 QTest::addColumn<int>(name: "expectedSliderPosition");
168
169 QTest::newRow(dataTag: "No action") << int(QAbstractSlider::SliderNoAction) // sliderAction
170 << 1000 // max
171 << 900 // min
172 << 987 // initial position
173 << 237 // single step size
174 << 234 // page step size
175 << 987; // expected position after
176
177 QTest::newRow(dataTag: "Move action") << int(QAbstractSlider::SliderMove) // sliderAction
178 << 1000 // max
179 << 900 // min
180 << 988 // initial position
181 << 237 // single step size
182 << 234 // page step size
183 << 988; // expected position after
184
185 QTest::newRow(dataTag: "Empty step add") << int(QAbstractSlider::SliderSingleStepAdd) // sliderAction
186 << 1000 // max
187 << 900 // min
188 << 988 // initial position
189 << 0 // single step size
190 << 234 // page step size
191 << 988; // expected position after
192
193 QTest::newRow(dataTag: "Empty step sub") << int(QAbstractSlider::SliderSingleStepSub) // sliderAction
194 << 1000 // max
195 << 900 // min
196 << 987 // initial position
197 << 0 // single step size
198 << 234 // page step size
199 << 987; // expected position after
200
201 QTest::newRow(dataTag: "Empty page add") << int(QAbstractSlider::SliderPageStepAdd) // sliderAction
202 << 1000 // max
203 << 900 // min
204 << 988 // initial position
205 << 234 // single step size
206 << 0 // page step size
207 << 988; // expected position after
208
209 QTest::newRow(dataTag: "Empty page sub") << int(QAbstractSlider::SliderPageStepSub) // sliderAction
210 << 1000 // max
211 << 900 // min
212 << 987 // initial position
213 << 234 // single step size
214 << 0 // page step size
215 << 987; // expected position after
216
217 QTest::newRow(dataTag: "Legal step add") << int(QAbstractSlider::SliderSingleStepAdd) // sliderAction
218 << 1000 // max
219 << 900 // min
220 << 988 // initial position
221 << 5 // single step size
222 << 234 // page step size
223 << 993; // expected position after
224
225 QTest::newRow(dataTag: "Legal step sub") << int(QAbstractSlider::SliderSingleStepSub) // sliderAction
226 << 1000 // max
227 << 900 // min
228 << 987 // initial position
229 << 5 // single step size
230 << 234 // page step size
231 << 982; // expected position after
232
233 QTest::newRow(dataTag: "Legal page add") << int(QAbstractSlider::SliderPageStepAdd) // sliderAction
234 << 1000 // max
235 << 900 // min
236 << 988 // initial position
237 << 234 // single step size
238 << 5 // page step size
239 << 993; // expected position after
240
241 QTest::newRow(dataTag: "Legal page sub") << int(QAbstractSlider::SliderPageStepSub) // sliderAction
242 << 1000 // max
243 << 900 // min
244 << 987 // initial position
245 << 234 // single step size
246 << 5 // page step size
247 << 982; // expected position after
248
249 QTest::newRow(dataTag: "Illegal step add") << int(QAbstractSlider::SliderSingleStepAdd) // sliderAction
250 << 1000 // max
251 << 900 // min
252 << 988 // initial position
253 << 500 // single step size
254 << 234 // page step size
255 << 1000; // expected position after
256
257 QTest::newRow(dataTag: "Illegal step sub") << int(QAbstractSlider::SliderSingleStepSub) // sliderAction
258 << 1000 // max
259 << 900 // min
260 << 987 // initial position
261 << 500 // single step size
262 << 234 // page step size
263 << 900; // expected position after
264
265 QTest::newRow(dataTag: "Illegal page add") << int(QAbstractSlider::SliderPageStepAdd) // sliderAction
266 << 1000 // max
267 << 900 // min
268 << 988 // initial position
269 << 234 // single step size
270 << 500 // page step size
271 << 1000; // expected position after
272
273 QTest::newRow(dataTag: "Illegal page sub") << int(QAbstractSlider::SliderPageStepSub) // sliderAction
274 << 1000 // max
275 << 900 // min
276 << 987 // initial position
277 << 234 // single step size
278 << 500 // page step size
279 << 900; // expected position after
280
281 // Negative steps will also be abs()'d so, check that case.
282 QTest::newRow(dataTag: "Negative step add") << int(QAbstractSlider::SliderSingleStepAdd) // sliderAction
283 << 1000 // max
284 << 900 // min
285 << 988 // initial position
286 << -1 // single step size
287 << 234 // page step size
288 << 989; // expected position after
289
290 QTest::newRow(dataTag: "Negative step sub") << int(QAbstractSlider::SliderSingleStepSub) // sliderAction
291 << 1000 // max
292 << 900 // min
293 << 987 // initial position
294 << -1 // single step size
295 << 234 // page step size
296 << 986; // expected position after
297
298 QTest::newRow(dataTag: "Negative page add") << int(QAbstractSlider::SliderPageStepAdd) // sliderAction
299 << 1000 // max
300 << 900 // min
301 << 988 // initial position
302 << 234 // single step size
303 << -1 // page step size
304 << 989; // expected position after
305
306 QTest::newRow(dataTag: "Negative page sub") << int(QAbstractSlider::SliderPageStepSub) // sliderAction
307 << 1000 // max
308 << 900 // min
309 << 987 // initial position
310 << 234 // single step size
311 << -1 // page step size
312 << 986; // expected position after
313
314 QTest::newRow(dataTag: "Illegal negative step add") << int(QAbstractSlider::SliderSingleStepAdd) // sliderAction
315 << 1000 // max
316 << 900 // min
317 << 988 // initial position
318 << -500 // single step size
319 << 234 // page step size
320 << 1000; // expected position after
321
322
323 QTest::newRow(dataTag: "Illegal negative step sub") << int(QAbstractSlider::SliderSingleStepSub) // sliderAction
324 << 1000 // max
325 << 900 // min
326 << 988 // initial position
327 << -500 // single step size
328 << 234 // page step size
329 << 900; // expected position after
330
331 QTest::newRow(dataTag: "Illegal negative page add") << int(QAbstractSlider::SliderPageStepAdd) // sliderAction
332 << 1000 // max
333 << 900 // min
334 << 988 // initial position
335 << 234 // single step size
336 << -500 // page step size
337 << 1000; // expected position after
338
339 QTest::newRow(dataTag: "Illegal negative page sub") << int(QAbstractSlider::SliderPageStepSub) // sliderAction
340 << 1000 // max
341 << 900 // min
342 << 988 // initial position
343 << 245 // single step size
344 << -500 // page step size
345 << 900; // expected position after
346
347 QTest::newRow(dataTag: "Slider to minimum") << int(QAbstractSlider::SliderToMinimum) // sliderAction
348 << 1000 // max
349 << 900 // min
350 << 988 // initial position
351 << 245 // single step size
352 << 1 // page step size
353 << 900; // expected position after
354
355 QTest::newRow(dataTag: "Slider to maximum") << int(QAbstractSlider::SliderToMaximum) // sliderAction
356 << 1000 // max
357 << 900 // min
358 << 988 // initial position
359 << 245 // single step size
360 << 1 // page step size
361 << 1000; // expected position after
362
363}
364
365void tst_QAbstractSlider::triggerAction()
366{
367 QFETCH(int,sliderAction);
368 QFETCH(int,maximum);
369 QFETCH(int,minimum);
370 QFETCH(int,initialSliderPosition);
371 QFETCH(int,singleStep);
372 QFETCH(int,pageStep);
373 QFETCH(int,expectedSliderPosition);
374
375 slider->setTracking(true);
376 slider->setRange(min: minimum,max: maximum);
377 slider->setSingleStep(singleStep);
378 slider->setPageStep(pageStep);
379 QCOMPARE(slider->singleStep(), qAbs(singleStep));
380 QCOMPARE(slider->pageStep(), qAbs(pageStep));
381
382 int oldPosition = slider->sliderPosition();
383 slider->setSliderPosition(initialSliderPosition);
384
385 QVERIFY( (oldPosition == initialSliderPosition && previousAction == int(QAbstractSlider::SliderNoAction)) ||
386 (oldPosition != initialSliderPosition && previousAction == int(QAbstractSlider::SliderMove)));
387 previousAction = int(QAbstractSlider::SliderNoAction);
388
389 QAbstractSlider::SliderAction *action = reinterpret_cast<QAbstractSlider::SliderAction*>(&sliderAction);
390 QVERIFY(action != 0);
391
392 slider->triggerAction(action: *action);
393 QCOMPARE(previousAction,sliderAction); // previousAction set in the actionTriggered() slot
394 QCOMPARE(slider->sliderPosition(),expectedSliderPosition);
395 QCOMPARE(slider->value(),expectedSliderPosition);
396 QCOMPARE(reportedValue,expectedSliderPosition);
397 previousAction = int(QAbstractSlider::SliderNoAction);
398 if (initialSliderPosition != expectedSliderPosition)
399 QVERIFY(actionTriggeredTimeStamp < valueChangedTimeStamp);
400}
401
402void tst_QAbstractSlider::minimum_maximum_data()
403{
404 QTest::addColumn<int>(name: "minimum");
405 QTest::addColumn<int>(name: "maximum");
406 QTest::addColumn<int>(name: "expectedMinimum");
407 QTest::addColumn<int>(name: "expectedMaximum");
408
409 QTest::newRow(dataTag: "Normal range") << 100 << 200 << 100 << 200;
410 QTest::newRow(dataTag: "Minimum higher") << 100 << 0 << 100 << 100;
411 QTest::newRow(dataTag: "Negative minimum") << -100 << 100 << -100 << 100;
412 QTest::newRow(dataTag: "Negative range") << -100 << -50 << -100 << -50;
413}
414
415void tst_QAbstractSlider::minimum_maximum()
416{
417 QFETCH(int, minimum);
418 QFETCH(int, maximum);
419 QFETCH(int, expectedMinimum);
420 QFETCH(int, expectedMaximum);
421
422 slider->setRange(min: minimum,max: maximum);
423 QCOMPARE(slider->minimum(),expectedMinimum);
424 QCOMPARE(slider->maximum(),expectedMaximum);
425 QCOMPARE(reportedMinimum,expectedMinimum);
426 QCOMPARE(reportedMaximum,expectedMaximum);
427
428 slider->setRange(min: minimum,max: maximum);
429 slider->setMaximum(slider->minimum() - 1);
430 QCOMPARE(slider->maximum(),slider->minimum());
431 QCOMPARE(reportedMinimum,slider->minimum());
432 QCOMPARE(reportedMaximum,slider->maximum());
433
434 slider->setRange(min: minimum,max: maximum);
435 slider->setMinimum(slider->maximum() + 1);
436 QCOMPARE(slider->minimum(),slider->maximum());
437 QCOMPARE(reportedMinimum,slider->minimum());
438 QCOMPARE(reportedMaximum,slider->maximum());
439
440 slider->setRange(min: minimum,max: maximum);
441 slider->setSliderPosition(slider->maximum() + 1);
442 QCOMPARE(slider->sliderPosition(), slider->maximum());
443 QCOMPARE(slider->value(), slider->maximum());
444 QCOMPARE(reportedValue, slider->maximum());
445
446 slider->setRange(min: minimum,max: maximum);
447 slider->setSliderPosition(slider->minimum() - 1);
448 QCOMPARE(slider->sliderPosition(), slider->minimum());
449 QCOMPARE(slider->value(), slider->minimum());
450 QCOMPARE(reportedValue, slider->minimum());
451
452 slider->setRange(min: minimum,max: maximum);
453 int oldPosition = slider->sliderPosition();
454 slider->setMaximum(oldPosition - 1);
455 QCOMPARE(slider->sliderPosition(),oldPosition - 1);
456
457 slider->setRange(min: minimum,max: maximum);
458 oldPosition = slider->sliderPosition();
459 slider->setMinimum(oldPosition + 1);
460 QCOMPARE(slider->sliderPosition(), oldPosition + 1);
461}
462
463void tst_QAbstractSlider::keyPressed_data()
464{
465 QTest::addColumn<int>(name: "initialSliderPosition");
466 QTest::addColumn<int>(name: "minimum");
467 QTest::addColumn<int>(name: "maximum");
468 QTest::addColumn<int>(name: "stepSize");
469 QTest::addColumn<int>(name: "pageSize");
470 QTest::addColumn<bool>(name: "invertedAppearance");
471 QTest::addColumn<bool>(name: "invertedControls");
472 QTest::addColumn<QList<Qt::Key> >(name: "keySequence");
473 QTest::addColumn<int>(name: "expectedSliderPosition");
474
475 QList<Qt::Key> list;
476 list << Qt::Key_Down;
477 QTest::newRow(dataTag: "Step down once 1, horizontal")
478 << 10 // initial position
479 << 0 // minimum
480 << 100 // maximum
481 << 3 // single step size
482 << 0 // page step size
483 << false// inverted appearance
484 << false// inverted controls
485 << list // key sequence
486 << 7; // expected position
487
488 QTest::newRow(dataTag: "Step down once 1, horizontal, appearance inverted")
489 << 10 // initial position
490 << 0 // minimum
491 << 100 // maximum
492 << 3 // single step size
493 << 0 // page step size
494 << true // inverted appearance
495 << false// inverted controls
496 << list // key sequence
497 << 7; // expected position
498
499 QTest::newRow(dataTag: "Step down once 1, horizontal, controls inverted")
500 << 10 // initial position
501 << 0 // minimum
502 << 100 // maximum
503 << 3 // single step size
504 << 0 // page step size
505 << false// inverted appearance
506 << true // inverted controls
507 << list // key sequence
508 << 13; // expected position
509
510 QTest::newRow(dataTag: "Step down once 1, horizontal, both inverted")
511 << 10 // initial position
512 << 0 // minimum
513 << 100 // maximum
514 << 3 // single step size
515 << 0 // page step size
516 << true // inverted appearance
517 << true // inverted controls
518 << list // key sequence
519 << 13; // expected position
520
521 QTest::newRow(dataTag: "Step down once 1, vertical")
522 << 10 // initial position
523 << 0 // minimum
524 << 100 // maximum
525 << 3 // single step size
526 << 0 // page step size
527 << false// inverted appearance
528 << false// inverted controls
529 << list // key sequence
530 << 7; // expected position
531
532 QTest::newRow(dataTag: "Step down once 1, vertical, appearance inverted")
533 << 10 // initial position
534 << 0 // minimum
535 << 100 // maximum
536 << 3 // single step size
537 << 0 // page step size
538 << true // inverted appearance
539 << false// inverted controls
540 << list // key sequence
541 << 7; // expected position
542
543 QTest::newRow(dataTag: "Step down once 1, vertical, controls inverted")
544 << 10 // initial position
545 << 0 // minimum
546 << 100 // maximum
547 << 3 // single step size
548 << 0 // page step size
549 << false// inverted appearance
550 << true // inverted controls
551 << list // key sequence
552 << 13; // expected position
553
554 QTest::newRow(dataTag: "Step down once 1, vertical, both inverted")
555 << 10 // initial position
556 << 0 // minimum
557 << 100 // maximum
558 << 3 // single step size
559 << 0 // page step size
560 << true // inverted appearance
561 << true // inverted controls
562 << list // key sequence
563 << 13; // expected position
564
565 list = QList<Qt::Key>();
566 list << Qt::Key_Up;
567 QTest::newRow(dataTag: "Step up once 2, horizontal")
568 << 10 // initial position
569 << 0 // minimum
570 << 100 // maximum
571 << 3 // single step size
572 << 0 // page step size
573 << false// inverted appearance
574 << false// inverted controls
575 << list // key sequence
576 << 13; // expected position
577
578 QTest::newRow(dataTag: "Step up once 2, horizontal, appearance inverted")
579 << 10 // initial position
580 << 0 // minimum
581 << 100 // maximum
582 << 3 // single step size
583 << 0 // page step size
584 << true // inverted appearance
585 << false// inverted controls
586 << list // key sequence
587 << 13; // expected position
588
589 QTest::newRow(dataTag: "Step up once 2, horizontal, controls inverted")
590 << 10 // initial position
591 << 0 // minimum
592 << 100 // maximum
593 << 3 // single step size
594 << 0 // page step size
595 << false// inverted appearance
596 << true // inverted controls
597 << list // key sequence
598 << 7; // expected position
599
600 QTest::newRow(dataTag: "Step up once 2, horizontal, both inverted")
601 << 10 // initial position
602 << 0 // minimum
603 << 100 // maximum
604 << 3 // single step size
605 << 0 // page step size
606 << true // inverted appearance
607 << true // inverted controls
608 << list // key sequence
609 << 7; // expected position
610
611 QTest::newRow(dataTag: "Step up once 2, vertical")
612 << 10 // initial position
613 << 0 // minimum
614 << 100 // maximum
615 << 3 // single step size
616 << 0 // page step size
617 << false// inverted appearance
618 << false// inverted controls
619 << list // key sequence
620 << 13; // expected position
621
622 QTest::newRow(dataTag: "Step up once 2, vertical, appearance inverted")
623 << 10 // initial position
624 << 0 // minimum
625 << 100 // maximum
626 << 3 // single step size
627 << 0 // page step size
628 << true // inverted appearance
629 << false// inverted controls
630 << list // key sequence
631 << 13; // expected position
632
633 QTest::newRow(dataTag: "Step up once 2, vertical, controls inverted")
634 << 10 // initial position
635 << 0 // minimum
636 << 100 // maximum
637 << 3 // single step size
638 << 0 // page step size
639 << false// inverted appearance
640 << true // inverted controls
641 << list // key sequence
642 << 7; // expected position
643
644 QTest::newRow(dataTag: "Step up once 2, vertical, both inverted")
645 << 10 // initial position
646 << 0 // minimum
647 << 100 // maximum
648 << 3 // single step size
649 << 0 // page step size
650 << true // inverted appearance
651 << true // inverted controls
652 << list // key sequence
653 << 7; // expected position
654
655 list = QList<Qt::Key>();
656 list << Qt::Key_Left;
657 QTest::newRow(dataTag: "Step left once 2, horizontal")
658 << 10 // initial position
659 << 0 // minimum
660 << 100 // maximum
661 << 3 // single step size
662 << 0 // page step size
663 << false// inverted appearance
664 << false// inverted controls
665 << list // key sequence
666 << 7; // expected position
667
668 QTest::newRow(dataTag: "Step left once 2, horizontal, appearance inverted")
669 << 10 // initial position
670 << 0 // minimum
671 << 100 // maximum
672 << 3 // single step size
673 << 0 // page step size
674 << true // inverted appearance
675 << false// inverted controls
676 << list // key sequence
677 << 7; // expected position
678
679 QTest::newRow(dataTag: "Step left once 2, horizontal, controls inverted")
680 << 10 // initial position
681 << 0 // minimum
682 << 100 // maximum
683 << 3 // single step size
684 << 0 // page step size
685 << false// inverted appearance
686 << true // inverted controls
687 << list // key sequence
688 << 13; // expected position
689
690 QTest::newRow(dataTag: "Step left once 2, horizontal, both inverted")
691 << 10 // initial position
692 << 0 // minimum
693 << 100 // maximum
694 << 3 // single step size
695 << 0 // page step size
696 << true // inverted appearance
697 << true // inverted controls
698 << list // key sequence
699 << 13; // expected position
700
701 QTest::newRow(dataTag: "Step left once 2, vertical")
702 << 10 // initial position
703 << 0 // minimum
704 << 100 // maximum
705 << 3 // single step size
706 << 0 // page step size
707 << false// inverted appearance
708 << false// inverted controls
709 << list // key sequence
710 << 7; // expected position
711
712 QTest::newRow(dataTag: "Step left once 2, vertical, appearance inverted")
713 << 10 // initial position
714 << 0 // minimum
715 << 100 // maximum
716 << 3 // single step size
717 << 0 // page step size
718 << true // inverted appearance
719 << false// inverted controls
720 << list // key sequence
721 << 7; // expected position
722
723 QTest::newRow(dataTag: "Step left once 2, vertical, controls inverted")
724 << 10 // initial position
725 << 0 // minimum
726 << 100 // maximum
727 << 3 // single step size
728 << 0 // page step size
729 << false// inverted appearance
730 << true // inverted controls
731 << list // key sequence
732 << 13; // expected position
733
734 QTest::newRow(dataTag: "Step left once 2, vertical, both inverted")
735 << 10 // initial position
736 << 0 // minimum
737 << 100 // maximum
738 << 3 // single step size
739 << 0 // page step size
740 << true // inverted appearance
741 << true // inverted controls
742 << list // key sequence
743 << 13; // expected position
744
745 list = QList<Qt::Key>();
746 list << Qt::Key_Right;
747 QTest::newRow(dataTag: "Step right once 2, horizontal")
748 << 10 // initial position
749 << 0 // minimum
750 << 100 // maximum
751 << 3 // single step size
752 << 0 // page step size
753 << false// inverted appearance
754 << false// inverted controls
755 << list // key sequence
756 << 13; // expected position
757
758 QTest::newRow(dataTag: "Step right once 2, horizontal, appearance inverted")
759 << 10 // initial position
760 << 0 // minimum
761 << 100 // maximum
762 << 3 // single step size
763 << 0 // page step size
764 << true // inverted appearance
765 << false// inverted controls
766 << list // key sequence
767 << 13; // expected position
768
769 QTest::newRow(dataTag: "Step right once 2, horizontal, controls inverted")
770 << 10 // initial position
771 << 0 // minimum
772 << 100 // maximum
773 << 3 // single step size
774 << 0 // page step size
775 << false// inverted appearance
776 << true // inverted controls
777 << list // key sequence
778 << 7; // expected position
779
780 QTest::newRow(dataTag: "Step right once 2, horizontal, both inverted")
781 << 10 // initial position
782 << 0 // minimum
783 << 100 // maximum
784 << 3 // single step size
785 << 0 // page step size
786 << true // inverted appearance
787 << true // inverted controls
788 << list // key sequence
789 << 7; // expected position
790
791 QTest::newRow(dataTag: "Step right once 2, vertical")
792 << 10 // initial position
793 << 0 // minimum
794 << 100 // maximum
795 << 3 // single step size
796 << 0 // page step size
797 << false// inverted appearance
798 << false// inverted controls
799 << list // key sequence
800 << 13; // expected position
801
802 QTest::newRow(dataTag: "Step right once 2, vertical, appearance inverted")
803 << 10 // initial position
804 << 0 // minimum
805 << 100 // maximum
806 << 3 // single step size
807 << 0 // page step size
808 << true // inverted appearance
809 << false// inverted controls
810 << list // key sequence
811 << 13; // expected position
812
813 QTest::newRow(dataTag: "Step right once 2, vertical, controls inverted")
814 << 10 // initial position
815 << 0 // minimum
816 << 100 // maximum
817 << 3 // single step size
818 << 0 // page step size
819 << false// inverted appearance
820 << true // inverted controls
821 << list // key sequence
822 << 7; // expected position
823
824 QTest::newRow(dataTag: "Step right once 2, vertical, both inverted")
825 << 10 // initial position
826 << 0 // minimum
827 << 100 // maximum
828 << 3 // single step size
829 << 0 // page step size
830 << true // inverted appearance
831 << true // inverted controls
832 << list // key sequence
833 << 7; // expected position
834
835 list = QList<Qt::Key>();
836 list << Qt::Key_PageDown;
837 QTest::newRow(dataTag: "Page down once, horizontal")
838 << 10 // initial position
839 << 0 // minimum
840 << 100 // maximum
841 << 0 // single step size
842 << 3 // page step size
843 << false// inverted appearance
844 << false// inverted controls
845 << list // key sequence
846 << 7; // expected position
847
848 QTest::newRow(dataTag: "Page down once, horizontal, appearance inverted")
849 << 10 // initial position
850 << 0 // minimum
851 << 100 // maximum
852 << 0 // single step size
853 << 3 // page step size
854 << true // inverted appearance
855 << false// inverted controls
856 << list // key sequence
857 << 7; // expected position
858
859 QTest::newRow(dataTag: "Page down once, horizontal, controls inverted")
860 << 10 // initial position
861 << 0 // minimum
862 << 100 // maximum
863 << 0 // single step size
864 << 3 // page step size
865 << false// inverted appearance
866 << true // inverted controls
867 << list // key sequence
868 << 13; // expected position
869
870 QTest::newRow(dataTag: "Page down once, horizontal, both inverted")
871 << 10 // initial position
872 << 0 // minimum
873 << 100 // maximum
874 << 0 // single step size
875 << 3 // page step size
876 << true // inverted appearance
877 << true // inverted controls
878 << list // key sequence
879 << 13; // expected position
880
881 QTest::newRow(dataTag: "Page down once, vertical")
882 << 10 // initial position
883 << 0 // minimum
884 << 100 // maximum
885 << 0 // single step size
886 << 3 // page step size
887 << false// inverted appearance
888 << false// inverted controls
889 << list // key sequence
890 << 7; // expected position
891
892 QTest::newRow(dataTag: "Page down once, vertical, appearance inverted")
893 << 10 // initial position
894 << 0 // minimum
895 << 100 // maximum
896 << 0 // single step size
897 << 3 // page step size
898 << true // inverted appearance
899 << false// inverted controls
900 << list // key sequence
901 << 7; // expected position
902
903 QTest::newRow(dataTag: "Page down once, vertical, controls inverted")
904 << 10 // initial position
905 << 0 // minimum
906 << 100 // maximum
907 << 0 // single step size
908 << 3 // page step size
909 << false// inverted appearance
910 << true // inverted controls
911 << list // key sequence
912 << 13; // expected position
913
914 QTest::newRow(dataTag: "Page down once, vertical, both inverted")
915 << 10 // initial position
916 << 0 // minimum
917 << 100 // maximum
918 << 0 // single step size
919 << 3 // page step size
920 << true // inverted appearance
921 << true // inverted controls
922 << list // key sequence
923 << 13; // expected position
924
925 list = QList<Qt::Key>();
926 list << Qt::Key_PageUp;
927 QTest::newRow(dataTag: "Page up once, horizontal")
928 << 10 // initial position
929 << 0 // minimum
930 << 100 // maximum
931 << 0 // single step size
932 << 3 // page step size
933 << false// inverted appearance
934 << false// inverted controls
935 << list // key sequence
936 << 13; // expected position
937
938 QTest::newRow(dataTag: "Page up once, horizontal, appearance inverted")
939 << 10 // initial position
940 << 0 // minimum
941 << 100 // maximum
942 << 0 // single step size
943 << 3 // page step size
944 << true // inverted appearance
945 << false// inverted controls
946 << list // key sequence
947 << 13; // expected position
948
949 QTest::newRow(dataTag: "Page up once, horizontal, controls inverted")
950 << 10 // initial position
951 << 0 // minimum
952 << 100 // maximum
953 << 0 // single step size
954 << 3 // page step size
955 << false// inverted appearance
956 << true // inverted controls
957 << list // key sequence
958 << 7; // expected position
959
960 QTest::newRow(dataTag: "Page up once, horizontal, both inverted")
961 << 10 // initial position
962 << 0 // minimum
963 << 100 // maximum
964 << 0 // single step size
965 << 3 // page step size
966 << true // inverted appearance
967 << true // inverted controls
968 << list // key sequence
969 << 7; // expected position
970
971 QTest::newRow(dataTag: "Page up once, vertical")
972 << 10 // initial position
973 << 0 // minimum
974 << 100 // maximum
975 << 0 // single step size
976 << 3 // page step size
977 << false// inverted appearance
978 << false// inverted controls
979 << list // key sequence
980 << 13; // expected position
981
982 QTest::newRow(dataTag: "Page up once, vertical, appearance inverted")
983 << 10 // initial position
984 << 0 // minimum
985 << 100 // maximum
986 << 0 // single step size
987 << 3 // page step size
988 << true // inverted appearance
989 << false// inverted controls
990 << list // key sequence
991 << 13; // expected position
992
993 QTest::newRow(dataTag: "Page up once, vertical, controls inverted")
994 << 10 // initial position
995 << 0 // minimum
996 << 100 // maximum
997 << 0 // single step size
998 << 3 // page step size
999 << false// inverted appearance
1000 << true // inverted controls
1001 << list // key sequence
1002 << 7; // expected position
1003
1004 QTest::newRow(dataTag: "Page up once, vertical, both inverted")
1005 << 10 // initial position
1006 << 0 // minimum
1007 << 100 // maximum
1008 << 0 // single step size
1009 << 3 // page step size
1010 << true // inverted appearance
1011 << true // inverted controls
1012 << list // key sequence
1013 << 7; // expected position
1014
1015 list = QList<Qt::Key>();
1016 list << Qt::Key_Up << Qt::Key_Up << Qt::Key_PageDown << Qt::Key_PageDown << Qt::Key_Left << Qt::Key_Left
1017 << Qt::Key_Right << Qt::Key_Down << Qt::Key_PageUp << Qt::Key_PageUp << Qt::Key_Down << Qt::Key_Right;
1018 QTest::newRow(dataTag: "Symmetric seq, horizontal")
1019 << 50 // initial position
1020 << 0 // minimum
1021 << 100 // maximum
1022 << 3 // single step size
1023 << 3 // page step size
1024 << false// inverted appearance
1025 << false// inverted controls
1026 << list // key sequence
1027 << 50; // expected position
1028
1029 QTest::newRow(dataTag: "Symmetric seq, horizontal, appearance inverted")
1030 << 50 // initial position
1031 << 0 // minimum
1032 << 100 // maximum
1033 << 3 // single step size
1034 << 3 // page step size
1035 << true // inverted appearance
1036 << false// inverted controls
1037 << list // key sequence
1038 << 50; // expected position
1039
1040 QTest::newRow(dataTag: "Symmetric seq, horizontal, controls inverted")
1041 << 50 // initial position
1042 << 0 // minimum
1043 << 100 // maximum
1044 << 3 // single step size
1045 << 3 // page step size
1046 << false// inverted appearance
1047 << true // inverted controls
1048 << list // key sequence
1049 << 50; // expected position
1050
1051 QTest::newRow(dataTag: "Symmetric seq, horizontal, both inverted")
1052 << 50 // initial position
1053 << 0 // minimum
1054 << 100 // maximum
1055 << 3 // single step size
1056 << 3 // page step size
1057 << true // inverted appearance
1058 << true // inverted controls
1059 << list // key sequence
1060 << 50; // expected position
1061
1062 QTest::newRow(dataTag: "Symmetric seq, vertical")
1063 << 50 // initial position
1064 << 0 // minimum
1065 << 100 // maximum
1066 << 3 // single step size
1067 << 3 // page step size
1068 << false// inverted appearance
1069 << false// inverted controls
1070 << list // key sequence
1071 << 50; // expected position
1072
1073 QTest::newRow(dataTag: "Symmetric seq, vertical, appearance inverted")
1074 << 50 // initial position
1075 << 0 // minimum
1076 << 100 // maximum
1077 << 3 // single step size
1078 << 3 // page step size
1079 << true // inverted appearance
1080 << false// inverted controls
1081 << list // key sequence
1082 << 50; // expected position
1083
1084 QTest::newRow(dataTag: "Symmetric seq, vertical, controls inverted")
1085 << 50 // initial position
1086 << 0 // minimum
1087 << 100 // maximum
1088 << 3 // single step size
1089 << 3 // page step size
1090 << false// inverted appearance
1091 << true // inverted controls
1092 << list // key sequence
1093 << 50; // expected position
1094
1095 QTest::newRow(dataTag: "Symmetric seq, vertical, both inverted")
1096 << 50 // initial position
1097 << 0 // minimum
1098 << 100 // maximum
1099 << 3 // single step size
1100 << 3 // page step size
1101 << true // inverted appearance
1102 << true // inverted controls
1103 << list // key sequence
1104 << 50; // expected position
1105
1106 list = QList<Qt::Key>();
1107 list << Qt::Key_Home;
1108 QTest::newRow(dataTag: "Home, horizontal")
1109 << 10 // initial position
1110 << 0 // minimum
1111 << 100 // maximum
1112 << 0 // single step size
1113 << 3 // page step size
1114 << false// inverted appearance
1115 << false// inverted controls
1116 << list // key sequence
1117 << 0; // expected position
1118
1119 QTest::newRow(dataTag: "Home, horizontal, appearance inverted")
1120 << 10 // initial position
1121 << 0 // minimum
1122 << 100 // maximum
1123 << 0 // single step size
1124 << 3 // page step size
1125 << true // inverted appearance
1126 << false// inverted controls
1127 << list // key sequence
1128 << 0; // expected position
1129
1130 QTest::newRow(dataTag: "Home, horizontal, controls inverted")
1131 << 10 // initial position
1132 << 0 // minimum
1133 << 100 // maximum
1134 << 0 // single step size
1135 << 3 // page step size
1136 << false// inverted appearance
1137 << true // inverted controls
1138 << list // key sequence
1139 << 0; // expected position
1140
1141 QTest::newRow(dataTag: "Home, horizontal, both inverted")
1142 << 10 // initial position
1143 << 0 // minimum
1144 << 100 // maximum
1145 << 0 // single step size
1146 << 3 // page step size
1147 << true // inverted appearance
1148 << true // inverted controls
1149 << list // key sequence
1150 << 0; // expected position
1151
1152 QTest::newRow(dataTag: "Home, vertical")
1153 << 10 // initial position
1154 << 0 // minimum
1155 << 100 // maximum
1156 << 0 // single step size
1157 << 3 // page step size
1158 << false// inverted appearance
1159 << false// inverted controls
1160 << list // key sequence
1161 << 0; // expected position
1162
1163 QTest::newRow(dataTag: "Home, vertical, appearance inverted")
1164 << 10 // initial position
1165 << 0 // minimum
1166 << 100 // maximum
1167 << 0 // single step size
1168 << 3 // page step size
1169 << true // inverted appearance
1170 << false// inverted controls
1171 << list // key sequence
1172 << 0; // expected position
1173
1174 QTest::newRow(dataTag: "Home, vertical, controls inverted")
1175 << 10 // initial position
1176 << 0 // minimum
1177 << 100 // maximum
1178 << 0 // single step size
1179 << 3 // page step size
1180 << false// inverted appearance
1181 << true // inverted controls
1182 << list // key sequence
1183 << 0; // expected position
1184
1185 QTest::newRow(dataTag: "Home, vertical, both inverted")
1186 << 10 // initial position
1187 << 0 // minimum
1188 << 100 // maximum
1189 << 0 // single step size
1190 << 3 // page step size
1191 << true // inverted appearance
1192 << true // inverted controls
1193 << list // key sequence
1194 << 0; // expected position
1195
1196 list = QList<Qt::Key>();
1197 list << Qt::Key_End;
1198 QTest::newRow(dataTag: "End, horizontal")
1199 << 10 // initial position
1200 << 0 // minimum
1201 << 100 // maximum
1202 << 0 // single step size
1203 << 3 // page step size
1204 << false// inverted appearance
1205 << false// inverted controls
1206 << list // key sequence
1207 << 100; // expected position
1208
1209 QTest::newRow(dataTag: "End, horizontal, appearance inverted")
1210 << 10 // initial position
1211 << 0 // minimum
1212 << 100 // maximum
1213 << 0 // single step size
1214 << 3 // page step size
1215 << true // inverted appearance
1216 << false// inverted controls
1217 << list // key sequence
1218 << 100; // expected position
1219
1220 QTest::newRow(dataTag: "End, horizontal, controls inverted")
1221 << 10 // initial position
1222 << 0 // minimum
1223 << 100 // maximum
1224 << 0 // single step size
1225 << 3 // page step size
1226 << false// inverted appearance
1227 << true // inverted controls
1228 << list // key sequence
1229 << 100; // expected position
1230
1231 QTest::newRow(dataTag: "End, horizontal, both inverted")
1232 << 10 // initial position
1233 << 0 // minimum
1234 << 100 // maximum
1235 << 0 // single step size
1236 << 3 // page step size
1237 << true // inverted appearance
1238 << true // inverted controls
1239 << list // key sequence
1240 << 100; // expected position
1241
1242 QTest::newRow(dataTag: "End, vertical")
1243 << 10 // initial position
1244 << 0 // minimum
1245 << 100 // maximum
1246 << 0 // single step size
1247 << 3 // page step size
1248 << false// inverted appearance
1249 << false// inverted controls
1250 << list // key sequence
1251 << 100; // expected position
1252
1253 QTest::newRow(dataTag: "End, vertical, appearance inverted")
1254 << 10 // initial position
1255 << 0 // minimum
1256 << 100 // maximum
1257 << 0 // single step size
1258 << 3 // page step size
1259 << true // inverted appearance
1260 << false// inverted controls
1261 << list // key sequence
1262 << 100; // expected position
1263
1264 QTest::newRow(dataTag: "End, vertical, controls inverted")
1265 << 10 // initial position
1266 << 0 // minimum
1267 << 100 // maximum
1268 << 0 // single step size
1269 << 3 // page step size
1270 << false// inverted appearance
1271 << true // inverted controls
1272 << list // key sequence
1273 << 100; // expected position
1274
1275 QTest::newRow(dataTag: "End, vertical, both inverted")
1276 << 10 // initial position
1277 << 0 // minimum
1278 << 100 // maximum
1279 << 0 // single step size
1280 << 3 // page step size
1281 << true // inverted appearance
1282 << true // inverted controls
1283 << list // key sequence
1284 << 100; // expected position
1285
1286 list = QList<Qt::Key>();
1287 list << Qt::Key_End << Qt::Key_Up;
1288 QTest::newRow(dataTag: "Past end, horizontal")
1289 << 10 // initial position
1290 << 0 // minimum
1291 << 100 // maximum
1292 << 3 // single step size
1293 << 3 // page step size
1294 << false// inverted appearance
1295 << false// inverted controls
1296 << list // key sequence
1297 << 100; // expected position
1298
1299 QTest::newRow(dataTag: "Past end, horizontal, appearance inverted")
1300 << 10 // initial position
1301 << 0 // minimum
1302 << 100 // maximum
1303 << 3 // single step size
1304 << 3 // page step size
1305 << true // inverted appearance
1306 << false// inverted controls
1307 << list // key sequence
1308 << 100; // expected position
1309
1310 QTest::newRow(dataTag: "Past end, horizontal, controls inverted")
1311 << 10 // initial position
1312 << 0 // minimum
1313 << 100 // maximum
1314 << 3 // single step size
1315 << 3 // page step size
1316 << false// inverted appearance
1317 << true // inverted controls
1318 << list // key sequence
1319 << 97; // expected position
1320
1321 QTest::newRow(dataTag: "Past end, horizontal, both inverted")
1322 << 10 // initial position
1323 << 0 // minimum
1324 << 100 // maximum
1325 << 3 // single step size
1326 << 3 // page step size
1327 << true // inverted appearance
1328 << true // inverted controls
1329 << list // key sequence
1330 << 97; // expected position
1331
1332 QTest::newRow(dataTag: "Past end, vertical")
1333 << 10 // initial position
1334 << 0 // minimum
1335 << 100 // maximum
1336 << 3 // single step size
1337 << 3 // page step size
1338 << false// inverted appearance
1339 << false// inverted controls
1340 << list // key sequence
1341 << 100; // expected position
1342
1343 QTest::newRow(dataTag: "Past end, vertical, appearance inverted")
1344 << 10 // initial position
1345 << 0 // minimum
1346 << 100 // maximum
1347 << 3 // single step size
1348 << 3 // page step size
1349 << true // inverted appearance
1350 << false// inverted controls
1351 << list // key sequence
1352 << 100; // expected position
1353
1354 QTest::newRow(dataTag: "Past end, vertical, controls inverted")
1355 << 10 // initial position
1356 << 0 // minimum
1357 << 100 // maximum
1358 << 3 // single step size
1359 << 3 // page step size
1360 << false// inverted appearance
1361 << true // inverted controls
1362 << list // key sequence
1363 << 97; // expected position
1364
1365 QTest::newRow(dataTag: "Past end, vertical, both inverted")
1366 << 10 // initial position
1367 << 0 // minimum
1368 << 100 // maximum
1369 << 3 // single step size
1370 << 3 // page step size
1371 << true // inverted appearance
1372 << true // inverted controls
1373 << list // key sequence
1374 << 97; // expected position
1375
1376 list = QList<Qt::Key>();
1377 list << Qt::Key_Home << Qt::Key_Down;
1378 QTest::newRow(dataTag: "Past home, horizontal")
1379 << 10 // initial position
1380 << 0 // minimum
1381 << 100 // maximum
1382 << 3 // single step size
1383 << 3 // page step size
1384 << false// inverted appearance
1385 << false// inverted controls
1386 << list // key sequence
1387 << 0; // expected position
1388
1389 QTest::newRow(dataTag: "Past home, horizontal, appearance inverted")
1390 << 10 // initial position
1391 << 0 // minimum
1392 << 100 // maximum
1393 << 3 // single step size
1394 << 3 // page step size
1395 << true // inverted appearance
1396 << false// inverted controls
1397 << list // key sequence
1398 << 0; // expected position
1399
1400 QTest::newRow(dataTag: "Past home, horizontal, controls inverted")
1401 << 10 // initial position
1402 << 0 // minimum
1403 << 100 // maximum
1404 << 3 // single step size
1405 << 3 // page step size
1406 << false// inverted appearance
1407 << true // inverted controls
1408 << list // key sequence
1409 << 3; // expected position
1410
1411 QTest::newRow(dataTag: "Past home, horizontal, both inverted")
1412 << 10 // initial position
1413 << 0 // minimum
1414 << 100 // maximum
1415 << 3 // single step size
1416 << 3 // page step size
1417 << true // inverted appearance
1418 << true // inverted controls
1419 << list // key sequence
1420 << 3; // expected position
1421
1422 QTest::newRow(dataTag: "Past home, vertical")
1423 << 10 // initial position
1424 << 0 // minimum
1425 << 100 // maximum
1426 << 3 // single step size
1427 << 3 // page step size
1428 << false// inverted appearance
1429 << false// inverted controls
1430 << list // key sequence
1431 << 0; // expected position
1432
1433 QTest::newRow(dataTag: "Past home, vertical, appearance inverted")
1434 << 10 // initial position
1435 << 0 // minimum
1436 << 100 // maximum
1437 << 3 // single step size
1438 << 3 // page step size
1439 << false// inverted appearance
1440 << false// inverted controls
1441 << list // key sequence
1442 << 0; // expected position
1443
1444 QTest::newRow(dataTag: "Past home, vertical, controls inverted")
1445 << 10 // initial position
1446 << 0 // minimum
1447 << 100 // maximum
1448 << 3 // single step size
1449 << 3 // page step size
1450 << false// inverted appearance
1451 << true // inverted controls
1452 << list // key sequence
1453 << 3; // expected position
1454
1455 QTest::newRow(dataTag: "Past home, vertical, both inverted")
1456 << 10 // initial position
1457 << 0 // minimum
1458 << 100 // maximum
1459 << 3 // single step size
1460 << 3 // page step size
1461 << true // inverted appearance
1462 << true // inverted controls
1463 << list // key sequence
1464 << 3; // expected position
1465}
1466
1467void tst_QAbstractSlider::keyPressed()
1468{
1469 QFETCH(int, initialSliderPosition);
1470 QFETCH(int, minimum);
1471 QFETCH(int, maximum);
1472 QFETCH(int, stepSize);
1473 QFETCH(int, pageSize);
1474 QFETCH(bool, invertedAppearance);
1475 QFETCH(bool, invertedControls);
1476 QFETCH(QList<Qt::Key>, keySequence);
1477 QFETCH(int, expectedSliderPosition);
1478
1479 slider->setRange(min: minimum,max: maximum);
1480 slider->setSliderPosition(initialSliderPosition);
1481 slider->setSingleStep(stepSize);
1482 slider->setPageStep(pageSize);
1483 slider->setOrientation(Qt::Horizontal);
1484 slider->setInvertedAppearance(invertedAppearance);
1485 slider->setInvertedControls(invertedControls);
1486 for (int i=0;i<keySequence.count();i++) {
1487 QTest::keyClick(widget: slider, key: keySequence.at(i));
1488 }
1489 QCOMPARE(slider->sliderPosition(), expectedSliderPosition);
1490}
1491
1492#if QT_CONFIG(wheelevent)
1493void tst_QAbstractSlider::wheelEvent_data()
1494{
1495 QTest::addColumn<int>(name: "initialSliderPosition");
1496 QTest::addColumn<int>(name: "minimum");
1497 QTest::addColumn<int>(name: "maximum");
1498 QTest::addColumn<int>(name: "singleStep");
1499 QTest::addColumn<int>(name: "pageStep");
1500 QTest::addColumn<bool>(name: "invertedControls");
1501 QTest::addColumn<int>(name: "wheelScrollLines");
1502 QTest::addColumn<bool>(name: "withModifiers"); // use keyboard modifiers while scrolling? (CTRL and SHIFT)
1503 QTest::addColumn<int>(name: "deltaMultiple"); // multiples of WHEEL_DELTA
1504 QTest::addColumn<Qt::Orientation>(name: "sliderOrientation");
1505 QTest::addColumn<Qt::Orientation>(name: "wheelOrientation");
1506 QTest::addColumn<int>(name: "expectedSliderPosition");
1507 QTest::addColumn<QPoint>(name: "distanceFromBottomRight"); // mpointer's distance from bottom-right corner of widget
1508
1509 QTest::newRow(dataTag: "Normal data step") << 0 // initial position
1510 << 0 // minimum
1511 << 100 // maximum
1512 << 1 // single step
1513 << 100 // page step
1514 << false // inverted controls
1515 << 20 // wheel scroll lines
1516 << false // with modifiers
1517 << 1 // delta
1518 << Qt::Vertical // orientation of slider
1519 << Qt::Vertical // orientation of wheel
1520 << 20 // expected position after
1521 << QPoint(0,0);
1522
1523 QTest::newRow(dataTag: "Normal data page") << 0 // initial position
1524 << 0 // minimum
1525 << 100 // maximum
1526 << 100 // single step
1527 << 1 // page step
1528 << false // inverted controls
1529 << 20 // wheel scroll lines
1530 << false // with modifiers
1531 << 1 // delta
1532 << Qt::Vertical // orientation of slider
1533 << Qt::Vertical // orientation of wheel
1534#ifndef Q_OS_MAC
1535 << 1 // expected position after
1536#else
1537 // We don't restrict scrolling to pageStep on Mac
1538 << 100 // expected position after
1539#endif
1540 << QPoint(1,1);
1541 QTest::newRow(dataTag: "Different orientation") << 0 // initial position
1542 << 0 // minimum
1543 << 100 // maximum
1544 << 100 // single step
1545 << 1 // page step
1546 << false // inverted controls
1547 << 20 // wheel scroll lines
1548 << false // with modifiers
1549 << 1 // delta
1550 << Qt::Horizontal // orientation of slider
1551 << Qt::Vertical // orientation of wheel
1552#ifndef Q_OS_MAC
1553 << 1 // expected position after
1554#else
1555 // We don't restrict scrolling to pageStep on Mac
1556 << 100 // expected position after
1557#endif
1558 << QPoint(1,1);
1559
1560 QTest::newRow(dataTag: "Different orientation2")<< 0 // initial position
1561 << 0 // minimum
1562 << 100 // maximum
1563 << 100 // single step
1564 << 1 // page step
1565 << false // inverted controls
1566 << 20 // wheel scroll lines
1567 << false // with modifiers
1568 << 1 // delta
1569 << Qt::Horizontal // orientation of slider
1570 << Qt::Vertical // orientation of wheel
1571#ifndef Q_OS_MAC
1572 << 1 // expected position after
1573#else
1574 // We don't restrict scrolling to pageStep on Mac
1575 << 100 // expected position after
1576#endif
1577 << QPoint(0,0);
1578
1579 QTest::newRow(dataTag: "Inverted controls") << 50 // initial position
1580 << 0 // minimum
1581 << 100 // maximum
1582 << 1 // single step
1583 << 100 // page step
1584 << true // inverted controls
1585 << 20 // wheel scroll lines
1586 << false // with modifiers
1587 << -1 // delta
1588 << Qt::Horizontal // orientation of slider
1589 << Qt::Horizontal // orientation of wheel
1590 << 30 // expected position after
1591 << QPoint(1,1);
1592
1593 QTest::newRow(dataTag: "Past end") << 50 // initial position
1594 << 0 // minimum
1595 << 100 // maximum
1596 << 26 // single step
1597 << 100 // page step
1598 << false // inverted controls
1599 << 1 // wheel scroll lines
1600 << false // with modifiers
1601 << -2 // delta
1602 << Qt::Horizontal // orientation of slider
1603 << Qt::Horizontal // orientation of wheel
1604 << 100 // expected position after
1605 << QPoint(0,0);
1606
1607 QTest::newRow(dataTag: "Past start") << 50 // initial position
1608 << 0 // minimum
1609 << 100 // maximum
1610 << 26 // single step
1611 << 100 // page step
1612 << false // inverted controls
1613 << 1 // wheel scroll lines
1614 << false // with modifiers
1615 << 2 // delta
1616 << Qt::Horizontal // orientation of slider
1617 << Qt::Horizontal // orientation of wheel
1618 << 0 // expected position after
1619 << QPoint(0,0);
1620
1621 QTest::newRow(dataTag: "With modifiers") << 50 // initial position
1622 << 0 // minimum
1623 << 100 // maximum
1624 << 1 // single step
1625 << 40 // page step
1626 << false // inverted controls
1627 << 20 // wheel scroll lines
1628 << true // with modifiers
1629 << -1 // delta
1630 << Qt::Horizontal // orientation of slider
1631 << Qt::Horizontal // orientation of wheel
1632 << 90 // expected position after
1633 << QPoint(0,0);
1634
1635}
1636
1637void tst_QAbstractSlider::wheelEvent()
1638{
1639 QFETCH(int,initialSliderPosition);
1640 QFETCH(int,minimum);
1641 QFETCH(int,maximum);
1642 QFETCH(int,singleStep);
1643 QFETCH(int,pageStep);
1644 QFETCH(bool,invertedControls);
1645 QFETCH(int,wheelScrollLines);
1646 QFETCH(bool,withModifiers);
1647 QFETCH(int,deltaMultiple);
1648 QFETCH(Qt::Orientation, sliderOrientation);
1649 QFETCH(Qt::Orientation, wheelOrientation);
1650 QFETCH(int,expectedSliderPosition);
1651 QFETCH(QPoint,distanceFromBottomRight);
1652
1653 QCoreApplication *applicationInstance = QCoreApplication::instance();
1654 QVERIFY(applicationInstance != 0);
1655 QApplication::setWheelScrollLines(wheelScrollLines);
1656
1657 slider->setRange(min: minimum,max: maximum);
1658 slider->setSliderPosition(initialSliderPosition);
1659 slider->setSingleStep(singleStep);
1660 slider->setPageStep(pageStep);
1661 slider->setInvertedControls(invertedControls);
1662 slider->setOrientation(sliderOrientation);
1663
1664 Qt::KeyboardModifier k = withModifiers ? Qt::ControlModifier : Qt::NoModifier;
1665
1666 const QPoint wheelPoint = slider->rect().bottomRight() + distanceFromBottomRight;
1667 const QPoint angleDelta(wheelOrientation == Qt::Horizontal ? WHEEL_DELTA * deltaMultiple : 0,
1668 wheelOrientation == Qt::Vertical ? WHEEL_DELTA * deltaMultiple : 0);
1669 QWheelEvent event(wheelPoint, slider->mapToGlobal(wheelPoint), QPoint(), angleDelta,
1670 Qt::NoButton, k, Qt::NoScrollPhase, false);
1671 QVERIFY(applicationInstance->sendEvent(slider,&event));
1672#ifdef Q_OS_MAC
1673 QEXPECT_FAIL("Normal data page", "QTBUG-23679", Continue);
1674 QEXPECT_FAIL("Different orientation", "QTBUG-23679", Continue);
1675 QEXPECT_FAIL("Different orientation2", "QTBUG-23679", Continue);
1676#endif
1677 QCOMPARE(slider->sliderPosition(),expectedSliderPosition);
1678
1679 slider->setSliderPosition(initialSliderPosition);
1680 k = withModifiers ? Qt::ShiftModifier : Qt::NoModifier;
1681 event = QWheelEvent(wheelPoint, slider->mapToGlobal(wheelPoint), QPoint(), angleDelta,
1682 Qt::NoButton, k, Qt::NoScrollPhase, false);
1683 QSignalSpy spy1(slider, SIGNAL(actionTriggered(int)));
1684 QSignalSpy spy2(slider, SIGNAL(valueChanged(int)));
1685 QVERIFY(applicationInstance->sendEvent(slider,&event));
1686#ifdef Q_OS_MAC
1687 QEXPECT_FAIL("Normal data page", "QTBUG-23679", Continue);
1688 QEXPECT_FAIL("Different orientation", "QTBUG-23679", Continue);
1689 QEXPECT_FAIL("Different orientation2", "QTBUG-23679", Continue);
1690#endif
1691 QCOMPARE(slider->sliderPosition(),expectedSliderPosition);
1692 int expectedSignalCount = (initialSliderPosition == expectedSliderPosition) ? 0 : 1;
1693 QCOMPARE(spy1.count(), expectedSignalCount);
1694 QCOMPARE(spy2.count(), expectedSignalCount);
1695 if (expectedSignalCount)
1696 QVERIFY(actionTriggeredTimeStamp < valueChangedTimeStamp);
1697}
1698
1699void tst_QAbstractSlider::fineGrainedWheelEvent_data()
1700{
1701 QTest::addColumn<bool>(name: "invertedControls");
1702 QTest::newRow(dataTag: "invertedControls=false") << false;
1703 QTest::newRow(dataTag: "invertedControls=true") << true;
1704}
1705
1706void tst_QAbstractSlider::fineGrainedWheelEvent()
1707{
1708 QFETCH(bool, invertedControls);
1709
1710 QCoreApplication *applicationInstance = QCoreApplication::instance();
1711 QVERIFY(applicationInstance != 0);
1712 QApplication::setWheelScrollLines(3);
1713
1714 slider->setRange(min: 0, max: 10);
1715 slider->setSingleStep(1);
1716 slider->setPageStep(10);
1717 slider->setInvertedControls(invertedControls);
1718 slider->setOrientation(Qt::Vertical);
1719 slider->setSliderPosition(0);
1720
1721 const int singleStepDelta = invertedControls ? (-WHEEL_DELTA / 3) : (WHEEL_DELTA / 3);
1722 const QPoint wheelPoint = slider->rect().bottomRight();
1723 QWheelEvent eventDown(wheelPoint, slider->mapToGlobal(wheelPoint), QPoint(), QPoint(0, singleStepDelta / 2),
1724 Qt::NoButton, Qt::NoModifier, Qt::NoScrollPhase, false);
1725 QVERIFY(applicationInstance->sendEvent(slider,&eventDown));
1726 QCOMPARE(slider->sliderPosition(), 0);
1727 QVERIFY(applicationInstance->sendEvent(slider,&eventDown));
1728 QCOMPARE(slider->sliderPosition(), 1);
1729
1730 QWheelEvent eventUp(wheelPoint, slider->mapToGlobal(wheelPoint), QPoint(), QPoint(0, -singleStepDelta / 2),
1731 Qt::NoButton, Qt::NoModifier, Qt::NoScrollPhase, false);
1732 QVERIFY(applicationInstance->sendEvent(slider,&eventUp));
1733 QCOMPARE(slider->sliderPosition(), 1);
1734 QVERIFY(applicationInstance->sendEvent(slider,&eventUp));
1735 QCOMPARE(slider->sliderPosition(), 0);
1736 QVERIFY(applicationInstance->sendEvent(slider,&eventUp));
1737 QCOMPARE(slider->sliderPosition(), 0);
1738 QVERIFY(applicationInstance->sendEvent(slider,&eventUp));
1739 QCOMPARE(slider->sliderPosition(), 0);
1740
1741 QVERIFY(applicationInstance->sendEvent(slider,&eventDown));
1742 QCOMPARE(slider->sliderPosition(), 0);
1743 QVERIFY(applicationInstance->sendEvent(slider,&eventDown));
1744 QCOMPARE(slider->sliderPosition(), 1);
1745}
1746
1747#endif // QT_CONFIG(wheelevent)
1748
1749void tst_QAbstractSlider::sliderPressedReleased_data()
1750{
1751 QTest::addColumn<int>(name: "control");
1752 QTest::addColumn<int>(name: "minimum");
1753 QTest::addColumn<int>(name: "maximum");
1754 QTest::addColumn<uint>(name: "subControl");
1755 QTest::addColumn<int>(name: "expectedCount");
1756
1757 QTest::newRow(dataTag: "slider on the handle") << int(QStyle::CC_Slider)
1758 << 0
1759 << 20
1760 << uint(QStyle::SC_SliderHandle)
1761 << 1;
1762
1763 QTest::newRow(dataTag: "slider on the groove") << int(QStyle::CC_Slider)
1764 << 0
1765 << 20
1766 << uint(QStyle::SC_SliderGroove)
1767 << ((qApp->style()->styleHint(stylehint: QStyle::SH_Slider_AbsoluteSetButtons) & Qt::LeftButton) ? 1 : 0);
1768
1769 QTest::newRow(dataTag: "scrollbar on the handle") << int(QStyle::CC_ScrollBar)
1770 << 0
1771 << 20
1772 << uint(QStyle::SC_ScrollBarSlider)
1773 << 1;
1774
1775 QTest::newRow(dataTag: "scrollbar on the groove") << int(QStyle::CC_ScrollBar)
1776 << 0
1777 << 20
1778 << uint(QStyle::SC_ScrollBarGroove)
1779 << 0;
1780}
1781
1782void tst_QAbstractSlider::sliderPressedReleased()
1783{
1784 QFETCH(int, control);
1785 QFETCH(int, minimum);
1786 QFETCH(int, maximum);
1787 QFETCH(uint, subControl);
1788 QFETCH(int, expectedCount);
1789
1790 QWidget topLevel;
1791 setFrameless(&topLevel);
1792 QAbstractSlider *slider;
1793 switch (control) {
1794 default:
1795 qWarning(msg: "Bad input into test, leaving");
1796 return;
1797 break;
1798 case QStyle::CC_Slider:
1799 slider = new QSlider(&topLevel);
1800 slider->setLayoutDirection(Qt::LeftToRight); // Makes "upside down" much easier to compute
1801 break;
1802 case QStyle::CC_ScrollBar:
1803 slider = new QScrollBar(&topLevel);
1804 break;
1805 }
1806
1807
1808 slider->setMinimum(minimum);
1809 slider->setMaximum(maximum);
1810 slider->setValue(0);
1811 slider->setOrientation(Qt::Vertical);
1812 slider->resize(w: slider->sizeHint().width(), h: slider->sizeHint().height() + 100);
1813 QSignalSpy spy1(slider, SIGNAL(sliderPressed()));
1814 QSignalSpy spy2(slider, SIGNAL(sliderReleased()));
1815
1816 // Mac Style requires the control to be active to get the correct values...
1817 topLevel.show();
1818 slider->activateWindow();
1819
1820 QStyleOptionSlider option;
1821 option.init(w: slider);
1822 option.upsideDown = control == QStyle::CC_Slider ? !slider->invertedAppearance()
1823 : slider->invertedAppearance();
1824 option.subControls = QStyle::SC_None;
1825 option.activeSubControls = QStyle::SC_None;
1826 option.orientation = slider->orientation();
1827 option.maximum = maximum;
1828 option.minimum = minimum;
1829 option.sliderPosition = slider->value();
1830 option.sliderValue = slider->value();
1831 option.singleStep = slider->singleStep();
1832 option.pageStep = slider->pageStep();
1833 QRect rect = slider->style()->subControlRect(cc: QStyle::ComplexControl(control), opt: &option,
1834 sc: QStyle::SubControl(subControl), widget: slider);
1835
1836 if (qApp->style()->styleHint(stylehint: QStyle::SH_ScrollBar_LeftClickAbsolutePosition))
1837 QSKIP("The result depends on system setting on mac");
1838
1839 QTest::mousePress(widget: slider, button: Qt::LeftButton, stateKey: {},
1840 pos: QPoint(rect.center().x() + 2, rect.center().y() + 2));
1841 QCOMPARE(spy1.count(), expectedCount);
1842 QTest::mouseRelease(widget: slider, button: Qt::LeftButton, stateKey: {}, pos: rect.center());
1843 QCOMPARE(spy2.count(), expectedCount);
1844
1845 delete slider;
1846}
1847
1848void tst_QAbstractSlider::sliderMoved_data()
1849{
1850 QTest::addColumn<int>(name: "control");
1851 QTest::addColumn<int>(name: "minimum");
1852 QTest::addColumn<int>(name: "maximum");
1853 QTest::addColumn<int>(name: "position");
1854 QTest::addColumn<bool>(name: "sliderDown");
1855 QTest::addColumn<int>(name: "expectedCount");
1856
1857 QTest::newRow(dataTag: "slider pressed") << int(QStyle::CC_Slider)
1858 << 0
1859 << 20
1860 << 10
1861 << true
1862 << 1;
1863
1864 QTest::newRow(dataTag: "slider not pressed") << int(QStyle::CC_Slider)
1865 << 0
1866 << 20
1867 << 10
1868 << false
1869 << 0;
1870
1871 QTest::newRow(dataTag: "scrollbar pressed") << int(QStyle::CC_ScrollBar)
1872 << 0
1873 << 20
1874 << 10
1875 << true
1876 << 1;
1877
1878 QTest::newRow(dataTag: "scrollbar not pressed") << int(QStyle::CC_ScrollBar)
1879 << 0
1880 << 20
1881 << 10
1882 << false
1883 << 0;
1884}
1885
1886void tst_QAbstractSlider::sliderMoved()
1887{
1888 QFETCH(int, control);
1889 QFETCH(int, minimum);
1890 QFETCH(int, maximum);
1891 QFETCH(int, position);
1892 QFETCH(bool, sliderDown);
1893 QFETCH(int, expectedCount);
1894 QAbstractSlider *slider;
1895 switch (control) {
1896 default:
1897 slider = 0;
1898 break;
1899 case QStyle::CC_Slider:
1900 slider = new QSlider;
1901 break;
1902 case QStyle::CC_ScrollBar:
1903 slider = new QScrollBar;
1904 break;
1905 }
1906 QSignalSpy spy(slider, SIGNAL(sliderMoved(int)));
1907
1908 slider->setMinimum(minimum);
1909 slider->setMaximum(maximum);
1910 slider->setSliderDown(sliderDown);
1911 slider->setSliderPosition(position);
1912 QCOMPARE(spy.count(), expectedCount);
1913
1914 delete slider;
1915}
1916
1917void tst_QAbstractSlider::setOrientation()
1918{
1919 QSlider slider(0);
1920
1921 QSizePolicy sp = slider.sizePolicy();
1922 slider.setOrientation(slider.orientation());
1923 QSizePolicy sp2 = slider.sizePolicy();
1924 QCOMPARE(sp, sp2);
1925
1926 slider.setOrientation(Qt::Horizontal);
1927 sp = slider.sizePolicy();
1928 slider.setOrientation(Qt::Vertical);
1929 sp2 = slider.sizePolicy();
1930
1931 QVERIFY(sp != sp2);
1932 sp2.transpose();
1933 QCOMPARE(sp, sp2);
1934}
1935
1936
1937void tst_QAbstractSlider::rangeChanged_data()
1938{
1939 QTest::addColumn<int>(name: "minimum");
1940 QTest::addColumn<int>(name: "maximum");
1941 QTest::addColumn<int>(name: "newMin");
1942 QTest::addColumn<int>(name: "newMax");
1943 QTest::addColumn<int>(name: "expectedCount");
1944
1945 QTest::newRow(dataTag: "no change")
1946 << 0
1947 << 20
1948 << 0
1949 << 20
1950 << 0;
1951
1952 QTest::newRow(dataTag: "min change")
1953 << 0
1954 << 20
1955 << 10
1956 << 20
1957 << 1;
1958 QTest::newRow(dataTag: "max change")
1959 << 0
1960 << 20
1961 << 0
1962 << 30
1963 << 1;
1964
1965 QTest::newRow(dataTag: "both change")
1966 << 0
1967 << 20
1968 << 10
1969 << 30
1970 << 1;
1971}
1972
1973void tst_QAbstractSlider::rangeChanged()
1974{
1975 QFETCH(int, minimum);
1976 QFETCH(int, maximum);
1977 QFETCH(int, newMin);
1978 QFETCH(int, newMax);
1979 QFETCH(int, expectedCount);
1980 QSlider slider;
1981 slider.setRange(min: minimum, max: maximum);
1982 QSignalSpy spy(&slider, SIGNAL(rangeChanged(int,int)));
1983 slider.setRange(min: newMin, max: newMax);
1984 QCOMPARE(spy.count(), expectedCount);
1985}
1986
1987void tst_QAbstractSlider::setSliderPosition_data()
1988{
1989 QTest::addColumn<bool>(name: "tracking");
1990 QTest::addColumn<bool>(name: "down");
1991
1992 QTest::newRow(dataTag: "tracking, slider down")
1993 << true
1994 << true;
1995 QTest::newRow(dataTag: "tracking, slider not down")
1996 << true
1997 << false;
1998 QTest::newRow(dataTag: "no tracking, slider down")
1999 << false
2000 << true;
2001 QTest::newRow(dataTag: "no tracking, slider not down")
2002 << false
2003 << false;
2004}
2005
2006void tst_QAbstractSlider::setSliderPosition()
2007{
2008 QFETCH(bool, tracking);
2009 QFETCH(bool, down);
2010 const int minimum = 0;
2011 const int maximum = 100;
2012 const int initialValue = 50;
2013 const int targetPosition = 75;
2014 slider->setRange(min: minimum, max: maximum);
2015 slider->setTracking(tracking);
2016 slider->setSliderDown(down);
2017 slider->setValue(initialValue);
2018 QCOMPARE(slider->sliderPosition(), initialValue);
2019 QSignalSpy spy1(slider, SIGNAL(sliderMoved(int)));
2020 QSignalSpy spy2(slider, SIGNAL(valueChanged(int)));
2021 slider->setSliderPosition(targetPosition);
2022 QCOMPARE(slider->sliderPosition(), targetPosition);
2023 QCOMPARE(spy1.count(), down ? 1 : 0);
2024 QCOMPARE(spy2.count(), tracking ? 1 : 0);
2025 QCOMPARE(slider->value(), tracking ? targetPosition : initialValue);
2026 if (tracking && down)
2027 QVERIFY(sliderMovedTimeStamp < valueChangedTimeStamp);
2028}
2029
2030void tst_QAbstractSlider::setValue_data()
2031{
2032 QTest::addColumn<bool>(name: "down");
2033
2034 QTest::newRow(dataTag: "slider down")
2035 << true;
2036 QTest::newRow(dataTag: "slider not down")
2037 << false;
2038}
2039
2040void tst_QAbstractSlider::setValue()
2041{
2042 QFETCH(bool, down);
2043 const int minimum = 0;
2044 const int maximum = 100;
2045 slider->setRange(min: minimum, max: maximum);
2046 slider->setSliderDown(down);
2047 slider->setValue(49); // to force a valueChanged() below
2048 QSignalSpy spy1(slider, SIGNAL(sliderMoved(int)));
2049 QSignalSpy spy2(slider, SIGNAL(valueChanged(int)));
2050 QSignalSpy spy3(slider, SIGNAL(actionTriggered(int)));
2051 slider->setValue(50);
2052 QCOMPARE(spy1.count(), down ? 1 : 0);
2053 QCOMPARE(spy2.count(), 1);
2054 QCOMPARE(spy3.count(), 0);
2055 QCOMPARE(slider->value(), reportedValue);
2056 QCOMPARE(slider->sliderPosition(), reportedSliderPosition);
2057 if (down)
2058 QVERIFY(sliderMovedTimeStamp < valueChangedTimeStamp);
2059}
2060
2061void tst_QAbstractSlider::waitUntilTimeElapsed(const QElapsedTimer &t, int ms)
2062{
2063 const int eps = 80;
2064 while (t.elapsed() < ms + eps)
2065 QTest::qWait(ms: qMax(a: int(ms - t.elapsed() + eps), b: 25));
2066}
2067
2068void tst_QAbstractSlider::setRepeatAction()
2069{
2070 slider->setRange(min: 0, max: 1000);
2071 slider->setValue(55);
2072 slider->setPageStep(10);
2073 QSignalSpy spy(slider, SIGNAL(actionTriggered(int)));
2074
2075 // Start repeat action with initial delay of 500 ms, and then repeating
2076 // every 250 ms.
2077 slider->setRepeatAction(action: QAbstractSlider::SliderPageStepAdd, thresholdTime: 500, repeatTime: 250);
2078 QCOMPARE(spy.count(), 0);
2079 QCOMPARE(slider->value(), 55);
2080
2081 QElapsedTimer t;
2082 t.start();
2083 QTest::qWait(ms: 300);
2084 QCOMPARE(spy.count(), 0);
2085 QCOMPARE(slider->value(), 55);
2086
2087 waitUntilTimeElapsed(t, ms: 550);
2088 QTRY_COMPARE(spy.count(), 1);
2089 QCOMPARE(slider->value(), 65);
2090 QCOMPARE(spy.at(0).at(0).toUInt(), (uint)QAbstractSlider::SliderPageStepAdd);
2091
2092 waitUntilTimeElapsed(t, ms: 790);
2093 QTRY_COMPARE(spy.count(), 2);
2094 QCOMPARE(slider->value(), 75);
2095 QCOMPARE(spy.at(1).at(0).toUInt(), (uint)QAbstractSlider::SliderPageStepAdd);
2096
2097 waitUntilTimeElapsed(t, ms: 1790);
2098 QTRY_COMPARE(spy.count(), 6);
2099 QCOMPARE(slider->value(), 115);
2100 QCOMPARE(spy.at(4).at(0).toUInt(), (uint)QAbstractSlider::SliderPageStepAdd);
2101 QCOMPARE(spy.at(5).at(0).toUInt(), (uint)QAbstractSlider::SliderPageStepAdd);
2102
2103 slider->setRepeatAction(action: QAbstractSlider::SliderNoAction);
2104 QCOMPARE(spy.count(), 6);
2105 QCOMPARE(slider->value(), 115);
2106
2107 QTest::qWait(ms: 300);
2108 QCOMPARE(spy.count(), 6);
2109 QCOMPARE(slider->value(), 115);
2110}
2111
2112void tst_QAbstractSlider::connectedSliders()
2113{
2114 Slider *slider2 = new Slider(topLevel);
2115 connect(sender: slider, SIGNAL(rangeChanged(int,int)), receiver: slider2, SLOT(setRange(int,int)));
2116 const int sliderlow = 13;
2117 const int sliderhigh = 1017;
2118 slider->setRange(min: sliderlow, max: sliderhigh);
2119 QCOMPARE(slider2->minimum(), sliderlow);
2120 QCOMPARE(slider2->maximum(), sliderhigh);
2121 delete slider2;
2122}
2123
2124QTEST_MAIN(tst_QAbstractSlider)
2125#include "tst_qabstractslider.moc"
2126

source code of qtbase/tests/auto/widgets/widgets/qabstractslider/tst_qabstractslider.cpp