|
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 <qgraphicsgridlayout.h> |
|
45 #include <qgraphicswidget.h> |
|
46 #include <qgraphicsscene.h> |
|
47 #include <qgraphicsview.h> |
|
48 |
|
49 class tst_QGraphicsGridLayout : public QObject |
|
50 { |
|
51 Q_OBJECT |
|
52 |
|
53 public slots: |
|
54 void initTestCase(); |
|
55 void cleanupTestCase(); |
|
56 void init(); |
|
57 void cleanup(); |
|
58 |
|
59 private slots: |
|
60 void qgraphicsgridlayout_data(); |
|
61 void qgraphicsgridlayout(); |
|
62 void addItem_data(); |
|
63 void addItem(); |
|
64 void alignment(); |
|
65 void alignment2(); |
|
66 void alignment2_data(); |
|
67 void columnAlignment(); |
|
68 void columnCount(); |
|
69 void columnMaximumWidth(); |
|
70 void columnMinimumWidth(); |
|
71 void columnPreferredWidth(); |
|
72 void setColumnFixedWidth(); |
|
73 void columnSpacing(); |
|
74 void columnStretchFactor(); |
|
75 void count(); |
|
76 void contentsMargins(); |
|
77 void horizontalSpacing_data(); |
|
78 void horizontalSpacing(); |
|
79 void itemAt(); |
|
80 void removeAt(); |
|
81 void rowAlignment(); |
|
82 void rowCount(); |
|
83 void rowMaximumHeight(); |
|
84 void rowMinimumHeight(); |
|
85 void rowPreferredHeight(); |
|
86 void rowSpacing(); |
|
87 void rowStretchFactor(); |
|
88 void setColumnSpacing_data(); |
|
89 void setColumnSpacing(); |
|
90 void setGeometry_data(); |
|
91 void setGeometry(); |
|
92 void setRowFixedHeight(); |
|
93 void setRowSpacing_data(); |
|
94 void setRowSpacing(); |
|
95 void setSpacing_data(); |
|
96 void setSpacing(); |
|
97 void sizeHint_data(); |
|
98 void sizeHint(); |
|
99 void verticalSpacing_data(); |
|
100 void verticalSpacing(); |
|
101 void layoutDirection(); |
|
102 void removeLayout(); |
|
103 void defaultStretchFactors_data(); |
|
104 void defaultStretchFactors(); |
|
105 void geometries_data(); |
|
106 void geometries(); |
|
107 void avoidRecursionInInsertItem(); |
|
108 void task236367_maxSizeHint(); |
|
109 }; |
|
110 |
|
111 // This will be called before the first test function is executed. |
|
112 // It is only called once. |
|
113 void tst_QGraphicsGridLayout::initTestCase() |
|
114 { |
|
115 } |
|
116 |
|
117 // This will be called after the last test function is executed. |
|
118 // It is only called once. |
|
119 void tst_QGraphicsGridLayout::cleanupTestCase() |
|
120 { |
|
121 } |
|
122 |
|
123 // This will be called before each test function is executed. |
|
124 void tst_QGraphicsGridLayout::init() |
|
125 { |
|
126 #ifdef Q_OS_WINCE //disable magic for WindowsCE |
|
127 qApp->setAutoMaximizeThreshold(-1); |
|
128 #endif |
|
129 } |
|
130 |
|
131 // This will be called after every test function. |
|
132 void tst_QGraphicsGridLayout::cleanup() |
|
133 { |
|
134 } |
|
135 |
|
136 void tst_QGraphicsGridLayout::qgraphicsgridlayout_data() |
|
137 { |
|
138 } |
|
139 |
|
140 void tst_QGraphicsGridLayout::qgraphicsgridlayout() |
|
141 { |
|
142 QGraphicsGridLayout layout; |
|
143 QTest::ignoreMessage(QtWarningMsg, "QGraphicsGridLayout::addItem: invalid row span/column span: 0"); |
|
144 layout.addItem(0, 0, 0, 0, 0); |
|
145 QTest::ignoreMessage(QtWarningMsg, "QGraphicsGridLayout::addItem: cannot add null item"); |
|
146 layout.addItem(0, 0, 0); |
|
147 layout.alignment(0); |
|
148 layout.columnAlignment(0); |
|
149 layout.columnCount(); |
|
150 layout.columnMaximumWidth(0); |
|
151 layout.columnMinimumWidth(0); |
|
152 layout.columnPreferredWidth(0); |
|
153 layout.columnSpacing(0); |
|
154 layout.columnStretchFactor(0); |
|
155 layout.count(); |
|
156 layout.horizontalSpacing(); |
|
157 QTest::ignoreMessage(QtWarningMsg, "QGraphicsGridLayout::itemAt: invalid row, column 0, 0"); |
|
158 layout.itemAt(0, 0); |
|
159 QTest::ignoreMessage(QtWarningMsg, "QGraphicsGridLayout::itemAt: invalid index 0"); |
|
160 layout.itemAt(0); |
|
161 QTest::ignoreMessage(QtWarningMsg, "QGraphicsGridLayout::removeAt: invalid index 0"); |
|
162 layout.removeAt(0); |
|
163 layout.rowAlignment(0); |
|
164 layout.rowCount(); |
|
165 layout.rowMaximumHeight(0); |
|
166 layout.rowMinimumHeight(0); |
|
167 layout.rowPreferredHeight(0); |
|
168 layout.rowSpacing(0); |
|
169 layout.rowStretchFactor(0); |
|
170 layout.setAlignment(0, Qt::AlignRight); |
|
171 layout.setColumnAlignment(0, Qt::AlignRight); |
|
172 layout.setColumnFixedWidth(0, 0); |
|
173 layout.setColumnMaximumWidth(0, 0); |
|
174 layout.setColumnMinimumWidth(0, 0); |
|
175 layout.setColumnPreferredWidth(0, 0); |
|
176 layout.setColumnSpacing(0, 0); |
|
177 layout.setColumnStretchFactor(0, 0); |
|
178 layout.setGeometry(QRectF()); |
|
179 layout.setHorizontalSpacing(0); |
|
180 layout.setRowAlignment(0, 0); |
|
181 layout.setRowFixedHeight(0, 0); |
|
182 layout.setRowMaximumHeight(0, 0); |
|
183 layout.setRowMinimumHeight(0, 0); |
|
184 layout.setRowPreferredHeight(0, 0); |
|
185 layout.setRowSpacing(0, 0); |
|
186 layout.setRowStretchFactor(0, 0); |
|
187 layout.setSpacing(0); |
|
188 layout.setVerticalSpacing(0); |
|
189 layout.sizeHint(Qt::MinimumSize); |
|
190 layout.verticalSpacing(); |
|
191 } |
|
192 |
|
193 class RectWidget : public QGraphicsWidget |
|
194 { |
|
195 public: |
|
196 RectWidget(QGraphicsItem *parent = 0) : QGraphicsWidget(parent){} |
|
197 |
|
198 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
199 { |
|
200 Q_UNUSED(option); |
|
201 Q_UNUSED(widget); |
|
202 painter->drawRoundRect(rect()); |
|
203 painter->drawLine(rect().topLeft(), rect().bottomRight()); |
|
204 painter->drawLine(rect().bottomLeft(), rect().topRight()); |
|
205 } |
|
206 |
|
207 QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const |
|
208 { |
|
209 if (m_sizeHints[which].isValid()) { |
|
210 return m_sizeHints[which]; |
|
211 } |
|
212 return QGraphicsWidget::sizeHint(which, constraint); |
|
213 } |
|
214 |
|
215 void setSizeHint(Qt::SizeHint which, const QSizeF &size) { |
|
216 m_sizeHints[which] = size; |
|
217 updateGeometry(); |
|
218 } |
|
219 |
|
220 QSizeF m_sizeHints[Qt::NSizeHints]; |
|
221 }; |
|
222 |
|
223 static void populateLayout(QGraphicsGridLayout *gridLayout, int width, int height) |
|
224 { |
|
225 for (int y = 0; y < height; ++y) { |
|
226 for (int x = 0; x < width; ++x) { |
|
227 QGraphicsWidget *item = new RectWidget(); |
|
228 item->setMinimumSize(10, 10); |
|
229 item->setPreferredSize(25, 25); |
|
230 item->setMaximumSize(50, 50); |
|
231 gridLayout->addItem(item, y, x); |
|
232 } |
|
233 } |
|
234 } |
|
235 |
|
236 |
|
237 /** populates \a gridLayout with a 3x2 layout: |
|
238 * +----+----+----+ |
|
239 * |+---|---+|xxxx| |
|
240 * ||span=2 ||hole| |
|
241 * |+---|---+|xxxx| |
|
242 * +----+----+----+ |
|
243 * |xxxx|+---|---+| |
|
244 * |hole||span=2 || |
|
245 * |xxxx|+---|---+| |
|
246 * +----+----+----+ |
|
247 */ |
|
248 static void populateLayoutWithSpansAndHoles(QGraphicsGridLayout *gridLayout) |
|
249 { |
|
250 QGraphicsWidget *item = new RectWidget(); |
|
251 item->setMinimumSize(10, 10); |
|
252 item->setPreferredSize(25, 25); |
|
253 item->setMaximumSize(50, 50); |
|
254 gridLayout->addItem(item, 0, 0, 1, 2); |
|
255 |
|
256 item = new RectWidget(); |
|
257 item->setMinimumSize(10, 10); |
|
258 item->setPreferredSize(25, 25); |
|
259 item->setMaximumSize(50, 50); |
|
260 gridLayout->addItem(item, 1, 1, 1, 2); |
|
261 } |
|
262 |
|
263 Q_DECLARE_METATYPE(Qt::Alignment) |
|
264 void tst_QGraphicsGridLayout::addItem_data() |
|
265 { |
|
266 QTest::addColumn<int>("row"); |
|
267 QTest::addColumn<int>("column"); |
|
268 QTest::addColumn<int>("rowSpan"); |
|
269 QTest::addColumn<int>("columnSpan"); |
|
270 QTest::addColumn<Qt::Alignment>("alignment"); |
|
271 |
|
272 for (int a = -1; a < 3; ++a) { |
|
273 for (int b = -1; b < 2; ++b) { |
|
274 for (int c = -1; c < 2; ++c) { |
|
275 for (int d = -1; d < 2; ++d) { |
|
276 for (int e = 0; e < 9; ++e) { |
|
277 int row = a; |
|
278 int column = b; |
|
279 int rowSpan = c; |
|
280 int columnSpan = d; |
|
281 QString name = QString::fromAscii("(%1,%2,%3,%4").arg(a).arg(b).arg(c).arg(d); |
|
282 Qt::Alignment alignment = Qt::AlignLeft; |
|
283 QTest::newRow(name.toLatin1()) << row << column << rowSpan << columnSpan << alignment; |
|
284 }}}}} |
|
285 } |
|
286 |
|
287 // public void addItem(QGraphicsLayoutItem* item, int row, int column, int rowSpan, int columnSpan, Qt::Alignment alignment = 0) |
|
288 void tst_QGraphicsGridLayout::addItem() |
|
289 { |
|
290 QFETCH(int, row); |
|
291 QFETCH(int, column); |
|
292 QFETCH(int, rowSpan); |
|
293 QFETCH(int, columnSpan); |
|
294 QFETCH(Qt::Alignment, alignment); |
|
295 |
|
296 QGraphicsGridLayout *layout = new QGraphicsGridLayout; |
|
297 |
|
298 QGraphicsWidget *wid = new QGraphicsWidget; |
|
299 if (row < 0 || column < 0) { |
|
300 QTest::ignoreMessage(QtWarningMsg, "QGraphicsGridLayout::addItem: invalid row/column: -1"); |
|
301 } else if (rowSpan < 1 || columnSpan < 1) { |
|
302 char buf[1024]; |
|
303 ::qsnprintf(buf, sizeof(buf), "QGraphicsGridLayout::addItem: invalid row span/column span: %d", |
|
304 rowSpan < 1 ? rowSpan : columnSpan); |
|
305 QTest::ignoreMessage(QtWarningMsg, buf); |
|
306 } |
|
307 layout->addItem(wid, row, column, rowSpan, columnSpan, alignment); |
|
308 |
|
309 delete layout; |
|
310 } |
|
311 |
|
312 // public Qt::Alignment alignment(QGraphicsLayoutItem* item) const |
|
313 void tst_QGraphicsGridLayout::alignment() |
|
314 { |
|
315 #ifdef Q_WS_MAC |
|
316 QSKIP("Resizing a QGraphicsWidget to effectiveSizeHint(Qt::MaximumSize) is currently not supported on mac", SkipAll); |
|
317 #endif |
|
318 QGraphicsScene scene; |
|
319 QGraphicsView view(&scene); |
|
320 QGraphicsWidget *widget = new QGraphicsWidget(0, Qt::Window); |
|
321 QGraphicsGridLayout *layout = new QGraphicsGridLayout(); |
|
322 scene.addItem(widget); |
|
323 widget->setLayout(layout); |
|
324 populateLayout(layout, 3, 2); |
|
325 layout->setContentsMargins(0, 0, 0, 0); |
|
326 layout->setSpacing(0); |
|
327 |
|
328 view.show(); |
|
329 widget->show(); |
|
330 widget->resize(widget->effectiveSizeHint(Qt::PreferredSize)); |
|
331 QApplication::processEvents(); |
|
332 // no alignment (the default) |
|
333 QCOMPARE(layout->itemAt(0, 0)->geometry().left(), 0.0); |
|
334 QCOMPARE(layout->itemAt(0, 0)->geometry().right(), layout->itemAt(0, 1)->geometry().left()); |
|
335 QCOMPARE(layout->itemAt(0, 1)->geometry().left(), 25.0); |
|
336 QCOMPARE(layout->itemAt(0, 1)->geometry().right(), layout->itemAt(0, 2)->geometry().left()); |
|
337 QCOMPARE(layout->itemAt(0, 2)->geometry().left(), 50.0); |
|
338 QCOMPARE(layout->itemAt(0, 2)->geometry().right(), 75.0); |
|
339 |
|
340 QCOMPARE(layout->itemAt(1, 0)->geometry().left(), 0.0); |
|
341 QCOMPARE(layout->itemAt(1, 0)->geometry().right(), layout->itemAt(1, 1)->geometry().left()); |
|
342 QCOMPARE(layout->itemAt(1, 1)->geometry().left(), 25.0); |
|
343 QCOMPARE(layout->itemAt(1, 1)->geometry().right(), layout->itemAt(1, 2)->geometry().left()); |
|
344 QCOMPARE(layout->itemAt(1, 2)->geometry().left(), 50.0); |
|
345 QCOMPARE(layout->itemAt(1, 2)->geometry().right(), 75.0); |
|
346 |
|
347 QCOMPARE(layout->itemAt(0, 0)->geometry().top(), 0.0); |
|
348 QCOMPARE(layout->itemAt(0, 0)->geometry().bottom(), layout->itemAt(1, 0)->geometry().top()); |
|
349 QCOMPARE(layout->itemAt(1, 0)->geometry().top(), 25.0); |
|
350 QCOMPARE(layout->itemAt(1, 0)->geometry().bottom(), 50.0); |
|
351 |
|
352 // align first column left, second hcenter, third right |
|
353 layout->setColumnMinimumWidth(0, 100); |
|
354 layout->setAlignment(layout->itemAt(0,0), Qt::AlignLeft); |
|
355 layout->setAlignment(layout->itemAt(1,0), Qt::AlignLeft); |
|
356 layout->setColumnMinimumWidth(1, 100); |
|
357 layout->setAlignment(layout->itemAt(0,1), Qt::AlignHCenter); |
|
358 layout->setAlignment(layout->itemAt(1,1), Qt::AlignHCenter); |
|
359 layout->setColumnMinimumWidth(2, 100); |
|
360 layout->setAlignment(layout->itemAt(0,2), Qt::AlignRight); |
|
361 layout->setAlignment(layout->itemAt(1,2), Qt::AlignRight); |
|
362 |
|
363 widget->resize(widget->effectiveSizeHint(Qt::MaximumSize)); |
|
364 QApplication::processEvents(); |
|
365 |
|
366 QCOMPARE(layout->itemAt(0,0)->geometry(), QRectF(0, 0, 50, 25)); |
|
367 QCOMPARE(layout->itemAt(1,0)->geometry(), QRectF(0, 25, 50, 25)); |
|
368 QCOMPARE(layout->itemAt(0,1)->geometry(), QRectF(125, 0, 50, 25)); |
|
369 QCOMPARE(layout->itemAt(1,1)->geometry(), QRectF(125, 25, 50, 25)); |
|
370 QCOMPARE(layout->itemAt(0,2)->geometry(), QRectF(250, 0, 50, 25)); |
|
371 QCOMPARE(layout->itemAt(1,2)->geometry(), QRectF(250, 25, 50, 25)); |
|
372 |
|
373 delete widget; |
|
374 } |
|
375 |
|
376 // public void setColumnAlignment(int column, Qt::Alignment alignment) |
|
377 // public Qt::Alignment columnAlignment(int column) const |
|
378 void tst_QGraphicsGridLayout::columnAlignment() |
|
379 { |
|
380 #ifdef Q_WS_MAC |
|
381 QSKIP("Resizing a QGraphicsWidget to effectiveSizeHint(Qt::MaximumSize) is currently not supported on mac", SkipAll); |
|
382 #endif |
|
383 QGraphicsScene scene; |
|
384 QGraphicsView view(&scene); |
|
385 QGraphicsWidget *widget = new QGraphicsWidget(0, Qt::Window); |
|
386 QGraphicsGridLayout *layout = new QGraphicsGridLayout(); |
|
387 scene.addItem(widget); |
|
388 widget->setLayout(layout); |
|
389 populateLayout(layout, 3, 2); |
|
390 layout->setContentsMargins(0, 0, 0, 0); |
|
391 layout->setSpacing(1); |
|
392 widget->setContentsMargins(0, 0, 0, 0); |
|
393 |
|
394 layout->setColumnMinimumWidth(0, 100); |
|
395 layout->setColumnMinimumWidth(1, 100); |
|
396 layout->setColumnMinimumWidth(2, 100); |
|
397 |
|
398 view.resize(450,150); |
|
399 widget->resize(widget->effectiveSizeHint(Qt::MaximumSize)); |
|
400 view.show(); |
|
401 widget->show(); |
|
402 QApplication::processEvents(); |
|
403 // Check default |
|
404 QCOMPARE(layout->columnAlignment(0), 0); |
|
405 QCOMPARE(layout->columnAlignment(1), 0); |
|
406 QCOMPARE(layout->columnAlignment(2), 0); |
|
407 |
|
408 layout->setColumnAlignment(0, Qt::AlignLeft); |
|
409 layout->setColumnAlignment(1, Qt::AlignHCenter); |
|
410 layout->setColumnAlignment(2, Qt::AlignRight); |
|
411 |
|
412 // see if item alignment takes preference over columnAlignment |
|
413 layout->setAlignment(layout->itemAt(1,0), Qt::AlignHCenter); |
|
414 layout->setAlignment(layout->itemAt(1,1), Qt::AlignRight); |
|
415 layout->setAlignment(layout->itemAt(1,2), Qt::AlignLeft); |
|
416 |
|
417 QApplication::processEvents(); // process LayoutRequest |
|
418 /* |
|
419 +----------+------------+---------+ |
|
420 | Left | HCenter | Right | |
|
421 +----------+------------+---------+ |
|
422 | HCenter | Right | Left | |
|
423 +---------------------------------+ |
|
424 */ |
|
425 QCOMPARE(layout->itemAt(0,0)->geometry(), QRectF(0, 0, 50, 25)); |
|
426 QCOMPARE(layout->itemAt(1,0)->geometry(), QRectF(25, 26, 50, 25)); // item is king |
|
427 QCOMPARE(layout->itemAt(0,1)->geometry(), QRectF(126, 0, 50, 25)); |
|
428 QCOMPARE(layout->itemAt(1,1)->geometry(), QRectF(151, 26, 50, 25)); // item is king |
|
429 QCOMPARE(layout->itemAt(0,2)->geometry(), QRectF(252, 0, 50, 25)); |
|
430 QCOMPARE(layout->itemAt(1,2)->geometry(), QRectF(202, 26, 50, 25)); // item is king |
|
431 |
|
432 delete widget; |
|
433 } |
|
434 |
|
435 // public int columnCount() const |
|
436 void tst_QGraphicsGridLayout::columnCount() |
|
437 { |
|
438 QGraphicsScene scene; |
|
439 QGraphicsView view(&scene); |
|
440 QGraphicsWidget *widget = new QGraphicsWidget(0, Qt::Window); |
|
441 QGraphicsGridLayout *layout = new QGraphicsGridLayout(); |
|
442 scene.addItem(widget); |
|
443 widget->setLayout(layout); |
|
444 layout->setContentsMargins(0, 0, 0, 0); |
|
445 layout->setSpacing(0); |
|
446 widget->setContentsMargins(0, 0, 0, 0); |
|
447 |
|
448 view.show(); |
|
449 widget->show(); |
|
450 QApplication::processEvents(); |
|
451 |
|
452 QCOMPARE(layout->columnCount(), 0); |
|
453 layout->addItem(new RectWidget(widget), 0, 0); |
|
454 QCOMPARE(layout->columnCount(), 1); |
|
455 layout->addItem(new RectWidget(widget), 1, 1); |
|
456 QCOMPARE(layout->columnCount(), 2); |
|
457 layout->addItem(new RectWidget(widget), 0, 2); |
|
458 QCOMPARE(layout->columnCount(), 3); |
|
459 layout->addItem(new RectWidget(widget), 1, 0); |
|
460 QCOMPARE(layout->columnCount(), 3); |
|
461 layout->addItem(new RectWidget(widget), 0, 1); |
|
462 QCOMPARE(layout->columnCount(), 3); |
|
463 layout->addItem(new RectWidget(widget), 1, 2); |
|
464 QCOMPARE(layout->columnCount(), 3); |
|
465 |
|
466 // ### Talk with Jasmin. Not sure if removeAt() should adjust columnCount(). |
|
467 widget->setLayout(0); |
|
468 layout = new QGraphicsGridLayout(); |
|
469 populateLayout(layout, 3, 2); |
|
470 QCOMPARE(layout->columnCount(), 3); |
|
471 layout->removeAt(5); |
|
472 layout->removeAt(3); |
|
473 QCOMPARE(layout->columnCount(), 3); |
|
474 layout->removeAt(1); |
|
475 QCOMPARE(layout->columnCount(), 3); |
|
476 layout->removeAt(0); |
|
477 QCOMPARE(layout->columnCount(), 3); |
|
478 layout->removeAt(0); |
|
479 QCOMPARE(layout->columnCount(), 2); |
|
480 |
|
481 delete widget; |
|
482 } |
|
483 |
|
484 // public qreal columnMaximumWidth(int column) const |
|
485 void tst_QGraphicsGridLayout::columnMaximumWidth() |
|
486 { |
|
487 QGraphicsScene scene; |
|
488 QGraphicsView view(&scene); |
|
489 QGraphicsWidget *widget = new QGraphicsWidget(0, Qt::Window); |
|
490 QGraphicsGridLayout *layout = new QGraphicsGridLayout(); |
|
491 scene.addItem(widget); |
|
492 widget->setLayout(layout); |
|
493 populateLayout(layout, 3, 2); |
|
494 layout->setContentsMargins(0, 0, 0, 0); |
|
495 layout->setSpacing(0); |
|
496 |
|
497 // should at least be a very large number |
|
498 QVERIFY(layout->columnMaximumWidth(0) >= 10000); |
|
499 QCOMPARE(layout->columnMaximumWidth(0), layout->columnMaximumWidth(1)); |
|
500 QCOMPARE(layout->columnMaximumWidth(1), layout->columnMaximumWidth(2)); |
|
501 layout->setColumnMaximumWidth(0, 20); |
|
502 layout->setColumnMaximumWidth(2, 60); |
|
503 |
|
504 view.show(); |
|
505 widget->show(); |
|
506 widget->resize(widget->effectiveSizeHint(Qt::PreferredSize)); |
|
507 QApplication::processEvents(); |
|
508 |
|
509 QCOMPARE(layout->itemAt(0,0)->geometry().width(), 20.0); |
|
510 QCOMPARE(layout->itemAt(1,0)->geometry().width(), 20.0); |
|
511 QCOMPARE(layout->itemAt(0,1)->geometry().width(), 25.0); |
|
512 QCOMPARE(layout->itemAt(1,1)->geometry().width(), 25.0); |
|
513 QCOMPARE(layout->itemAt(0,2)->geometry().width(), 25.0); |
|
514 QCOMPARE(layout->itemAt(1,2)->geometry().width(), 25.0); |
|
515 |
|
516 delete widget; |
|
517 } |
|
518 |
|
519 // public qreal columnMinimumWidth(int column) const |
|
520 void tst_QGraphicsGridLayout::columnMinimumWidth() |
|
521 { |
|
522 QGraphicsScene scene; |
|
523 QGraphicsView view(&scene); |
|
524 QGraphicsWidget *widget = new QGraphicsWidget(0, Qt::Window); |
|
525 QGraphicsGridLayout *layout = new QGraphicsGridLayout(); |
|
526 scene.addItem(widget); |
|
527 widget->setLayout(layout); |
|
528 populateLayout(layout, 3, 2); |
|
529 layout->setContentsMargins(0, 0, 0, 0); |
|
530 layout->setSpacing(0); |
|
531 |
|
532 // should at least be a very large number |
|
533 QCOMPARE(layout->columnMinimumWidth(0), 0.0); |
|
534 QCOMPARE(layout->columnMinimumWidth(0), layout->columnMinimumWidth(1)); |
|
535 QCOMPARE(layout->columnMinimumWidth(1), layout->columnMinimumWidth(2)); |
|
536 layout->setColumnMinimumWidth(0, 20); |
|
537 layout->setColumnMinimumWidth(2, 40); |
|
538 |
|
539 view.show(); |
|
540 widget->show(); |
|
541 widget->resize(widget->effectiveSizeHint(Qt::PreferredSize)); |
|
542 QApplication::processEvents(); |
|
543 |
|
544 QCOMPARE(layout->itemAt(0,0)->geometry().width(), 25.0); |
|
545 QCOMPARE(layout->itemAt(1,0)->geometry().width(), 25.0); |
|
546 QCOMPARE(layout->itemAt(0,1)->geometry().width(), 25.0); |
|
547 QCOMPARE(layout->itemAt(1,1)->geometry().width(), 25.0); |
|
548 QCOMPARE(layout->itemAt(0,2)->geometry().width(), 40.0); |
|
549 QCOMPARE(layout->itemAt(1,2)->geometry().width(), 40.0); |
|
550 |
|
551 delete widget; |
|
552 } |
|
553 |
|
554 // public qreal columnPreferredWidth(int column) const |
|
555 void tst_QGraphicsGridLayout::columnPreferredWidth() |
|
556 { |
|
557 QGraphicsScene scene; |
|
558 QGraphicsView view(&scene); |
|
559 QGraphicsWidget *widget = new QGraphicsWidget(0, Qt::Window); |
|
560 QGraphicsGridLayout *layout = new QGraphicsGridLayout(); |
|
561 scene.addItem(widget); |
|
562 widget->setLayout(layout); |
|
563 populateLayout(layout, 3, 2); |
|
564 layout->setContentsMargins(0, 0, 0, 0); |
|
565 layout->setSpacing(0); |
|
566 |
|
567 // default preferred width ?? |
|
568 QCOMPARE(layout->columnPreferredWidth(0), 0.0); |
|
569 QCOMPARE(layout->columnPreferredWidth(0), layout->columnPreferredWidth(1)); |
|
570 QCOMPARE(layout->columnPreferredWidth(1), layout->columnPreferredWidth(2)); |
|
571 layout->setColumnPreferredWidth(0, 20); |
|
572 layout->setColumnPreferredWidth(2, 40); |
|
573 |
|
574 view.show(); |
|
575 widget->show(); |
|
576 widget->resize(widget->effectiveSizeHint(Qt::PreferredSize)); |
|
577 QApplication::processEvents(); |
|
578 |
|
579 QCOMPARE(layout->itemAt(0,0)->geometry().width(), 25.0); |
|
580 QCOMPARE(layout->itemAt(1,0)->geometry().width(), 25.0); |
|
581 QCOMPARE(layout->itemAt(0,1)->geometry().width(), 25.0); |
|
582 QCOMPARE(layout->itemAt(1,1)->geometry().width(), 25.0); |
|
583 QCOMPARE(layout->itemAt(0,2)->geometry().width(), 40.0); |
|
584 QCOMPARE(layout->itemAt(1,2)->geometry().width(), 40.0); |
|
585 |
|
586 delete widget; |
|
587 } |
|
588 |
|
589 // public void setColumnFixedWidth(int row, qreal height) |
|
590 void tst_QGraphicsGridLayout::setColumnFixedWidth() |
|
591 { |
|
592 QGraphicsScene scene; |
|
593 QGraphicsView view(&scene); |
|
594 QGraphicsWidget *widget = new QGraphicsWidget(0, Qt::Window); |
|
595 QGraphicsGridLayout *layout = new QGraphicsGridLayout(); |
|
596 scene.addItem(widget); |
|
597 widget->setLayout(layout); |
|
598 populateLayout(layout, 3, 2); |
|
599 layout->setContentsMargins(0, 0, 0, 0); |
|
600 layout->setSpacing(0); |
|
601 |
|
602 layout->setColumnFixedWidth(0, 20); |
|
603 layout->setColumnFixedWidth(2, 40); |
|
604 |
|
605 view.show(); |
|
606 widget->show(); |
|
607 widget->resize(widget->effectiveSizeHint(Qt::PreferredSize)); |
|
608 QApplication::processEvents(); |
|
609 |
|
610 QCOMPARE(layout->itemAt(0,0)->geometry().width(), 20.0); |
|
611 QCOMPARE(layout->itemAt(1,0)->geometry().width(), 20.0); |
|
612 QCOMPARE(layout->itemAt(0,1)->geometry().width(), 25.0); |
|
613 QCOMPARE(layout->itemAt(1,1)->geometry().width(), 25.0); |
|
614 QCOMPARE(layout->itemAt(0,2)->geometry().width(), 40.0); |
|
615 QCOMPARE(layout->itemAt(1,2)->geometry().width(), 40.0); |
|
616 |
|
617 delete widget; |
|
618 } |
|
619 |
|
620 // public qreal columnSpacing(int column) const |
|
621 void tst_QGraphicsGridLayout::columnSpacing() |
|
622 { |
|
623 QGraphicsScene scene; |
|
624 QGraphicsView view(&scene); |
|
625 QGraphicsWidget *widget = new QGraphicsWidget(0, Qt::Window); |
|
626 QGraphicsGridLayout *layout = new QGraphicsGridLayout(); |
|
627 scene.addItem(widget); |
|
628 widget->setLayout(layout); |
|
629 populateLayout(layout, 3, 2); |
|
630 layout->setContentsMargins(0, 0, 0, 0); |
|
631 layout->setSpacing(0); |
|
632 QCOMPARE(layout->columnSpacing(0), 0.0); |
|
633 |
|
634 layout->setColumnSpacing(0, 20); |
|
635 view.show(); |
|
636 widget->show(); |
|
637 widget->resize(widget->effectiveSizeHint(Qt::PreferredSize)); |
|
638 QApplication::processEvents(); |
|
639 |
|
640 QCOMPARE(layout->itemAt(0,0)->geometry().left(), 0.0); |
|
641 QCOMPARE(layout->itemAt(0,0)->geometry().right(), 25.0); |
|
642 QCOMPARE(layout->itemAt(0,1)->geometry().left(), 45.0); |
|
643 QCOMPARE(layout->itemAt(0,1)->geometry().right(), 70.0); |
|
644 QCOMPARE(layout->itemAt(0,2)->geometry().left(), 70.0); |
|
645 QCOMPARE(layout->itemAt(0,2)->geometry().right(), 95.0); |
|
646 |
|
647 delete widget; |
|
648 } |
|
649 |
|
650 // public int columnStretchFactor(int column) const |
|
651 void tst_QGraphicsGridLayout::columnStretchFactor() |
|
652 { |
|
653 QGraphicsScene scene; |
|
654 QGraphicsView view(&scene); |
|
655 QGraphicsWidget *widget = new QGraphicsWidget(0, Qt::Window); |
|
656 QGraphicsGridLayout *layout = new QGraphicsGridLayout(); |
|
657 scene.addItem(widget); |
|
658 widget->setLayout(layout); |
|
659 populateLayout(layout, 3, 2); |
|
660 layout->setContentsMargins(0, 0, 0, 0); |
|
661 layout->setSpacing(0); |
|
662 |
|
663 layout->setColumnStretchFactor(0, 1); |
|
664 layout->setColumnStretchFactor(1, 2); |
|
665 layout->setColumnStretchFactor(2, 3); |
|
666 view.show(); |
|
667 widget->show(); |
|
668 widget->resize(130, 50); |
|
669 QApplication::processEvents(); |
|
670 |
|
671 QVERIFY(layout->itemAt(0,0)->geometry().width() < layout->itemAt(0,1)->geometry().width()); |
|
672 QVERIFY(layout->itemAt(0,1)->geometry().width() < layout->itemAt(0,2)->geometry().width()); |
|
673 QVERIFY(layout->itemAt(1,0)->geometry().width() < layout->itemAt(1,1)->geometry().width()); |
|
674 QVERIFY(layout->itemAt(1,1)->geometry().width() < layout->itemAt(1,2)->geometry().width()); |
|
675 |
|
676 delete widget; |
|
677 } |
|
678 |
|
679 |
|
680 // public int count() const |
|
681 void tst_QGraphicsGridLayout::count() |
|
682 { |
|
683 QGraphicsScene scene; |
|
684 QGraphicsView view(&scene); |
|
685 QGraphicsWidget *widget = new QGraphicsWidget(0, Qt::Window); |
|
686 QGraphicsGridLayout *layout = new QGraphicsGridLayout(); |
|
687 scene.addItem(widget); |
|
688 widget->setLayout(layout); |
|
689 populateLayout(layout, 3, 2); |
|
690 QCOMPARE(layout->count(), 6); |
|
691 layout->removeAt(5); |
|
692 layout->removeAt(3); |
|
693 QCOMPARE(layout->count(), 4); |
|
694 layout->removeAt(1); |
|
695 QCOMPARE(layout->count(), 3); |
|
696 layout->removeAt(0); |
|
697 QCOMPARE(layout->count(), 2); |
|
698 layout->removeAt(0); |
|
699 QCOMPARE(layout->count(), 1); |
|
700 layout->removeAt(0); |
|
701 QCOMPARE(layout->count(), 0); |
|
702 |
|
703 delete widget; |
|
704 } |
|
705 |
|
706 void tst_QGraphicsGridLayout::horizontalSpacing_data() |
|
707 { |
|
708 QTest::addColumn<qreal>("horizontalSpacing"); |
|
709 QTest::newRow("zero") << qreal(0.0); |
|
710 QTest::newRow("10") << qreal(10.0); |
|
711 } |
|
712 |
|
713 // public qreal horizontalSpacing() const |
|
714 void tst_QGraphicsGridLayout::horizontalSpacing() |
|
715 { |
|
716 QFETCH(qreal, horizontalSpacing); |
|
717 QGraphicsScene scene; |
|
718 QGraphicsView view(&scene); |
|
719 QGraphicsWidget *widget = new QGraphicsWidget(0, Qt::Window); |
|
720 QGraphicsGridLayout *layout = new QGraphicsGridLayout(); |
|
721 scene.addItem(widget); |
|
722 widget->setLayout(layout); |
|
723 populateLayout(layout, 3, 2); |
|
724 layout->setContentsMargins(0, 0, 0, 0); |
|
725 qreal w = layout->sizeHint(Qt::PreferredSize, QSizeF()).width(); |
|
726 qreal oldSpacing = layout->horizontalSpacing(); |
|
727 if (oldSpacing != -1) { |
|
728 layout->setHorizontalSpacing(horizontalSpacing); |
|
729 QApplication::processEvents(); |
|
730 qreal new_w = layout->sizeHint(Qt::PreferredSize, QSizeF()).width(); |
|
731 QCOMPARE(new_w, w - (3-1)*(oldSpacing - horizontalSpacing)); |
|
732 } else { |
|
733 QSKIP("The current style uses non-uniform layout spacing", SkipAll); |
|
734 } |
|
735 delete widget; |
|
736 } |
|
737 |
|
738 void tst_QGraphicsGridLayout::contentsMargins() |
|
739 { |
|
740 QGraphicsScene scene; |
|
741 QGraphicsView view(&scene); |
|
742 QGraphicsWidget *widget = new QGraphicsWidget(0, Qt::Window); |
|
743 QGraphicsGridLayout *layout = new QGraphicsGridLayout(); |
|
744 QGraphicsGridLayout *sublayout = new QGraphicsGridLayout(); |
|
745 scene.addItem(widget); |
|
746 widget->setLayout(layout); |
|
747 layout->addItem(sublayout,0, 1); |
|
748 |
|
749 qreal left, top, right, bottom; |
|
750 // sublayouts have 0 margin |
|
751 sublayout->getContentsMargins(&left, &top, &right, &bottom); |
|
752 QCOMPARE(left, 0.0); |
|
753 QCOMPARE(top, 0.0); |
|
754 QCOMPARE(right, 0.0); |
|
755 QCOMPARE(bottom, 0.0); |
|
756 |
|
757 // top level layouts have style dependent margins. |
|
758 // we'll just check if its different from 0. (applies to all our styles) |
|
759 layout->getContentsMargins(&left, &top, &right, &bottom); |
|
760 QVERIFY(left >= 0.0); |
|
761 QVERIFY(top >= 0.0); |
|
762 QVERIFY(right >= 0.0); |
|
763 QVERIFY(bottom >= 0.0); |
|
764 |
|
765 delete widget; |
|
766 } |
|
767 |
|
768 // public QGraphicsLayoutItem* itemAt(int index) const |
|
769 void tst_QGraphicsGridLayout::itemAt() |
|
770 { |
|
771 QGraphicsScene scene; |
|
772 QGraphicsView view(&scene); |
|
773 QGraphicsWidget *widget = new QGraphicsWidget(0, Qt::Window); |
|
774 QGraphicsGridLayout *layout = new QGraphicsGridLayout(); |
|
775 scene.addItem(widget); |
|
776 widget->setLayout(layout); |
|
777 populateLayoutWithSpansAndHoles(layout); |
|
778 |
|
779 //itemAt(int row, int column) |
|
780 QVERIFY( layout->itemAt(0,0)); |
|
781 QVERIFY( layout->itemAt(0,1)); |
|
782 QCOMPARE(layout->itemAt(0,2), static_cast<QGraphicsLayoutItem*>(0)); |
|
783 QCOMPARE(layout->itemAt(1,0), static_cast<QGraphicsLayoutItem*>(0)); |
|
784 QVERIFY( layout->itemAt(1,1)); |
|
785 QVERIFY( layout->itemAt(1,2)); |
|
786 |
|
787 |
|
788 //itemAt(int index) |
|
789 for (int i = -2; i < layout->count() + 2; ++i) { |
|
790 if (i >= 0 && i < layout->count()) { |
|
791 QVERIFY(layout->itemAt(i)); |
|
792 } else { |
|
793 QTest::ignoreMessage(QtWarningMsg, QString::fromAscii("QGraphicsGridLayout::itemAt: invalid index %1").arg(i).toLatin1().constData()); |
|
794 QCOMPARE(layout->itemAt(i), static_cast<QGraphicsLayoutItem*>(0)); |
|
795 } |
|
796 } |
|
797 delete widget; |
|
798 } |
|
799 |
|
800 // public void removeAt(int index) |
|
801 void tst_QGraphicsGridLayout::removeAt() |
|
802 { |
|
803 QGraphicsScene scene; |
|
804 QGraphicsView view(&scene); |
|
805 QGraphicsWidget *widget = new QGraphicsWidget(0, Qt::Window); |
|
806 QGraphicsGridLayout *layout = new QGraphicsGridLayout(); |
|
807 scene.addItem(widget); |
|
808 widget->setLayout(layout); |
|
809 populateLayout(layout, 3, 2); |
|
810 QCOMPARE(layout->count(), 6); |
|
811 layout->removeAt(5); |
|
812 layout->removeAt(3); |
|
813 QCOMPARE(layout->count(), 4); |
|
814 layout->removeAt(1); |
|
815 QCOMPARE(layout->count(), 3); |
|
816 layout->removeAt(0); |
|
817 QCOMPARE(layout->count(), 2); |
|
818 layout->removeAt(0); |
|
819 QCOMPARE(layout->count(), 1); |
|
820 QGraphicsLayoutItem *item0 = layout->itemAt(0); |
|
821 QCOMPARE(item0->parentLayoutItem(), static_cast<QGraphicsLayoutItem *>(layout)); |
|
822 layout->removeAt(0); |
|
823 QCOMPARE(item0->parentLayoutItem(), static_cast<QGraphicsLayoutItem *>(0)); |
|
824 QCOMPARE(layout->count(), 0); |
|
825 QTest::ignoreMessage(QtWarningMsg, QString::fromAscii("QGraphicsGridLayout::removeAt: invalid index 0").toLatin1().constData()); |
|
826 layout->removeAt(0); |
|
827 QCOMPARE(layout->count(), 0); |
|
828 delete widget; |
|
829 } |
|
830 |
|
831 // public Qt::Alignment rowAlignment(int row) const |
|
832 void tst_QGraphicsGridLayout::rowAlignment() |
|
833 { |
|
834 QGraphicsScene scene; |
|
835 QGraphicsView view(&scene); |
|
836 QGraphicsWidget *widget = new QGraphicsWidget(0, Qt::Window); |
|
837 QGraphicsGridLayout *layout = new QGraphicsGridLayout(); |
|
838 scene.addItem(widget); |
|
839 widget->setLayout(layout); |
|
840 populateLayout(layout, 2, 3); |
|
841 layout->setContentsMargins(0, 0, 0, 0); |
|
842 layout->setSpacing(1); |
|
843 widget->setContentsMargins(0, 0, 0, 0); |
|
844 |
|
845 view.resize(330,450); |
|
846 widget->resize(300, 400); |
|
847 view.show(); |
|
848 widget->show(); |
|
849 QApplication::processEvents(); |
|
850 // Check default |
|
851 QCOMPARE(layout->rowAlignment(0), 0); |
|
852 QCOMPARE(layout->rowAlignment(1), 0); |
|
853 QCOMPARE(layout->rowAlignment(2), 0); |
|
854 |
|
855 // make the grids larger than the items, so that alignment kicks in |
|
856 layout->setRowMinimumHeight(0, 100.0); |
|
857 layout->setRowMinimumHeight(1, 100.0); |
|
858 layout->setRowMinimumHeight(2, 100.0); |
|
859 // expand columns also, so we can test combination of horiz and vertical alignment |
|
860 layout->setColumnMinimumWidth(0, 100.0); |
|
861 layout->setColumnMinimumWidth(1, 100.0); |
|
862 |
|
863 layout->setRowAlignment(0, Qt::AlignBottom); |
|
864 layout->setRowAlignment(1, Qt::AlignVCenter); |
|
865 layout->setRowAlignment(2, Qt::AlignTop); |
|
866 |
|
867 // see if item alignment takes preference over rowAlignment |
|
868 layout->setAlignment(layout->itemAt(0,0), Qt::AlignRight); |
|
869 layout->setAlignment(layout->itemAt(1,0), Qt::AlignTop); |
|
870 layout->setAlignment(layout->itemAt(2,0), Qt::AlignHCenter); |
|
871 |
|
872 QApplication::processEvents(); // process LayoutRequest |
|
873 |
|
874 QCOMPARE(layout->alignment(layout->itemAt(0,0)), Qt::AlignRight); //Qt::AlignRight | Qt::AlignBottom |
|
875 QCOMPARE(layout->itemAt(0,0)->geometry(), QRectF(50, 50, 50, 50)); |
|
876 QCOMPARE(layout->rowAlignment(0), Qt::AlignBottom); |
|
877 QCOMPARE(layout->itemAt(0,1)->geometry(), QRectF(101, 50, 50, 50)); |
|
878 QCOMPARE(layout->alignment(layout->itemAt(1,0)), Qt::AlignTop); |
|
879 QCOMPARE(layout->itemAt(1,0)->geometry(), QRectF(0, 101, 50, 50)); |
|
880 QCOMPARE(layout->rowAlignment(1), Qt::AlignVCenter); |
|
881 QCOMPARE(layout->itemAt(1,1)->geometry(), QRectF(101, 126, 50, 50)); |
|
882 QCOMPARE(layout->alignment(layout->itemAt(2,0)), Qt::AlignHCenter); |
|
883 QCOMPARE(layout->itemAt(2,0)->geometry(), QRectF(25, 202, 50, 50)); |
|
884 QCOMPARE(layout->rowAlignment(2), Qt::AlignTop); |
|
885 QCOMPARE(layout->itemAt(2,1)->geometry(), QRectF(101,202, 50, 50)); |
|
886 |
|
887 delete widget; |
|
888 } |
|
889 |
|
890 // public int rowCount() const |
|
891 // public int columnCount() const |
|
892 void tst_QGraphicsGridLayout::rowCount() |
|
893 { |
|
894 QGraphicsScene scene; |
|
895 QGraphicsView view(&scene); |
|
896 QGraphicsWidget *widget = new QGraphicsWidget(0, Qt::Window); |
|
897 QGraphicsGridLayout *layout = new QGraphicsGridLayout(); |
|
898 scene.addItem(widget); |
|
899 widget->setLayout(layout); |
|
900 populateLayout(layout, 2, 3); |
|
901 layout->setContentsMargins(0, 0, 0, 0); |
|
902 layout->setSpacing(0); |
|
903 widget->setContentsMargins(0, 0, 0, 0); |
|
904 QCOMPARE(layout->rowCount(), 3); |
|
905 QCOMPARE(layout->columnCount(), 2); |
|
906 |
|
907 // with spans and holes... |
|
908 widget->setLayout(0); |
|
909 layout = new QGraphicsGridLayout(); |
|
910 populateLayoutWithSpansAndHoles(layout); |
|
911 QCOMPARE(layout->rowCount(), 2); |
|
912 QCOMPARE(layout->columnCount(), 3); |
|
913 |
|
914 delete widget; |
|
915 } |
|
916 |
|
917 // public qreal rowMaximumHeight(int row) const |
|
918 void tst_QGraphicsGridLayout::rowMaximumHeight() |
|
919 { |
|
920 QGraphicsScene scene; |
|
921 QGraphicsView view(&scene); |
|
922 QGraphicsWidget *widget = new QGraphicsWidget(0, Qt::Window); |
|
923 QGraphicsGridLayout *layout = new QGraphicsGridLayout; |
|
924 scene.addItem(widget); |
|
925 widget->setLayout(layout); |
|
926 populateLayout(layout, 2, 3); |
|
927 layout->setContentsMargins(0, 0, 0, 0); |
|
928 layout->setSpacing(0); |
|
929 |
|
930 // should at least be a very large number |
|
931 QVERIFY(layout->rowMaximumHeight(0) >= 10000); |
|
932 QCOMPARE(layout->rowMaximumHeight(0), layout->rowMaximumHeight(1)); |
|
933 QCOMPARE(layout->rowMaximumHeight(1), layout->rowMaximumHeight(2)); |
|
934 layout->setRowMaximumHeight(0, 20); |
|
935 layout->setRowMaximumHeight(2, 60); |
|
936 |
|
937 view.show(); |
|
938 widget->show(); |
|
939 widget->resize(widget->effectiveSizeHint(Qt::PreferredSize)); |
|
940 QApplication::processEvents(); |
|
941 |
|
942 QCOMPARE(layout->itemAt(0,0)->geometry().height(), 20.0); |
|
943 QCOMPARE(layout->itemAt(0,1)->geometry().height(), 20.0); |
|
944 QCOMPARE(layout->itemAt(1,0)->geometry().height(), 25.0); |
|
945 QCOMPARE(layout->itemAt(1,1)->geometry().height(), 25.0); |
|
946 QCOMPARE(layout->itemAt(2,0)->geometry().height(), 25.0); |
|
947 QCOMPARE(layout->itemAt(2,1)->geometry().height(), 25.0); |
|
948 |
|
949 delete widget; |
|
950 } |
|
951 |
|
952 // public qreal rowMinimumHeight(int row) const |
|
953 void tst_QGraphicsGridLayout::rowMinimumHeight() |
|
954 { |
|
955 QGraphicsScene scene; |
|
956 QGraphicsView view(&scene); |
|
957 QGraphicsWidget *widget = new QGraphicsWidget(0, Qt::Window); |
|
958 QGraphicsGridLayout *layout = new QGraphicsGridLayout(); |
|
959 scene.addItem(widget); |
|
960 widget->setLayout(layout); |
|
961 populateLayout(layout, 2, 3); |
|
962 layout->setContentsMargins(0, 0, 0, 0); |
|
963 layout->setSpacing(0); |
|
964 |
|
965 // should at least be a very large number |
|
966 QCOMPARE(layout->rowMinimumHeight(0), 0.0); |
|
967 QCOMPARE(layout->rowMinimumHeight(0), layout->rowMinimumHeight(1)); |
|
968 QCOMPARE(layout->rowMinimumHeight(1), layout->rowMinimumHeight(2)); |
|
969 layout->setRowMinimumHeight(0, 20); |
|
970 layout->setRowMinimumHeight(2, 40); |
|
971 |
|
972 view.show(); |
|
973 widget->show(); |
|
974 widget->resize(widget->effectiveSizeHint(Qt::PreferredSize)); |
|
975 QApplication::processEvents(); |
|
976 |
|
977 QCOMPARE(layout->itemAt(0,0)->geometry().height(), 25.0); |
|
978 QCOMPARE(layout->itemAt(0,1)->geometry().height(), 25.0); |
|
979 QCOMPARE(layout->itemAt(1,0)->geometry().height(), 25.0); |
|
980 QCOMPARE(layout->itemAt(1,1)->geometry().height(), 25.0); |
|
981 QCOMPARE(layout->itemAt(2,0)->geometry().height(), 40.0); |
|
982 QCOMPARE(layout->itemAt(2,1)->geometry().height(), 40.0); |
|
983 |
|
984 delete widget; |
|
985 } |
|
986 |
|
987 // public qreal rowPreferredHeight(int row) const |
|
988 void tst_QGraphicsGridLayout::rowPreferredHeight() |
|
989 { |
|
990 QGraphicsScene scene; |
|
991 QGraphicsView view(&scene); |
|
992 QGraphicsWidget *widget = new QGraphicsWidget(0, Qt::Window); |
|
993 QGraphicsGridLayout *layout = new QGraphicsGridLayout(); |
|
994 scene.addItem(widget); |
|
995 widget->setLayout(layout); |
|
996 populateLayout(layout, 2, 3); |
|
997 layout->setContentsMargins(0, 0, 0, 0); |
|
998 layout->setSpacing(0); |
|
999 |
|
1000 // default preferred height ?? |
|
1001 QCOMPARE(layout->rowPreferredHeight(0), 0.0); |
|
1002 QCOMPARE(layout->rowPreferredHeight(0), layout->rowPreferredHeight(1)); |
|
1003 QCOMPARE(layout->rowPreferredHeight(1), layout->rowPreferredHeight(2)); |
|
1004 layout->setRowPreferredHeight(0, 20); |
|
1005 layout->setRowPreferredHeight(2, 40); |
|
1006 |
|
1007 view.show(); |
|
1008 widget->show(); |
|
1009 widget->resize(widget->effectiveSizeHint(Qt::PreferredSize)); |
|
1010 QApplication::processEvents(); |
|
1011 |
|
1012 // ### Jasmin: Should rowPreferredHeight have precedence over sizeHint(Qt::PreferredSize) ? |
|
1013 QCOMPARE(layout->itemAt(0,0)->geometry().height(), 25.0); |
|
1014 QCOMPARE(layout->itemAt(0,1)->geometry().height(), 25.0); |
|
1015 QCOMPARE(layout->itemAt(1,0)->geometry().height(), 25.0); |
|
1016 QCOMPARE(layout->itemAt(1,1)->geometry().height(), 25.0); |
|
1017 QCOMPARE(layout->itemAt(2,0)->geometry().height(), 40.0); |
|
1018 QCOMPARE(layout->itemAt(2,1)->geometry().height(), 40.0); |
|
1019 |
|
1020 delete widget; |
|
1021 } |
|
1022 |
|
1023 // public void setRowFixedHeight(int row, qreal height) |
|
1024 void tst_QGraphicsGridLayout::setRowFixedHeight() |
|
1025 { |
|
1026 QGraphicsScene scene; |
|
1027 QGraphicsView view(&scene); |
|
1028 QGraphicsWidget *widget = new QGraphicsWidget(0, Qt::Window); |
|
1029 QGraphicsGridLayout *layout = new QGraphicsGridLayout(); |
|
1030 scene.addItem(widget); |
|
1031 widget->setLayout(layout); |
|
1032 populateLayout(layout, 2, 3); |
|
1033 layout->setContentsMargins(0, 0, 0, 0); |
|
1034 layout->setSpacing(0); |
|
1035 |
|
1036 layout->setRowFixedHeight(0, 20.); |
|
1037 layout->setRowFixedHeight(2, 40.); |
|
1038 |
|
1039 view.show(); |
|
1040 widget->show(); |
|
1041 widget->resize(widget->effectiveSizeHint(Qt::PreferredSize)); |
|
1042 QApplication::processEvents(); |
|
1043 |
|
1044 QCOMPARE(layout->itemAt(0,0)->geometry().height(), 20.0); |
|
1045 QCOMPARE(layout->itemAt(0,1)->geometry().height(), 20.0); |
|
1046 QCOMPARE(layout->itemAt(1,0)->geometry().height(), 25.0); |
|
1047 QCOMPARE(layout->itemAt(1,1)->geometry().height(), 25.0); |
|
1048 QCOMPARE(layout->itemAt(2,0)->geometry().height(), 40.0); |
|
1049 QCOMPARE(layout->itemAt(2,1)->geometry().height(), 40.0); |
|
1050 |
|
1051 delete widget; |
|
1052 } |
|
1053 |
|
1054 // public qreal rowSpacing(int row) const |
|
1055 void tst_QGraphicsGridLayout::rowSpacing() |
|
1056 { |
|
1057 QGraphicsScene scene; |
|
1058 QGraphicsView view(&scene); |
|
1059 QGraphicsWidget *widget = new QGraphicsWidget(0, Qt::Window); |
|
1060 QGraphicsGridLayout *layout = new QGraphicsGridLayout(); |
|
1061 scene.addItem(widget); |
|
1062 widget->setLayout(layout); |
|
1063 populateLayout(layout, 3, 2); |
|
1064 layout->setContentsMargins(0, 0, 0, 0); |
|
1065 layout->setSpacing(0); |
|
1066 QCOMPARE(layout->columnSpacing(0), 0.0); |
|
1067 |
|
1068 layout->setColumnSpacing(0, 20); |
|
1069 view.show(); |
|
1070 widget->show(); |
|
1071 widget->resize(widget->effectiveSizeHint(Qt::PreferredSize)); |
|
1072 QApplication::processEvents(); |
|
1073 |
|
1074 QCOMPARE(layout->itemAt(0,0)->geometry().left(), 0.0); |
|
1075 QCOMPARE(layout->itemAt(0,0)->geometry().right(), 25.0); |
|
1076 QCOMPARE(layout->itemAt(0,1)->geometry().left(), 45.0); |
|
1077 QCOMPARE(layout->itemAt(0,1)->geometry().right(), 70.0); |
|
1078 QCOMPARE(layout->itemAt(0,2)->geometry().left(), 70.0); |
|
1079 QCOMPARE(layout->itemAt(0,2)->geometry().right(), 95.0); |
|
1080 |
|
1081 delete widget; |
|
1082 |
|
1083 } |
|
1084 |
|
1085 // public int rowStretchFactor(int row) const |
|
1086 void tst_QGraphicsGridLayout::rowStretchFactor() |
|
1087 { |
|
1088 QGraphicsScene scene; |
|
1089 QGraphicsView view(&scene); |
|
1090 QGraphicsWidget *widget = new QGraphicsWidget(0, Qt::Window); |
|
1091 QGraphicsGridLayout *layout = new QGraphicsGridLayout(); |
|
1092 scene.addItem(widget); |
|
1093 widget->setLayout(layout); |
|
1094 populateLayout(layout, 2, 3); |
|
1095 layout->setContentsMargins(0, 0, 0, 0); |
|
1096 layout->setSpacing(0); |
|
1097 |
|
1098 layout->setRowStretchFactor(0, 1); |
|
1099 layout->setRowStretchFactor(1, 2); |
|
1100 layout->setRowStretchFactor(2, 3); |
|
1101 view.show(); |
|
1102 widget->show(); |
|
1103 widget->resize(50, 130); |
|
1104 QApplication::processEvents(); |
|
1105 |
|
1106 QVERIFY(layout->itemAt(0,0)->geometry().height() < layout->itemAt(1,0)->geometry().height()); |
|
1107 QVERIFY(layout->itemAt(1,0)->geometry().height() < layout->itemAt(2,0)->geometry().height()); |
|
1108 QVERIFY(layout->itemAt(0,1)->geometry().height() < layout->itemAt(1,1)->geometry().height()); |
|
1109 QVERIFY(layout->itemAt(1,1)->geometry().height() < layout->itemAt(2,1)->geometry().height()); |
|
1110 |
|
1111 delete widget; |
|
1112 } |
|
1113 |
|
1114 void tst_QGraphicsGridLayout::setColumnSpacing_data() |
|
1115 { |
|
1116 QTest::addColumn<int>("column"); |
|
1117 QTest::addColumn<qreal>("spacing"); |
|
1118 QTest::newRow("null") << 0 << qreal(0.0); |
|
1119 QTest::newRow("10") << 0 << qreal(10.0); |
|
1120 |
|
1121 } |
|
1122 |
|
1123 // public void setColumnSpacing(int column, qreal spacing) |
|
1124 void tst_QGraphicsGridLayout::setColumnSpacing() |
|
1125 { |
|
1126 QFETCH(int, column); |
|
1127 QFETCH(qreal, spacing); |
|
1128 |
|
1129 QGraphicsScene scene; |
|
1130 QGraphicsView view(&scene); |
|
1131 QGraphicsWidget *widget = new QGraphicsWidget(0, Qt::Window); |
|
1132 QGraphicsGridLayout *layout = new QGraphicsGridLayout(); |
|
1133 scene.addItem(widget); |
|
1134 widget->setLayout(layout); |
|
1135 populateLayout(layout, 3, 2); |
|
1136 layout->setSpacing(0); |
|
1137 layout->setContentsMargins(0, 0, 0, 0); |
|
1138 qreal oldSpacing = layout->columnSpacing(column); |
|
1139 QCOMPARE(oldSpacing, 0.0); |
|
1140 qreal w = layout->sizeHint(Qt::PreferredSize, QSizeF()).width(); |
|
1141 layout->setColumnSpacing(column, spacing); |
|
1142 QApplication::processEvents(); |
|
1143 QCOMPARE(layout->sizeHint(Qt::PreferredSize, QSizeF()).width(), w + spacing); |
|
1144 } |
|
1145 |
|
1146 void tst_QGraphicsGridLayout::setGeometry_data() |
|
1147 { |
|
1148 QTest::addColumn<QRectF>("rect"); |
|
1149 QTest::newRow("null") << QRectF(); |
|
1150 QTest::newRow("normal") << QRectF(0,0, 50, 50); |
|
1151 } |
|
1152 |
|
1153 // public void setGeometry(QRectF const& rect) |
|
1154 void tst_QGraphicsGridLayout::setGeometry() |
|
1155 { |
|
1156 QFETCH(QRectF, rect); |
|
1157 |
|
1158 QGraphicsWidget *window = new QGraphicsWidget; |
|
1159 QGraphicsGridLayout *layout = new QGraphicsGridLayout(); |
|
1160 window->setLayout(layout); |
|
1161 QGraphicsGridLayout *layout2 = new QGraphicsGridLayout(); |
|
1162 layout2->setMaximumSize(100, 100); |
|
1163 layout->addItem(layout2, 0, 0); |
|
1164 layout2->setGeometry(rect); |
|
1165 QCOMPARE(layout2->geometry(), rect); |
|
1166 } |
|
1167 |
|
1168 void tst_QGraphicsGridLayout::setRowSpacing_data() |
|
1169 { |
|
1170 QTest::addColumn<int>("row"); |
|
1171 QTest::addColumn<qreal>("spacing"); |
|
1172 QTest::newRow("null") << 0 << qreal(0.0); |
|
1173 QTest::newRow("10") << 0 << qreal(10.0); |
|
1174 |
|
1175 } |
|
1176 |
|
1177 // public void setRowSpacing(int row, qreal spacing) |
|
1178 void tst_QGraphicsGridLayout::setRowSpacing() |
|
1179 { |
|
1180 QFETCH(int, row); |
|
1181 QFETCH(qreal, spacing); |
|
1182 |
|
1183 QGraphicsScene scene; |
|
1184 QGraphicsView view(&scene); |
|
1185 QGraphicsWidget *widget = new QGraphicsWidget(0, Qt::Window); |
|
1186 QGraphicsGridLayout *layout = new QGraphicsGridLayout(); |
|
1187 scene.addItem(widget); |
|
1188 widget->setLayout(layout); |
|
1189 populateLayout(layout, 3, 2); |
|
1190 layout->setSpacing(0); |
|
1191 layout->setContentsMargins(0, 0, 0, 0); |
|
1192 qreal oldSpacing = layout->rowSpacing(row); |
|
1193 QCOMPARE(oldSpacing, 0.0); |
|
1194 qreal h = layout->sizeHint(Qt::PreferredSize, QSizeF()).height(); |
|
1195 layout->setRowSpacing(row, spacing); |
|
1196 QApplication::processEvents(); |
|
1197 QCOMPARE(layout->sizeHint(Qt::PreferredSize, QSizeF()).height(), h + spacing); |
|
1198 } |
|
1199 |
|
1200 void tst_QGraphicsGridLayout::setSpacing_data() |
|
1201 { |
|
1202 QTest::addColumn<qreal>("spacing"); |
|
1203 QTest::newRow("zero") << qreal(0.0); |
|
1204 QTest::newRow("17") << qreal(17.0); |
|
1205 } |
|
1206 |
|
1207 // public void setSpacing(qreal spacing) |
|
1208 void tst_QGraphicsGridLayout::setSpacing() |
|
1209 { |
|
1210 QFETCH(qreal, spacing); |
|
1211 QGraphicsScene scene; |
|
1212 QGraphicsView view(&scene); |
|
1213 QGraphicsWidget *widget = new QGraphicsWidget(0, Qt::Window); |
|
1214 QGraphicsGridLayout *layout = new QGraphicsGridLayout(); |
|
1215 scene.addItem(widget); |
|
1216 widget->setLayout(layout); |
|
1217 populateLayout(layout, 3, 2); |
|
1218 layout->setContentsMargins(0, 0, 0, 0); |
|
1219 QSizeF sh = layout->sizeHint(Qt::PreferredSize, QSizeF()); |
|
1220 qreal oldVSpacing = layout->verticalSpacing(); |
|
1221 qreal oldHSpacing = layout->horizontalSpacing(); |
|
1222 if (oldVSpacing != -1) { |
|
1223 layout->setSpacing(spacing); |
|
1224 QApplication::processEvents(); |
|
1225 QSizeF newSH = layout->sizeHint(Qt::PreferredSize, QSizeF()); |
|
1226 QCOMPARE(newSH.height(), sh.height() - (2-1)*(oldVSpacing - spacing)); |
|
1227 QCOMPARE(newSH.width(), sh.width() - (3-1)*(oldHSpacing - spacing)); |
|
1228 } else { |
|
1229 QSKIP("The current style uses non-uniform layout spacing", SkipAll); |
|
1230 } |
|
1231 delete widget; |
|
1232 } |
|
1233 |
|
1234 void tst_QGraphicsGridLayout::sizeHint_data() |
|
1235 { |
|
1236 |
|
1237 /* |
|
1238 QTest::addColumn<Qt::SizeHint>("which"); |
|
1239 QTest::addColumn<QSizeF>("constraint"); |
|
1240 QTest::addColumn<QSizeF>("sizeHint"); |
|
1241 QTest::newRow("null") << 0; |
|
1242 */ |
|
1243 } |
|
1244 |
|
1245 // public QSizeF sizeHint(Qt::SizeHint which, QSizeF const& constraint = QSizeF()) const |
|
1246 void tst_QGraphicsGridLayout::sizeHint() |
|
1247 { |
|
1248 /* |
|
1249 QFETCH(Qt::SizeHint, which); |
|
1250 QFETCH(QSizeF, constraint); |
|
1251 QFETCH(QSizeF, sizeHint); |
|
1252 |
|
1253 QGraphicsGridLayout layout; |
|
1254 |
|
1255 layout.sizeHint(); |
|
1256 */ |
|
1257 QSKIP("Test unimplemented", SkipSingle); |
|
1258 } |
|
1259 |
|
1260 void tst_QGraphicsGridLayout::verticalSpacing_data() |
|
1261 { |
|
1262 QTest::addColumn<qreal>("verticalSpacing"); |
|
1263 QTest::newRow("zero") << qreal(0.0); |
|
1264 QTest::newRow("17") << qreal(10.0); |
|
1265 } |
|
1266 |
|
1267 // public qreal verticalSpacing() const |
|
1268 void tst_QGraphicsGridLayout::verticalSpacing() |
|
1269 { |
|
1270 QFETCH(qreal, verticalSpacing); |
|
1271 QGraphicsScene scene; |
|
1272 QGraphicsView view(&scene); |
|
1273 QGraphicsWidget *widget = new QGraphicsWidget(0, Qt::Window); |
|
1274 QGraphicsGridLayout *layout = new QGraphicsGridLayout(); |
|
1275 scene.addItem(widget); |
|
1276 widget->setLayout(layout); |
|
1277 populateLayout(layout, 3, 2); |
|
1278 layout->setContentsMargins(0, 0, 0, 0); |
|
1279 qreal h = layout->sizeHint(Qt::PreferredSize, QSizeF()).height(); |
|
1280 qreal oldSpacing = layout->verticalSpacing(); |
|
1281 if (oldSpacing != -1) { |
|
1282 layout->setVerticalSpacing(verticalSpacing); |
|
1283 QApplication::processEvents(); |
|
1284 qreal new_h = layout->sizeHint(Qt::PreferredSize, QSizeF()).height(); |
|
1285 QCOMPARE(new_h, h - (2-1)*(oldSpacing - verticalSpacing)); |
|
1286 } else { |
|
1287 QSKIP("The current style uses non-uniform layout spacing", SkipAll); |
|
1288 } |
|
1289 delete widget; |
|
1290 } |
|
1291 |
|
1292 void tst_QGraphicsGridLayout::layoutDirection() |
|
1293 { |
|
1294 QGraphicsScene scene; |
|
1295 QGraphicsView view(&scene); |
|
1296 |
|
1297 QGraphicsWidget *window = new QGraphicsWidget(0, Qt::Window); |
|
1298 QGraphicsGridLayout *layout = new QGraphicsGridLayout; |
|
1299 layout->setContentsMargins(1, 2, 3, 4); |
|
1300 layout->setSpacing(6); |
|
1301 RectWidget *w1 = new RectWidget; |
|
1302 w1->setMinimumSize(30, 20); |
|
1303 layout->addItem(w1, 0, 0); |
|
1304 RectWidget *w2 = new RectWidget; |
|
1305 w2->setMinimumSize(20, 20); |
|
1306 w2->setMaximumSize(20, 20); |
|
1307 layout->addItem(w2, 0, 1); |
|
1308 RectWidget *w3 = new RectWidget; |
|
1309 w3->setMinimumSize(20, 20); |
|
1310 w3->setMaximumSize(20, 20); |
|
1311 layout->addItem(w3, 1, 0); |
|
1312 RectWidget *w4 = new RectWidget; |
|
1313 w4->setMinimumSize(30, 20); |
|
1314 layout->addItem(w4, 1, 1); |
|
1315 |
|
1316 layout->setAlignment(w2, Qt::AlignRight); |
|
1317 layout->setAlignment(w3, Qt::AlignLeft); |
|
1318 |
|
1319 scene.addItem(window); |
|
1320 window->setLayout(layout); |
|
1321 view.show(); |
|
1322 window->resize(70, 52); |
|
1323 QApplication::processEvents(); |
|
1324 QCOMPARE(w1->geometry().left(), 1.0); |
|
1325 QCOMPARE(w1->geometry().right(), 31.0); |
|
1326 QCOMPARE(w2->geometry().left(), 47.0); |
|
1327 QCOMPARE(w2->geometry().right(), 67.0); |
|
1328 QCOMPARE(w3->geometry().left(), 1.0); |
|
1329 QCOMPARE(w3->geometry().right(), 21.0); |
|
1330 QCOMPARE(w4->geometry().left(), 37.0); |
|
1331 QCOMPARE(w4->geometry().right(), 67.0); |
|
1332 |
|
1333 window->setLayoutDirection(Qt::RightToLeft); |
|
1334 QApplication::processEvents(); |
|
1335 QCOMPARE(w1->geometry().left(), 39.0); |
|
1336 QCOMPARE(w1->geometry().right(), 69.0); |
|
1337 QCOMPARE(w2->geometry().left(), 3.0); |
|
1338 QCOMPARE(w2->geometry().right(), 23.0); |
|
1339 QCOMPARE(w3->geometry().left(), 49.0); |
|
1340 QCOMPARE(w3->geometry().right(), 69.0); |
|
1341 QCOMPARE(w4->geometry().left(), 3.0); |
|
1342 QCOMPARE(w4->geometry().right(), 33.0); |
|
1343 |
|
1344 delete window; |
|
1345 } |
|
1346 |
|
1347 void tst_QGraphicsGridLayout::removeLayout() |
|
1348 { |
|
1349 QGraphicsScene scene; |
|
1350 RectWidget *textEdit = new RectWidget; |
|
1351 RectWidget *pushButton = new RectWidget; |
|
1352 scene.addItem(textEdit); |
|
1353 scene.addItem(pushButton); |
|
1354 |
|
1355 QGraphicsGridLayout *layout = new QGraphicsGridLayout; |
|
1356 layout->addItem(textEdit, 0, 0); |
|
1357 layout->addItem(pushButton, 1, 0); |
|
1358 |
|
1359 QGraphicsWidget *form = new QGraphicsWidget; |
|
1360 form->setLayout(layout); |
|
1361 scene.addItem(form); |
|
1362 |
|
1363 QGraphicsView view(&scene); |
|
1364 view.show(); |
|
1365 QTest::qWait(20); |
|
1366 |
|
1367 QRectF r1 = textEdit->geometry(); |
|
1368 QRectF r2 = pushButton->geometry(); |
|
1369 form->setLayout(0); |
|
1370 //documentation of QGraphicsWidget::setLayout: |
|
1371 //If layout is 0, the widget is left without a layout. Existing subwidgets' geometries will remain unaffected. |
|
1372 QCOMPARE(textEdit->geometry(), r1); |
|
1373 QCOMPARE(pushButton->geometry(), r2); |
|
1374 } |
|
1375 |
|
1376 struct ItemDesc |
|
1377 { |
|
1378 ItemDesc(int row, int col) |
|
1379 : m_pos(qMakePair(row, col)), |
|
1380 m_rowSpan(1), |
|
1381 m_colSpan(1), |
|
1382 m_sizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred)), |
|
1383 m_align(0) |
|
1384 { |
|
1385 } |
|
1386 |
|
1387 ItemDesc &rowSpan(int span) { |
|
1388 m_rowSpan = span; |
|
1389 return (*this); |
|
1390 } |
|
1391 |
|
1392 ItemDesc &colSpan(int span) { |
|
1393 m_colSpan = span; |
|
1394 return (*this); |
|
1395 } |
|
1396 |
|
1397 ItemDesc &sizePolicy(const QSizePolicy &sp) { |
|
1398 m_sizePolicy = sp; |
|
1399 return (*this); |
|
1400 } |
|
1401 |
|
1402 ItemDesc &sizePolicy(QSizePolicy::Policy horAndVer) { |
|
1403 m_sizePolicy = QSizePolicy(horAndVer, horAndVer); |
|
1404 return (*this); |
|
1405 } |
|
1406 |
|
1407 ItemDesc &sizePolicyH(QSizePolicy::Policy hor) { |
|
1408 m_sizePolicy.setHorizontalPolicy(hor); |
|
1409 return (*this); |
|
1410 } |
|
1411 |
|
1412 ItemDesc &sizePolicyV(QSizePolicy::Policy ver) { |
|
1413 m_sizePolicy.setVerticalPolicy(ver); |
|
1414 return (*this); |
|
1415 } |
|
1416 |
|
1417 ItemDesc &sizePolicy(QSizePolicy::Policy hor, QSizePolicy::Policy ver) { |
|
1418 m_sizePolicy = QSizePolicy(hor, ver); |
|
1419 return (*this); |
|
1420 } |
|
1421 |
|
1422 ItemDesc &sizeHint(Qt::SizeHint which, const QSizeF &sh) { |
|
1423 m_sizeHints[which] = sh; |
|
1424 return (*this); |
|
1425 } |
|
1426 |
|
1427 ItemDesc &preferredSizeHint(const QSizeF &sh) { |
|
1428 m_sizeHints[Qt::PreferredSize] = sh; |
|
1429 return (*this); |
|
1430 } |
|
1431 |
|
1432 ItemDesc &minSize(const QSizeF &sz) { |
|
1433 m_sizes[Qt::MinimumSize] = sz; |
|
1434 return (*this); |
|
1435 } |
|
1436 ItemDesc &preferredSize(const QSizeF &sz) { |
|
1437 m_sizes[Qt::PreferredSize] = sz; |
|
1438 return (*this); |
|
1439 } |
|
1440 ItemDesc &maxSize(const QSizeF &sz) { |
|
1441 m_sizes[Qt::MaximumSize] = sz; |
|
1442 return (*this); |
|
1443 } |
|
1444 |
|
1445 ItemDesc &alignment(Qt::Alignment alignment) { |
|
1446 m_align = alignment; |
|
1447 return (*this); |
|
1448 } |
|
1449 |
|
1450 void apply(QGraphicsGridLayout *layout, RectWidget *item) { |
|
1451 item->setSizePolicy(m_sizePolicy); |
|
1452 for (int i = 0; i < Qt::NSizeHints; ++i) { |
|
1453 item->setSizeHint((Qt::SizeHint)i, m_sizeHints[i]); |
|
1454 if (!m_sizes[i].isValid()) |
|
1455 continue; |
|
1456 switch ((Qt::SizeHint)i) { |
|
1457 case Qt::MinimumSize: |
|
1458 item->setMinimumSize(m_sizes[i]); |
|
1459 break; |
|
1460 case Qt::PreferredSize: |
|
1461 item->setPreferredSize(m_sizes[i]); |
|
1462 break; |
|
1463 case Qt::MaximumSize: |
|
1464 item->setMaximumSize(m_sizes[i]); |
|
1465 break; |
|
1466 default: |
|
1467 qWarning("not implemented"); |
|
1468 break; |
|
1469 } |
|
1470 } |
|
1471 layout->addItem(item, m_pos.first, m_pos.second, m_rowSpan, m_colSpan); |
|
1472 layout->setAlignment(item, m_align); |
|
1473 } |
|
1474 |
|
1475 //private: |
|
1476 QPair<int,int> m_pos; // row,col |
|
1477 int m_rowSpan; |
|
1478 int m_colSpan; |
|
1479 QSizePolicy m_sizePolicy; |
|
1480 QSizeF m_sizeHints[Qt::NSizeHints]; |
|
1481 QSizeF m_sizes[Qt::NSizeHints]; |
|
1482 Qt::Alignment m_align; |
|
1483 }; |
|
1484 |
|
1485 typedef QList<ItemDesc> ItemList; |
|
1486 Q_DECLARE_METATYPE(ItemList); |
|
1487 |
|
1488 typedef QList<QSizeF> SizeList; |
|
1489 Q_DECLARE_METATYPE(SizeList); |
|
1490 |
|
1491 void tst_QGraphicsGridLayout::defaultStretchFactors_data() |
|
1492 { |
|
1493 QTest::addColumn<ItemList>("itemDescriptions"); |
|
1494 QTest::addColumn<QSizeF>("newSize"); |
|
1495 QTest::addColumn<SizeList>("expectedSizes"); |
|
1496 |
|
1497 QTest::newRow("usepreferredsize") << (ItemList() |
|
1498 << ItemDesc(0,0) |
|
1499 .preferredSizeHint(QSizeF(10,10)) |
|
1500 << ItemDesc(0,1) |
|
1501 .preferredSizeHint(QSizeF(10,10)) |
|
1502 << ItemDesc(0,2) |
|
1503 .preferredSizeHint(QSizeF(10,10)) |
|
1504 << ItemDesc(1,0) |
|
1505 .preferredSizeHint(QSizeF(10,10)) |
|
1506 << ItemDesc(1,1) |
|
1507 .preferredSizeHint(QSizeF(10,10)) |
|
1508 << ItemDesc(1,2) |
|
1509 .preferredSizeHint(QSizeF(10,10)) |
|
1510 ) |
|
1511 << QSizeF() |
|
1512 << (SizeList() |
|
1513 << QSizeF(10,10) << QSizeF(10,10) << QSizeF(10,10) |
|
1514 << QSizeF(10,10) << QSizeF(10,10) << QSizeF(10,10) |
|
1515 ); |
|
1516 |
|
1517 QTest::newRow("ignoreitem01") << (ItemList() |
|
1518 << ItemDesc(0,0) |
|
1519 .preferredSizeHint(QSizeF(10,10)) |
|
1520 << ItemDesc(0,1) |
|
1521 .sizePolicy(QSizePolicy::Ignored) |
|
1522 .preferredSizeHint(QSizeF(10,10)) |
|
1523 << ItemDesc(0,2) |
|
1524 .preferredSizeHint(QSizeF(10,10)) |
|
1525 << ItemDesc(1,0) |
|
1526 .preferredSizeHint(QSizeF(10,10)) |
|
1527 << ItemDesc(1,1) |
|
1528 .preferredSizeHint(QSizeF(10,10)) |
|
1529 << ItemDesc(1,2) |
|
1530 .preferredSizeHint(QSizeF(10,10)) |
|
1531 ) |
|
1532 << QSizeF() |
|
1533 << (SizeList() |
|
1534 << QSizeF(10,10) << QSizeF(10,10) << QSizeF(10,10) |
|
1535 << QSizeF(10,10) << QSizeF(10,10) << QSizeF(10,10) |
|
1536 ); |
|
1537 |
|
1538 QTest::newRow("ignoreitem01_resize120x40") << (ItemList() |
|
1539 << ItemDesc(0,0) |
|
1540 .preferredSizeHint(QSizeF(10,10)) |
|
1541 << ItemDesc(0,1) |
|
1542 .sizePolicy(QSizePolicy::Ignored) |
|
1543 .preferredSizeHint(QSizeF(20,10)) |
|
1544 << ItemDesc(0,2) |
|
1545 .preferredSizeHint(QSizeF(30,10)) |
|
1546 << ItemDesc(1,0) |
|
1547 .preferredSizeHint(QSizeF(10,10)) |
|
1548 << ItemDesc(1,1) |
|
1549 .preferredSizeHint(QSizeF(20,10)) |
|
1550 << ItemDesc(1,2) |
|
1551 .preferredSizeHint(QSizeF(30,10)) |
|
1552 ) |
|
1553 << QSizeF(120, 40) |
|
1554 << (SizeList() |
|
1555 << QSizeF(20,20) << QSizeF(40,20) << QSizeF(60,20) |
|
1556 << QSizeF(20,20) << QSizeF(40,20) << QSizeF(60,20) |
|
1557 ); |
|
1558 |
|
1559 QTest::newRow("ignoreitem11_resize120x40") << (ItemList() |
|
1560 << ItemDesc(0,0) |
|
1561 .preferredSizeHint(QSizeF(10,10)) |
|
1562 << ItemDesc(0,1) |
|
1563 .preferredSizeHint(QSizeF(20,10)) |
|
1564 << ItemDesc(0,2) |
|
1565 .preferredSizeHint(QSizeF(30,10)) |
|
1566 << ItemDesc(1,0) |
|
1567 .preferredSizeHint(QSizeF(10,20)) |
|
1568 << ItemDesc(1,1) |
|
1569 .sizePolicy(QSizePolicy::Ignored) |
|
1570 .preferredSizeHint(QSizeF(20,20)) |
|
1571 << ItemDesc(1,2) |
|
1572 .preferredSizeHint(QSizeF(30,20)) |
|
1573 ) |
|
1574 << QSizeF(120, 60) |
|
1575 << (SizeList() |
|
1576 << QSizeF(20,20) << QSizeF(40,20) << QSizeF(60,20) |
|
1577 << QSizeF(20,40) << QSizeF(40,40) << QSizeF(60,40) |
|
1578 ); |
|
1579 |
|
1580 QTest::newRow("ignoreitem01_span01_resize70x60") << (ItemList() |
|
1581 << ItemDesc(0,0) |
|
1582 .preferredSizeHint(QSizeF(10,10)) |
|
1583 << ItemDesc(0,1) |
|
1584 .preferredSizeHint(QSizeF(20,10)) |
|
1585 .sizePolicy(QSizePolicy::Ignored) |
|
1586 .rowSpan(2) |
|
1587 << ItemDesc(0,2) |
|
1588 .preferredSizeHint(QSizeF(30,10)) |
|
1589 << ItemDesc(1,0) |
|
1590 .preferredSizeHint(QSizeF(10,20)) |
|
1591 << ItemDesc(1,2) |
|
1592 .preferredSizeHint(QSizeF(30,20)) |
|
1593 ) |
|
1594 << QSizeF(70, 60) |
|
1595 << (SizeList() |
|
1596 << QSizeF(20,20) << QSizeF(10,60) << QSizeF(40,20) |
|
1597 << QSizeF(20,40) << QSizeF(40,40) |
|
1598 ); |
|
1599 |
|
1600 QTest::newRow("ignoreitem10_resize40x120") << (ItemList() |
|
1601 << ItemDesc(0,0) |
|
1602 .preferredSizeHint(QSizeF(10,10)) |
|
1603 << ItemDesc(0,1) |
|
1604 .preferredSizeHint(QSizeF(10,10)) |
|
1605 << ItemDesc(1,0) |
|
1606 .sizePolicy(QSizePolicy::Ignored) |
|
1607 .preferredSizeHint(QSizeF(10,20)) |
|
1608 << ItemDesc(1,1) |
|
1609 .preferredSizeHint(QSizeF(10,20)) |
|
1610 << ItemDesc(2,0) |
|
1611 .preferredSizeHint(QSizeF(10,30)) |
|
1612 << ItemDesc(2,1) |
|
1613 .preferredSizeHint(QSizeF(10,30)) |
|
1614 ) |
|
1615 << QSizeF(40, 120) |
|
1616 << (SizeList() |
|
1617 << QSizeF(20,20) << QSizeF(20,20) |
|
1618 << QSizeF(20,40) << QSizeF(20,40) |
|
1619 << QSizeF(20,60) << QSizeF(20,60) |
|
1620 ); |
|
1621 |
|
1622 QTest::newRow("ignoreitem01_span02") << (ItemList() |
|
1623 << ItemDesc(0,0) |
|
1624 .preferredSizeHint(QSizeF(10,10)) |
|
1625 << ItemDesc(0,1) |
|
1626 .sizePolicy(QSizePolicy::Ignored) |
|
1627 .preferredSizeHint(QSizeF(10,20)) |
|
1628 .rowSpan(2) |
|
1629 << ItemDesc(0,2) |
|
1630 .preferredSizeHint(QSizeF(10,10)) |
|
1631 << ItemDesc(1,0) |
|
1632 .preferredSizeHint(QSizeF(10,10)) |
|
1633 << ItemDesc(1,2) |
|
1634 .preferredSizeHint(QSizeF(10,10)) |
|
1635 ) |
|
1636 << QSizeF() |
|
1637 << (SizeList() |
|
1638 << QSizeF(10,10) << QSizeF(0,20) << QSizeF(10,10) |
|
1639 << QSizeF(10,10) << QSizeF(10,10) |
|
1640 ); |
|
1641 |
|
1642 QTest::newRow("ignoreitem02_span02") << (ItemList() |
|
1643 << ItemDesc(0,0) |
|
1644 .preferredSizeHint(QSizeF(10,10)) |
|
1645 << ItemDesc(0,1) |
|
1646 .preferredSizeHint(QSizeF(10,10)) |
|
1647 << ItemDesc(0,2) |
|
1648 .sizePolicy(QSizePolicy::Ignored) |
|
1649 .preferredSizeHint(QSizeF(10,20)) |
|
1650 .rowSpan(2) |
|
1651 << ItemDesc(1,0) |
|
1652 .preferredSizeHint(QSizeF(10,10)) |
|
1653 << ItemDesc(1,1) |
|
1654 .preferredSizeHint(QSizeF(10,10)) |
|
1655 ) |
|
1656 << QSizeF() |
|
1657 << (SizeList() |
|
1658 << QSizeF(10,10) << QSizeF(10,10) << QSizeF(0,20) |
|
1659 << QSizeF(10,10) << QSizeF(10,10) |
|
1660 ); |
|
1661 |
|
1662 QTest::newRow("ignoreitem02_span00_span02") << (ItemList() |
|
1663 << ItemDesc(0,0) |
|
1664 .preferredSizeHint(QSizeF(10,10)) |
|
1665 .rowSpan(2) |
|
1666 << ItemDesc(0,1) |
|
1667 .preferredSizeHint(QSizeF(10,10)) |
|
1668 << ItemDesc(0,2) |
|
1669 .sizePolicy(QSizePolicy::Ignored) |
|
1670 .preferredSizeHint(QSizeF(10,20)) |
|
1671 .rowSpan(2) |
|
1672 << ItemDesc(1,1) |
|
1673 .preferredSizeHint(QSizeF(10,10)) |
|
1674 ) |
|
1675 << QSizeF() |
|
1676 << (SizeList() |
|
1677 << QSizeF(10,20) << QSizeF(10,10) << QSizeF(0,20) |
|
1678 << QSizeF(10,10) |
|
1679 ); |
|
1680 |
|
1681 QTest::newRow("ignoreitem00_colspan00") << (ItemList() |
|
1682 << ItemDesc(0,0) |
|
1683 .sizePolicy(QSizePolicy::Ignored) |
|
1684 .preferredSizeHint(QSizeF(10,20)) |
|
1685 .colSpan(2) |
|
1686 << ItemDesc(0,2) |
|
1687 .preferredSizeHint(QSizeF(10,10)) |
|
1688 << ItemDesc(1,0) |
|
1689 .preferredSizeHint(QSizeF(10,10)) |
|
1690 << ItemDesc(1,1) |
|
1691 .preferredSizeHint(QSizeF(10,10)) |
|
1692 << ItemDesc(1,2) |
|
1693 .preferredSizeHint(QSizeF(10,10)) |
|
1694 ) |
|
1695 << QSizeF() |
|
1696 << (SizeList() |
|
1697 << QSizeF(20,10) << QSizeF(10,10) << QSizeF(10,10) |
|
1698 << QSizeF(10,10) << QSizeF(10,10) |
|
1699 ); |
|
1700 |
|
1701 QTest::newRow("ignoreitem01_colspan01") << (ItemList() |
|
1702 << ItemDesc(0,0) |
|
1703 .preferredSizeHint(QSizeF(10,10)) |
|
1704 << ItemDesc(0,1) |
|
1705 .sizePolicy(QSizePolicy::Ignored) |
|
1706 .preferredSizeHint(QSizeF(10,20)) |
|
1707 .colSpan(2) |
|
1708 << ItemDesc(1,0) |
|
1709 .preferredSizeHint(QSizeF(10,10)) |
|
1710 << ItemDesc(1,1) |
|
1711 .preferredSizeHint(QSizeF(10,10)) |
|
1712 << ItemDesc(1,2) |
|
1713 .preferredSizeHint(QSizeF(10,10)) |
|
1714 ) |
|
1715 << QSizeF() |
|
1716 << (SizeList() |
|
1717 << QSizeF(10,10) << QSizeF(20,10) << QSizeF(10,10) |
|
1718 << QSizeF(10,10) << QSizeF(10,10) |
|
1719 ); |
|
1720 |
|
1721 QTest::newRow("ignorecolumn1_resize70x60") << (ItemList() |
|
1722 << ItemDesc(0,0) |
|
1723 .preferredSizeHint(QSizeF(10,10)) |
|
1724 << ItemDesc(0,1) |
|
1725 .sizePolicy(QSizePolicy::Ignored) |
|
1726 .preferredSizeHint(QSizeF(20,10)) |
|
1727 << ItemDesc(0,2) |
|
1728 .preferredSizeHint(QSizeF(30,10)) |
|
1729 << ItemDesc(1,0) |
|
1730 .preferredSizeHint(QSizeF(10,20)) |
|
1731 << ItemDesc(1,1) |
|
1732 .sizePolicy(QSizePolicy::Ignored) |
|
1733 .preferredSizeHint(QSizeF(20,20)) |
|
1734 << ItemDesc(1,2) |
|
1735 .preferredSizeHint(QSizeF(30,20)) |
|
1736 ) |
|
1737 << QSizeF(70, 60) |
|
1738 << (SizeList() |
|
1739 << QSizeF(20,20) << QSizeF(10,20) << QSizeF(40,20) |
|
1740 << QSizeF(20,40) << QSizeF(10,40) << QSizeF(40,40) |
|
1741 ); |
|
1742 |
|
1743 QTest::newRow("ignorerow0") << (ItemList() |
|
1744 << ItemDesc(0,0) |
|
1745 .sizePolicy(QSizePolicy::Ignored) |
|
1746 .preferredSizeHint(QSizeF(10,10)) |
|
1747 << ItemDesc(0,1) |
|
1748 .sizePolicy(QSizePolicy::Ignored) |
|
1749 .preferredSizeHint(QSizeF(10,10)) |
|
1750 << ItemDesc(0,2) |
|
1751 .sizePolicy(QSizePolicy::Ignored) |
|
1752 .preferredSizeHint(QSizeF(10,10)) |
|
1753 << ItemDesc(1,0) |
|
1754 .preferredSizeHint(QSizeF(10,10)) |
|
1755 << ItemDesc(1,1) |
|
1756 .preferredSizeHint(QSizeF(10,10)) |
|
1757 << ItemDesc(1,2) |
|
1758 .preferredSizeHint(QSizeF(10,10)) |
|
1759 ) |
|
1760 << QSizeF() |
|
1761 << (SizeList() |
|
1762 << QSizeF(10,0) << QSizeF(10,0) << QSizeF(10,0) |
|
1763 << QSizeF(10,10) << QSizeF(10,10) << QSizeF(10,10) |
|
1764 ); |
|
1765 |
|
1766 QTest::newRow("ignorerow1") << (ItemList() |
|
1767 << ItemDesc(0,0) |
|
1768 .preferredSizeHint(QSizeF(10,10)) |
|
1769 << ItemDesc(0,1) |
|
1770 .preferredSizeHint(QSizeF(10,10)) |
|
1771 << ItemDesc(0,2) |
|
1772 .preferredSizeHint(QSizeF(10,10)) |
|
1773 << ItemDesc(1,0) |
|
1774 .sizePolicy(QSizePolicy::Ignored) |
|
1775 .preferredSizeHint(QSizeF(10,10)) |
|
1776 << ItemDesc(1,1) |
|
1777 .sizePolicy(QSizePolicy::Ignored) |
|
1778 .preferredSizeHint(QSizeF(10,10)) |
|
1779 << ItemDesc(1,2) |
|
1780 .sizePolicy(QSizePolicy::Ignored) |
|
1781 .preferredSizeHint(QSizeF(10,10)) |
|
1782 ) |
|
1783 << QSizeF() |
|
1784 << (SizeList() |
|
1785 << QSizeF(10,10) << QSizeF(10,10) << QSizeF(10,10) |
|
1786 << QSizeF(10,0) << QSizeF(10,0) << QSizeF(10,0) |
|
1787 ); |
|
1788 |
|
1789 QTest::newRow("ignorerow0_resize60x50") << (ItemList() |
|
1790 << ItemDesc(0,0) |
|
1791 .sizePolicy(QSizePolicy::Ignored) |
|
1792 .preferredSizeHint(QSizeF(10,10)) |
|
1793 << ItemDesc(0,1) |
|
1794 .sizePolicy(QSizePolicy::Ignored) |
|
1795 .preferredSizeHint(QSizeF(20,10)) |
|
1796 << ItemDesc(0,2) |
|
1797 .sizePolicy(QSizePolicy::Ignored) |
|
1798 .preferredSizeHint(QSizeF(30,10)) |
|
1799 << ItemDesc(1,0) |
|
1800 .preferredSizeHint(QSizeF(10,30)) |
|
1801 << ItemDesc(1,1) |
|
1802 .preferredSizeHint(QSizeF(20,30)) |
|
1803 << ItemDesc(1,2) |
|
1804 .preferredSizeHint(QSizeF(30,30)) |
|
1805 ) |
|
1806 << QSizeF(60, 50) |
|
1807 << (SizeList() |
|
1808 << QSizeF(10,10) << QSizeF(20,10) << QSizeF(30,10) |
|
1809 << QSizeF(10,40) << QSizeF(20,40) << QSizeF(30,40) |
|
1810 ); |
|
1811 |
|
1812 } |
|
1813 |
|
1814 void tst_QGraphicsGridLayout::defaultStretchFactors() |
|
1815 { |
|
1816 QFETCH(ItemList, itemDescriptions); |
|
1817 QFETCH(QSizeF, newSize); |
|
1818 QFETCH(SizeList, expectedSizes); |
|
1819 |
|
1820 QGraphicsScene scene; |
|
1821 QGraphicsView view(&scene); |
|
1822 QGraphicsWidget *widget = new QGraphicsWidget(0, Qt::Window); |
|
1823 QGraphicsGridLayout *layout = new QGraphicsGridLayout; |
|
1824 scene.addItem(widget); |
|
1825 widget->setLayout(layout); |
|
1826 layout->setContentsMargins(0, 0, 0, 0); |
|
1827 layout->setSpacing(0.0); |
|
1828 widget->setContentsMargins(0, 0, 0, 0); |
|
1829 |
|
1830 int i; |
|
1831 for (i = 0; i < itemDescriptions.count(); ++i) { |
|
1832 ItemDesc desc = itemDescriptions.at(i); |
|
1833 RectWidget *item = new RectWidget(widget); |
|
1834 desc.apply(layout, item); |
|
1835 } |
|
1836 |
|
1837 QApplication::processEvents(); |
|
1838 |
|
1839 widget->show(); |
|
1840 view.show(); |
|
1841 view.resize(400,300); |
|
1842 if (newSize.isValid()) |
|
1843 widget->resize(newSize); |
|
1844 |
|
1845 QApplication::processEvents(); |
|
1846 for (i = 0; i < expectedSizes.count(); ++i) { |
|
1847 QSizeF itemSize = layout->itemAt(i)->geometry().size(); |
|
1848 QCOMPARE(itemSize, expectedSizes.at(i)); |
|
1849 } |
|
1850 |
|
1851 delete widget; |
|
1852 } |
|
1853 |
|
1854 typedef QList<QRectF> RectList; |
|
1855 Q_DECLARE_METATYPE(RectList); |
|
1856 |
|
1857 void tst_QGraphicsGridLayout::alignment2_data() |
|
1858 { |
|
1859 QTest::addColumn<ItemList>("itemDescriptions"); |
|
1860 QTest::addColumn<QSizeF>("newSize"); |
|
1861 QTest::addColumn<RectList>("expectedGeometries"); |
|
1862 |
|
1863 QTest::newRow("hor_sizepolicy_fixed") << (ItemList() |
|
1864 << ItemDesc(0,0) |
|
1865 .preferredSizeHint(QSizeF(10,20)) |
|
1866 .sizePolicyV(QSizePolicy::Fixed) |
|
1867 << ItemDesc(0,1) |
|
1868 .preferredSizeHint(QSizeF(10,10)) |
|
1869 .sizePolicyV(QSizePolicy::Fixed) |
|
1870 ) |
|
1871 << QSizeF() |
|
1872 << (RectList() |
|
1873 << QRectF(0, 0, 10,20) << QRectF(10, 0, 10,10) |
|
1874 ); |
|
1875 |
|
1876 QTest::newRow("hor_sizepolicy_fixed_alignvcenter") << (ItemList() |
|
1877 << ItemDesc(0,0) |
|
1878 .preferredSizeHint(QSizeF(10,20)) |
|
1879 .sizePolicyV(QSizePolicy::Fixed) |
|
1880 << ItemDesc(0,1) |
|
1881 .preferredSizeHint(QSizeF(10,10)) |
|
1882 .sizePolicyV(QSizePolicy::Fixed) |
|
1883 .alignment(Qt::AlignVCenter) |
|
1884 ) |
|
1885 << QSizeF() |
|
1886 << (RectList() |
|
1887 << QRectF(0, 0, 10,20) << QRectF(10, 5, 10,10) |
|
1888 ); |
|
1889 |
|
1890 QTest::newRow("hor_sizepolicy_fixed_aligntop") << (ItemList() |
|
1891 << ItemDesc(0,0) |
|
1892 .preferredSizeHint(QSizeF(10,20)) |
|
1893 .sizePolicyV(QSizePolicy::Fixed) |
|
1894 << ItemDesc(0,1) |
|
1895 .preferredSizeHint(QSizeF(10,10)) |
|
1896 .sizePolicyV(QSizePolicy::Fixed) |
|
1897 .alignment(Qt::AlignTop) |
|
1898 ) |
|
1899 << QSizeF() |
|
1900 << (RectList() |
|
1901 << QRectF(0, 0, 10,20) << QRectF(10, 0, 10,10) |
|
1902 ); |
|
1903 |
|
1904 QTest::newRow("hor_sizepolicy_fixed_alignbottom") << (ItemList() |
|
1905 << ItemDesc(0,0) |
|
1906 .preferredSizeHint(QSizeF(10,20)) |
|
1907 .sizePolicyV(QSizePolicy::Fixed) |
|
1908 << ItemDesc(0,1) |
|
1909 .preferredSizeHint(QSizeF(10,10)) |
|
1910 .sizePolicyV(QSizePolicy::Fixed) |
|
1911 .alignment(Qt::AlignBottom) |
|
1912 ) |
|
1913 << QSizeF() |
|
1914 << (RectList() |
|
1915 << QRectF(0, 0, 10,20) << QRectF(10, 10, 10,10) |
|
1916 ); |
|
1917 |
|
1918 QTest::newRow("ver_sizepolicy_fixed") << (ItemList() |
|
1919 << ItemDesc(0,0) |
|
1920 .preferredSizeHint(QSizeF(20,10)) |
|
1921 .sizePolicyH(QSizePolicy::Fixed) |
|
1922 << ItemDesc(1,0) |
|
1923 .preferredSizeHint(QSizeF(10,10)) |
|
1924 .sizePolicyH(QSizePolicy::Fixed) |
|
1925 ) |
|
1926 << QSizeF() |
|
1927 << (RectList() |
|
1928 << QRectF(0, 0, 20,10) << QRectF(0, 10, 10,10) |
|
1929 ); |
|
1930 |
|
1931 QTest::newRow("ver_sizepolicy_fixed_alignhcenter") << (ItemList() |
|
1932 << ItemDesc(0,0) |
|
1933 .preferredSizeHint(QSizeF(20,10)) |
|
1934 .sizePolicyH(QSizePolicy::Fixed) |
|
1935 << ItemDesc(1,0) |
|
1936 .preferredSizeHint(QSizeF(10,10)) |
|
1937 .sizePolicyH(QSizePolicy::Fixed) |
|
1938 .alignment(Qt::AlignHCenter) |
|
1939 ) |
|
1940 << QSizeF() |
|
1941 << (RectList() |
|
1942 << QRectF(0, 0, 20,10) << QRectF(5, 10, 10,10) |
|
1943 ); |
|
1944 |
|
1945 QTest::newRow("ver_sizepolicy_fixed_alignleft") << (ItemList() |
|
1946 << ItemDesc(0,0) |
|
1947 .preferredSizeHint(QSizeF(20,10)) |
|
1948 .sizePolicyH(QSizePolicy::Fixed) |
|
1949 << ItemDesc(1,0) |
|
1950 .preferredSizeHint(QSizeF(10,10)) |
|
1951 .sizePolicyH(QSizePolicy::Fixed) |
|
1952 .alignment(Qt::AlignLeft) |
|
1953 ) |
|
1954 << QSizeF() |
|
1955 << (RectList() |
|
1956 << QRectF(0, 0, 20,10) << QRectF(0, 10, 10,10) |
|
1957 ); |
|
1958 |
|
1959 QTest::newRow("ver_sizepolicy_fixed_alignright") << (ItemList() |
|
1960 << ItemDesc(0,0) |
|
1961 .preferredSizeHint(QSizeF(20,10)) |
|
1962 .sizePolicyH(QSizePolicy::Fixed) |
|
1963 << ItemDesc(1,0) |
|
1964 .preferredSizeHint(QSizeF(10,10)) |
|
1965 .sizePolicyH(QSizePolicy::Fixed) |
|
1966 .alignment(Qt::AlignRight) |
|
1967 ) |
|
1968 << QSizeF() |
|
1969 << (RectList() |
|
1970 << QRectF(0, 0, 20,10) << QRectF(10, 10, 10,10) |
|
1971 ); |
|
1972 } |
|
1973 |
|
1974 void tst_QGraphicsGridLayout::alignment2() |
|
1975 { |
|
1976 QFETCH(ItemList, itemDescriptions); |
|
1977 QFETCH(QSizeF, newSize); |
|
1978 QFETCH(RectList, expectedGeometries); |
|
1979 |
|
1980 QGraphicsScene scene; |
|
1981 QGraphicsView view(&scene); |
|
1982 QGraphicsWidget *widget = new QGraphicsWidget(0, Qt::Window); |
|
1983 QGraphicsGridLayout *layout = new QGraphicsGridLayout; |
|
1984 scene.addItem(widget); |
|
1985 widget->setLayout(layout); |
|
1986 layout->setContentsMargins(0, 0, 0, 0); |
|
1987 layout->setSpacing(0.0); |
|
1988 widget->setContentsMargins(0, 0, 0, 0); |
|
1989 |
|
1990 int i; |
|
1991 for (i = 0; i < itemDescriptions.count(); ++i) { |
|
1992 ItemDesc desc = itemDescriptions.at(i); |
|
1993 RectWidget *item = new RectWidget(widget); |
|
1994 desc.apply(layout, item); |
|
1995 } |
|
1996 |
|
1997 QApplication::processEvents(); |
|
1998 |
|
1999 widget->show(); |
|
2000 view.resize(400,300); |
|
2001 view.show(); |
|
2002 if (newSize.isValid()) |
|
2003 widget->resize(newSize); |
|
2004 |
|
2005 QApplication::processEvents(); |
|
2006 for (i = 0; i < expectedGeometries.count(); ++i) { |
|
2007 QRectF itemRect = layout->itemAt(i)->geometry(); |
|
2008 QCOMPARE(itemRect, expectedGeometries.at(i)); |
|
2009 } |
|
2010 |
|
2011 delete widget; |
|
2012 } |
|
2013 |
|
2014 void tst_QGraphicsGridLayout::geometries_data() |
|
2015 { |
|
2016 |
|
2017 QTest::addColumn<ItemList>("itemDescriptions"); |
|
2018 QTest::addColumn<QSizeF>("newSize"); |
|
2019 QTest::addColumn<RectList>("expectedGeometries"); |
|
2020 |
|
2021 QTest::newRow("combine_max_sizes") << (ItemList() |
|
2022 << ItemDesc(0,0) |
|
2023 .maxSize(QSizeF(50,10)) |
|
2024 << ItemDesc(1,0) |
|
2025 .maxSize(QSizeF(10,10)) |
|
2026 ) |
|
2027 << QSizeF(50, 20) |
|
2028 << (RectList() |
|
2029 << QRectF(0, 0, 50,10) << QRectF(0, 10, 10,10) |
|
2030 ); |
|
2031 |
|
2032 QTest::newRow("combine_min_sizes") << (ItemList() |
|
2033 << ItemDesc(0,0) |
|
2034 .minSize(QSizeF(50,10)) |
|
2035 << ItemDesc(1,0) |
|
2036 .minSize(QSizeF(10,10)) |
|
2037 ) |
|
2038 << QSizeF(60, 20) |
|
2039 << (RectList() |
|
2040 << QRectF(0, 0, 60,10) << QRectF(0, 10, 60,10) |
|
2041 ); |
|
2042 |
|
2043 } |
|
2044 |
|
2045 void tst_QGraphicsGridLayout::geometries() |
|
2046 { |
|
2047 QFETCH(ItemList, itemDescriptions); |
|
2048 QFETCH(QSizeF, newSize); |
|
2049 QFETCH(RectList, expectedGeometries); |
|
2050 |
|
2051 QGraphicsScene scene; |
|
2052 QGraphicsView view(&scene); |
|
2053 QGraphicsWidget *widget = new QGraphicsWidget(0, Qt::Window); |
|
2054 QGraphicsGridLayout *layout = new QGraphicsGridLayout; |
|
2055 scene.addItem(widget); |
|
2056 widget->setLayout(layout); |
|
2057 layout->setContentsMargins(0, 0, 0, 0); |
|
2058 layout->setSpacing(0.0); |
|
2059 widget->setContentsMargins(0, 0, 0, 0); |
|
2060 |
|
2061 int i; |
|
2062 for (i = 0; i < itemDescriptions.count(); ++i) { |
|
2063 ItemDesc desc = itemDescriptions.at(i); |
|
2064 RectWidget *item = new RectWidget(widget); |
|
2065 desc.apply(layout, item); |
|
2066 } |
|
2067 |
|
2068 QApplication::processEvents(); |
|
2069 |
|
2070 widget->show(); |
|
2071 view.resize(400,300); |
|
2072 view.show(); |
|
2073 if (newSize.isValid()) |
|
2074 widget->resize(newSize); |
|
2075 |
|
2076 QApplication::processEvents(); |
|
2077 for (i = 0; i < expectedGeometries.count(); ++i) { |
|
2078 QRectF itemRect = layout->itemAt(i)->geometry(); |
|
2079 QCOMPARE(itemRect, expectedGeometries.at(i)); |
|
2080 } |
|
2081 |
|
2082 delete widget; |
|
2083 } |
|
2084 |
|
2085 void tst_QGraphicsGridLayout::avoidRecursionInInsertItem() |
|
2086 { |
|
2087 QGraphicsWidget window(0, Qt::Window); |
|
2088 QGraphicsGridLayout *layout = new QGraphicsGridLayout(&window); |
|
2089 QCOMPARE(layout->count(), 0); |
|
2090 QTest::ignoreMessage(QtWarningMsg, "QGraphicsGridLayout::addItem: cannot insert itself"); |
|
2091 layout->addItem(layout, 0, 0); |
|
2092 QCOMPARE(layout->count(), 0); |
|
2093 } |
|
2094 |
|
2095 void tst_QGraphicsGridLayout::task236367_maxSizeHint() |
|
2096 { |
|
2097 QGraphicsWidget *widget = new QGraphicsWidget; |
|
2098 QGraphicsGridLayout *layout = new QGraphicsGridLayout; |
|
2099 widget->setLayout(layout); |
|
2100 layout->setContentsMargins(0, 0, 0, 0); |
|
2101 int w = 203; |
|
2102 int h = 204; |
|
2103 widget->resize(w, h); |
|
2104 QCOMPARE(widget->size(), QSizeF(w, h)); |
|
2105 } |
|
2106 |
|
2107 QTEST_MAIN(tst_QGraphicsGridLayout) |
|
2108 #include "tst_qgraphicsgridlayout.moc" |
|
2109 |