| 1 |
/**************************************************************************** |
| 2 |
** |
| 3 |
** Copyright (C) 2012 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 |
** GNU Lesser General Public License Usage |
| 11 |
** This file may be used under the terms of the GNU Lesser General Public |
| 12 |
** License version 2.1 as published by the Free Software Foundation and |
| 13 |
** appearing in the file LICENSE.LGPL included in the packaging of this |
| 14 |
** file. Please review the following information to ensure the GNU Lesser |
| 15 |
** General Public License version 2.1 requirements will be met: |
| 16 |
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
| 17 |
** |
| 18 |
** In addition, as a special exception, Nokia gives you certain additional |
| 19 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
| 20 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
| 21 |
** |
| 22 |
** GNU General Public License Usage |
| 23 |
** Alternatively, this file may be used under the terms of the GNU General |
| 24 |
** Public License version 3.0 as published by the Free Software Foundation |
| 25 |
** and appearing in the file LICENSE.GPL included in the packaging of this |
| 26 |
** file. Please review the following information to ensure the GNU General |
| 27 |
** Public License version 3.0 requirements will be met: |
| 28 |
** http://www.gnu.org/copyleft/gpl.html. |
| 29 |
** |
| 30 |
** Other Usage |
| 31 |
** Alternatively, this file may be used in accordance with the terms and |
| 32 |
** conditions contained in a signed written agreement between you and Nokia. |
| 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 |
Slider(QWidget *parent) |
| 59 |
: QAbstractSlider(parent) {} |
| 60 |
using QAbstractSlider::setRepeatAction; |
| 61 |
using QAbstractSlider::repeatAction; |
| 62 |
}; |
| 63 |
|
| 64 |
class tst_QAbstractSlider: public QObject |
| 65 |
{ |
| 66 |
Q_OBJECT |
| 67 |
public slots: |
| 68 |
void initTestCase(); |
| 69 |
void cleanupTestCase(); |
| 70 |
void actionTriggered(int action); |
| 71 |
void rangeChanged(int min, int max); |
| 72 |
void valueChanged(int value); |
| 73 |
void sliderMoved(int value); |
| 74 |
|
| 75 |
private slots: |
| 76 |
void triggerAction_data(); |
| 77 |
void triggerAction(); |
| 78 |
void minimum_maximum_data(); |
| 79 |
void minimum_maximum(); |
| 80 |
void keyPressed_data(); |
| 81 |
void keyPressed(); |
| 82 |
void wheelEvent_data(); |
| 83 |
void wheelEvent(); |
| 84 |
void sliderPressedReleased_data(); |
| 85 |
void sliderPressedReleased(); |
| 86 |
void setOrientation(); |
| 87 |
void sliderMoved_data(); |
| 88 |
void sliderMoved(); |
| 89 |
void rangeChanged_data(); |
| 90 |
void rangeChanged(); |
| 91 |
void setSliderPosition_data(); |
| 92 |
void setSliderPosition(); |
| 93 |
void setValue_data(); |
| 94 |
void setValue(); |
| 95 |
void setRepeatAction(); |
| 96 |
|
| 97 |
private: |
| 98 |
void waitUntilTimeElapsed(const QTime& t, int ms); |
| 99 |
|
| 100 |
QWidget *topLevel; |
| 101 |
Slider *slider; |
| 102 |
int previousAction; |
| 103 |
int reportedMinimum; |
| 104 |
int reportedMaximum; |
| 105 |
int reportedValue; |
| 106 |
int reportedSliderPosition; |
| 107 |
qint64 timeStamp; |
| 108 |
qint64 actionTriggeredTimeStamp; |
| 109 |
qint64 valueChangedTimeStamp; |
| 110 |
qint64 rangeChangedTimeStamp; |
| 111 |
qint64 sliderMovedTimeStamp; |
| 112 |
}; |
| 113 |
|
| 114 |
Q_DECLARE_METATYPE(QList<Qt::Key>) |
| 115 |
Q_DECLARE_METATYPE(QPoint) |
| 116 |
|
| 117 |
void tst_QAbstractSlider::initTestCase() |
| 118 |
{ |
| 119 |
topLevel = new QWidget; |
| 120 |
slider = new Slider(topLevel); |
| 121 |
slider->setObjectName("testWidget"); |
| 122 |
slider->resize(100,100); |
| 123 |
slider->show(); |
| 124 |
|
| 125 |
previousAction = QAbstractSlider::SliderNoAction; |
| 126 |
timeStamp = 0; |
| 127 |
|
| 128 |
connect(slider,SIGNAL(actionTriggered(int)),this,SLOT(actionTriggered(int))); |
| 129 |
connect(slider,SIGNAL(rangeChanged(int,int)),this,SLOT(rangeChanged(int,int))); |
| 130 |
connect(slider,SIGNAL(valueChanged(int)),this,SLOT(valueChanged(int))); |
| 131 |
connect(slider,SIGNAL(sliderMoved(int)),this,SLOT(sliderMoved(int))); |
| 132 |
} |
| 133 |
|
| 134 |
void tst_QAbstractSlider::cleanupTestCase() |
| 135 |
{ |
| 136 |
delete topLevel; |
| 137 |
} |
| 138 |
|
| 139 |
void tst_QAbstractSlider::actionTriggered(int action) |
| 140 |
{ |
| 141 |
previousAction = action; |
| 142 |
actionTriggeredTimeStamp = timeStamp++; |
| 143 |
} |
| 144 |
|
| 145 |
void tst_QAbstractSlider::rangeChanged(int min,int max) |
| 146 |
{ |
| 147 |
reportedMinimum = min; |
| 148 |
reportedMaximum = max; |
| 149 |
rangeChangedTimeStamp = timeStamp++; |
| 150 |
} |
| 151 |
|
| 152 |
void tst_QAbstractSlider::valueChanged(int value) |
| 153 |
{ |
| 154 |
reportedValue = value; |
| 155 |
valueChangedTimeStamp = timeStamp++; |
| 156 |
} |
| 157 |
|
| 158 |
void tst_QAbstractSlider::sliderMoved(int value) |
| 159 |
{ |
| 160 |
reportedSliderPosition = value; |
| 161 |
sliderMovedTimeStamp = timeStamp++; |
| 162 |
} |
| 163 |
|
| 164 |
void tst_QAbstractSlider::triggerAction_data() |
| 165 |
{ |
| 166 |
QTest::addColumn<int>("sliderAction"); |
| 167 |
QTest::addColumn<int>("maximum"); |
| 168 |
QTest::addColumn<int>("minimum"); |
| 169 |
QTest::addColumn<int>("initialSliderPosition"); |
| 170 |
QTest::addColumn<int>("singleStep"); |
| 171 |
QTest::addColumn<int>("pageStep"); |
| 172 |
QTest::addColumn<int>("expectedSliderPosition"); |
| 173 |
|
| 174 |
QTest::newRow("No action") << int(QAbstractSlider::SliderNoAction) // sliderAction |
| 175 |
<< 1000 // max |
| 176 |
<< 900 // min |
| 177 |
<< 987 // initial position |
| 178 |
<< 237 // single step size |
| 179 |
<< 234 // page step size |
| 180 |
<< 987; // expected position after |
| 181 |
|
| 182 |
QTest::newRow("Move action") << int(QAbstractSlider::SliderMove) // sliderAction |
| 183 |
<< 1000 // max |
| 184 |
<< 900 // min |
| 185 |
<< 988 // initial position |
| 186 |
<< 237 // single step size |
| 187 |
<< 234 // page step size |
| 188 |
<< 988; // expected position after |
| 189 |
|
| 190 |
QTest::newRow("Empty step add") << int(QAbstractSlider::SliderSingleStepAdd) // sliderAction |
| 191 |
<< 1000 // max |
| 192 |
<< 900 // min |
| 193 |
<< 988 // initial position |
| 194 |
<< 0 // single step size |
| 195 |
<< 234 // page step size |
| 196 |
<< 988; // expected position after |
| 197 |
|
| 198 |
QTest::newRow("Empty step sub") << int(QAbstractSlider::SliderSingleStepSub) // sliderAction |
| 199 |
<< 1000 // max |
| 200 |
<< 900 // min |
| 201 |
<< 987 // initial position |
| 202 |
<< 0 // single step size |
| 203 |
<< 234 // page step size |
| 204 |
<< 987; // expected position after |
| 205 |
|
| 206 |
QTest::newRow("Empty page add") << int(QAbstractSlider::SliderPageStepAdd) // sliderAction |
| 207 |
<< 1000 // max |
| 208 |
<< 900 // min |
| 209 |
<< 988 // initial position |
| 210 |
<< 234 // single step size |
| 211 |
<< 0 // page step size |
| 212 |
<< 988; // expected position after |
| 213 |
|
| 214 |
QTest::newRow("Empty page sub") << int(QAbstractSlider::SliderPageStepSub) // sliderAction |
| 215 |
<< 1000 // max |
| 216 |
<< 900 // min |
| 217 |
<< 987 // initial position |
| 218 |
<< 234 // single step size |
| 219 |
<< 0 // page step size |
| 220 |
<< 987; // expected position after |
| 221 |
|
| 222 |
QTest::newRow("Legal step add") << int(QAbstractSlider::SliderSingleStepAdd) // sliderAction |
| 223 |
<< 1000 // max |
| 224 |
<< 900 // min |
| 225 |
<< 988 // initial position |
| 226 |
<< 5 // single step size |
| 227 |
<< 234 // page step size |
| 228 |
<< 993; // expected position after |
| 229 |
|
| 230 |
QTest::newRow("Legal step sub") << int(QAbstractSlider::SliderSingleStepSub) // sliderAction |
| 231 |
<< 1000 // max |
| 232 |
<< 900 // min |
| 233 |
<< 987 // initial position |
| 234 |
<< 5 // single step size |
| 235 |
<< 234 // page step size |
| 236 |
<< 982; // expected position after |
| 237 |
|
| 238 |
QTest::newRow("Legal page add") << int(QAbstractSlider::SliderPageStepAdd) // sliderAction |
| 239 |
<< 1000 // max |
| 240 |
<< 900 // min |
| 241 |
<< 988 // initial position |
| 242 |
<< 234 // single step size |
| 243 |
<< 5 // page step size |
| 244 |
<< 993; // expected position after |
| 245 |
|
| 246 |
QTest::newRow("Legal page sub") << int(QAbstractSlider::SliderPageStepSub) // sliderAction |
| 247 |
<< 1000 // max |
| 248 |
<< 900 // min |
| 249 |
<< 987 // initial position |
| 250 |
<< 234 // single step size |
| 251 |
<< 5 // page step size |
| 252 |
<< 982; // expected position after |
| 253 |
|
| 254 |
QTest::newRow("Illegal step add") << int(QAbstractSlider::SliderSingleStepAdd) // sliderAction |
| 255 |
<< 1000 // max |
| 256 |
<< 900 // min |
| 257 |
<< 988 // initial position |
| 258 |
<< 500 // single step size |
| 259 |
<< 234 // page step size |
| 260 |
<< 1000; // expected position after |
| 261 |
|
| 262 |
QTest::newRow("Illegal step sub") << int(QAbstractSlider::SliderSingleStepSub) // sliderAction |
| 263 |
<< 1000 // max |
| 264 |
<< 900 // min |
| 265 |
<< 987 // initial position |
| 266 |
<< 500 // single step size |
| 267 |
<< 234 // page step size |
| 268 |
<< 900; // expected position after |
| 269 |
|
| 270 |
QTest::newRow("Illegal page add") << int(QAbstractSlider::SliderPageStepAdd) // sliderAction |
| 271 |
<< 1000 // max |
| 272 |
<< 900 // min |
| 273 |
<< 988 // initial position |
| 274 |
<< 234 // single step size |
| 275 |
<< 500 // page step size |
| 276 |
<< 1000; // expected position after |
| 277 |
|
| 278 |
QTest::newRow("Illegal page sub") << int(QAbstractSlider::SliderPageStepSub) // sliderAction |
| 279 |
<< 1000 // max |
| 280 |
<< 900 // min |
| 281 |
<< 987 // initial position |
| 282 |
<< 234 // single step size |
| 283 |
<< 500 // page step size |
| 284 |
<< 900; // expected position after |
| 285 |
|
| 286 |
// Negative steps will also be abs()'d so, check that case. |
| 287 |
QTest::newRow("Negative step add") << int(QAbstractSlider::SliderSingleStepAdd) // sliderAction |
| 288 |
<< 1000 // max |
| 289 |
<< 900 // min |
| 290 |
<< 988 // initial position |
| 291 |
<< -1 // single step size |
| 292 |
<< 234 // page step size |
| 293 |
<< 989; // expected position after |
| 294 |
|
| 295 |
QTest::newRow("Negative step sub") << int(QAbstractSlider::SliderSingleStepSub) // sliderAction |
| 296 |
<< 1000 // max |
| 297 |
<< 900 // min |
| 298 |
<< 987 // initial position |
| 299 |
<< -1 // single step size |
| 300 |
<< 234 // page step size |
| 301 |
<< 986; // expected position after |
| 302 |
|
| 303 |
QTest::newRow("Negative page add") << int(QAbstractSlider::SliderPageStepAdd) // sliderAction |
| 304 |
<< 1000 // max |
| 305 |
<< 900 // min |
| 306 |
<< 988 // initial position |
| 307 |
<< 234 // single step size |
| 308 |
<< -1 // page step size |
| 309 |
<< 989; // expected position after |
| 310 |
|
| 311 |
QTest::newRow("Negative page sub") << int(QAbstractSlider::SliderPageStepSub) // sliderAction |
| 312 |
<< 1000 // max |
| 313 |
<< 900 // min |
| 314 |
<< 987 // initial position |
| 315 |
<< 234 // single step size |
| 316 |
<< -1 // page step size |
| 317 |
<< 986; // expected position after |
| 318 |
|
| 319 |
QTest::newRow("Illegal negative step add") << int(QAbstractSlider::SliderSingleStepAdd) // sliderAction |
| 320 |
<< 1000 // max |
| 321 |
<< 900 // min |
| 322 |
<< 988 // initial position |
| 323 |
<< -500 // single step size |
| 324 |
<< 234 // page step size |
| 325 |
<< 1000; // expected position after |
| 326 |
|
| 327 |
|
| 328 |
QTest::newRow("Illegal negative step sub") << int(QAbstractSlider::SliderSingleStepSub) // sliderAction |
| 329 |
<< 1000 // max |
| 330 |
<< 900 // min |
| 331 |
<< 988 // initial position |
| 332 |
<< -500 // single step size |
| 333 |
<< 234 // page step size |
| 334 |
<< 900; // expected position after |
| 335 |
|
| 336 |
QTest::newRow("Illegal negative page add") << int(QAbstractSlider::SliderPageStepAdd) // sliderAction |
| 337 |
<< 1000 // max |
| 338 |
<< 900 // min |
| 339 |
<< 988 // initial position |
| 340 |
<< 234 // single step size |
| 341 |
<< -500 // page step size |
| 342 |
<< 1000; // expected position after |
| 343 |
|
| 344 |
QTest::newRow("Illegal negative page sub") << int(QAbstractSlider::SliderPageStepSub) // sliderAction |
| 345 |
<< 1000 // max |
| 346 |
<< 900 // min |
| 347 |
<< 988 // initial position |
| 348 |
<< 245 // single step size |
| 349 |
<< -500 // page step size |
| 350 |
<< 900; // expected position after |
| 351 |
|
| 352 |
QTest::newRow("Slider to minimum") << int(QAbstractSlider::SliderToMinimum) // sliderAction |
| 353 |
<< 1000 // max |
| 354 |
<< 900 // min |
| 355 |
<< 988 // initial position |
| 356 |
<< 245 // single step size |
| 357 |
<< 1 // page step size |
| 358 |
<< 900; // expected position after |
| 359 |
|
| 360 |
QTest::newRow("Slider to maximum") << int(QAbstractSlider::SliderToMaximum) // sliderAction |
| 361 |
<< 1000 // max |
| 362 |
<< 900 // min |
| 363 |
<< 988 // initial position |
| 364 |
<< 245 // single step size |
| 365 |
<< 1 // page step size |
| 366 |
<< 1000; // expected position after |
| 367 |
|
| 368 |
} |
| 369 |
|
| 370 |
void tst_QAbstractSlider::triggerAction() |
| 371 |
{ |
| 372 |
QFETCH(int,sliderAction); |
| 373 |
QFETCH(int,maximum); |
| 374 |
QFETCH(int,minimum); |
| 375 |
QFETCH(int,initialSliderPosition); |
| 376 |
QFETCH(int,singleStep); |
| 377 |
QFETCH(int,pageStep); |
| 378 |
QFETCH(int,expectedSliderPosition); |
| 379 |
|
| 380 |
slider->setTracking(true); |
| 381 |
slider->setRange(minimum,maximum); |
| 382 |
slider->setSingleStep(singleStep); |
| 383 |
slider->setPageStep(pageStep); |
| 384 |
QCOMPARE(slider->singleStep(), qAbs(singleStep)); |
| 385 |
QCOMPARE(slider->pageStep(), qAbs(pageStep)); |
| 386 |
|
| 387 |
int oldPosition = slider->sliderPosition(); |
| 388 |
slider->setSliderPosition(initialSliderPosition); |
| 389 |
|
| 390 |
QVERIFY( (oldPosition == initialSliderPosition && previousAction == int(QAbstractSlider::SliderNoAction)) || |
| 391 |
(oldPosition != initialSliderPosition && previousAction == int(QAbstractSlider::SliderMove))); |
| 392 |
previousAction = int(QAbstractSlider::SliderNoAction); |
| 393 |
|
| 394 |
QAbstractSlider::SliderAction *action = reinterpret_cast<QAbstractSlider::SliderAction*>(&sliderAction); |
| 395 |
QVERIFY(action != 0); |
| 396 |
|
| 397 |
slider->triggerAction(*action); |
| 398 |
QCOMPARE(previousAction,sliderAction); // previousAction set in the actionTriggered() slot |
| 399 |
QCOMPARE(slider->sliderPosition(),expectedSliderPosition); |
| 400 |
QCOMPARE(slider->value(),expectedSliderPosition); |
| 401 |
QCOMPARE(reportedValue,expectedSliderPosition); |
| 402 |
previousAction = int(QAbstractSlider::SliderNoAction); |
| 403 |
if (initialSliderPosition != expectedSliderPosition) |
| 404 |
QVERIFY(actionTriggeredTimeStamp < valueChangedTimeStamp); |
| 405 |
} |
| 406 |
|
| 407 |
void tst_QAbstractSlider::minimum_maximum_data() |
| 408 |
{ |
| 409 |
QTest::addColumn<int>("minimum"); |
| 410 |
QTest::addColumn<int>("maximum"); |
| 411 |
QTest::addColumn<int>("expectedMinimum"); |
| 412 |
QTest::addColumn<int>("expectedMaximum"); |
| 413 |
|
| 414 |
QTest::newRow("Normal range") << 100 << 200 << 100 << 200; |
| 415 |
QTest::newRow("Minimum higher") << 100 << 0 << 100 << 100; |
| 416 |
QTest::newRow("Negative minimum") << -100 << 100 << -100 << 100; |
| 417 |
QTest::newRow("Negative range") << -100 << -50 << -100 << -50; |
| 418 |
} |
| 419 |
|
| 420 |
void tst_QAbstractSlider::minimum_maximum() |
| 421 |
{ |
| 422 |
QFETCH(int, minimum); |
| 423 |
QFETCH(int, maximum); |
| 424 |
QFETCH(int, expectedMinimum); |
| 425 |
QFETCH(int, expectedMaximum); |
| 426 |
|
| 427 |
slider->setRange(minimum,maximum); |
| 428 |
QCOMPARE(slider->minimum(),expectedMinimum); |
| 429 |
QCOMPARE(slider->maximum(),expectedMaximum); |
| 430 |
QCOMPARE(reportedMinimum,expectedMinimum); |
| 431 |
QCOMPARE(reportedMaximum,expectedMaximum); |
| 432 |
|
| 433 |
slider->setRange(minimum,maximum); |
| 434 |
slider->setMaximum(slider->minimum() - 1); |
| 435 |
QCOMPARE(slider->maximum(),slider->minimum()); |
| 436 |
QCOMPARE(reportedMinimum,slider->minimum()); |
| 437 |
QCOMPARE(reportedMaximum,slider->maximum()); |
| 438 |
|
| 439 |
slider->setRange(minimum,maximum); |
| 440 |
slider->setMinimum(slider->maximum() + 1); |
| 441 |
QCOMPARE(slider->minimum(),slider->maximum()); |
| 442 |
QCOMPARE(reportedMinimum,slider->minimum()); |
| 443 |
QCOMPARE(reportedMaximum,slider->maximum()); |
| 444 |
|
| 445 |
slider->setRange(minimum,maximum); |
| 446 |
slider->setSliderPosition(slider->maximum() + 1); |
| 447 |
QCOMPARE(slider->sliderPosition(), slider->maximum()); |
| 448 |
QCOMPARE(slider->value(), slider->maximum()); |
| 449 |
QCOMPARE(reportedValue, slider->maximum()); |
| 450 |
|
| 451 |
slider->setRange(minimum,maximum); |
| 452 |
slider->setSliderPosition(slider->minimum() - 1); |
| 453 |
QCOMPARE(slider->sliderPosition(), slider->minimum()); |
| 454 |
QCOMPARE(slider->value(), slider->minimum()); |
| 455 |
QCOMPARE(reportedValue, slider->minimum()); |
| 456 |
|
| 457 |
slider->setRange(minimum,maximum); |
| 458 |
int oldPosition = slider->sliderPosition(); |
| 459 |
slider->setMaximum(oldPosition - 1); |
| 460 |
QCOMPARE(slider->sliderPosition(),oldPosition - 1); |
| 461 |
|
| 462 |
slider->setRange(minimum,maximum); |
| 463 |
oldPosition = slider->sliderPosition(); |
| 464 |
slider->setMinimum(oldPosition + 1); |
| 465 |
QCOMPARE(slider->sliderPosition(), oldPosition + 1); |
| 466 |
} |
| 467 |
|
| 468 |
void tst_QAbstractSlider::keyPressed_data() |
| 469 |
{ |
| 470 |
QTest::addColumn<int>("initialSliderPosition"); |
| 471 |
QTest::addColumn<int>("minimum"); |
| 472 |
QTest::addColumn<int>("maximum"); |
| 473 |
QTest::addColumn<int>("stepSize"); |
| 474 |
QTest::addColumn<int>("pageSize"); |
| 475 |
QTest::addColumn<QList<Qt::Key> >("keySequence"); |
| 476 |
QTest::addColumn<int>("expectedSliderPositionHorizontal"); |
| 477 |
QTest::addColumn<int>("expectedSliderPositionVertical"); |
| 478 |
QTest::addColumn<int>("expectedSliderPositionHorizontalInverted"); // :) |
| 479 |
QTest::addColumn<int>("expectedSliderPositionVerticalInverted"); |
| 480 |
|
| 481 |
|
| 482 |
QList<Qt::Key> list; |
| 483 |
|
| 484 |
list << Qt::Key_Down; |
| 485 |
QTest::newRow("Step down once") << 10 // initial position |
| 486 |
<< 0 // minimum |
| 487 |
<< 100 // maximum |
| 488 |
<< 3 // single step size |
| 489 |
<< 0 // page step size |
| 490 |
<< list // key sequence |
| 491 |
<< 7 // result in case of horizontal slider |
| 492 |
<< 7 // result in case of vertical slider |
| 493 |
<< 13 // result in case of inverted horiz. slider |
| 494 |
<< 13; // result in case of inverted vertical slider |
| 495 |
|
| 496 |
list = QList<Qt::Key>(); |
| 497 |
list << Qt::Key_Up; |
| 498 |
QTest::newRow("Step down once") << 10 // initial position |
| 499 |
<< 0 // minimum |
| 500 |
<< 100 // maximum |
| 501 |
<< 3 // single step size |
| 502 |
<< 0 // page step size |
| 503 |
<< list // key sequence |
| 504 |
<< 13 // result in case of horizontal slider |
| 505 |
<< 13 // result in case of vertical slider |
| 506 |
<< 7 // result in case of inverted horiz. slider |
| 507 |
<< 7; // result in case of inverted vertical slider |
| 508 |
|
| 509 |
|
| 510 |
list = QList<Qt::Key>(); |
| 511 |
list << Qt::Key_Left; |
| 512 |
QTest::newRow("Step left once") << 10 // initial position |
| 513 |
<< 0 // minimum |
| 514 |
<< 100 // maximum |
| 515 |
<< 3 // single step size |
| 516 |
<< 0 // page step size |
| 517 |
<< list // key sequence |
| 518 |
<< 7 // result in case of horizontal slider |
| 519 |
<< 7 // result in case of vertical slider |
| 520 |
<< 13 // result in case of inverted horiz. slider |
| 521 |
<< 13; // result in case of inverted vertical slider |
| 522 |
|
| 523 |
list = QList<Qt::Key>(); |
| 524 |
list << Qt::Key_Right; |
| 525 |
QTest::newRow("Step right once") << 10 // initial position |
| 526 |
<< 0 // minimum |
| 527 |
<< 100 // maximum |
| 528 |
<< 3 // single step size |
| 529 |
<< 0 // page step size |
| 530 |
<< list // key sequence |
| 531 |
<< 13 // result in case of horizontal slider |
| 532 |
<< 13 // result in case of vertical slider |
| 533 |
<< 7 // result in case of inverted horiz. slider |
| 534 |
<< 7; // result in case of inverted vertical slider |
| 535 |
|
| 536 |
list = QList<Qt::Key>(); |
| 537 |
list << Qt::Key_PageDown; |
| 538 |
QTest::newRow("Page down once") << 10 // initial position |
| 539 |
<< 0 // minimum |
| 540 |
<< 100 // maximum |
| 541 |
<< 0 // single step size |
| 542 |
<< 3 // page step size |
| 543 |
<< list // key sequence |
| 544 |
<< 7 // result in case of horizontal slider |
| 545 |
<< 7 // result in case of vertical slider |
| 546 |
<< 13 // result in case of inverted horiz. slider |
| 547 |
<< 13; // result in case of inverted vertical slider |
| 548 |
|
| 549 |
list = QList<Qt::Key>(); |
| 550 |
list << Qt::Key_PageUp; |
| 551 |
QTest::newRow("Page up once") << 10 // initial position |
| 552 |
<< 0 // minimum |
| 553 |
<< 100 // maximum |
| 554 |
<< 0 // single step size |
| 555 |
<< 3 // page step size |
| 556 |
<< list // key sequence |
| 557 |
<< 13 // result in case of horizontal slider |
| 558 |
<< 13 // result in case of vertical slider |
| 559 |
<< 7 // result in case of inverted horiz. slider |
| 560 |
<< 7; // result in case of inverted vertical slider |
| 561 |
|
| 562 |
list = QList<Qt::Key>(); |
| 563 |
list << Qt::Key_Up << Qt::Key_Up << Qt::Key_PageDown << Qt::Key_PageDown << Qt::Key_Left << Qt::Key_Left |
| 564 |
<< Qt::Key_Right << Qt::Key_Down << Qt::Key_PageUp << Qt::Key_PageUp << Qt::Key_Down << Qt::Key_Right; |
| 565 |
QTest::newRow("Symmetric seq") << 50 // initial position |
| 566 |
<< 0 // minimum |
| 567 |
<< 100 // maximum |
| 568 |
<< 3 // single step size |
| 569 |
<< 3 // page step size |
| 570 |
<< list // key sequence |
| 571 |
<< 50 // result in case of horizontal slider |
| 572 |
<< 50 // result in case of vertical slider |
| 573 |
<< 50 // result in case of inverted horiz. slider |
| 574 |
<< 50; // result in case of inverted vertical slider |
| 575 |
|
| 576 |
|
| 577 |
list = QList<Qt::Key>(); |
| 578 |
list << Qt::Key_Home; |
| 579 |
QTest::newRow("Home") << 10 // initial position |
| 580 |
<< 0 // minimum |
| 581 |
<< 100 // maximum |
| 582 |
<< 0 // single step size |
| 583 |
<< 3 // page step size |
| 584 |
<< list // key sequence |
| 585 |
<< 0 // result in case of horizontal slider |
| 586 |
<< 0 // result in case of vertical slider |
| 587 |
<< 0 // result in case of inverted horiz. slider |
| 588 |
<< 0; // result in case of inverted vertical slider |
| 589 |
|
| 590 |
list = QList<Qt::Key>(); |
| 591 |
list << Qt::Key_End; |
| 592 |
QTest::newRow("End") << 10 // initial position |
| 593 |
<< 0 // minimum |
| 594 |
<< 100 // maximum |
| 595 |
<< 0 // single step size |
| 596 |
<< 3 // page step size |
| 597 |
<< list // key sequence |
| 598 |
<< 100 // result in case of horizontal slider |
| 599 |
<< 100 // result in case of vertical slider |
| 600 |
<< 100 // result in case of inverted horiz. slider |
| 601 |
<< 100; // result in case of inverted vertical slider |
| 602 |
|
| 603 |
list = QList<Qt::Key>(); |
| 604 |
list << Qt::Key_End << Qt::Key_Up; |
| 605 |
QTest::newRow("Past end")<< 10 // initial position |
| 606 |
<< 0 // minimum |
| 607 |
<< 100 // maximum |
| 608 |
<< 3 // single step size |
| 609 |
<< 3 // page step size |
| 610 |
<< list // key sequence |
| 611 |
<< 100 // result in case of horizontal slider |
| 612 |
<< 100 // result in case of vertical slider |
| 613 |
<< 97 // result in case of inverted horiz. slider |
| 614 |
<< 97; // result in case of inverted vertical slider |
| 615 |
|
| 616 |
list = QList<Qt::Key>(); |
| 617 |
list << Qt::Key_Home << Qt::Key_Down; |
| 618 |
QTest::newRow("Past home")<< 10 // initial position |
| 619 |
<< 0 // minimum |
| 620 |
<< 100 // maximum |
| 621 |
<< 3 // single step size |
| 622 |
<< 3 // page step size |
| 623 |
<< list // key sequence |
| 624 |
<< 0 // result in case of horizontal slider |
| 625 |
<< 0 // result in case of vertical slider |
| 626 |
<< 3 // result in case of inverted horiz. slider |
| 627 |
<< 3; // result in case of inverted vertical slider |
| 628 |
|
| 629 |
} |
| 630 |
|
| 631 |
void tst_QAbstractSlider::keyPressed() |
| 632 |
{ |
| 633 |
QFETCH(int, initialSliderPosition); |
| 634 |
QFETCH(int, minimum); |
| 635 |
QFETCH(int, maximum); |
| 636 |
QFETCH(int, stepSize); |
| 637 |
QFETCH(int, pageSize); |
| 638 |
QFETCH(QList<Qt::Key>, keySequence); |
| 639 |
QFETCH(int, expectedSliderPositionHorizontal); |
| 640 |
QFETCH(int, expectedSliderPositionVertical); |
| 641 |
QFETCH(int, expectedSliderPositionHorizontalInverted); |
| 642 |
QFETCH(int, expectedSliderPositionVerticalInverted); |
| 643 |
|
| 644 |
// Horizontal non-inverted |
| 645 |
slider->setRange(minimum,maximum); |
| 646 |
slider->setSliderPosition(initialSliderPosition); |
| 647 |
slider->setSingleStep(stepSize); |
| 648 |
slider->setPageStep(pageSize); |
| 649 |
slider->setOrientation(Qt::Horizontal); |
| 650 |
slider->setInvertedAppearance(false); |
| 651 |
slider->setInvertedControls(false); |
| 652 |
for (int i=0;i<keySequence.count();i++) { |
| 653 |
QTest::keyClick(slider, keySequence.at(i)); |
| 654 |
} |
| 655 |
QCOMPARE(slider->sliderPosition(), expectedSliderPositionHorizontal); |
| 656 |
|
| 657 |
// Horizontal inverted |
| 658 |
slider->setRange(minimum,maximum); |
| 659 |
slider->setSliderPosition(initialSliderPosition); |
| 660 |
slider->setSingleStep(stepSize); |
| 661 |
slider->setPageStep(pageSize); |
| 662 |
slider->setOrientation(Qt::Horizontal); |
| 663 |
slider->setInvertedAppearance(true); |
| 664 |
slider->setInvertedControls(true); |
| 665 |
for (int i=0;i<keySequence.count();i++) |
| 666 |
QTest::keyPress(slider, keySequence.at(i)); |
| 667 |
QCOMPARE(slider->sliderPosition(), expectedSliderPositionHorizontalInverted); |
| 668 |
|
| 669 |
// Vertical non-inverted |
| 670 |
slider->setRange(minimum,maximum); |
| 671 |
slider->setSliderPosition(initialSliderPosition); |
| 672 |
slider->setSingleStep(stepSize); |
| 673 |
slider->setPageStep(pageSize); |
| 674 |
slider->setOrientation(Qt::Vertical); |
| 675 |
slider->setInvertedAppearance(false); |
| 676 |
slider->setInvertedControls(false); |
| 677 |
for (int i=0;i<keySequence.count();i++) |
| 678 |
QTest::keyPress(slider, keySequence.at(i)); |
| 679 |
QCOMPARE(slider->sliderPosition(), expectedSliderPositionVertical); |
| 680 |
|
| 681 |
// Vertical inverted |
| 682 |
slider->setRange(minimum,maximum); |
| 683 |
slider->setSliderPosition(initialSliderPosition); |
| 684 |
slider->setSingleStep(stepSize); |
| 685 |
slider->setPageStep(pageSize); |
| 686 |
slider->setOrientation(Qt::Vertical); |
| 687 |
slider->setInvertedAppearance(true); |
| 688 |
slider->setInvertedControls(true); |
| 689 |
for (int i=0;i<keySequence.count();i++) |
| 690 |
QTest::keyPress(slider, keySequence.at(i)); |
| 691 |
QCOMPARE(slider->sliderPosition(), expectedSliderPositionVerticalInverted); |
| 692 |
} |
| 693 |
|
| 694 |
void tst_QAbstractSlider::wheelEvent_data() |
| 695 |
{ |
| 696 |
QTest::addColumn<int>("initialSliderPosition"); |
| 697 |
QTest::addColumn<int>("minimum"); |
| 698 |
QTest::addColumn<int>("maximum"); |
| 699 |
QTest::addColumn<int>("singleStep"); |
| 700 |
QTest::addColumn<int>("pageStep"); |
| 701 |
QTest::addColumn<bool>("invertedControls"); |
| 702 |
QTest::addColumn<int>("wheelScrollLines"); |
| 703 |
QTest::addColumn<bool>("withModifiers"); // use keyboard modifiers while scrolling? (CTRL and SHIFT) |
| 704 |
QTest::addColumn<int>("deltaMultiple"); // multiples of WHEEL_DELTA |
| 705 |
QTest::addColumn<int>("sliderOrientation"); |
| 706 |
QTest::addColumn<int>("wheelOrientation"); |
| 707 |
QTest::addColumn<int>("expectedSliderPosition"); |
| 708 |
QTest::addColumn<QPoint>("distanceFromBottomRight"); // mpointer's distance from bottom-right corner of widget |
| 709 |
|
| 710 |
QTest::newRow("Normal data step") << 0 // initial position |
| 711 |
<< 0 // minimum |
| 712 |
<< 100 // maximum |
| 713 |
<< 1 // single step |
| 714 |
<< 100 // page step |
| 715 |
<< false // inverted controls |
| 716 |
<< 20 // wheel scroll lines |
| 717 |
<< false // with modifiers |
| 718 |
<< 1 // delta |
| 719 |
<< int(Qt::Vertical) // orientation of slider |
| 720 |
<< int(Qt::Vertical) // orientation of wheel |
| 721 |
<< 20 // expected position after |
| 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 |
#ifndef Q_WS_MAC |
| 736 |
<< 1 // expected position after |
| 737 |
#else |
| 738 |
// We don't restrict scrolling to pageStep on Mac |
| 739 |
<< 100 // expected position after |
| 740 |
#endif |
| 741 |
<< QPoint(1,1); |
| 742 |
QTest::newRow("Different orientation") << 0 // initial position |
| 743 |
<< 0 // minimum |
| 744 |
<< 100 // maximum |
| 745 |
<< 100 // single step |
| 746 |
<< 1 // page step |
| 747 |
<< false // inverted controls |
| 748 |
<< 20 // wheel scroll lines |
| 749 |
<< false // with modifiers |
| 750 |
<< 1 // delta |
| 751 |
<< int(Qt::Horizontal) // orientation of slider |
| 752 |
<< int(Qt::Vertical) // orientation of wheel |
| 753 |
#ifndef Q_WS_MAC |
| 754 |
<< 1 // expected position after |
| 755 |
#else |
| 756 |
// We don't restrict scrolling to pageStep on Mac |
| 757 |
<< 100 // expected position after |
| 758 |
#endif |
| 759 |
<< QPoint(1,1); |
| 760 |
|
| 761 |
QTest::newRow("Different orientation2")<< 0 // initial position |
| 762 |
<< 0 // minimum |
| 763 |
<< 100 // maximum |
| 764 |
<< 100 // single step |
| 765 |
<< 1 // page step |
| 766 |
<< false // inverted controls |
| 767 |
<< 20 // wheel scroll lines |
| 768 |
<< false // with modifiers |
| 769 |
<< 1 // delta |
| 770 |
<< int(Qt::Horizontal) // orientation of slider |
| 771 |
<< int(Qt::Vertical) // orientation of wheel |
| 772 |
#ifndef Q_WS_MAC |
| 773 |
<< 1 // expected position after |
| 774 |
#else |
| 775 |
// We don't restrict scrolling to pageStep on Mac |
| 776 |
<< 100 // expected position after |
| 777 |
#endif |
| 778 |
<< QPoint(0,0); |
| 779 |
|
| 780 |
QTest::newRow("Inverted controls") << 50 // initial position |
| 781 |
<< 0 // minimum |
| 782 |
<< 100 // maximum |
| 783 |
<< 1 // single step |
| 784 |
<< 100 // page step |
| 785 |
<< true // inverted controls |
| 786 |
<< 20 // wheel scroll lines |
| 787 |
<< false // with modifiers |
| 788 |
<< -1 // delta |
| 789 |
<< int(Qt::Horizontal) // orientation of slider |
| 790 |
<< int(Qt::Horizontal) // orientation of wheel |
| 791 |
<< 30 // expected position after |
| 792 |
<< QPoint(1,1); |
| 793 |
|
| 794 |
QTest::newRow("Past end") << 50 // initial position |
| 795 |
<< 0 // minimum |
| 796 |
<< 100 // maximum |
| 797 |
<< 26 // single step |
| 798 |
<< 100 // page step |
| 799 |
<< false // inverted controls |
| 800 |
<< 1 // wheel scroll lines |
| 801 |
<< false // with modifiers |
| 802 |
<< -2 // delta |
| 803 |
<< int(Qt::Horizontal) // orientation of slider |
| 804 |
<< int(Qt::Horizontal) // orientation of wheel |
| 805 |
<< 100 // expected position after |
| 806 |
<< QPoint(0,0); |
| 807 |
|
| 808 |
QTest::newRow("Past start") << 50 // initial position |
| 809 |
<< 0 // minimum |
| 810 |
<< 100 // maximum |
| 811 |
<< 26 // single step |
| 812 |
<< 100 // page step |
| 813 |
<< false // inverted controls |
| 814 |
<< 1 // wheel scroll lines |
| 815 |
<< false // with modifiers |
| 816 |
<< 2 // delta |
| 817 |
<< int(Qt::Horizontal) // orientation of slider |
| 818 |
<< int(Qt::Horizontal) // orientation of wheel |
| 819 |
<< 0 // expected position after |
| 820 |
<< QPoint(0,0); |
| 821 |
|
| 822 |
QTest::newRow("With modifiers") << 50 // initial position |
| 823 |
<< 0 // minimum |
| 824 |
<< 100 // maximum |
| 825 |
<< 1 // single step |
| 826 |
<< 40 // page step |
| 827 |
<< false // inverted controls |
| 828 |
<< 20 // wheel scroll lines |
| 829 |
<< true // with modifiers |
| 830 |
<< -1 // delta |
| 831 |
<< int(Qt::Horizontal) // orientation of slider |
| 832 |
<< int(Qt::Horizontal) // orientation of wheel |
| 833 |
<< 90 // expected position after |
| 834 |
<< QPoint(0,0); |
| 835 |
|
| 836 |
} |
| 837 |
|
| 838 |
void tst_QAbstractSlider::wheelEvent() |
| 839 |
{ |
| 840 |
QFETCH(int,initialSliderPosition); |
| 841 |
QFETCH(int,minimum); |
| 842 |
QFETCH(int,maximum); |
| 843 |
QFETCH(int,singleStep); |
| 844 |
QFETCH(int,pageStep); |
| 845 |
QFETCH(bool,invertedControls); |
| 846 |
QFETCH(int,wheelScrollLines); |
| 847 |
QFETCH(bool,withModifiers); |
| 848 |
QFETCH(int,deltaMultiple); |
| 849 |
QFETCH(int,sliderOrientation); |
| 850 |
QFETCH(int,wheelOrientation); |
| 851 |
QFETCH(int,expectedSliderPosition); |
| 852 |
QFETCH(QPoint,distanceFromBottomRight); |
| 853 |
|
| 854 |
QCoreApplication *applicationInstance = QCoreApplication::instance(); |
| 855 |
QVERIFY(applicationInstance != 0); |
| 856 |
QApplication::setWheelScrollLines(wheelScrollLines); |
| 857 |
|
| 858 |
Qt::Orientation orientation = *reinterpret_cast<Qt::Orientation*>(&sliderOrientation); |
| 859 |
slider->setRange(minimum,maximum); |
| 860 |
slider->setSliderPosition(initialSliderPosition); |
| 861 |
slider->setSingleStep(singleStep); |
| 862 |
slider->setPageStep(pageStep); |
| 863 |
slider->setInvertedControls(invertedControls); |
| 864 |
slider->setOrientation(orientation); |
| 865 |
|
| 866 |
Qt::KeyboardModifier k = withModifiers ? Qt::ControlModifier : Qt::NoModifier; |
| 867 |
orientation = *reinterpret_cast<Qt::Orientation*>(&wheelOrientation); |
| 868 |
QWheelEvent event(slider->rect().bottomRight() + distanceFromBottomRight, WHEEL_DELTA * deltaMultiple, |
| 869 |
Qt::NoButton, k, orientation); |
| 870 |
QVERIFY(applicationInstance->sendEvent(slider,&event)); |
| 871 |
QCOMPARE(slider->sliderPosition(),expectedSliderPosition); |
| 872 |
|
| 873 |
slider->setSliderPosition(initialSliderPosition); |
| 874 |
k = withModifiers ? Qt::ShiftModifier : Qt::NoModifier; |
| 875 |
event = QWheelEvent(slider->rect().bottomRight() + distanceFromBottomRight, WHEEL_DELTA * deltaMultiple, |
| 876 |
Qt::NoButton, k, orientation); |
| 877 |
QSignalSpy spy1(slider, SIGNAL(actionTriggered(int))); |
| 878 |
QSignalSpy spy2(slider, SIGNAL(valueChanged(int))); |
| 879 |
QVERIFY(applicationInstance->sendEvent(slider,&event)); |
| 880 |
QCOMPARE(slider->sliderPosition(),expectedSliderPosition); |
| 881 |
int expectedSignalCount = (initialSliderPosition == expectedSliderPosition) ? 0 : 1; |
| 882 |
QCOMPARE(spy1.count(), expectedSignalCount); |
| 883 |
QCOMPARE(spy2.count(), expectedSignalCount); |
| 884 |
if (expectedSignalCount) |
| 885 |
QVERIFY(actionTriggeredTimeStamp < valueChangedTimeStamp); |
| 886 |
} |
| 887 |
|
| 888 |
void tst_QAbstractSlider::sliderPressedReleased_data() |
| 889 |
{ |
| 890 |
QTest::addColumn<int>("control"); |
| 891 |
QTest::addColumn<int>("minimum"); |
| 892 |
QTest::addColumn<int>("maximum"); |
| 893 |
QTest::addColumn<uint>("subControl"); |
| 894 |
QTest::addColumn<int>("expectedCount"); |
| 895 |
|
| 896 |
QTest::newRow("slider on the handle") << int(QStyle::CC_Slider) |
| 897 |
<< 0 |
| 898 |
<< 20 |
| 899 |
<< uint(QStyle::SC_SliderHandle) |
| 900 |
<< 1; |
| 901 |
|
| 902 |
QTest::newRow("slider on the groove") << int(QStyle::CC_Slider) |
| 903 |
<< 0 |
| 904 |
<< 20 |
| 905 |
<< uint(QStyle::SC_SliderGroove) |
| 906 |
<< ((qApp->style()->styleHint(QStyle::SH_Slider_AbsoluteSetButtons) & Qt::LeftButton) ? 1 : 0); |
| 907 |
|
| 908 |
QTest::newRow("scrollbar on the handle") << int(QStyle::CC_ScrollBar) |
| 909 |
<< 0 |
| 910 |
<< 20 |
| 911 |
<< uint(QStyle::SC_ScrollBarSlider) |
| 912 |
<< 1; |
| 913 |
|
| 914 |
QTest::newRow("scrollbar on the groove") << int(QStyle::CC_ScrollBar) |
| 915 |
<< 0 |
| 916 |
<< 20 |
| 917 |
<< uint(QStyle::SC_ScrollBarGroove) |
| 918 |
<< 0; |
| 919 |
} |
| 920 |
|
| 921 |
void tst_QAbstractSlider::sliderPressedReleased() |
| 922 |
{ |
| 923 |
QFETCH(int, control); |
| 924 |
QFETCH(int, minimum); |
| 925 |
QFETCH(int, maximum); |
| 926 |
QFETCH(uint, subControl); |
| 927 |
QFETCH(int, expectedCount); |
| 928 |
|
| 929 |
QWidget topLevel; |
| 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(&topLevel); |
| 938 |
slider->setLayoutDirection(Qt::LeftToRight); // Makes "upside down" much easier to compute |
| 939 |
break; |
| 940 |
case QStyle::CC_ScrollBar: |
| 941 |
slider = new QScrollBar(&topLevel); |
| 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 |
topLevel.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" |