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 0 | 1918ee327afb |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
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 |
||
46 |
#include <qabstractbutton.h> |
|
47 |
#include <qaction.h> |
|
48 |
#include <qlayout.h> |
|
49 |
#include <qmainwindow.h> |
|
50 |
#include <qpixmap.h> |
|
51 |
#include <qstyle.h> |
|
52 |
#include <qtoolbar.h> |
|
53 |
#include <qwidgetaction.h> |
|
54 |
#include <qtoolbutton.h> |
|
55 |
#include <qlineedit.h> |
|
56 |
#include <qkeysequence.h> |
|
57 |
#include <qmenu.h> |
|
58 |
#include <private/qtoolbarextension_p.h> |
|
59 |
||
60 |
#include "../../shared/util.h" |
|
61 |
||
62 |
//TESTED_FILES= |
|
63 |
||
64 |
QT_FORWARD_DECLARE_CLASS(QAction) |
|
65 |
||
66 |
class tst_QToolBar : public QObject |
|
67 |
{ |
|
68 |
Q_OBJECT |
|
69 |
||
70 |
public: |
|
71 |
tst_QToolBar(); |
|
72 |
||
73 |
public slots: |
|
74 |
void slot(); |
|
75 |
void slot(QAction *action); |
|
76 |
||
77 |
private slots: |
|
78 |
void setMovable(); |
|
79 |
void isMovable(); |
|
80 |
void setAllowedAreas(); |
|
81 |
void allowedAreas(); |
|
82 |
void isAreaAllowed(); |
|
83 |
void setOrientation(); |
|
84 |
void orientation(); |
|
85 |
void clear(); |
|
86 |
void addAction(); |
|
87 |
void insertAction(); |
|
88 |
void addSeparator(); |
|
89 |
void insertSeparator(); |
|
90 |
void addWidget(); |
|
91 |
void insertWidget(); |
|
92 |
void actionGeometry(); |
|
93 |
void actionAt(); |
|
94 |
void toggleViewAction(); |
|
95 |
void iconSize(); |
|
96 |
void setIconSize(); |
|
97 |
void toolButtonStyle(); |
|
98 |
void setToolButtonStyle(); |
|
99 |
void actionTriggered(); |
|
100 |
void movableChanged(); |
|
101 |
void allowedAreasChanged(); |
|
102 |
void orientationChanged(); |
|
103 |
void iconSizeChanged(); |
|
104 |
void toolButtonStyleChanged(); |
|
105 |
void actionOwnership(); |
|
106 |
void widgetAction(); |
|
107 |
void accel(); |
|
108 |
||
109 |
void task191727_layout(); |
|
110 |
void task197996_visibility(); |
|
111 |
}; |
|
112 |
||
113 |
||
114 |
QAction *triggered = 0; |
|
115 |
||
116 |
tst_QToolBar::tst_QToolBar() |
|
117 |
{ |
|
118 |
qRegisterMetaType<QSize>("QSize"); |
|
119 |
qRegisterMetaType<Qt::Orientation>("Qt::Orientation"); |
|
120 |
qRegisterMetaType<Qt::ToolBarAreas>("Qt::ToolBarAreas"); |
|
121 |
qRegisterMetaType<Qt::ToolButtonStyle>("Qt::ToolButtonStyle"); |
|
122 |
} |
|
123 |
||
124 |
void tst_QToolBar::slot() |
|
125 |
{ } |
|
126 |
||
127 |
void tst_QToolBar::slot(QAction *action) |
|
128 |
{ ::triggered = action; } |
|
129 |
||
130 |
void tst_QToolBar::setMovable() |
|
131 |
{ DEPENDS_ON("isMovable()"); } |
|
132 |
||
133 |
void tst_QToolBar::isMovable() |
|
134 |
{ |
|
135 |
#define DO_TEST \ |
|
136 |
do { \ |
|
137 |
QVERIFY(tb.isMovable()); \ |
|
138 |
tb.setMovable(false); \ |
|
139 |
QVERIFY(!tb.isMovable()); \ |
|
140 |
QCOMPARE(spy.count(), 1); \ |
|
141 |
QCOMPARE(spy.at(0).value(0).toBool(), tb.isMovable()); \ |
|
142 |
spy.clear(); \ |
|
143 |
tb.setMovable(tb.isMovable()); \ |
|
144 |
QCOMPARE(spy.count(), 0); \ |
|
145 |
spy.clear(); \ |
|
146 |
tb.setMovable(true); \ |
|
147 |
QVERIFY(tb.isMovable()); \ |
|
148 |
QCOMPARE(spy.count(), 1); \ |
|
149 |
QCOMPARE(spy.at(0).value(0).toBool(), tb.isMovable()); \ |
|
150 |
spy.clear(); \ |
|
151 |
tb.setMovable(tb.isMovable()); \ |
|
152 |
QCOMPARE(spy.count(), 0); \ |
|
153 |
spy.clear(); \ |
|
154 |
} while (false) |
|
155 |
||
156 |
QMainWindow mw; |
|
157 |
QToolBar tb; |
|
158 |
||
159 |
QCOMPARE(tb.isMovable(), (bool)qApp->style()->styleHint(QStyle::SH_ToolBar_Movable)); |
|
160 |
if (!tb.isMovable()) |
|
161 |
tb.setMovable(true); |
|
162 |
||
163 |
QSignalSpy spy(&tb, SIGNAL(movableChanged(bool))); |
|
164 |
||
165 |
DO_TEST; |
|
166 |
mw.addToolBar(&tb); |
|
167 |
DO_TEST; |
|
168 |
mw.removeToolBar(&tb); |
|
169 |
DO_TEST; |
|
170 |
} |
|
171 |
||
172 |
void tst_QToolBar::setAllowedAreas() |
|
173 |
{ DEPENDS_ON("allowedAreas()"); } |
|
174 |
||
175 |
void tst_QToolBar::allowedAreas() |
|
176 |
{ |
|
177 |
QToolBar tb; |
|
178 |
||
179 |
QSignalSpy spy(&tb, SIGNAL(allowedAreasChanged(Qt::ToolBarAreas))); |
|
180 |
||
181 |
// default |
|
182 |
QCOMPARE((int)tb.allowedAreas(), (int)Qt::AllToolBarAreas); |
|
183 |
QVERIFY(tb.isAreaAllowed(Qt::LeftToolBarArea)); |
|
184 |
QVERIFY(tb.isAreaAllowed(Qt::RightToolBarArea)); |
|
185 |
QVERIFY(tb.isAreaAllowed(Qt::TopToolBarArea)); |
|
186 |
QVERIFY(tb.isAreaAllowed(Qt::BottomToolBarArea)); |
|
187 |
||
188 |
// a single dock window area |
|
189 |
tb.setAllowedAreas(Qt::LeftToolBarArea); |
|
190 |
QCOMPARE((int)tb.allowedAreas(), (int)Qt::LeftToolBarArea); |
|
191 |
QVERIFY(tb.isAreaAllowed(Qt::LeftToolBarArea)); |
|
192 |
QVERIFY(!tb.isAreaAllowed(Qt::RightToolBarArea)); |
|
193 |
QVERIFY(!tb.isAreaAllowed(Qt::TopToolBarArea)); |
|
194 |
QVERIFY(!tb.isAreaAllowed(Qt::BottomToolBarArea)); |
|
195 |
QCOMPARE(spy.count(), 1); |
|
196 |
QCOMPARE(*static_cast<const Qt::ToolBarAreas *>(spy.at(0).value(0).constData()), |
|
197 |
tb.allowedAreas()); |
|
198 |
spy.clear(); |
|
199 |
tb.setAllowedAreas(tb.allowedAreas()); |
|
200 |
QCOMPARE(spy.count(), 0); |
|
201 |
||
202 |
tb.setAllowedAreas(Qt::RightToolBarArea); |
|
203 |
QCOMPARE((int)tb.allowedAreas(), (int)Qt::RightToolBarArea); |
|
204 |
QVERIFY(!tb.isAreaAllowed(Qt::LeftToolBarArea)); |
|
205 |
QVERIFY(tb.isAreaAllowed(Qt::RightToolBarArea)); |
|
206 |
QVERIFY(!tb.isAreaAllowed(Qt::TopToolBarArea)); |
|
207 |
QVERIFY(!tb.isAreaAllowed(Qt::BottomToolBarArea)); |
|
208 |
QCOMPARE(spy.count(), 1); |
|
209 |
QCOMPARE(*static_cast<const Qt::ToolBarAreas *>(spy.at(0).value(0).constData()), |
|
210 |
tb.allowedAreas()); |
|
211 |
spy.clear(); |
|
212 |
tb.setAllowedAreas(tb.allowedAreas()); |
|
213 |
QCOMPARE(spy.count(), 0); |
|
214 |
||
215 |
tb.setAllowedAreas(Qt::TopToolBarArea); |
|
216 |
QCOMPARE((int)tb.allowedAreas(), (int)Qt::TopToolBarArea); |
|
217 |
QVERIFY(!tb.isAreaAllowed(Qt::LeftToolBarArea)); |
|
218 |
QVERIFY(!tb.isAreaAllowed(Qt::RightToolBarArea)); |
|
219 |
QVERIFY(tb.isAreaAllowed(Qt::TopToolBarArea)); |
|
220 |
QVERIFY(!tb.isAreaAllowed(Qt::BottomToolBarArea)); |
|
221 |
QCOMPARE(spy.count(), 1); |
|
222 |
QCOMPARE(*static_cast<const Qt::ToolBarAreas *>(spy.at(0).value(0).constData()), |
|
223 |
tb.allowedAreas()); |
|
224 |
spy.clear(); |
|
225 |
tb.setAllowedAreas(tb.allowedAreas()); |
|
226 |
QCOMPARE(spy.count(), 0); |
|
227 |
||
228 |
tb.setAllowedAreas(Qt::BottomToolBarArea); |
|
229 |
QCOMPARE((int)tb.allowedAreas(), (int)Qt::BottomToolBarArea); |
|
230 |
QVERIFY(!tb.isAreaAllowed(Qt::LeftToolBarArea)); |
|
231 |
QVERIFY(!tb.isAreaAllowed(Qt::RightToolBarArea)); |
|
232 |
QVERIFY(!tb.isAreaAllowed(Qt::TopToolBarArea)); |
|
233 |
QVERIFY(tb.isAreaAllowed(Qt::BottomToolBarArea)); |
|
234 |
QCOMPARE(spy.count(), 1); |
|
235 |
QCOMPARE(*static_cast<const Qt::ToolBarAreas *>(spy.at(0).value(0).constData()), |
|
236 |
tb.allowedAreas()); |
|
237 |
spy.clear(); |
|
238 |
tb.setAllowedAreas(tb.allowedAreas()); |
|
239 |
QCOMPARE(spy.count(), 0); |
|
240 |
||
241 |
// multiple dock window areas |
|
242 |
tb.setAllowedAreas(Qt::TopToolBarArea | Qt::BottomToolBarArea); |
|
243 |
QCOMPARE(tb.allowedAreas(), Qt::TopToolBarArea | Qt::BottomToolBarArea); |
|
244 |
QVERIFY(!tb.isAreaAllowed(Qt::LeftToolBarArea)); |
|
245 |
QVERIFY(!tb.isAreaAllowed(Qt::RightToolBarArea)); |
|
246 |
QVERIFY(tb.isAreaAllowed(Qt::TopToolBarArea)); |
|
247 |
QVERIFY(tb.isAreaAllowed(Qt::BottomToolBarArea)); |
|
248 |
QCOMPARE(spy.count(), 1); |
|
249 |
QCOMPARE(*static_cast<const Qt::ToolBarAreas *>(spy.at(0).value(0).constData()), |
|
250 |
tb.allowedAreas()); |
|
251 |
spy.clear(); |
|
252 |
tb.setAllowedAreas(tb.allowedAreas()); |
|
253 |
QCOMPARE(spy.count(), 0); |
|
254 |
||
255 |
tb.setAllowedAreas(Qt::LeftToolBarArea | Qt::RightToolBarArea); |
|
256 |
QCOMPARE(tb.allowedAreas(), Qt::LeftToolBarArea | Qt::RightToolBarArea); |
|
257 |
QVERIFY(tb.isAreaAllowed(Qt::LeftToolBarArea)); |
|
258 |
QVERIFY(tb.isAreaAllowed(Qt::RightToolBarArea)); |
|
259 |
QVERIFY(!tb.isAreaAllowed(Qt::TopToolBarArea)); |
|
260 |
QVERIFY(!tb.isAreaAllowed(Qt::BottomToolBarArea)); |
|
261 |
QCOMPARE(spy.count(), 1); |
|
262 |
QCOMPARE(*static_cast<const Qt::ToolBarAreas *>(spy.at(0).value(0).constData()), |
|
263 |
tb.allowedAreas()); |
|
264 |
spy.clear(); |
|
265 |
tb.setAllowedAreas(tb.allowedAreas()); |
|
266 |
QCOMPARE(spy.count(), 0); |
|
267 |
||
268 |
tb.setAllowedAreas(Qt::TopToolBarArea | Qt::LeftToolBarArea); |
|
269 |
QCOMPARE(tb.allowedAreas(), Qt::TopToolBarArea | Qt::LeftToolBarArea); |
|
270 |
QVERIFY(tb.isAreaAllowed(Qt::LeftToolBarArea)); |
|
271 |
QVERIFY(!tb.isAreaAllowed(Qt::RightToolBarArea)); |
|
272 |
QVERIFY(tb.isAreaAllowed(Qt::TopToolBarArea)); |
|
273 |
QVERIFY(!tb.isAreaAllowed(Qt::BottomToolBarArea)); |
|
274 |
QCOMPARE(spy.count(), 1); |
|
275 |
QCOMPARE(*static_cast<const Qt::ToolBarAreas *>(spy.at(0).value(0).constData()), |
|
276 |
tb.allowedAreas()); |
|
277 |
spy.clear(); |
|
278 |
tb.setAllowedAreas(tb.allowedAreas()); |
|
279 |
QCOMPARE(spy.count(), 0); |
|
280 |
||
281 |
tb.setAllowedAreas(Qt::BottomToolBarArea | Qt::RightToolBarArea); |
|
282 |
QCOMPARE(tb.allowedAreas(), Qt::BottomToolBarArea | Qt::RightToolBarArea); |
|
283 |
QVERIFY(!tb.isAreaAllowed(Qt::LeftToolBarArea)); |
|
284 |
QVERIFY(tb.isAreaAllowed(Qt::RightToolBarArea)); |
|
285 |
QVERIFY(!tb.isAreaAllowed(Qt::TopToolBarArea)); |
|
286 |
QVERIFY(tb.isAreaAllowed(Qt::BottomToolBarArea)); |
|
287 |
QCOMPARE(spy.count(), 1); |
|
288 |
QCOMPARE(*static_cast<const Qt::ToolBarAreas *>(spy.at(0).value(0).constData()), |
|
289 |
tb.allowedAreas()); |
|
290 |
spy.clear(); |
|
291 |
tb.setAllowedAreas(tb.allowedAreas()); |
|
292 |
QCOMPARE(spy.count(), 0); |
|
293 |
} |
|
294 |
||
295 |
void tst_QToolBar::isAreaAllowed() |
|
296 |
{ DEPENDS_ON("allowedAreas()"); } |
|
297 |
||
298 |
void tst_QToolBar::setOrientation() |
|
299 |
{ DEPENDS_ON("orientation()"); } |
|
300 |
||
301 |
void tst_QToolBar::orientation() |
|
302 |
{ |
|
303 |
QToolBar tb; |
|
304 |
QCOMPARE(tb.orientation(), Qt::Horizontal); |
|
305 |
||
306 |
QSignalSpy spy(&tb, SIGNAL(orientationChanged(Qt::Orientation))); |
|
307 |
||
308 |
tb.setOrientation(Qt::Vertical); |
|
309 |
QCOMPARE(tb.orientation(), Qt::Vertical); |
|
310 |
QCOMPARE(spy.count(), 1); |
|
311 |
QCOMPARE(*static_cast<const Qt::Orientation *>(spy.at(0).value(0).constData()), |
|
312 |
tb.orientation()); |
|
313 |
spy.clear(); |
|
314 |
tb.setOrientation(tb.orientation()); |
|
315 |
QCOMPARE(spy.count(), 0); |
|
316 |
||
317 |
tb.setOrientation(Qt::Horizontal); |
|
318 |
QCOMPARE(tb.orientation(), Qt::Horizontal); |
|
319 |
QCOMPARE(spy.count(), 1); |
|
320 |
QCOMPARE(*static_cast<const Qt::Orientation *>(spy.at(0).value(0).constData()), |
|
321 |
tb.orientation()); |
|
322 |
spy.clear(); |
|
323 |
tb.setOrientation(tb.orientation()); |
|
324 |
QCOMPARE(spy.count(), 0); |
|
325 |
||
326 |
tb.setOrientation(Qt::Vertical); |
|
327 |
QCOMPARE(tb.orientation(), Qt::Vertical); |
|
328 |
QCOMPARE(spy.count(), 1); |
|
329 |
QCOMPARE(*static_cast<const Qt::Orientation *>(spy.at(0).value(0).constData()), |
|
330 |
tb.orientation()); |
|
331 |
spy.clear(); |
|
332 |
tb.setOrientation(tb.orientation()); |
|
333 |
QCOMPARE(spy.count(), 0); |
|
334 |
||
335 |
tb.setOrientation(Qt::Horizontal); |
|
336 |
QCOMPARE(tb.orientation(), Qt::Horizontal); |
|
337 |
QCOMPARE(spy.count(), 1); |
|
338 |
QCOMPARE(*static_cast<const Qt::Orientation *>(spy.at(0).value(0).constData()), |
|
339 |
tb.orientation()); |
|
340 |
spy.clear(); |
|
341 |
tb.setOrientation(tb.orientation()); |
|
342 |
QCOMPARE(spy.count(), 0); |
|
343 |
||
344 |
tb.setOrientation(Qt::Vertical); |
|
345 |
QCOMPARE(tb.orientation(), Qt::Vertical); |
|
346 |
QCOMPARE(spy.count(), 1); |
|
347 |
QCOMPARE(*static_cast<const Qt::Orientation *>(spy.at(0).value(0).constData()), |
|
348 |
tb.orientation()); |
|
349 |
spy.clear(); |
|
350 |
tb.setOrientation(tb.orientation()); |
|
351 |
QCOMPARE(spy.count(), 0); |
|
352 |
} |
|
353 |
||
354 |
void tst_QToolBar::clear() |
|
355 |
{ |
|
356 |
DEPENDS_ON("addAction()"); |
|
357 |
DEPENDS_ON("insertAction()"); |
|
358 |
DEPENDS_ON("addSeparator()"); |
|
359 |
DEPENDS_ON("insertSeparator()"); |
|
360 |
DEPENDS_ON("addWidget()"); |
|
361 |
DEPENDS_ON("insertWidget()"); |
|
362 |
} |
|
363 |
||
364 |
void tst_QToolBar::addAction() |
|
365 |
{ |
|
366 |
QToolBar tb; |
|
367 |
||
368 |
{ |
|
369 |
QAction action(0); |
|
370 |
||
371 |
QCOMPARE(tb.actions().count(), 0); |
|
372 |
tb.addAction(&action); |
|
373 |
QCOMPARE(tb.actions().count(), 1); |
|
374 |
QCOMPARE(tb.actions()[0], &action); |
|
375 |
||
376 |
tb.clear(); |
|
377 |
QCOMPARE(tb.actions().count(), 0); |
|
378 |
} |
|
379 |
||
380 |
{ |
|
381 |
QString text = "text"; |
|
382 |
QPixmap pm(32, 32); |
|
383 |
pm.fill(Qt::blue); |
|
384 |
QIcon icon = pm; |
|
385 |
||
386 |
QAction *action1 = tb.addAction(text); |
|
387 |
QCOMPARE(text, action1->text()); |
|
388 |
||
389 |
QAction *action2 = tb.addAction(icon, text); |
|
390 |
QCOMPARE(icon, action2->icon()); |
|
391 |
QCOMPARE(text, action2->text()); |
|
392 |
||
393 |
QAction *action3 = tb.addAction(text, this, SLOT(slot())); |
|
394 |
QCOMPARE(text, action3->text()); |
|
395 |
||
396 |
QAction *action4 = tb.addAction(icon, text, this, SLOT(slot())); |
|
397 |
QCOMPARE(icon, action4->icon()); |
|
398 |
QCOMPARE(text, action4->text()); |
|
399 |
||
400 |
QCOMPARE(tb.actions().count(), 4); |
|
401 |
QCOMPARE(tb.actions()[0], action1); |
|
402 |
QCOMPARE(tb.actions()[1], action2); |
|
403 |
QCOMPARE(tb.actions()[2], action3); |
|
404 |
QCOMPARE(tb.actions()[3], action4); |
|
405 |
||
406 |
tb.clear(); |
|
407 |
QCOMPARE(tb.actions().count(), 0); |
|
408 |
} |
|
409 |
} |
|
410 |
||
411 |
void tst_QToolBar::insertAction() |
|
412 |
{ |
|
413 |
QToolBar tb; |
|
414 |
QAction action1(0); |
|
415 |
QAction action2(0); |
|
416 |
QAction action3(0); |
|
417 |
QAction action4(0); |
|
418 |
||
419 |
QCOMPARE(tb.actions().count(), 0); |
|
420 |
tb.insertAction(0, &action1); |
|
421 |
tb.insertAction(&action1, &action2); |
|
422 |
tb.insertAction(&action2, &action3); |
|
423 |
tb.insertAction(&action3, &action4); |
|
424 |
QCOMPARE(tb.actions().count(), 4); |
|
425 |
QCOMPARE(tb.actions()[0], &action4); |
|
426 |
QCOMPARE(tb.actions()[1], &action3); |
|
427 |
QCOMPARE(tb.actions()[2], &action2); |
|
428 |
QCOMPARE(tb.actions()[3], &action1); |
|
429 |
||
430 |
tb.clear(); |
|
431 |
QCOMPARE(tb.actions().count(), 0); |
|
432 |
} |
|
433 |
||
434 |
void tst_QToolBar::addSeparator() |
|
435 |
{ |
|
436 |
QToolBar tb; |
|
437 |
||
438 |
QAction action1(0); |
|
439 |
QAction action2(0); |
|
440 |
||
441 |
tb.addAction(&action1); |
|
442 |
QAction *sep = tb.addSeparator(); |
|
443 |
tb.addAction(&action2); |
|
444 |
||
445 |
QCOMPARE(tb.actions().count(), 3); |
|
446 |
QCOMPARE(tb.actions()[0], &action1); |
|
447 |
QCOMPARE(tb.actions()[1], sep); |
|
448 |
QCOMPARE(tb.actions()[2], &action2); |
|
449 |
||
450 |
tb.clear(); |
|
451 |
QCOMPARE(tb.actions().count(), 0); |
|
452 |
} |
|
453 |
||
454 |
void tst_QToolBar::insertSeparator() |
|
455 |
{ |
|
456 |
QToolBar tb; |
|
457 |
||
458 |
QAction action1(0); |
|
459 |
QAction action2(0); |
|
460 |
||
461 |
tb.addAction(&action1); |
|
462 |
tb.addAction(&action2); |
|
463 |
QAction *sep = tb.insertSeparator(&action2); |
|
464 |
||
465 |
QCOMPARE(tb.actions().count(), 3); |
|
466 |
QCOMPARE(tb.actions()[0], &action1); |
|
467 |
QCOMPARE(tb.actions()[1], sep); |
|
468 |
QCOMPARE(tb.actions()[2], &action2); |
|
469 |
||
470 |
tb.clear(); |
|
471 |
QCOMPARE(tb.actions().count(), 0); |
|
472 |
} |
|
473 |
||
474 |
void tst_QToolBar::addWidget() |
|
475 |
{ |
|
476 |
QToolBar tb; |
|
477 |
QWidget w(&tb); |
|
478 |
||
479 |
QAction action1(0); |
|
480 |
QAction action2(0); |
|
481 |
||
482 |
tb.addAction(&action1); |
|
483 |
QAction *widget = tb.addWidget(&w); |
|
484 |
tb.addAction(&action2); |
|
485 |
||
486 |
QCOMPARE(tb.actions().count(), 3); |
|
487 |
QCOMPARE(tb.actions()[0], &action1); |
|
488 |
QCOMPARE(tb.actions()[1], widget); |
|
489 |
QCOMPARE(tb.actions()[2], &action2); |
|
490 |
||
491 |
// it should be possible to reuse the action returned by |
|
492 |
// addWidget() to place the widget somewhere else in the toolbar |
|
493 |
tb.removeAction(widget); |
|
494 |
QCOMPARE(tb.actions().count(), 2); |
|
495 |
QCOMPARE(tb.actions()[0], &action1); |
|
496 |
QCOMPARE(tb.actions()[1], &action2); |
|
497 |
||
498 |
tb.addAction(widget); |
|
499 |
QCOMPARE(tb.actions().count(), 3); |
|
500 |
QCOMPARE(tb.actions()[0], &action1); |
|
501 |
QCOMPARE(tb.actions()[1], &action2); |
|
502 |
QCOMPARE(tb.actions()[2], widget); |
|
503 |
||
504 |
tb.clear(); |
|
505 |
QCOMPARE(tb.actions().count(), 0); |
|
506 |
} |
|
507 |
||
508 |
void tst_QToolBar::insertWidget() |
|
509 |
{ |
|
510 |
QToolBar tb; |
|
511 |
QWidget w(&tb); |
|
512 |
||
513 |
QAction action1(0); |
|
514 |
QAction action2(0); |
|
515 |
||
516 |
tb.addAction(&action1); |
|
517 |
tb.addAction(&action2); |
|
518 |
QAction *widget = tb.insertWidget(&action2, &w); |
|
519 |
||
520 |
QCOMPARE(tb.actions().count(), 3); |
|
521 |
QCOMPARE(tb.actions()[0], &action1); |
|
522 |
QCOMPARE(tb.actions()[1], widget); |
|
523 |
QCOMPARE(tb.actions()[2], &action2); |
|
524 |
||
525 |
// it should be possible to reuse the action returned by |
|
526 |
// addWidget() to place the widget somewhere else in the toolbar |
|
527 |
tb.removeAction(widget); |
|
528 |
QCOMPARE(tb.actions().count(), 2); |
|
529 |
QCOMPARE(tb.actions()[0], &action1); |
|
530 |
QCOMPARE(tb.actions()[1], &action2); |
|
531 |
||
532 |
tb.insertAction(&action1, widget); |
|
533 |
QCOMPARE(tb.actions().count(), 3); |
|
534 |
QCOMPARE(tb.actions()[0], widget); |
|
535 |
QCOMPARE(tb.actions()[1], &action1); |
|
536 |
QCOMPARE(tb.actions()[2], &action2); |
|
537 |
||
538 |
tb.clear(); |
|
539 |
QCOMPARE(tb.actions().count(), 0); |
|
540 |
||
541 |
{ |
|
542 |
QToolBar tb; |
|
543 |
QPointer<QWidget> widget = new QWidget; |
|
544 |
QAction *action = tb.addWidget(widget); |
|
545 |
QVERIFY(action->parent() == &tb); |
|
546 |
||
547 |
QToolBar tb2; |
|
548 |
tb.removeAction(action); |
|
549 |
tb2.addAction(action); |
|
550 |
QVERIFY(widget && widget->parent() == &tb2); |
|
551 |
QVERIFY(action->parent() == &tb2); |
|
552 |
} |
|
553 |
} |
|
554 |
||
555 |
void tst_QToolBar::actionGeometry() |
|
556 |
{ |
|
557 |
QToolBar tb; |
|
558 |
||
559 |
QAction action1(0); |
|
560 |
QAction action2(0); |
|
561 |
QAction action3(0); |
|
562 |
QAction action4(0); |
|
563 |
||
564 |
tb.addAction(&action1); |
|
565 |
tb.addAction(&action2); |
|
566 |
tb.addAction(&action3); |
|
567 |
tb.addAction(&action4); |
|
568 |
||
569 |
tb.show(); |
|
570 |
#ifdef Q_WS_X11 |
|
571 |
qt_x11_wait_for_window_manager(&tb); |
|
572 |
#endif |
|
573 |
||
574 |
QList<QToolBarExtension *> extensions = tb.findChildren<QToolBarExtension *>(); |
|
575 |
||
576 |
QRect rect01; |
|
577 |
QRect rect02; |
|
578 |
QRect rect03; |
|
579 |
QRect rect04; |
|
580 |
QMenu *popupMenu; |
|
581 |
||
582 |
if (extensions.size() != 0) |
|
583 |
{ |
|
584 |
QToolBarExtension *extension = extensions.at(0); |
|
585 |
if (extension->isVisible()) { |
|
586 |
QRect rect0 = extension->geometry(); |
|
587 |
QTest::mouseClick( extension, Qt::LeftButton, 0, rect0.center(), -1 ); |
|
588 |
QApplication::processEvents(); |
|
589 |
popupMenu = qobject_cast<QMenu *>(extension->menu()); |
|
590 |
rect01 = popupMenu->actionGeometry(&action1); |
|
591 |
rect02 = popupMenu->actionGeometry(&action2); |
|
592 |
rect03 = popupMenu->actionGeometry(&action3); |
|
593 |
rect04 = popupMenu->actionGeometry(&action4); |
|
594 |
} |
|
595 |
} |
|
596 |
||
597 |
QRect rect1 = tb.actionGeometry(&action1); |
|
598 |
QRect rect2 = tb.actionGeometry(&action2); |
|
599 |
QRect rect3 = tb.actionGeometry(&action3); |
|
600 |
QRect rect4 = tb.actionGeometry(&action4); |
|
601 |
||
602 |
QVERIFY(rect1.isValid()); |
|
603 |
QVERIFY(!rect1.isNull()); |
|
604 |
QVERIFY(!rect1.isEmpty()); |
|
605 |
||
606 |
QVERIFY(rect2.isValid()); |
|
607 |
QVERIFY(!rect2.isNull()); |
|
608 |
QVERIFY(!rect2.isEmpty()); |
|
609 |
||
610 |
QVERIFY(rect3.isValid()); |
|
611 |
QVERIFY(!rect3.isNull()); |
|
612 |
QVERIFY(!rect3.isEmpty()); |
|
613 |
||
614 |
QVERIFY(rect4.isValid()); |
|
615 |
QVERIFY(!rect4.isNull()); |
|
616 |
QVERIFY(!rect4.isEmpty()); |
|
617 |
||
618 |
if (rect01.isValid()) |
|
619 |
QCOMPARE(popupMenu->actionAt(rect01.center()), &action1); |
|
620 |
else |
|
621 |
QCOMPARE(tb.actionAt(rect1.center()), &action1); |
|
622 |
||
623 |
if (rect02.isValid()) |
|
624 |
QCOMPARE(popupMenu->actionAt(rect02.center()), &action2); |
|
625 |
else |
|
626 |
QCOMPARE(tb.actionAt(rect2.center()), &action2); |
|
627 |
||
628 |
if (rect03.isValid()) |
|
629 |
QCOMPARE(popupMenu->actionAt(rect03.center()), &action3); |
|
630 |
else |
|
631 |
QCOMPARE(tb.actionAt(rect3.center()), &action3); |
|
632 |
||
633 |
if (rect04.isValid()) |
|
634 |
QCOMPARE(popupMenu->actionAt(rect04.center()), &action4); |
|
635 |
else |
|
636 |
QCOMPARE(tb.actionAt(rect4.center()), &action4); |
|
637 |
} |
|
638 |
||
639 |
void tst_QToolBar::actionAt() |
|
640 |
{ DEPENDS_ON("actionGeometry()"); } |
|
641 |
||
642 |
void tst_QToolBar::toggleViewAction() |
|
643 |
{ |
|
644 |
{ |
|
645 |
QToolBar tb; |
|
646 |
QAction *toggleViewAction = tb.toggleViewAction(); |
|
647 |
QVERIFY(tb.isHidden()); |
|
648 |
toggleViewAction->trigger(); |
|
649 |
QVERIFY(!tb.isHidden()); |
|
650 |
toggleViewAction->trigger(); |
|
651 |
QVERIFY(tb.isHidden()); |
|
652 |
} |
|
653 |
||
654 |
{ |
|
655 |
QMainWindow mw; |
|
656 |
QToolBar tb(&mw); |
|
657 |
mw.addToolBar(&tb); |
|
658 |
mw.show(); |
|
659 |
QAction *toggleViewAction = tb.toggleViewAction(); |
|
660 |
QVERIFY(!tb.isHidden()); |
|
661 |
toggleViewAction->trigger(); |
|
662 |
QVERIFY(tb.isHidden()); |
|
663 |
toggleViewAction->trigger(); |
|
664 |
QVERIFY(!tb.isHidden()); |
|
665 |
toggleViewAction->trigger(); |
|
666 |
QVERIFY(tb.isHidden()); |
|
667 |
} |
|
668 |
} |
|
669 |
||
670 |
void tst_QToolBar::setIconSize() |
|
671 |
{ DEPENDS_ON("iconSize()"); } |
|
672 |
||
673 |
void tst_QToolBar::iconSize() |
|
674 |
{ |
|
675 |
{ |
|
676 |
QToolBar tb; |
|
677 |
||
678 |
QSignalSpy spy(&tb, SIGNAL(iconSizeChanged(QSize))); |
|
679 |
||
680 |
// the default is determined by the style |
|
681 |
const int metric = tb.style()->pixelMetric(QStyle::PM_ToolBarIconSize); |
|
682 |
const QSize defaultIconSize = QSize(metric, metric); |
|
683 |
const QSize smallIconSize = QSize(metric / 2, metric / 2); |
|
684 |
const QSize largeIconSize = QSize(metric * 2, metric * 2); |
|
685 |
||
686 |
QCOMPARE(tb.iconSize(), defaultIconSize); |
|
687 |
tb.setIconSize(defaultIconSize); |
|
688 |
QCOMPARE(tb.iconSize(), defaultIconSize); |
|
689 |
QCOMPARE(spy.count(), 0); |
|
690 |
||
691 |
spy.clear(); |
|
692 |
tb.setIconSize(largeIconSize); |
|
693 |
QCOMPARE(tb.iconSize(), largeIconSize); |
|
694 |
QCOMPARE(spy.count(), 1); |
|
695 |
QCOMPARE(spy.first().first().toSize(), largeIconSize); |
|
696 |
||
697 |
// no-op |
|
698 |
spy.clear(); |
|
699 |
tb.setIconSize(largeIconSize); |
|
700 |
QCOMPARE(tb.iconSize(), largeIconSize); |
|
701 |
QCOMPARE(spy.count(), 0); |
|
702 |
||
703 |
spy.clear(); |
|
704 |
tb.setIconSize(defaultIconSize); |
|
705 |
QCOMPARE(tb.iconSize(), defaultIconSize); |
|
706 |
QCOMPARE(spy.count(), 1); |
|
707 |
QCOMPARE(spy.first().first().toSize(), defaultIconSize); |
|
708 |
||
709 |
// no-op |
|
710 |
spy.clear(); |
|
711 |
tb.setIconSize(defaultIconSize); |
|
712 |
QCOMPARE(tb.iconSize(), defaultIconSize); |
|
713 |
QCOMPARE(spy.count(), 0); |
|
714 |
||
715 |
spy.clear(); |
|
716 |
tb.setIconSize(smallIconSize); |
|
717 |
QCOMPARE(tb.iconSize(), smallIconSize); |
|
718 |
QCOMPARE(spy.count(), 1); |
|
719 |
QCOMPARE(spy.first().first().toSize(), smallIconSize); |
|
720 |
||
721 |
// no-op |
|
722 |
spy.clear(); |
|
723 |
tb.setIconSize(smallIconSize); |
|
724 |
QCOMPARE(tb.iconSize(), smallIconSize); |
|
725 |
QCOMPARE(spy.count(), 0); |
|
726 |
||
727 |
// setting the icon size to an invalid QSize will reset the |
|
728 |
// iconSize property to the default |
|
729 |
tb.setIconSize(QSize()); |
|
730 |
QCOMPARE(tb.iconSize(), defaultIconSize); |
|
731 |
QCOMPARE(spy.size(), 1); |
|
732 |
QCOMPARE(spy.first().first().toSize(), defaultIconSize); |
|
733 |
spy.clear(); |
|
734 |
} |
|
735 |
||
736 |
{ |
|
737 |
QMainWindow mw; |
|
738 |
QToolBar tb; |
|
739 |
QSignalSpy mwSpy(&mw, SIGNAL(iconSizeChanged(QSize))); |
|
740 |
QSignalSpy tbSpy(&tb, SIGNAL(iconSizeChanged(QSize))); |
|
741 |
||
742 |
// the default is determined by the style |
|
743 |
const int metric = tb.style()->pixelMetric(QStyle::PM_ToolBarIconSize); |
|
744 |
const QSize defaultIconSize = QSize(metric, metric); |
|
745 |
const QSize smallIconSize = QSize(metric / 2, metric / 2); |
|
746 |
const QSize largeIconSize = QSize(metric * 2, metric * 2); |
|
747 |
||
748 |
mw.setIconSize(smallIconSize); |
|
749 |
||
750 |
// explicitly set it to the default |
|
751 |
tb.setIconSize(defaultIconSize); |
|
752 |
QCOMPARE(tb.iconSize(), defaultIconSize); |
|
753 |
QCOMPARE(tbSpy.count(), 0); |
|
754 |
||
755 |
mw.addToolBar(&tb); |
|
756 |
||
757 |
// tb icon size should not change since it has been explicitly set |
|
758 |
QCOMPARE(tb.iconSize(), defaultIconSize); |
|
759 |
QCOMPARE(tbSpy.count(), 0); |
|
760 |
||
761 |
mw.setIconSize(largeIconSize); |
|
762 |
||
763 |
QCOMPARE(tb.iconSize(), defaultIconSize); |
|
764 |
QCOMPARE(tbSpy.count(), 0); |
|
765 |
||
766 |
mw.setIconSize(defaultIconSize); |
|
767 |
||
768 |
QCOMPARE(tb.iconSize(), defaultIconSize); |
|
769 |
QCOMPARE(tbSpy.count(), 0); |
|
770 |
||
771 |
mw.setIconSize(smallIconSize); |
|
772 |
||
773 |
QCOMPARE(tb.iconSize(), defaultIconSize); |
|
774 |
QCOMPARE(tbSpy.count(), 0); |
|
775 |
||
776 |
// resetting to the default should cause the toolbar to take |
|
777 |
// on the mainwindow's icon size |
|
778 |
tb.setIconSize(QSize()); |
|
779 |
QCOMPARE(tb.iconSize(), smallIconSize); |
|
780 |
QCOMPARE(tbSpy.size(), 1); |
|
781 |
QCOMPARE(tbSpy.first().first().toSize(), smallIconSize); |
|
782 |
tbSpy.clear(); |
|
783 |
} |
|
784 |
} |
|
785 |
||
786 |
void tst_QToolBar::setToolButtonStyle() |
|
787 |
{ DEPENDS_ON("toolButtonStyle()"); } |
|
788 |
||
789 |
void tst_QToolBar::toolButtonStyle() |
|
790 |
{ |
|
791 |
{ |
|
792 |
QToolBar tb; |
|
793 |
||
794 |
QSignalSpy spy(&tb, SIGNAL(toolButtonStyleChanged(Qt::ToolButtonStyle))); |
|
795 |
||
796 |
// no-op |
|
797 |
QCOMPARE(tb.toolButtonStyle(), Qt::ToolButtonIconOnly); |
|
798 |
tb.setToolButtonStyle(Qt::ToolButtonIconOnly); |
|
799 |
QCOMPARE(tb.toolButtonStyle(), Qt::ToolButtonIconOnly); |
|
800 |
QCOMPARE(spy.count(), 0); |
|
801 |
||
802 |
tb.setToolButtonStyle(Qt::ToolButtonTextOnly); |
|
803 |
QCOMPARE(tb.toolButtonStyle(), Qt::ToolButtonTextOnly); |
|
804 |
QCOMPARE(spy.count(), 1); |
|
805 |
spy.clear(); |
|
806 |
||
807 |
// no-op |
|
808 |
tb.setToolButtonStyle(Qt::ToolButtonTextOnly); |
|
809 |
QCOMPARE(tb.toolButtonStyle(), Qt::ToolButtonTextOnly); |
|
810 |
QCOMPARE(spy.count(), 0); |
|
811 |
||
812 |
tb.setToolButtonStyle(Qt::ToolButtonIconOnly); |
|
813 |
QCOMPARE(tb.toolButtonStyle(), Qt::ToolButtonIconOnly); |
|
814 |
QCOMPARE(spy.count(), 1); |
|
815 |
spy.clear(); |
|
816 |
||
817 |
// no-op |
|
818 |
tb.setToolButtonStyle(Qt::ToolButtonIconOnly); |
|
819 |
QCOMPARE(tb.toolButtonStyle(), Qt::ToolButtonIconOnly); |
|
820 |
QCOMPARE(spy.count(), 0); |
|
821 |
||
822 |
tb.setToolButtonStyle(Qt::ToolButtonTextBesideIcon); |
|
823 |
QCOMPARE(tb.toolButtonStyle(), Qt::ToolButtonTextBesideIcon); |
|
824 |
QCOMPARE(spy.count(), 1); |
|
825 |
spy.clear(); |
|
826 |
||
827 |
// no-op |
|
828 |
tb.setToolButtonStyle(Qt::ToolButtonTextBesideIcon); |
|
829 |
QCOMPARE(tb.toolButtonStyle(), Qt::ToolButtonTextBesideIcon); |
|
830 |
QCOMPARE(spy.count(), 0); |
|
831 |
||
832 |
tb.setToolButtonStyle(Qt::ToolButtonTextUnderIcon); |
|
833 |
QCOMPARE(tb.toolButtonStyle(), Qt::ToolButtonTextUnderIcon); |
|
834 |
QCOMPARE(spy.count(), 1); |
|
835 |
spy.clear(); |
|
836 |
||
837 |
// no-op |
|
838 |
tb.setToolButtonStyle(Qt::ToolButtonTextUnderIcon); |
|
839 |
QCOMPARE(tb.toolButtonStyle(), Qt::ToolButtonTextUnderIcon); |
|
840 |
QCOMPARE(spy.count(), 0); |
|
841 |
||
842 |
tb.setToolButtonStyle(Qt::ToolButtonFollowStyle); |
|
843 |
QCOMPARE(tb.toolButtonStyle(), Qt::ToolButtonFollowStyle); |
|
844 |
QCOMPARE(spy.count(), 1); |
|
845 |
} |
|
846 |
||
847 |
{ |
|
848 |
QMainWindow mw; |
|
849 |
QToolBar tb; |
|
850 |
QSignalSpy mwSpy(&mw, SIGNAL(toolButtonStyleChanged(Qt::ToolButtonStyle))); |
|
851 |
QSignalSpy tbSpy(&tb, SIGNAL(toolButtonStyleChanged(Qt::ToolButtonStyle))); |
|
852 |
||
853 |
mw.setToolButtonStyle(Qt::ToolButtonTextBesideIcon); |
|
854 |
||
855 |
// explicitly set the tb to the default |
|
856 |
tb.setToolButtonStyle(Qt::ToolButtonIconOnly); |
|
857 |
QCOMPARE(tb.toolButtonStyle(), Qt::ToolButtonIconOnly); |
|
858 |
QCOMPARE(tbSpy.count(), 0); |
|
859 |
||
860 |
mw.addToolBar(&tb); |
|
861 |
||
862 |
// tb icon size should not change since it has been explicitly set |
|
863 |
QCOMPARE(tb.toolButtonStyle(), Qt::ToolButtonIconOnly); |
|
864 |
QCOMPARE(tbSpy.count(), 0); |
|
865 |
||
866 |
mw.setToolButtonStyle(Qt::ToolButtonIconOnly); |
|
867 |
||
868 |
QCOMPARE(tb.toolButtonStyle(), Qt::ToolButtonIconOnly); |
|
869 |
QCOMPARE(tbSpy.count(), 0); |
|
870 |
||
871 |
mw.setToolButtonStyle(Qt::ToolButtonTextOnly); |
|
872 |
||
873 |
QCOMPARE(tb.toolButtonStyle(), Qt::ToolButtonIconOnly); |
|
874 |
QCOMPARE(tbSpy.count(), 0); |
|
875 |
||
876 |
mw.setToolButtonStyle(Qt::ToolButtonTextUnderIcon); |
|
877 |
||
878 |
QCOMPARE(tb.toolButtonStyle(), Qt::ToolButtonIconOnly); |
|
879 |
QCOMPARE(tbSpy.count(), 0); |
|
880 |
||
881 |
// note: there is no way to clear the explicitly set tool |
|
882 |
// button style... once you explicitly set it, the toolbar |
|
883 |
// will never follow the mainwindow again |
|
884 |
} |
|
885 |
} |
|
886 |
||
887 |
void tst_QToolBar::actionTriggered() |
|
888 |
{ |
|
889 |
QToolBar tb; |
|
890 |
connect(&tb, SIGNAL(actionTriggered(QAction *)), SLOT(slot(QAction *))); |
|
891 |
||
892 |
QAction action1(0); |
|
893 |
QAction action2(0); |
|
894 |
QAction action3(0); |
|
895 |
QAction action4(0); |
|
896 |
||
897 |
tb.addAction(&action1); |
|
898 |
tb.addAction(&action2); |
|
899 |
tb.addAction(&action3); |
|
900 |
tb.addAction(&action4); |
|
901 |
||
902 |
tb.show(); |
|
903 |
#ifdef Q_WS_X11 |
|
904 |
qt_x11_wait_for_window_manager(&tb); |
|
905 |
#endif |
|
906 |
||
907 |
QList<QToolBarExtension *> extensions = tb.findChildren<QToolBarExtension *>(); |
|
908 |
||
909 |
QRect rect01; |
|
910 |
QRect rect02; |
|
911 |
QRect rect03; |
|
912 |
QRect rect04; |
|
913 |
QMenu *popupMenu; |
|
914 |
||
915 |
if (extensions.size() != 0) |
|
916 |
{ |
|
917 |
QToolBarExtension *extension = extensions.at(0); |
|
918 |
if (extension->isVisible()) { |
|
919 |
QRect rect0 = extension->geometry(); |
|
920 |
QTest::mouseClick( extension, Qt::LeftButton, 0, rect0.center(), -1 ); |
|
921 |
QApplication::processEvents(); |
|
922 |
popupMenu = qobject_cast<QMenu *>(extension->menu()); |
|
923 |
rect01 = popupMenu->actionGeometry(&action1); |
|
924 |
rect02 = popupMenu->actionGeometry(&action2); |
|
925 |
rect03 = popupMenu->actionGeometry(&action3); |
|
926 |
rect04 = popupMenu->actionGeometry(&action4); |
|
927 |
} |
|
928 |
} |
|
929 |
||
930 |
QRect rect1 = tb.actionGeometry(&action1); |
|
931 |
QRect rect2 = tb.actionGeometry(&action2); |
|
932 |
QRect rect3 = tb.actionGeometry(&action3); |
|
933 |
QRect rect4 = tb.actionGeometry(&action4); |
|
934 |
||
935 |
QAbstractButton *button1; |
|
936 |
QAbstractButton *button2; |
|
937 |
QAbstractButton *button3; |
|
938 |
QAbstractButton *button4; |
|
939 |
||
940 |
if (!rect01.isValid()) { |
|
941 |
button1 = qobject_cast<QAbstractButton *>(tb.childAt(rect1.center())); |
|
942 |
QVERIFY(button1 != 0); |
|
943 |
} |
|
944 |
if (!rect02.isValid()) { |
|
945 |
button2 = qobject_cast<QAbstractButton *>(tb.childAt(rect2.center())); |
|
946 |
QVERIFY(button2 != 0); |
|
947 |
} |
|
948 |
if (!rect03.isValid()) { |
|
949 |
button3 = qobject_cast<QAbstractButton *>(tb.childAt(rect3.center())); |
|
950 |
QVERIFY(button3 != 0); |
|
951 |
} |
|
952 |
if (!rect04.isValid()) { |
|
953 |
button4 = qobject_cast<QAbstractButton *>(tb.childAt(rect4.center())); |
|
954 |
QVERIFY(button4 != 0); |
|
955 |
} |
|
956 |
||
957 |
::triggered = 0; |
|
958 |
if (!rect01.isValid()) |
|
959 |
QTest::mouseClick(button1, Qt::LeftButton); |
|
960 |
else |
|
961 |
QTest::mouseClick(popupMenu, Qt::LeftButton, 0, rect01.center(), -1 ); |
|
962 |
QCOMPARE(::triggered, &action1); |
|
963 |
||
964 |
::triggered = 0; |
|
965 |
if (!rect02.isValid()) |
|
966 |
QTest::mouseClick(button2, Qt::LeftButton); |
|
967 |
else |
|
968 |
QTest::mouseClick(popupMenu, Qt::LeftButton, 0, rect02.center(), -1 ); |
|
969 |
QCOMPARE(::triggered, &action2); |
|
970 |
||
971 |
::triggered = 0; |
|
972 |
if (!rect03.isValid()) |
|
973 |
QTest::mouseClick(button3, Qt::LeftButton); |
|
974 |
else |
|
975 |
QTest::mouseClick(popupMenu, Qt::LeftButton, 0, rect03.center(), -1 ); |
|
976 |
QCOMPARE(::triggered, &action3); |
|
977 |
||
978 |
::triggered = 0; |
|
979 |
if (!rect04.isValid()) |
|
980 |
QTest::mouseClick(button4, Qt::LeftButton); |
|
981 |
else |
|
982 |
QTest::mouseClick(popupMenu, Qt::LeftButton, 0, rect04.center(), -1 ); |
|
983 |
QCOMPARE(::triggered, &action4); |
|
984 |
} |
|
985 |
||
986 |
void tst_QToolBar::movableChanged() |
|
987 |
{ DEPENDS_ON("isMovable()"); } |
|
988 |
||
989 |
void tst_QToolBar::allowedAreasChanged() |
|
990 |
{ DEPENDS_ON("allowedAreas()"); } |
|
991 |
||
992 |
void tst_QToolBar::orientationChanged() |
|
993 |
{ DEPENDS_ON("orientation()"); } |
|
994 |
||
995 |
void tst_QToolBar::iconSizeChanged() |
|
996 |
{ DEPENDS_ON("iconSize()"); } |
|
997 |
||
998 |
void tst_QToolBar::toolButtonStyleChanged() |
|
999 |
{ DEPENDS_ON("toolButtonStyle()"); } |
|
1000 |
||
1001 |
void tst_QToolBar::actionOwnership() |
|
1002 |
{ |
|
1003 |
{ |
|
1004 |
QToolBar *tb1 = new QToolBar; |
|
1005 |
QToolBar *tb2 = new QToolBar; |
|
1006 |
||
1007 |
QPointer<QAction> action = tb1->addAction("test"); |
|
1008 |
QVERIFY(action->parent() == tb1); |
|
1009 |
||
1010 |
tb2->addAction(action); |
|
1011 |
QVERIFY(action->parent() == tb1); |
|
1012 |
||
1013 |
delete tb1; |
|
1014 |
QVERIFY(!action); |
|
1015 |
delete tb2; |
|
1016 |
} |
|
1017 |
{ |
|
1018 |
QToolBar *tb1 = new QToolBar; |
|
1019 |
QToolBar *tb2 = new QToolBar; |
|
1020 |
||
1021 |
QPointer<QAction> action = tb1->addAction("test"); |
|
1022 |
QVERIFY(action->parent() == tb1); |
|
1023 |
||
1024 |
tb1->removeAction(action); |
|
1025 |
QVERIFY(action->parent() == tb1); |
|
1026 |
||
1027 |
tb2->addAction(action); |
|
1028 |
QVERIFY(action->parent() == tb1); |
|
1029 |
||
1030 |
delete tb1; |
|
1031 |
QVERIFY(!action); |
|
1032 |
delete tb2; |
|
1033 |
} |
|
1034 |
} |
|
1035 |
||
1036 |
void tst_QToolBar::widgetAction() |
|
1037 |
{ |
|
1038 |
// ensure that a QWidgetAction without widget behaves like a normal action |
|
1039 |
QToolBar tb; |
|
1040 |
QWidgetAction *a = new QWidgetAction(0); |
|
1041 |
a->setIconText("Blah"); |
|
1042 |
||
1043 |
tb.addAction(a); |
|
1044 |
QWidget *w = tb.widgetForAction(a); |
|
1045 |
QVERIFY(w); |
|
1046 |
QToolButton *button = qobject_cast<QToolButton *>(w); |
|
1047 |
QVERIFY(button); |
|
1048 |
QCOMPARE(a->iconText(), button->text()); |
|
1049 |
||
1050 |
delete a; |
|
1051 |
} |
|
1052 |
||
1053 |
void tst_QToolBar::accel() |
|
1054 |
{ |
|
1055 |
#ifdef Q_WS_MAC |
|
1056 |
extern void qt_set_sequence_auto_mnemonic(bool b); |
|
1057 |
qt_set_sequence_auto_mnemonic(true); |
|
1058 |
#endif |
|
1059 |
QMainWindow mw; |
|
1060 |
QToolBar *toolBar = mw.addToolBar("test"); |
|
1061 |
QAction *action = toolBar->addAction("&test"); |
|
1062 |
action->setIconText(action->text()); // we really want that mnemonic in the button! |
|
1063 |
||
1064 |
QSignalSpy spy(action, SIGNAL(triggered(bool))); |
|
1065 |
||
1066 |
mw.show(); |
|
1067 |
QApplication::setActiveWindow(&mw); |
|
1068 |
QTest::qWait(100); |
|
1069 |
QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget *>(&mw)); |
|
1070 |
||
1071 |
QTest::keyClick(&mw, Qt::Key_T, Qt::AltModifier); |
|
1072 |
QTest::qWait(300); |
|
1073 |
||
1074 |
QTRY_COMPARE(spy.count(), 1); |
|
1075 |
#ifdef Q_WS_MAC |
|
1076 |
qt_set_sequence_auto_mnemonic(false); |
|
1077 |
#endif |
|
1078 |
} |
|
1079 |
||
1080 |
void tst_QToolBar::task191727_layout() |
|
1081 |
{ |
|
1082 |
QMainWindow mw; |
|
1083 |
QToolBar *toolBar = mw.addToolBar("test"); |
|
1084 |
toolBar->addAction("one"); |
|
1085 |
QAction *action = toolBar->addAction("two"); |
|
1086 |
||
1087 |
QLineEdit *lineedit = new QLineEdit; |
|
1088 |
lineedit->setMaximumWidth(50); |
|
1089 |
toolBar->addWidget(lineedit); |
|
1090 |
||
1091 |
mw.resize(400, 400); |
|
1092 |
mw.show(); |
|
1093 |
||
1094 |
QWidget *actionwidget = toolBar->widgetForAction(action); |
|
1095 |
QVERIFY(qAbs(lineedit->pos().x() - (actionwidget->geometry().right() + 1 + toolBar->layout()->spacing())) < 2); |
|
1096 |
} |
|
1097 |
||
1098 |
void tst_QToolBar::task197996_visibility() |
|
1099 |
{ |
|
1100 |
QMainWindow mw; |
|
1101 |
QToolBar *toolBar = new QToolBar(&mw); |
|
1102 |
||
1103 |
mw.addToolBar(toolBar); |
|
1104 |
toolBar->addAction(new QAction("Foo", &mw)); |
|
1105 |
QAction *pAction = new QAction("Test", &mw); |
|
1106 |
toolBar->addAction(pAction); |
|
1107 |
||
1108 |
pAction->setVisible(false); |
|
1109 |
toolBar->setVisible(false); |
|
1110 |
||
1111 |
toolBar->setVisible(true); |
|
1112 |
pAction->setVisible(true); |
|
1113 |
||
1114 |
mw.show(); |
|
1115 |
||
1116 |
QVERIFY(toolBar->widgetForAction(pAction)->isVisible()); |
|
1117 |
||
1118 |
toolBar->setVisible(false); |
|
1119 |
pAction->setVisible(false); |
|
1120 |
||
1121 |
toolBar->setVisible(true); |
|
1122 |
pAction->setVisible(true); |
|
1123 |
||
1124 |
QTest::qWait(100); |
|
1125 |
||
1126 |
QVERIFY(toolBar->widgetForAction(pAction)->isVisible()); |
|
1127 |
||
1128 |
} |
|
1129 |
||
1130 |
QTEST_MAIN(tst_QToolBar) |
|
1131 |
#include "tst_qtoolbar.moc" |