0
|
1 |
/****************************************************************************
|
|
2 |
**
|
|
3 |
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
4 |
** All rights reserved.
|
|
5 |
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
6 |
**
|
|
7 |
** This file is part of the test suite of the Qt Toolkit.
|
|
8 |
**
|
|
9 |
** $QT_BEGIN_LICENSE:LGPL$
|
|
10 |
** No Commercial Usage
|
|
11 |
** This file contains pre-release code and may not be distributed.
|
|
12 |
** You may use this file in accordance with the terms and conditions
|
|
13 |
** contained in the Technology Preview License Agreement accompanying
|
|
14 |
** this package.
|
|
15 |
**
|
|
16 |
** GNU Lesser General Public License Usage
|
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
18 |
** General Public License version 2.1 as published by the Free Software
|
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
20 |
** packaging of this file. Please review the following information to
|
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
23 |
**
|
|
24 |
** In addition, as a special exception, Nokia gives you certain additional
|
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception
|
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
27 |
**
|
|
28 |
** If you have questions regarding the use of this file, please contact
|
|
29 |
** Nokia at qt-info@nokia.com.
|
|
30 |
**
|
|
31 |
**
|
|
32 |
**
|
|
33 |
**
|
|
34 |
**
|
|
35 |
**
|
|
36 |
**
|
|
37 |
**
|
|
38 |
** $QT_END_LICENSE$
|
|
39 |
**
|
|
40 |
****************************************************************************/
|
|
41 |
|
|
42 |
#include <QtTest/QtTest>
|
|
43 |
#include <QtGui/qgraphicsanchorlayout.h>
|
|
44 |
#include <private/qgraphicsanchorlayout_p.h>
|
|
45 |
#include <QtGui/qgraphicswidget.h>
|
|
46 |
#include <QtGui/qgraphicsproxywidget.h>
|
|
47 |
#include <QtGui/qgraphicsview.h>
|
|
48 |
|
|
49 |
class tst_QGraphicsAnchorLayout : public QObject {
|
|
50 |
Q_OBJECT;
|
|
51 |
|
|
52 |
public:
|
|
53 |
tst_QGraphicsAnchorLayout() : QObject() {
|
|
54 |
hasSimplification = qgetenv("QT_ANCHORLAYOUT_NO_SIMPLIFICATION").isEmpty();
|
|
55 |
}
|
|
56 |
|
|
57 |
private:
|
|
58 |
bool hasSimplification;
|
|
59 |
|
|
60 |
private slots:
|
|
61 |
void simple();
|
|
62 |
void simple_center();
|
|
63 |
void simple_semifloat();
|
|
64 |
void layoutDirection();
|
|
65 |
void diagonal();
|
|
66 |
void parallel();
|
|
67 |
void parallel2();
|
|
68 |
void snake();
|
|
69 |
void snakeOppositeDirections();
|
|
70 |
void fairDistribution();
|
|
71 |
void fairDistributionOppositeDirections();
|
|
72 |
void proportionalPreferred();
|
|
73 |
void example();
|
|
74 |
void setSpacing();
|
|
75 |
void hardComplexS60();
|
|
76 |
void stability();
|
|
77 |
void delete_anchor();
|
|
78 |
void conflicts();
|
|
79 |
void sizePolicy();
|
|
80 |
void expandingSequence();
|
|
81 |
void expandingSequenceFairDistribution();
|
|
82 |
void expandingParallel();
|
|
83 |
void floatConflict();
|
|
84 |
void infiniteMaxSizes();
|
|
85 |
};
|
|
86 |
|
|
87 |
class RectWidget : public QGraphicsWidget
|
|
88 |
{
|
|
89 |
public:
|
|
90 |
RectWidget(QGraphicsItem *parent = 0) : QGraphicsWidget(parent){}
|
|
91 |
|
|
92 |
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
|
93 |
{
|
|
94 |
Q_UNUSED(option);
|
|
95 |
Q_UNUSED(widget);
|
|
96 |
painter->drawRoundRect(rect());
|
|
97 |
painter->drawLine(rect().topLeft(), rect().bottomRight());
|
|
98 |
painter->drawLine(rect().bottomLeft(), rect().topRight());
|
|
99 |
}
|
|
100 |
};
|
|
101 |
|
|
102 |
static QGraphicsWidget *createItem(const QSizeF &minimum = QSizeF(100.0, 100.0),
|
|
103 |
const QSizeF &preferred = QSize(150.0, 100.0),
|
|
104 |
const QSizeF &maximum = QSizeF(200.0, 100.0),
|
|
105 |
const QString &name = QString())
|
|
106 |
{
|
|
107 |
QGraphicsWidget *w = new RectWidget;
|
|
108 |
w->setMinimumSize(minimum);
|
|
109 |
w->setPreferredSize(preferred);
|
|
110 |
w->setMaximumSize(maximum);
|
|
111 |
w->setData(0, name);
|
|
112 |
return w;
|
|
113 |
}
|
|
114 |
|
|
115 |
static void setAnchor(QGraphicsAnchorLayout *l,
|
|
116 |
QGraphicsLayoutItem *firstItem,
|
|
117 |
Qt::AnchorPoint firstEdge,
|
|
118 |
QGraphicsLayoutItem *secondItem,
|
|
119 |
Qt::AnchorPoint secondEdge,
|
|
120 |
qreal spacing = 0)
|
|
121 |
{
|
|
122 |
QGraphicsAnchor *anchor = l->addAnchor(firstItem, firstEdge, secondItem, secondEdge);
|
|
123 |
anchor->setSpacing(spacing);
|
|
124 |
}
|
|
125 |
|
|
126 |
static bool checkReverseDirection(QGraphicsWidget *w)
|
|
127 |
{
|
|
128 |
QGraphicsLayout *l = w->layout();
|
|
129 |
Q_ASSERT(l);
|
|
130 |
qreal left, top, right, bottom;
|
|
131 |
l->getContentsMargins(&left, &top, &right, &bottom);
|
|
132 |
w->setLayoutDirection(Qt::LeftToRight);
|
|
133 |
QApplication::processEvents();
|
|
134 |
const QRectF lg = l->geometry();
|
|
135 |
QMap<QGraphicsLayoutItem *, QRectF> geometries;
|
|
136 |
for (int i = 0; i < l->count(); ++i) {
|
|
137 |
QGraphicsLayoutItem *w = l->itemAt(i);
|
|
138 |
geometries.insert(w, w->geometry());
|
|
139 |
}
|
|
140 |
w->setLayoutDirection(Qt::RightToLeft);
|
|
141 |
QApplication::processEvents();
|
|
142 |
lg.adjusted(+right, +top, -left, -bottom);
|
|
143 |
for (int i = 0; i < l->count(); ++i) {
|
|
144 |
QGraphicsLayoutItem *w = l->itemAt(i);
|
|
145 |
const QRectF rtlGeom = w->geometry();
|
|
146 |
const QRectF ltrGeom = geometries.value(w);
|
|
147 |
QRectF expectedGeom = ltrGeom;
|
|
148 |
expectedGeom.moveRight(lg.right() - (0 + ltrGeom.left()));
|
|
149 |
if (expectedGeom != rtlGeom) {
|
|
150 |
qDebug() << "layout->geometry():" << lg
|
|
151 |
<< "expected:" << expectedGeom
|
|
152 |
<< "actual:" << rtlGeom;
|
|
153 |
return false;
|
|
154 |
}
|
|
155 |
}
|
|
156 |
return true;
|
|
157 |
}
|
|
158 |
|
|
159 |
static bool layoutHasConflict(QGraphicsAnchorLayout *l)
|
|
160 |
{
|
|
161 |
return QGraphicsAnchorLayoutPrivate::get(l)->hasConflicts();
|
|
162 |
}
|
|
163 |
|
|
164 |
static bool usedSimplex(QGraphicsAnchorLayout *l, Qt::Orientation o)
|
|
165 |
{
|
|
166 |
QGraphicsAnchorLayoutPrivate::Orientation oo = (o == Qt::Horizontal) ?
|
|
167 |
QGraphicsAnchorLayoutPrivate::Horizontal :
|
|
168 |
QGraphicsAnchorLayoutPrivate::Vertical;
|
|
169 |
|
|
170 |
return QGraphicsAnchorLayoutPrivate::get(l)->lastCalculationUsedSimplex[oo];
|
|
171 |
}
|
|
172 |
|
|
173 |
void tst_QGraphicsAnchorLayout::simple()
|
|
174 |
{
|
|
175 |
QGraphicsWidget *w1 = createItem();
|
|
176 |
QGraphicsWidget *w2 = createItem();
|
|
177 |
|
|
178 |
QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout;
|
|
179 |
l->setContentsMargins(0, 0, 0, 0);
|
|
180 |
|
|
181 |
// Horizontal
|
|
182 |
l->addAnchor(l, Qt::AnchorLeft, w1, Qt::AnchorLeft);
|
|
183 |
l->addAnchor(w1, Qt::AnchorRight, w2, Qt::AnchorLeft);
|
|
184 |
l->addAnchor(w2, Qt::AnchorRight, l, Qt::AnchorRight);
|
|
185 |
|
|
186 |
// Vertical
|
|
187 |
l->addAnchors(l, w1, Qt::Vertical);
|
|
188 |
l->addAnchors(l, w2, Qt::Vertical);
|
|
189 |
|
|
190 |
QCOMPARE(l->count(), 2);
|
|
191 |
|
|
192 |
QGraphicsWidget p;
|
|
193 |
p.setLayout(l);
|
|
194 |
p.adjustSize();
|
|
195 |
|
|
196 |
if (hasSimplification) {
|
|
197 |
QVERIFY(!usedSimplex(l, Qt::Horizontal));
|
|
198 |
QVERIFY(!usedSimplex(l, Qt::Vertical));
|
|
199 |
}
|
|
200 |
}
|
|
201 |
|
|
202 |
void tst_QGraphicsAnchorLayout::simple_center()
|
|
203 |
{
|
|
204 |
QSizeF min(10, 10);
|
|
205 |
QSizeF pref(50, 10);
|
|
206 |
QSizeF max(100, 10);
|
|
207 |
|
|
208 |
QGraphicsWidget *a = createItem(min, pref, max, "a");
|
|
209 |
QGraphicsWidget *b = createItem(min, pref, max, "b");
|
|
210 |
QGraphicsWidget *c = createItem(min, pref, max, "c");
|
|
211 |
|
|
212 |
QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout;
|
|
213 |
l->setContentsMargins(0, 0, 0, 0);
|
|
214 |
// horizontal
|
|
215 |
setAnchor(l, l, Qt::AnchorLeft, a, Qt::AnchorLeft, 0);
|
|
216 |
setAnchor(l, a, Qt::AnchorRight, b, Qt::AnchorLeft, 0);
|
|
217 |
setAnchor(l, b, Qt::AnchorRight, l, Qt::AnchorRight, 0);
|
|
218 |
setAnchor(l, a, Qt::AnchorHorizontalCenter, c, Qt::AnchorLeft, 0);
|
|
219 |
setAnchor(l, c, Qt::AnchorRight, b, Qt::AnchorHorizontalCenter, 0);
|
|
220 |
|
|
221 |
// vertical
|
|
222 |
setAnchor(l, l, Qt::AnchorTop, a, Qt::AnchorTop, 0);
|
|
223 |
setAnchor(l, l, Qt::AnchorTop, b, Qt::AnchorTop, 0);
|
|
224 |
setAnchor(l, a, Qt::AnchorBottom, c, Qt::AnchorTop, 0);
|
|
225 |
setAnchor(l, b, Qt::AnchorBottom, c, Qt::AnchorTop, 0);
|
|
226 |
setAnchor(l, c, Qt::AnchorBottom, l, Qt::AnchorBottom, 0);
|
|
227 |
|
|
228 |
QCOMPARE(l->count(), 3);
|
|
229 |
|
|
230 |
QGraphicsWidget *p = new QGraphicsWidget(0, Qt::Window);
|
|
231 |
p->setLayout(l);
|
|
232 |
|
|
233 |
QSizeF layoutMinimumSize = l->effectiveSizeHint(Qt::MinimumSize);
|
|
234 |
QCOMPARE(layoutMinimumSize, QSizeF(20, 20));
|
|
235 |
|
|
236 |
QSizeF layoutMaximumSize = l->effectiveSizeHint(Qt::MaximumSize);
|
|
237 |
QCOMPARE(layoutMaximumSize, QSizeF(200, 20));
|
|
238 |
|
|
239 |
if (hasSimplification) {
|
|
240 |
QVERIFY(usedSimplex(l, Qt::Horizontal));
|
|
241 |
QVERIFY(!usedSimplex(l, Qt::Vertical));
|
|
242 |
}
|
|
243 |
|
|
244 |
delete p;
|
|
245 |
}
|
|
246 |
|
|
247 |
void tst_QGraphicsAnchorLayout::simple_semifloat()
|
|
248 |
{
|
|
249 |
// Useful for testing simplification between A_left and B_left.
|
|
250 |
// Unfortunately the only way to really test that now is to manually inspect the
|
|
251 |
// simplified graph.
|
|
252 |
QSizeF min(10, 10);
|
|
253 |
QSizeF pref(50, 10);
|
|
254 |
QSizeF max(100, 10);
|
|
255 |
|
|
256 |
QGraphicsWidget *A = createItem(min, pref, max, "A");
|
|
257 |
QGraphicsWidget *B = createItem(min, pref, max, "B");
|
|
258 |
QGraphicsWidget *a = createItem(min, pref, max, "a");
|
|
259 |
QGraphicsWidget *b = createItem(min, pref, max, "b");
|
|
260 |
|
|
261 |
QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout;
|
|
262 |
l->setContentsMargins(0, 0, 0, 0);
|
|
263 |
|
|
264 |
// horizontal
|
|
265 |
setAnchor(l, l, Qt::AnchorLeft, A, Qt::AnchorLeft, 0);
|
|
266 |
setAnchor(l, A, Qt::AnchorRight, B, Qt::AnchorLeft, 0);
|
|
267 |
setAnchor(l, B, Qt::AnchorRight, l, Qt::AnchorRight, 0);
|
|
268 |
|
|
269 |
setAnchor(l, A, Qt::AnchorLeft, a, Qt::AnchorLeft, 0);
|
|
270 |
setAnchor(l, B, Qt::AnchorLeft, b, Qt::AnchorLeft, 0);
|
|
271 |
|
|
272 |
// vertical
|
|
273 |
setAnchor(l, l, Qt::AnchorTop, A, Qt::AnchorTop, 0);
|
|
274 |
setAnchor(l, l, Qt::AnchorTop, B, Qt::AnchorTop, 0);
|
|
275 |
setAnchor(l, A, Qt::AnchorBottom, a, Qt::AnchorTop, 0);
|
|
276 |
setAnchor(l, B, Qt::AnchorBottom, b, Qt::AnchorTop, 0);
|
|
277 |
setAnchor(l, a, Qt::AnchorBottom, l, Qt::AnchorBottom, 0);
|
|
278 |
setAnchor(l, b, Qt::AnchorBottom, l, Qt::AnchorBottom, 0);
|
|
279 |
|
|
280 |
QCOMPARE(l->count(), 4);
|
|
281 |
|
|
282 |
QGraphicsWidget *p = new QGraphicsWidget(0, Qt::Window);
|
|
283 |
p->setLayout(l);
|
|
284 |
|
|
285 |
QSizeF layoutMinimumSize = l->effectiveSizeHint(Qt::MinimumSize);
|
|
286 |
QCOMPARE(layoutMinimumSize, QSizeF(20, 20));
|
|
287 |
|
|
288 |
QCOMPARE(l->effectiveSizeHint(Qt::PreferredSize), QSizeF(100, 20));
|
|
289 |
|
|
290 |
QSizeF layoutMaximumSize = l->effectiveSizeHint(Qt::MaximumSize);
|
|
291 |
QCOMPARE(layoutMaximumSize, QSizeF(200, 20));
|
|
292 |
|
|
293 |
delete p;
|
|
294 |
}
|
|
295 |
|
|
296 |
void tst_QGraphicsAnchorLayout::layoutDirection()
|
|
297 |
{
|
|
298 |
QSizeF min(10, 10);
|
|
299 |
QSizeF pref(50, 10);
|
|
300 |
QSizeF max(100, 10);
|
|
301 |
|
|
302 |
QGraphicsWidget *a = createItem(min, pref, max, "a");
|
|
303 |
QGraphicsWidget *b = createItem(min, pref, max, "b");
|
|
304 |
QGraphicsWidget *c = createItem(min, pref, QSizeF(100, 20), "c");
|
|
305 |
|
|
306 |
a->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
|
307 |
b->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
|
308 |
c->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
|
309 |
|
|
310 |
|
|
311 |
QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout;
|
|
312 |
l->setContentsMargins(0, 5, 10, 15);
|
|
313 |
// horizontal
|
|
314 |
setAnchor(l, l, Qt::AnchorLeft, a, Qt::AnchorLeft, 0);
|
|
315 |
setAnchor(l, a, Qt::AnchorRight, b, Qt::AnchorLeft, 0);
|
|
316 |
setAnchor(l, b, Qt::AnchorRight, l, Qt::AnchorRight, 0);
|
|
317 |
setAnchor(l, a, Qt::AnchorHorizontalCenter, c, Qt::AnchorLeft, 0);
|
|
318 |
setAnchor(l, c, Qt::AnchorRight, b, Qt::AnchorHorizontalCenter, 0);
|
|
319 |
|
|
320 |
// vertical
|
|
321 |
setAnchor(l, l, Qt::AnchorTop, a, Qt::AnchorTop, 0);
|
|
322 |
setAnchor(l, l, Qt::AnchorTop, b, Qt::AnchorTop, 0);
|
|
323 |
setAnchor(l, a, Qt::AnchorBottom, c, Qt::AnchorTop, 0);
|
|
324 |
setAnchor(l, b, Qt::AnchorBottom, c, Qt::AnchorTop, 0);
|
|
325 |
setAnchor(l, c, Qt::AnchorBottom, l, Qt::AnchorBottom, 0);
|
|
326 |
|
|
327 |
QCOMPARE(l->count(), 3);
|
|
328 |
|
|
329 |
QGraphicsWidget *p = new QGraphicsWidget(0, Qt::Window);
|
|
330 |
p->setLayoutDirection(Qt::LeftToRight);
|
|
331 |
p->setLayout(l);
|
|
332 |
|
|
333 |
QGraphicsScene scene;
|
|
334 |
QGraphicsView *view = new QGraphicsView(&scene);
|
|
335 |
scene.addItem(p);
|
|
336 |
p->show();
|
|
337 |
view->show();
|
|
338 |
|
|
339 |
QCOMPARE(checkReverseDirection(p), true);
|
|
340 |
|
|
341 |
QVERIFY(usedSimplex(l, Qt::Horizontal));
|
|
342 |
QVERIFY(!usedSimplex(l, Qt::Vertical));
|
|
343 |
|
|
344 |
delete p;
|
|
345 |
delete view;
|
|
346 |
}
|
|
347 |
|
|
348 |
void tst_QGraphicsAnchorLayout::diagonal()
|
|
349 |
{
|
|
350 |
QSizeF min(10, 100);
|
|
351 |
QSizeF pref(70, 100);
|
|
352 |
QSizeF max(100, 100);
|
|
353 |
|
|
354 |
QGraphicsWidget *a = createItem(min, pref, max, "A");
|
|
355 |
QGraphicsWidget *b = createItem(min, pref, max, "B");
|
|
356 |
QGraphicsWidget *c = createItem(min, pref, max, "C");
|
|
357 |
QGraphicsWidget *d = createItem(min, pref, max, "D");
|
|
358 |
QGraphicsWidget *e = createItem(min, pref, max, "E");
|
|
359 |
|
|
360 |
QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout;
|
|
361 |
l->setContentsMargins(0, 0, 0, 0);
|
|
362 |
l->setSpacing(0);
|
|
363 |
|
|
364 |
// vertical
|
|
365 |
l->addAnchor(a, Qt::AnchorTop, l, Qt::AnchorTop);
|
|
366 |
l->addAnchor(b, Qt::AnchorTop, l, Qt::AnchorTop);
|
|
367 |
l->addAnchor(c, Qt::AnchorTop, a, Qt::AnchorBottom);
|
|
368 |
l->addAnchor(c, Qt::AnchorTop, b, Qt::AnchorBottom);
|
|
369 |
l->addAnchor(c, Qt::AnchorBottom, d, Qt::AnchorTop);
|
|
370 |
l->addAnchor(c, Qt::AnchorBottom, e, Qt::AnchorTop);
|
|
371 |
l->addAnchor(d, Qt::AnchorBottom, l, Qt::AnchorBottom);
|
|
372 |
l->addAnchor(e, Qt::AnchorBottom, l, Qt::AnchorBottom);
|
|
373 |
|
|
374 |
// horizontal
|
|
375 |
l->addAnchor(l, Qt::AnchorLeft, a, Qt::AnchorLeft);
|
|
376 |
l->addAnchor(l, Qt::AnchorLeft, d, Qt::AnchorLeft);
|
|
377 |
l->addAnchor(a, Qt::AnchorRight, b, Qt::AnchorLeft);
|
|
378 |
|
|
379 |
l->addAnchor(a, Qt::AnchorRight, c, Qt::AnchorLeft);
|
|
380 |
l->addAnchor(c, Qt::AnchorRight, e, Qt::AnchorLeft);
|
|
381 |
|
|
382 |
l->addAnchor(b, Qt::AnchorRight, l, Qt::AnchorRight);
|
|
383 |
l->addAnchor(e, Qt::AnchorRight, l, Qt::AnchorRight);
|
|
384 |
l->addAnchor(d, Qt::AnchorRight, e, Qt::AnchorLeft);
|
|
385 |
|
|
386 |
QCOMPARE(l->count(), 5);
|
|
387 |
|
|
388 |
QGraphicsWidget p;
|
|
389 |
p.setLayout(l);
|
|
390 |
|
|
391 |
QSizeF layoutMinimumSize = l->effectiveSizeHint(Qt::MinimumSize);
|
|
392 |
QSizeF layoutMaximumSize = l->effectiveSizeHint(Qt::MaximumSize);
|
|
393 |
QSizeF layoutPreferredSize = l->effectiveSizeHint(Qt::PreferredSize);
|
|
394 |
|
|
395 |
QCOMPARE(layoutMinimumSize, QSizeF(30.0, 300.0));
|
|
396 |
QCOMPARE(layoutPreferredSize, QSizeF(170.0, 300.0));
|
|
397 |
QCOMPARE(layoutMaximumSize, QSizeF(190.0, 300.0));
|
|
398 |
|
|
399 |
p.resize(layoutMinimumSize);
|
|
400 |
QCOMPARE(a->geometry(), QRectF(0.0, 0.0, 10.0, 100.0));
|
|
401 |
QCOMPARE(b->geometry(), QRectF(10.0, 0.0, 20.0, 100.0));
|
|
402 |
QCOMPARE(c->geometry(), QRectF(10.0, 100.0, 10.0, 100.0));
|
|
403 |
QCOMPARE(d->geometry(), QRectF(0.0, 200.0, 20.0, 100.0));
|
|
404 |
QCOMPARE(e->geometry(), QRectF(20.0, 200.0, 10.0, 100.0));
|
|
405 |
QCOMPARE(p.size(), layoutMinimumSize);
|
|
406 |
|
|
407 |
p.resize(layoutPreferredSize);
|
|
408 |
QCOMPARE(a->geometry(), QRectF(0.0, 0.0, 70.0, 100.0));
|
|
409 |
QCOMPARE(b->geometry(), QRectF(70.0, 0.0, 100.0, 100.0));
|
|
410 |
QCOMPARE(c->geometry(), QRectF(70.0, 100.0, 30.0, 100.0));
|
|
411 |
QCOMPARE(d->geometry(), QRectF(0.0, 200.0, 100.0, 100.0));
|
|
412 |
QCOMPARE(e->geometry(), QRectF(100.0, 200.0, 70.0, 100.0));
|
|
413 |
QCOMPARE(p.size(), layoutPreferredSize);
|
|
414 |
|
|
415 |
p.resize(layoutMaximumSize);
|
|
416 |
QCOMPARE(a->geometry(), QRectF(0.0, 0.0, 90.0, 100.0));
|
|
417 |
QCOMPARE(b->geometry(), QRectF(90.0, 0.0, 100.0, 100.0));
|
|
418 |
QCOMPARE(c->geometry(), QRectF(90.0, 100.0, 10.0, 100.0));
|
|
419 |
QCOMPARE(d->geometry(), QRectF(0.0, 200.0, 100.0, 100.0));
|
|
420 |
QCOMPARE(e->geometry(), QRectF(100.0, 200.0, 90.0, 100.0));
|
|
421 |
QCOMPARE(p.size(), layoutMaximumSize);
|
|
422 |
|
|
423 |
QSizeF testA(175.0, 300.0);
|
|
424 |
p.resize(testA);
|
|
425 |
QCOMPARE(a->geometry(), QRectF(0.0, 0.0, 75.0, 100.0));
|
|
426 |
QCOMPARE(b->geometry(), QRectF(75.0, 0.0, 100.0, 100.0));
|
|
427 |
QCOMPARE(c->geometry(), QRectF(75.0, 100.0, 25.0, 100.0));
|
|
428 |
QCOMPARE(d->geometry(), QRectF(0.0, 200.0, 100.0, 100.0));
|
|
429 |
QCOMPARE(e->geometry(), QRectF(100.0, 200.0, 75.0, 100.0));
|
|
430 |
QCOMPARE(p.size(), testA);
|
|
431 |
|
|
432 |
if (hasSimplification) {
|
|
433 |
QVERIFY(usedSimplex(l, Qt::Horizontal));
|
|
434 |
QVERIFY(!usedSimplex(l, Qt::Vertical));
|
|
435 |
}
|
|
436 |
|
|
437 |
QCOMPARE(checkReverseDirection(&p), true);
|
|
438 |
|
|
439 |
c->setMinimumWidth(300);
|
|
440 |
QVERIFY(layoutHasConflict(l));
|
|
441 |
}
|
|
442 |
|
|
443 |
void tst_QGraphicsAnchorLayout::parallel()
|
|
444 |
{
|
|
445 |
QGraphicsWidget *a = createItem(QSizeF(100, 100),
|
|
446 |
QSizeF(150, 100),
|
|
447 |
QSizeF(200, 100), "A");
|
|
448 |
|
|
449 |
QGraphicsWidget *b = createItem(QSizeF(100, 100),
|
|
450 |
QSizeF(150, 100),
|
|
451 |
QSizeF(300, 100), "B");
|
|
452 |
|
|
453 |
QGraphicsWidget *c = createItem(QSizeF(100, 100),
|
|
454 |
QSizeF(200, 100),
|
|
455 |
QSizeF(350, 100), "C");
|
|
456 |
|
|
457 |
QGraphicsWidget *d = createItem(QSizeF(100, 100),
|
|
458 |
QSizeF(170, 100),
|
|
459 |
QSizeF(200, 100), "D");
|
|
460 |
|
|
461 |
QGraphicsWidget *e = createItem(QSizeF(150, 100),
|
|
462 |
QSizeF(150, 100),
|
|
463 |
QSizeF(200, 100), "E");
|
|
464 |
|
|
465 |
QGraphicsWidget *f = createItem(QSizeF(100, 100),
|
|
466 |
QSizeF(150, 100),
|
|
467 |
QSizeF(200, 100), "F");
|
|
468 |
|
|
469 |
QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout;
|
|
470 |
l->setContentsMargins(0, 0, 0, 0);
|
|
471 |
l->setSpacing(0);
|
|
472 |
|
|
473 |
l->addAnchor(l, Qt::AnchorTop, a, Qt::AnchorTop);
|
|
474 |
l->addAnchor(a, Qt::AnchorBottom, b, Qt::AnchorTop);
|
|
475 |
l->addAnchor(b, Qt::AnchorBottom, c, Qt::AnchorTop);
|
|
476 |
l->addAnchor(c, Qt::AnchorBottom, d, Qt::AnchorTop);
|
|
477 |
l->addAnchor(d, Qt::AnchorBottom, e, Qt::AnchorTop);
|
|
478 |
l->addAnchor(e, Qt::AnchorBottom, f, Qt::AnchorTop);
|
|
479 |
l->addAnchor(f, Qt::AnchorBottom, l, Qt::AnchorBottom);
|
|
480 |
|
|
481 |
l->addAnchor(l, Qt::AnchorLeft, a, Qt::AnchorLeft);
|
|
482 |
l->addAnchor(a, Qt::AnchorRight, b, Qt::AnchorLeft);
|
|
483 |
l->addAnchor(a, Qt::AnchorRight, c, Qt::AnchorLeft);
|
|
484 |
l->addAnchor(b, Qt::AnchorRight, d, Qt::AnchorLeft);
|
|
485 |
l->addAnchor(b, Qt::AnchorRight, e, Qt::AnchorLeft);
|
|
486 |
l->addAnchor(c, Qt::AnchorRight, f, Qt::AnchorLeft);
|
|
487 |
l->addAnchor(d, Qt::AnchorRight, f, Qt::AnchorLeft);
|
|
488 |
l->addAnchor(e, Qt::AnchorRight, f, Qt::AnchorLeft);
|
|
489 |
l->addAnchor(f, Qt::AnchorRight, l, Qt::AnchorRight);
|
|
490 |
|
|
491 |
QCOMPARE(l->count(), 6);
|
|
492 |
|
|
493 |
QGraphicsWidget p;
|
|
494 |
p.setLayout(l);
|
|
495 |
|
|
496 |
QSizeF layoutMinimumSize = l->effectiveSizeHint(Qt::MinimumSize);
|
|
497 |
QSizeF layoutPreferredSize = l->effectiveSizeHint(Qt::PreferredSize);
|
|
498 |
QSizeF layoutMaximumSize = l->effectiveSizeHint(Qt::MaximumSize);
|
|
499 |
|
|
500 |
QCOMPARE(layoutMinimumSize, QSizeF(450, 600));
|
|
501 |
QCOMPARE(layoutPreferredSize, QSizeF(620, 600));
|
|
502 |
QCOMPARE(layoutMaximumSize, QSizeF(750, 600));
|
|
503 |
|
|
504 |
p.resize(layoutMinimumSize);
|
|
505 |
QCOMPARE(a->geometry(), QRectF(0, 0, 100, 100));
|
|
506 |
QCOMPARE(b->geometry(), QRectF(100, 100, 100, 100));
|
|
507 |
QCOMPARE(c->geometry(), QRectF(100, 200, 250, 100));
|
|
508 |
QCOMPARE(d->geometry(), QRectF(200, 300, 150, 100));
|
|
509 |
QCOMPARE(e->geometry(), QRectF(200, 400, 150, 100));
|
|
510 |
QCOMPARE(f->geometry(), QRectF(350, 500, 100, 100));
|
|
511 |
QCOMPARE(p.size(), layoutMinimumSize);
|
|
512 |
|
|
513 |
if (!hasSimplification)
|
|
514 |
return;
|
|
515 |
|
|
516 |
p.resize(layoutPreferredSize);
|
|
517 |
QCOMPARE(a->geometry(), QRectF(0, 0, 150, 100));
|
|
518 |
QCOMPARE(b->geometry(), QRectF(150, 100, 150, 100));
|
|
519 |
QCOMPARE(c->geometry(), QRectF(150, 200, 320, 100));
|
|
520 |
QCOMPARE(d->geometry(), QRectF(300, 300, 170, 100));
|
|
521 |
QCOMPARE(e->geometry(), QRectF(300, 400, 170, 100));
|
|
522 |
QCOMPARE(f->geometry(), QRectF(470, 500, 150, 100));
|
|
523 |
QCOMPARE(p.size(), layoutPreferredSize);
|
|
524 |
|
|
525 |
// Maximum size depends on simplification / fair distribution
|
|
526 |
// Without that, test may or may not pass, depending on the
|
|
527 |
// solution found by the solver at runtime.
|
|
528 |
p.resize(layoutMaximumSize);
|
|
529 |
QCOMPARE(a->geometry(), QRectF(0, 0, 200, 100));
|
|
530 |
QCOMPARE(b->geometry(), QRectF(200, 100, 175, 100));
|
|
531 |
QCOMPARE(c->geometry(), QRectF(200, 200, 350, 100));
|
|
532 |
QCOMPARE(d->geometry(), QRectF(375, 300, 175, 100));
|
|
533 |
QCOMPARE(e->geometry(), QRectF(375, 400, 175, 100));
|
|
534 |
QCOMPARE(f->geometry(), QRectF(550, 500, 200, 100));
|
|
535 |
QCOMPARE(p.size(), layoutMaximumSize);
|
|
536 |
|
|
537 |
QVERIFY(!usedSimplex(l, Qt::Horizontal));
|
|
538 |
QVERIFY(!usedSimplex(l, Qt::Vertical));
|
|
539 |
}
|
|
540 |
|
|
541 |
void tst_QGraphicsAnchorLayout::parallel2()
|
|
542 |
{
|
|
543 |
QGraphicsWidget *a = createItem(QSizeF(70.0, 100.0),
|
|
544 |
QSizeF(100.0, 100.0),
|
|
545 |
QSizeF(200.0, 100.0), "A");
|
|
546 |
|
|
547 |
QGraphicsWidget *b = createItem(QSizeF(100.0, 100.0),
|
|
548 |
QSizeF(150.0, 100.0),
|
|
549 |
QSizeF(190.0, 100.0), "B");
|
|
550 |
|
|
551 |
QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout;
|
|
552 |
l->setContentsMargins(0, 0, 0, 0);
|
|
553 |
l->setSpacing(0);
|
|
554 |
|
|
555 |
l->addAnchor(l, Qt::AnchorTop, a, Qt::AnchorTop);
|
|
556 |
l->addAnchor(a, Qt::AnchorBottom, b, Qt::AnchorTop);
|
|
557 |
l->addAnchor(b, Qt::AnchorBottom, l, Qt::AnchorBottom);
|
|
558 |
|
|
559 |
l->addAnchors(l, a, Qt::Horizontal);
|
|
560 |
l->addAnchor(l, Qt::AnchorLeft, b, Qt::AnchorLeft);
|
|
561 |
l->addAnchor(b, Qt::AnchorRight, a, Qt::AnchorRight);
|
|
562 |
|
|
563 |
QCOMPARE(l->count(), 2);
|
|
564 |
|
|
565 |
QGraphicsWidget p;
|
|
566 |
p.setLayout(l);
|
|
567 |
|
|
568 |
QSizeF layoutMinimumSize = l->effectiveSizeHint(Qt::MinimumSize);
|
|
569 |
QSizeF layoutPreferredSize = l->effectiveSizeHint(Qt::PreferredSize);
|
|
570 |
QSizeF layoutMaximumSize = l->effectiveSizeHint(Qt::MaximumSize);
|
|
571 |
|
|
572 |
QCOMPARE(layoutMinimumSize, QSizeF(100.0, 200.0));
|
|
573 |
QCOMPARE(layoutPreferredSize, QSizeF(150.0, 200.0));
|
|
574 |
QCOMPARE(layoutMaximumSize, QSizeF(190.0, 200.0));
|
|
575 |
|
|
576 |
p.resize(layoutMinimumSize);
|
|
577 |
QCOMPARE(p.size(), layoutMinimumSize);
|
|
578 |
|
|
579 |
p.resize(layoutPreferredSize);
|
|
580 |
QCOMPARE(p.size(), layoutPreferredSize);
|
|
581 |
|
|
582 |
p.resize(layoutMaximumSize);
|
|
583 |
QCOMPARE(p.size(), layoutMaximumSize);
|
|
584 |
|
|
585 |
if (hasSimplification) {
|
|
586 |
QVERIFY(!usedSimplex(l, Qt::Horizontal));
|
|
587 |
QVERIFY(!usedSimplex(l, Qt::Vertical));
|
|
588 |
}
|
|
589 |
}
|
|
590 |
|
|
591 |
void tst_QGraphicsAnchorLayout::snake()
|
|
592 |
{
|
|
593 |
QGraphicsWidget *a = createItem(QSizeF(50.0, 100.0),
|
|
594 |
QSizeF(70.0, 100.0),
|
|
595 |
QSizeF(100.0, 100.0), "A");
|
|
596 |
|
|
597 |
QGraphicsWidget *b = createItem(QSizeF(10.0, 100.0),
|
|
598 |
QSizeF(20.0, 100.0),
|
|
599 |
QSizeF(40.0, 100.0), "B");
|
|
600 |
|
|
601 |
QGraphicsWidget *c = createItem(QSizeF(50.0, 100.0),
|
|
602 |
QSizeF(70.0, 100.0),
|
|
603 |
QSizeF(100.0, 100.0), "C");
|
|
604 |
|
|
605 |
QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout;
|
|
606 |
l->setContentsMargins(0, 0, 0, 0);
|
|
607 |
l->setSpacing(0);
|
|
608 |
|
|
609 |
l->addAnchor(l, Qt::AnchorTop, a, Qt::AnchorTop);
|
|
610 |
l->addAnchor(a, Qt::AnchorBottom, b, Qt::AnchorTop);
|
|
611 |
l->addAnchor(b, Qt::AnchorBottom, c, Qt::AnchorTop);
|
|
612 |
l->addAnchor(c, Qt::AnchorBottom, l, Qt::AnchorBottom);
|
|
613 |
|
|
614 |
l->addAnchor(l, Qt::AnchorLeft, a, Qt::AnchorLeft);
|
|
615 |
l->addAnchor(a, Qt::AnchorRight, b, Qt::AnchorRight);
|
|
616 |
l->addAnchor(b, Qt::AnchorLeft, c, Qt::AnchorLeft);
|
|
617 |
l->addAnchor(c, Qt::AnchorRight, l, Qt::AnchorRight);
|
|
618 |
|
|
619 |
QCOMPARE(l->count(), 3);
|
|
620 |
|
|
621 |
QGraphicsWidget p;
|
|
622 |
p.setLayout(l);
|
|
623 |
|
|
624 |
QSizeF layoutMinimumSize = l->effectiveSizeHint(Qt::MinimumSize);
|
|
625 |
QSizeF layoutMaximumSize = l->effectiveSizeHint(Qt::MaximumSize);
|
|
626 |
QSizeF layoutPreferredSize = l->effectiveSizeHint(Qt::PreferredSize);
|
|
627 |
|
|
628 |
QCOMPARE(layoutMinimumSize, QSizeF(60.0, 300.0));
|
|
629 |
QCOMPARE(layoutPreferredSize, QSizeF(120.0, 300.0));
|
|
630 |
QCOMPARE(layoutMaximumSize, QSizeF(190.0, 300.0));
|
|
631 |
|
|
632 |
p.resize(layoutMinimumSize);
|
|
633 |
QCOMPARE(a->geometry(), QRectF(0.0, 0.0, 50.0, 100.0));
|
|
634 |
QCOMPARE(b->geometry(), QRectF(10.0, 100.0, 40.0, 100.0));
|
|
635 |
QCOMPARE(c->geometry(), QRectF(10.0, 200.0, 50.0, 100.0));
|
|
636 |
QCOMPARE(p.size(), layoutMinimumSize);
|
|
637 |
|
|
638 |
p.resize(layoutPreferredSize);
|
|
639 |
QCOMPARE(a->geometry(), QRectF(0.0, 0.0, 70.0, 100.0));
|
|
640 |
QCOMPARE(b->geometry(), QRectF(50.0, 100.0, 20.0, 100.0));
|
|
641 |
QCOMPARE(c->geometry(), QRectF(50.0, 200.0, 70.0, 100.0));
|
|
642 |
QCOMPARE(p.size(), layoutPreferredSize);
|
|
643 |
|
|
644 |
p.resize(layoutMaximumSize);
|
|
645 |
QCOMPARE(a->geometry(), QRectF(0.0, 0.0, 100.0, 100.0));
|
|
646 |
QCOMPARE(b->geometry(), QRectF(90.0, 100.0, 10.0, 100.0));
|
|
647 |
QCOMPARE(c->geometry(), QRectF(90.0, 200.0, 100.0, 100.0));
|
|
648 |
QCOMPARE(p.size(), layoutMaximumSize);
|
|
649 |
|
|
650 |
QVERIFY(layoutHasConflict(l) == false);
|
|
651 |
|
|
652 |
// Test QSizePolicy::ExpandFlag, it shouldn't change the extreme
|
|
653 |
// points of the layout...
|
|
654 |
b->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
|
655 |
|
|
656 |
QSizeF newLayoutMinimumSize = l->effectiveSizeHint(Qt::MinimumSize);
|
|
657 |
QSizeF newLayoutMaximumSize = l->effectiveSizeHint(Qt::MaximumSize);
|
|
658 |
QSizeF newLayoutPreferredSize = l->effectiveSizeHint(Qt::PreferredSize);
|
|
659 |
|
|
660 |
QCOMPARE(layoutMinimumSize, newLayoutMinimumSize);
|
|
661 |
QCOMPARE(layoutMaximumSize, newLayoutMaximumSize);
|
|
662 |
QCOMPARE(layoutPreferredSize, newLayoutPreferredSize);
|
|
663 |
}
|
|
664 |
|
|
665 |
void tst_QGraphicsAnchorLayout::snakeOppositeDirections()
|
|
666 |
{
|
|
667 |
QGraphicsWidget *a = createItem(QSizeF(50.0, 100.0),
|
|
668 |
QSizeF(70.0, 100.0),
|
|
669 |
QSizeF(100.0, 100.0), "A");
|
|
670 |
|
|
671 |
QGraphicsWidget *b = createItem(QSizeF(10.0, 100.0),
|
|
672 |
QSizeF(20.0, 100.0),
|
|
673 |
QSizeF(40.0, 100.0), "B");
|
|
674 |
|
|
675 |
QGraphicsWidget *c = createItem(QSizeF(50.0, 100.0),
|
|
676 |
QSizeF(70.0, 100.0),
|
|
677 |
QSizeF(100.0, 100.0), "C");
|
|
678 |
|
|
679 |
QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout;
|
|
680 |
l->setContentsMargins(0, 0, 0, 0);
|
|
681 |
l->setSpacing(0);
|
|
682 |
|
|
683 |
l->addAnchor(l, Qt::AnchorTop, a, Qt::AnchorTop);
|
|
684 |
l->addAnchor(a, Qt::AnchorBottom, b, Qt::AnchorTop);
|
|
685 |
l->addAnchor(b, Qt::AnchorBottom, c, Qt::AnchorTop);
|
|
686 |
l->addAnchor(c, Qt::AnchorBottom, l, Qt::AnchorBottom);
|
|
687 |
|
|
688 |
l->addAnchor(l, Qt::AnchorLeft, a, Qt::AnchorLeft);
|
|
689 |
|
|
690 |
// Both a and c are 'pointing' to b
|
|
691 |
l->addAnchor(a, Qt::AnchorRight, b, Qt::AnchorRight);
|
|
692 |
l->addAnchor(c, Qt::AnchorLeft, b, Qt::AnchorLeft);
|
|
693 |
|
|
694 |
l->addAnchor(c, Qt::AnchorRight, l, Qt::AnchorRight);
|
|
695 |
|
|
696 |
QCOMPARE(l->count(), 3);
|
|
697 |
|
|
698 |
QGraphicsWidget p;
|
|
699 |
p.setLayout(l);
|
|
700 |
|
|
701 |
QSizeF layoutMinimumSize = l->effectiveSizeHint(Qt::MinimumSize);
|
|
702 |
QSizeF layoutMaximumSize = l->effectiveSizeHint(Qt::MaximumSize);
|
|
703 |
QSizeF layoutPreferredSize = l->effectiveSizeHint(Qt::PreferredSize);
|
|
704 |
|
|
705 |
QCOMPARE(layoutMinimumSize, QSizeF(60.0, 300.0));
|
|
706 |
QCOMPARE(layoutPreferredSize, QSizeF(120.0, 300.0));
|
|
707 |
QCOMPARE(layoutMaximumSize, QSizeF(190.0, 300.0));
|
|
708 |
|
|
709 |
p.resize(layoutMinimumSize);
|
|
710 |
QCOMPARE(a->geometry(), QRectF(0.0, 0.0, 50.0, 100.0));
|
|
711 |
QCOMPARE(b->geometry(), QRectF(10.0, 100.0, 40.0, 100.0));
|
|
712 |
QCOMPARE(c->geometry(), QRectF(10.0, 200.0, 50.0, 100.0));
|
|
713 |
QCOMPARE(p.size(), layoutMinimumSize);
|
|
714 |
|
|
715 |
p.resize(layoutPreferredSize);
|
|
716 |
QCOMPARE(a->geometry(), QRectF(0.0, 0.0, 70.0, 100.0));
|
|
717 |
QCOMPARE(b->geometry(), QRectF(50.0, 100.0, 20.0, 100.0));
|
|
718 |
QCOMPARE(c->geometry(), QRectF(50.0, 200.0, 70.0, 100.0));
|
|
719 |
QCOMPARE(p.size(), layoutPreferredSize);
|
|
720 |
|
|
721 |
p.resize(layoutMaximumSize);
|
|
722 |
QCOMPARE(a->geometry(), QRectF(0.0, 0.0, 100.0, 100.0));
|
|
723 |
QCOMPARE(b->geometry(), QRectF(90.0, 100.0, 10.0, 100.0));
|
|
724 |
QCOMPARE(c->geometry(), QRectF(90.0, 200.0, 100.0, 100.0));
|
|
725 |
QCOMPARE(p.size(), layoutMaximumSize);
|
|
726 |
|
|
727 |
QCOMPARE(checkReverseDirection(&p), true);
|
|
728 |
}
|
|
729 |
|
|
730 |
void tst_QGraphicsAnchorLayout::fairDistribution()
|
|
731 |
{
|
|
732 |
QGraphicsWidget *a = createItem(QSizeF(10.0, 100.0),
|
|
733 |
QSizeF(50.0, 100.0),
|
|
734 |
QSizeF(100.0, 100.0), "A");
|
|
735 |
|
|
736 |
QGraphicsWidget *b = createItem(QSizeF(10.0, 100.0),
|
|
737 |
QSizeF(50.0, 100.0),
|
|
738 |
QSizeF(100.0, 100.0), "B");
|
|
739 |
|
|
740 |
QGraphicsWidget *c = createItem(QSizeF(10.0, 100.0),
|
|
741 |
QSizeF(50.0, 100.0),
|
|
742 |
QSizeF(100.0, 100.0), "C");
|
|
743 |
|
|
744 |
QGraphicsWidget *d = createItem(QSizeF(60.0, 100.0),
|
|
745 |
QSizeF(165.0, 100.0),
|
|
746 |
QSizeF(600.0, 100.0), "D");
|
|
747 |
|
|
748 |
|
|
749 |
QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout;
|
|
750 |
l->setContentsMargins(0, 0, 0, 0);
|
|
751 |
l->setSpacing(0);
|
|
752 |
|
|
753 |
l->addAnchor(l, Qt::AnchorTop, a, Qt::AnchorTop);
|
|
754 |
l->addAnchor(a, Qt::AnchorBottom, b, Qt::AnchorTop);
|
|
755 |
l->addAnchor(b, Qt::AnchorBottom, c, Qt::AnchorTop);
|
|
756 |
l->addAnchor(c, Qt::AnchorBottom, d, Qt::AnchorTop);
|
|
757 |
l->addAnchor(d, Qt::AnchorBottom, l, Qt::AnchorBottom);
|
|
758 |
|
|
759 |
l->addAnchor(l, Qt::AnchorLeft, a, Qt::AnchorLeft);
|
|
760 |
l->addAnchor(a, Qt::AnchorRight, b, Qt::AnchorLeft);
|
|
761 |
l->addAnchor(b, Qt::AnchorRight, c, Qt::AnchorLeft);
|
|
762 |
l->addAnchor(c, Qt::AnchorRight, l, Qt::AnchorRight);
|
|
763 |
l->addAnchor(l, Qt::AnchorLeft, d, Qt::AnchorLeft);
|
|
764 |
l->addAnchor(d, Qt::AnchorRight, l, Qt::AnchorRight);
|
|
765 |
|
|
766 |
QCOMPARE(l->count(), 4);
|
|
767 |
|
|
768 |
QGraphicsWidget p;
|
|
769 |
p.setLayout(l);
|
|
770 |
|
|
771 |
QSizeF layoutMinimumSize = l->effectiveSizeHint(Qt::MinimumSize);
|
|
772 |
QSizeF layoutMaximumSize = l->effectiveSizeHint(Qt::MaximumSize);
|
|
773 |
QSizeF layoutPreferredSize = l->effectiveSizeHint(Qt::PreferredSize);
|
|
774 |
|
|
775 |
QCOMPARE(layoutMinimumSize, QSizeF(60.0, 400.0));
|
|
776 |
QCOMPARE(layoutPreferredSize, QSizeF(165.0, 400.0));
|
|
777 |
QCOMPARE(layoutMaximumSize, QSizeF(300.0, 400.0));
|
|
778 |
|
|
779 |
p.resize(layoutMinimumSize);
|
|
780 |
if (!hasSimplification)
|
|
781 |
QEXPECT_FAIL("", "Without simplification there is no fair distribution.", Abort);
|
|
782 |
QCOMPARE(a->geometry(), QRectF(0.0, 0.0, 20.0, 100.0));
|
|
783 |
QCOMPARE(b->geometry(), QRectF(20.0, 100.0, 20.0, 100.0));
|
|
784 |
QCOMPARE(c->geometry(), QRectF(40.0, 200.0, 20.0, 100.0));
|
|
785 |
QCOMPARE(d->geometry(), QRectF(0.0, 300.0, 60.0, 100.0));
|
|
786 |
QCOMPARE(p.size(), layoutMinimumSize);
|
|
787 |
|
|
788 |
p.resize(layoutPreferredSize);
|
|
789 |
QCOMPARE(a->geometry(), QRectF(0.0, 0.0, 55.0, 100.0));
|
|
790 |
QCOMPARE(b->geometry(), QRectF(55.0, 100.0, 55.0, 100.0));
|
|
791 |
QCOMPARE(c->geometry(), QRectF(110.0, 200.0, 55.0, 100.0));
|
|
792 |
QCOMPARE(d->geometry(), QRectF(0.0, 300.0, 165.0, 100.0));
|
|
793 |
QCOMPARE(p.size(), layoutPreferredSize);
|
|
794 |
|
|
795 |
p.resize(layoutMaximumSize);
|
|
796 |
QCOMPARE(a->geometry(), QRectF(0.0, 0.0, 100.0, 100.0));
|
|
797 |
QCOMPARE(b->geometry(), QRectF(100.0, 100.0, 100.0, 100.0));
|
|
798 |
QCOMPARE(c->geometry(), QRectF(200.0, 200.0, 100.0, 100.0));
|
|
799 |
QCOMPARE(d->geometry(), QRectF(0.0, 300.0, 300.0, 100.0));
|
|
800 |
QCOMPARE(p.size(), layoutMaximumSize);
|
|
801 |
|
|
802 |
if (hasSimplification) {
|
|
803 |
QVERIFY(!usedSimplex(l, Qt::Horizontal));
|
|
804 |
QVERIFY(!usedSimplex(l, Qt::Vertical));
|
|
805 |
}
|
|
806 |
}
|
|
807 |
|
|
808 |
void tst_QGraphicsAnchorLayout::fairDistributionOppositeDirections()
|
|
809 |
{
|
|
810 |
QGraphicsWidget *a = createItem(QSizeF(10.0, 100.0),
|
|
811 |
QSizeF(50.0, 100.0),
|
|
812 |
QSizeF(100.0, 100.0), "A");
|
|
813 |
|
|
814 |
QGraphicsWidget *b = createItem(QSizeF(10.0, 100.0),
|
|
815 |
QSizeF(50.0, 100.0),
|
|
816 |
QSizeF(100.0, 100.0), "B");
|
|
817 |
|
|
818 |
QGraphicsWidget *c = createItem(QSizeF(10.0, 100.0),
|
|
819 |
QSizeF(50.0, 100.0),
|
|
820 |
QSizeF(100.0, 100.0), "C");
|
|
821 |
|
|
822 |
QGraphicsWidget *d = createItem(QSizeF(10.0, 100.0),
|
|
823 |
QSizeF(50.0, 100.0),
|
|
824 |
QSizeF(100.0, 100.0), "D");
|
|
825 |
|
|
826 |
QGraphicsWidget *e = createItem(QSizeF(60.0, 100.0),
|
|
827 |
QSizeF(220.0, 100.0),
|
|
828 |
QSizeF(600.0, 100.0), "E");
|
|
829 |
|
|
830 |
|
|
831 |
QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout;
|
|
832 |
l->setContentsMargins(0, 0, 0, 0);
|
|
833 |
l->setSpacing(0);
|
|
834 |
|
|
835 |
l->addAnchor(l, Qt::AnchorTop, a, Qt::AnchorTop);
|
|
836 |
l->addAnchor(a, Qt::AnchorBottom, b, Qt::AnchorTop);
|
|
837 |
l->addAnchor(b, Qt::AnchorBottom, c, Qt::AnchorTop);
|
|
838 |
l->addAnchor(c, Qt::AnchorBottom, d, Qt::AnchorTop);
|
|
839 |
l->addAnchor(d, Qt::AnchorBottom, e, Qt::AnchorTop);
|
|
840 |
l->addAnchor(e, Qt::AnchorBottom, l, Qt::AnchorBottom);
|
|
841 |
|
|
842 |
l->addAnchor(a, Qt::AnchorLeft, l, Qt::AnchorLeft);
|
|
843 |
l->addAnchor(b, Qt::AnchorLeft, a, Qt::AnchorRight);
|
|
844 |
l->addAnchor(c, Qt::AnchorLeft, b, Qt::AnchorRight);
|
|
845 |
l->addAnchor(d, Qt::AnchorLeft, c, Qt::AnchorRight);
|
|
846 |
l->addAnchor(d, Qt::AnchorRight, l, Qt::AnchorRight);
|
|
847 |
l->addAnchors(l, e, Qt::Horizontal);
|
|
848 |
|
|
849 |
QCOMPARE(l->count(), 5);
|
|
850 |
|
|
851 |
QGraphicsWidget p;
|
|
852 |
p.setLayout(l);
|
|
853 |
|
|
854 |
QSizeF layoutMinimumSize = l->effectiveSizeHint(Qt::MinimumSize);
|
|
855 |
QSizeF layoutMaximumSize = l->effectiveSizeHint(Qt::MaximumSize);
|
|
856 |
QSizeF layoutPreferredSize = l->effectiveSizeHint(Qt::PreferredSize);
|
|
857 |
|
|
858 |
QCOMPARE(layoutMinimumSize, QSizeF(60.0, 500.0));
|
|
859 |
QCOMPARE(layoutPreferredSize, QSizeF(220.0, 500.0));
|
|
860 |
QCOMPARE(layoutMaximumSize, QSizeF(400.0, 500.0));
|
|
861 |
|
|
862 |
if (!hasSimplification)
|
|
863 |
return;
|
|
864 |
|
|
865 |
p.resize(layoutMinimumSize);
|
|
866 |
QCOMPARE(a->size(), b->size());
|
|
867 |
QCOMPARE(a->size(), c->size());
|
|
868 |
QCOMPARE(a->size(), d->size());
|
|
869 |
QCOMPARE(e->size().width(), 4 * a->size().width());
|
|
870 |
QCOMPARE(p.size(), layoutMinimumSize);
|
|
871 |
|
|
872 |
p.resize(layoutPreferredSize);
|
|
873 |
QCOMPARE(a->size(), b->size());
|
|
874 |
QCOMPARE(a->size(), c->size());
|
|
875 |
QCOMPARE(a->size(), d->size());
|
|
876 |
QCOMPARE(e->size().width(), 4 * a->size().width());
|
|
877 |
QCOMPARE(p.size(), layoutPreferredSize);
|
|
878 |
|
|
879 |
p.resize(layoutMaximumSize);
|
|
880 |
QCOMPARE(a->size(), b->size());
|
|
881 |
QCOMPARE(a->size(), c->size());
|
|
882 |
QCOMPARE(a->size(), d->size());
|
|
883 |
QCOMPARE(e->size().width(), 4 * a->size().width());
|
|
884 |
QCOMPARE(p.size(), layoutMaximumSize);
|
|
885 |
|
|
886 |
QVERIFY(!usedSimplex(l, Qt::Horizontal));
|
|
887 |
QVERIFY(!usedSimplex(l, Qt::Vertical));
|
|
888 |
}
|
|
889 |
|
|
890 |
void tst_QGraphicsAnchorLayout::proportionalPreferred()
|
|
891 |
{
|
|
892 |
QSizeF min(0, 100);
|
|
893 |
|
|
894 |
QGraphicsWidget *a = createItem(min, QSizeF(10, 100), QSizeF(20, 100), "A");
|
|
895 |
QGraphicsWidget *b = createItem(min, QSizeF(20, 100), QSizeF(30, 100), "B");
|
|
896 |
QGraphicsWidget *c = createItem(min, QSizeF(14, 100), QSizeF(20, 100), "C");
|
|
897 |
QGraphicsWidget *d = createItem(min, QSizeF(10, 100), QSizeF(20, 100), "D");
|
|
898 |
|
|
899 |
QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout;
|
|
900 |
l->setContentsMargins(0, 0, 0, 0);
|
|
901 |
l->setSpacing(0);
|
|
902 |
|
|
903 |
l->addAnchor(l, Qt::AnchorTop, a, Qt::AnchorTop);
|
|
904 |
l->addAnchor(a, Qt::AnchorBottom, b, Qt::AnchorTop);
|
|
905 |
l->addAnchor(b, Qt::AnchorBottom, c, Qt::AnchorTop);
|
|
906 |
l->addAnchor(c, Qt::AnchorBottom, d, Qt::AnchorTop);
|
|
907 |
l->addAnchor(d, Qt::AnchorBottom, l, Qt::AnchorBottom);
|
|
908 |
|
|
909 |
l->addAnchor(l, Qt::AnchorLeft, a, Qt::AnchorLeft);
|
|
910 |
l->addAnchor(l, Qt::AnchorLeft, b, Qt::AnchorLeft);
|
|
911 |
l->addAnchor(a, Qt::AnchorRight, c, Qt::AnchorLeft);
|
|
912 |
l->addAnchor(a, Qt::AnchorRight, d, Qt::AnchorLeft);
|
|
913 |
l->addAnchor(b, Qt::AnchorRight, l, Qt::AnchorRight);
|
|
914 |
l->addAnchor(c, Qt::AnchorRight, l, Qt::AnchorRight);
|
|
915 |
l->addAnchor(d, Qt::AnchorRight, l, Qt::AnchorRight);
|
|
916 |
|
|
917 |
QCOMPARE(l->count(), 4);
|
|
918 |
|
|
919 |
QGraphicsWidget p;
|
|
920 |
p.setLayout(l);
|
|
921 |
|
|
922 |
QSizeF layoutMinimumSize = l->effectiveSizeHint(Qt::MinimumSize);
|
|
923 |
QSizeF layoutPreferredSize = l->effectiveSizeHint(Qt::PreferredSize);
|
|
924 |
QSizeF layoutMaximumSize = l->effectiveSizeHint(Qt::MaximumSize);
|
|
925 |
|
|
926 |
QCOMPARE(layoutMinimumSize, QSizeF(0, 400));
|
|
927 |
QCOMPARE(layoutPreferredSize, QSizeF(24, 400));
|
|
928 |
QCOMPARE(layoutMaximumSize, QSizeF(30, 400));
|
|
929 |
|
|
930 |
p.resize(layoutMinimumSize);
|
|
931 |
QCOMPARE(p.size(), layoutMinimumSize);
|
|
932 |
|
|
933 |
p.resize(layoutPreferredSize);
|
|
934 |
QCOMPARE(c->size().width(), d->size().width());
|
|
935 |
QCOMPARE(p.size(), layoutPreferredSize);
|
|
936 |
|
|
937 |
p.resize(layoutMaximumSize);
|
|
938 |
QCOMPARE(p.size(), layoutMaximumSize);
|
|
939 |
|
|
940 |
p.resize(QSizeF(12, 400));
|
|
941 |
|
|
942 |
// Proportionality between size given and preferred size, this
|
|
943 |
// should be respected in this graph for (a) and (b)|(c).
|
|
944 |
qreal factor = 12.0 / 24.0;
|
|
945 |
|
|
946 |
QCOMPARE(c->size().width(), d->size().width());
|
|
947 |
QCOMPARE(a->size().width(), 10 * factor);
|
|
948 |
QCOMPARE(c->size().width(), 14 * factor);
|
|
949 |
QCOMPARE(p.size(), QSizeF(12, 400));
|
|
950 |
|
|
951 |
if (hasSimplification) {
|
|
952 |
QVERIFY(!usedSimplex(l, Qt::Horizontal));
|
|
953 |
QVERIFY(!usedSimplex(l, Qt::Vertical));
|
|
954 |
}
|
|
955 |
}
|
|
956 |
|
|
957 |
void tst_QGraphicsAnchorLayout::example()
|
|
958 |
{
|
|
959 |
QSizeF min(30, 100);
|
|
960 |
QSizeF pref(210, 100);
|
|
961 |
QSizeF max(300, 100);
|
|
962 |
|
|
963 |
QGraphicsWidget *a = createItem(min, pref, max, "A");
|
|
964 |
QGraphicsWidget *b = createItem(min, pref, max, "B");
|
|
965 |
QGraphicsWidget *c = createItem(min, pref, max, "C");
|
|
966 |
QGraphicsWidget *d = createItem(min, pref, max, "D");
|
|
967 |
QGraphicsWidget *e = createItem(min, pref, max, "E");
|
|
968 |
QGraphicsWidget *f = createItem(QSizeF(30, 50), QSizeF(150, 50), max, "F");
|
|
969 |
QGraphicsWidget *g = createItem(QSizeF(30, 50), QSizeF(30, 100), max, "G");
|
|
970 |
|
|
971 |
QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout;
|
|
972 |
l->setContentsMargins(0, 0, 0, 0);
|
|
973 |
l->setSpacing(0);
|
|
974 |
|
|
975 |
// vertical
|
|
976 |
l->addAnchor(a, Qt::AnchorTop, l, Qt::AnchorTop);
|
|
977 |
l->addAnchor(b, Qt::AnchorTop, l, Qt::AnchorTop);
|
|
978 |
|
|
979 |
l->addAnchor(c, Qt::AnchorTop, a, Qt::AnchorBottom);
|
|
980 |
l->addAnchor(c, Qt::AnchorTop, b, Qt::AnchorBottom);
|
|
981 |
l->addAnchor(c, Qt::AnchorBottom, d, Qt::AnchorTop);
|
|
982 |
l->addAnchor(c, Qt::AnchorBottom, e, Qt::AnchorTop);
|
|
983 |
|
|
984 |
l->addAnchor(d, Qt::AnchorBottom, l, Qt::AnchorBottom);
|
|
985 |
l->addAnchor(e, Qt::AnchorBottom, l, Qt::AnchorBottom);
|
|
986 |
|
|
987 |
l->addAnchor(c, Qt::AnchorTop, f, Qt::AnchorTop);
|
|
988 |
l->addAnchor(c, Qt::AnchorVerticalCenter, f, Qt::AnchorBottom);
|
|
989 |
l->addAnchor(f, Qt::AnchorBottom, g, Qt::AnchorTop);
|
|
990 |
l->addAnchor(c, Qt::AnchorBottom, g, Qt::AnchorBottom);
|
|
991 |
|
|
992 |
// horizontal
|
|
993 |
l->addAnchor(l, Qt::AnchorLeft, a, Qt::AnchorLeft);
|
|
994 |
l->addAnchor(l, Qt::AnchorLeft, d, Qt::AnchorLeft);
|
|
995 |
l->addAnchor(a, Qt::AnchorRight, b, Qt::AnchorLeft);
|
|
996 |
|
|
997 |
l->addAnchor(a, Qt::AnchorRight, c, Qt::AnchorLeft);
|
|
998 |
l->addAnchor(c, Qt::AnchorRight, e, Qt::AnchorLeft);
|
|
999 |
|
|
1000 |
l->addAnchor(b, Qt::AnchorRight, l, Qt::AnchorRight);
|
|
1001 |
l->addAnchor(e, Qt::AnchorRight, l, Qt::AnchorRight);
|
|
1002 |
l->addAnchor(d, Qt::AnchorRight, e, Qt::AnchorLeft);
|
|
1003 |
|
|
1004 |
l->addAnchor(l, Qt::AnchorLeft, f, Qt::AnchorLeft);
|
|
1005 |
l->addAnchor(l, Qt::AnchorLeft, g, Qt::AnchorLeft);
|
|
1006 |
l->addAnchor(f, Qt::AnchorRight, g, Qt::AnchorRight);
|
|
1007 |
|
|
1008 |
QCOMPARE(l->count(), 7);
|
|
1009 |
|
|
1010 |
QGraphicsWidget p;
|
|
1011 |
p.setLayout(l);
|
|
1012 |
|
|
1013 |
QSizeF layoutMinimumSize = l->effectiveSizeHint(Qt::MinimumSize);
|
|
1014 |
QSizeF layoutMaximumSize = l->effectiveSizeHint(Qt::MaximumSize);
|
|
1015 |
QSizeF layoutPreferredSize = l->effectiveSizeHint(Qt::PreferredSize);
|
|
1016 |
|
|
1017 |
QCOMPARE(layoutMinimumSize, QSizeF(90.0, 300.0));
|
|
1018 |
QCOMPARE(layoutPreferredSize, QSizeF(510.0, 300.0));
|
|
1019 |
QCOMPARE(layoutMaximumSize, QSizeF(570.0, 300.0));
|
|
1020 |
|
|
1021 |
p.resize(layoutMinimumSize);
|
|
1022 |
QCOMPARE(p.size(), layoutMinimumSize);
|
|
1023 |
QCOMPARE(a->size(), e->size());
|
|
1024 |
QCOMPARE(b->size(), d->size());
|
|
1025 |
QCOMPARE(f->size(), g->size());
|
|
1026 |
|
|
1027 |
p.resize(layoutPreferredSize);
|
|
1028 |
QCOMPARE(p.size(), layoutPreferredSize);
|
|
1029 |
QCOMPARE(a->size(), e->size());
|
|
1030 |
QCOMPARE(b->size(), d->size());
|
|
1031 |
QCOMPARE(f->size(), g->size());
|
|
1032 |
|
|
1033 |
p.resize(layoutMaximumSize);
|
|
1034 |
QCOMPARE(p.size(), layoutMaximumSize);
|
|
1035 |
QCOMPARE(a->size(), e->size());
|
|
1036 |
QCOMPARE(b->size(), d->size());
|
|
1037 |
QCOMPARE(f->size(), g->size());
|
|
1038 |
|
|
1039 |
if (hasSimplification) {
|
|
1040 |
QVERIFY(usedSimplex(l, Qt::Horizontal));
|
|
1041 |
QVERIFY(usedSimplex(l, Qt::Vertical));
|
|
1042 |
}
|
|
1043 |
}
|
|
1044 |
|
|
1045 |
void tst_QGraphicsAnchorLayout::setSpacing()
|
|
1046 |
{
|
|
1047 |
QSizeF min(10, 10);
|
|
1048 |
QSizeF pref(20, 20);
|
|
1049 |
QSizeF max(50, 50);
|
|
1050 |
|
|
1051 |
QGraphicsWidget *a = createItem(min, pref, max);
|
|
1052 |
QGraphicsWidget *b = createItem(min, pref, max);
|
|
1053 |
QGraphicsWidget *c = createItem(min, pref, max);
|
|
1054 |
|
|
1055 |
QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout;
|
|
1056 |
l->addCornerAnchors(l, Qt::TopLeftCorner, a, Qt::TopLeftCorner);
|
|
1057 |
l->addCornerAnchors(b, Qt::TopRightCorner, l, Qt::TopRightCorner);
|
|
1058 |
l->addAnchor(a, Qt::AnchorRight, b, Qt::AnchorLeft);
|
|
1059 |
|
|
1060 |
l->addAnchors(l, c, Qt::Horizontal);
|
|
1061 |
|
|
1062 |
l->addAnchor(a, Qt::AnchorBottom, c, Qt::AnchorTop);
|
|
1063 |
l->addAnchor(c, Qt::AnchorBottom, l, Qt::AnchorBottom);
|
|
1064 |
|
|
1065 |
QGraphicsWidget *p = new QGraphicsWidget(0, Qt::Window);
|
|
1066 |
|
|
1067 |
p->setLayout(l);
|
|
1068 |
l->setSpacing(1);
|
|
1069 |
|
|
1070 |
// don't let the style influence the test.
|
|
1071 |
l->setContentsMargins(0, 0, 0, 0);
|
|
1072 |
|
|
1073 |
QGraphicsScene scene;
|
|
1074 |
scene.addItem(p);
|
|
1075 |
QGraphicsView *view = new QGraphicsView(&scene);
|
|
1076 |
view->show();
|
|
1077 |
p->show();
|
|
1078 |
|
|
1079 |
QApplication::processEvents();
|
|
1080 |
#ifdef Q_WS_MAC
|
|
1081 |
QTest::qWait(200);
|
|
1082 |
#endif
|
|
1083 |
QCOMPARE(a->geometry(), QRectF(0, 0, 20, 20));
|
|
1084 |
QCOMPARE(b->geometry(), QRectF(21, 0, 20, 20));
|
|
1085 |
QCOMPARE(c->geometry(), QRectF(0, 21, 41, 20));
|
|
1086 |
|
|
1087 |
l->setHorizontalSpacing(4);
|
|
1088 |
QApplication::processEvents();
|
|
1089 |
p->adjustSize();
|
|
1090 |
QCOMPARE(a->geometry(), QRectF(0, 0, 20, 20));
|
|
1091 |
QCOMPARE(b->geometry(), QRectF(24, 0, 20, 20));
|
|
1092 |
QCOMPARE(c->geometry(), QRectF(0, 21, 44, 20));
|
|
1093 |
|
|
1094 |
l->setVerticalSpacing(0);
|
|
1095 |
QApplication::processEvents();
|
|
1096 |
p->adjustSize();
|
|
1097 |
QCOMPARE(a->geometry(), QRectF(0, 0, 20, 20));
|
|
1098 |
QCOMPARE(b->geometry(), QRectF(24, 0, 20, 20));
|
|
1099 |
QCOMPARE(c->geometry(), QRectF(0, 20, 44, 20));
|
|
1100 |
|
|
1101 |
delete p;
|
|
1102 |
delete view;
|
|
1103 |
}
|
|
1104 |
|
|
1105 |
/*!
|
|
1106 |
Taken from "hard" complex case, found at
|
|
1107 |
https://cwiki.nokia.com/S60QTUI/AnchorLayoutComplexCases
|
|
1108 |
|
|
1109 |
This layout has a special property, since it has two possible solutions for its minimum size.
|
|
1110 |
|
|
1111 |
For instance, when it is in its minimum size - the layout have two possible solutions:
|
|
1112 |
1. c.width == 10, e.width == 10 and g.width == 10
|
|
1113 |
(all others have width 0)
|
|
1114 |
2. d.width == 10 and g.width == 10
|
|
1115 |
(all others have width 0)
|
|
1116 |
|
|
1117 |
It also has several solutions for preferred size.
|
|
1118 |
*/
|
|
1119 |
static QGraphicsAnchorLayout *createAmbiguousS60Layout()
|
|
1120 |
{
|
|
1121 |
QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout;
|
|
1122 |
l->setContentsMargins(0, 0, 0, 0);
|
|
1123 |
l->setSpacing(0);
|
|
1124 |
|
|
1125 |
QSizeF min(0, 10);
|
|
1126 |
QSizeF pref(50, 10);
|
|
1127 |
QSizeF max(100, 10);
|
|
1128 |
|
|
1129 |
QGraphicsWidget *a = createItem(min, pref, max, "a");
|
|
1130 |
QGraphicsWidget *b = createItem(min, pref, max, "b");
|
|
1131 |
QGraphicsWidget *c = createItem(min, pref, max, "c");
|
|
1132 |
QGraphicsWidget *d = createItem(min, pref, max, "d");
|
|
1133 |
QGraphicsWidget *e = createItem(min, pref, max, "e");
|
|
1134 |
QGraphicsWidget *f = createItem(min, pref, max, "f");
|
|
1135 |
QGraphicsWidget *g = createItem(min, pref, max, "g");
|
|
1136 |
|
|
1137 |
//<!-- Trunk -->
|
|
1138 |
setAnchor(l, l, Qt::AnchorLeft, a, Qt::AnchorLeft, 10);
|
|
1139 |
setAnchor(l, a, Qt::AnchorRight, b, Qt::AnchorLeft, 10);
|
|
1140 |
setAnchor(l, b, Qt::AnchorRight, c, Qt::AnchorLeft, 10);
|
|
1141 |
setAnchor(l, c, Qt::AnchorRight, d, Qt::AnchorLeft, 10);
|
|
1142 |
setAnchor(l, d, Qt::AnchorRight, l, Qt::AnchorRight, 10);
|
|
1143 |
|
|
1144 |
//<!-- Above trunk -->
|
|
1145 |
setAnchor(l, b, Qt::AnchorLeft, e, Qt::AnchorLeft, 10);
|
|
1146 |
setAnchor(l, e, Qt::AnchorRight, d, Qt::AnchorLeft, 10);
|
|
1147 |
|
|
1148 |
//<!-- Below trunk -->
|
|
1149 |
setAnchor(l, a, Qt::AnchorHorizontalCenter, g, Qt::AnchorLeft, 10);
|
|
1150 |
setAnchor(l, g, Qt::AnchorRight, f, Qt::AnchorHorizontalCenter, 10);
|
|
1151 |
setAnchor(l, c, Qt::AnchorLeft, f, Qt::AnchorLeft, 10);
|
|
1152 |
setAnchor(l, f, Qt::AnchorRight, d, Qt::AnchorRight, 10);
|
|
1153 |
|
|
1154 |
//<!-- vertical is simpler -->
|
|
1155 |
setAnchor(l, l, Qt::AnchorTop, e, Qt::AnchorTop, 0);
|
|
1156 |
setAnchor(l, e, Qt::AnchorBottom, a, Qt::AnchorTop, 0);
|
|
1157 |
setAnchor(l, e, Qt::AnchorBottom, b, Qt::AnchorTop, 0);
|
|
1158 |
setAnchor(l, e, Qt::AnchorBottom, c, Qt::AnchorTop, 0);
|
|
1159 |
setAnchor(l, e, Qt::AnchorBottom, d, Qt::AnchorTop, 0);
|
|
1160 |
setAnchor(l, a, Qt::AnchorBottom, f, Qt::AnchorTop, 0);
|
|
1161 |
setAnchor(l, a, Qt::AnchorBottom, b, Qt::AnchorBottom, 0);
|
|
1162 |
setAnchor(l, a, Qt::AnchorBottom, c, Qt::AnchorBottom, 0);
|
|
1163 |
setAnchor(l, a, Qt::AnchorBottom, d, Qt::AnchorBottom, 0);
|
|
1164 |
setAnchor(l, f, Qt::AnchorBottom, g, Qt::AnchorTop, 0);
|
|
1165 |
setAnchor(l, g, Qt::AnchorBottom, l, Qt::AnchorBottom, 0);
|
|
1166 |
return l;
|
|
1167 |
}
|
|
1168 |
|
|
1169 |
void tst_QGraphicsAnchorLayout::hardComplexS60()
|
|
1170 |
{
|
|
1171 |
QGraphicsAnchorLayout *l = createAmbiguousS60Layout();
|
|
1172 |
QCOMPARE(l->count(), 7);
|
|
1173 |
|
|
1174 |
QGraphicsWidget *p = new QGraphicsWidget(0, Qt::Window);
|
|
1175 |
p->setLayout(l);
|
|
1176 |
|
|
1177 |
QSizeF layoutMinimumSize = l->effectiveSizeHint(Qt::MinimumSize);
|
|
1178 |
QCOMPARE(layoutMinimumSize, QSizeF(60, 40));
|
|
1179 |
// expected preferred might be wrong, (haven't manually verified it)
|
|
1180 |
QSizeF layoutPreferredSize = l->effectiveSizeHint(Qt::PreferredSize);
|
|
1181 |
QCOMPARE(layoutPreferredSize, QSizeF(220, 40));
|
|
1182 |
QSizeF layoutMaximumSize = l->effectiveSizeHint(Qt::MaximumSize);
|
|
1183 |
QCOMPARE(layoutMaximumSize, QSizeF(240, 40));
|
|
1184 |
|
|
1185 |
delete p;
|
|
1186 |
}
|
|
1187 |
|
|
1188 |
void tst_QGraphicsAnchorLayout::stability()
|
|
1189 |
{
|
|
1190 |
QVector<QRectF> geometries;
|
|
1191 |
geometries.resize(7);
|
|
1192 |
QGraphicsWidget *p = new QGraphicsWidget(0, Qt::Window);
|
|
1193 |
bool sameAsPreviousArrangement = true;
|
|
1194 |
// it usually fails after 3-4 iterations
|
|
1195 |
for (int pass = 0; pass < 20 && sameAsPreviousArrangement; ++pass) {
|
|
1196 |
// In case we need to "scramble" the heap allocator to provoke this bug.
|
|
1197 |
//static const int primes[] = {2, 3, 5, 13, 89, 233, 1597, 28657, 514229}; // fibo primes
|
|
1198 |
//const int primeCount = sizeof(primes)/sizeof(int);
|
|
1199 |
//int alloc = primes[pass % primeCount] + pass;
|
|
1200 |
//void *mem = qMalloc(alloc);
|
|
1201 |
//qFree(mem);
|
|
1202 |
QGraphicsAnchorLayout *l = createAmbiguousS60Layout();
|
|
1203 |
p->setLayout(l);
|
|
1204 |
QSizeF layoutMinimumSize = l->effectiveSizeHint(Qt::MinimumSize);
|
|
1205 |
l->setGeometry(QRectF(QPointF(0,0), layoutMinimumSize));
|
|
1206 |
QApplication::processEvents();
|
|
1207 |
for (int i = l->count() - 1; i >=0 && sameAsPreviousArrangement; --i) {
|
|
1208 |
QRectF geom = l->itemAt(i)->geometry();
|
|
1209 |
if (pass != 0) {
|
|
1210 |
sameAsPreviousArrangement = (geometries[i] == geom);
|
|
1211 |
}
|
|
1212 |
geometries[i] = geom;
|
|
1213 |
}
|
|
1214 |
p->setLayout(0); // uninstalls and deletes the layout
|
|
1215 |
QApplication::processEvents();
|
|
1216 |
}
|
|
1217 |
delete p;
|
|
1218 |
QEXPECT_FAIL("", "The layout have several solutions, but which solution it picks is not stable", Continue);
|
|
1219 |
QCOMPARE(sameAsPreviousArrangement, true);
|
|
1220 |
}
|
|
1221 |
|
|
1222 |
void tst_QGraphicsAnchorLayout::delete_anchor()
|
|
1223 |
{
|
|
1224 |
QGraphicsScene scene;
|
|
1225 |
QSizeF minSize(0, 0);
|
|
1226 |
QSizeF prefSize(50, 50);
|
|
1227 |
QSizeF maxSize(100, 100);
|
|
1228 |
QGraphicsWidget *w1 = createItem(minSize, prefSize, maxSize, "w1");
|
|
1229 |
QGraphicsWidget *w2 = createItem(minSize, prefSize, maxSize, "w2");
|
|
1230 |
QGraphicsWidget *w3 = createItem(minSize, prefSize, maxSize, "w3");
|
|
1231 |
|
|
1232 |
QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout;
|
|
1233 |
l->setSpacing(0);
|
|
1234 |
l->setContentsMargins(0, 0, 0, 0);
|
|
1235 |
|
|
1236 |
// Horizontal
|
|
1237 |
l->addAnchor(l, Qt::AnchorLeft, w1, Qt::AnchorLeft);
|
|
1238 |
l->addAnchor(w1, Qt::AnchorRight, w2, Qt::AnchorLeft);
|
|
1239 |
l->addAnchor(w2, Qt::AnchorRight, l, Qt::AnchorRight);
|
|
1240 |
l->addAnchor(w1, Qt::AnchorRight, w3, Qt::AnchorLeft);
|
|
1241 |
l->addAnchor(w3, Qt::AnchorRight, l, Qt::AnchorRight);
|
|
1242 |
|
|
1243 |
// Vertical
|
|
1244 |
l->addAnchors(l, w1, Qt::Vertical);
|
|
1245 |
l->addAnchors(l, w2, Qt::Vertical);
|
|
1246 |
l->addAnchors(l, w3, Qt::Vertical);
|
|
1247 |
|
|
1248 |
QGraphicsAnchor *anchor = l->anchor(w3, Qt::AnchorRight, l, Qt::AnchorRight);
|
|
1249 |
anchor->setSpacing(10);
|
|
1250 |
|
|
1251 |
QGraphicsWidget *p = new QGraphicsWidget;
|
|
1252 |
p->setLayout(l);
|
|
1253 |
|
|
1254 |
QCOMPARE(l->count(), 3);
|
|
1255 |
|
|
1256 |
scene.addItem(p);
|
|
1257 |
QGraphicsView *view = new QGraphicsView(&scene);
|
|
1258 |
QApplication::processEvents();
|
|
1259 |
// Should now be simplified
|
|
1260 |
QCOMPARE(l->effectiveSizeHint(Qt::PreferredSize).width(), qreal(110));
|
|
1261 |
QGraphicsAnchor *anchor1 = l->anchor(w3, Qt::AnchorRight, l, Qt::AnchorRight);
|
|
1262 |
QVERIFY(anchor1);
|
|
1263 |
QGraphicsAnchor *anchor2 = l->anchor(w3, Qt::AnchorRight, l, Qt::AnchorRight);
|
|
1264 |
QVERIFY(anchor2);
|
|
1265 |
QGraphicsAnchor *anchor3 = l->anchor(l, Qt::AnchorRight, w3, Qt::AnchorRight);
|
|
1266 |
QVERIFY(anchor3);
|
|
1267 |
QGraphicsAnchor *anchor4 = l->anchor(l, Qt::AnchorRight, w3, Qt::AnchorRight);
|
|
1268 |
QVERIFY(anchor4);
|
|
1269 |
|
|
1270 |
// should all be the same object
|
|
1271 |
QCOMPARE(anchor1, anchor2);
|
|
1272 |
QCOMPARE(anchor2, anchor3);
|
|
1273 |
QCOMPARE(anchor3, anchor4);
|
|
1274 |
|
|
1275 |
// check if removal works
|
|
1276 |
delete anchor1;
|
|
1277 |
|
|
1278 |
QApplication::processEvents();
|
|
1279 |
|
|
1280 |
// it should also change the preferred size of the layout
|
|
1281 |
QCOMPARE(l->effectiveSizeHint(Qt::PreferredSize).width(), qreal(100));
|
|
1282 |
|
|
1283 |
delete p;
|
|
1284 |
delete view;
|
|
1285 |
}
|
|
1286 |
|
|
1287 |
void tst_QGraphicsAnchorLayout::sizePolicy()
|
|
1288 |
{
|
|
1289 |
QGraphicsScene scene;
|
|
1290 |
QSizeF minSize(0, 0);
|
|
1291 |
QSizeF prefSize(50, 50);
|
|
1292 |
QSizeF maxSize(100, 100);
|
|
1293 |
QGraphicsWidget *w1 = createItem(minSize, prefSize, maxSize, "w1");
|
|
1294 |
|
|
1295 |
QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout;
|
|
1296 |
l->setSpacing(0);
|
|
1297 |
l->setContentsMargins(0, 0, 0, 0);
|
|
1298 |
|
|
1299 |
// horizontal and vertical
|
|
1300 |
l->addAnchors(l, w1);
|
|
1301 |
|
|
1302 |
QGraphicsWidget *p = new QGraphicsWidget;
|
|
1303 |
p->setLayout(l);
|
|
1304 |
|
|
1305 |
scene.addItem(p);
|
|
1306 |
QGraphicsView *view = new QGraphicsView(&scene);
|
|
1307 |
|
|
1308 |
// QSizePolicy::Minimum
|
|
1309 |
w1->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
|
|
1310 |
QApplication::processEvents();
|
|
1311 |
w1->adjustSize();
|
|
1312 |
|
|
1313 |
QCOMPARE(l->effectiveSizeHint(Qt::MinimumSize), QSizeF(50, 50));
|
|
1314 |
QCOMPARE(l->effectiveSizeHint(Qt::PreferredSize), QSizeF(50, 50));
|
|
1315 |
QCOMPARE(l->effectiveSizeHint(Qt::MaximumSize), QSizeF(100, 100));
|
|
1316 |
|
|
1317 |
// QSizePolicy::Maximum
|
|
1318 |
w1->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
|
|
1319 |
QApplication::processEvents();
|
|
1320 |
w1->adjustSize();
|
|
1321 |
|
|
1322 |
QCOMPARE(l->effectiveSizeHint(Qt::MinimumSize), QSizeF(0, 0));
|
|
1323 |
QCOMPARE(l->effectiveSizeHint(Qt::PreferredSize), QSizeF(50, 50));
|
|
1324 |
QCOMPARE(l->effectiveSizeHint(Qt::MaximumSize), QSizeF(50, 50));
|
|
1325 |
|
|
1326 |
// QSizePolicy::Fixed
|
|
1327 |
w1->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
|
1328 |
QApplication::processEvents();
|
|
1329 |
w1->adjustSize();
|
|
1330 |
|
|
1331 |
QCOMPARE(l->effectiveSizeHint(Qt::MinimumSize), QSizeF(50, 50));
|
|
1332 |
QCOMPARE(l->effectiveSizeHint(Qt::PreferredSize), QSizeF(50, 50));
|
|
1333 |
QCOMPARE(l->effectiveSizeHint(Qt::MaximumSize), QSizeF(50, 50));
|
|
1334 |
|
|
1335 |
// QSizePolicy::Preferred
|
|
1336 |
w1->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
|
1337 |
QApplication::processEvents();
|
|
1338 |
w1->adjustSize();
|
|
1339 |
|
|
1340 |
QCOMPARE(l->effectiveSizeHint(Qt::MinimumSize), QSizeF(0, 0));
|
|
1341 |
QCOMPARE(l->effectiveSizeHint(Qt::PreferredSize), QSizeF(50, 50));
|
|
1342 |
QCOMPARE(l->effectiveSizeHint(Qt::MaximumSize), QSizeF(100, 100));
|
|
1343 |
|
|
1344 |
// QSizePolicy::Ignored
|
|
1345 |
w1->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
|
|
1346 |
QApplication::processEvents();
|
|
1347 |
w1->adjustSize();
|
|
1348 |
|
|
1349 |
QCOMPARE(l->effectiveSizeHint(Qt::MinimumSize), QSizeF(0, 0));
|
|
1350 |
QCOMPARE(l->effectiveSizeHint(Qt::PreferredSize), QSizeF(0, 0));
|
|
1351 |
QCOMPARE(l->effectiveSizeHint(Qt::MaximumSize), QSizeF(100, 100));
|
|
1352 |
|
|
1353 |
// Anchor size policies
|
|
1354 |
w1->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
|
1355 |
QGraphicsAnchor *anchor = l->anchor(l, Qt::AnchorLeft, w1, Qt::AnchorLeft);
|
|
1356 |
anchor->setSpacing(10);
|
|
1357 |
|
|
1358 |
// QSizePolicy::Minimum
|
|
1359 |
anchor->setSizePolicy(QSizePolicy::Minimum);
|
|
1360 |
QApplication::processEvents();
|
|
1361 |
|
|
1362 |
QCOMPARE(l->effectiveSizeHint(Qt::MinimumSize), QSizeF(60, 50));
|
|
1363 |
QCOMPARE(l->effectiveSizeHint(Qt::PreferredSize), QSizeF(60, 50));
|
|
1364 |
// The layout has a maximum size of QWIDGETSIZE_MAX, so the result won't exceed that value.
|
|
1365 |
QCOMPARE(l->effectiveSizeHint(Qt::MaximumSize), QSizeF(QWIDGETSIZE_MAX, 50));
|
|
1366 |
|
|
1367 |
// QSizePolicy::Preferred
|
|
1368 |
anchor->setSizePolicy(QSizePolicy::Preferred);
|
|
1369 |
QApplication::processEvents();
|
|
1370 |
|
|
1371 |
QCOMPARE(l->effectiveSizeHint(Qt::MinimumSize), QSizeF(50, 50));
|
|
1372 |
QCOMPARE(l->effectiveSizeHint(Qt::PreferredSize), QSizeF(60, 50));
|
|
1373 |
// The layout has a maximum size of QWIDGETSIZE_MAX, so the result won't exceed that value.
|
|
1374 |
QCOMPARE(l->effectiveSizeHint(Qt::MaximumSize), QSizeF(QWIDGETSIZE_MAX, 50));
|
|
1375 |
|
|
1376 |
// QSizePolicy::Maximum
|
|
1377 |
anchor->setSizePolicy(QSizePolicy::Maximum);
|
|
1378 |
QApplication::processEvents();
|
|
1379 |
|
|
1380 |
QCOMPARE(l->effectiveSizeHint(Qt::MinimumSize), QSizeF(50, 50));
|
|
1381 |
QCOMPARE(l->effectiveSizeHint(Qt::PreferredSize), QSizeF(60, 50));
|
|
1382 |
QCOMPARE(l->effectiveSizeHint(Qt::MaximumSize), QSizeF(60, 50));
|
|
1383 |
|
|
1384 |
// QSizePolicy::Ignored
|
|
1385 |
anchor->setSizePolicy(QSizePolicy::Ignored);
|
|
1386 |
QApplication::processEvents();
|
|
1387 |
|
|
1388 |
QCOMPARE(l->effectiveSizeHint(Qt::MinimumSize), QSizeF(50, 50));
|
|
1389 |
QCOMPARE(l->effectiveSizeHint(Qt::PreferredSize), QSizeF(50, 50));
|
|
1390 |
QCOMPARE(l->effectiveSizeHint(Qt::MaximumSize), QSizeF(QWIDGETSIZE_MAX, 50));
|
|
1391 |
|
|
1392 |
if (hasSimplification) {
|
|
1393 |
QVERIFY(!usedSimplex(l, Qt::Horizontal));
|
|
1394 |
QVERIFY(!usedSimplex(l, Qt::Vertical));
|
|
1395 |
}
|
|
1396 |
|
|
1397 |
delete p;
|
|
1398 |
delete view;
|
|
1399 |
}
|
|
1400 |
|
|
1401 |
/*!
|
|
1402 |
\internal
|
|
1403 |
|
|
1404 |
Uses private API. (We have decided to pull hasConflicts() out of the API). However, it also
|
|
1405 |
tests some tight conditions (almost-in-conflict) that we really want to test.
|
|
1406 |
*/
|
|
1407 |
void tst_QGraphicsAnchorLayout::conflicts()
|
|
1408 |
{
|
|
1409 |
QGraphicsWidget *a = createItem(QSizeF(80,10), QSizeF(90,10), QSizeF(100,10), "a");
|
|
1410 |
QGraphicsWidget *b = createItem(QSizeF(10,10), QSizeF(20,10), QSizeF(30,10), "b");
|
|
1411 |
QGraphicsWidget *c = createItem(QSizeF(10,10), QSizeF(20,10), QSizeF(30,10), "c");
|
|
1412 |
|
|
1413 |
QGraphicsAnchorLayout *l;
|
|
1414 |
QGraphicsWidget *p = new QGraphicsWidget(0, Qt::Window);
|
|
1415 |
|
|
1416 |
l = new QGraphicsAnchorLayout;
|
|
1417 |
l->setContentsMargins(0, 0, 0, 0);
|
|
1418 |
|
|
1419 |
// with the following setup, 'a' cannot be larger than 30 we will first have a Simplex conflict
|
|
1420 |
|
|
1421 |
// horizontal
|
|
1422 |
setAnchor(l, l, Qt::AnchorLeft, b, Qt::AnchorLeft);
|
|
1423 |
setAnchor(l, b, Qt::AnchorRight, c, Qt::AnchorLeft);
|
|
1424 |
setAnchor(l, c, Qt::AnchorRight, l, Qt::AnchorRight);
|
|
1425 |
setAnchor(l, b, Qt::AnchorHorizontalCenter, a, Qt::AnchorLeft);
|
|
1426 |
setAnchor(l, a, Qt::AnchorRight, c, Qt::AnchorHorizontalCenter);
|
|
1427 |
|
|
1428 |
// vertical
|
|
1429 |
setAnchor(l, l, Qt::AnchorTop, a, Qt::AnchorTop);
|
|
1430 |
setAnchor(l, a, Qt::AnchorBottom, b, Qt::AnchorTop);
|
|
1431 |
setAnchor(l, a, Qt::AnchorBottom, c, Qt::AnchorTop);
|
|
1432 |
setAnchor(l, b, Qt::AnchorBottom, l, Qt::AnchorBottom);
|
|
1433 |
setAnchor(l, c, Qt::AnchorBottom, l, Qt::AnchorBottom);
|
|
1434 |
|
|
1435 |
p->setLayout(l);
|
|
1436 |
|
|
1437 |
QCOMPARE(layoutHasConflict(l), true);
|
|
1438 |
|
|
1439 |
a->setMinimumSize(QSizeF(29,10));
|
|
1440 |
QCOMPARE(layoutHasConflict(l), false);
|
|
1441 |
|
|
1442 |
a->setMinimumSize(QSizeF(30,10));
|
|
1443 |
QCOMPARE(layoutHasConflict(l), false);
|
|
1444 |
|
|
1445 |
delete p;
|
|
1446 |
}
|
|
1447 |
|
|
1448 |
void tst_QGraphicsAnchorLayout::expandingSequence()
|
|
1449 |
{
|
|
1450 |
QSizeF min(10, 10);
|
|
1451 |
QSizeF pref(50, 10);
|
|
1452 |
QSizeF max(100, 10);
|
|
1453 |
|
|
1454 |
QGraphicsWidget *a = createItem(min, pref, max, "a");
|
|
1455 |
QGraphicsWidget *b = createItem(min, pref, max, "b");
|
|
1456 |
|
|
1457 |
b->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
|
1458 |
|
|
1459 |
QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout;
|
|
1460 |
l->setContentsMargins(0, 0, 0, 0);
|
|
1461 |
|
|
1462 |
// horizontal
|
|
1463 |
setAnchor(l, l, Qt::AnchorLeft, a, Qt::AnchorLeft, 0);
|
|
1464 |
setAnchor(l, a, Qt::AnchorRight, b, Qt::AnchorLeft, 0);
|
|
1465 |
setAnchor(l, b, Qt::AnchorRight, l, Qt::AnchorRight, 0);
|
|
1466 |
|
|
1467 |
// vertical
|
|
1468 |
l->addAnchors(l, a, Qt::Vertical);
|
|
1469 |
l->addAnchors(l, b, Qt::Vertical);
|
|
1470 |
|
|
1471 |
QCOMPARE(l->count(), 2);
|
|
1472 |
|
|
1473 |
QGraphicsWidget p;
|
|
1474 |
p.setLayout(l);
|
|
1475 |
|
|
1476 |
QSizeF layoutMinimumSize = l->effectiveSizeHint(Qt::MinimumSize);
|
|
1477 |
QCOMPARE(layoutMinimumSize.width(), qreal(20));
|
|
1478 |
|
|
1479 |
QSizeF layoutExpandedSize(pref.width() + max.width(), layoutMinimumSize.height());
|
|
1480 |
p.resize(layoutExpandedSize);
|
|
1481 |
|
|
1482 |
QCOMPARE(a->geometry().size(), pref);
|
|
1483 |
QCOMPARE(b->geometry().size(), max);
|
|
1484 |
|
|
1485 |
QSizeF layoutMaximumSize = l->effectiveSizeHint(Qt::MaximumSize);
|
|
1486 |
QCOMPARE(layoutMaximumSize.width(), qreal(200));
|
|
1487 |
|
|
1488 |
if (hasSimplification) {
|
|
1489 |
QVERIFY(!usedSimplex(l, Qt::Horizontal));
|
|
1490 |
QVERIFY(!usedSimplex(l, Qt::Vertical));
|
|
1491 |
}
|
|
1492 |
}
|
|
1493 |
|
|
1494 |
void tst_QGraphicsAnchorLayout::expandingSequenceFairDistribution()
|
|
1495 |
{
|
|
1496 |
QSizeF min(10, 10);
|
|
1497 |
QSizeF pref(50, 10);
|
|
1498 |
QSizeF max(100, 10);
|
|
1499 |
|
|
1500 |
QGraphicsWidget *a = createItem(min, pref, max, "a");
|
|
1501 |
QGraphicsWidget *b = createItem(min, pref, max, "b");
|
|
1502 |
QGraphicsWidget *c = createItem(min, pref, max, "c");
|
|
1503 |
QGraphicsWidget *d = createItem(min, pref, max, "d");
|
|
1504 |
|
|
1505 |
b->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
|
1506 |
d->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
|
1507 |
|
|
1508 |
QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout;
|
|
1509 |
l->setContentsMargins(0, 0, 0, 0);
|
|
1510 |
|
|
1511 |
// horizontal
|
|
1512 |
setAnchor(l, l, Qt::AnchorLeft, a, Qt::AnchorLeft, 0);
|
|
1513 |
setAnchor(l, a, Qt::AnchorRight, b, Qt::AnchorLeft, 0);
|
|
1514 |
setAnchor(l, b, Qt::AnchorRight, c, Qt::AnchorLeft, 0);
|
|
1515 |
setAnchor(l, c, Qt::AnchorRight, d, Qt::AnchorLeft, 0);
|
|
1516 |
setAnchor(l, d, Qt::AnchorRight, l, Qt::AnchorRight, 0);
|
|
1517 |
|
|
1518 |
// vertical
|
|
1519 |
l->addAnchors(l, a, Qt::Vertical);
|
|
1520 |
l->addAnchors(l, b, Qt::Vertical);
|
|
1521 |
l->addAnchors(l, c, Qt::Vertical);
|
|
1522 |
l->addAnchors(l, d, Qt::Vertical);
|
|
1523 |
|
|
1524 |
QCOMPARE(l->count(), 4);
|
|
1525 |
|
|
1526 |
QGraphicsWidget p;
|
|
1527 |
p.setLayout(l);
|
|
1528 |
|
|
1529 |
QSizeF layoutMinimumSize = l->effectiveSizeHint(Qt::MinimumSize);
|
|
1530 |
QCOMPARE(layoutMinimumSize.width(), qreal(40));
|
|
1531 |
|
|
1532 |
QSizeF layoutPartialExpandedSize((2 * pref.width()) + (2 * (pref.width() + 10)),
|
|
1533 |
layoutMinimumSize.height());
|
|
1534 |
p.resize(layoutPartialExpandedSize);
|
|
1535 |
|
|
1536 |
QCOMPARE(a->geometry().size(), pref);
|
|
1537 |
QCOMPARE(b->geometry().size(), pref + QSizeF(10, 0));
|
|
1538 |
QCOMPARE(c->geometry().size(), pref);
|
|
1539 |
QCOMPARE(d->geometry().size(), pref + QSizeF(10, 0));
|
|
1540 |
|
|
1541 |
QSizeF layoutExpandedSize((2 * pref.width()) + (2 * max.width()),
|
|
1542 |
layoutMinimumSize.height());
|
|
1543 |
p.resize(layoutExpandedSize);
|
|
1544 |
|
|
1545 |
QCOMPARE(a->geometry().size(), pref);
|
|
1546 |
QCOMPARE(b->geometry().size(), max);
|
|
1547 |
QCOMPARE(c->geometry().size(), pref);
|
|
1548 |
QCOMPARE(d->geometry().size(), max);
|
|
1549 |
|
|
1550 |
QSizeF layoutMaximumSize = l->effectiveSizeHint(Qt::MaximumSize);
|
|
1551 |
QCOMPARE(layoutMaximumSize.width(), qreal(400));
|
|
1552 |
|
|
1553 |
if (hasSimplification) {
|
|
1554 |
QVERIFY(!usedSimplex(l, Qt::Horizontal));
|
|
1555 |
QVERIFY(!usedSimplex(l, Qt::Vertical));
|
|
1556 |
}
|
|
1557 |
|
|
1558 |
// Now we change D to have more "room for growth" from its preferred size
|
|
1559 |
// to its maximum size. We expect a proportional fair distribution. Note that
|
|
1560 |
// this seems to not conform with what QGraphicsLinearLayout does.
|
|
1561 |
d->setMaximumSize(QSizeF(150, 10));
|
|
1562 |
|
|
1563 |
QSizeF newLayoutExpandedSize((2 * pref.width()) + (max.width() + 150),
|
|
1564 |
layoutMinimumSize.height());
|
|
1565 |
p.resize(newLayoutExpandedSize);
|
|
1566 |
|
|
1567 |
QCOMPARE(a->geometry().size(), pref);
|
|
1568 |
QCOMPARE(b->geometry().size(), max);
|
|
1569 |
QCOMPARE(c->geometry().size(), pref);
|
|
1570 |
QCOMPARE(d->geometry().size(), QSizeF(150, 10));
|
|
1571 |
|
|
1572 |
QSizeF newLayoutPartialExpandedSize((4 * pref.width()) + 75,
|
|
1573 |
layoutMinimumSize.height());
|
|
1574 |
p.resize(newLayoutPartialExpandedSize);
|
|
1575 |
|
|
1576 |
QCOMPARE(a->geometry().size(), pref);
|
|
1577 |
QCOMPARE(b->geometry().size(), pref + QSizeF(25, 0));
|
|
1578 |
QCOMPARE(c->geometry().size(), pref);
|
|
1579 |
QCOMPARE(d->geometry().size(), pref + QSizeF(50, 0));
|
|
1580 |
|
|
1581 |
if (hasSimplification) {
|
|
1582 |
QVERIFY(!usedSimplex(l, Qt::Horizontal));
|
|
1583 |
QVERIFY(!usedSimplex(l, Qt::Vertical));
|
|
1584 |
}
|
|
1585 |
}
|
|
1586 |
|
|
1587 |
void tst_QGraphicsAnchorLayout::expandingParallel()
|
|
1588 |
{
|
|
1589 |
QSizeF min(10, 10);
|
|
1590 |
QSizeF pref(50, 10);
|
|
1591 |
QSizeF max(100, 10);
|
|
1592 |
QSizeF max2(100, 50);
|
|
1593 |
|
|
1594 |
QGraphicsWidget *a = createItem(min, pref, max, "a");
|
|
1595 |
QGraphicsWidget *b = createItem(min, pref, max, "b");
|
|
1596 |
QGraphicsWidget *c = createItem(min, pref, max2, "c");
|
|
1597 |
|
|
1598 |
b->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
|
1599 |
|
|
1600 |
QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout;
|
|
1601 |
l->setContentsMargins(0, 0, 0, 0);
|
|
1602 |
|
|
1603 |
// horizontal
|
|
1604 |
setAnchor(l, l, Qt::AnchorLeft, a, Qt::AnchorLeft, 0);
|
|
1605 |
setAnchor(l, l, Qt::AnchorLeft, b, Qt::AnchorLeft, 0);
|
|
1606 |
|
|
1607 |
setAnchor(l, a, Qt::AnchorRight, c, Qt::AnchorLeft, 0);
|
|
1608 |
setAnchor(l, b, Qt::AnchorRight, c, Qt::AnchorLeft, 0);
|
|
1609 |
|
|
1610 |
setAnchor(l, c, Qt::AnchorRight, l, Qt::AnchorRight, 0);
|
|
1611 |
|
|
1612 |
// vertical
|
|
1613 |
l->addAnchors(l, c, Qt::Vertical);
|
|
1614 |
setAnchor(l, l, Qt::AnchorTop, a, Qt::AnchorTop, 0);
|
|
1615 |
setAnchor(l, a, Qt::AnchorBottom, c, Qt::AnchorVerticalCenter, 0);
|
|
1616 |
setAnchor(l, b, Qt::AnchorTop, c, Qt::AnchorVerticalCenter, 0);
|
|
1617 |
setAnchor(l, b, Qt::AnchorBottom, l, Qt::AnchorBottom, 0);
|
|
1618 |
|
|
1619 |
QCOMPARE(l->count(), 3);
|
|
1620 |
|
|
1621 |
QGraphicsWidget p;
|
|
1622 |
p.setLayout(l);
|
|
1623 |
|
|
1624 |
QSizeF layoutMinimumSize = l->effectiveSizeHint(Qt::MinimumSize);
|
|
1625 |
QCOMPARE(layoutMinimumSize.width(), qreal(20));
|
|
1626 |
|
|
1627 |
QSizeF layoutExpandedSize(pref.width() + max.width(), layoutMinimumSize.height());
|
|
1628 |
p.resize(layoutExpandedSize);
|
|
1629 |
|
|
1630 |
QCOMPARE(a->geometry().size(), max);
|
|
1631 |
QCOMPARE(b->geometry().size(), max);
|
|
1632 |
QCOMPARE(c->geometry().size(), QSizeF(pref.width(), 20));
|
|
1633 |
|
|
1634 |
QSizeF layoutMaximumSize = l->effectiveSizeHint(Qt::MaximumSize);
|
|
1635 |
QCOMPARE(layoutMaximumSize.width(), qreal(200));
|
|
1636 |
|
|
1637 |
//
|
|
1638 |
// Change the parallel connection to a paralell connection of b with a center...
|
|
1639 |
//
|
|
1640 |
QGraphicsAnchor *anchor = l->anchor(b, Qt::AnchorRight, c, Qt::AnchorLeft);
|
|
1641 |
delete anchor;
|
|
1642 |
setAnchor(l, b, Qt::AnchorRight, a, Qt::AnchorHorizontalCenter, 0);
|
|
1643 |
a->setMaximumSize(max + QSizeF(100, 0));
|
|
1644 |
|
|
1645 |
QSizeF newLayoutMinimumSize = l->effectiveSizeHint(Qt::MinimumSize);
|
|
1646 |
QCOMPARE(newLayoutMinimumSize.width(), qreal(30));
|
|
1647 |
|
|
1648 |
QSizeF newLayoutExpandedSize = layoutExpandedSize + QSizeF(100, 0);
|
|
1649 |
p.resize(newLayoutExpandedSize);
|
|
1650 |
|
|
1651 |
QCOMPARE(a->geometry().size(), max + QSizeF(100, 0));
|
|
1652 |
QCOMPARE(b->geometry().size(), max);
|
|
1653 |
QCOMPARE(c->geometry().size(), QSizeF(pref.width(), 20));
|
|
1654 |
|
|
1655 |
QSizeF newLayoutMaximumSize = l->effectiveSizeHint(Qt::MaximumSize);
|
|
1656 |
QCOMPARE(newLayoutMaximumSize.width(), qreal(300));
|
|
1657 |
}
|
|
1658 |
|
|
1659 |
void tst_QGraphicsAnchorLayout::floatConflict()
|
|
1660 |
{
|
|
1661 |
QGraphicsWidget *a = createItem(QSizeF(80,10), QSizeF(90,10), QSizeF(100,10), "a");
|
|
1662 |
QGraphicsWidget *b = createItem(QSizeF(80,10), QSizeF(90,10), QSizeF(100,10), "b");
|
|
1663 |
|
|
1664 |
QGraphicsAnchorLayout *l;
|
|
1665 |
QGraphicsWidget *p = new QGraphicsWidget(0, Qt::Window);
|
|
1666 |
|
|
1667 |
l = new QGraphicsAnchorLayout;
|
|
1668 |
l->setContentsMargins(0, 0, 0, 0);
|
|
1669 |
|
|
1670 |
p->setLayout(l);
|
|
1671 |
|
|
1672 |
// horizontal
|
|
1673 |
// with this anchor we have two floating items
|
|
1674 |
setAnchor(l, a, Qt::AnchorRight, b, Qt::AnchorLeft);
|
|
1675 |
|
|
1676 |
// Just checking if the layout is handling well the removal of floating items
|
|
1677 |
delete l->anchor(a, Qt::AnchorRight, b, Qt::AnchorLeft);
|
|
1678 |
QCOMPARE(l->count(), 0);
|
|
1679 |
QCOMPARE(layoutHasConflict(l), false);
|
|
1680 |
|
|
1681 |
// setting back the same anchor
|
|
1682 |
setAnchor(l, a, Qt::AnchorRight, b, Qt::AnchorLeft);
|
|
1683 |
|
|
1684 |
// We don't support floating items but they should be counted as if they are in the layout
|
|
1685 |
QCOMPARE(l->count(), 2);
|
|
1686 |
// Although, we have an invalid situation
|
|
1687 |
QCOMPARE(layoutHasConflict(l), true);
|
|
1688 |
|
|
1689 |
// Semi-floats are supported
|
|
1690 |
setAnchor(l, a, Qt::AnchorLeft, l, Qt::AnchorLeft);
|
|
1691 |
QCOMPARE(l->count(), 2);
|
|
1692 |
|
|
1693 |
// Vertically the layout has floating items. Therefore, we have a conflict
|
|
1694 |
QCOMPARE(layoutHasConflict(l), true);
|
|
1695 |
|
|
1696 |
// No more floating items
|
|
1697 |
setAnchor(l, b, Qt::AnchorRight, l, Qt::AnchorRight);
|
|
1698 |
setAnchor(l, a, Qt::AnchorTop, l, Qt::AnchorTop);
|
|
1699 |
setAnchor(l, a, Qt::AnchorBottom, l, Qt::AnchorBottom);
|
|
1700 |
setAnchor(l, b, Qt::AnchorTop, l, Qt::AnchorTop);
|
|
1701 |
setAnchor(l, b, Qt::AnchorBottom, l, Qt::AnchorBottom);
|
|
1702 |
QCOMPARE(layoutHasConflict(l), false);
|
|
1703 |
|
|
1704 |
delete p;
|
|
1705 |
}
|
|
1706 |
|
|
1707 |
void tst_QGraphicsAnchorLayout::infiniteMaxSizes()
|
|
1708 |
{
|
|
1709 |
QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout;
|
|
1710 |
l->setContentsMargins(0, 0, 0, 0);
|
|
1711 |
l->setSpacing(0);
|
|
1712 |
|
|
1713 |
QSizeF min(10, 10);
|
|
1714 |
QSizeF pref(50, 10);
|
|
1715 |
QSizeF max(QWIDGETSIZE_MAX, 10);
|
|
1716 |
|
|
1717 |
QGraphicsWidget *a = createItem(min, pref, max, "a");
|
|
1718 |
QGraphicsWidget *b = createItem(min, pref, max, "b");
|
|
1719 |
QGraphicsWidget *c = createItem(min, pref, max, "c");
|
|
1720 |
QGraphicsWidget *d = createItem(min, pref, max, "d");
|
|
1721 |
|
|
1722 |
//<!-- Trunk -->
|
|
1723 |
setAnchor(l, l, Qt::AnchorLeft, a, Qt::AnchorLeft, 0);
|
|
1724 |
setAnchor(l, a, Qt::AnchorRight, b, Qt::AnchorLeft, 0);
|
|
1725 |
setAnchor(l, b, Qt::AnchorRight, c, Qt::AnchorLeft, 0);
|
|
1726 |
setAnchor(l, c, Qt::AnchorRight, d, Qt::AnchorLeft, 0);
|
|
1727 |
setAnchor(l, d, Qt::AnchorRight, l, Qt::AnchorRight, 0);
|
|
1728 |
|
|
1729 |
a->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
|
1730 |
c->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
|
1731 |
|
|
1732 |
QGraphicsWidget p;
|
|
1733 |
p.setLayout(l);
|
|
1734 |
|
|
1735 |
p.resize(200, 10);
|
|
1736 |
QCOMPARE(a->geometry(), QRectF(0, 0, 50, 10));
|
|
1737 |
QCOMPARE(b->geometry(), QRectF(50, 0, 50, 10));
|
|
1738 |
QCOMPARE(c->geometry(), QRectF(100, 0, 50, 10));
|
|
1739 |
QCOMPARE(d->geometry(), QRectF(150, 0, 50, 10));
|
|
1740 |
|
|
1741 |
if (!hasSimplification)
|
|
1742 |
QEXPECT_FAIL("", "Without simplification there is no fair distribution.", Abort);
|
|
1743 |
|
|
1744 |
p.resize(1000, 10);
|
|
1745 |
QCOMPARE(a->geometry(), QRectF(0, 0, 450, 10));
|
|
1746 |
QCOMPARE(b->geometry(), QRectF(450, 0, 50, 10));
|
|
1747 |
QCOMPARE(c->geometry(), QRectF(500, 0, 450, 10));
|
|
1748 |
QCOMPARE(d->geometry(), QRectF(950, 0, 50, 10));
|
|
1749 |
|
|
1750 |
qreal expMaxSize = (QWIDGETSIZE_MAX - 100.0) / 2;
|
|
1751 |
p.resize(QWIDGETSIZE_MAX, 10);
|
|
1752 |
QCOMPARE(a->geometry(), QRectF(0, 0, expMaxSize, 10));
|
|
1753 |
QCOMPARE(b->geometry(), QRectF(expMaxSize, 0, 50, 10));
|
|
1754 |
QCOMPARE(c->geometry(), QRectF(expMaxSize + 50, 0, expMaxSize, 10));
|
|
1755 |
QCOMPARE(d->geometry(), QRectF(QWIDGETSIZE_MAX - 50, 0, 50, 10));
|
|
1756 |
}
|
|
1757 |
|
|
1758 |
QTEST_MAIN(tst_QGraphicsAnchorLayout)
|
|
1759 |
#include "tst_qgraphicsanchorlayout.moc"
|