author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 02 Feb 2010 00:43:10 +0200 | |
changeset 3 | 41300fa6a67c |
parent 0 | 1918ee327afb |
child 4 | 3b1da2848fc7 |
permissions | -rw-r--r-- |
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> |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
48 |
#include <QtGui/qwindowsstyle.h> |
0 | 49 |
|
50 |
class tst_QGraphicsAnchorLayout : public QObject { |
|
51 |
Q_OBJECT; |
|
52 |
||
53 |
public: |
|
54 |
tst_QGraphicsAnchorLayout() : QObject() { |
|
55 |
hasSimplification = qgetenv("QT_ANCHORLAYOUT_NO_SIMPLIFICATION").isEmpty(); |
|
56 |
} |
|
57 |
||
58 |
private: |
|
59 |
bool hasSimplification; |
|
60 |
||
61 |
private slots: |
|
62 |
void simple(); |
|
63 |
void simple_center(); |
|
64 |
void simple_semifloat(); |
|
65 |
void layoutDirection(); |
|
66 |
void diagonal(); |
|
67 |
void parallel(); |
|
68 |
void parallel2(); |
|
69 |
void snake(); |
|
70 |
void snakeOppositeDirections(); |
|
71 |
void fairDistribution(); |
|
72 |
void fairDistributionOppositeDirections(); |
|
73 |
void proportionalPreferred(); |
|
74 |
void example(); |
|
75 |
void setSpacing(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
76 |
void styleDefaults(); |
0 | 77 |
void hardComplexS60(); |
78 |
void stability(); |
|
79 |
void delete_anchor(); |
|
80 |
void conflicts(); |
|
81 |
void sizePolicy(); |
|
82 |
void floatConflict(); |
|
83 |
void infiniteMaxSizes(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
84 |
void simplifiableUnfeasible(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
85 |
void simplificationVsOrder(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
86 |
void parallelSimplificationOfCenter(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
87 |
void simplificationVsRedundance(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
88 |
void spacingPersistency(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
89 |
void snakeParallelWithLayout(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
90 |
void parallelToHalfLayout(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
91 |
void globalSpacing(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
92 |
void graphicsAnchorHandling(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
93 |
void invalidHierarchyCheck(); |
0 | 94 |
}; |
95 |
||
96 |
class RectWidget : public QGraphicsWidget |
|
97 |
{ |
|
98 |
public: |
|
99 |
RectWidget(QGraphicsItem *parent = 0) : QGraphicsWidget(parent){} |
|
100 |
||
101 |
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
102 |
{ |
|
103 |
Q_UNUSED(option); |
|
104 |
Q_UNUSED(widget); |
|
105 |
painter->drawRoundRect(rect()); |
|
106 |
painter->drawLine(rect().topLeft(), rect().bottomRight()); |
|
107 |
painter->drawLine(rect().bottomLeft(), rect().topRight()); |
|
108 |
} |
|
109 |
}; |
|
110 |
||
111 |
static QGraphicsWidget *createItem(const QSizeF &minimum = QSizeF(100.0, 100.0), |
|
112 |
const QSizeF &preferred = QSize(150.0, 100.0), |
|
113 |
const QSizeF &maximum = QSizeF(200.0, 100.0), |
|
114 |
const QString &name = QString()) |
|
115 |
{ |
|
116 |
QGraphicsWidget *w = new RectWidget; |
|
117 |
w->setMinimumSize(minimum); |
|
118 |
w->setPreferredSize(preferred); |
|
119 |
w->setMaximumSize(maximum); |
|
120 |
w->setData(0, name); |
|
121 |
return w; |
|
122 |
} |
|
123 |
||
124 |
static void setAnchor(QGraphicsAnchorLayout *l, |
|
125 |
QGraphicsLayoutItem *firstItem, |
|
126 |
Qt::AnchorPoint firstEdge, |
|
127 |
QGraphicsLayoutItem *secondItem, |
|
128 |
Qt::AnchorPoint secondEdge, |
|
129 |
qreal spacing = 0) |
|
130 |
{ |
|
131 |
QGraphicsAnchor *anchor = l->addAnchor(firstItem, firstEdge, secondItem, secondEdge); |
|
132 |
anchor->setSpacing(spacing); |
|
133 |
} |
|
134 |
||
135 |
static bool checkReverseDirection(QGraphicsWidget *w) |
|
136 |
{ |
|
137 |
QGraphicsLayout *l = w->layout(); |
|
138 |
Q_ASSERT(l); |
|
139 |
qreal left, top, right, bottom; |
|
140 |
l->getContentsMargins(&left, &top, &right, &bottom); |
|
141 |
w->setLayoutDirection(Qt::LeftToRight); |
|
142 |
QApplication::processEvents(); |
|
143 |
const QRectF lg = l->geometry(); |
|
144 |
QMap<QGraphicsLayoutItem *, QRectF> geometries; |
|
145 |
for (int i = 0; i < l->count(); ++i) { |
|
146 |
QGraphicsLayoutItem *w = l->itemAt(i); |
|
147 |
geometries.insert(w, w->geometry()); |
|
148 |
} |
|
149 |
w->setLayoutDirection(Qt::RightToLeft); |
|
150 |
QApplication::processEvents(); |
|
151 |
lg.adjusted(+right, +top, -left, -bottom); |
|
152 |
for (int i = 0; i < l->count(); ++i) { |
|
153 |
QGraphicsLayoutItem *w = l->itemAt(i); |
|
154 |
const QRectF rtlGeom = w->geometry(); |
|
155 |
const QRectF ltrGeom = geometries.value(w); |
|
156 |
QRectF expectedGeom = ltrGeom; |
|
157 |
expectedGeom.moveRight(lg.right() - (0 + ltrGeom.left())); |
|
158 |
if (expectedGeom != rtlGeom) { |
|
159 |
qDebug() << "layout->geometry():" << lg |
|
160 |
<< "expected:" << expectedGeom |
|
161 |
<< "actual:" << rtlGeom; |
|
162 |
return false; |
|
163 |
} |
|
164 |
} |
|
165 |
return true; |
|
166 |
} |
|
167 |
||
168 |
static bool layoutHasConflict(QGraphicsAnchorLayout *l) |
|
169 |
{ |
|
170 |
return QGraphicsAnchorLayoutPrivate::get(l)->hasConflicts(); |
|
171 |
} |
|
172 |
||
173 |
static bool usedSimplex(QGraphicsAnchorLayout *l, Qt::Orientation o) |
|
174 |
{ |
|
175 |
QGraphicsAnchorLayoutPrivate::Orientation oo = (o == Qt::Horizontal) ? |
|
176 |
QGraphicsAnchorLayoutPrivate::Horizontal : |
|
177 |
QGraphicsAnchorLayoutPrivate::Vertical; |
|
178 |
||
179 |
return QGraphicsAnchorLayoutPrivate::get(l)->lastCalculationUsedSimplex[oo]; |
|
180 |
} |
|
181 |
||
182 |
void tst_QGraphicsAnchorLayout::simple() |
|
183 |
{ |
|
184 |
QGraphicsWidget *w1 = createItem(); |
|
185 |
QGraphicsWidget *w2 = createItem(); |
|
186 |
||
187 |
QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout; |
|
188 |
l->setContentsMargins(0, 0, 0, 0); |
|
189 |
||
190 |
// Horizontal |
|
191 |
l->addAnchor(l, Qt::AnchorLeft, w1, Qt::AnchorLeft); |
|
192 |
l->addAnchor(w1, Qt::AnchorRight, w2, Qt::AnchorLeft); |
|
193 |
l->addAnchor(w2, Qt::AnchorRight, l, Qt::AnchorRight); |
|
194 |
||
195 |
// Vertical |
|
196 |
l->addAnchors(l, w1, Qt::Vertical); |
|
197 |
l->addAnchors(l, w2, Qt::Vertical); |
|
198 |
||
199 |
QCOMPARE(l->count(), 2); |
|
200 |
||
201 |
QGraphicsWidget p; |
|
202 |
p.setLayout(l); |
|
203 |
p.adjustSize(); |
|
204 |
||
205 |
if (hasSimplification) { |
|
206 |
QVERIFY(!usedSimplex(l, Qt::Horizontal)); |
|
207 |
QVERIFY(!usedSimplex(l, Qt::Vertical)); |
|
208 |
} |
|
209 |
} |
|
210 |
||
211 |
void tst_QGraphicsAnchorLayout::simple_center() |
|
212 |
{ |
|
213 |
QSizeF min(10, 10); |
|
214 |
QSizeF pref(50, 10); |
|
215 |
QSizeF max(100, 10); |
|
216 |
||
217 |
QGraphicsWidget *a = createItem(min, pref, max, "a"); |
|
218 |
QGraphicsWidget *b = createItem(min, pref, max, "b"); |
|
219 |
QGraphicsWidget *c = createItem(min, pref, max, "c"); |
|
220 |
||
221 |
QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout; |
|
222 |
l->setContentsMargins(0, 0, 0, 0); |
|
223 |
// horizontal |
|
224 |
setAnchor(l, l, Qt::AnchorLeft, a, Qt::AnchorLeft, 0); |
|
225 |
setAnchor(l, a, Qt::AnchorRight, b, Qt::AnchorLeft, 0); |
|
226 |
setAnchor(l, b, Qt::AnchorRight, l, Qt::AnchorRight, 0); |
|
227 |
setAnchor(l, a, Qt::AnchorHorizontalCenter, c, Qt::AnchorLeft, 0); |
|
228 |
setAnchor(l, c, Qt::AnchorRight, b, Qt::AnchorHorizontalCenter, 0); |
|
229 |
||
230 |
// vertical |
|
231 |
setAnchor(l, l, Qt::AnchorTop, a, Qt::AnchorTop, 0); |
|
232 |
setAnchor(l, l, Qt::AnchorTop, b, Qt::AnchorTop, 0); |
|
233 |
setAnchor(l, a, Qt::AnchorBottom, c, Qt::AnchorTop, 0); |
|
234 |
setAnchor(l, b, Qt::AnchorBottom, c, Qt::AnchorTop, 0); |
|
235 |
setAnchor(l, c, Qt::AnchorBottom, l, Qt::AnchorBottom, 0); |
|
236 |
||
237 |
QCOMPARE(l->count(), 3); |
|
238 |
||
239 |
QGraphicsWidget *p = new QGraphicsWidget(0, Qt::Window); |
|
240 |
p->setLayout(l); |
|
241 |
||
242 |
QSizeF layoutMinimumSize = l->effectiveSizeHint(Qt::MinimumSize); |
|
243 |
QCOMPARE(layoutMinimumSize, QSizeF(20, 20)); |
|
244 |
||
245 |
QSizeF layoutMaximumSize = l->effectiveSizeHint(Qt::MaximumSize); |
|
246 |
QCOMPARE(layoutMaximumSize, QSizeF(200, 20)); |
|
247 |
||
248 |
if (hasSimplification) { |
|
249 |
QVERIFY(usedSimplex(l, Qt::Horizontal)); |
|
250 |
QVERIFY(!usedSimplex(l, Qt::Vertical)); |
|
251 |
} |
|
252 |
||
253 |
delete p; |
|
254 |
} |
|
255 |
||
256 |
void tst_QGraphicsAnchorLayout::simple_semifloat() |
|
257 |
{ |
|
258 |
// Useful for testing simplification between A_left and B_left. |
|
259 |
// Unfortunately the only way to really test that now is to manually inspect the |
|
260 |
// simplified graph. |
|
261 |
QSizeF min(10, 10); |
|
262 |
QSizeF pref(50, 10); |
|
263 |
QSizeF max(100, 10); |
|
264 |
||
265 |
QGraphicsWidget *A = createItem(min, pref, max, "A"); |
|
266 |
QGraphicsWidget *B = createItem(min, pref, max, "B"); |
|
267 |
QGraphicsWidget *a = createItem(min, pref, max, "a"); |
|
268 |
QGraphicsWidget *b = createItem(min, pref, max, "b"); |
|
269 |
||
270 |
QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout; |
|
271 |
l->setContentsMargins(0, 0, 0, 0); |
|
272 |
||
273 |
// horizontal |
|
274 |
setAnchor(l, l, Qt::AnchorLeft, A, Qt::AnchorLeft, 0); |
|
275 |
setAnchor(l, A, Qt::AnchorRight, B, Qt::AnchorLeft, 0); |
|
276 |
setAnchor(l, B, Qt::AnchorRight, l, Qt::AnchorRight, 0); |
|
277 |
||
278 |
setAnchor(l, A, Qt::AnchorLeft, a, Qt::AnchorLeft, 0); |
|
279 |
setAnchor(l, B, Qt::AnchorLeft, b, Qt::AnchorLeft, 0); |
|
280 |
||
281 |
// vertical |
|
282 |
setAnchor(l, l, Qt::AnchorTop, A, Qt::AnchorTop, 0); |
|
283 |
setAnchor(l, l, Qt::AnchorTop, B, Qt::AnchorTop, 0); |
|
284 |
setAnchor(l, A, Qt::AnchorBottom, a, Qt::AnchorTop, 0); |
|
285 |
setAnchor(l, B, Qt::AnchorBottom, b, Qt::AnchorTop, 0); |
|
286 |
setAnchor(l, a, Qt::AnchorBottom, l, Qt::AnchorBottom, 0); |
|
287 |
setAnchor(l, b, Qt::AnchorBottom, l, Qt::AnchorBottom, 0); |
|
288 |
||
289 |
QCOMPARE(l->count(), 4); |
|
290 |
||
291 |
QGraphicsWidget *p = new QGraphicsWidget(0, Qt::Window); |
|
292 |
p->setLayout(l); |
|
293 |
||
294 |
QSizeF layoutMinimumSize = l->effectiveSizeHint(Qt::MinimumSize); |
|
295 |
QCOMPARE(layoutMinimumSize, QSizeF(20, 20)); |
|
296 |
||
297 |
QCOMPARE(l->effectiveSizeHint(Qt::PreferredSize), QSizeF(100, 20)); |
|
298 |
||
299 |
QSizeF layoutMaximumSize = l->effectiveSizeHint(Qt::MaximumSize); |
|
300 |
QCOMPARE(layoutMaximumSize, QSizeF(200, 20)); |
|
301 |
||
302 |
delete p; |
|
303 |
} |
|
304 |
||
305 |
void tst_QGraphicsAnchorLayout::layoutDirection() |
|
306 |
{ |
|
307 |
QSizeF min(10, 10); |
|
308 |
QSizeF pref(50, 10); |
|
309 |
QSizeF max(100, 10); |
|
310 |
||
311 |
QGraphicsWidget *a = createItem(min, pref, max, "a"); |
|
312 |
QGraphicsWidget *b = createItem(min, pref, max, "b"); |
|
313 |
QGraphicsWidget *c = createItem(min, pref, QSizeF(100, 20), "c"); |
|
314 |
||
315 |
a->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); |
|
316 |
b->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); |
|
317 |
c->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); |
|
318 |
||
319 |
||
320 |
QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout; |
|
321 |
l->setContentsMargins(0, 5, 10, 15); |
|
322 |
// horizontal |
|
323 |
setAnchor(l, l, Qt::AnchorLeft, a, Qt::AnchorLeft, 0); |
|
324 |
setAnchor(l, a, Qt::AnchorRight, b, Qt::AnchorLeft, 0); |
|
325 |
setAnchor(l, b, Qt::AnchorRight, l, Qt::AnchorRight, 0); |
|
326 |
setAnchor(l, a, Qt::AnchorHorizontalCenter, c, Qt::AnchorLeft, 0); |
|
327 |
setAnchor(l, c, Qt::AnchorRight, b, Qt::AnchorHorizontalCenter, 0); |
|
328 |
||
329 |
// vertical |
|
330 |
setAnchor(l, l, Qt::AnchorTop, a, Qt::AnchorTop, 0); |
|
331 |
setAnchor(l, l, Qt::AnchorTop, b, Qt::AnchorTop, 0); |
|
332 |
setAnchor(l, a, Qt::AnchorBottom, c, Qt::AnchorTop, 0); |
|
333 |
setAnchor(l, b, Qt::AnchorBottom, c, Qt::AnchorTop, 0); |
|
334 |
setAnchor(l, c, Qt::AnchorBottom, l, Qt::AnchorBottom, 0); |
|
335 |
||
336 |
QCOMPARE(l->count(), 3); |
|
337 |
||
338 |
QGraphicsWidget *p = new QGraphicsWidget(0, Qt::Window); |
|
339 |
p->setLayoutDirection(Qt::LeftToRight); |
|
340 |
p->setLayout(l); |
|
341 |
||
342 |
QGraphicsScene scene; |
|
343 |
QGraphicsView *view = new QGraphicsView(&scene); |
|
344 |
scene.addItem(p); |
|
345 |
p->show(); |
|
346 |
view->show(); |
|
347 |
||
348 |
QCOMPARE(checkReverseDirection(p), true); |
|
349 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
350 |
if (hasSimplification) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
351 |
QVERIFY(usedSimplex(l, Qt::Horizontal)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
352 |
QVERIFY(!usedSimplex(l, Qt::Vertical)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
353 |
} |
0 | 354 |
|
355 |
delete p; |
|
356 |
delete view; |
|
357 |
} |
|
358 |
||
359 |
void tst_QGraphicsAnchorLayout::diagonal() |
|
360 |
{ |
|
361 |
QSizeF min(10, 100); |
|
362 |
QSizeF pref(70, 100); |
|
363 |
QSizeF max(100, 100); |
|
364 |
||
365 |
QGraphicsWidget *a = createItem(min, pref, max, "A"); |
|
366 |
QGraphicsWidget *b = createItem(min, pref, max, "B"); |
|
367 |
QGraphicsWidget *c = createItem(min, pref, max, "C"); |
|
368 |
QGraphicsWidget *d = createItem(min, pref, max, "D"); |
|
369 |
QGraphicsWidget *e = createItem(min, pref, max, "E"); |
|
370 |
||
371 |
QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout; |
|
372 |
l->setContentsMargins(0, 0, 0, 0); |
|
373 |
l->setSpacing(0); |
|
374 |
||
375 |
// vertical |
|
376 |
l->addAnchor(a, Qt::AnchorTop, l, Qt::AnchorTop); |
|
377 |
l->addAnchor(b, Qt::AnchorTop, l, Qt::AnchorTop); |
|
378 |
l->addAnchor(c, Qt::AnchorTop, a, Qt::AnchorBottom); |
|
379 |
l->addAnchor(c, Qt::AnchorTop, b, Qt::AnchorBottom); |
|
380 |
l->addAnchor(c, Qt::AnchorBottom, d, Qt::AnchorTop); |
|
381 |
l->addAnchor(c, Qt::AnchorBottom, e, Qt::AnchorTop); |
|
382 |
l->addAnchor(d, Qt::AnchorBottom, l, Qt::AnchorBottom); |
|
383 |
l->addAnchor(e, Qt::AnchorBottom, l, Qt::AnchorBottom); |
|
384 |
||
385 |
// horizontal |
|
386 |
l->addAnchor(l, Qt::AnchorLeft, a, Qt::AnchorLeft); |
|
387 |
l->addAnchor(l, Qt::AnchorLeft, d, Qt::AnchorLeft); |
|
388 |
l->addAnchor(a, Qt::AnchorRight, b, Qt::AnchorLeft); |
|
389 |
||
390 |
l->addAnchor(a, Qt::AnchorRight, c, Qt::AnchorLeft); |
|
391 |
l->addAnchor(c, Qt::AnchorRight, e, Qt::AnchorLeft); |
|
392 |
||
393 |
l->addAnchor(b, Qt::AnchorRight, l, Qt::AnchorRight); |
|
394 |
l->addAnchor(e, Qt::AnchorRight, l, Qt::AnchorRight); |
|
395 |
l->addAnchor(d, Qt::AnchorRight, e, Qt::AnchorLeft); |
|
396 |
||
397 |
QCOMPARE(l->count(), 5); |
|
398 |
||
399 |
QGraphicsWidget p; |
|
400 |
p.setLayout(l); |
|
401 |
||
402 |
QSizeF layoutMinimumSize = l->effectiveSizeHint(Qt::MinimumSize); |
|
403 |
QSizeF layoutMaximumSize = l->effectiveSizeHint(Qt::MaximumSize); |
|
404 |
QSizeF layoutPreferredSize = l->effectiveSizeHint(Qt::PreferredSize); |
|
405 |
||
406 |
QCOMPARE(layoutMinimumSize, QSizeF(30.0, 300.0)); |
|
407 |
QCOMPARE(layoutPreferredSize, QSizeF(170.0, 300.0)); |
|
408 |
QCOMPARE(layoutMaximumSize, QSizeF(190.0, 300.0)); |
|
409 |
||
410 |
p.resize(layoutMinimumSize); |
|
411 |
QCOMPARE(a->geometry(), QRectF(0.0, 0.0, 10.0, 100.0)); |
|
412 |
QCOMPARE(b->geometry(), QRectF(10.0, 0.0, 20.0, 100.0)); |
|
413 |
QCOMPARE(c->geometry(), QRectF(10.0, 100.0, 10.0, 100.0)); |
|
414 |
QCOMPARE(d->geometry(), QRectF(0.0, 200.0, 20.0, 100.0)); |
|
415 |
QCOMPARE(e->geometry(), QRectF(20.0, 200.0, 10.0, 100.0)); |
|
416 |
QCOMPARE(p.size(), layoutMinimumSize); |
|
417 |
||
418 |
p.resize(layoutPreferredSize); |
|
419 |
QCOMPARE(a->geometry(), QRectF(0.0, 0.0, 70.0, 100.0)); |
|
420 |
QCOMPARE(b->geometry(), QRectF(70.0, 0.0, 100.0, 100.0)); |
|
421 |
QCOMPARE(c->geometry(), QRectF(70.0, 100.0, 30.0, 100.0)); |
|
422 |
QCOMPARE(d->geometry(), QRectF(0.0, 200.0, 100.0, 100.0)); |
|
423 |
QCOMPARE(e->geometry(), QRectF(100.0, 200.0, 70.0, 100.0)); |
|
424 |
QCOMPARE(p.size(), layoutPreferredSize); |
|
425 |
||
426 |
p.resize(layoutMaximumSize); |
|
427 |
QCOMPARE(a->geometry(), QRectF(0.0, 0.0, 90.0, 100.0)); |
|
428 |
QCOMPARE(b->geometry(), QRectF(90.0, 0.0, 100.0, 100.0)); |
|
429 |
QCOMPARE(c->geometry(), QRectF(90.0, 100.0, 10.0, 100.0)); |
|
430 |
QCOMPARE(d->geometry(), QRectF(0.0, 200.0, 100.0, 100.0)); |
|
431 |
QCOMPARE(e->geometry(), QRectF(100.0, 200.0, 90.0, 100.0)); |
|
432 |
QCOMPARE(p.size(), layoutMaximumSize); |
|
433 |
||
434 |
QSizeF testA(175.0, 300.0); |
|
435 |
p.resize(testA); |
|
436 |
QCOMPARE(a->geometry(), QRectF(0.0, 0.0, 75.0, 100.0)); |
|
437 |
QCOMPARE(b->geometry(), QRectF(75.0, 0.0, 100.0, 100.0)); |
|
438 |
QCOMPARE(c->geometry(), QRectF(75.0, 100.0, 25.0, 100.0)); |
|
439 |
QCOMPARE(d->geometry(), QRectF(0.0, 200.0, 100.0, 100.0)); |
|
440 |
QCOMPARE(e->geometry(), QRectF(100.0, 200.0, 75.0, 100.0)); |
|
441 |
QCOMPARE(p.size(), testA); |
|
442 |
||
443 |
if (hasSimplification) { |
|
444 |
QVERIFY(usedSimplex(l, Qt::Horizontal)); |
|
445 |
QVERIFY(!usedSimplex(l, Qt::Vertical)); |
|
446 |
} |
|
447 |
||
448 |
QCOMPARE(checkReverseDirection(&p), true); |
|
449 |
||
450 |
c->setMinimumWidth(300); |
|
451 |
QVERIFY(layoutHasConflict(l)); |
|
452 |
} |
|
453 |
||
454 |
void tst_QGraphicsAnchorLayout::parallel() |
|
455 |
{ |
|
456 |
QGraphicsWidget *a = createItem(QSizeF(100, 100), |
|
457 |
QSizeF(150, 100), |
|
458 |
QSizeF(200, 100), "A"); |
|
459 |
||
460 |
QGraphicsWidget *b = createItem(QSizeF(100, 100), |
|
461 |
QSizeF(150, 100), |
|
462 |
QSizeF(300, 100), "B"); |
|
463 |
||
464 |
QGraphicsWidget *c = createItem(QSizeF(100, 100), |
|
465 |
QSizeF(200, 100), |
|
466 |
QSizeF(350, 100), "C"); |
|
467 |
||
468 |
QGraphicsWidget *d = createItem(QSizeF(100, 100), |
|
469 |
QSizeF(170, 100), |
|
470 |
QSizeF(200, 100), "D"); |
|
471 |
||
472 |
QGraphicsWidget *e = createItem(QSizeF(150, 100), |
|
473 |
QSizeF(150, 100), |
|
474 |
QSizeF(200, 100), "E"); |
|
475 |
||
476 |
QGraphicsWidget *f = createItem(QSizeF(100, 100), |
|
477 |
QSizeF(150, 100), |
|
478 |
QSizeF(200, 100), "F"); |
|
479 |
||
480 |
QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout; |
|
481 |
l->setContentsMargins(0, 0, 0, 0); |
|
482 |
l->setSpacing(0); |
|
483 |
||
484 |
l->addAnchor(l, Qt::AnchorTop, a, Qt::AnchorTop); |
|
485 |
l->addAnchor(a, Qt::AnchorBottom, b, Qt::AnchorTop); |
|
486 |
l->addAnchor(b, Qt::AnchorBottom, c, Qt::AnchorTop); |
|
487 |
l->addAnchor(c, Qt::AnchorBottom, d, Qt::AnchorTop); |
|
488 |
l->addAnchor(d, Qt::AnchorBottom, e, Qt::AnchorTop); |
|
489 |
l->addAnchor(e, Qt::AnchorBottom, f, Qt::AnchorTop); |
|
490 |
l->addAnchor(f, Qt::AnchorBottom, l, Qt::AnchorBottom); |
|
491 |
||
492 |
l->addAnchor(l, Qt::AnchorLeft, a, Qt::AnchorLeft); |
|
493 |
l->addAnchor(a, Qt::AnchorRight, b, Qt::AnchorLeft); |
|
494 |
l->addAnchor(a, Qt::AnchorRight, c, Qt::AnchorLeft); |
|
495 |
l->addAnchor(b, Qt::AnchorRight, d, Qt::AnchorLeft); |
|
496 |
l->addAnchor(b, Qt::AnchorRight, e, Qt::AnchorLeft); |
|
497 |
l->addAnchor(c, Qt::AnchorRight, f, Qt::AnchorLeft); |
|
498 |
l->addAnchor(d, Qt::AnchorRight, f, Qt::AnchorLeft); |
|
499 |
l->addAnchor(e, Qt::AnchorRight, f, Qt::AnchorLeft); |
|
500 |
l->addAnchor(f, Qt::AnchorRight, l, Qt::AnchorRight); |
|
501 |
||
502 |
QCOMPARE(l->count(), 6); |
|
503 |
||
504 |
QGraphicsWidget p; |
|
505 |
p.setLayout(l); |
|
506 |
||
507 |
QSizeF layoutMinimumSize = l->effectiveSizeHint(Qt::MinimumSize); |
|
508 |
QSizeF layoutPreferredSize = l->effectiveSizeHint(Qt::PreferredSize); |
|
509 |
QSizeF layoutMaximumSize = l->effectiveSizeHint(Qt::MaximumSize); |
|
510 |
||
511 |
QCOMPARE(layoutMinimumSize, QSizeF(450, 600)); |
|
512 |
QCOMPARE(layoutPreferredSize, QSizeF(620, 600)); |
|
513 |
QCOMPARE(layoutMaximumSize, QSizeF(750, 600)); |
|
514 |
||
515 |
p.resize(layoutMinimumSize); |
|
516 |
QCOMPARE(a->geometry(), QRectF(0, 0, 100, 100)); |
|
517 |
QCOMPARE(b->geometry(), QRectF(100, 100, 100, 100)); |
|
518 |
QCOMPARE(c->geometry(), QRectF(100, 200, 250, 100)); |
|
519 |
QCOMPARE(d->geometry(), QRectF(200, 300, 150, 100)); |
|
520 |
QCOMPARE(e->geometry(), QRectF(200, 400, 150, 100)); |
|
521 |
QCOMPARE(f->geometry(), QRectF(350, 500, 100, 100)); |
|
522 |
QCOMPARE(p.size(), layoutMinimumSize); |
|
523 |
||
524 |
if (!hasSimplification) |
|
525 |
return; |
|
526 |
||
527 |
p.resize(layoutPreferredSize); |
|
528 |
QCOMPARE(a->geometry(), QRectF(0, 0, 150, 100)); |
|
529 |
QCOMPARE(b->geometry(), QRectF(150, 100, 150, 100)); |
|
530 |
QCOMPARE(c->geometry(), QRectF(150, 200, 320, 100)); |
|
531 |
QCOMPARE(d->geometry(), QRectF(300, 300, 170, 100)); |
|
532 |
QCOMPARE(e->geometry(), QRectF(300, 400, 170, 100)); |
|
533 |
QCOMPARE(f->geometry(), QRectF(470, 500, 150, 100)); |
|
534 |
QCOMPARE(p.size(), layoutPreferredSize); |
|
535 |
||
536 |
// Maximum size depends on simplification / fair distribution |
|
537 |
// Without that, test may or may not pass, depending on the |
|
538 |
// solution found by the solver at runtime. |
|
539 |
p.resize(layoutMaximumSize); |
|
540 |
QCOMPARE(a->geometry(), QRectF(0, 0, 200, 100)); |
|
541 |
QCOMPARE(b->geometry(), QRectF(200, 100, 175, 100)); |
|
542 |
QCOMPARE(c->geometry(), QRectF(200, 200, 350, 100)); |
|
543 |
QCOMPARE(d->geometry(), QRectF(375, 300, 175, 100)); |
|
544 |
QCOMPARE(e->geometry(), QRectF(375, 400, 175, 100)); |
|
545 |
QCOMPARE(f->geometry(), QRectF(550, 500, 200, 100)); |
|
546 |
QCOMPARE(p.size(), layoutMaximumSize); |
|
547 |
||
548 |
QVERIFY(!usedSimplex(l, Qt::Horizontal)); |
|
549 |
QVERIFY(!usedSimplex(l, Qt::Vertical)); |
|
550 |
} |
|
551 |
||
552 |
void tst_QGraphicsAnchorLayout::parallel2() |
|
553 |
{ |
|
554 |
QGraphicsWidget *a = createItem(QSizeF(70.0, 100.0), |
|
555 |
QSizeF(100.0, 100.0), |
|
556 |
QSizeF(200.0, 100.0), "A"); |
|
557 |
||
558 |
QGraphicsWidget *b = createItem(QSizeF(100.0, 100.0), |
|
559 |
QSizeF(150.0, 100.0), |
|
560 |
QSizeF(190.0, 100.0), "B"); |
|
561 |
||
562 |
QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout; |
|
563 |
l->setContentsMargins(0, 0, 0, 0); |
|
564 |
l->setSpacing(0); |
|
565 |
||
566 |
l->addAnchor(l, Qt::AnchorTop, a, Qt::AnchorTop); |
|
567 |
l->addAnchor(a, Qt::AnchorBottom, b, Qt::AnchorTop); |
|
568 |
l->addAnchor(b, Qt::AnchorBottom, l, Qt::AnchorBottom); |
|
569 |
||
570 |
l->addAnchors(l, a, Qt::Horizontal); |
|
571 |
l->addAnchor(l, Qt::AnchorLeft, b, Qt::AnchorLeft); |
|
572 |
l->addAnchor(b, Qt::AnchorRight, a, Qt::AnchorRight); |
|
573 |
||
574 |
QCOMPARE(l->count(), 2); |
|
575 |
||
576 |
QGraphicsWidget p; |
|
577 |
p.setLayout(l); |
|
578 |
||
579 |
QSizeF layoutMinimumSize = l->effectiveSizeHint(Qt::MinimumSize); |
|
580 |
QSizeF layoutPreferredSize = l->effectiveSizeHint(Qt::PreferredSize); |
|
581 |
QSizeF layoutMaximumSize = l->effectiveSizeHint(Qt::MaximumSize); |
|
582 |
||
583 |
QCOMPARE(layoutMinimumSize, QSizeF(100.0, 200.0)); |
|
584 |
QCOMPARE(layoutPreferredSize, QSizeF(150.0, 200.0)); |
|
585 |
QCOMPARE(layoutMaximumSize, QSizeF(190.0, 200.0)); |
|
586 |
||
587 |
p.resize(layoutMinimumSize); |
|
588 |
QCOMPARE(p.size(), layoutMinimumSize); |
|
589 |
||
590 |
p.resize(layoutPreferredSize); |
|
591 |
QCOMPARE(p.size(), layoutPreferredSize); |
|
592 |
||
593 |
p.resize(layoutMaximumSize); |
|
594 |
QCOMPARE(p.size(), layoutMaximumSize); |
|
595 |
||
596 |
if (hasSimplification) { |
|
597 |
QVERIFY(!usedSimplex(l, Qt::Horizontal)); |
|
598 |
QVERIFY(!usedSimplex(l, Qt::Vertical)); |
|
599 |
} |
|
600 |
} |
|
601 |
||
602 |
void tst_QGraphicsAnchorLayout::snake() |
|
603 |
{ |
|
604 |
QGraphicsWidget *a = createItem(QSizeF(50.0, 100.0), |
|
605 |
QSizeF(70.0, 100.0), |
|
606 |
QSizeF(100.0, 100.0), "A"); |
|
607 |
||
608 |
QGraphicsWidget *b = createItem(QSizeF(10.0, 100.0), |
|
609 |
QSizeF(20.0, 100.0), |
|
610 |
QSizeF(40.0, 100.0), "B"); |
|
611 |
||
612 |
QGraphicsWidget *c = createItem(QSizeF(50.0, 100.0), |
|
613 |
QSizeF(70.0, 100.0), |
|
614 |
QSizeF(100.0, 100.0), "C"); |
|
615 |
||
616 |
QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout; |
|
617 |
l->setContentsMargins(0, 0, 0, 0); |
|
618 |
l->setSpacing(0); |
|
619 |
||
620 |
l->addAnchor(l, Qt::AnchorTop, a, Qt::AnchorTop); |
|
621 |
l->addAnchor(a, Qt::AnchorBottom, b, Qt::AnchorTop); |
|
622 |
l->addAnchor(b, Qt::AnchorBottom, c, Qt::AnchorTop); |
|
623 |
l->addAnchor(c, Qt::AnchorBottom, l, Qt::AnchorBottom); |
|
624 |
||
625 |
l->addAnchor(l, Qt::AnchorLeft, a, Qt::AnchorLeft); |
|
626 |
l->addAnchor(a, Qt::AnchorRight, b, Qt::AnchorRight); |
|
627 |
l->addAnchor(b, Qt::AnchorLeft, c, Qt::AnchorLeft); |
|
628 |
l->addAnchor(c, Qt::AnchorRight, l, Qt::AnchorRight); |
|
629 |
||
630 |
QCOMPARE(l->count(), 3); |
|
631 |
||
632 |
QGraphicsWidget p; |
|
633 |
p.setLayout(l); |
|
634 |
||
635 |
QSizeF layoutMinimumSize = l->effectiveSizeHint(Qt::MinimumSize); |
|
636 |
QSizeF layoutMaximumSize = l->effectiveSizeHint(Qt::MaximumSize); |
|
637 |
QSizeF layoutPreferredSize = l->effectiveSizeHint(Qt::PreferredSize); |
|
638 |
||
639 |
QCOMPARE(layoutMinimumSize, QSizeF(60.0, 300.0)); |
|
640 |
QCOMPARE(layoutPreferredSize, QSizeF(120.0, 300.0)); |
|
641 |
QCOMPARE(layoutMaximumSize, QSizeF(190.0, 300.0)); |
|
642 |
||
643 |
p.resize(layoutMinimumSize); |
|
644 |
QCOMPARE(a->geometry(), QRectF(0.0, 0.0, 50.0, 100.0)); |
|
645 |
QCOMPARE(b->geometry(), QRectF(10.0, 100.0, 40.0, 100.0)); |
|
646 |
QCOMPARE(c->geometry(), QRectF(10.0, 200.0, 50.0, 100.0)); |
|
647 |
QCOMPARE(p.size(), layoutMinimumSize); |
|
648 |
||
649 |
p.resize(layoutPreferredSize); |
|
650 |
QCOMPARE(a->geometry(), QRectF(0.0, 0.0, 70.0, 100.0)); |
|
651 |
QCOMPARE(b->geometry(), QRectF(50.0, 100.0, 20.0, 100.0)); |
|
652 |
QCOMPARE(c->geometry(), QRectF(50.0, 200.0, 70.0, 100.0)); |
|
653 |
QCOMPARE(p.size(), layoutPreferredSize); |
|
654 |
||
655 |
p.resize(layoutMaximumSize); |
|
656 |
QCOMPARE(a->geometry(), QRectF(0.0, 0.0, 100.0, 100.0)); |
|
657 |
QCOMPARE(b->geometry(), QRectF(90.0, 100.0, 10.0, 100.0)); |
|
658 |
QCOMPARE(c->geometry(), QRectF(90.0, 200.0, 100.0, 100.0)); |
|
659 |
QCOMPARE(p.size(), layoutMaximumSize); |
|
660 |
||
661 |
QVERIFY(layoutHasConflict(l) == false); |
|
662 |
||
663 |
// Test QSizePolicy::ExpandFlag, it shouldn't change the extreme |
|
664 |
// points of the layout... |
|
665 |
b->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); |
|
666 |
||
667 |
QSizeF newLayoutMinimumSize = l->effectiveSizeHint(Qt::MinimumSize); |
|
668 |
QSizeF newLayoutMaximumSize = l->effectiveSizeHint(Qt::MaximumSize); |
|
669 |
QSizeF newLayoutPreferredSize = l->effectiveSizeHint(Qt::PreferredSize); |
|
670 |
||
671 |
QCOMPARE(layoutMinimumSize, newLayoutMinimumSize); |
|
672 |
QCOMPARE(layoutMaximumSize, newLayoutMaximumSize); |
|
673 |
QCOMPARE(layoutPreferredSize, newLayoutPreferredSize); |
|
674 |
} |
|
675 |
||
676 |
void tst_QGraphicsAnchorLayout::snakeOppositeDirections() |
|
677 |
{ |
|
678 |
QGraphicsWidget *a = createItem(QSizeF(50.0, 100.0), |
|
679 |
QSizeF(70.0, 100.0), |
|
680 |
QSizeF(100.0, 100.0), "A"); |
|
681 |
||
682 |
QGraphicsWidget *b = createItem(QSizeF(10.0, 100.0), |
|
683 |
QSizeF(20.0, 100.0), |
|
684 |
QSizeF(40.0, 100.0), "B"); |
|
685 |
||
686 |
QGraphicsWidget *c = createItem(QSizeF(50.0, 100.0), |
|
687 |
QSizeF(70.0, 100.0), |
|
688 |
QSizeF(100.0, 100.0), "C"); |
|
689 |
||
690 |
QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout; |
|
691 |
l->setContentsMargins(0, 0, 0, 0); |
|
692 |
l->setSpacing(0); |
|
693 |
||
694 |
l->addAnchor(l, Qt::AnchorTop, a, Qt::AnchorTop); |
|
695 |
l->addAnchor(a, Qt::AnchorBottom, b, Qt::AnchorTop); |
|
696 |
l->addAnchor(b, Qt::AnchorBottom, c, Qt::AnchorTop); |
|
697 |
l->addAnchor(c, Qt::AnchorBottom, l, Qt::AnchorBottom); |
|
698 |
||
699 |
l->addAnchor(l, Qt::AnchorLeft, a, Qt::AnchorLeft); |
|
700 |
||
701 |
// Both a and c are 'pointing' to b |
|
702 |
l->addAnchor(a, Qt::AnchorRight, b, Qt::AnchorRight); |
|
703 |
l->addAnchor(c, Qt::AnchorLeft, b, Qt::AnchorLeft); |
|
704 |
||
705 |
l->addAnchor(c, Qt::AnchorRight, l, Qt::AnchorRight); |
|
706 |
||
707 |
QCOMPARE(l->count(), 3); |
|
708 |
||
709 |
QGraphicsWidget p; |
|
710 |
p.setLayout(l); |
|
711 |
||
712 |
QSizeF layoutMinimumSize = l->effectiveSizeHint(Qt::MinimumSize); |
|
713 |
QSizeF layoutMaximumSize = l->effectiveSizeHint(Qt::MaximumSize); |
|
714 |
QSizeF layoutPreferredSize = l->effectiveSizeHint(Qt::PreferredSize); |
|
715 |
||
716 |
QCOMPARE(layoutMinimumSize, QSizeF(60.0, 300.0)); |
|
717 |
QCOMPARE(layoutPreferredSize, QSizeF(120.0, 300.0)); |
|
718 |
QCOMPARE(layoutMaximumSize, QSizeF(190.0, 300.0)); |
|
719 |
||
720 |
p.resize(layoutMinimumSize); |
|
721 |
QCOMPARE(a->geometry(), QRectF(0.0, 0.0, 50.0, 100.0)); |
|
722 |
QCOMPARE(b->geometry(), QRectF(10.0, 100.0, 40.0, 100.0)); |
|
723 |
QCOMPARE(c->geometry(), QRectF(10.0, 200.0, 50.0, 100.0)); |
|
724 |
QCOMPARE(p.size(), layoutMinimumSize); |
|
725 |
||
726 |
p.resize(layoutPreferredSize); |
|
727 |
QCOMPARE(a->geometry(), QRectF(0.0, 0.0, 70.0, 100.0)); |
|
728 |
QCOMPARE(b->geometry(), QRectF(50.0, 100.0, 20.0, 100.0)); |
|
729 |
QCOMPARE(c->geometry(), QRectF(50.0, 200.0, 70.0, 100.0)); |
|
730 |
QCOMPARE(p.size(), layoutPreferredSize); |
|
731 |
||
732 |
p.resize(layoutMaximumSize); |
|
733 |
QCOMPARE(a->geometry(), QRectF(0.0, 0.0, 100.0, 100.0)); |
|
734 |
QCOMPARE(b->geometry(), QRectF(90.0, 100.0, 10.0, 100.0)); |
|
735 |
QCOMPARE(c->geometry(), QRectF(90.0, 200.0, 100.0, 100.0)); |
|
736 |
QCOMPARE(p.size(), layoutMaximumSize); |
|
737 |
||
738 |
QCOMPARE(checkReverseDirection(&p), true); |
|
739 |
} |
|
740 |
||
741 |
void tst_QGraphicsAnchorLayout::fairDistribution() |
|
742 |
{ |
|
743 |
QGraphicsWidget *a = createItem(QSizeF(10.0, 100.0), |
|
744 |
QSizeF(50.0, 100.0), |
|
745 |
QSizeF(100.0, 100.0), "A"); |
|
746 |
||
747 |
QGraphicsWidget *b = createItem(QSizeF(10.0, 100.0), |
|
748 |
QSizeF(50.0, 100.0), |
|
749 |
QSizeF(100.0, 100.0), "B"); |
|
750 |
||
751 |
QGraphicsWidget *c = createItem(QSizeF(10.0, 100.0), |
|
752 |
QSizeF(50.0, 100.0), |
|
753 |
QSizeF(100.0, 100.0), "C"); |
|
754 |
||
755 |
QGraphicsWidget *d = createItem(QSizeF(60.0, 100.0), |
|
756 |
QSizeF(165.0, 100.0), |
|
757 |
QSizeF(600.0, 100.0), "D"); |
|
758 |
||
759 |
||
760 |
QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout; |
|
761 |
l->setContentsMargins(0, 0, 0, 0); |
|
762 |
l->setSpacing(0); |
|
763 |
||
764 |
l->addAnchor(l, Qt::AnchorTop, a, Qt::AnchorTop); |
|
765 |
l->addAnchor(a, Qt::AnchorBottom, b, Qt::AnchorTop); |
|
766 |
l->addAnchor(b, Qt::AnchorBottom, c, Qt::AnchorTop); |
|
767 |
l->addAnchor(c, Qt::AnchorBottom, d, Qt::AnchorTop); |
|
768 |
l->addAnchor(d, Qt::AnchorBottom, l, Qt::AnchorBottom); |
|
769 |
||
770 |
l->addAnchor(l, Qt::AnchorLeft, a, Qt::AnchorLeft); |
|
771 |
l->addAnchor(a, Qt::AnchorRight, b, Qt::AnchorLeft); |
|
772 |
l->addAnchor(b, Qt::AnchorRight, c, Qt::AnchorLeft); |
|
773 |
l->addAnchor(c, Qt::AnchorRight, l, Qt::AnchorRight); |
|
774 |
l->addAnchor(l, Qt::AnchorLeft, d, Qt::AnchorLeft); |
|
775 |
l->addAnchor(d, Qt::AnchorRight, l, Qt::AnchorRight); |
|
776 |
||
777 |
QCOMPARE(l->count(), 4); |
|
778 |
||
779 |
QGraphicsWidget p; |
|
780 |
p.setLayout(l); |
|
781 |
||
782 |
QSizeF layoutMinimumSize = l->effectiveSizeHint(Qt::MinimumSize); |
|
783 |
QSizeF layoutMaximumSize = l->effectiveSizeHint(Qt::MaximumSize); |
|
784 |
QSizeF layoutPreferredSize = l->effectiveSizeHint(Qt::PreferredSize); |
|
785 |
||
786 |
QCOMPARE(layoutMinimumSize, QSizeF(60.0, 400.0)); |
|
787 |
QCOMPARE(layoutPreferredSize, QSizeF(165.0, 400.0)); |
|
788 |
QCOMPARE(layoutMaximumSize, QSizeF(300.0, 400.0)); |
|
789 |
||
790 |
p.resize(layoutMinimumSize); |
|
791 |
if (!hasSimplification) |
|
792 |
QEXPECT_FAIL("", "Without simplification there is no fair distribution.", Abort); |
|
793 |
QCOMPARE(a->geometry(), QRectF(0.0, 0.0, 20.0, 100.0)); |
|
794 |
QCOMPARE(b->geometry(), QRectF(20.0, 100.0, 20.0, 100.0)); |
|
795 |
QCOMPARE(c->geometry(), QRectF(40.0, 200.0, 20.0, 100.0)); |
|
796 |
QCOMPARE(d->geometry(), QRectF(0.0, 300.0, 60.0, 100.0)); |
|
797 |
QCOMPARE(p.size(), layoutMinimumSize); |
|
798 |
||
799 |
p.resize(layoutPreferredSize); |
|
800 |
QCOMPARE(a->geometry(), QRectF(0.0, 0.0, 55.0, 100.0)); |
|
801 |
QCOMPARE(b->geometry(), QRectF(55.0, 100.0, 55.0, 100.0)); |
|
802 |
QCOMPARE(c->geometry(), QRectF(110.0, 200.0, 55.0, 100.0)); |
|
803 |
QCOMPARE(d->geometry(), QRectF(0.0, 300.0, 165.0, 100.0)); |
|
804 |
QCOMPARE(p.size(), layoutPreferredSize); |
|
805 |
||
806 |
p.resize(layoutMaximumSize); |
|
807 |
QCOMPARE(a->geometry(), QRectF(0.0, 0.0, 100.0, 100.0)); |
|
808 |
QCOMPARE(b->geometry(), QRectF(100.0, 100.0, 100.0, 100.0)); |
|
809 |
QCOMPARE(c->geometry(), QRectF(200.0, 200.0, 100.0, 100.0)); |
|
810 |
QCOMPARE(d->geometry(), QRectF(0.0, 300.0, 300.0, 100.0)); |
|
811 |
QCOMPARE(p.size(), layoutMaximumSize); |
|
812 |
||
813 |
if (hasSimplification) { |
|
814 |
QVERIFY(!usedSimplex(l, Qt::Horizontal)); |
|
815 |
QVERIFY(!usedSimplex(l, Qt::Vertical)); |
|
816 |
} |
|
817 |
} |
|
818 |
||
819 |
void tst_QGraphicsAnchorLayout::fairDistributionOppositeDirections() |
|
820 |
{ |
|
821 |
QGraphicsWidget *a = createItem(QSizeF(10.0, 100.0), |
|
822 |
QSizeF(50.0, 100.0), |
|
823 |
QSizeF(100.0, 100.0), "A"); |
|
824 |
||
825 |
QGraphicsWidget *b = createItem(QSizeF(10.0, 100.0), |
|
826 |
QSizeF(50.0, 100.0), |
|
827 |
QSizeF(100.0, 100.0), "B"); |
|
828 |
||
829 |
QGraphicsWidget *c = createItem(QSizeF(10.0, 100.0), |
|
830 |
QSizeF(50.0, 100.0), |
|
831 |
QSizeF(100.0, 100.0), "C"); |
|
832 |
||
833 |
QGraphicsWidget *d = createItem(QSizeF(10.0, 100.0), |
|
834 |
QSizeF(50.0, 100.0), |
|
835 |
QSizeF(100.0, 100.0), "D"); |
|
836 |
||
837 |
QGraphicsWidget *e = createItem(QSizeF(60.0, 100.0), |
|
838 |
QSizeF(220.0, 100.0), |
|
839 |
QSizeF(600.0, 100.0), "E"); |
|
840 |
||
841 |
||
842 |
QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout; |
|
843 |
l->setContentsMargins(0, 0, 0, 0); |
|
844 |
l->setSpacing(0); |
|
845 |
||
846 |
l->addAnchor(l, Qt::AnchorTop, a, Qt::AnchorTop); |
|
847 |
l->addAnchor(a, Qt::AnchorBottom, b, Qt::AnchorTop); |
|
848 |
l->addAnchor(b, Qt::AnchorBottom, c, Qt::AnchorTop); |
|
849 |
l->addAnchor(c, Qt::AnchorBottom, d, Qt::AnchorTop); |
|
850 |
l->addAnchor(d, Qt::AnchorBottom, e, Qt::AnchorTop); |
|
851 |
l->addAnchor(e, Qt::AnchorBottom, l, Qt::AnchorBottom); |
|
852 |
||
853 |
l->addAnchor(a, Qt::AnchorLeft, l, Qt::AnchorLeft); |
|
854 |
l->addAnchor(b, Qt::AnchorLeft, a, Qt::AnchorRight); |
|
855 |
l->addAnchor(c, Qt::AnchorLeft, b, Qt::AnchorRight); |
|
856 |
l->addAnchor(d, Qt::AnchorLeft, c, Qt::AnchorRight); |
|
857 |
l->addAnchor(d, Qt::AnchorRight, l, Qt::AnchorRight); |
|
858 |
l->addAnchors(l, e, Qt::Horizontal); |
|
859 |
||
860 |
QCOMPARE(l->count(), 5); |
|
861 |
||
862 |
QGraphicsWidget p; |
|
863 |
p.setLayout(l); |
|
864 |
||
865 |
QSizeF layoutMinimumSize = l->effectiveSizeHint(Qt::MinimumSize); |
|
866 |
QSizeF layoutMaximumSize = l->effectiveSizeHint(Qt::MaximumSize); |
|
867 |
QSizeF layoutPreferredSize = l->effectiveSizeHint(Qt::PreferredSize); |
|
868 |
||
869 |
QCOMPARE(layoutMinimumSize, QSizeF(60.0, 500.0)); |
|
870 |
QCOMPARE(layoutPreferredSize, QSizeF(220.0, 500.0)); |
|
871 |
QCOMPARE(layoutMaximumSize, QSizeF(400.0, 500.0)); |
|
872 |
||
873 |
if (!hasSimplification) |
|
874 |
return; |
|
875 |
||
876 |
p.resize(layoutMinimumSize); |
|
877 |
QCOMPARE(a->size(), b->size()); |
|
878 |
QCOMPARE(a->size(), c->size()); |
|
879 |
QCOMPARE(a->size(), d->size()); |
|
880 |
QCOMPARE(e->size().width(), 4 * a->size().width()); |
|
881 |
QCOMPARE(p.size(), layoutMinimumSize); |
|
882 |
||
883 |
p.resize(layoutPreferredSize); |
|
884 |
QCOMPARE(a->size(), b->size()); |
|
885 |
QCOMPARE(a->size(), c->size()); |
|
886 |
QCOMPARE(a->size(), d->size()); |
|
887 |
QCOMPARE(e->size().width(), 4 * a->size().width()); |
|
888 |
QCOMPARE(p.size(), layoutPreferredSize); |
|
889 |
||
890 |
p.resize(layoutMaximumSize); |
|
891 |
QCOMPARE(a->size(), b->size()); |
|
892 |
QCOMPARE(a->size(), c->size()); |
|
893 |
QCOMPARE(a->size(), d->size()); |
|
894 |
QCOMPARE(e->size().width(), 4 * a->size().width()); |
|
895 |
QCOMPARE(p.size(), layoutMaximumSize); |
|
896 |
||
897 |
QVERIFY(!usedSimplex(l, Qt::Horizontal)); |
|
898 |
QVERIFY(!usedSimplex(l, Qt::Vertical)); |
|
899 |
} |
|
900 |
||
901 |
void tst_QGraphicsAnchorLayout::proportionalPreferred() |
|
902 |
{ |
|
903 |
QSizeF min(0, 100); |
|
904 |
||
905 |
QGraphicsWidget *a = createItem(min, QSizeF(10, 100), QSizeF(20, 100), "A"); |
|
906 |
QGraphicsWidget *b = createItem(min, QSizeF(20, 100), QSizeF(30, 100), "B"); |
|
907 |
QGraphicsWidget *c = createItem(min, QSizeF(14, 100), QSizeF(20, 100), "C"); |
|
908 |
QGraphicsWidget *d = createItem(min, QSizeF(10, 100), QSizeF(20, 100), "D"); |
|
909 |
||
910 |
QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout; |
|
911 |
l->setContentsMargins(0, 0, 0, 0); |
|
912 |
l->setSpacing(0); |
|
913 |
||
914 |
l->addAnchor(l, Qt::AnchorTop, a, Qt::AnchorTop); |
|
915 |
l->addAnchor(a, Qt::AnchorBottom, b, Qt::AnchorTop); |
|
916 |
l->addAnchor(b, Qt::AnchorBottom, c, Qt::AnchorTop); |
|
917 |
l->addAnchor(c, Qt::AnchorBottom, d, Qt::AnchorTop); |
|
918 |
l->addAnchor(d, Qt::AnchorBottom, l, Qt::AnchorBottom); |
|
919 |
||
920 |
l->addAnchor(l, Qt::AnchorLeft, a, Qt::AnchorLeft); |
|
921 |
l->addAnchor(l, Qt::AnchorLeft, b, Qt::AnchorLeft); |
|
922 |
l->addAnchor(a, Qt::AnchorRight, c, Qt::AnchorLeft); |
|
923 |
l->addAnchor(a, Qt::AnchorRight, d, Qt::AnchorLeft); |
|
924 |
l->addAnchor(b, Qt::AnchorRight, l, Qt::AnchorRight); |
|
925 |
l->addAnchor(c, Qt::AnchorRight, l, Qt::AnchorRight); |
|
926 |
l->addAnchor(d, Qt::AnchorRight, l, Qt::AnchorRight); |
|
927 |
||
928 |
QCOMPARE(l->count(), 4); |
|
929 |
||
930 |
QGraphicsWidget p; |
|
931 |
p.setLayout(l); |
|
932 |
||
933 |
QSizeF layoutMinimumSize = l->effectiveSizeHint(Qt::MinimumSize); |
|
934 |
QSizeF layoutPreferredSize = l->effectiveSizeHint(Qt::PreferredSize); |
|
935 |
QSizeF layoutMaximumSize = l->effectiveSizeHint(Qt::MaximumSize); |
|
936 |
||
937 |
QCOMPARE(layoutMinimumSize, QSizeF(0, 400)); |
|
938 |
QCOMPARE(layoutPreferredSize, QSizeF(24, 400)); |
|
939 |
QCOMPARE(layoutMaximumSize, QSizeF(30, 400)); |
|
940 |
||
941 |
p.resize(layoutMinimumSize); |
|
942 |
QCOMPARE(p.size(), layoutMinimumSize); |
|
943 |
||
944 |
p.resize(layoutPreferredSize); |
|
945 |
QCOMPARE(c->size().width(), d->size().width()); |
|
946 |
QCOMPARE(p.size(), layoutPreferredSize); |
|
947 |
||
948 |
p.resize(layoutMaximumSize); |
|
949 |
QCOMPARE(p.size(), layoutMaximumSize); |
|
950 |
||
951 |
p.resize(QSizeF(12, 400)); |
|
952 |
||
953 |
// Proportionality between size given and preferred size, this |
|
954 |
// should be respected in this graph for (a) and (b)|(c). |
|
955 |
qreal factor = 12.0 / 24.0; |
|
956 |
||
957 |
QCOMPARE(c->size().width(), d->size().width()); |
|
958 |
QCOMPARE(a->size().width(), 10 * factor); |
|
959 |
QCOMPARE(c->size().width(), 14 * factor); |
|
960 |
QCOMPARE(p.size(), QSizeF(12, 400)); |
|
961 |
||
962 |
if (hasSimplification) { |
|
963 |
QVERIFY(!usedSimplex(l, Qt::Horizontal)); |
|
964 |
QVERIFY(!usedSimplex(l, Qt::Vertical)); |
|
965 |
} |
|
966 |
} |
|
967 |
||
968 |
void tst_QGraphicsAnchorLayout::example() |
|
969 |
{ |
|
970 |
QSizeF min(30, 100); |
|
971 |
QSizeF pref(210, 100); |
|
972 |
QSizeF max(300, 100); |
|
973 |
||
974 |
QGraphicsWidget *a = createItem(min, pref, max, "A"); |
|
975 |
QGraphicsWidget *b = createItem(min, pref, max, "B"); |
|
976 |
QGraphicsWidget *c = createItem(min, pref, max, "C"); |
|
977 |
QGraphicsWidget *d = createItem(min, pref, max, "D"); |
|
978 |
QGraphicsWidget *e = createItem(min, pref, max, "E"); |
|
979 |
QGraphicsWidget *f = createItem(QSizeF(30, 50), QSizeF(150, 50), max, "F"); |
|
980 |
QGraphicsWidget *g = createItem(QSizeF(30, 50), QSizeF(30, 100), max, "G"); |
|
981 |
||
982 |
QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout; |
|
983 |
l->setContentsMargins(0, 0, 0, 0); |
|
984 |
l->setSpacing(0); |
|
985 |
||
986 |
// vertical |
|
987 |
l->addAnchor(a, Qt::AnchorTop, l, Qt::AnchorTop); |
|
988 |
l->addAnchor(b, Qt::AnchorTop, l, Qt::AnchorTop); |
|
989 |
||
990 |
l->addAnchor(c, Qt::AnchorTop, a, Qt::AnchorBottom); |
|
991 |
l->addAnchor(c, Qt::AnchorTop, b, Qt::AnchorBottom); |
|
992 |
l->addAnchor(c, Qt::AnchorBottom, d, Qt::AnchorTop); |
|
993 |
l->addAnchor(c, Qt::AnchorBottom, e, Qt::AnchorTop); |
|
994 |
||
995 |
l->addAnchor(d, Qt::AnchorBottom, l, Qt::AnchorBottom); |
|
996 |
l->addAnchor(e, Qt::AnchorBottom, l, Qt::AnchorBottom); |
|
997 |
||
998 |
l->addAnchor(c, Qt::AnchorTop, f, Qt::AnchorTop); |
|
999 |
l->addAnchor(c, Qt::AnchorVerticalCenter, f, Qt::AnchorBottom); |
|
1000 |
l->addAnchor(f, Qt::AnchorBottom, g, Qt::AnchorTop); |
|
1001 |
l->addAnchor(c, Qt::AnchorBottom, g, Qt::AnchorBottom); |
|
1002 |
||
1003 |
// horizontal |
|
1004 |
l->addAnchor(l, Qt::AnchorLeft, a, Qt::AnchorLeft); |
|
1005 |
l->addAnchor(l, Qt::AnchorLeft, d, Qt::AnchorLeft); |
|
1006 |
l->addAnchor(a, Qt::AnchorRight, b, Qt::AnchorLeft); |
|
1007 |
||
1008 |
l->addAnchor(a, Qt::AnchorRight, c, Qt::AnchorLeft); |
|
1009 |
l->addAnchor(c, Qt::AnchorRight, e, Qt::AnchorLeft); |
|
1010 |
||
1011 |
l->addAnchor(b, Qt::AnchorRight, l, Qt::AnchorRight); |
|
1012 |
l->addAnchor(e, Qt::AnchorRight, l, Qt::AnchorRight); |
|
1013 |
l->addAnchor(d, Qt::AnchorRight, e, Qt::AnchorLeft); |
|
1014 |
||
1015 |
l->addAnchor(l, Qt::AnchorLeft, f, Qt::AnchorLeft); |
|
1016 |
l->addAnchor(l, Qt::AnchorLeft, g, Qt::AnchorLeft); |
|
1017 |
l->addAnchor(f, Qt::AnchorRight, g, Qt::AnchorRight); |
|
1018 |
||
1019 |
QCOMPARE(l->count(), 7); |
|
1020 |
||
1021 |
QGraphicsWidget p; |
|
1022 |
p.setLayout(l); |
|
1023 |
||
1024 |
QSizeF layoutMinimumSize = l->effectiveSizeHint(Qt::MinimumSize); |
|
1025 |
QSizeF layoutMaximumSize = l->effectiveSizeHint(Qt::MaximumSize); |
|
1026 |
QSizeF layoutPreferredSize = l->effectiveSizeHint(Qt::PreferredSize); |
|
1027 |
||
1028 |
QCOMPARE(layoutMinimumSize, QSizeF(90.0, 300.0)); |
|
1029 |
QCOMPARE(layoutPreferredSize, QSizeF(510.0, 300.0)); |
|
1030 |
QCOMPARE(layoutMaximumSize, QSizeF(570.0, 300.0)); |
|
1031 |
||
1032 |
p.resize(layoutMinimumSize); |
|
1033 |
QCOMPARE(p.size(), layoutMinimumSize); |
|
1034 |
QCOMPARE(a->size(), e->size()); |
|
1035 |
QCOMPARE(b->size(), d->size()); |
|
1036 |
QCOMPARE(f->size(), g->size()); |
|
1037 |
||
1038 |
p.resize(layoutPreferredSize); |
|
1039 |
QCOMPARE(p.size(), layoutPreferredSize); |
|
1040 |
QCOMPARE(a->size(), e->size()); |
|
1041 |
QCOMPARE(b->size(), d->size()); |
|
1042 |
QCOMPARE(f->size(), g->size()); |
|
1043 |
||
1044 |
p.resize(layoutMaximumSize); |
|
1045 |
QCOMPARE(p.size(), layoutMaximumSize); |
|
1046 |
QCOMPARE(a->size(), e->size()); |
|
1047 |
QCOMPARE(b->size(), d->size()); |
|
1048 |
QCOMPARE(f->size(), g->size()); |
|
1049 |
||
1050 |
if (hasSimplification) { |
|
1051 |
QVERIFY(usedSimplex(l, Qt::Horizontal)); |
|
1052 |
QVERIFY(usedSimplex(l, Qt::Vertical)); |
|
1053 |
} |
|
1054 |
} |
|
1055 |
||
1056 |
void tst_QGraphicsAnchorLayout::setSpacing() |
|
1057 |
{ |
|
1058 |
QSizeF min(10, 10); |
|
1059 |
QSizeF pref(20, 20); |
|
1060 |
QSizeF max(50, 50); |
|
1061 |
||
1062 |
QGraphicsWidget *a = createItem(min, pref, max); |
|
1063 |
QGraphicsWidget *b = createItem(min, pref, max); |
|
1064 |
QGraphicsWidget *c = createItem(min, pref, max); |
|
1065 |
||
1066 |
QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout; |
|
1067 |
l->addCornerAnchors(l, Qt::TopLeftCorner, a, Qt::TopLeftCorner); |
|
1068 |
l->addCornerAnchors(b, Qt::TopRightCorner, l, Qt::TopRightCorner); |
|
1069 |
l->addAnchor(a, Qt::AnchorRight, b, Qt::AnchorLeft); |
|
1070 |
||
1071 |
l->addAnchors(l, c, Qt::Horizontal); |
|
1072 |
||
1073 |
l->addAnchor(a, Qt::AnchorBottom, c, Qt::AnchorTop); |
|
1074 |
l->addAnchor(c, Qt::AnchorBottom, l, Qt::AnchorBottom); |
|
1075 |
||
1076 |
QGraphicsWidget *p = new QGraphicsWidget(0, Qt::Window); |
|
1077 |
||
1078 |
p->setLayout(l); |
|
1079 |
l->setSpacing(1); |
|
1080 |
||
1081 |
// don't let the style influence the test. |
|
1082 |
l->setContentsMargins(0, 0, 0, 0); |
|
1083 |
||
1084 |
QGraphicsScene scene; |
|
1085 |
scene.addItem(p); |
|
1086 |
QGraphicsView *view = new QGraphicsView(&scene); |
|
1087 |
view->show(); |
|
1088 |
p->show(); |
|
1089 |
||
1090 |
QApplication::processEvents(); |
|
1091 |
#ifdef Q_WS_MAC |
|
1092 |
QTest::qWait(200); |
|
1093 |
#endif |
|
1094 |
QCOMPARE(a->geometry(), QRectF(0, 0, 20, 20)); |
|
1095 |
QCOMPARE(b->geometry(), QRectF(21, 0, 20, 20)); |
|
1096 |
QCOMPARE(c->geometry(), QRectF(0, 21, 41, 20)); |
|
1097 |
||
1098 |
l->setHorizontalSpacing(4); |
|
1099 |
QApplication::processEvents(); |
|
1100 |
p->adjustSize(); |
|
1101 |
QCOMPARE(a->geometry(), QRectF(0, 0, 20, 20)); |
|
1102 |
QCOMPARE(b->geometry(), QRectF(24, 0, 20, 20)); |
|
1103 |
QCOMPARE(c->geometry(), QRectF(0, 21, 44, 20)); |
|
1104 |
||
1105 |
l->setVerticalSpacing(0); |
|
1106 |
QApplication::processEvents(); |
|
1107 |
p->adjustSize(); |
|
1108 |
QCOMPARE(a->geometry(), QRectF(0, 0, 20, 20)); |
|
1109 |
QCOMPARE(b->geometry(), QRectF(24, 0, 20, 20)); |
|
1110 |
QCOMPARE(c->geometry(), QRectF(0, 20, 44, 20)); |
|
1111 |
||
1112 |
delete p; |
|
1113 |
delete view; |
|
1114 |
} |
|
1115 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1116 |
class CustomLayoutStyle : public QWindowsStyle |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1117 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1118 |
Q_OBJECT |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1119 |
public: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1120 |
CustomLayoutStyle() : QWindowsStyle() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1121 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1122 |
hspacing = 5; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1123 |
vspacing = 10; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1124 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1125 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1126 |
virtual int pixelMetric(PixelMetric metric, const QStyleOption * option = 0, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1127 |
const QWidget * widget = 0 ) const; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1128 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1129 |
int hspacing; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1130 |
int vspacing; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1131 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1132 |
protected slots: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1133 |
int layoutSpacingImplementation(QSizePolicy::ControlType control1, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1134 |
QSizePolicy::ControlType control2, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1135 |
Qt::Orientation orientation, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1136 |
const QStyleOption *option = 0, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1137 |
const QWidget *widget = 0) const; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1138 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1139 |
}; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1140 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1141 |
#define CT1(c) CT2(c, c) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1142 |
#define CT2(c1, c2) ((uint)c1 << 16) | (uint)c2 |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1143 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1144 |
int CustomLayoutStyle::layoutSpacingImplementation(QSizePolicy::ControlType control1, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1145 |
QSizePolicy::ControlType control2, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1146 |
Qt::Orientation orientation, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1147 |
const QStyleOption * /*option = 0*/, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1148 |
const QWidget * /*widget = 0*/) const |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1149 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1150 |
if (orientation == Qt::Horizontal) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1151 |
switch (CT2(control1, control2)) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1152 |
case CT1(QSizePolicy::PushButton): |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1153 |
return 2; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1154 |
break; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1155 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1156 |
return 5; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1157 |
} else { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1158 |
switch (CT2(control1, control2)) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1159 |
case CT1(QSizePolicy::RadioButton): |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1160 |
return 2; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1161 |
break; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1162 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1163 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1164 |
return 10; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1165 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1166 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1167 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1168 |
int CustomLayoutStyle::pixelMetric(PixelMetric metric, const QStyleOption * option /*= 0*/, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1169 |
const QWidget * widget /*= 0*/ ) const |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1170 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1171 |
switch (metric) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1172 |
case PM_LayoutLeftMargin: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1173 |
return 0; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1174 |
break; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1175 |
case PM_LayoutTopMargin: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1176 |
return 3; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1177 |
break; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1178 |
case PM_LayoutRightMargin: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1179 |
return 6; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1180 |
break; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1181 |
case PM_LayoutBottomMargin: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1182 |
return 9; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1183 |
break; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1184 |
case PM_LayoutHorizontalSpacing: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1185 |
return hspacing; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1186 |
case PM_LayoutVerticalSpacing: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1187 |
return vspacing; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1188 |
break; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1189 |
default: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1190 |
break; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1191 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1192 |
return QWindowsStyle::pixelMetric(metric, option, widget); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1193 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1194 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1195 |
void tst_QGraphicsAnchorLayout::styleDefaults() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1196 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1197 |
QSizeF min (10, 10); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1198 |
QSizeF pref(20, 20); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1199 |
QSizeF max (50, 50); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1200 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1201 |
/* |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1202 |
create this layout, where a,b have controlType QSizePolicy::RadioButton |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1203 |
c,d have controlType QSizePolicy::PushButton: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1204 |
+-------+ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1205 |
|a | |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1206 |
| b | |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1207 |
| c | |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1208 |
| d| |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1209 |
+-------+ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1210 |
*/ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1211 |
QGraphicsScene scene; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1212 |
QGraphicsWidget *a = createItem(min, pref, max); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1213 |
QSizePolicy spRadioButton = a->sizePolicy(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1214 |
spRadioButton.setControlType(QSizePolicy::RadioButton); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1215 |
a->setSizePolicy(spRadioButton); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1216 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1217 |
QGraphicsWidget *b = createItem(min, pref, max); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1218 |
b->setSizePolicy(spRadioButton); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1219 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1220 |
QGraphicsWidget *c = createItem(min, pref, max); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1221 |
QSizePolicy spPushButton = c->sizePolicy(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1222 |
spPushButton.setControlType(QSizePolicy::PushButton); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1223 |
c->setSizePolicy(spPushButton); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1224 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1225 |
QGraphicsWidget *d = createItem(min, pref, max); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1226 |
d->setSizePolicy(spPushButton); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1227 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1228 |
QGraphicsWidget *window = new QGraphicsWidget(0, Qt::Window); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1229 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1230 |
// Test layoutSpacingImplementation |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1231 |
CustomLayoutStyle *style = new CustomLayoutStyle; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1232 |
style->hspacing = -1; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1233 |
style->vspacing = -1; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1234 |
window->setStyle(style); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1235 |
QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1236 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1237 |
l->addCornerAnchors(l, Qt::TopLeftCorner, a, Qt::TopLeftCorner); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1238 |
l->addCornerAnchors(a, Qt::BottomRightCorner, b, Qt::TopLeftCorner); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1239 |
l->addCornerAnchors(b, Qt::BottomRightCorner, c, Qt::TopLeftCorner); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1240 |
l->addCornerAnchors(c, Qt::BottomRightCorner, d, Qt::TopLeftCorner); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1241 |
l->addCornerAnchors(d, Qt::BottomRightCorner, l, Qt::BottomRightCorner); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1242 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1243 |
window->setLayout(l); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1244 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1245 |
scene.addItem(window); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1246 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1247 |
window->show(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1248 |
QGraphicsView view(&scene); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1249 |
view.resize(200, 200); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1250 |
view.show(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1251 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1252 |
window->adjustSize(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1253 |
QCOMPARE(a->geometry(), QRectF(0, 3, 20, 20)); //radio |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1254 |
QCOMPARE(b->geometry(), QRectF(25, 25, 20, 20)); //radio |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1255 |
QCOMPARE(c->geometry(), QRectF(50, 55, 20, 20)); //push |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1256 |
QCOMPARE(d->geometry(), QRectF(72, 85, 20, 20)); //push |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1257 |
QCOMPARE(l->geometry(), QRectF(0, 0, 98, 114)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1258 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1259 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1260 |
// Test pixelMetric(PM_Layout{Horizontal|Vertical}Spacing |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1261 |
window->setStyle(0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1262 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1263 |
style->hspacing = 1; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1264 |
style->vspacing = 2; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1265 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1266 |
window->setStyle(style); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1267 |
window->adjustSize(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1268 |
QCOMPARE(a->geometry(), QRectF(0, 3, 20, 20)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1269 |
QCOMPARE(b->geometry(), QRectF(21, 25, 20, 20)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1270 |
QCOMPARE(c->geometry(), QRectF(42, 47, 20, 20)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1271 |
QCOMPARE(d->geometry(), QRectF(63, 69, 20, 20)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1272 |
QCOMPARE(l->geometry(), QRectF(0, 0, 89, 98)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1273 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1274 |
window->setStyle(0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1275 |
delete style; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1276 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1277 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1278 |
|
0 | 1279 |
/*! |
1280 |
Taken from "hard" complex case, found at |
|
1281 |
https://cwiki.nokia.com/S60QTUI/AnchorLayoutComplexCases |
|
1282 |
||
1283 |
This layout has a special property, since it has two possible solutions for its minimum size. |
|
1284 |
||
1285 |
For instance, when it is in its minimum size - the layout have two possible solutions: |
|
1286 |
1. c.width == 10, e.width == 10 and g.width == 10 |
|
1287 |
(all others have width 0) |
|
1288 |
2. d.width == 10 and g.width == 10 |
|
1289 |
(all others have width 0) |
|
1290 |
||
1291 |
It also has several solutions for preferred size. |
|
1292 |
*/ |
|
1293 |
static QGraphicsAnchorLayout *createAmbiguousS60Layout() |
|
1294 |
{ |
|
1295 |
QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout; |
|
1296 |
l->setContentsMargins(0, 0, 0, 0); |
|
1297 |
l->setSpacing(0); |
|
1298 |
||
1299 |
QSizeF min(0, 10); |
|
1300 |
QSizeF pref(50, 10); |
|
1301 |
QSizeF max(100, 10); |
|
1302 |
||
1303 |
QGraphicsWidget *a = createItem(min, pref, max, "a"); |
|
1304 |
QGraphicsWidget *b = createItem(min, pref, max, "b"); |
|
1305 |
QGraphicsWidget *c = createItem(min, pref, max, "c"); |
|
1306 |
QGraphicsWidget *d = createItem(min, pref, max, "d"); |
|
1307 |
QGraphicsWidget *e = createItem(min, pref, max, "e"); |
|
1308 |
QGraphicsWidget *f = createItem(min, pref, max, "f"); |
|
1309 |
QGraphicsWidget *g = createItem(min, pref, max, "g"); |
|
1310 |
||
1311 |
//<!-- Trunk --> |
|
1312 |
setAnchor(l, l, Qt::AnchorLeft, a, Qt::AnchorLeft, 10); |
|
1313 |
setAnchor(l, a, Qt::AnchorRight, b, Qt::AnchorLeft, 10); |
|
1314 |
setAnchor(l, b, Qt::AnchorRight, c, Qt::AnchorLeft, 10); |
|
1315 |
setAnchor(l, c, Qt::AnchorRight, d, Qt::AnchorLeft, 10); |
|
1316 |
setAnchor(l, d, Qt::AnchorRight, l, Qt::AnchorRight, 10); |
|
1317 |
||
1318 |
//<!-- Above trunk --> |
|
1319 |
setAnchor(l, b, Qt::AnchorLeft, e, Qt::AnchorLeft, 10); |
|
1320 |
setAnchor(l, e, Qt::AnchorRight, d, Qt::AnchorLeft, 10); |
|
1321 |
||
1322 |
//<!-- Below trunk --> |
|
1323 |
setAnchor(l, a, Qt::AnchorHorizontalCenter, g, Qt::AnchorLeft, 10); |
|
1324 |
setAnchor(l, g, Qt::AnchorRight, f, Qt::AnchorHorizontalCenter, 10); |
|
1325 |
setAnchor(l, c, Qt::AnchorLeft, f, Qt::AnchorLeft, 10); |
|
1326 |
setAnchor(l, f, Qt::AnchorRight, d, Qt::AnchorRight, 10); |
|
1327 |
||
1328 |
//<!-- vertical is simpler --> |
|
1329 |
setAnchor(l, l, Qt::AnchorTop, e, Qt::AnchorTop, 0); |
|
1330 |
setAnchor(l, e, Qt::AnchorBottom, a, Qt::AnchorTop, 0); |
|
1331 |
setAnchor(l, e, Qt::AnchorBottom, b, Qt::AnchorTop, 0); |
|
1332 |
setAnchor(l, e, Qt::AnchorBottom, c, Qt::AnchorTop, 0); |
|
1333 |
setAnchor(l, e, Qt::AnchorBottom, d, Qt::AnchorTop, 0); |
|
1334 |
setAnchor(l, a, Qt::AnchorBottom, f, Qt::AnchorTop, 0); |
|
1335 |
setAnchor(l, a, Qt::AnchorBottom, b, Qt::AnchorBottom, 0); |
|
1336 |
setAnchor(l, a, Qt::AnchorBottom, c, Qt::AnchorBottom, 0); |
|
1337 |
setAnchor(l, a, Qt::AnchorBottom, d, Qt::AnchorBottom, 0); |
|
1338 |
setAnchor(l, f, Qt::AnchorBottom, g, Qt::AnchorTop, 0); |
|
1339 |
setAnchor(l, g, Qt::AnchorBottom, l, Qt::AnchorBottom, 0); |
|
1340 |
return l; |
|
1341 |
} |
|
1342 |
||
1343 |
void tst_QGraphicsAnchorLayout::hardComplexS60() |
|
1344 |
{ |
|
1345 |
QGraphicsAnchorLayout *l = createAmbiguousS60Layout(); |
|
1346 |
QCOMPARE(l->count(), 7); |
|
1347 |
||
1348 |
QGraphicsWidget *p = new QGraphicsWidget(0, Qt::Window); |
|
1349 |
p->setLayout(l); |
|
1350 |
||
1351 |
QSizeF layoutMinimumSize = l->effectiveSizeHint(Qt::MinimumSize); |
|
1352 |
QCOMPARE(layoutMinimumSize, QSizeF(60, 40)); |
|
1353 |
// expected preferred might be wrong, (haven't manually verified it) |
|
1354 |
QSizeF layoutPreferredSize = l->effectiveSizeHint(Qt::PreferredSize); |
|
1355 |
QCOMPARE(layoutPreferredSize, QSizeF(220, 40)); |
|
1356 |
QSizeF layoutMaximumSize = l->effectiveSizeHint(Qt::MaximumSize); |
|
1357 |
QCOMPARE(layoutMaximumSize, QSizeF(240, 40)); |
|
1358 |
||
1359 |
delete p; |
|
1360 |
} |
|
1361 |
||
1362 |
void tst_QGraphicsAnchorLayout::stability() |
|
1363 |
{ |
|
1364 |
QVector<QRectF> geometries; |
|
1365 |
geometries.resize(7); |
|
1366 |
QGraphicsWidget *p = new QGraphicsWidget(0, Qt::Window); |
|
1367 |
bool sameAsPreviousArrangement = true; |
|
1368 |
// it usually fails after 3-4 iterations |
|
1369 |
for (int pass = 0; pass < 20 && sameAsPreviousArrangement; ++pass) { |
|
1370 |
// In case we need to "scramble" the heap allocator to provoke this bug. |
|
1371 |
//static const int primes[] = {2, 3, 5, 13, 89, 233, 1597, 28657, 514229}; // fibo primes |
|
1372 |
//const int primeCount = sizeof(primes)/sizeof(int); |
|
1373 |
//int alloc = primes[pass % primeCount] + pass; |
|
1374 |
//void *mem = qMalloc(alloc); |
|
1375 |
//qFree(mem); |
|
1376 |
QGraphicsAnchorLayout *l = createAmbiguousS60Layout(); |
|
1377 |
p->setLayout(l); |
|
1378 |
QSizeF layoutMinimumSize = l->effectiveSizeHint(Qt::MinimumSize); |
|
1379 |
l->setGeometry(QRectF(QPointF(0,0), layoutMinimumSize)); |
|
1380 |
QApplication::processEvents(); |
|
1381 |
for (int i = l->count() - 1; i >=0 && sameAsPreviousArrangement; --i) { |
|
1382 |
QRectF geom = l->itemAt(i)->geometry(); |
|
1383 |
if (pass != 0) { |
|
1384 |
sameAsPreviousArrangement = (geometries[i] == geom); |
|
1385 |
} |
|
1386 |
geometries[i] = geom; |
|
1387 |
} |
|
1388 |
p->setLayout(0); // uninstalls and deletes the layout |
|
1389 |
QApplication::processEvents(); |
|
1390 |
} |
|
1391 |
delete p; |
|
1392 |
QEXPECT_FAIL("", "The layout have several solutions, but which solution it picks is not stable", Continue); |
|
1393 |
QCOMPARE(sameAsPreviousArrangement, true); |
|
1394 |
} |
|
1395 |
||
1396 |
void tst_QGraphicsAnchorLayout::delete_anchor() |
|
1397 |
{ |
|
1398 |
QGraphicsScene scene; |
|
1399 |
QSizeF minSize(0, 0); |
|
1400 |
QSizeF prefSize(50, 50); |
|
1401 |
QSizeF maxSize(100, 100); |
|
1402 |
QGraphicsWidget *w1 = createItem(minSize, prefSize, maxSize, "w1"); |
|
1403 |
QGraphicsWidget *w2 = createItem(minSize, prefSize, maxSize, "w2"); |
|
1404 |
QGraphicsWidget *w3 = createItem(minSize, prefSize, maxSize, "w3"); |
|
1405 |
||
1406 |
QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout; |
|
1407 |
l->setSpacing(0); |
|
1408 |
l->setContentsMargins(0, 0, 0, 0); |
|
1409 |
||
1410 |
// Horizontal |
|
1411 |
l->addAnchor(l, Qt::AnchorLeft, w1, Qt::AnchorLeft); |
|
1412 |
l->addAnchor(w1, Qt::AnchorRight, w2, Qt::AnchorLeft); |
|
1413 |
l->addAnchor(w2, Qt::AnchorRight, l, Qt::AnchorRight); |
|
1414 |
l->addAnchor(w1, Qt::AnchorRight, w3, Qt::AnchorLeft); |
|
1415 |
l->addAnchor(w3, Qt::AnchorRight, l, Qt::AnchorRight); |
|
1416 |
||
1417 |
// Vertical |
|
1418 |
l->addAnchors(l, w1, Qt::Vertical); |
|
1419 |
l->addAnchors(l, w2, Qt::Vertical); |
|
1420 |
l->addAnchors(l, w3, Qt::Vertical); |
|
1421 |
||
1422 |
QGraphicsAnchor *anchor = l->anchor(w3, Qt::AnchorRight, l, Qt::AnchorRight); |
|
1423 |
anchor->setSpacing(10); |
|
1424 |
||
1425 |
QGraphicsWidget *p = new QGraphicsWidget; |
|
1426 |
p->setLayout(l); |
|
1427 |
||
1428 |
QCOMPARE(l->count(), 3); |
|
1429 |
||
1430 |
scene.addItem(p); |
|
1431 |
QGraphicsView *view = new QGraphicsView(&scene); |
|
1432 |
QApplication::processEvents(); |
|
1433 |
// Should now be simplified |
|
1434 |
QCOMPARE(l->effectiveSizeHint(Qt::PreferredSize).width(), qreal(110)); |
|
1435 |
QGraphicsAnchor *anchor1 = l->anchor(w3, Qt::AnchorRight, l, Qt::AnchorRight); |
|
1436 |
QVERIFY(anchor1); |
|
1437 |
QGraphicsAnchor *anchor2 = l->anchor(w3, Qt::AnchorRight, l, Qt::AnchorRight); |
|
1438 |
QVERIFY(anchor2); |
|
1439 |
QGraphicsAnchor *anchor3 = l->anchor(l, Qt::AnchorRight, w3, Qt::AnchorRight); |
|
1440 |
QVERIFY(anchor3); |
|
1441 |
QGraphicsAnchor *anchor4 = l->anchor(l, Qt::AnchorRight, w3, Qt::AnchorRight); |
|
1442 |
QVERIFY(anchor4); |
|
1443 |
||
1444 |
// should all be the same object |
|
1445 |
QCOMPARE(anchor1, anchor2); |
|
1446 |
QCOMPARE(anchor2, anchor3); |
|
1447 |
QCOMPARE(anchor3, anchor4); |
|
1448 |
||
1449 |
// check if removal works |
|
1450 |
delete anchor1; |
|
1451 |
||
1452 |
QApplication::processEvents(); |
|
1453 |
||
1454 |
// it should also change the preferred size of the layout |
|
1455 |
QCOMPARE(l->effectiveSizeHint(Qt::PreferredSize).width(), qreal(100)); |
|
1456 |
||
1457 |
delete p; |
|
1458 |
delete view; |
|
1459 |
} |
|
1460 |
||
1461 |
void tst_QGraphicsAnchorLayout::sizePolicy() |
|
1462 |
{ |
|
1463 |
QGraphicsScene scene; |
|
1464 |
QSizeF minSize(0, 0); |
|
1465 |
QSizeF prefSize(50, 50); |
|
1466 |
QSizeF maxSize(100, 100); |
|
1467 |
QGraphicsWidget *w1 = createItem(minSize, prefSize, maxSize, "w1"); |
|
1468 |
||
1469 |
QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout; |
|
1470 |
l->setSpacing(0); |
|
1471 |
l->setContentsMargins(0, 0, 0, 0); |
|
1472 |
||
1473 |
// horizontal and vertical |
|
1474 |
l->addAnchors(l, w1); |
|
1475 |
||
1476 |
QGraphicsWidget *p = new QGraphicsWidget; |
|
1477 |
p->setLayout(l); |
|
1478 |
||
1479 |
scene.addItem(p); |
|
1480 |
QGraphicsView *view = new QGraphicsView(&scene); |
|
1481 |
||
1482 |
// QSizePolicy::Minimum |
|
1483 |
w1->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); |
|
1484 |
QApplication::processEvents(); |
|
1485 |
w1->adjustSize(); |
|
1486 |
||
1487 |
QCOMPARE(l->effectiveSizeHint(Qt::MinimumSize), QSizeF(50, 50)); |
|
1488 |
QCOMPARE(l->effectiveSizeHint(Qt::PreferredSize), QSizeF(50, 50)); |
|
1489 |
QCOMPARE(l->effectiveSizeHint(Qt::MaximumSize), QSizeF(100, 100)); |
|
1490 |
||
1491 |
// QSizePolicy::Maximum |
|
1492 |
w1->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum); |
|
1493 |
QApplication::processEvents(); |
|
1494 |
w1->adjustSize(); |
|
1495 |
||
1496 |
QCOMPARE(l->effectiveSizeHint(Qt::MinimumSize), QSizeF(0, 0)); |
|
1497 |
QCOMPARE(l->effectiveSizeHint(Qt::PreferredSize), QSizeF(50, 50)); |
|
1498 |
QCOMPARE(l->effectiveSizeHint(Qt::MaximumSize), QSizeF(50, 50)); |
|
1499 |
||
1500 |
// QSizePolicy::Fixed |
|
1501 |
w1->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); |
|
1502 |
QApplication::processEvents(); |
|
1503 |
w1->adjustSize(); |
|
1504 |
||
1505 |
QCOMPARE(l->effectiveSizeHint(Qt::MinimumSize), QSizeF(50, 50)); |
|
1506 |
QCOMPARE(l->effectiveSizeHint(Qt::PreferredSize), QSizeF(50, 50)); |
|
1507 |
QCOMPARE(l->effectiveSizeHint(Qt::MaximumSize), QSizeF(50, 50)); |
|
1508 |
||
1509 |
// QSizePolicy::Preferred |
|
1510 |
w1->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); |
|
1511 |
QApplication::processEvents(); |
|
1512 |
w1->adjustSize(); |
|
1513 |
||
1514 |
QCOMPARE(l->effectiveSizeHint(Qt::MinimumSize), QSizeF(0, 0)); |
|
1515 |
QCOMPARE(l->effectiveSizeHint(Qt::PreferredSize), QSizeF(50, 50)); |
|
1516 |
QCOMPARE(l->effectiveSizeHint(Qt::MaximumSize), QSizeF(100, 100)); |
|
1517 |
||
1518 |
// QSizePolicy::Ignored |
|
1519 |
w1->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); |
|
1520 |
QApplication::processEvents(); |
|
1521 |
w1->adjustSize(); |
|
1522 |
||
1523 |
QCOMPARE(l->effectiveSizeHint(Qt::MinimumSize), QSizeF(0, 0)); |
|
1524 |
QCOMPARE(l->effectiveSizeHint(Qt::PreferredSize), QSizeF(0, 0)); |
|
1525 |
QCOMPARE(l->effectiveSizeHint(Qt::MaximumSize), QSizeF(100, 100)); |
|
1526 |
||
1527 |
// Anchor size policies |
|
1528 |
w1->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); |
|
1529 |
QGraphicsAnchor *anchor = l->anchor(l, Qt::AnchorLeft, w1, Qt::AnchorLeft); |
|
1530 |
anchor->setSpacing(10); |
|
1531 |
||
1532 |
// QSizePolicy::Minimum |
|
1533 |
anchor->setSizePolicy(QSizePolicy::Minimum); |
|
1534 |
QApplication::processEvents(); |
|
1535 |
||
1536 |
QCOMPARE(l->effectiveSizeHint(Qt::MinimumSize), QSizeF(60, 50)); |
|
1537 |
QCOMPARE(l->effectiveSizeHint(Qt::PreferredSize), QSizeF(60, 50)); |
|
1538 |
// The layout has a maximum size of QWIDGETSIZE_MAX, so the result won't exceed that value. |
|
1539 |
QCOMPARE(l->effectiveSizeHint(Qt::MaximumSize), QSizeF(QWIDGETSIZE_MAX, 50)); |
|
1540 |
||
1541 |
// QSizePolicy::Preferred |
|
1542 |
anchor->setSizePolicy(QSizePolicy::Preferred); |
|
1543 |
QApplication::processEvents(); |
|
1544 |
||
1545 |
QCOMPARE(l->effectiveSizeHint(Qt::MinimumSize), QSizeF(50, 50)); |
|
1546 |
QCOMPARE(l->effectiveSizeHint(Qt::PreferredSize), QSizeF(60, 50)); |
|
1547 |
// The layout has a maximum size of QWIDGETSIZE_MAX, so the result won't exceed that value. |
|
1548 |
QCOMPARE(l->effectiveSizeHint(Qt::MaximumSize), QSizeF(QWIDGETSIZE_MAX, 50)); |
|
1549 |
||
1550 |
// QSizePolicy::Maximum |
|
1551 |
anchor->setSizePolicy(QSizePolicy::Maximum); |
|
1552 |
QApplication::processEvents(); |
|
1553 |
||
1554 |
QCOMPARE(l->effectiveSizeHint(Qt::MinimumSize), QSizeF(50, 50)); |
|
1555 |
QCOMPARE(l->effectiveSizeHint(Qt::PreferredSize), QSizeF(60, 50)); |
|
1556 |
QCOMPARE(l->effectiveSizeHint(Qt::MaximumSize), QSizeF(60, 50)); |
|
1557 |
||
1558 |
// QSizePolicy::Ignored |
|
1559 |
anchor->setSizePolicy(QSizePolicy::Ignored); |
|
1560 |
QApplication::processEvents(); |
|
1561 |
||
1562 |
QCOMPARE(l->effectiveSizeHint(Qt::MinimumSize), QSizeF(50, 50)); |
|
1563 |
QCOMPARE(l->effectiveSizeHint(Qt::PreferredSize), QSizeF(50, 50)); |
|
1564 |
QCOMPARE(l->effectiveSizeHint(Qt::MaximumSize), QSizeF(QWIDGETSIZE_MAX, 50)); |
|
1565 |
||
1566 |
if (hasSimplification) { |
|
1567 |
QVERIFY(!usedSimplex(l, Qt::Horizontal)); |
|
1568 |
QVERIFY(!usedSimplex(l, Qt::Vertical)); |
|
1569 |
} |
|
1570 |
||
1571 |
delete p; |
|
1572 |
delete view; |
|
1573 |
} |
|
1574 |
||
1575 |
/*! |
|
1576 |
\internal |
|
1577 |
||
1578 |
Uses private API. (We have decided to pull hasConflicts() out of the API). However, it also |
|
1579 |
tests some tight conditions (almost-in-conflict) that we really want to test. |
|
1580 |
*/ |
|
1581 |
void tst_QGraphicsAnchorLayout::conflicts() |
|
1582 |
{ |
|
1583 |
QGraphicsWidget *a = createItem(QSizeF(80,10), QSizeF(90,10), QSizeF(100,10), "a"); |
|
1584 |
QGraphicsWidget *b = createItem(QSizeF(10,10), QSizeF(20,10), QSizeF(30,10), "b"); |
|
1585 |
QGraphicsWidget *c = createItem(QSizeF(10,10), QSizeF(20,10), QSizeF(30,10), "c"); |
|
1586 |
||
1587 |
QGraphicsAnchorLayout *l; |
|
1588 |
QGraphicsWidget *p = new QGraphicsWidget(0, Qt::Window); |
|
1589 |
||
1590 |
l = new QGraphicsAnchorLayout; |
|
1591 |
l->setContentsMargins(0, 0, 0, 0); |
|
1592 |
||
1593 |
// with the following setup, 'a' cannot be larger than 30 we will first have a Simplex conflict |
|
1594 |
||
1595 |
// horizontal |
|
1596 |
setAnchor(l, l, Qt::AnchorLeft, b, Qt::AnchorLeft); |
|
1597 |
setAnchor(l, b, Qt::AnchorRight, c, Qt::AnchorLeft); |
|
1598 |
setAnchor(l, c, Qt::AnchorRight, l, Qt::AnchorRight); |
|
1599 |
setAnchor(l, b, Qt::AnchorHorizontalCenter, a, Qt::AnchorLeft); |
|
1600 |
setAnchor(l, a, Qt::AnchorRight, c, Qt::AnchorHorizontalCenter); |
|
1601 |
||
1602 |
// vertical |
|
1603 |
setAnchor(l, l, Qt::AnchorTop, a, Qt::AnchorTop); |
|
1604 |
setAnchor(l, a, Qt::AnchorBottom, b, Qt::AnchorTop); |
|
1605 |
setAnchor(l, a, Qt::AnchorBottom, c, Qt::AnchorTop); |
|
1606 |
setAnchor(l, b, Qt::AnchorBottom, l, Qt::AnchorBottom); |
|
1607 |
setAnchor(l, c, Qt::AnchorBottom, l, Qt::AnchorBottom); |
|
1608 |
||
1609 |
p->setLayout(l); |
|
1610 |
||
1611 |
QCOMPARE(layoutHasConflict(l), true); |
|
1612 |
||
1613 |
a->setMinimumSize(QSizeF(29,10)); |
|
1614 |
QCOMPARE(layoutHasConflict(l), false); |
|
1615 |
||
1616 |
a->setMinimumSize(QSizeF(30,10)); |
|
1617 |
QCOMPARE(layoutHasConflict(l), false); |
|
1618 |
||
1619 |
delete p; |
|
1620 |
} |
|
1621 |
||
1622 |
void tst_QGraphicsAnchorLayout::floatConflict() |
|
1623 |
{ |
|
1624 |
QGraphicsWidget *a = createItem(QSizeF(80,10), QSizeF(90,10), QSizeF(100,10), "a"); |
|
1625 |
QGraphicsWidget *b = createItem(QSizeF(80,10), QSizeF(90,10), QSizeF(100,10), "b"); |
|
1626 |
||
1627 |
QGraphicsAnchorLayout *l; |
|
1628 |
QGraphicsWidget *p = new QGraphicsWidget(0, Qt::Window); |
|
1629 |
||
1630 |
l = new QGraphicsAnchorLayout; |
|
1631 |
l->setContentsMargins(0, 0, 0, 0); |
|
1632 |
||
1633 |
p->setLayout(l); |
|
1634 |
||
1635 |
// horizontal |
|
1636 |
// with this anchor we have two floating items |
|
1637 |
setAnchor(l, a, Qt::AnchorRight, b, Qt::AnchorLeft); |
|
1638 |
||
1639 |
// Just checking if the layout is handling well the removal of floating items |
|
1640 |
delete l->anchor(a, Qt::AnchorRight, b, Qt::AnchorLeft); |
|
1641 |
QCOMPARE(l->count(), 0); |
|
1642 |
QCOMPARE(layoutHasConflict(l), false); |
|
1643 |
||
1644 |
// setting back the same anchor |
|
1645 |
setAnchor(l, a, Qt::AnchorRight, b, Qt::AnchorLeft); |
|
1646 |
||
1647 |
// We don't support floating items but they should be counted as if they are in the layout |
|
1648 |
QCOMPARE(l->count(), 2); |
|
1649 |
// Although, we have an invalid situation |
|
1650 |
QCOMPARE(layoutHasConflict(l), true); |
|
1651 |
||
1652 |
// Semi-floats are supported |
|
1653 |
setAnchor(l, a, Qt::AnchorLeft, l, Qt::AnchorLeft); |
|
1654 |
QCOMPARE(l->count(), 2); |
|
1655 |
||
1656 |
// Vertically the layout has floating items. Therefore, we have a conflict |
|
1657 |
QCOMPARE(layoutHasConflict(l), true); |
|
1658 |
||
1659 |
// No more floating items |
|
1660 |
setAnchor(l, b, Qt::AnchorRight, l, Qt::AnchorRight); |
|
1661 |
setAnchor(l, a, Qt::AnchorTop, l, Qt::AnchorTop); |
|
1662 |
setAnchor(l, a, Qt::AnchorBottom, l, Qt::AnchorBottom); |
|
1663 |
setAnchor(l, b, Qt::AnchorTop, l, Qt::AnchorTop); |
|
1664 |
setAnchor(l, b, Qt::AnchorBottom, l, Qt::AnchorBottom); |
|
1665 |
QCOMPARE(layoutHasConflict(l), false); |
|
1666 |
||
1667 |
delete p; |
|
1668 |
} |
|
1669 |
||
1670 |
void tst_QGraphicsAnchorLayout::infiniteMaxSizes() |
|
1671 |
{ |
|
1672 |
QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout; |
|
1673 |
l->setContentsMargins(0, 0, 0, 0); |
|
1674 |
l->setSpacing(0); |
|
1675 |
||
1676 |
QSizeF min(10, 10); |
|
1677 |
QSizeF pref(50, 10); |
|
1678 |
QSizeF max(QWIDGETSIZE_MAX, 10); |
|
1679 |
||
1680 |
QGraphicsWidget *a = createItem(min, pref, max, "a"); |
|
1681 |
QGraphicsWidget *b = createItem(min, pref, max, "b"); |
|
1682 |
QGraphicsWidget *c = createItem(min, pref, max, "c"); |
|
1683 |
QGraphicsWidget *d = createItem(min, pref, max, "d"); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1684 |
QGraphicsWidget *e = createItem(min, pref, max, "e"); |
0 | 1685 |
|
1686 |
//<!-- Trunk --> |
|
1687 |
setAnchor(l, l, Qt::AnchorLeft, a, Qt::AnchorLeft, 0); |
|
1688 |
setAnchor(l, a, Qt::AnchorRight, b, Qt::AnchorLeft, 0); |
|
1689 |
setAnchor(l, b, Qt::AnchorRight, c, Qt::AnchorLeft, 0); |
|
1690 |
setAnchor(l, c, Qt::AnchorRight, d, Qt::AnchorLeft, 0); |
|
1691 |
setAnchor(l, d, Qt::AnchorRight, l, Qt::AnchorRight, 0); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1692 |
setAnchor(l, b, Qt::AnchorHorizontalCenter, e, Qt::AnchorLeft, 0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1693 |
setAnchor(l, e, Qt::AnchorRight, c, Qt::AnchorHorizontalCenter, 0); |
0 | 1694 |
|
1695 |
QGraphicsWidget p; |
|
1696 |
p.setLayout(l); |
|
1697 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1698 |
QCOMPARE(int(p.effectiveSizeHint(Qt::MaximumSize).width()), |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1699 |
QWIDGETSIZE_MAX); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1700 |
|
0 | 1701 |
p.resize(200, 10); |
1702 |
QCOMPARE(a->geometry(), QRectF(0, 0, 50, 10)); |
|
1703 |
QCOMPARE(b->geometry(), QRectF(50, 0, 50, 10)); |
|
1704 |
QCOMPARE(c->geometry(), QRectF(100, 0, 50, 10)); |
|
1705 |
QCOMPARE(d->geometry(), QRectF(150, 0, 50, 10)); |
|
1706 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1707 |
p.resize(1000, 10); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1708 |
QCOMPARE(a->geometry(), QRectF(0, 0, 250, 10)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1709 |
QCOMPARE(b->geometry(), QRectF(250, 0, 250, 10)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1710 |
QCOMPARE(c->geometry(), QRectF(500, 0, 250, 10)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1711 |
QCOMPARE(d->geometry(), QRectF(750, 0, 250, 10)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1712 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1713 |
p.resize(40000, 10); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1714 |
QCOMPARE(a->geometry(), QRectF(0, 0, 10000, 10)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1715 |
QCOMPARE(b->geometry(), QRectF(10000, 0, 10000, 10)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1716 |
QCOMPARE(c->geometry(), QRectF(20000, 0, 10000, 10)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1717 |
QCOMPARE(d->geometry(), QRectF(30000, 0, 10000, 10)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1718 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1719 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1720 |
void tst_QGraphicsAnchorLayout::simplifiableUnfeasible() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1721 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1722 |
QGraphicsWidget *a = createItem(QSizeF(70.0, 100.0), |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1723 |
QSizeF(100.0, 100.0), |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1724 |
QSizeF(100.0, 100.0), "A"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1725 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1726 |
QGraphicsWidget *b = createItem(QSizeF(110.0, 100.0), |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1727 |
QSizeF(150.0, 100.0), |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1728 |
QSizeF(190.0, 100.0), "B"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1729 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1730 |
QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1731 |
l->setContentsMargins(0, 0, 0, 0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1732 |
l->setSpacing(0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1733 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1734 |
l->addAnchor(l, Qt::AnchorTop, a, Qt::AnchorTop); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1735 |
l->addAnchor(a, Qt::AnchorBottom, b, Qt::AnchorTop); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1736 |
l->addAnchor(b, Qt::AnchorBottom, l, Qt::AnchorBottom); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1737 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1738 |
l->addAnchors(l, a, Qt::Horizontal); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1739 |
l->addAnchor(l, Qt::AnchorLeft, b, Qt::AnchorLeft); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1740 |
l->addAnchor(b, Qt::AnchorRight, a, Qt::AnchorRight); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1741 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1742 |
QCOMPARE(l->count(), 2); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1743 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1744 |
QGraphicsWidget p; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1745 |
p.setLayout(l); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1746 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1747 |
l->invalidate(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1748 |
QVERIFY(layoutHasConflict(l)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1749 |
if (hasSimplification) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1750 |
QVERIFY(!usedSimplex(l, Qt::Horizontal)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1751 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1752 |
// Now we make it valid |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1753 |
b->setMinimumWidth(100); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1754 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1755 |
l->invalidate(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1756 |
QVERIFY(!layoutHasConflict(l)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1757 |
if (hasSimplification) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1758 |
QVERIFY(!usedSimplex(l, Qt::Horizontal)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1759 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1760 |
// And make it invalid again |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1761 |
a->setPreferredWidth(70); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1762 |
a->setMaximumWidth(70); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1763 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1764 |
l->invalidate(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1765 |
QVERIFY(layoutHasConflict(l)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1766 |
if (hasSimplification) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1767 |
QVERIFY(!usedSimplex(l, Qt::Horizontal)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1768 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1769 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1770 |
/* |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1771 |
Test whether the anchor direction can prevent it from |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1772 |
being simplificated |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1773 |
*/ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1774 |
void tst_QGraphicsAnchorLayout::simplificationVsOrder() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1775 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1776 |
QSizeF min(10, 10); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1777 |
QSizeF pref(20, 10); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1778 |
QSizeF max(50, 10); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1779 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1780 |
QGraphicsWidget *a = createItem(min, pref, max, "A"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1781 |
QGraphicsWidget *b = createItem(min, pref, max, "B"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1782 |
QGraphicsWidget *c = createItem(min, pref, max, "C"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1783 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1784 |
QGraphicsWidget frame; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1785 |
QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout(&frame); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1786 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1787 |
// Bulk anchors |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1788 |
l->addAnchor(l, Qt::AnchorLeft, a, Qt::AnchorLeft); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1789 |
l->addAnchor(a, Qt::AnchorRight, b, Qt::AnchorLeft); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1790 |
l->addAnchor(b, Qt::AnchorLeft, c, Qt::AnchorLeft); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1791 |
l->addAnchor(c, Qt::AnchorRight, l, Qt::AnchorRight); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1792 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1793 |
// Problematic anchor, direction b->c |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1794 |
QGraphicsAnchor *anchor = l->addAnchor(b, Qt::AnchorRight, c, Qt::AnchorRight); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1795 |
anchor->setSpacing(5); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1796 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1797 |
l->effectiveSizeHint(Qt::MinimumSize); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1798 |
if (hasSimplification) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1799 |
QCOMPARE(usedSimplex(l, Qt::Horizontal), false); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1800 |
QCOMPARE(usedSimplex(l, Qt::Vertical), false); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1801 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1802 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1803 |
// Problematic anchor, direction c->b |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1804 |
delete anchor; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1805 |
anchor = l->addAnchor(c, Qt::AnchorRight, b, Qt::AnchorRight); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1806 |
anchor->setSpacing(5); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1807 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1808 |
l->effectiveSizeHint(Qt::MinimumSize); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1809 |
if (hasSimplification) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1810 |
QCOMPARE(usedSimplex(l, Qt::Horizontal), false); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1811 |
QCOMPARE(usedSimplex(l, Qt::Vertical), false); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1812 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1813 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1814 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1815 |
void tst_QGraphicsAnchorLayout::parallelSimplificationOfCenter() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1816 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1817 |
QSizeF min(10, 10); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1818 |
QSizeF pref(20, 10); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1819 |
QSizeF max(50, 10); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1820 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1821 |
QGraphicsWidget *a = createItem(min, pref, max, "A"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1822 |
QGraphicsWidget *b = createItem(min, pref, max, "B"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1823 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1824 |
QGraphicsWidget parent; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1825 |
QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout(&parent); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1826 |
l->setContentsMargins(0, 0, 0, 0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1827 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1828 |
l->addAnchor(l, Qt::AnchorLeft, a, Qt::AnchorLeft); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1829 |
l->addAnchor(l, Qt::AnchorRight, a, Qt::AnchorRight); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1830 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1831 |
l->addAnchor(a, Qt::AnchorHorizontalCenter, b, Qt::AnchorLeft); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1832 |
l->addAnchor(b, Qt::AnchorRight, a, Qt::AnchorRight); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1833 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1834 |
parent.resize(l->effectiveSizeHint(Qt::PreferredSize)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1835 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1836 |
QCOMPARE(a->geometry(), QRectF(0, 0, 40, 10)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1837 |
QCOMPARE(b->geometry(), QRectF(20, 0, 20, 10)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1838 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1839 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1840 |
/* |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1841 |
Test whether redundance of anchors (in this case by using addCornerAnchors), will |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1842 |
prevent simplification to take place when it should. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1843 |
*/ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1844 |
void tst_QGraphicsAnchorLayout::simplificationVsRedundance() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1845 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1846 |
QSizeF min(10, 10); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1847 |
QSizeF pref(20, 10); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1848 |
QSizeF max(50, 30); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1849 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1850 |
QGraphicsWidget *a = createItem(min, pref, max, "A"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1851 |
QGraphicsWidget *b = createItem(min, pref, max, "B"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1852 |
QGraphicsWidget *c = createItem(min, pref, max, "C"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1853 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1854 |
QGraphicsWidget frame; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1855 |
QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout(&frame); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1856 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1857 |
l->addCornerAnchors(a, Qt::TopLeftCorner, l, Qt::TopLeftCorner); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1858 |
l->addCornerAnchors(a, Qt::BottomLeftCorner, l, Qt::BottomLeftCorner); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1859 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1860 |
l->addCornerAnchors(b, Qt::TopLeftCorner, a, Qt::TopRightCorner); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1861 |
l->addCornerAnchors(b, Qt::TopRightCorner, l, Qt::TopRightCorner); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1862 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1863 |
l->addCornerAnchors(c, Qt::TopLeftCorner, b, Qt::BottomLeftCorner); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1864 |
l->addCornerAnchors(c, Qt::BottomLeftCorner, a, Qt::BottomRightCorner); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1865 |
l->addCornerAnchors(c, Qt::TopRightCorner, b, Qt::BottomRightCorner); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1866 |
l->addCornerAnchors(c, Qt::BottomRightCorner, l, Qt::BottomRightCorner); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1867 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1868 |
l->effectiveSizeHint(Qt::MinimumSize); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1869 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1870 |
QCOMPARE(layoutHasConflict(l), false); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1871 |
|
0 | 1872 |
if (!hasSimplification) |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1873 |
QEXPECT_FAIL("", "Test depends on simplification.", Abort); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1874 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1875 |
QCOMPARE(usedSimplex(l, Qt::Horizontal), false); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1876 |
QCOMPARE(usedSimplex(l, Qt::Vertical), false); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1877 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1878 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1879 |
/* |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1880 |
Avoid regression where the saved prefSize would be lost. This was |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1881 |
solved by saving the original spacing in the QGraphicsAnchorPrivate class |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1882 |
*/ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1883 |
void tst_QGraphicsAnchorLayout::spacingPersistency() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1884 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1885 |
QGraphicsWidget w; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1886 |
QGraphicsWidget *a = createItem(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1887 |
QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout(&w); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1888 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1889 |
l->addAnchors(l, a, Qt::Horizontal); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1890 |
QGraphicsAnchor *anchor = l->anchor(l, Qt::AnchorLeft, a, Qt::AnchorLeft); |
0 | 1891 |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1892 |
anchor->setSpacing(-30); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1893 |
QCOMPARE(anchor->spacing(), -30.0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1894 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1895 |
anchor->setSpacing(30); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1896 |
QCOMPARE(anchor->spacing(), 30.0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1897 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1898 |
anchor->setSizePolicy(QSizePolicy::Ignored); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1899 |
w.effectiveSizeHint(Qt::PreferredSize); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1900 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1901 |
QCOMPARE(anchor->spacing(), 30.0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1902 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1903 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1904 |
/* |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1905 |
Test whether a correct preferred size is set when a "snake" sequence is in parallel with the |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1906 |
layout or half of the layout. The tricky thing here is that all items on the snake should |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1907 |
keep their preferred sizes. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1908 |
*/ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1909 |
void tst_QGraphicsAnchorLayout::snakeParallelWithLayout() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1910 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1911 |
QSizeF min(10, 20); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1912 |
QSizeF pref(50, 20); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1913 |
QSizeF max(100, 20); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1914 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1915 |
QGraphicsWidget *a = createItem(max, max, max, "A"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1916 |
QGraphicsWidget *b = createItem(min, pref, max, "B"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1917 |
QGraphicsWidget *c = createItem(max, max, max, "C"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1918 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1919 |
QGraphicsWidget parent; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1920 |
QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout(&parent); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1921 |
l->setContentsMargins(0, 0, 0, 0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1922 |
l->setSpacing(0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1923 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1924 |
// First we'll do the case in parallel with the entire layout... |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1925 |
l->addAnchor(l, Qt::AnchorLeft, a, Qt::AnchorLeft); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1926 |
l->addAnchor(a, Qt::AnchorRight, b, Qt::AnchorRight); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1927 |
l->addAnchor(b, Qt::AnchorLeft, c, Qt::AnchorLeft); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1928 |
l->addAnchor(c, Qt::AnchorRight, l, Qt::AnchorRight); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1929 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1930 |
l->addAnchor(l, Qt::AnchorTop, a, Qt::AnchorTop); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1931 |
l->addAnchor(a, Qt::AnchorBottom, b, Qt::AnchorTop); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1932 |
l->addAnchor(b, Qt::AnchorBottom, c, Qt::AnchorTop); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1933 |
l->addAnchor(c, Qt::AnchorBottom, l, Qt::AnchorBottom); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1934 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1935 |
parent.resize(l->effectiveSizeHint(Qt::PreferredSize)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1936 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1937 |
// Note that A and C are fixed in the maximum size |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1938 |
QCOMPARE(l->geometry(), QRectF(QPointF(0, 0), QSizeF(150, 60))); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1939 |
QCOMPARE(a->geometry(), QRectF(QPointF(0, 0), max)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1940 |
QCOMPARE(b->geometry(), QRectF(QPointF(50, 20), pref)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1941 |
QCOMPARE(c->geometry(), QRectF(QPointF(50, 40), max)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1942 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1943 |
// Then, we change the "snake" to be in parallel with half of the layout |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1944 |
delete l->anchor(c, Qt::AnchorRight, l, Qt::AnchorRight); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1945 |
l->addAnchor(c, Qt::AnchorRight, l, Qt::AnchorHorizontalCenter); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1946 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1947 |
parent.resize(l->effectiveSizeHint(Qt::PreferredSize)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1948 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1949 |
QCOMPARE(l->geometry(), QRectF(QPointF(0, 0), QSizeF(300, 60))); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1950 |
QCOMPARE(a->geometry(), QRectF(QPointF(0, 0), max)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1951 |
QCOMPARE(b->geometry(), QRectF(QPointF(50, 20), pref)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1952 |
QCOMPARE(c->geometry(), QRectF(QPointF(50, 40), max)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1953 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1954 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1955 |
/* |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1956 |
Avoid regression where the sizeHint constraints would not be |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1957 |
created for a parallel anchor that included the first layout half |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1958 |
*/ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1959 |
void tst_QGraphicsAnchorLayout::parallelToHalfLayout() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1960 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1961 |
QGraphicsWidget *a = createItem(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1962 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1963 |
QGraphicsWidget w; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1964 |
QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout(&w); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1965 |
l->setContentsMargins(10, 10, 10, 10); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1966 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1967 |
l->addAnchors(l, a, Qt::Vertical); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1968 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1969 |
QGraphicsAnchor *anchor; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1970 |
anchor = l->addAnchor(l, Qt::AnchorLeft, a, Qt::AnchorLeft); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1971 |
anchor->setSpacing(5); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1972 |
anchor = l->addAnchor(l, Qt::AnchorHorizontalCenter, a, Qt::AnchorRight); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1973 |
anchor->setSpacing(-5); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1974 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1975 |
const QSizeF minimumSizeHint = w.effectiveSizeHint(Qt::MinimumSize); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1976 |
const QSizeF preferredSizeHint = w.effectiveSizeHint(Qt::PreferredSize); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1977 |
const QSizeF maximumSizeHint = w.effectiveSizeHint(Qt::MaximumSize); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1978 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1979 |
const QSizeF overhead = QSizeF(10 + 5 + 5, 10) * 2; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1980 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1981 |
QCOMPARE(minimumSizeHint, QSizeF(200, 100) + overhead); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1982 |
QCOMPARE(preferredSizeHint, QSizeF(300, 100) + overhead); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1983 |
QCOMPARE(maximumSizeHint, QSizeF(400, 100) + overhead); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1984 |
} |
0 | 1985 |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1986 |
void tst_QGraphicsAnchorLayout::globalSpacing() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1987 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1988 |
QGraphicsWidget *a = createItem(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1989 |
QGraphicsWidget *b = createItem(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1990 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1991 |
QGraphicsWidget w; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1992 |
QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout(&w); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1993 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1994 |
l->addCornerAnchors(l, Qt::TopLeftCorner, a, Qt::TopLeftCorner); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1995 |
l->addCornerAnchors(a, Qt::BottomRightCorner, b, Qt::TopLeftCorner); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1996 |
l->addCornerAnchors(b, Qt::BottomRightCorner, l, Qt::BottomRightCorner); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1997 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1998 |
w.resize(w.effectiveSizeHint(Qt::PreferredSize)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1999 |
qreal vSpacing = b->geometry().top() - a->geometry().bottom(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2000 |
qreal hSpacing = b->geometry().left() - a->geometry().right(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2001 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2002 |
// Set spacings manually |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2003 |
l->setVerticalSpacing(vSpacing + 10); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2004 |
l->setHorizontalSpacing(hSpacing + 5); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2005 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2006 |
w.resize(w.effectiveSizeHint(Qt::PreferredSize)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2007 |
qreal newVSpacing = b->geometry().top() - a->geometry().bottom(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2008 |
qreal newHSpacing = b->geometry().left() - a->geometry().right(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2009 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2010 |
QCOMPARE(newVSpacing, vSpacing + 10); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2011 |
QCOMPARE(newHSpacing, hSpacing + 5); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2012 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2013 |
// Set a negative spacing. This will unset the previous spacing and |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2014 |
// bring back the widget-defined spacing. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2015 |
l->setSpacing(-1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2016 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2017 |
w.resize(w.effectiveSizeHint(Qt::PreferredSize)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2018 |
newVSpacing = b->geometry().top() - a->geometry().bottom(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2019 |
newHSpacing = b->geometry().left() - a->geometry().right(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2020 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2021 |
QCOMPARE(newVSpacing, vSpacing); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2022 |
QCOMPARE(newHSpacing, hSpacing); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2023 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2024 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2025 |
void tst_QGraphicsAnchorLayout::graphicsAnchorHandling() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2026 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2027 |
QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2028 |
QGraphicsWidget *a = createItem(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2029 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2030 |
l->addAnchors(l, a); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2031 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2032 |
QGraphicsAnchor *layoutAnchor = l->anchor(l, Qt::AnchorTop, l, Qt::AnchorBottom); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2033 |
QGraphicsAnchor *itemAnchor = l->anchor(a, Qt::AnchorTop, a, Qt::AnchorBottom); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2034 |
QGraphicsAnchor *invalidAnchor = l->anchor(a, Qt::AnchorTop, l, Qt::AnchorBottom); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2035 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2036 |
// Ensure none of these anchors are accessible. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2037 |
QVERIFY(layoutAnchor == 0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2038 |
QVERIFY(itemAnchor == 0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2039 |
QVERIFY(invalidAnchor == 0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2040 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2041 |
// Hook the anchors to a QObject |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2042 |
QObject object; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2043 |
QGraphicsAnchor *userAnchor = l->anchor(l, Qt::AnchorTop, a, Qt::AnchorTop); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2044 |
userAnchor->setParent(&object); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2045 |
userAnchor = l->anchor(l, Qt::AnchorBottom, a, Qt::AnchorBottom); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2046 |
userAnchor->setParent(&object); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2047 |
userAnchor = l->anchor(l, Qt::AnchorRight, a, Qt::AnchorRight); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2048 |
userAnchor->setParent(&object); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2049 |
userAnchor = l->anchor(l, Qt::AnchorLeft, a, Qt::AnchorLeft); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2050 |
userAnchor->setParent(&object); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2051 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2052 |
QCOMPARE(object.children().size(), 4); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2053 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2054 |
// Delete layout, this will cause all anchors to be deleted internally. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2055 |
// We expect the public QGraphicsAnchor instances to be deleted too. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2056 |
delete l; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2057 |
QCOMPARE(object.children().size(), 0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2058 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2059 |
delete a; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2060 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2061 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2062 |
void tst_QGraphicsAnchorLayout::invalidHierarchyCheck() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2063 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2064 |
QGraphicsWidget window(0, Qt::Window); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2065 |
QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2066 |
window.setLayout(l); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2067 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2068 |
QCOMPARE(l->count(), 0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2069 |
QTest::ignoreMessage(QtWarningMsg, "QGraphicsAnchorLayout::addAnchor(): " |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2070 |
"You cannot add the parent of the layout to the layout."); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2071 |
QVERIFY(!l->addAnchor(l, Qt::AnchorLeft, &window, Qt::AnchorLeft)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2072 |
QTest::ignoreMessage(QtWarningMsg, "QGraphicsAnchorLayout::addAnchor(): " |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2073 |
"You cannot add the parent of the layout to the layout."); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2074 |
l->addAnchors(l, &window); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2075 |
QTest::ignoreMessage(QtWarningMsg, "QGraphicsAnchorLayout::addAnchor(): " |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2076 |
"You cannot add the parent of the layout to the layout."); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2077 |
l->addCornerAnchors(l, Qt::TopLeftCorner, &window, Qt::TopLeftCorner); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2078 |
QCOMPARE(l->count(), 0); |
0 | 2079 |
} |
2080 |
||
2081 |
QTEST_MAIN(tst_QGraphicsAnchorLayout) |
|
2082 |
#include "tst_qgraphicsanchorlayout.moc" |