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