author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 19 Feb 2010 23:40:16 +0200 | |
branch | RCL_3 |
changeset 4 | 3b1da2848fc7 |
parent 3 | 41300fa6a67c |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the test suite of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
||
43 |
#include <QtTest/QtTest> |
|
44 |
#include <qapplication.h> |
|
45 |
#include <qtabbar.h> |
|
46 |
||
47 |
#include <qpushbutton.h> |
|
48 |
#include <qstyle.h> |
|
49 |
#include "../../shared/util.h" |
|
50 |
||
51 |
class tst_QTabBar : public QObject |
|
52 |
{ |
|
53 |
Q_OBJECT |
|
54 |
||
55 |
public: |
|
56 |
tst_QTabBar(); |
|
57 |
virtual ~tst_QTabBar(); |
|
58 |
||
59 |
public slots: |
|
60 |
void initTestCase(); |
|
61 |
void cleanupTestCase(); |
|
62 |
void init(); |
|
63 |
||
64 |
private slots: |
|
65 |
void getSetCheck(); |
|
66 |
void setIconSize(); |
|
67 |
void setIconSize_data(); |
|
68 |
||
69 |
void testCurrentChanged_data(); |
|
70 |
void testCurrentChanged(); |
|
71 |
||
72 |
void insertAtCurrentIndex(); |
|
73 |
||
74 |
void removeTab_data(); |
|
75 |
void removeTab(); |
|
76 |
||
77 |
void setElideMode_data(); |
|
78 |
void setElideMode(); |
|
79 |
||
80 |
void setUsesScrollButtons_data(); |
|
81 |
void setUsesScrollButtons(); |
|
82 |
||
83 |
void removeLastTab(); |
|
84 |
||
85 |
void closeButton(); |
|
86 |
||
87 |
void tabButton_data(); |
|
88 |
void tabButton(); |
|
89 |
||
90 |
void selectionBehaviorOnRemove_data(); |
|
91 |
void selectionBehaviorOnRemove(); |
|
92 |
||
93 |
void moveTab_data(); |
|
94 |
void moveTab(); |
|
95 |
||
96 |
void task251184_removeTab(); |
|
97 |
void changeTitleWhileDoubleClickingTab(); |
|
98 |
}; |
|
99 |
||
100 |
// Testing get/set functions |
|
101 |
void tst_QTabBar::getSetCheck() |
|
102 |
{ |
|
103 |
QTabBar obj1; |
|
104 |
obj1.addTab("Tab1"); |
|
105 |
obj1.addTab("Tab2"); |
|
106 |
obj1.addTab("Tab3"); |
|
107 |
obj1.addTab("Tab4"); |
|
108 |
obj1.addTab("Tab5"); |
|
109 |
// Shape QTabBar::shape() |
|
110 |
// void QTabBar::setShape(Shape) |
|
111 |
obj1.setShape(QTabBar::Shape(QTabBar::RoundedNorth)); |
|
112 |
QCOMPARE(QTabBar::Shape(QTabBar::RoundedNorth), obj1.shape()); |
|
113 |
obj1.setShape(QTabBar::Shape(QTabBar::RoundedSouth)); |
|
114 |
QCOMPARE(QTabBar::Shape(QTabBar::RoundedSouth), obj1.shape()); |
|
115 |
obj1.setShape(QTabBar::Shape(QTabBar::RoundedWest)); |
|
116 |
QCOMPARE(QTabBar::Shape(QTabBar::RoundedWest), obj1.shape()); |
|
117 |
obj1.setShape(QTabBar::Shape(QTabBar::RoundedEast)); |
|
118 |
QCOMPARE(QTabBar::Shape(QTabBar::RoundedEast), obj1.shape()); |
|
119 |
obj1.setShape(QTabBar::Shape(QTabBar::TriangularNorth)); |
|
120 |
QCOMPARE(QTabBar::Shape(QTabBar::TriangularNorth), obj1.shape()); |
|
121 |
obj1.setShape(QTabBar::Shape(QTabBar::TriangularSouth)); |
|
122 |
QCOMPARE(QTabBar::Shape(QTabBar::TriangularSouth), obj1.shape()); |
|
123 |
obj1.setShape(QTabBar::Shape(QTabBar::TriangularWest)); |
|
124 |
QCOMPARE(QTabBar::Shape(QTabBar::TriangularWest), obj1.shape()); |
|
125 |
obj1.setShape(QTabBar::Shape(QTabBar::TriangularEast)); |
|
126 |
QCOMPARE(QTabBar::Shape(QTabBar::TriangularEast), obj1.shape()); |
|
127 |
||
128 |
// bool QTabBar::drawBase() |
|
129 |
// void QTabBar::setDrawBase(bool) |
|
130 |
obj1.setDrawBase(false); |
|
131 |
QCOMPARE(false, obj1.drawBase()); |
|
132 |
obj1.setDrawBase(true); |
|
133 |
QCOMPARE(true, obj1.drawBase()); |
|
134 |
||
135 |
// int QTabBar::currentIndex() |
|
136 |
// void QTabBar::setCurrentIndex(int) |
|
137 |
obj1.setCurrentIndex(0); |
|
138 |
QCOMPARE(0, obj1.currentIndex()); |
|
139 |
obj1.setCurrentIndex(INT_MIN); |
|
140 |
QCOMPARE(0, obj1.currentIndex()); |
|
141 |
obj1.setCurrentIndex(INT_MAX); |
|
142 |
QCOMPARE(0, obj1.currentIndex()); |
|
143 |
obj1.setCurrentIndex(4); |
|
144 |
QCOMPARE(4, obj1.currentIndex()); |
|
145 |
} |
|
146 |
||
147 |
tst_QTabBar::tst_QTabBar() |
|
148 |
{ |
|
149 |
} |
|
150 |
||
151 |
tst_QTabBar::~tst_QTabBar() |
|
152 |
{ |
|
153 |
} |
|
154 |
||
155 |
void tst_QTabBar::initTestCase() |
|
156 |
{ |
|
157 |
} |
|
158 |
||
159 |
void tst_QTabBar::cleanupTestCase() |
|
160 |
{ |
|
161 |
} |
|
162 |
||
163 |
void tst_QTabBar::init() |
|
164 |
{ |
|
165 |
} |
|
166 |
||
167 |
void tst_QTabBar::setIconSize_data() |
|
168 |
{ |
|
169 |
QTest::addColumn<int>("sizeToSet"); |
|
170 |
QTest::addColumn<int>("expectedWidth"); |
|
171 |
||
172 |
int iconDefault = qApp->style()->pixelMetric(QStyle::PM_TabBarIconSize); |
|
173 |
int small = qApp->style()->pixelMetric(QStyle::PM_SmallIconSize); |
|
174 |
int large = qApp->style()->pixelMetric(QStyle::PM_LargeIconSize); |
|
175 |
QTest::newRow("default") << -1 << iconDefault; |
|
176 |
QTest::newRow("zero") << 0 << 0; |
|
177 |
QTest::newRow("same as default") << iconDefault << iconDefault; |
|
178 |
QTest::newRow("large") << large << large; |
|
179 |
QTest::newRow("small") << small << small; |
|
180 |
} |
|
181 |
||
182 |
void tst_QTabBar::setIconSize() |
|
183 |
{ |
|
184 |
QFETCH(int, sizeToSet); |
|
185 |
QFETCH(int, expectedWidth); |
|
186 |
QTabBar tabBar; |
|
187 |
tabBar.setIconSize(QSize(sizeToSet, sizeToSet)); |
|
188 |
QCOMPARE(tabBar.iconSize().width(), expectedWidth); |
|
189 |
} |
|
190 |
||
191 |
void tst_QTabBar::testCurrentChanged_data() |
|
192 |
{ |
|
193 |
QTest::addColumn<int>("tabToSet"); |
|
194 |
QTest::addColumn<int>("expectedCount"); |
|
195 |
||
196 |
QTest::newRow("pressAntotherTab") << 1 << 2; |
|
197 |
QTest::newRow("pressTheSameTab") << 0 << 1; |
|
198 |
} |
|
199 |
||
200 |
void tst_QTabBar::testCurrentChanged() |
|
201 |
{ |
|
202 |
QFETCH(int, tabToSet); |
|
203 |
QFETCH(int, expectedCount); |
|
204 |
QTabBar tabBar; |
|
205 |
QSignalSpy spy(&tabBar, SIGNAL(currentChanged(int))); |
|
206 |
tabBar.addTab("Tab1"); |
|
207 |
tabBar.addTab("Tab2"); |
|
208 |
QCOMPARE(tabBar.currentIndex(), 0); |
|
209 |
tabBar.setCurrentIndex(tabToSet); |
|
210 |
QCOMPARE(tabBar.currentIndex(), tabToSet); |
|
211 |
QCOMPARE(spy.count(), expectedCount); |
|
212 |
} |
|
213 |
||
214 |
void tst_QTabBar::insertAtCurrentIndex() |
|
215 |
{ |
|
216 |
QTabBar tabBar; |
|
217 |
tabBar.addTab("Tab1"); |
|
218 |
QCOMPARE(tabBar.currentIndex(), 0); |
|
219 |
tabBar.insertTab(0, "Tab2"); |
|
220 |
QCOMPARE(tabBar.currentIndex(), 1); |
|
221 |
tabBar.insertTab(0, "Tab3"); |
|
222 |
QCOMPARE(tabBar.currentIndex(), 2); |
|
223 |
tabBar.insertTab(2, "Tab4"); |
|
224 |
QCOMPARE(tabBar.currentIndex(), 3); |
|
225 |
} |
|
226 |
||
227 |
void tst_QTabBar::removeTab_data() |
|
228 |
{ |
|
229 |
QTest::addColumn<int>("currentIndex"); |
|
230 |
QTest::addColumn<int>("deleteIndex"); |
|
231 |
QTest::addColumn<int>("spyCount"); |
|
232 |
QTest::addColumn<int>("finalIndex"); |
|
233 |
||
234 |
QTest::newRow("deleteEnd") << 0 << 2 << 0 << 0; |
|
235 |
QTest::newRow("deleteEndWithIndexOnEnd") << 2 << 2 << 1 << 1; |
|
236 |
QTest::newRow("deleteMiddle") << 2 << 1 << 1 << 1; |
|
237 |
QTest::newRow("deleteMiddleOnMiddle") << 1 << 1 << 1 << 1; |
|
238 |
} |
|
239 |
void tst_QTabBar::removeTab() |
|
240 |
{ |
|
241 |
QTabBar tabbar; |
|
242 |
||
243 |
QFETCH(int, currentIndex); |
|
244 |
QFETCH(int, deleteIndex); |
|
245 |
tabbar.addTab("foo"); |
|
246 |
tabbar.addTab("bar"); |
|
247 |
tabbar.addTab("baz"); |
|
248 |
tabbar.setCurrentIndex(currentIndex); |
|
249 |
QSignalSpy spy(&tabbar, SIGNAL(currentChanged(int))); |
|
250 |
tabbar.removeTab(deleteIndex); |
|
251 |
QTEST(spy.count(), "spyCount"); |
|
252 |
QTEST(tabbar.currentIndex(), "finalIndex"); |
|
253 |
} |
|
254 |
||
255 |
void tst_QTabBar::setElideMode_data() |
|
256 |
{ |
|
257 |
QTest::addColumn<int>("tabElideMode"); |
|
258 |
QTest::addColumn<int>("expectedMode"); |
|
259 |
||
260 |
QTest::newRow("default") << -128 << qApp->style()->styleHint(QStyle::SH_TabBar_ElideMode); |
|
261 |
QTest::newRow("explicit default") << qApp->style()->styleHint(QStyle::SH_TabBar_ElideMode) |
|
262 |
<< qApp->style()->styleHint(QStyle::SH_TabBar_ElideMode); |
|
263 |
QTest::newRow("None") << int(Qt::ElideNone) << int(Qt::ElideNone); |
|
264 |
QTest::newRow("Left") << int(Qt::ElideLeft) << int(Qt::ElideLeft); |
|
265 |
QTest::newRow("Center") << int(Qt::ElideMiddle) << int(Qt::ElideMiddle); |
|
266 |
QTest::newRow("Right") << int(Qt::ElideRight) << int(Qt::ElideRight); |
|
267 |
} |
|
268 |
||
269 |
void tst_QTabBar::setElideMode() |
|
270 |
{ |
|
271 |
QFETCH(int, tabElideMode); |
|
272 |
QTabBar tabBar; |
|
273 |
if (tabElideMode != -128) |
|
274 |
tabBar.setElideMode(Qt::TextElideMode(tabElideMode)); |
|
275 |
QTEST(int(tabBar.elideMode()), "expectedMode"); |
|
276 |
} |
|
277 |
||
278 |
void tst_QTabBar::setUsesScrollButtons_data() |
|
279 |
{ |
|
280 |
QTest::addColumn<int>("usesArrows"); |
|
281 |
QTest::addColumn<bool>("expectedArrows"); |
|
282 |
||
283 |
QTest::newRow("default") << -128 << !qApp->style()->styleHint(QStyle::SH_TabBar_PreferNoArrows); |
|
284 |
QTest::newRow("explicit default") |
|
285 |
<< int(!qApp->style()->styleHint(QStyle::SH_TabBar_PreferNoArrows)) |
|
286 |
<< !qApp->style()->styleHint(QStyle::SH_TabBar_PreferNoArrows); |
|
287 |
QTest::newRow("No") << int(false) << false; |
|
288 |
QTest::newRow("Yes") << int(true) << true; |
|
289 |
} |
|
290 |
||
291 |
void tst_QTabBar::setUsesScrollButtons() |
|
292 |
{ |
|
293 |
QFETCH(int, usesArrows); |
|
294 |
QTabBar tabBar; |
|
295 |
if (usesArrows != -128) |
|
296 |
tabBar.setUsesScrollButtons(usesArrows); |
|
297 |
QTEST(tabBar.usesScrollButtons(), "expectedArrows"); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
298 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
299 |
// Make sure style sheet does not override user set mode |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
300 |
tabBar.setStyleSheet("QWidget { background-color: #ABA8A6;}"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
301 |
QTEST(tabBar.usesScrollButtons(), "expectedArrows"); |
0 | 302 |
} |
303 |
||
304 |
void tst_QTabBar::removeLastTab() |
|
305 |
{ |
|
306 |
QTabBar tabbar; |
|
307 |
QSignalSpy spy(&tabbar, SIGNAL(currentChanged(int))); |
|
308 |
int index = tabbar.addTab("foo"); |
|
309 |
QCOMPARE(spy.count(), 1); |
|
310 |
QCOMPARE(spy.at(0).at(0).toInt(), index); |
|
311 |
spy.clear(); |
|
312 |
||
313 |
tabbar.removeTab(index); |
|
314 |
QCOMPARE(spy.count(), 1); |
|
315 |
QCOMPARE(spy.at(0).at(0).toInt(), -1); |
|
316 |
spy.clear(); |
|
317 |
} |
|
318 |
||
319 |
void tst_QTabBar::closeButton() |
|
320 |
{ |
|
321 |
QTabBar tabbar; |
|
322 |
QCOMPARE(tabbar.tabsClosable(), false); |
|
323 |
tabbar.setTabsClosable(true); |
|
324 |
QCOMPARE(tabbar.tabsClosable(), true); |
|
325 |
tabbar.addTab("foo"); |
|
326 |
||
327 |
QTabBar::ButtonPosition closeSide = (QTabBar::ButtonPosition)tabbar.style()->styleHint(QStyle::SH_TabBar_CloseButtonPosition, 0, &tabbar); |
|
328 |
QTabBar::ButtonPosition otherSide = (closeSide == QTabBar::LeftSide ? QTabBar::RightSide : QTabBar::LeftSide); |
|
329 |
QVERIFY(tabbar.tabButton(0, otherSide) == 0); |
|
330 |
QVERIFY(tabbar.tabButton(0, closeSide) != 0); |
|
331 |
||
332 |
QAbstractButton *button = static_cast<QAbstractButton*>(tabbar.tabButton(0, closeSide)); |
|
333 |
QVERIFY(button); |
|
334 |
QSignalSpy spy(&tabbar, SIGNAL(tabCloseRequested(int))); |
|
335 |
button->click(); |
|
336 |
QCOMPARE(tabbar.count(), 1); |
|
337 |
QCOMPARE(spy.count(), 1); |
|
338 |
} |
|
339 |
||
340 |
Q_DECLARE_METATYPE(QTabBar::ButtonPosition) |
|
341 |
void tst_QTabBar::tabButton_data() |
|
342 |
{ |
|
343 |
QTest::addColumn<QTabBar::ButtonPosition>("position"); |
|
344 |
||
345 |
QTest::newRow("left") << QTabBar::LeftSide; |
|
346 |
QTest::newRow("right") << QTabBar::RightSide; |
|
347 |
} |
|
348 |
||
349 |
// QTabBar::setTabButton(index, closeSide, closeButton); |
|
350 |
void tst_QTabBar::tabButton() |
|
351 |
{ |
|
352 |
QFETCH(QTabBar::ButtonPosition, position); |
|
353 |
QTabBar::ButtonPosition otherSide = (position == QTabBar::LeftSide ? QTabBar::RightSide : QTabBar::LeftSide); |
|
354 |
||
355 |
QTabBar tabbar; |
|
356 |
tabbar.resize(500, 200); |
|
357 |
tabbar.show(); |
|
358 |
QTRY_VERIFY(tabbar.isVisible()); |
|
359 |
||
360 |
tabbar.setTabButton(-1, position, 0); |
|
361 |
QVERIFY(tabbar.tabButton(-1, position) == 0); |
|
362 |
QVERIFY(tabbar.tabButton(0, position) == 0); |
|
363 |
||
364 |
tabbar.addTab("foo"); |
|
365 |
QCOMPARE(tabbar.count(), 1); |
|
366 |
tabbar.setTabButton(0, position, 0); |
|
367 |
QVERIFY(tabbar.tabButton(0, position) == 0); |
|
368 |
||
369 |
QPushButton *button = new QPushButton; |
|
370 |
button->show(); |
|
371 |
button->setText("hi"); |
|
372 |
button->resize(10, 10); |
|
373 |
QTRY_VERIFY(button->isVisible()); |
|
374 |
QTRY_VERIFY(button->isVisible()); |
|
375 |
||
376 |
tabbar.setTabButton(0, position, button); |
|
377 |
||
378 |
QCOMPARE(tabbar.tabButton(0, position), static_cast<QWidget *>(button)); |
|
379 |
QTRY_VERIFY(!button->isHidden()); |
|
380 |
QVERIFY(tabbar.tabButton(0, otherSide) == 0); |
|
381 |
QCOMPARE(button->parent(), static_cast<QObject *>(&tabbar)); |
|
382 |
QVERIFY(button->pos() != QPoint(0, 0)); |
|
383 |
||
384 |
QPushButton *button2 = new QPushButton; |
|
385 |
tabbar.setTabButton(0, position, button2); |
|
386 |
QVERIFY(button->isHidden()); |
|
387 |
} |
|
388 |
||
389 |
typedef QList<int> IntList; |
|
390 |
Q_DECLARE_METATYPE(QTabBar::SelectionBehavior) |
|
391 |
Q_DECLARE_METATYPE(IntList) |
|
392 |
#define ONE(x) (IntList() << x) |
|
393 |
void tst_QTabBar::selectionBehaviorOnRemove_data() |
|
394 |
{ |
|
395 |
QTest::addColumn<QTabBar::SelectionBehavior>("selectionBehavior"); |
|
396 |
QTest::addColumn<int>("tabs"); |
|
397 |
QTest::addColumn<IntList>("select"); |
|
398 |
QTest::addColumn<IntList>("remove"); |
|
399 |
QTest::addColumn<int>("expected"); |
|
400 |
||
401 |
// Count select remove current |
|
402 |
QTest::newRow("left-1") << QTabBar::SelectLeftTab << 3 << (IntList() << 0) << ONE(0) << 0; |
|
403 |
||
404 |
QTest::newRow("left-2") << QTabBar::SelectLeftTab << 3 << (IntList() << 0) << ONE(1) << 0; // not removing current |
|
405 |
QTest::newRow("left-3") << QTabBar::SelectLeftTab << 3 << (IntList() << 0) << ONE(2) << 0; // not removing current |
|
406 |
QTest::newRow("left-4") << QTabBar::SelectLeftTab << 3 << (IntList() << 1) << ONE(0) << 0; // not removing current |
|
407 |
QTest::newRow("left-5") << QTabBar::SelectLeftTab << 3 << (IntList() << 1) << ONE(1) << 0; |
|
408 |
QTest::newRow("left-6") << QTabBar::SelectLeftTab << 3 << (IntList() << 1) << ONE(2) << 1; |
|
409 |
QTest::newRow("left-7") << QTabBar::SelectLeftTab << 3 << (IntList() << 2) << ONE(0) << 1; // not removing current |
|
410 |
QTest::newRow("left-8") << QTabBar::SelectLeftTab << 3 << (IntList() << 2) << ONE(1) << 1; // not removing current |
|
411 |
QTest::newRow("left-9") << QTabBar::SelectLeftTab << 3 << (IntList() << 2) << ONE(2) << 1; |
|
412 |
||
413 |
QTest::newRow("right-1") << QTabBar::SelectRightTab << 3 << (IntList() << 0) << ONE(0) << 0; |
|
414 |
QTest::newRow("right-2") << QTabBar::SelectRightTab << 3 << (IntList() << 0) << ONE(1) << 0; // not removing current |
|
415 |
QTest::newRow("right-3") << QTabBar::SelectRightTab << 3 << (IntList() << 0) << ONE(2) << 0; // not removing current |
|
416 |
QTest::newRow("right-4") << QTabBar::SelectRightTab << 3 << (IntList() << 1) << ONE(0) << 0; // not removing current |
|
417 |
QTest::newRow("right-5") << QTabBar::SelectRightTab << 3 << (IntList() << 1) << ONE(1) << 1; |
|
418 |
QTest::newRow("right-6") << QTabBar::SelectRightTab << 3 << (IntList() << 1) << ONE(2) << 1; // not removing current |
|
419 |
QTest::newRow("right-7") << QTabBar::SelectRightTab << 3 << (IntList() << 2) << ONE(0) << 1; // not removing current |
|
420 |
QTest::newRow("right-8") << QTabBar::SelectRightTab << 3 << (IntList() << 2) << ONE(1) << 1; // not removing current |
|
421 |
QTest::newRow("right-9") << QTabBar::SelectRightTab << 3 << (IntList() << 2) << ONE(2) << 1; |
|
422 |
||
423 |
QTest::newRow("previous-0") << QTabBar::SelectPreviousTab << 3 << (IntList()) << ONE(0) << 0; |
|
424 |
QTest::newRow("previous-1") << QTabBar::SelectPreviousTab << 3 << (IntList()) << ONE(1) << 0; // not removing current |
|
425 |
QTest::newRow("previous-2") << QTabBar::SelectPreviousTab << 3 << (IntList()) << ONE(2) << 0; // not removing current |
|
426 |
||
427 |
QTest::newRow("previous-3") << QTabBar::SelectPreviousTab << 3 << (IntList() << 2) << ONE(0) << 1; // not removing current |
|
428 |
QTest::newRow("previous-4") << QTabBar::SelectPreviousTab << 3 << (IntList() << 2) << ONE(1) << 1; // not removing current |
|
429 |
QTest::newRow("previous-5") << QTabBar::SelectPreviousTab << 3 << (IntList() << 2) << ONE(2) << 0; |
|
430 |
||
431 |
// go back one |
|
432 |
QTest::newRow("previous-6") << QTabBar::SelectPreviousTab << 4 << (IntList() << 0 << 2 << 3 << 1) << (IntList() << 1) << 2; |
|
433 |
// go back two |
|
434 |
QTest::newRow("previous-7") << QTabBar::SelectPreviousTab << 4 << (IntList() << 0 << 2 << 3 << 1) << (IntList() << 1 << 2) << 1; |
|
435 |
// go back three |
|
436 |
QTest::newRow("previous-8") << QTabBar::SelectPreviousTab << 4 << (IntList() << 0 << 2 << 3 << 1) << (IntList() << 1 << 2 << 1) << 0; |
|
437 |
||
438 |
// pick from the middle |
|
439 |
QTest::newRow("previous-9") << QTabBar::SelectPreviousTab << 4 << (IntList() << 0 << 2 << 3 << 1) << (IntList() << 2 << 1) << 1; |
|
440 |
||
441 |
// every other one |
|
442 |
QTest::newRow("previous-10") << QTabBar::SelectPreviousTab << 7 << (IntList() << 0 << 2 << 4 << 6) << (IntList() << 6 << 4) << 2; |
|
443 |
||
444 |
||
445 |
} |
|
446 |
||
447 |
void tst_QTabBar::selectionBehaviorOnRemove() |
|
448 |
{ |
|
449 |
QFETCH(QTabBar::SelectionBehavior, selectionBehavior); |
|
450 |
QFETCH(int, tabs); |
|
451 |
QFETCH(IntList, select); |
|
452 |
QFETCH(IntList, remove); |
|
453 |
QFETCH(int, expected); |
|
454 |
||
455 |
QTabBar tabbar; |
|
456 |
tabbar.setSelectionBehaviorOnRemove(selectionBehavior); |
|
457 |
while(--tabs >= 0) |
|
458 |
tabbar.addTab(QString::number(tabs)); |
|
459 |
QCOMPARE(tabbar.currentIndex(), 0); |
|
460 |
while(!select.isEmpty()) |
|
461 |
tabbar.setCurrentIndex(select.takeFirst()); |
|
462 |
while(!remove.isEmpty()) |
|
463 |
tabbar.removeTab(remove.takeFirst()); |
|
464 |
QVERIFY(tabbar.count() > 0); |
|
465 |
QCOMPARE(tabbar.currentIndex(), expected); |
|
466 |
} |
|
467 |
||
468 |
class TabBar : public QTabBar |
|
469 |
{ |
|
470 |
Q_OBJECT |
|
471 |
public: |
|
472 |
void callMoveTab(int from, int to){ moveTab(from, to); } |
|
473 |
}; |
|
474 |
||
475 |
||
476 |
Q_DECLARE_METATYPE(QTabBar::Shape) |
|
477 |
void tst_QTabBar::moveTab_data() |
|
478 |
{ |
|
479 |
QTest::addColumn<QTabBar::Shape>("shape"); |
|
480 |
QTest::addColumn<int>("tabs"); |
|
481 |
QTest::addColumn<int>("from"); |
|
482 |
QTest::addColumn<int>("to"); |
|
483 |
||
484 |
QTest::newRow("null-0") << QTabBar::RoundedNorth << 0 << -1 << -1; |
|
485 |
QTest::newRow("null-1") << QTabBar::RoundedEast << 0 << -1 << -1; |
|
486 |
QTest::newRow("null-2") << QTabBar::RoundedEast << 1 << 0 << 0; |
|
487 |
||
488 |
QTest::newRow("two-0") << QTabBar::RoundedNorth << 2 << 0 << 1; |
|
489 |
QTest::newRow("two-1") << QTabBar::RoundedNorth << 2 << 1 << 0; |
|
490 |
||
491 |
QTest::newRow("five-0") << QTabBar::RoundedNorth << 5 << 1 << 3; // forward |
|
492 |
QTest::newRow("five-1") << QTabBar::RoundedNorth << 5 << 3 << 1; // reverse |
|
493 |
||
494 |
QTest::newRow("five-2") << QTabBar::RoundedNorth << 5 << 0 << 4; // forward |
|
495 |
QTest::newRow("five-3") << QTabBar::RoundedNorth << 5 << 1 << 4; // forward |
|
496 |
QTest::newRow("five-4") << QTabBar::RoundedNorth << 5 << 3 << 4; // forward |
|
497 |
} |
|
498 |
||
499 |
void tst_QTabBar::moveTab() |
|
500 |
{ |
|
501 |
QFETCH(QTabBar::Shape, shape); |
|
502 |
QFETCH(int, tabs); |
|
503 |
QFETCH(int, from); |
|
504 |
QFETCH(int, to); |
|
505 |
||
506 |
TabBar bar; |
|
507 |
bar.setShape(shape); |
|
508 |
while(--tabs >= 0) |
|
509 |
bar.addTab(QString::number(tabs)); |
|
510 |
bar.callMoveTab(from, to); |
|
511 |
} |
|
512 |
||
513 |
||
514 |
class MyTabBar : public QTabBar |
|
515 |
{ |
|
516 |
Q_OBJECT |
|
517 |
public slots: |
|
518 |
void onCurrentChanged() |
|
519 |
{ |
|
520 |
//we just want this to be done once |
|
521 |
disconnect(this, SIGNAL(currentChanged(int)), this, SLOT(onCurrentChanged())); |
|
522 |
removeTab(0); |
|
523 |
} |
|
524 |
}; |
|
525 |
||
526 |
void tst_QTabBar::task251184_removeTab() |
|
527 |
{ |
|
528 |
MyTabBar bar; |
|
529 |
bar.addTab("bar1"); |
|
530 |
bar.addTab("bar2"); |
|
531 |
QCOMPARE(bar.count(), 2); |
|
532 |
QCOMPARE(bar.currentIndex(), 0); |
|
533 |
||
534 |
bar.connect(&bar, SIGNAL(currentChanged(int)), SLOT(onCurrentChanged())); |
|
535 |
bar.setCurrentIndex(1); |
|
536 |
||
537 |
QCOMPARE(bar.count(), 1); |
|
538 |
QCOMPARE(bar.currentIndex(), 0); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
539 |
QCOMPARE(bar.tabText(bar.currentIndex()), QString("bar2")); |
0 | 540 |
} |
541 |
||
542 |
||
543 |
class TitleChangeTabBar : public QTabBar |
|
544 |
{ |
|
545 |
Q_OBJECT |
|
546 |
||
547 |
QTimer timer; |
|
548 |
int count; |
|
549 |
||
550 |
public: |
|
551 |
TitleChangeTabBar(QWidget * parent = 0) : QTabBar(parent), count(0) |
|
552 |
{ |
|
553 |
setMovable(true); |
|
554 |
addTab("0"); |
|
555 |
connect(&timer, SIGNAL(timeout()), this, SLOT(updateTabText())); |
|
556 |
timer.start(1); |
|
557 |
} |
|
558 |
||
559 |
public slots: |
|
560 |
void updateTabText() |
|
561 |
{ |
|
562 |
count++; |
|
563 |
setTabText(0, QString("%1").arg(count)); |
|
564 |
} |
|
565 |
}; |
|
566 |
||
567 |
void tst_QTabBar::changeTitleWhileDoubleClickingTab() |
|
568 |
{ |
|
569 |
TitleChangeTabBar bar; |
|
570 |
QPoint tabPos = bar.tabRect(0).center(); |
|
571 |
||
572 |
for(int i=0; i < 10; i++) |
|
573 |
QTest::mouseDClick(&bar, Qt::LeftButton, 0, tabPos); |
|
574 |
} |
|
575 |
||
576 |
QTEST_MAIN(tst_QTabBar) |
|
577 |
#include "tst_qtabbar.moc" |