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