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