author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 12 Mar 2010 15:46:37 +0200 | |
branch | RCL_3 |
changeset 5 | d3bac044e0f0 |
parent 4 | 3b1da2848fc7 |
child 8 | 3f74d0d4af4c |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the test suite of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
||
43 |
#include <QtTest/QtTest> |
|
44 |
||
45 |
#include <qcoreapplication.h> |
|
46 |
#include <qdebug.h> |
|
47 |
#include <qabstractscrollarea.h> |
|
48 |
#include <qscrollarea.h> |
|
49 |
#include <qscrollbar.h> |
|
50 |
#include <qlabel.h> |
|
51 |
#include <qwidget.h> |
|
52 |
#include <qdialog.h> |
|
53 |
||
54 |
//TESTED_CLASS= |
|
55 |
//TESTED_FILES= |
|
56 |
||
57 |
class tst_QAbstractScrollArea : public QObject |
|
58 |
{ |
|
59 |
Q_OBJECT |
|
60 |
||
61 |
public: |
|
62 |
tst_QAbstractScrollArea(); |
|
63 |
virtual ~tst_QAbstractScrollArea(); |
|
64 |
private slots: |
|
65 |
void scrollBarWidgets(); |
|
66 |
void setScrollBars(); |
|
67 |
void setScrollBars2(); |
|
68 |
void objectNaming(); |
|
69 |
void patternBackground(); |
|
70 |
||
71 |
void viewportCrash(); |
|
72 |
void task214488_layoutDirection_data(); |
|
73 |
void task214488_layoutDirection(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
74 |
void wheelEvent_data(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
75 |
void wheelEvent(); |
0 | 76 |
}; |
77 |
||
78 |
tst_QAbstractScrollArea::tst_QAbstractScrollArea() |
|
79 |
{ |
|
80 |
} |
|
81 |
||
82 |
tst_QAbstractScrollArea::~tst_QAbstractScrollArea() |
|
83 |
{ |
|
84 |
} |
|
85 |
||
86 |
void tst_QAbstractScrollArea::scrollBarWidgets() |
|
87 |
{ |
|
88 |
QWidget *w1 = new QWidget(0); |
|
89 |
QWidget *w2 = new QWidget(0); |
|
90 |
QWidget *w3 = new QWidget(0); |
|
91 |
||
92 |
Qt::Alignment all = Qt::AlignLeft | Qt::AlignRight | Qt::AlignTop | Qt::AlignBottom; |
|
93 |
||
94 |
QWidgetList w1List = QWidgetList() << w1; |
|
95 |
QWidgetList w2List = QWidgetList() << w2; |
|
96 |
QWidgetList w3List = QWidgetList() << w3; |
|
97 |
||
98 |
QWidgetList w1w2List = w1List + w2List; |
|
99 |
QWidgetList allList = w1List + w2List + w3List; |
|
100 |
||
101 |
QAbstractScrollArea area; |
|
102 |
area.show(); |
|
103 |
QCOMPARE(area.scrollBarWidgets(all), QWidgetList()); |
|
104 |
||
105 |
area.addScrollBarWidget(w1, Qt::AlignLeft); |
|
106 |
QCOMPARE(area.scrollBarWidgets(all), w1List); |
|
107 |
QCOMPARE(area.scrollBarWidgets(Qt::AlignLeft), w1List); |
|
108 |
QCOMPARE(area.scrollBarWidgets(Qt::AlignRight), QWidgetList()); |
|
109 |
QCOMPARE(area.scrollBarWidgets(Qt::AlignTop), QWidgetList()); |
|
110 |
QCOMPARE(area.scrollBarWidgets(Qt::AlignBottom), QWidgetList()); |
|
111 |
||
112 |
area.addScrollBarWidget(w2, Qt::AlignBottom); |
|
113 |
QCOMPARE(area.scrollBarWidgets(all), w1w2List); |
|
114 |
QCOMPARE(area.scrollBarWidgets(Qt::AlignLeft), w1List); |
|
115 |
QCOMPARE(area.scrollBarWidgets(Qt::AlignRight), QWidgetList()); |
|
116 |
QCOMPARE(area.scrollBarWidgets(Qt::AlignTop), QWidgetList()); |
|
117 |
QCOMPARE(area.scrollBarWidgets(Qt::AlignBottom), w2List); |
|
118 |
||
119 |
// duplicate add |
|
120 |
area.addScrollBarWidget(w2, Qt::AlignBottom); |
|
121 |
QCOMPARE(area.scrollBarWidgets(all), w1w2List); |
|
122 |
QCOMPARE(area.scrollBarWidgets(Qt::AlignLeft), w1List); |
|
123 |
QCOMPARE(area.scrollBarWidgets(Qt::AlignRight), QWidgetList()); |
|
124 |
QCOMPARE(area.scrollBarWidgets(Qt::AlignTop), QWidgetList()); |
|
125 |
QCOMPARE(area.scrollBarWidgets(Qt::AlignBottom), w2List); |
|
126 |
||
127 |
//reparent |
|
128 |
w2->setParent(w1); |
|
129 |
QCOMPARE(area.scrollBarWidgets(all), w1List); |
|
130 |
QCOMPARE(area.scrollBarWidgets(Qt::AlignLeft), w1List); |
|
131 |
QCOMPARE(area.scrollBarWidgets(Qt::AlignRight), QWidgetList()); |
|
132 |
QCOMPARE(area.scrollBarWidgets(Qt::AlignTop), QWidgetList()); |
|
133 |
QCOMPARE(area.scrollBarWidgets(Qt::AlignBottom), QWidgetList()); |
|
134 |
||
135 |
// add after reparent |
|
136 |
area.addScrollBarWidget(w2, Qt::AlignBottom); |
|
137 |
QCOMPARE(area.scrollBarWidgets(all), w1w2List); |
|
138 |
QCOMPARE(area.scrollBarWidgets(Qt::AlignLeft), w1List); |
|
139 |
QCOMPARE(area.scrollBarWidgets(Qt::AlignRight), QWidgetList()); |
|
140 |
QCOMPARE(area.scrollBarWidgets(Qt::AlignTop), QWidgetList()); |
|
141 |
QCOMPARE(area.scrollBarWidgets(Qt::AlignBottom), w2List); |
|
142 |
||
143 |
// two widgets at Bottom. |
|
144 |
area.addScrollBarWidget(w3, Qt::AlignBottom); |
|
145 |
QCOMPARE(area.scrollBarWidgets(all).toSet(), allList.toSet()); |
|
146 |
QCOMPARE(area.scrollBarWidgets(Qt::AlignLeft), w1List); |
|
147 |
QCOMPARE(area.scrollBarWidgets(Qt::AlignRight), QWidgetList()); |
|
148 |
QCOMPARE(area.scrollBarWidgets(Qt::AlignTop), QWidgetList()); |
|
149 |
QCOMPARE(area.scrollBarWidgets(Qt::AlignBottom).toSet(), (w2List + w3List).toSet()); |
|
150 |
||
151 |
//delete |
|
152 |
delete w1; |
|
153 |
delete w2; |
|
154 |
delete w3; |
|
155 |
||
156 |
QCOMPARE(area.scrollBarWidgets(all), QWidgetList()); |
|
157 |
QCOMPARE(area.scrollBarWidgets(Qt::AlignLeft), QWidgetList()); |
|
158 |
QCOMPARE(area.scrollBarWidgets(Qt::AlignRight), QWidgetList()); |
|
159 |
QCOMPARE(area.scrollBarWidgets(Qt::AlignTop), QWidgetList()); |
|
160 |
QCOMPARE(area.scrollBarWidgets(Qt::AlignBottom), QWidgetList()); |
|
161 |
} |
|
162 |
||
163 |
void tst_QAbstractScrollArea::setScrollBars() |
|
164 |
{ |
|
165 |
QScrollArea scrollArea; |
|
166 |
scrollArea.resize(300, 300); |
|
167 |
scrollArea.show(); |
|
168 |
||
169 |
QPointer<QScrollBar> vbar = scrollArea.verticalScrollBar(); |
|
170 |
QPointer<QScrollBar> hbar = scrollArea.horizontalScrollBar(); |
|
171 |
||
172 |
// Now set properties on the scroll bars |
|
173 |
scrollArea.verticalScrollBar()->setInvertedAppearance(true); |
|
174 |
scrollArea.verticalScrollBar()->setInvertedControls(true); |
|
175 |
scrollArea.verticalScrollBar()->setTracking(true); |
|
176 |
scrollArea.verticalScrollBar()->setRange(-100, 100); |
|
177 |
scrollArea.verticalScrollBar()->setPageStep(42); |
|
178 |
scrollArea.verticalScrollBar()->setSingleStep(3); |
|
179 |
scrollArea.verticalScrollBar()->setValue(43); |
|
180 |
scrollArea.horizontalScrollBar()->setInvertedAppearance(true); |
|
181 |
scrollArea.horizontalScrollBar()->setInvertedControls(true); |
|
182 |
scrollArea.horizontalScrollBar()->setTracking(true); |
|
183 |
scrollArea.horizontalScrollBar()->setRange(-100, 100); |
|
184 |
scrollArea.horizontalScrollBar()->setPageStep(42); |
|
185 |
scrollArea.horizontalScrollBar()->setSingleStep(3); |
|
186 |
scrollArea.horizontalScrollBar()->setValue(43); |
|
187 |
||
188 |
qApp->processEvents(); |
|
189 |
||
190 |
// Then replace the scroll bars |
|
191 |
scrollArea.setVerticalScrollBar(new QScrollBar); |
|
192 |
scrollArea.setHorizontalScrollBar(new QScrollBar); |
|
193 |
||
194 |
// Check that the old ones were deleted |
|
195 |
QVERIFY(!vbar); |
|
196 |
QVERIFY(!hbar); |
|
197 |
||
198 |
qApp->processEvents(); |
|
199 |
||
200 |
// Check that all properties have been populated |
|
201 |
QVERIFY(scrollArea.verticalScrollBar()->invertedAppearance()); |
|
202 |
QVERIFY(scrollArea.verticalScrollBar()->invertedControls()); |
|
203 |
QVERIFY(scrollArea.verticalScrollBar()->hasTracking()); |
|
204 |
QVERIFY(scrollArea.verticalScrollBar()->isVisible()); |
|
205 |
QCOMPARE(scrollArea.verticalScrollBar()->minimum(), -100); |
|
206 |
QCOMPARE(scrollArea.verticalScrollBar()->maximum(), 100); |
|
207 |
QCOMPARE(scrollArea.verticalScrollBar()->pageStep(), 42); |
|
208 |
QCOMPARE(scrollArea.verticalScrollBar()->singleStep(), 3); |
|
209 |
QCOMPARE(scrollArea.verticalScrollBar()->value(), 43); |
|
210 |
QVERIFY(scrollArea.horizontalScrollBar()->invertedAppearance()); |
|
211 |
QVERIFY(scrollArea.horizontalScrollBar()->invertedControls()); |
|
212 |
QVERIFY(scrollArea.horizontalScrollBar()->hasTracking()); |
|
213 |
QVERIFY(scrollArea.horizontalScrollBar()->isVisible()); |
|
214 |
QCOMPARE(scrollArea.horizontalScrollBar()->minimum(), -100); |
|
215 |
QCOMPARE(scrollArea.horizontalScrollBar()->maximum(), 100); |
|
216 |
QCOMPARE(scrollArea.horizontalScrollBar()->pageStep(), 42); |
|
217 |
QCOMPARE(scrollArea.horizontalScrollBar()->singleStep(), 3); |
|
218 |
QCOMPARE(scrollArea.horizontalScrollBar()->value(), 43); |
|
219 |
} |
|
220 |
||
221 |
void tst_QAbstractScrollArea::setScrollBars2() |
|
222 |
{ |
|
223 |
QAbstractScrollArea scrollArea; |
|
224 |
scrollArea.resize(300, 300); |
|
225 |
||
226 |
QScrollBar *hbar = new QScrollBar; |
|
227 |
scrollArea.setHorizontalScrollBar(hbar); |
|
228 |
qApp->processEvents(); |
|
229 |
QCOMPARE(scrollArea.horizontalScrollBar(), hbar); |
|
230 |
||
231 |
QScrollBar *vbar = new QScrollBar; |
|
232 |
scrollArea.setVerticalScrollBar(vbar); |
|
233 |
qApp->processEvents(); |
|
234 |
QCOMPARE(scrollArea.verticalScrollBar(), vbar); |
|
235 |
||
236 |
scrollArea.horizontalScrollBar()->setRange(0, 100); |
|
237 |
scrollArea.verticalScrollBar()->setRange(0, 100); |
|
238 |
scrollArea.show(); |
|
239 |
||
240 |
// Make sure scroll bars are not explicitly hidden by QAbstractScrollArea itself. |
|
241 |
QVERIFY(hbar->isVisible()); |
|
242 |
QVERIFY(vbar->isVisible()); |
|
243 |
||
244 |
// Hide the OLD scroll bar and ensure that the NEW one is hidden. |
|
245 |
hbar->hide(); |
|
246 |
scrollArea.setHorizontalScrollBar(new QScrollBar); |
|
247 |
qApp->processEvents(); |
|
248 |
QVERIFY(!scrollArea.horizontalScrollBar()->isVisible()); |
|
249 |
||
250 |
vbar->hide(); |
|
251 |
scrollArea.setVerticalScrollBar(new QScrollBar); |
|
252 |
qApp->processEvents(); |
|
253 |
QVERIFY(!scrollArea.verticalScrollBar()->isVisible()); |
|
254 |
||
255 |
scrollArea.verticalScrollBar()->show(); |
|
256 |
scrollArea.horizontalScrollBar()->show(); |
|
257 |
||
258 |
// Hide the NEW scroll bar and ensure that it's visible |
|
259 |
// (because the OLD one is visible). |
|
260 |
hbar = new QScrollBar; |
|
261 |
hbar->hide(); |
|
262 |
scrollArea.setHorizontalScrollBar(hbar); |
|
263 |
qApp->processEvents(); |
|
264 |
QVERIFY(hbar->isVisible()); |
|
265 |
||
266 |
vbar = new QScrollBar; |
|
267 |
vbar->hide(); |
|
268 |
scrollArea.setVerticalScrollBar(vbar); |
|
269 |
qApp->processEvents(); |
|
270 |
QVERIFY(vbar->isVisible()); |
|
271 |
||
272 |
vbar->setRange(0, 0); |
|
273 |
qApp->processEvents(); |
|
274 |
QVERIFY(!vbar->isVisible()); |
|
275 |
||
276 |
hbar->setRange(0, 0); |
|
277 |
qApp->processEvents(); |
|
278 |
QVERIFY(!hbar->isVisible()); |
|
279 |
} |
|
280 |
||
281 |
// we need to make sure the viewport internal widget is named |
|
282 |
// qt_scrollarea_viewport, otherwise we're going to confuse Squish |
|
283 |
// and friends. |
|
284 |
void tst_QAbstractScrollArea::objectNaming() |
|
285 |
{ |
|
286 |
QScrollArea area; |
|
287 |
QCOMPARE(area.viewport()->objectName(), QString("qt_scrollarea_viewport")); |
|
288 |
} |
|
289 |
||
290 |
class ViewportCrashWidget : public QDialog |
|
291 |
{ |
|
292 |
public: |
|
293 |
ViewportCrashWidget() |
|
294 |
{ |
|
295 |
// temprorary set PaintOnScreen to set the nativeChildrenForced flag. |
|
296 |
setAttribute(Qt::WA_PaintOnScreen, true); |
|
297 |
setAttribute(Qt::WA_PaintOnScreen, false); |
|
298 |
||
299 |
setAttribute(Qt::WA_DropSiteRegistered, true); |
|
300 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
301 |
startTimer(200); |
0 | 302 |
} |
303 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
304 |
void timerEvent(QTimerEvent *) |
0 | 305 |
{ |
306 |
// should not crash. |
|
307 |
(void)new QScrollArea(this); |
|
308 |
accept(); |
|
309 |
} |
|
310 |
}; |
|
311 |
||
312 |
void tst_QAbstractScrollArea::viewportCrash() |
|
313 |
{ |
|
314 |
ViewportCrashWidget w; |
|
315 |
// should not crash |
|
316 |
w.exec(); |
|
317 |
} |
|
318 |
||
319 |
Q_DECLARE_METATYPE(Qt::LayoutDirection); |
|
320 |
Q_DECLARE_METATYPE(Qt::Key); |
|
321 |
||
322 |
void tst_QAbstractScrollArea::task214488_layoutDirection_data() |
|
323 |
{ |
|
324 |
QTest::addColumn<Qt::LayoutDirection>("dir"); |
|
325 |
QTest::addColumn<Qt::Key>("key"); |
|
326 |
QTest::addColumn<bool>("lessThan"); |
|
327 |
||
328 |
QTest::newRow("LTR left") << Qt::LeftToRight << Qt::Key_Left << true; |
|
329 |
QTest::newRow("LTR right") << Qt::LeftToRight << Qt::Key_Right << false; |
|
330 |
QTest::newRow("RTL left") << Qt::RightToLeft << Qt::Key_Left << false; |
|
331 |
QTest::newRow("RTL right") << Qt::RightToLeft << Qt::Key_Right << true; |
|
332 |
} |
|
333 |
||
334 |
void tst_QAbstractScrollArea::task214488_layoutDirection() |
|
335 |
{ |
|
336 |
QScrollArea scrollArea; |
|
337 |
scrollArea.resize(200, 200); |
|
338 |
QWidget widget; |
|
339 |
widget.resize(600, 600); |
|
340 |
scrollArea.setWidget(&widget); |
|
341 |
scrollArea.show(); |
|
342 |
QScrollBar *hbar = scrollArea.horizontalScrollBar(); |
|
343 |
hbar->setValue((hbar->minimum() + hbar->maximum()) / 2); |
|
344 |
||
345 |
QFETCH(Qt::LayoutDirection, dir); |
|
346 |
QFETCH(Qt::Key, key); |
|
347 |
QFETCH(bool, lessThan); |
|
348 |
||
349 |
scrollArea.setLayoutDirection(dir); |
|
350 |
||
351 |
int refValue = hbar->value(); |
|
352 |
qApp->sendEvent(&scrollArea, new QKeyEvent(QEvent::KeyPress, key, Qt::NoModifier)); |
|
353 |
QVERIFY(lessThan ? (hbar->value() < refValue) : (hbar->value() > refValue)); |
|
354 |
} |
|
355 |
||
356 |
void tst_QAbstractScrollArea::patternBackground() |
|
357 |
{ |
|
358 |
QScrollArea scrollArea; |
|
359 |
scrollArea.resize(200, 200); |
|
360 |
QWidget widget; |
|
361 |
widget.resize(600, 600); |
|
362 |
scrollArea.setWidget(&widget); |
|
363 |
scrollArea.show(); |
|
364 |
||
365 |
QLinearGradient linearGrad(QPointF(250, 250), QPointF(300, 300)); |
|
366 |
linearGrad.setColorAt(0, Qt::yellow); |
|
367 |
linearGrad.setColorAt(1, Qt::red); |
|
368 |
QBrush bg(linearGrad); |
|
369 |
scrollArea.viewport()->setPalette(QPalette(Qt::black, bg, bg, bg, bg, bg, bg, bg, bg)); |
|
370 |
widget.setPalette(Qt::transparent); |
|
371 |
||
372 |
QTest::qWait(50); |
|
373 |
||
374 |
QImage image(200, 200, QImage::Format_ARGB32); |
|
375 |
scrollArea.render(&image); |
|
376 |
||
377 |
QCOMPARE(image.pixel(QPoint(20,20)) , QColor(Qt::yellow).rgb()); |
|
378 |
||
379 |
QScrollBar *hbar = scrollArea.horizontalScrollBar(); |
|
380 |
hbar->setValue(hbar->maximum()); |
|
381 |
QScrollBar *vbar = scrollArea.verticalScrollBar(); |
|
382 |
vbar->setValue(vbar->maximum()); |
|
383 |
||
384 |
QTest::qWait(50); |
|
385 |
||
386 |
scrollArea.render(&image); |
|
387 |
QCOMPARE(image.pixel(QPoint(20,20)) , QColor(Qt::red).rgb()); |
|
388 |
} |
|
389 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
390 |
Q_DECLARE_METATYPE(QWheelEvent *); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
391 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
392 |
void tst_QAbstractScrollArea::wheelEvent_data() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
393 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
394 |
QTest::addColumn<QSize>("widgetSize"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
395 |
QTest::addColumn<QPoint>("initialOffset"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
396 |
QTest::addColumn<QWheelEvent *>("event"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
397 |
QTest::addColumn<int>("movedX"); // -1 , 0 , or 1 |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
398 |
QTest::addColumn<int>("movedY"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
399 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
400 |
QPoint pos(100,100); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
401 |
int delta =-120; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
402 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
403 |
QTest::newRow("1") << QSize(600,600) << QPoint(50,50) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
404 |
<< new QWheelEvent(pos, delta, 0, 0, Qt::Horizontal) << 1 << 0; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
405 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
406 |
QTest::newRow("2") << QSize(600,600) << QPoint(50,50) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
407 |
<< new QWheelEvent(pos, delta, 0, 0, Qt::Vertical) << 0 << 1; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
408 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
409 |
QTest::newRow("3") << QSize(600,600) << QPoint(50,50) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
410 |
<< new QWheelEvent(pos, -delta, 0, 0, Qt::Horizontal) << -1 << 0; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
411 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
412 |
QTest::newRow("4") << QSize(600,600) << QPoint(50,50) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
413 |
<< new QWheelEvent(pos, -delta, 0, 0, Qt::Vertical) << 0 << -1; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
414 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
415 |
QTest::newRow("5") << QSize(20,600) << QPoint(0,50) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
416 |
<< new QWheelEvent(pos, delta, 0, 0, Qt::Horizontal) << 0 << 1; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
417 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
418 |
QTest::newRow("6") << QSize(20,600) << QPoint(0,50) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
419 |
<< new QWheelEvent(pos, delta, 0, 0, Qt::Vertical) << 0 << 1; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
420 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
421 |
QTest::newRow("7") << QSize(20,600) << QPoint(0,50) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
422 |
<< new QWheelEvent(pos, -delta, 0, 0, Qt::Horizontal) << 0 << -1; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
423 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
424 |
QTest::newRow("8") << QSize(20,600) << QPoint(0,50) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
425 |
<< new QWheelEvent(pos, -delta, 0, 0, Qt::Vertical) << 0 << -1; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
426 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
427 |
QTest::newRow("9") << QSize(600,20) << QPoint(50,0) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
428 |
<< new QWheelEvent(pos, delta, 0, 0, Qt::Horizontal) << 1 << 0; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
429 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
430 |
QTest::newRow("a") << QSize(600,20) << QPoint(50,0) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
431 |
<< new QWheelEvent(pos, delta, 0, 0, Qt::Vertical) << 1 << 0; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
432 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
433 |
QTest::newRow("b") << QSize(600,20) << QPoint(50,0) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
434 |
<< new QWheelEvent(pos, -delta, 0, 0, Qt::Horizontal) << -1 << 0; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
435 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
436 |
QTest::newRow("c") << QSize(600,20) << QPoint(50,0) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
437 |
<< new QWheelEvent(pos, -delta, 0, 0, Qt::Vertical) << -1 << 0; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
438 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
439 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
440 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
441 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
442 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
443 |
void tst_QAbstractScrollArea::wheelEvent() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
444 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
445 |
QFETCH(QSize, widgetSize); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
446 |
QFETCH(QPoint, initialOffset); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
447 |
QFETCH(QWheelEvent *, event); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
448 |
QFETCH(int, movedX); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
449 |
QFETCH(int, movedY); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
450 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
451 |
QScrollArea scrollArea; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
452 |
scrollArea.resize(200, 200); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
453 |
QLabel widget("H e l l o"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
454 |
widget.resize(widgetSize); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
455 |
scrollArea.setWidget(&widget); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
456 |
scrollArea.show(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
457 |
QTest::qWait(20); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
458 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
459 |
scrollArea.verticalScrollBar()->setValue(initialOffset.y()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
460 |
scrollArea.horizontalScrollBar()->setValue(initialOffset.x()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
461 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
462 |
QCOMPARE(scrollArea.verticalScrollBar()->value(), initialOffset.y()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
463 |
QCOMPARE(scrollArea.horizontalScrollBar()->value(), initialOffset.x()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
464 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
465 |
QApplication::sendEvent(scrollArea.viewport(), event); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
466 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
467 |
if(movedX == 0) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
468 |
QCOMPARE(scrollArea.horizontalScrollBar()->value(), initialOffset.x()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
469 |
else |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
470 |
QVERIFY(movedX * scrollArea.horizontalScrollBar()->value() > movedX * initialOffset.x()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
471 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
472 |
if(movedY == 0) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
473 |
QCOMPARE(scrollArea.verticalScrollBar()->value(), initialOffset.y()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
474 |
else |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
475 |
QVERIFY(movedY * scrollArea.verticalScrollBar()->value() > movedY * initialOffset.y()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
476 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
477 |
delete event; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
478 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
479 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
480 |
|
0 | 481 |
QTEST_MAIN(tst_QAbstractScrollArea) |
482 |
#include "tst_qabstractscrollarea.moc" |