0
|
1 |
/****************************************************************************
|
|
2 |
**
|
|
3 |
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
4 |
** All rights reserved.
|
|
5 |
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
6 |
**
|
|
7 |
** This file is part of the test suite of the Qt Toolkit.
|
|
8 |
**
|
|
9 |
** $QT_BEGIN_LICENSE:LGPL$
|
|
10 |
** No Commercial Usage
|
|
11 |
** This file contains pre-release code and may not be distributed.
|
|
12 |
** You may use this file in accordance with the terms and conditions
|
|
13 |
** contained in the Technology Preview License Agreement accompanying
|
|
14 |
** this package.
|
|
15 |
**
|
|
16 |
** GNU Lesser General Public License Usage
|
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
18 |
** General Public License version 2.1 as published by the Free Software
|
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
20 |
** packaging of this file. Please review the following information to
|
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
23 |
**
|
|
24 |
** In addition, as a special exception, Nokia gives you certain additional
|
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception
|
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
27 |
**
|
|
28 |
** If you have questions regarding the use of this file, please contact
|
|
29 |
** Nokia at qt-info@nokia.com.
|
|
30 |
**
|
|
31 |
**
|
|
32 |
**
|
|
33 |
**
|
|
34 |
**
|
|
35 |
**
|
|
36 |
**
|
|
37 |
**
|
|
38 |
** $QT_END_LICENSE$
|
|
39 |
**
|
|
40 |
****************************************************************************/
|
|
41 |
|
|
42 |
|
|
43 |
#include <QtTest/QtTest>
|
|
44 |
#include <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");
|
|
298 |
}
|
|
299 |
|
|
300 |
void tst_QTabBar::removeLastTab()
|
|
301 |
{
|
|
302 |
QTabBar tabbar;
|
|
303 |
QSignalSpy spy(&tabbar, SIGNAL(currentChanged(int)));
|
|
304 |
int index = tabbar.addTab("foo");
|
|
305 |
QCOMPARE(spy.count(), 1);
|
|
306 |
QCOMPARE(spy.at(0).at(0).toInt(), index);
|
|
307 |
spy.clear();
|
|
308 |
|
|
309 |
tabbar.removeTab(index);
|
|
310 |
QCOMPARE(spy.count(), 1);
|
|
311 |
QCOMPARE(spy.at(0).at(0).toInt(), -1);
|
|
312 |
spy.clear();
|
|
313 |
}
|
|
314 |
|
|
315 |
void tst_QTabBar::closeButton()
|
|
316 |
{
|
|
317 |
QTabBar tabbar;
|
|
318 |
QCOMPARE(tabbar.tabsClosable(), false);
|
|
319 |
tabbar.setTabsClosable(true);
|
|
320 |
QCOMPARE(tabbar.tabsClosable(), true);
|
|
321 |
tabbar.addTab("foo");
|
|
322 |
|
|
323 |
QTabBar::ButtonPosition closeSide = (QTabBar::ButtonPosition)tabbar.style()->styleHint(QStyle::SH_TabBar_CloseButtonPosition, 0, &tabbar);
|
|
324 |
QTabBar::ButtonPosition otherSide = (closeSide == QTabBar::LeftSide ? QTabBar::RightSide : QTabBar::LeftSide);
|
|
325 |
QVERIFY(tabbar.tabButton(0, otherSide) == 0);
|
|
326 |
QVERIFY(tabbar.tabButton(0, closeSide) != 0);
|
|
327 |
|
|
328 |
QAbstractButton *button = static_cast<QAbstractButton*>(tabbar.tabButton(0, closeSide));
|
|
329 |
QVERIFY(button);
|
|
330 |
QSignalSpy spy(&tabbar, SIGNAL(tabCloseRequested(int)));
|
|
331 |
button->click();
|
|
332 |
QCOMPARE(tabbar.count(), 1);
|
|
333 |
QCOMPARE(spy.count(), 1);
|
|
334 |
}
|
|
335 |
|
|
336 |
Q_DECLARE_METATYPE(QTabBar::ButtonPosition)
|
|
337 |
void tst_QTabBar::tabButton_data()
|
|
338 |
{
|
|
339 |
QTest::addColumn<QTabBar::ButtonPosition>("position");
|
|
340 |
|
|
341 |
QTest::newRow("left") << QTabBar::LeftSide;
|
|
342 |
QTest::newRow("right") << QTabBar::RightSide;
|
|
343 |
}
|
|
344 |
|
|
345 |
// QTabBar::setTabButton(index, closeSide, closeButton);
|
|
346 |
void tst_QTabBar::tabButton()
|
|
347 |
{
|
|
348 |
QFETCH(QTabBar::ButtonPosition, position);
|
|
349 |
QTabBar::ButtonPosition otherSide = (position == QTabBar::LeftSide ? QTabBar::RightSide : QTabBar::LeftSide);
|
|
350 |
|
|
351 |
QTabBar tabbar;
|
|
352 |
tabbar.resize(500, 200);
|
|
353 |
tabbar.show();
|
|
354 |
QTRY_VERIFY(tabbar.isVisible());
|
|
355 |
|
|
356 |
tabbar.setTabButton(-1, position, 0);
|
|
357 |
QVERIFY(tabbar.tabButton(-1, position) == 0);
|
|
358 |
QVERIFY(tabbar.tabButton(0, position) == 0);
|
|
359 |
|
|
360 |
tabbar.addTab("foo");
|
|
361 |
QCOMPARE(tabbar.count(), 1);
|
|
362 |
tabbar.setTabButton(0, position, 0);
|
|
363 |
QVERIFY(tabbar.tabButton(0, position) == 0);
|
|
364 |
|
|
365 |
QPushButton *button = new QPushButton;
|
|
366 |
button->show();
|
|
367 |
button->setText("hi");
|
|
368 |
button->resize(10, 10);
|
|
369 |
QTRY_VERIFY(button->isVisible());
|
|
370 |
QTRY_VERIFY(button->isVisible());
|
|
371 |
|
|
372 |
tabbar.setTabButton(0, position, button);
|
|
373 |
|
|
374 |
QCOMPARE(tabbar.tabButton(0, position), static_cast<QWidget *>(button));
|
|
375 |
QTRY_VERIFY(!button->isHidden());
|
|
376 |
QVERIFY(tabbar.tabButton(0, otherSide) == 0);
|
|
377 |
QCOMPARE(button->parent(), static_cast<QObject *>(&tabbar));
|
|
378 |
QVERIFY(button->pos() != QPoint(0, 0));
|
|
379 |
|
|
380 |
QPushButton *button2 = new QPushButton;
|
|
381 |
tabbar.setTabButton(0, position, button2);
|
|
382 |
QVERIFY(button->isHidden());
|
|
383 |
}
|
|
384 |
|
|
385 |
typedef QList<int> IntList;
|
|
386 |
Q_DECLARE_METATYPE(QTabBar::SelectionBehavior)
|
|
387 |
Q_DECLARE_METATYPE(IntList)
|
|
388 |
#define ONE(x) (IntList() << x)
|
|
389 |
void tst_QTabBar::selectionBehaviorOnRemove_data()
|
|
390 |
{
|
|
391 |
QTest::addColumn<QTabBar::SelectionBehavior>("selectionBehavior");
|
|
392 |
QTest::addColumn<int>("tabs");
|
|
393 |
QTest::addColumn<IntList>("select");
|
|
394 |
QTest::addColumn<IntList>("remove");
|
|
395 |
QTest::addColumn<int>("expected");
|
|
396 |
|
|
397 |
// Count select remove current
|
|
398 |
QTest::newRow("left-1") << QTabBar::SelectLeftTab << 3 << (IntList() << 0) << ONE(0) << 0;
|
|
399 |
|
|
400 |
QTest::newRow("left-2") << QTabBar::SelectLeftTab << 3 << (IntList() << 0) << ONE(1) << 0; // not removing current
|
|
401 |
QTest::newRow("left-3") << QTabBar::SelectLeftTab << 3 << (IntList() << 0) << ONE(2) << 0; // not removing current
|
|
402 |
QTest::newRow("left-4") << QTabBar::SelectLeftTab << 3 << (IntList() << 1) << ONE(0) << 0; // not removing current
|
|
403 |
QTest::newRow("left-5") << QTabBar::SelectLeftTab << 3 << (IntList() << 1) << ONE(1) << 0;
|
|
404 |
QTest::newRow("left-6") << QTabBar::SelectLeftTab << 3 << (IntList() << 1) << ONE(2) << 1;
|
|
405 |
QTest::newRow("left-7") << QTabBar::SelectLeftTab << 3 << (IntList() << 2) << ONE(0) << 1; // not removing current
|
|
406 |
QTest::newRow("left-8") << QTabBar::SelectLeftTab << 3 << (IntList() << 2) << ONE(1) << 1; // not removing current
|
|
407 |
QTest::newRow("left-9") << QTabBar::SelectLeftTab << 3 << (IntList() << 2) << ONE(2) << 1;
|
|
408 |
|
|
409 |
QTest::newRow("right-1") << QTabBar::SelectRightTab << 3 << (IntList() << 0) << ONE(0) << 0;
|
|
410 |
QTest::newRow("right-2") << QTabBar::SelectRightTab << 3 << (IntList() << 0) << ONE(1) << 0; // not removing current
|
|
411 |
QTest::newRow("right-3") << QTabBar::SelectRightTab << 3 << (IntList() << 0) << ONE(2) << 0; // not removing current
|
|
412 |
QTest::newRow("right-4") << QTabBar::SelectRightTab << 3 << (IntList() << 1) << ONE(0) << 0; // not removing current
|
|
413 |
QTest::newRow("right-5") << QTabBar::SelectRightTab << 3 << (IntList() << 1) << ONE(1) << 1;
|
|
414 |
QTest::newRow("right-6") << QTabBar::SelectRightTab << 3 << (IntList() << 1) << ONE(2) << 1; // not removing current
|
|
415 |
QTest::newRow("right-7") << QTabBar::SelectRightTab << 3 << (IntList() << 2) << ONE(0) << 1; // not removing current
|
|
416 |
QTest::newRow("right-8") << QTabBar::SelectRightTab << 3 << (IntList() << 2) << ONE(1) << 1; // not removing current
|
|
417 |
QTest::newRow("right-9") << QTabBar::SelectRightTab << 3 << (IntList() << 2) << ONE(2) << 1;
|
|
418 |
|
|
419 |
QTest::newRow("previous-0") << QTabBar::SelectPreviousTab << 3 << (IntList()) << ONE(0) << 0;
|
|
420 |
QTest::newRow("previous-1") << QTabBar::SelectPreviousTab << 3 << (IntList()) << ONE(1) << 0; // not removing current
|
|
421 |
QTest::newRow("previous-2") << QTabBar::SelectPreviousTab << 3 << (IntList()) << ONE(2) << 0; // not removing current
|
|
422 |
|
|
423 |
QTest::newRow("previous-3") << QTabBar::SelectPreviousTab << 3 << (IntList() << 2) << ONE(0) << 1; // not removing current
|
|
424 |
QTest::newRow("previous-4") << QTabBar::SelectPreviousTab << 3 << (IntList() << 2) << ONE(1) << 1; // not removing current
|
|
425 |
QTest::newRow("previous-5") << QTabBar::SelectPreviousTab << 3 << (IntList() << 2) << ONE(2) << 0;
|
|
426 |
|
|
427 |
// go back one
|
|
428 |
QTest::newRow("previous-6") << QTabBar::SelectPreviousTab << 4 << (IntList() << 0 << 2 << 3 << 1) << (IntList() << 1) << 2;
|
|
429 |
// go back two
|
|
430 |
QTest::newRow("previous-7") << QTabBar::SelectPreviousTab << 4 << (IntList() << 0 << 2 << 3 << 1) << (IntList() << 1 << 2) << 1;
|
|
431 |
// go back three
|
|
432 |
QTest::newRow("previous-8") << QTabBar::SelectPreviousTab << 4 << (IntList() << 0 << 2 << 3 << 1) << (IntList() << 1 << 2 << 1) << 0;
|
|
433 |
|
|
434 |
// pick from the middle
|
|
435 |
QTest::newRow("previous-9") << QTabBar::SelectPreviousTab << 4 << (IntList() << 0 << 2 << 3 << 1) << (IntList() << 2 << 1) << 1;
|
|
436 |
|
|
437 |
// every other one
|
|
438 |
QTest::newRow("previous-10") << QTabBar::SelectPreviousTab << 7 << (IntList() << 0 << 2 << 4 << 6) << (IntList() << 6 << 4) << 2;
|
|
439 |
|
|
440 |
|
|
441 |
}
|
|
442 |
|
|
443 |
void tst_QTabBar::selectionBehaviorOnRemove()
|
|
444 |
{
|
|
445 |
QFETCH(QTabBar::SelectionBehavior, selectionBehavior);
|
|
446 |
QFETCH(int, tabs);
|
|
447 |
QFETCH(IntList, select);
|
|
448 |
QFETCH(IntList, remove);
|
|
449 |
QFETCH(int, expected);
|
|
450 |
|
|
451 |
QTabBar tabbar;
|
|
452 |
tabbar.setSelectionBehaviorOnRemove(selectionBehavior);
|
|
453 |
while(--tabs >= 0)
|
|
454 |
tabbar.addTab(QString::number(tabs));
|
|
455 |
QCOMPARE(tabbar.currentIndex(), 0);
|
|
456 |
while(!select.isEmpty())
|
|
457 |
tabbar.setCurrentIndex(select.takeFirst());
|
|
458 |
while(!remove.isEmpty())
|
|
459 |
tabbar.removeTab(remove.takeFirst());
|
|
460 |
QVERIFY(tabbar.count() > 0);
|
|
461 |
QCOMPARE(tabbar.currentIndex(), expected);
|
|
462 |
}
|
|
463 |
|
|
464 |
class TabBar : public QTabBar
|
|
465 |
{
|
|
466 |
Q_OBJECT
|
|
467 |
public:
|
|
468 |
void callMoveTab(int from, int to){ moveTab(from, to); }
|
|
469 |
};
|
|
470 |
|
|
471 |
|
|
472 |
Q_DECLARE_METATYPE(QTabBar::Shape)
|
|
473 |
void tst_QTabBar::moveTab_data()
|
|
474 |
{
|
|
475 |
QTest::addColumn<QTabBar::Shape>("shape");
|
|
476 |
QTest::addColumn<int>("tabs");
|
|
477 |
QTest::addColumn<int>("from");
|
|
478 |
QTest::addColumn<int>("to");
|
|
479 |
|
|
480 |
QTest::newRow("null-0") << QTabBar::RoundedNorth << 0 << -1 << -1;
|
|
481 |
QTest::newRow("null-1") << QTabBar::RoundedEast << 0 << -1 << -1;
|
|
482 |
QTest::newRow("null-2") << QTabBar::RoundedEast << 1 << 0 << 0;
|
|
483 |
|
|
484 |
QTest::newRow("two-0") << QTabBar::RoundedNorth << 2 << 0 << 1;
|
|
485 |
QTest::newRow("two-1") << QTabBar::RoundedNorth << 2 << 1 << 0;
|
|
486 |
|
|
487 |
QTest::newRow("five-0") << QTabBar::RoundedNorth << 5 << 1 << 3; // forward
|
|
488 |
QTest::newRow("five-1") << QTabBar::RoundedNorth << 5 << 3 << 1; // reverse
|
|
489 |
|
|
490 |
QTest::newRow("five-2") << QTabBar::RoundedNorth << 5 << 0 << 4; // forward
|
|
491 |
QTest::newRow("five-3") << QTabBar::RoundedNorth << 5 << 1 << 4; // forward
|
|
492 |
QTest::newRow("five-4") << QTabBar::RoundedNorth << 5 << 3 << 4; // forward
|
|
493 |
}
|
|
494 |
|
|
495 |
void tst_QTabBar::moveTab()
|
|
496 |
{
|
|
497 |
QFETCH(QTabBar::Shape, shape);
|
|
498 |
QFETCH(int, tabs);
|
|
499 |
QFETCH(int, from);
|
|
500 |
QFETCH(int, to);
|
|
501 |
|
|
502 |
TabBar bar;
|
|
503 |
bar.setShape(shape);
|
|
504 |
while(--tabs >= 0)
|
|
505 |
bar.addTab(QString::number(tabs));
|
|
506 |
bar.callMoveTab(from, to);
|
|
507 |
}
|
|
508 |
|
|
509 |
|
|
510 |
class MyTabBar : public QTabBar
|
|
511 |
{
|
|
512 |
Q_OBJECT
|
|
513 |
public slots:
|
|
514 |
void onCurrentChanged()
|
|
515 |
{
|
|
516 |
//we just want this to be done once
|
|
517 |
disconnect(this, SIGNAL(currentChanged(int)), this, SLOT(onCurrentChanged()));
|
|
518 |
removeTab(0);
|
|
519 |
}
|
|
520 |
};
|
|
521 |
|
|
522 |
void tst_QTabBar::task251184_removeTab()
|
|
523 |
{
|
|
524 |
MyTabBar bar;
|
|
525 |
bar.addTab("bar1");
|
|
526 |
bar.addTab("bar2");
|
|
527 |
QCOMPARE(bar.count(), 2);
|
|
528 |
QCOMPARE(bar.currentIndex(), 0);
|
|
529 |
|
|
530 |
bar.connect(&bar, SIGNAL(currentChanged(int)), SLOT(onCurrentChanged()));
|
|
531 |
bar.setCurrentIndex(1);
|
|
532 |
|
|
533 |
QCOMPARE(bar.count(), 1);
|
|
534 |
QCOMPARE(bar.currentIndex(), 0);
|
|
535 |
QCOMPARE(bar.tabText(bar.currentIndex()), QString("bar2"));
|
|
536 |
}
|
|
537 |
|
|
538 |
|
|
539 |
class TitleChangeTabBar : public QTabBar
|
|
540 |
{
|
|
541 |
Q_OBJECT
|
|
542 |
|
|
543 |
QTimer timer;
|
|
544 |
int count;
|
|
545 |
|
|
546 |
public:
|
|
547 |
TitleChangeTabBar(QWidget * parent = 0) : QTabBar(parent), count(0)
|
|
548 |
{
|
|
549 |
setMovable(true);
|
|
550 |
addTab("0");
|
|
551 |
connect(&timer, SIGNAL(timeout()), this, SLOT(updateTabText()));
|
|
552 |
timer.start(1);
|
|
553 |
}
|
|
554 |
|
|
555 |
public slots:
|
|
556 |
void updateTabText()
|
|
557 |
{
|
|
558 |
count++;
|
|
559 |
setTabText(0, QString("%1").arg(count));
|
|
560 |
}
|
|
561 |
};
|
|
562 |
|
|
563 |
void tst_QTabBar::changeTitleWhileDoubleClickingTab()
|
|
564 |
{
|
|
565 |
TitleChangeTabBar bar;
|
|
566 |
QPoint tabPos = bar.tabRect(0).center();
|
|
567 |
|
|
568 |
for(int i=0; i < 10; i++)
|
|
569 |
QTest::mouseDClick(&bar, Qt::LeftButton, 0, tabPos);
|
|
570 |
}
|
|
571 |
|
|
572 |
QTEST_MAIN(tst_QTabBar)
|
|
573 |
#include "tst_qtabbar.moc"
|