0
|
1 |
/****************************************************************************
|
|
2 |
**
|
|
3 |
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
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 |
#ifdef Q_WS_MAC
|
|
718 |
<< 1 // expected position after
|
|
719 |
#else
|
|
720 |
<< 20 // expected position after
|
|
721 |
#endif
|
|
722 |
<< QPoint(0,0);
|
|
723 |
|
|
724 |
QTest::newRow("Normal data page") << 0 // initial position
|
|
725 |
<< 0 // minimum
|
|
726 |
<< 100 // maximum
|
|
727 |
<< 100 // single step
|
|
728 |
<< 1 // page step
|
|
729 |
<< false // inverted controls
|
|
730 |
<< 20 // wheel scroll lines
|
|
731 |
<< false // with modifiers
|
|
732 |
<< 1 // delta
|
|
733 |
<< int(Qt::Vertical) // orientation of slider
|
|
734 |
<< int(Qt::Vertical) // orientation of wheel
|
|
735 |
<< 1 // expected position after
|
|
736 |
<< QPoint(1,1);
|
|
737 |
|
|
738 |
QTest::newRow("Different orientation") << 0 // initial position
|
|
739 |
<< 0 // minimum
|
|
740 |
<< 100 // maximum
|
|
741 |
<< 100 // single step
|
|
742 |
<< 1 // page step
|
|
743 |
<< false // inverted controls
|
|
744 |
<< 20 // wheel scroll lines
|
|
745 |
<< false // with modifiers
|
|
746 |
<< 1 // delta
|
|
747 |
<< int(Qt::Horizontal) // orientation of slider
|
|
748 |
<< int(Qt::Vertical) // orientation of wheel
|
|
749 |
<< 0 // expected position after
|
|
750 |
<< QPoint(1,1);
|
|
751 |
|
|
752 |
// Scrolling in a slider of a different orientation than the wheel works
|
|
753 |
// if the mouse pointer is within the widget's rect
|
|
754 |
QTest::newRow("Different orientation2")<< 0 // initial position
|
|
755 |
<< 0 // minimum
|
|
756 |
<< 100 // maximum
|
|
757 |
<< 100 // single step
|
|
758 |
<< 1 // page step
|
|
759 |
<< false // inverted controls
|
|
760 |
<< 20 // wheel scroll lines
|
|
761 |
<< false // with modifiers
|
|
762 |
<< 1 // delta
|
|
763 |
<< int(Qt::Horizontal) // orientation of slider
|
|
764 |
<< int(Qt::Vertical) // orientation of wheel
|
|
765 |
<< 1 // expected position after
|
|
766 |
<< QPoint(0,0);
|
|
767 |
|
|
768 |
|
|
769 |
QTest::newRow("Inverted controls") << 50 // initial position
|
|
770 |
<< 0 // minimum
|
|
771 |
<< 100 // maximum
|
|
772 |
<< 1 // single step
|
|
773 |
<< 100 // page step
|
|
774 |
<< true // inverted controls
|
|
775 |
<< 20 // wheel scroll lines
|
|
776 |
<< false // with modifiers
|
|
777 |
<< 1 // delta
|
|
778 |
<< int(Qt::Horizontal) // orientation of slider
|
|
779 |
<< int(Qt::Horizontal) // orientation of wheel
|
|
780 |
#ifdef Q_WS_MAC
|
|
781 |
<< 49 // expected position after
|
|
782 |
#else
|
|
783 |
<< 30 // expected position after
|
|
784 |
#endif
|
|
785 |
<< QPoint(1,1);
|
|
786 |
|
|
787 |
QTest::newRow("Past end") << 50 // initial position
|
|
788 |
<< 0 // minimum
|
|
789 |
<< 100 // maximum
|
|
790 |
<< 26 // single step
|
|
791 |
<< 100 // page step
|
|
792 |
<< false // inverted controls
|
|
793 |
<< 1 // wheel scroll lines
|
|
794 |
<< false // with modifiers
|
|
795 |
#ifdef Q_WS_MAC
|
|
796 |
<< 60 // delta
|
|
797 |
#else
|
|
798 |
<< 2 // delta
|
|
799 |
#endif
|
|
800 |
<< int(Qt::Horizontal) // orientation of slider
|
|
801 |
<< int(Qt::Horizontal) // orientation of wheel
|
|
802 |
<< 100 // expected position after
|
|
803 |
<< QPoint(0,0);
|
|
804 |
|
|
805 |
QTest::newRow("Past start") << 50 // initial position
|
|
806 |
<< 0 // minimum
|
|
807 |
<< 100 // maximum
|
|
808 |
<< 26 // single step
|
|
809 |
<< 100 // page step
|
|
810 |
<< false // inverted controls
|
|
811 |
<< 1 // wheel scroll lines
|
|
812 |
<< false // with modifiers
|
|
813 |
#ifdef Q_WS_MAC
|
|
814 |
<< -60 // delta
|
|
815 |
#else
|
|
816 |
<< -2 // delta
|
|
817 |
#endif
|
|
818 |
<< int(Qt::Horizontal) // orientation of slider
|
|
819 |
<< int(Qt::Horizontal) // orientation of wheel
|
|
820 |
<< 0 // expected position after
|
|
821 |
<< QPoint(0,0);
|
|
822 |
|
|
823 |
QTest::newRow("With modifiers") << 50 // initial position
|
|
824 |
<< 0 // minimum
|
|
825 |
<< 100 // maximum
|
|
826 |
<< 1 // single step
|
|
827 |
<< 40 // page step
|
|
828 |
<< false // inverted controls
|
|
829 |
<< 20 // wheel scroll lines
|
|
830 |
<< true // with modifiers
|
|
831 |
<< 1 // delta
|
|
832 |
<< int(Qt::Horizontal) // orientation of slider
|
|
833 |
<< int(Qt::Horizontal) // orientation of wheel
|
|
834 |
<< 90 // expected position after
|
|
835 |
<< QPoint(0,0);
|
|
836 |
|
|
837 |
}
|
|
838 |
|
|
839 |
void tst_QAbstractSlider::wheelEvent()
|
|
840 |
{
|
|
841 |
QFETCH(int,initialSliderPosition);
|
|
842 |
QFETCH(int,minimum);
|
|
843 |
QFETCH(int,maximum);
|
|
844 |
QFETCH(int,singleStep);
|
|
845 |
QFETCH(int,pageStep);
|
|
846 |
QFETCH(bool,invertedControls);
|
|
847 |
QFETCH(int,wheelScrollLines);
|
|
848 |
QFETCH(bool,withModifiers);
|
|
849 |
QFETCH(int,deltaMultiple);
|
|
850 |
QFETCH(int,sliderOrientation);
|
|
851 |
QFETCH(int,wheelOrientation);
|
|
852 |
QFETCH(int,expectedSliderPosition);
|
|
853 |
QFETCH(QPoint,distanceFromBottomRight);
|
|
854 |
|
|
855 |
QCoreApplication *applicationInstance = QCoreApplication::instance();
|
|
856 |
QVERIFY(applicationInstance != 0);
|
|
857 |
QApplication::setWheelScrollLines(wheelScrollLines);
|
|
858 |
|
|
859 |
Qt::Orientation orientation = *reinterpret_cast<Qt::Orientation*>(&sliderOrientation);
|
|
860 |
slider->setRange(minimum,maximum);
|
|
861 |
slider->setSliderPosition(initialSliderPosition);
|
|
862 |
slider->setSingleStep(singleStep);
|
|
863 |
slider->setPageStep(pageStep);
|
|
864 |
slider->setInvertedControls(invertedControls);
|
|
865 |
slider->setOrientation(orientation);
|
|
866 |
|
|
867 |
Qt::KeyboardModifier k = withModifiers ? Qt::ControlModifier : Qt::NoModifier;
|
|
868 |
orientation = *reinterpret_cast<Qt::Orientation*>(&wheelOrientation);
|
|
869 |
QWheelEvent event(slider->rect().bottomRight() + distanceFromBottomRight, WHEEL_DELTA * deltaMultiple,
|
|
870 |
Qt::NoButton, k, orientation);
|
|
871 |
QVERIFY(applicationInstance->sendEvent(slider,&event));
|
|
872 |
QCOMPARE(slider->sliderPosition(),expectedSliderPosition);
|
|
873 |
|
|
874 |
slider->setSliderPosition(initialSliderPosition);
|
|
875 |
k = withModifiers ? Qt::ShiftModifier : Qt::NoModifier;
|
|
876 |
event = QWheelEvent(slider->rect().bottomRight() + distanceFromBottomRight, WHEEL_DELTA * deltaMultiple,
|
|
877 |
Qt::NoButton, k, orientation);
|
|
878 |
QSignalSpy spy1(slider, SIGNAL(actionTriggered(int)));
|
|
879 |
QSignalSpy spy2(slider, SIGNAL(valueChanged(int)));
|
|
880 |
QVERIFY(applicationInstance->sendEvent(slider,&event));
|
|
881 |
QCOMPARE(slider->sliderPosition(),expectedSliderPosition);
|
|
882 |
int expectedSignalCount = (initialSliderPosition == expectedSliderPosition) ? 0 : 1;
|
|
883 |
QCOMPARE(spy1.count(), expectedSignalCount);
|
|
884 |
QCOMPARE(spy2.count(), expectedSignalCount);
|
|
885 |
if (expectedSignalCount)
|
|
886 |
QVERIFY(actionTriggeredTimeStamp < valueChangedTimeStamp);
|
|
887 |
}
|
|
888 |
|
|
889 |
void tst_QAbstractSlider::sliderPressedReleased_data()
|
|
890 |
{
|
|
891 |
QTest::addColumn<int>("control");
|
|
892 |
QTest::addColumn<int>("minimum");
|
|
893 |
QTest::addColumn<int>("maximum");
|
|
894 |
QTest::addColumn<uint>("subControl");
|
|
895 |
QTest::addColumn<int>("expectedCount");
|
|
896 |
|
|
897 |
QTest::newRow("slider on the handle") << int(QStyle::CC_Slider)
|
|
898 |
<< 0
|
|
899 |
<< 20
|
|
900 |
<< uint(QStyle::SC_SliderHandle)
|
|
901 |
<< 1;
|
|
902 |
|
|
903 |
QTest::newRow("slider on the groove") << int(QStyle::CC_Slider)
|
|
904 |
<< 0
|
|
905 |
<< 20
|
|
906 |
<< uint(QStyle::SC_SliderGroove)
|
|
907 |
<< ((qApp->style()->styleHint(QStyle::SH_Slider_AbsoluteSetButtons) & Qt::LeftButton) ? 1 : 0);
|
|
908 |
|
|
909 |
QTest::newRow("scrollbar on the handle") << int(QStyle::CC_ScrollBar)
|
|
910 |
<< 0
|
|
911 |
<< 20
|
|
912 |
<< uint(QStyle::SC_ScrollBarSlider)
|
|
913 |
<< 1;
|
|
914 |
|
|
915 |
QTest::newRow("scrollbar on the groove") << int(QStyle::CC_ScrollBar)
|
|
916 |
<< 0
|
|
917 |
<< 20
|
|
918 |
<< uint(QStyle::SC_ScrollBarGroove)
|
|
919 |
<< 0;
|
|
920 |
}
|
|
921 |
|
|
922 |
void tst_QAbstractSlider::sliderPressedReleased()
|
|
923 |
{
|
|
924 |
QFETCH(int, control);
|
|
925 |
QFETCH(int, minimum);
|
|
926 |
QFETCH(int, maximum);
|
|
927 |
QFETCH(uint, subControl);
|
|
928 |
QFETCH(int, expectedCount);
|
|
929 |
|
|
930 |
QAbstractSlider *slider;
|
|
931 |
switch (control) {
|
|
932 |
default:
|
|
933 |
qWarning("Bad input into test, leaving");
|
|
934 |
return;
|
|
935 |
break;
|
|
936 |
case QStyle::CC_Slider:
|
|
937 |
slider = new QSlider;
|
|
938 |
slider->setLayoutDirection(Qt::LeftToRight); // Makes "upside down" much easier to compute
|
|
939 |
break;
|
|
940 |
case QStyle::CC_ScrollBar:
|
|
941 |
slider = new QScrollBar;
|
|
942 |
break;
|
|
943 |
}
|
|
944 |
|
|
945 |
|
|
946 |
slider->setMinimum(minimum);
|
|
947 |
slider->setMaximum(maximum);
|
|
948 |
slider->setValue(0);
|
|
949 |
slider->setOrientation(Qt::Vertical);
|
|
950 |
slider->resize(slider->sizeHint().width(), slider->sizeHint().height() + 100);
|
|
951 |
QSignalSpy spy1(slider, SIGNAL(sliderPressed()));
|
|
952 |
QSignalSpy spy2(slider, SIGNAL(sliderReleased()));
|
|
953 |
|
|
954 |
// Mac Style requires the control to be active to get the correct values...
|
|
955 |
slider->show();
|
|
956 |
slider->activateWindow();
|
|
957 |
|
|
958 |
QStyleOptionSlider option;
|
|
959 |
option.init(slider);
|
|
960 |
option.upsideDown = control == QStyle::CC_Slider ? !slider->invertedAppearance()
|
|
961 |
: slider->invertedAppearance();
|
|
962 |
option.subControls = QStyle::SC_None;
|
|
963 |
option.activeSubControls = QStyle::SC_None;
|
|
964 |
option.orientation = slider->orientation();
|
|
965 |
option.maximum = maximum;
|
|
966 |
option.minimum = minimum;
|
|
967 |
option.sliderPosition = slider->value();
|
|
968 |
option.sliderValue = slider->value();
|
|
969 |
option.singleStep = slider->singleStep();
|
|
970 |
option.pageStep = slider->pageStep();
|
|
971 |
QRect rect = slider->style()->subControlRect(QStyle::ComplexControl(control), &option,
|
|
972 |
QStyle::SubControl(subControl), slider);
|
|
973 |
|
|
974 |
QTest::mousePress(slider, Qt::LeftButton, 0, QPoint(rect.center().x() + 2, rect.center().y() + 2));
|
|
975 |
QCOMPARE(spy1.count(), expectedCount);
|
|
976 |
QTest::mouseRelease(slider, Qt::LeftButton, 0, rect.center());
|
|
977 |
QCOMPARE(spy2.count(), expectedCount);
|
|
978 |
|
|
979 |
delete slider;
|
|
980 |
}
|
|
981 |
|
|
982 |
void tst_QAbstractSlider::sliderMoved_data()
|
|
983 |
{
|
|
984 |
QTest::addColumn<int>("control");
|
|
985 |
QTest::addColumn<int>("minimum");
|
|
986 |
QTest::addColumn<int>("maximum");
|
|
987 |
QTest::addColumn<int>("position");
|
|
988 |
QTest::addColumn<bool>("sliderDown");
|
|
989 |
QTest::addColumn<int>("expectedCount");
|
|
990 |
|
|
991 |
QTest::newRow("slider pressed") << int(QStyle::CC_Slider)
|
|
992 |
<< 0
|
|
993 |
<< 20
|
|
994 |
<< 10
|
|
995 |
<< true
|
|
996 |
<< 1;
|
|
997 |
|
|
998 |
QTest::newRow("slider not pressed") << int(QStyle::CC_Slider)
|
|
999 |
<< 0
|
|
1000 |
<< 20
|
|
1001 |
<< 10
|
|
1002 |
<< false
|
|
1003 |
<< 0;
|
|
1004 |
|
|
1005 |
QTest::newRow("scrollbar pressed") << int(QStyle::CC_ScrollBar)
|
|
1006 |
<< 0
|
|
1007 |
<< 20
|
|
1008 |
<< 10
|
|
1009 |
<< true
|
|
1010 |
<< 1;
|
|
1011 |
|
|
1012 |
QTest::newRow("scrollbar not pressed") << int(QStyle::CC_ScrollBar)
|
|
1013 |
<< 0
|
|
1014 |
<< 20
|
|
1015 |
<< 10
|
|
1016 |
<< false
|
|
1017 |
<< 0;
|
|
1018 |
}
|
|
1019 |
|
|
1020 |
void tst_QAbstractSlider::sliderMoved()
|
|
1021 |
{
|
|
1022 |
QFETCH(int, control);
|
|
1023 |
QFETCH(int, minimum);
|
|
1024 |
QFETCH(int, maximum);
|
|
1025 |
QFETCH(int, position);
|
|
1026 |
QFETCH(bool, sliderDown);
|
|
1027 |
QFETCH(int, expectedCount);
|
|
1028 |
QAbstractSlider *slider;
|
|
1029 |
switch (control) {
|
|
1030 |
default:
|
|
1031 |
slider = 0;
|
|
1032 |
break;
|
|
1033 |
case QStyle::CC_Slider:
|
|
1034 |
slider = new QSlider;
|
|
1035 |
break;
|
|
1036 |
case QStyle::CC_ScrollBar:
|
|
1037 |
slider = new QScrollBar;
|
|
1038 |
break;
|
|
1039 |
}
|
|
1040 |
QSignalSpy spy(slider, SIGNAL(sliderMoved(int)));
|
|
1041 |
|
|
1042 |
slider->setMinimum(minimum);
|
|
1043 |
slider->setMaximum(maximum);
|
|
1044 |
slider->setSliderDown(sliderDown);
|
|
1045 |
slider->setSliderPosition(position);
|
|
1046 |
QCOMPARE(spy.count(), expectedCount);
|
|
1047 |
|
|
1048 |
delete slider;
|
|
1049 |
}
|
|
1050 |
|
|
1051 |
void tst_QAbstractSlider::setOrientation()
|
|
1052 |
{
|
|
1053 |
QSlider slider(0);
|
|
1054 |
|
|
1055 |
QSizePolicy sp = slider.sizePolicy();
|
|
1056 |
slider.setOrientation(slider.orientation());
|
|
1057 |
QSizePolicy sp2 = slider.sizePolicy();
|
|
1058 |
QCOMPARE(sp, sp2);
|
|
1059 |
|
|
1060 |
slider.setOrientation(Qt::Horizontal);
|
|
1061 |
sp = slider.sizePolicy();
|
|
1062 |
slider.setOrientation(Qt::Vertical);
|
|
1063 |
sp2 = slider.sizePolicy();
|
|
1064 |
|
|
1065 |
QVERIFY(sp != sp2);
|
|
1066 |
sp2.transpose();
|
|
1067 |
QCOMPARE(sp, sp2);
|
|
1068 |
}
|
|
1069 |
|
|
1070 |
|
|
1071 |
void tst_QAbstractSlider::rangeChanged_data()
|
|
1072 |
{
|
|
1073 |
QTest::addColumn<int>("minimum");
|
|
1074 |
QTest::addColumn<int>("maximum");
|
|
1075 |
QTest::addColumn<int>("newMin");
|
|
1076 |
QTest::addColumn<int>("newMax");
|
|
1077 |
QTest::addColumn<int>("expectedCount");
|
|
1078 |
|
|
1079 |
QTest::newRow("no change")
|
|
1080 |
<< 0
|
|
1081 |
<< 20
|
|
1082 |
<< 0
|
|
1083 |
<< 20
|
|
1084 |
<< 0;
|
|
1085 |
|
|
1086 |
QTest::newRow("min change")
|
|
1087 |
<< 0
|
|
1088 |
<< 20
|
|
1089 |
<< 10
|
|
1090 |
<< 20
|
|
1091 |
<< 1;
|
|
1092 |
QTest::newRow("max change")
|
|
1093 |
<< 0
|
|
1094 |
<< 20
|
|
1095 |
<< 0
|
|
1096 |
<< 30
|
|
1097 |
<< 1;
|
|
1098 |
|
|
1099 |
QTest::newRow("both change")
|
|
1100 |
<< 0
|
|
1101 |
<< 20
|
|
1102 |
<< 10
|
|
1103 |
<< 30
|
|
1104 |
<< 1;
|
|
1105 |
}
|
|
1106 |
|
|
1107 |
void tst_QAbstractSlider::rangeChanged()
|
|
1108 |
{
|
|
1109 |
QFETCH(int, minimum);
|
|
1110 |
QFETCH(int, maximum);
|
|
1111 |
QFETCH(int, newMin);
|
|
1112 |
QFETCH(int, newMax);
|
|
1113 |
QFETCH(int, expectedCount);
|
|
1114 |
QSlider slider;
|
|
1115 |
slider.setRange(minimum, maximum);
|
|
1116 |
QSignalSpy spy(&slider, SIGNAL(rangeChanged(int, int)));
|
|
1117 |
slider.setRange(newMin, newMax);
|
|
1118 |
QCOMPARE(spy.count(), expectedCount);
|
|
1119 |
}
|
|
1120 |
|
|
1121 |
void tst_QAbstractSlider::setSliderPosition_data()
|
|
1122 |
{
|
|
1123 |
QTest::addColumn<bool>("tracking");
|
|
1124 |
QTest::addColumn<bool>("down");
|
|
1125 |
|
|
1126 |
QTest::newRow("tracking, slider down")
|
|
1127 |
<< true
|
|
1128 |
<< true;
|
|
1129 |
QTest::newRow("tracking, slider not down")
|
|
1130 |
<< true
|
|
1131 |
<< false;
|
|
1132 |
QTest::newRow("no tracking, slider down")
|
|
1133 |
<< false
|
|
1134 |
<< true;
|
|
1135 |
QTest::newRow("no tracking, slider not down")
|
|
1136 |
<< false
|
|
1137 |
<< false;
|
|
1138 |
}
|
|
1139 |
|
|
1140 |
void tst_QAbstractSlider::setSliderPosition()
|
|
1141 |
{
|
|
1142 |
QFETCH(bool, tracking);
|
|
1143 |
QFETCH(bool, down);
|
|
1144 |
const int minimum = 0;
|
|
1145 |
const int maximum = 100;
|
|
1146 |
const int initialValue = 50;
|
|
1147 |
const int targetPosition = 75;
|
|
1148 |
slider->setRange(minimum, maximum);
|
|
1149 |
slider->setTracking(tracking);
|
|
1150 |
slider->setSliderDown(down);
|
|
1151 |
slider->setValue(initialValue);
|
|
1152 |
QCOMPARE(slider->sliderPosition(), initialValue);
|
|
1153 |
QSignalSpy spy1(slider, SIGNAL(sliderMoved(int)));
|
|
1154 |
QSignalSpy spy2(slider, SIGNAL(valueChanged(int)));
|
|
1155 |
slider->setSliderPosition(targetPosition);
|
|
1156 |
QCOMPARE(slider->sliderPosition(), targetPosition);
|
|
1157 |
QCOMPARE(spy1.count(), down ? 1 : 0);
|
|
1158 |
QCOMPARE(spy2.count(), tracking ? 1 : 0);
|
|
1159 |
QCOMPARE(slider->value(), tracking ? targetPosition : initialValue);
|
|
1160 |
if (tracking && down)
|
|
1161 |
QVERIFY(sliderMovedTimeStamp < valueChangedTimeStamp);
|
|
1162 |
}
|
|
1163 |
|
|
1164 |
void tst_QAbstractSlider::setValue_data()
|
|
1165 |
{
|
|
1166 |
QTest::addColumn<bool>("down");
|
|
1167 |
|
|
1168 |
QTest::newRow("slider down")
|
|
1169 |
<< true;
|
|
1170 |
QTest::newRow("slider not down")
|
|
1171 |
<< false;
|
|
1172 |
}
|
|
1173 |
|
|
1174 |
void tst_QAbstractSlider::setValue()
|
|
1175 |
{
|
|
1176 |
QFETCH(bool, down);
|
|
1177 |
const int minimum = 0;
|
|
1178 |
const int maximum = 100;
|
|
1179 |
slider->setRange(minimum, maximum);
|
|
1180 |
slider->setSliderDown(down);
|
|
1181 |
slider->setValue(49); // to force a valueChanged() below
|
|
1182 |
QSignalSpy spy1(slider, SIGNAL(sliderMoved(int)));
|
|
1183 |
QSignalSpy spy2(slider, SIGNAL(valueChanged(int)));
|
|
1184 |
QSignalSpy spy3(slider, SIGNAL(actionTriggered(int)));
|
|
1185 |
slider->setValue(50);
|
|
1186 |
QCOMPARE(spy1.count(), down ? 1 : 0);
|
|
1187 |
QCOMPARE(spy2.count(), 1);
|
|
1188 |
QCOMPARE(spy3.count(), 0);
|
|
1189 |
QCOMPARE(slider->value(), reportedValue);
|
|
1190 |
QCOMPARE(slider->sliderPosition(), reportedSliderPosition);
|
|
1191 |
if (down)
|
|
1192 |
QVERIFY(sliderMovedTimeStamp < valueChangedTimeStamp);
|
|
1193 |
}
|
|
1194 |
|
|
1195 |
void tst_QAbstractSlider::waitUntilTimeElapsed(const QTime& t, int ms)
|
|
1196 |
{
|
|
1197 |
const int eps = 80;
|
|
1198 |
while (t.elapsed() < ms + eps)
|
|
1199 |
QTest::qWait(qMax(ms - t.elapsed() + eps, 25));
|
|
1200 |
}
|
|
1201 |
|
|
1202 |
void tst_QAbstractSlider::setRepeatAction()
|
|
1203 |
{
|
|
1204 |
slider->setRange(0, 1000);
|
|
1205 |
slider->setValue(55);
|
|
1206 |
slider->setPageStep(10);
|
|
1207 |
QSignalSpy spy(slider, SIGNAL(actionTriggered(int)));
|
|
1208 |
|
|
1209 |
// Start repeat action with initial delay of 500 ms, and then repeating
|
|
1210 |
// every 250 ms.
|
|
1211 |
slider->setRepeatAction(QAbstractSlider::SliderPageStepAdd, 500, 250);
|
|
1212 |
QCOMPARE(spy.count(), 0);
|
|
1213 |
QCOMPARE(slider->value(), 55);
|
|
1214 |
|
|
1215 |
QTime t;
|
|
1216 |
t.start();
|
|
1217 |
QTest::qWait(300);
|
|
1218 |
QCOMPARE(spy.count(), 0);
|
|
1219 |
QCOMPARE(slider->value(), 55);
|
|
1220 |
|
|
1221 |
waitUntilTimeElapsed(t, 550);
|
|
1222 |
QCOMPARE(spy.count(), 1);
|
|
1223 |
QCOMPARE(slider->value(), 65);
|
|
1224 |
QCOMPARE(spy.at(0).at(0).toUInt(), (uint)QAbstractSlider::SliderPageStepAdd);
|
|
1225 |
|
|
1226 |
waitUntilTimeElapsed(t, 790);
|
|
1227 |
QCOMPARE(spy.count(), 2);
|
|
1228 |
QCOMPARE(slider->value(), 75);
|
|
1229 |
QCOMPARE(spy.at(1).at(0).toUInt(), (uint)QAbstractSlider::SliderPageStepAdd);
|
|
1230 |
|
|
1231 |
waitUntilTimeElapsed(t, 1790);
|
|
1232 |
QCOMPARE(spy.count(), 6);
|
|
1233 |
QCOMPARE(slider->value(), 115);
|
|
1234 |
QCOMPARE(spy.at(4).at(0).toUInt(), (uint)QAbstractSlider::SliderPageStepAdd);
|
|
1235 |
QCOMPARE(spy.at(5).at(0).toUInt(), (uint)QAbstractSlider::SliderPageStepAdd);
|
|
1236 |
|
|
1237 |
slider->setRepeatAction(QAbstractSlider::SliderNoAction);
|
|
1238 |
QCOMPARE(spy.count(), 6);
|
|
1239 |
QCOMPARE(slider->value(), 115);
|
|
1240 |
|
|
1241 |
QTest::qWait(300);
|
|
1242 |
QCOMPARE(spy.count(), 6);
|
|
1243 |
QCOMPARE(slider->value(), 115);
|
|
1244 |
}
|
|
1245 |
|
|
1246 |
QTEST_MAIN(tst_QAbstractSlider)
|
|
1247 |
#include "tst_qabstractslider.moc"
|