author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Thu, 22 Apr 2010 16:15:11 +0300 | |
branch | RCL_3 |
changeset 14 | 8c4229025c0b |
parent 7 | 3f74d0d4af4c |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the test suite of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
||
43 |
#include <QtTest/QtTest> |
|
44 |
#include <QAbstractSlider> |
|
45 |
#include <QScrollBar> |
|
46 |
#include <QSlider> |
|
47 |
#include <QStyle> |
|
48 |
#include <QStyleOption> |
|
49 |
#include <QTime> |
|
50 |
#include <QDebug> |
|
51 |
||
52 |
// defined to be 120 by the wheel mouse vendors according to the docs |
|
53 |
#define WHEEL_DELTA 120 |
|
54 |
||
55 |
class Slider : public QAbstractSlider |
|
56 |
{ |
|
57 |
public: |
|
58 |
using QAbstractSlider::setRepeatAction; |
|
59 |
using QAbstractSlider::repeatAction; |
|
60 |
}; |
|
61 |
||
62 |
class tst_QAbstractSlider: public QObject |
|
63 |
{ |
|
64 |
Q_OBJECT |
|
65 |
public slots: |
|
66 |
void initTestCase(); |
|
67 |
void cleanupTestCase(); |
|
68 |
void actionTriggered(int action); |
|
69 |
void rangeChanged(int min, int max); |
|
70 |
void valueChanged(int value); |
|
71 |
void sliderMoved(int value); |
|
72 |
||
73 |
private slots: |
|
74 |
void triggerAction_data(); |
|
75 |
void triggerAction(); |
|
76 |
void minimum_maximum_data(); |
|
77 |
void minimum_maximum(); |
|
78 |
void keyPressed_data(); |
|
79 |
void keyPressed(); |
|
80 |
void wheelEvent_data(); |
|
81 |
void wheelEvent(); |
|
82 |
void sliderPressedReleased_data(); |
|
83 |
void sliderPressedReleased(); |
|
84 |
void setOrientation(); |
|
85 |
void sliderMoved_data(); |
|
86 |
void sliderMoved(); |
|
87 |
void rangeChanged_data(); |
|
88 |
void rangeChanged(); |
|
89 |
void setSliderPosition_data(); |
|
90 |
void setSliderPosition(); |
|
91 |
void setValue_data(); |
|
92 |
void setValue(); |
|
93 |
void setRepeatAction(); |
|
94 |
||
95 |
private: |
|
96 |
void waitUntilTimeElapsed(const QTime& t, int ms); |
|
97 |
||
98 |
Slider *slider; |
|
99 |
int previousAction; |
|
100 |
int reportedMinimum; |
|
101 |
int reportedMaximum; |
|
102 |
int reportedValue; |
|
103 |
int reportedSliderPosition; |
|
104 |
qint64 timeStamp; |
|
105 |
qint64 actionTriggeredTimeStamp; |
|
106 |
qint64 valueChangedTimeStamp; |
|
107 |
qint64 rangeChangedTimeStamp; |
|
108 |
qint64 sliderMovedTimeStamp; |
|
109 |
}; |
|
110 |
||
111 |
Q_DECLARE_METATYPE(QList<Qt::Key>) |
|
112 |
Q_DECLARE_METATYPE(QPoint) |
|
113 |
||
114 |
void tst_QAbstractSlider::initTestCase() |
|
115 |
{ |
|
116 |
slider = new Slider; |
|
117 |
slider->setObjectName("testWidget"); |
|
118 |
slider->resize(100,100); |
|
119 |
slider->show(); |
|
120 |
||
121 |
previousAction = QAbstractSlider::SliderNoAction; |
|
122 |
timeStamp = 0; |
|
123 |
||
124 |
connect(slider,SIGNAL(actionTriggered(int)),this,SLOT(actionTriggered(int))); |
|
125 |
connect(slider,SIGNAL(rangeChanged(int,int)),this,SLOT(rangeChanged(int,int))); |
|
126 |
connect(slider,SIGNAL(valueChanged(int)),this,SLOT(valueChanged(int))); |
|
127 |
connect(slider,SIGNAL(sliderMoved(int)),this,SLOT(sliderMoved(int))); |
|
128 |
} |
|
129 |
||
130 |
void tst_QAbstractSlider::cleanupTestCase() |
|
131 |
{ |
|
132 |
delete slider; |
|
133 |
} |
|
134 |
||
135 |
void tst_QAbstractSlider::actionTriggered(int action) |
|
136 |
{ |
|
137 |
previousAction = action; |
|
138 |
actionTriggeredTimeStamp = timeStamp++; |
|
139 |
} |
|
140 |
||
141 |
void tst_QAbstractSlider::rangeChanged(int min,int max) |
|
142 |
{ |
|
143 |
reportedMinimum = min; |
|
144 |
reportedMaximum = max; |
|
145 |
rangeChangedTimeStamp = timeStamp++; |
|
146 |
} |
|
147 |
||
148 |
void tst_QAbstractSlider::valueChanged(int value) |
|
149 |
{ |
|
150 |
reportedValue = value; |
|
151 |
valueChangedTimeStamp = timeStamp++; |
|
152 |
} |
|
153 |
||
154 |
void tst_QAbstractSlider::sliderMoved(int value) |
|
155 |
{ |
|
156 |
reportedSliderPosition = value; |
|
157 |
sliderMovedTimeStamp = timeStamp++; |
|
158 |
} |
|
159 |
||
160 |
void tst_QAbstractSlider::triggerAction_data() |
|
161 |
{ |
|
162 |
QTest::addColumn<int>("sliderAction"); |
|
163 |
QTest::addColumn<int>("maximum"); |
|
164 |
QTest::addColumn<int>("minimum"); |
|
165 |
QTest::addColumn<int>("initialSliderPosition"); |
|
166 |
QTest::addColumn<int>("singleStep"); |
|
167 |
QTest::addColumn<int>("pageStep"); |
|
168 |
QTest::addColumn<int>("expectedSliderPosition"); |
|
169 |
||
170 |
QTest::newRow("No action") << int(QAbstractSlider::SliderNoAction) // sliderAction |
|
171 |
<< 1000 // max |
|
172 |
<< 900 // min |
|
173 |
<< 987 // initial position |
|
174 |
<< 237 // single step size |
|
175 |
<< 234 // page step size |
|
176 |
<< 987; // expected position after |
|
177 |
||
178 |
QTest::newRow("Move action") << int(QAbstractSlider::SliderMove) // sliderAction |
|
179 |
<< 1000 // max |
|
180 |
<< 900 // min |
|
181 |
<< 988 // initial position |
|
182 |
<< 237 // single step size |
|
183 |
<< 234 // page step size |
|
184 |
<< 988; // expected position after |
|
185 |
||
186 |
QTest::newRow("Empty step add") << int(QAbstractSlider::SliderSingleStepAdd) // sliderAction |
|
187 |
<< 1000 // max |
|
188 |
<< 900 // min |
|
189 |
<< 988 // initial position |
|
190 |
<< 0 // single step size |
|
191 |
<< 234 // page step size |
|
192 |
<< 988; // expected position after |
|
193 |
||
194 |
QTest::newRow("Empty step sub") << int(QAbstractSlider::SliderSingleStepSub) // sliderAction |
|
195 |
<< 1000 // max |
|
196 |
<< 900 // min |
|
197 |
<< 987 // initial position |
|
198 |
<< 0 // single step size |
|
199 |
<< 234 // page step size |
|
200 |
<< 987; // expected position after |
|
201 |
||
202 |
QTest::newRow("Empty page add") << int(QAbstractSlider::SliderPageStepAdd) // sliderAction |
|
203 |
<< 1000 // max |
|
204 |
<< 900 // min |
|
205 |
<< 988 // initial position |
|
206 |
<< 234 // single step size |
|
207 |
<< 0 // page step size |
|
208 |
<< 988; // expected position after |
|
209 |
||
210 |
QTest::newRow("Empty page sub") << int(QAbstractSlider::SliderPageStepSub) // sliderAction |
|
211 |
<< 1000 // max |
|
212 |
<< 900 // min |
|
213 |
<< 987 // initial position |
|
214 |
<< 234 // single step size |
|
215 |
<< 0 // page step size |
|
216 |
<< 987; // expected position after |
|
217 |
||
218 |
QTest::newRow("Legal step add") << int(QAbstractSlider::SliderSingleStepAdd) // sliderAction |
|
219 |
<< 1000 // max |
|
220 |
<< 900 // min |
|
221 |
<< 988 // initial position |
|
222 |
<< 5 // single step size |
|
223 |
<< 234 // page step size |
|
224 |
<< 993; // expected position after |
|
225 |
||
226 |
QTest::newRow("Legal step sub") << int(QAbstractSlider::SliderSingleStepSub) // sliderAction |
|
227 |
<< 1000 // max |
|
228 |
<< 900 // min |
|
229 |
<< 987 // initial position |
|
230 |
<< 5 // single step size |
|
231 |
<< 234 // page step size |
|
232 |
<< 982; // expected position after |
|
233 |
||
234 |
QTest::newRow("Legal page add") << int(QAbstractSlider::SliderPageStepAdd) // sliderAction |
|
235 |
<< 1000 // max |
|
236 |
<< 900 // min |
|
237 |
<< 988 // initial position |
|
238 |
<< 234 // single step size |
|
239 |
<< 5 // page step size |
|
240 |
<< 993; // expected position after |
|
241 |
||
242 |
QTest::newRow("Legal page sub") << int(QAbstractSlider::SliderPageStepSub) // sliderAction |
|
243 |
<< 1000 // max |
|
244 |
<< 900 // min |
|
245 |
<< 987 // initial position |
|
246 |
<< 234 // single step size |
|
247 |
<< 5 // page step size |
|
248 |
<< 982; // expected position after |
|
249 |
||
250 |
QTest::newRow("Illegal step add") << int(QAbstractSlider::SliderSingleStepAdd) // sliderAction |
|
251 |
<< 1000 // max |
|
252 |
<< 900 // min |
|
253 |
<< 988 // initial position |
|
254 |
<< 500 // single step size |
|
255 |
<< 234 // page step size |
|
256 |
<< 1000; // expected position after |
|
257 |
||
258 |
QTest::newRow("Illegal step sub") << int(QAbstractSlider::SliderSingleStepSub) // sliderAction |
|
259 |
<< 1000 // max |
|
260 |
<< 900 // min |
|
261 |
<< 987 // initial position |
|
262 |
<< 500 // single step size |
|
263 |
<< 234 // page step size |
|
264 |
<< 900; // expected position after |
|
265 |
||
266 |
QTest::newRow("Illegal page add") << int(QAbstractSlider::SliderPageStepAdd) // sliderAction |
|
267 |
<< 1000 // max |
|
268 |
<< 900 // min |
|
269 |
<< 988 // initial position |
|
270 |
<< 234 // single step size |
|
271 |
<< 500 // page step size |
|
272 |
<< 1000; // expected position after |
|
273 |
||
274 |
QTest::newRow("Illegal page sub") << int(QAbstractSlider::SliderPageStepSub) // sliderAction |
|
275 |
<< 1000 // max |
|
276 |
<< 900 // min |
|
277 |
<< 987 // initial position |
|
278 |
<< 234 // single step size |
|
279 |
<< 500 // page step size |
|
280 |
<< 900; // expected position after |
|
281 |
||
282 |
// Negative steps will also be abs()'d so, check that case. |
|
283 |
QTest::newRow("Negative step add") << int(QAbstractSlider::SliderSingleStepAdd) // sliderAction |
|
284 |
<< 1000 // max |
|
285 |
<< 900 // min |
|
286 |
<< 988 // initial position |
|
287 |
<< -1 // single step size |
|
288 |
<< 234 // page step size |
|
289 |
<< 989; // expected position after |
|
290 |
||
291 |
QTest::newRow("Negative step sub") << int(QAbstractSlider::SliderSingleStepSub) // sliderAction |
|
292 |
<< 1000 // max |
|
293 |
<< 900 // min |
|
294 |
<< 987 // initial position |
|
295 |
<< -1 // single step size |
|
296 |
<< 234 // page step size |
|
297 |
<< 986; // expected position after |
|
298 |
||
299 |
QTest::newRow("Negative page add") << int(QAbstractSlider::SliderPageStepAdd) // sliderAction |
|
300 |
<< 1000 // max |
|
301 |
<< 900 // min |
|
302 |
<< 988 // initial position |
|
303 |
<< 234 // single step size |
|
304 |
<< -1 // page step size |
|
305 |
<< 989; // expected position after |
|
306 |
||
307 |
QTest::newRow("Negative page sub") << int(QAbstractSlider::SliderPageStepSub) // sliderAction |
|
308 |
<< 1000 // max |
|
309 |
<< 900 // min |
|
310 |
<< 987 // initial position |
|
311 |
<< 234 // single step size |
|
312 |
<< -1 // page step size |
|
313 |
<< 986; // expected position after |
|
314 |
||
315 |
QTest::newRow("Illegal negative step add") << int(QAbstractSlider::SliderSingleStepAdd) // sliderAction |
|
316 |
<< 1000 // max |
|
317 |
<< 900 // min |
|
318 |
<< 988 // initial position |
|
319 |
<< -500 // single step size |
|
320 |
<< 234 // page step size |
|
321 |
<< 1000; // expected position after |
|
322 |
||
323 |
||
324 |
QTest::newRow("Illegal negative step sub") << int(QAbstractSlider::SliderSingleStepSub) // sliderAction |
|
325 |
<< 1000 // max |
|
326 |
<< 900 // min |
|
327 |
<< 988 // initial position |
|
328 |
<< -500 // single step size |
|
329 |
<< 234 // page step size |
|
330 |
<< 900; // expected position after |
|
331 |
||
332 |
QTest::newRow("Illegal negative page add") << int(QAbstractSlider::SliderPageStepAdd) // sliderAction |
|
333 |
<< 1000 // max |
|
334 |
<< 900 // min |
|
335 |
<< 988 // initial position |
|
336 |
<< 234 // single step size |
|
337 |
<< -500 // page step size |
|
338 |
<< 1000; // expected position after |
|
339 |
||
340 |
QTest::newRow("Illegal negative page sub") << int(QAbstractSlider::SliderPageStepSub) // sliderAction |
|
341 |
<< 1000 // max |
|
342 |
<< 900 // min |
|
343 |
<< 988 // initial position |
|
344 |
<< 245 // single step size |
|
345 |
<< -500 // page step size |
|
346 |
<< 900; // expected position after |
|
347 |
||
348 |
QTest::newRow("Slider to minimum") << int(QAbstractSlider::SliderToMinimum) // sliderAction |
|
349 |
<< 1000 // max |
|
350 |
<< 900 // min |
|
351 |
<< 988 // initial position |
|
352 |
<< 245 // single step size |
|
353 |
<< 1 // page step size |
|
354 |
<< 900; // expected position after |
|
355 |
||
356 |
QTest::newRow("Slider to maximum") << int(QAbstractSlider::SliderToMaximum) // sliderAction |
|
357 |
<< 1000 // max |
|
358 |
<< 900 // min |
|
359 |
<< 988 // initial position |
|
360 |
<< 245 // single step size |
|
361 |
<< 1 // page step size |
|
362 |
<< 1000; // expected position after |
|
363 |
||
364 |
} |
|
365 |
||
366 |
void tst_QAbstractSlider::triggerAction() |
|
367 |
{ |
|
368 |
QFETCH(int,sliderAction); |
|
369 |
QFETCH(int,maximum); |
|
370 |
QFETCH(int,minimum); |
|
371 |
QFETCH(int,initialSliderPosition); |
|
372 |
QFETCH(int,singleStep); |
|
373 |
QFETCH(int,pageStep); |
|
374 |
QFETCH(int,expectedSliderPosition); |
|
375 |
||
376 |
slider->setTracking(true); |
|
377 |
slider->setRange(minimum,maximum); |
|
378 |
slider->setSingleStep(singleStep); |
|
379 |
slider->setPageStep(pageStep); |
|
380 |
QCOMPARE(slider->singleStep(), qAbs(singleStep)); |
|
381 |
QCOMPARE(slider->pageStep(), qAbs(pageStep)); |
|
382 |
||
383 |
int oldPosition = slider->sliderPosition(); |
|
384 |
slider->setSliderPosition(initialSliderPosition); |
|
385 |
||
386 |
QVERIFY( (oldPosition == initialSliderPosition && previousAction == int(QAbstractSlider::SliderNoAction)) || |
|
387 |
(oldPosition != initialSliderPosition && previousAction == int(QAbstractSlider::SliderMove))); |
|
388 |
previousAction = int(QAbstractSlider::SliderNoAction); |
|
389 |
||
390 |
QAbstractSlider::SliderAction *action = reinterpret_cast<QAbstractSlider::SliderAction*>(&sliderAction); |
|
391 |
QVERIFY(action != 0); |
|
392 |
||
393 |
slider->triggerAction(*action); |
|
394 |
QCOMPARE(previousAction,sliderAction); // previousAction set in the actionTriggered() slot |
|
395 |
QCOMPARE(slider->sliderPosition(),expectedSliderPosition); |
|
396 |
QCOMPARE(slider->value(),expectedSliderPosition); |
|
397 |
QCOMPARE(reportedValue,expectedSliderPosition); |
|
398 |
previousAction = int(QAbstractSlider::SliderNoAction); |
|
399 |
if (initialSliderPosition != expectedSliderPosition) |
|
400 |
QVERIFY(actionTriggeredTimeStamp < valueChangedTimeStamp); |
|
401 |
} |
|
402 |
||
403 |
void tst_QAbstractSlider::minimum_maximum_data() |
|
404 |
{ |
|
405 |
QTest::addColumn<int>("minimum"); |
|
406 |
QTest::addColumn<int>("maximum"); |
|
407 |
QTest::addColumn<int>("expectedMinimum"); |
|
408 |
QTest::addColumn<int>("expectedMaximum"); |
|
409 |
||
410 |
QTest::newRow("Normal range") << 100 << 200 << 100 << 200; |
|
411 |
QTest::newRow("Minimum higher") << 100 << 0 << 100 << 100; |
|
412 |
QTest::newRow("Negative minimum") << -100 << 100 << -100 << 100; |
|
413 |
QTest::newRow("Negative range") << -100 << -50 << -100 << -50; |
|
414 |
} |
|
415 |
||
416 |
void tst_QAbstractSlider::minimum_maximum() |
|
417 |
{ |
|
418 |
QFETCH(int, minimum); |
|
419 |
QFETCH(int, maximum); |
|
420 |
QFETCH(int, expectedMinimum); |
|
421 |
QFETCH(int, expectedMaximum); |
|
422 |
||
423 |
slider->setRange(minimum,maximum); |
|
424 |
QCOMPARE(slider->minimum(),expectedMinimum); |
|
425 |
QCOMPARE(slider->maximum(),expectedMaximum); |
|
426 |
QCOMPARE(reportedMinimum,expectedMinimum); |
|
427 |
QCOMPARE(reportedMaximum,expectedMaximum); |
|
428 |
||
429 |
slider->setRange(minimum,maximum); |
|
430 |
slider->setMaximum(slider->minimum() - 1); |
|
431 |
QCOMPARE(slider->maximum(),slider->minimum()); |
|
432 |
QCOMPARE(reportedMinimum,slider->minimum()); |
|
433 |
QCOMPARE(reportedMaximum,slider->maximum()); |
|
434 |
||
435 |
slider->setRange(minimum,maximum); |
|
436 |
slider->setMinimum(slider->maximum() + 1); |
|
437 |
QCOMPARE(slider->minimum(),slider->maximum()); |
|
438 |
QCOMPARE(reportedMinimum,slider->minimum()); |
|
439 |
QCOMPARE(reportedMaximum,slider->maximum()); |
|
440 |
||
441 |
slider->setRange(minimum,maximum); |
|
442 |
slider->setSliderPosition(slider->maximum() + 1); |
|
443 |
QCOMPARE(slider->sliderPosition(), slider->maximum()); |
|
444 |
QCOMPARE(slider->value(), slider->maximum()); |
|
445 |
QCOMPARE(reportedValue, slider->maximum()); |
|
446 |
||
447 |
slider->setRange(minimum,maximum); |
|
448 |
slider->setSliderPosition(slider->minimum() - 1); |
|
449 |
QCOMPARE(slider->sliderPosition(), slider->minimum()); |
|
450 |
QCOMPARE(slider->value(), slider->minimum()); |
|
451 |
QCOMPARE(reportedValue, slider->minimum()); |
|
452 |
||
453 |
slider->setRange(minimum,maximum); |
|
454 |
int oldPosition = slider->sliderPosition(); |
|
455 |
slider->setMaximum(oldPosition - 1); |
|
456 |
QCOMPARE(slider->sliderPosition(),oldPosition - 1); |
|
457 |
||
458 |
slider->setRange(minimum,maximum); |
|
459 |
oldPosition = slider->sliderPosition(); |
|
460 |
slider->setMinimum(oldPosition + 1); |
|
461 |
QCOMPARE(slider->sliderPosition(), oldPosition + 1); |
|
462 |
} |
|
463 |
||
464 |
void tst_QAbstractSlider::keyPressed_data() |
|
465 |
{ |
|
466 |
QTest::addColumn<int>("initialSliderPosition"); |
|
467 |
QTest::addColumn<int>("minimum"); |
|
468 |
QTest::addColumn<int>("maximum"); |
|
469 |
QTest::addColumn<int>("stepSize"); |
|
470 |
QTest::addColumn<int>("pageSize"); |
|
471 |
QTest::addColumn<QList<Qt::Key> >("keySequence"); |
|
472 |
QTest::addColumn<int>("expectedSliderPositionHorizontal"); |
|
473 |
QTest::addColumn<int>("expectedSliderPositionVertical"); |
|
474 |
QTest::addColumn<int>("expectedSliderPositionHorizontalInverted"); // :) |
|
475 |
QTest::addColumn<int>("expectedSliderPositionVerticalInverted"); |
|
476 |
||
477 |
||
478 |
QList<Qt::Key> list; |
|
479 |
||
480 |
list << Qt::Key_Down; |
|
481 |
QTest::newRow("Step down once") << 10 // initial position |
|
482 |
<< 0 // minimum |
|
483 |
<< 100 // maximum |
|
484 |
<< 3 // single step size |
|
485 |
<< 0 // page step size |
|
486 |
<< list // key sequence |
|
487 |
<< 7 // result in case of horizontal slider |
|
488 |
<< 7 // result in case of vertical slider |
|
489 |
<< 13 // result in case of inverted horiz. slider |
|
490 |
<< 13; // result in case of inverted vertical slider |
|
491 |
||
492 |
list = QList<Qt::Key>(); |
|
493 |
list << Qt::Key_Up; |
|
494 |
QTest::newRow("Step down once") << 10 // initial position |
|
495 |
<< 0 // minimum |
|
496 |
<< 100 // maximum |
|
497 |
<< 3 // single step size |
|
498 |
<< 0 // page step size |
|
499 |
<< list // key sequence |
|
500 |
<< 13 // result in case of horizontal slider |
|
501 |
<< 13 // result in case of vertical slider |
|
502 |
<< 7 // result in case of inverted horiz. slider |
|
503 |
<< 7; // result in case of inverted vertical slider |
|
504 |
||
505 |
||
506 |
list = QList<Qt::Key>(); |
|
507 |
list << Qt::Key_Left; |
|
508 |
QTest::newRow("Step left once") << 10 // initial position |
|
509 |
<< 0 // minimum |
|
510 |
<< 100 // maximum |
|
511 |
<< 3 // single step size |
|
512 |
<< 0 // page step size |
|
513 |
<< list // key sequence |
|
514 |
<< 7 // result in case of horizontal slider |
|
515 |
<< 7 // result in case of vertical slider |
|
516 |
<< 13 // result in case of inverted horiz. slider |
|
517 |
<< 13; // result in case of inverted vertical slider |
|
518 |
||
519 |
list = QList<Qt::Key>(); |
|
520 |
list << Qt::Key_Right; |
|
521 |
QTest::newRow("Step right once") << 10 // initial position |
|
522 |
<< 0 // minimum |
|
523 |
<< 100 // maximum |
|
524 |
<< 3 // single step size |
|
525 |
<< 0 // page step size |
|
526 |
<< list // key sequence |
|
527 |
<< 13 // result in case of horizontal slider |
|
528 |
<< 13 // result in case of vertical slider |
|
529 |
<< 7 // result in case of inverted horiz. slider |
|
530 |
<< 7; // result in case of inverted vertical slider |
|
531 |
||
532 |
list = QList<Qt::Key>(); |
|
533 |
list << Qt::Key_PageDown; |
|
534 |
QTest::newRow("Page down once") << 10 // initial position |
|
535 |
<< 0 // minimum |
|
536 |
<< 100 // maximum |
|
537 |
<< 0 // single step size |
|
538 |
<< 3 // page step size |
|
539 |
<< list // key sequence |
|
540 |
<< 7 // result in case of horizontal slider |
|
541 |
<< 7 // result in case of vertical slider |
|
542 |
<< 13 // result in case of inverted horiz. slider |
|
543 |
<< 13; // result in case of inverted vertical slider |
|
544 |
||
545 |
list = QList<Qt::Key>(); |
|
546 |
list << Qt::Key_PageUp; |
|
547 |
QTest::newRow("Page up once") << 10 // initial position |
|
548 |
<< 0 // minimum |
|
549 |
<< 100 // maximum |
|
550 |
<< 0 // single step size |
|
551 |
<< 3 // page step size |
|
552 |
<< list // key sequence |
|
553 |
<< 13 // result in case of horizontal slider |
|
554 |
<< 13 // result in case of vertical slider |
|
555 |
<< 7 // result in case of inverted horiz. slider |
|
556 |
<< 7; // result in case of inverted vertical slider |
|
557 |
||
558 |
list = QList<Qt::Key>(); |
|
559 |
list << Qt::Key_Up << Qt::Key_Up << Qt::Key_PageDown << Qt::Key_PageDown << Qt::Key_Left << Qt::Key_Left |
|
560 |
<< Qt::Key_Right << Qt::Key_Down << Qt::Key_PageUp << Qt::Key_PageUp << Qt::Key_Down << Qt::Key_Right; |
|
561 |
QTest::newRow("Symmetric seq") << 50 // initial position |
|
562 |
<< 0 // minimum |
|
563 |
<< 100 // maximum |
|
564 |
<< 3 // single step size |
|
565 |
<< 3 // page step size |
|
566 |
<< list // key sequence |
|
567 |
<< 50 // result in case of horizontal slider |
|
568 |
<< 50 // result in case of vertical slider |
|
569 |
<< 50 // result in case of inverted horiz. slider |
|
570 |
<< 50; // result in case of inverted vertical slider |
|
571 |
||
572 |
||
573 |
list = QList<Qt::Key>(); |
|
574 |
list << Qt::Key_Home; |
|
575 |
QTest::newRow("Home") << 10 // initial position |
|
576 |
<< 0 // minimum |
|
577 |
<< 100 // maximum |
|
578 |
<< 0 // single step size |
|
579 |
<< 3 // page step size |
|
580 |
<< list // key sequence |
|
581 |
<< 0 // result in case of horizontal slider |
|
582 |
<< 0 // result in case of vertical slider |
|
583 |
<< 0 // result in case of inverted horiz. slider |
|
584 |
<< 0; // result in case of inverted vertical slider |
|
585 |
||
586 |
list = QList<Qt::Key>(); |
|
587 |
list << Qt::Key_End; |
|
588 |
QTest::newRow("End") << 10 // initial position |
|
589 |
<< 0 // minimum |
|
590 |
<< 100 // maximum |
|
591 |
<< 0 // single step size |
|
592 |
<< 3 // page step size |
|
593 |
<< list // key sequence |
|
594 |
<< 100 // result in case of horizontal slider |
|
595 |
<< 100 // result in case of vertical slider |
|
596 |
<< 100 // result in case of inverted horiz. slider |
|
597 |
<< 100; // result in case of inverted vertical slider |
|
598 |
||
599 |
list = QList<Qt::Key>(); |
|
600 |
list << Qt::Key_End << Qt::Key_Up; |
|
601 |
QTest::newRow("Past end")<< 10 // initial position |
|
602 |
<< 0 // minimum |
|
603 |
<< 100 // maximum |
|
604 |
<< 3 // single step size |
|
605 |
<< 3 // page step size |
|
606 |
<< list // key sequence |
|
607 |
<< 100 // result in case of horizontal slider |
|
608 |
<< 100 // result in case of vertical slider |
|
609 |
<< 97 // result in case of inverted horiz. slider |
|
610 |
<< 97; // result in case of inverted vertical slider |
|
611 |
||
612 |
list = QList<Qt::Key>(); |
|
613 |
list << Qt::Key_Home << Qt::Key_Down; |
|
614 |
QTest::newRow("Past home")<< 10 // initial position |
|
615 |
<< 0 // minimum |
|
616 |
<< 100 // maximum |
|
617 |
<< 3 // single step size |
|
618 |
<< 3 // page step size |
|
619 |
<< list // key sequence |
|
620 |
<< 0 // result in case of horizontal slider |
|
621 |
<< 0 // result in case of vertical slider |
|
622 |
<< 3 // result in case of inverted horiz. slider |
|
623 |
<< 3; // result in case of inverted vertical slider |
|
624 |
||
625 |
} |
|
626 |
||
627 |
void tst_QAbstractSlider::keyPressed() |
|
628 |
{ |
|
629 |
QFETCH(int, initialSliderPosition); |
|
630 |
QFETCH(int, minimum); |
|
631 |
QFETCH(int, maximum); |
|
632 |
QFETCH(int, stepSize); |
|
633 |
QFETCH(int, pageSize); |
|
634 |
QFETCH(QList<Qt::Key>, keySequence); |
|
635 |
QFETCH(int, expectedSliderPositionHorizontal); |
|
636 |
QFETCH(int, expectedSliderPositionVertical); |
|
637 |
QFETCH(int, expectedSliderPositionHorizontalInverted); |
|
638 |
QFETCH(int, expectedSliderPositionVerticalInverted); |
|
639 |
||
640 |
// Horizontal non-inverted |
|
641 |
slider->setRange(minimum,maximum); |
|
642 |
slider->setSliderPosition(initialSliderPosition); |
|
643 |
slider->setSingleStep(stepSize); |
|
644 |
slider->setPageStep(pageSize); |
|
645 |
slider->setOrientation(Qt::Horizontal); |
|
646 |
slider->setInvertedAppearance(false); |
|
647 |
slider->setInvertedControls(false); |
|
648 |
for (int i=0;i<keySequence.count();i++) { |
|
649 |
QTest::keyClick(slider, keySequence.at(i)); |
|
650 |
} |
|
651 |
QCOMPARE(slider->sliderPosition(), expectedSliderPositionHorizontal); |
|
652 |
||
653 |
// Horizontal inverted |
|
654 |
slider->setRange(minimum,maximum); |
|
655 |
slider->setSliderPosition(initialSliderPosition); |
|
656 |
slider->setSingleStep(stepSize); |
|
657 |
slider->setPageStep(pageSize); |
|
658 |
slider->setOrientation(Qt::Horizontal); |
|
659 |
slider->setInvertedAppearance(true); |
|
660 |
slider->setInvertedControls(true); |
|
661 |
for (int i=0;i<keySequence.count();i++) |
|
662 |
QTest::keyPress(slider, keySequence.at(i)); |
|
663 |
QCOMPARE(slider->sliderPosition(), expectedSliderPositionHorizontalInverted); |
|
664 |
||
665 |
// Vertical non-inverted |
|
666 |
slider->setRange(minimum,maximum); |
|
667 |
slider->setSliderPosition(initialSliderPosition); |
|
668 |
slider->setSingleStep(stepSize); |
|
669 |
slider->setPageStep(pageSize); |
|
670 |
slider->setOrientation(Qt::Vertical); |
|
671 |
slider->setInvertedAppearance(false); |
|
672 |
slider->setInvertedControls(false); |
|
673 |
for (int i=0;i<keySequence.count();i++) |
|
674 |
QTest::keyPress(slider, keySequence.at(i)); |
|
675 |
QCOMPARE(slider->sliderPosition(), expectedSliderPositionVertical); |
|
676 |
||
677 |
// Vertical inverted |
|
678 |
slider->setRange(minimum,maximum); |
|
679 |
slider->setSliderPosition(initialSliderPosition); |
|
680 |
slider->setSingleStep(stepSize); |
|
681 |
slider->setPageStep(pageSize); |
|
682 |
slider->setOrientation(Qt::Vertical); |
|
683 |
slider->setInvertedAppearance(true); |
|
684 |
slider->setInvertedControls(true); |
|
685 |
for (int i=0;i<keySequence.count();i++) |
|
686 |
QTest::keyPress(slider, keySequence.at(i)); |
|
687 |
QCOMPARE(slider->sliderPosition(), expectedSliderPositionVerticalInverted); |
|
688 |
} |
|
689 |
||
690 |
void tst_QAbstractSlider::wheelEvent_data() |
|
691 |
{ |
|
692 |
QTest::addColumn<int>("initialSliderPosition"); |
|
693 |
QTest::addColumn<int>("minimum"); |
|
694 |
QTest::addColumn<int>("maximum"); |
|
695 |
QTest::addColumn<int>("singleStep"); |
|
696 |
QTest::addColumn<int>("pageStep"); |
|
697 |
QTest::addColumn<bool>("invertedControls"); |
|
698 |
QTest::addColumn<int>("wheelScrollLines"); |
|
699 |
QTest::addColumn<bool>("withModifiers"); // use keyboard modifiers while scrolling? (CTRL and SHIFT) |
|
700 |
QTest::addColumn<int>("deltaMultiple"); // multiples of WHEEL_DELTA |
|
701 |
QTest::addColumn<int>("sliderOrientation"); |
|
702 |
QTest::addColumn<int>("wheelOrientation"); |
|
703 |
QTest::addColumn<int>("expectedSliderPosition"); |
|
704 |
QTest::addColumn<QPoint>("distanceFromBottomRight"); // mpointer's distance from bottom-right corner of widget |
|
705 |
||
706 |
QTest::newRow("Normal data step") << 0 // initial position |
|
707 |
<< 0 // minimum |
|
708 |
<< 100 // maximum |
|
709 |
<< 1 // single step |
|
710 |
<< 100 // page step |
|
711 |
<< false // inverted controls |
|
712 |
<< 20 // wheel scroll lines |
|
713 |
<< false // with modifiers |
|
714 |
<< 1 // delta |
|
715 |
<< int(Qt::Vertical) // orientation of slider |
|
716 |
<< int(Qt::Vertical) // orientation of wheel |
|
717 |
<< 20 // expected position after |
|
718 |
<< QPoint(0,0); |
|
719 |
||
720 |
QTest::newRow("Normal data page") << 0 // initial position |
|
721 |
<< 0 // minimum |
|
722 |
<< 100 // maximum |
|
723 |
<< 100 // single step |
|
724 |
<< 1 // page step |
|
725 |
<< false // inverted controls |
|
726 |
<< 20 // wheel scroll lines |
|
727 |
<< false // with modifiers |
|
728 |
<< 1 // delta |
|
729 |
<< int(Qt::Vertical) // orientation of slider |
|
730 |
<< int(Qt::Vertical) // orientation of wheel |
|
731 |
<< 1 // expected position after |
|
732 |
<< QPoint(1,1); |
|
733 |
||
734 |
QTest::newRow("Different orientation") << 0 // initial position |
|
735 |
<< 0 // minimum |
|
736 |
<< 100 // maximum |
|
737 |
<< 100 // single step |
|
738 |
<< 1 // page step |
|
739 |
<< false // inverted controls |
|
740 |
<< 20 // wheel scroll lines |
|
741 |
<< false // with modifiers |
|
742 |
<< 1 // delta |
|
743 |
<< int(Qt::Horizontal) // orientation of slider |
|
744 |
<< int(Qt::Vertical) // orientation of wheel |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
745 |
<< 1 // expected position after |
0 | 746 |
<< QPoint(1,1); |
747 |
||
748 |
QTest::newRow("Different orientation2")<< 0 // initial position |
|
749 |
<< 0 // minimum |
|
750 |
<< 100 // maximum |
|
751 |
<< 100 // single step |
|
752 |
<< 1 // page step |
|
753 |
<< false // inverted controls |
|
754 |
<< 20 // wheel scroll lines |
|
755 |
<< false // with modifiers |
|
756 |
<< 1 // delta |
|
757 |
<< int(Qt::Horizontal) // orientation of slider |
|
758 |
<< int(Qt::Vertical) // orientation of wheel |
|
759 |
<< 1 // expected position after |
|
760 |
<< QPoint(0,0); |
|
761 |
||
762 |
||
763 |
QTest::newRow("Inverted controls") << 50 // initial position |
|
764 |
<< 0 // minimum |
|
765 |
<< 100 // maximum |
|
766 |
<< 1 // single step |
|
767 |
<< 100 // page step |
|
768 |
<< true // inverted controls |
|
769 |
<< 20 // wheel scroll lines |
|
770 |
<< false // with modifiers |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
771 |
<< -1 // delta |
0 | 772 |
<< int(Qt::Horizontal) // orientation of slider |
773 |
<< int(Qt::Horizontal) // orientation of wheel |
|
774 |
<< 30 // expected position after |
|
775 |
<< QPoint(1,1); |
|
776 |
||
777 |
QTest::newRow("Past end") << 50 // initial position |
|
778 |
<< 0 // minimum |
|
779 |
<< 100 // maximum |
|
780 |
<< 26 // single step |
|
781 |
<< 100 // page step |
|
782 |
<< false // inverted controls |
|
783 |
<< 1 // wheel scroll lines |
|
784 |
<< false // with modifiers |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
785 |
<< -2 // delta |
0 | 786 |
<< int(Qt::Horizontal) // orientation of slider |
787 |
<< int(Qt::Horizontal) // orientation of wheel |
|
788 |
<< 100 // expected position after |
|
789 |
<< QPoint(0,0); |
|
790 |
||
791 |
QTest::newRow("Past start") << 50 // initial position |
|
792 |
<< 0 // minimum |
|
793 |
<< 100 // maximum |
|
794 |
<< 26 // single step |
|
795 |
<< 100 // page step |
|
796 |
<< false // inverted controls |
|
797 |
<< 1 // wheel scroll lines |
|
798 |
<< false // with modifiers |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
799 |
<< 2 // delta |
0 | 800 |
<< int(Qt::Horizontal) // orientation of slider |
801 |
<< int(Qt::Horizontal) // orientation of wheel |
|
802 |
<< 0 // expected position after |
|
803 |
<< QPoint(0,0); |
|
804 |
||
805 |
QTest::newRow("With modifiers") << 50 // initial position |
|
806 |
<< 0 // minimum |
|
807 |
<< 100 // maximum |
|
808 |
<< 1 // single step |
|
809 |
<< 40 // page step |
|
810 |
<< false // inverted controls |
|
811 |
<< 20 // wheel scroll lines |
|
812 |
<< true // with modifiers |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
813 |
<< -1 // delta |
0 | 814 |
<< int(Qt::Horizontal) // orientation of slider |
815 |
<< int(Qt::Horizontal) // orientation of wheel |
|
816 |
<< 90 // expected position after |
|
817 |
<< QPoint(0,0); |
|
818 |
||
819 |
} |
|
820 |
||
821 |
void tst_QAbstractSlider::wheelEvent() |
|
822 |
{ |
|
823 |
QFETCH(int,initialSliderPosition); |
|
824 |
QFETCH(int,minimum); |
|
825 |
QFETCH(int,maximum); |
|
826 |
QFETCH(int,singleStep); |
|
827 |
QFETCH(int,pageStep); |
|
828 |
QFETCH(bool,invertedControls); |
|
829 |
QFETCH(int,wheelScrollLines); |
|
830 |
QFETCH(bool,withModifiers); |
|
831 |
QFETCH(int,deltaMultiple); |
|
832 |
QFETCH(int,sliderOrientation); |
|
833 |
QFETCH(int,wheelOrientation); |
|
834 |
QFETCH(int,expectedSliderPosition); |
|
835 |
QFETCH(QPoint,distanceFromBottomRight); |
|
836 |
||
837 |
QCoreApplication *applicationInstance = QCoreApplication::instance(); |
|
838 |
QVERIFY(applicationInstance != 0); |
|
839 |
QApplication::setWheelScrollLines(wheelScrollLines); |
|
840 |
||
841 |
Qt::Orientation orientation = *reinterpret_cast<Qt::Orientation*>(&sliderOrientation); |
|
842 |
slider->setRange(minimum,maximum); |
|
843 |
slider->setSliderPosition(initialSliderPosition); |
|
844 |
slider->setSingleStep(singleStep); |
|
845 |
slider->setPageStep(pageStep); |
|
846 |
slider->setInvertedControls(invertedControls); |
|
847 |
slider->setOrientation(orientation); |
|
848 |
||
849 |
Qt::KeyboardModifier k = withModifiers ? Qt::ControlModifier : Qt::NoModifier; |
|
850 |
orientation = *reinterpret_cast<Qt::Orientation*>(&wheelOrientation); |
|
851 |
QWheelEvent event(slider->rect().bottomRight() + distanceFromBottomRight, WHEEL_DELTA * deltaMultiple, |
|
852 |
Qt::NoButton, k, orientation); |
|
853 |
QVERIFY(applicationInstance->sendEvent(slider,&event)); |
|
854 |
QCOMPARE(slider->sliderPosition(),expectedSliderPosition); |
|
855 |
||
856 |
slider->setSliderPosition(initialSliderPosition); |
|
857 |
k = withModifiers ? Qt::ShiftModifier : Qt::NoModifier; |
|
858 |
event = QWheelEvent(slider->rect().bottomRight() + distanceFromBottomRight, WHEEL_DELTA * deltaMultiple, |
|
859 |
Qt::NoButton, k, orientation); |
|
860 |
QSignalSpy spy1(slider, SIGNAL(actionTriggered(int))); |
|
861 |
QSignalSpy spy2(slider, SIGNAL(valueChanged(int))); |
|
862 |
QVERIFY(applicationInstance->sendEvent(slider,&event)); |
|
863 |
QCOMPARE(slider->sliderPosition(),expectedSliderPosition); |
|
864 |
int expectedSignalCount = (initialSliderPosition == expectedSliderPosition) ? 0 : 1; |
|
865 |
QCOMPARE(spy1.count(), expectedSignalCount); |
|
866 |
QCOMPARE(spy2.count(), expectedSignalCount); |
|
867 |
if (expectedSignalCount) |
|
868 |
QVERIFY(actionTriggeredTimeStamp < valueChangedTimeStamp); |
|
869 |
} |
|
870 |
||
871 |
void tst_QAbstractSlider::sliderPressedReleased_data() |
|
872 |
{ |
|
873 |
QTest::addColumn<int>("control"); |
|
874 |
QTest::addColumn<int>("minimum"); |
|
875 |
QTest::addColumn<int>("maximum"); |
|
876 |
QTest::addColumn<uint>("subControl"); |
|
877 |
QTest::addColumn<int>("expectedCount"); |
|
878 |
||
879 |
QTest::newRow("slider on the handle") << int(QStyle::CC_Slider) |
|
880 |
<< 0 |
|
881 |
<< 20 |
|
882 |
<< uint(QStyle::SC_SliderHandle) |
|
883 |
<< 1; |
|
884 |
||
885 |
QTest::newRow("slider on the groove") << int(QStyle::CC_Slider) |
|
886 |
<< 0 |
|
887 |
<< 20 |
|
888 |
<< uint(QStyle::SC_SliderGroove) |
|
889 |
<< ((qApp->style()->styleHint(QStyle::SH_Slider_AbsoluteSetButtons) & Qt::LeftButton) ? 1 : 0); |
|
890 |
||
891 |
QTest::newRow("scrollbar on the handle") << int(QStyle::CC_ScrollBar) |
|
892 |
<< 0 |
|
893 |
<< 20 |
|
894 |
<< uint(QStyle::SC_ScrollBarSlider) |
|
895 |
<< 1; |
|
896 |
||
897 |
QTest::newRow("scrollbar on the groove") << int(QStyle::CC_ScrollBar) |
|
898 |
<< 0 |
|
899 |
<< 20 |
|
900 |
<< uint(QStyle::SC_ScrollBarGroove) |
|
901 |
<< 0; |
|
902 |
} |
|
903 |
||
904 |
void tst_QAbstractSlider::sliderPressedReleased() |
|
905 |
{ |
|
906 |
QFETCH(int, control); |
|
907 |
QFETCH(int, minimum); |
|
908 |
QFETCH(int, maximum); |
|
909 |
QFETCH(uint, subControl); |
|
910 |
QFETCH(int, expectedCount); |
|
911 |
||
912 |
QAbstractSlider *slider; |
|
913 |
switch (control) { |
|
914 |
default: |
|
915 |
qWarning("Bad input into test, leaving"); |
|
916 |
return; |
|
917 |
break; |
|
918 |
case QStyle::CC_Slider: |
|
919 |
slider = new QSlider; |
|
920 |
slider->setLayoutDirection(Qt::LeftToRight); // Makes "upside down" much easier to compute |
|
921 |
break; |
|
922 |
case QStyle::CC_ScrollBar: |
|
923 |
slider = new QScrollBar; |
|
924 |
break; |
|
925 |
} |
|
926 |
||
927 |
||
928 |
slider->setMinimum(minimum); |
|
929 |
slider->setMaximum(maximum); |
|
930 |
slider->setValue(0); |
|
931 |
slider->setOrientation(Qt::Vertical); |
|
932 |
slider->resize(slider->sizeHint().width(), slider->sizeHint().height() + 100); |
|
933 |
QSignalSpy spy1(slider, SIGNAL(sliderPressed())); |
|
934 |
QSignalSpy spy2(slider, SIGNAL(sliderReleased())); |
|
935 |
||
936 |
// Mac Style requires the control to be active to get the correct values... |
|
937 |
slider->show(); |
|
938 |
slider->activateWindow(); |
|
939 |
||
940 |
QStyleOptionSlider option; |
|
941 |
option.init(slider); |
|
942 |
option.upsideDown = control == QStyle::CC_Slider ? !slider->invertedAppearance() |
|
943 |
: slider->invertedAppearance(); |
|
944 |
option.subControls = QStyle::SC_None; |
|
945 |
option.activeSubControls = QStyle::SC_None; |
|
946 |
option.orientation = slider->orientation(); |
|
947 |
option.maximum = maximum; |
|
948 |
option.minimum = minimum; |
|
949 |
option.sliderPosition = slider->value(); |
|
950 |
option.sliderValue = slider->value(); |
|
951 |
option.singleStep = slider->singleStep(); |
|
952 |
option.pageStep = slider->pageStep(); |
|
953 |
QRect rect = slider->style()->subControlRect(QStyle::ComplexControl(control), &option, |
|
954 |
QStyle::SubControl(subControl), slider); |
|
955 |
||
956 |
QTest::mousePress(slider, Qt::LeftButton, 0, QPoint(rect.center().x() + 2, rect.center().y() + 2)); |
|
957 |
QCOMPARE(spy1.count(), expectedCount); |
|
958 |
QTest::mouseRelease(slider, Qt::LeftButton, 0, rect.center()); |
|
959 |
QCOMPARE(spy2.count(), expectedCount); |
|
960 |
||
961 |
delete slider; |
|
962 |
} |
|
963 |
||
964 |
void tst_QAbstractSlider::sliderMoved_data() |
|
965 |
{ |
|
966 |
QTest::addColumn<int>("control"); |
|
967 |
QTest::addColumn<int>("minimum"); |
|
968 |
QTest::addColumn<int>("maximum"); |
|
969 |
QTest::addColumn<int>("position"); |
|
970 |
QTest::addColumn<bool>("sliderDown"); |
|
971 |
QTest::addColumn<int>("expectedCount"); |
|
972 |
||
973 |
QTest::newRow("slider pressed") << int(QStyle::CC_Slider) |
|
974 |
<< 0 |
|
975 |
<< 20 |
|
976 |
<< 10 |
|
977 |
<< true |
|
978 |
<< 1; |
|
979 |
||
980 |
QTest::newRow("slider not pressed") << int(QStyle::CC_Slider) |
|
981 |
<< 0 |
|
982 |
<< 20 |
|
983 |
<< 10 |
|
984 |
<< false |
|
985 |
<< 0; |
|
986 |
||
987 |
QTest::newRow("scrollbar pressed") << int(QStyle::CC_ScrollBar) |
|
988 |
<< 0 |
|
989 |
<< 20 |
|
990 |
<< 10 |
|
991 |
<< true |
|
992 |
<< 1; |
|
993 |
||
994 |
QTest::newRow("scrollbar not pressed") << int(QStyle::CC_ScrollBar) |
|
995 |
<< 0 |
|
996 |
<< 20 |
|
997 |
<< 10 |
|
998 |
<< false |
|
999 |
<< 0; |
|
1000 |
} |
|
1001 |
||
1002 |
void tst_QAbstractSlider::sliderMoved() |
|
1003 |
{ |
|
1004 |
QFETCH(int, control); |
|
1005 |
QFETCH(int, minimum); |
|
1006 |
QFETCH(int, maximum); |
|
1007 |
QFETCH(int, position); |
|
1008 |
QFETCH(bool, sliderDown); |
|
1009 |
QFETCH(int, expectedCount); |
|
1010 |
QAbstractSlider *slider; |
|
1011 |
switch (control) { |
|
1012 |
default: |
|
1013 |
slider = 0; |
|
1014 |
break; |
|
1015 |
case QStyle::CC_Slider: |
|
1016 |
slider = new QSlider; |
|
1017 |
break; |
|
1018 |
case QStyle::CC_ScrollBar: |
|
1019 |
slider = new QScrollBar; |
|
1020 |
break; |
|
1021 |
} |
|
1022 |
QSignalSpy spy(slider, SIGNAL(sliderMoved(int))); |
|
1023 |
||
1024 |
slider->setMinimum(minimum); |
|
1025 |
slider->setMaximum(maximum); |
|
1026 |
slider->setSliderDown(sliderDown); |
|
1027 |
slider->setSliderPosition(position); |
|
1028 |
QCOMPARE(spy.count(), expectedCount); |
|
1029 |
||
1030 |
delete slider; |
|
1031 |
} |
|
1032 |
||
1033 |
void tst_QAbstractSlider::setOrientation() |
|
1034 |
{ |
|
1035 |
QSlider slider(0); |
|
1036 |
||
1037 |
QSizePolicy sp = slider.sizePolicy(); |
|
1038 |
slider.setOrientation(slider.orientation()); |
|
1039 |
QSizePolicy sp2 = slider.sizePolicy(); |
|
1040 |
QCOMPARE(sp, sp2); |
|
1041 |
||
1042 |
slider.setOrientation(Qt::Horizontal); |
|
1043 |
sp = slider.sizePolicy(); |
|
1044 |
slider.setOrientation(Qt::Vertical); |
|
1045 |
sp2 = slider.sizePolicy(); |
|
1046 |
||
1047 |
QVERIFY(sp != sp2); |
|
1048 |
sp2.transpose(); |
|
1049 |
QCOMPARE(sp, sp2); |
|
1050 |
} |
|
1051 |
||
1052 |
||
1053 |
void tst_QAbstractSlider::rangeChanged_data() |
|
1054 |
{ |
|
1055 |
QTest::addColumn<int>("minimum"); |
|
1056 |
QTest::addColumn<int>("maximum"); |
|
1057 |
QTest::addColumn<int>("newMin"); |
|
1058 |
QTest::addColumn<int>("newMax"); |
|
1059 |
QTest::addColumn<int>("expectedCount"); |
|
1060 |
||
1061 |
QTest::newRow("no change") |
|
1062 |
<< 0 |
|
1063 |
<< 20 |
|
1064 |
<< 0 |
|
1065 |
<< 20 |
|
1066 |
<< 0; |
|
1067 |
||
1068 |
QTest::newRow("min change") |
|
1069 |
<< 0 |
|
1070 |
<< 20 |
|
1071 |
<< 10 |
|
1072 |
<< 20 |
|
1073 |
<< 1; |
|
1074 |
QTest::newRow("max change") |
|
1075 |
<< 0 |
|
1076 |
<< 20 |
|
1077 |
<< 0 |
|
1078 |
<< 30 |
|
1079 |
<< 1; |
|
1080 |
||
1081 |
QTest::newRow("both change") |
|
1082 |
<< 0 |
|
1083 |
<< 20 |
|
1084 |
<< 10 |
|
1085 |
<< 30 |
|
1086 |
<< 1; |
|
1087 |
} |
|
1088 |
||
1089 |
void tst_QAbstractSlider::rangeChanged() |
|
1090 |
{ |
|
1091 |
QFETCH(int, minimum); |
|
1092 |
QFETCH(int, maximum); |
|
1093 |
QFETCH(int, newMin); |
|
1094 |
QFETCH(int, newMax); |
|
1095 |
QFETCH(int, expectedCount); |
|
1096 |
QSlider slider; |
|
1097 |
slider.setRange(minimum, maximum); |
|
1098 |
QSignalSpy spy(&slider, SIGNAL(rangeChanged(int, int))); |
|
1099 |
slider.setRange(newMin, newMax); |
|
1100 |
QCOMPARE(spy.count(), expectedCount); |
|
1101 |
} |
|
1102 |
||
1103 |
void tst_QAbstractSlider::setSliderPosition_data() |
|
1104 |
{ |
|
1105 |
QTest::addColumn<bool>("tracking"); |
|
1106 |
QTest::addColumn<bool>("down"); |
|
1107 |
||
1108 |
QTest::newRow("tracking, slider down") |
|
1109 |
<< true |
|
1110 |
<< true; |
|
1111 |
QTest::newRow("tracking, slider not down") |
|
1112 |
<< true |
|
1113 |
<< false; |
|
1114 |
QTest::newRow("no tracking, slider down") |
|
1115 |
<< false |
|
1116 |
<< true; |
|
1117 |
QTest::newRow("no tracking, slider not down") |
|
1118 |
<< false |
|
1119 |
<< false; |
|
1120 |
} |
|
1121 |
||
1122 |
void tst_QAbstractSlider::setSliderPosition() |
|
1123 |
{ |
|
1124 |
QFETCH(bool, tracking); |
|
1125 |
QFETCH(bool, down); |
|
1126 |
const int minimum = 0; |
|
1127 |
const int maximum = 100; |
|
1128 |
const int initialValue = 50; |
|
1129 |
const int targetPosition = 75; |
|
1130 |
slider->setRange(minimum, maximum); |
|
1131 |
slider->setTracking(tracking); |
|
1132 |
slider->setSliderDown(down); |
|
1133 |
slider->setValue(initialValue); |
|
1134 |
QCOMPARE(slider->sliderPosition(), initialValue); |
|
1135 |
QSignalSpy spy1(slider, SIGNAL(sliderMoved(int))); |
|
1136 |
QSignalSpy spy2(slider, SIGNAL(valueChanged(int))); |
|
1137 |
slider->setSliderPosition(targetPosition); |
|
1138 |
QCOMPARE(slider->sliderPosition(), targetPosition); |
|
1139 |
QCOMPARE(spy1.count(), down ? 1 : 0); |
|
1140 |
QCOMPARE(spy2.count(), tracking ? 1 : 0); |
|
1141 |
QCOMPARE(slider->value(), tracking ? targetPosition : initialValue); |
|
1142 |
if (tracking && down) |
|
1143 |
QVERIFY(sliderMovedTimeStamp < valueChangedTimeStamp); |
|
1144 |
} |
|
1145 |
||
1146 |
void tst_QAbstractSlider::setValue_data() |
|
1147 |
{ |
|
1148 |
QTest::addColumn<bool>("down"); |
|
1149 |
||
1150 |
QTest::newRow("slider down") |
|
1151 |
<< true; |
|
1152 |
QTest::newRow("slider not down") |
|
1153 |
<< false; |
|
1154 |
} |
|
1155 |
||
1156 |
void tst_QAbstractSlider::setValue() |
|
1157 |
{ |
|
1158 |
QFETCH(bool, down); |
|
1159 |
const int minimum = 0; |
|
1160 |
const int maximum = 100; |
|
1161 |
slider->setRange(minimum, maximum); |
|
1162 |
slider->setSliderDown(down); |
|
1163 |
slider->setValue(49); // to force a valueChanged() below |
|
1164 |
QSignalSpy spy1(slider, SIGNAL(sliderMoved(int))); |
|
1165 |
QSignalSpy spy2(slider, SIGNAL(valueChanged(int))); |
|
1166 |
QSignalSpy spy3(slider, SIGNAL(actionTriggered(int))); |
|
1167 |
slider->setValue(50); |
|
1168 |
QCOMPARE(spy1.count(), down ? 1 : 0); |
|
1169 |
QCOMPARE(spy2.count(), 1); |
|
1170 |
QCOMPARE(spy3.count(), 0); |
|
1171 |
QCOMPARE(slider->value(), reportedValue); |
|
1172 |
QCOMPARE(slider->sliderPosition(), reportedSliderPosition); |
|
1173 |
if (down) |
|
1174 |
QVERIFY(sliderMovedTimeStamp < valueChangedTimeStamp); |
|
1175 |
} |
|
1176 |
||
1177 |
void tst_QAbstractSlider::waitUntilTimeElapsed(const QTime& t, int ms) |
|
1178 |
{ |
|
1179 |
const int eps = 80; |
|
1180 |
while (t.elapsed() < ms + eps) |
|
1181 |
QTest::qWait(qMax(ms - t.elapsed() + eps, 25)); |
|
1182 |
} |
|
1183 |
||
1184 |
void tst_QAbstractSlider::setRepeatAction() |
|
1185 |
{ |
|
1186 |
slider->setRange(0, 1000); |
|
1187 |
slider->setValue(55); |
|
1188 |
slider->setPageStep(10); |
|
1189 |
QSignalSpy spy(slider, SIGNAL(actionTriggered(int))); |
|
1190 |
||
1191 |
// Start repeat action with initial delay of 500 ms, and then repeating |
|
1192 |
// every 250 ms. |
|
1193 |
slider->setRepeatAction(QAbstractSlider::SliderPageStepAdd, 500, 250); |
|
1194 |
QCOMPARE(spy.count(), 0); |
|
1195 |
QCOMPARE(slider->value(), 55); |
|
1196 |
||
1197 |
QTime t; |
|
1198 |
t.start(); |
|
1199 |
QTest::qWait(300); |
|
1200 |
QCOMPARE(spy.count(), 0); |
|
1201 |
QCOMPARE(slider->value(), 55); |
|
1202 |
||
1203 |
waitUntilTimeElapsed(t, 550); |
|
1204 |
QCOMPARE(spy.count(), 1); |
|
1205 |
QCOMPARE(slider->value(), 65); |
|
1206 |
QCOMPARE(spy.at(0).at(0).toUInt(), (uint)QAbstractSlider::SliderPageStepAdd); |
|
1207 |
||
1208 |
waitUntilTimeElapsed(t, 790); |
|
1209 |
QCOMPARE(spy.count(), 2); |
|
1210 |
QCOMPARE(slider->value(), 75); |
|
1211 |
QCOMPARE(spy.at(1).at(0).toUInt(), (uint)QAbstractSlider::SliderPageStepAdd); |
|
1212 |
||
1213 |
waitUntilTimeElapsed(t, 1790); |
|
1214 |
QCOMPARE(spy.count(), 6); |
|
1215 |
QCOMPARE(slider->value(), 115); |
|
1216 |
QCOMPARE(spy.at(4).at(0).toUInt(), (uint)QAbstractSlider::SliderPageStepAdd); |
|
1217 |
QCOMPARE(spy.at(5).at(0).toUInt(), (uint)QAbstractSlider::SliderPageStepAdd); |
|
1218 |
||
1219 |
slider->setRepeatAction(QAbstractSlider::SliderNoAction); |
|
1220 |
QCOMPARE(spy.count(), 6); |
|
1221 |
QCOMPARE(slider->value(), 115); |
|
1222 |
||
1223 |
QTest::qWait(300); |
|
1224 |
QCOMPARE(spy.count(), 6); |
|
1225 |
QCOMPARE(slider->value(), 115); |
|
1226 |
} |
|
1227 |
||
1228 |
QTEST_MAIN(tst_QAbstractSlider) |
|
1229 |
#include "tst_qabstractslider.moc" |