author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Mon, 04 Oct 2010 01:19:32 +0300 | |
changeset 37 | 758a864f9613 |
parent 18 | 2f34d5167611 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the QtGui module of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
#include "qglobal.h" |
|
43 |
||
44 |
#ifndef QT_NO_GRAPHICSVIEW |
|
45 |
||
46 |
#include <math.h> |
|
47 |
||
48 |
#include "qgraphicslayoutitem.h" |
|
49 |
#include "qgridlayoutengine_p.h" |
|
50 |
#include "qstyleoption.h" |
|
51 |
#include "qvarlengtharray.h" |
|
52 |
||
53 |
#include <QtDebug> |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
54 |
#include <QtCore/qmath.h> |
0 | 55 |
|
56 |
QT_BEGIN_NAMESPACE |
|
57 |
||
58 |
template <typename T> |
|
59 |
static void insertOrRemoveItems(QVector<T> &items, int index, int delta) |
|
60 |
{ |
|
61 |
int count = items.count(); |
|
62 |
if (index < count) { |
|
63 |
if (delta > 0) { |
|
64 |
items.insert(index, delta, T()); |
|
65 |
} else if (delta < 0) { |
|
66 |
items.remove(index, qMin(-delta, count - index)); |
|
67 |
} |
|
68 |
} |
|
69 |
} |
|
70 |
||
71 |
static qreal growthFactorBelowPreferredSize(qreal desired, qreal sumAvailable, qreal sumDesired) |
|
72 |
{ |
|
73 |
Q_ASSERT(sumDesired != 0.0); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
74 |
return desired * qPow(sumAvailable / sumDesired, desired / sumDesired); |
0 | 75 |
} |
76 |
||
77 |
static qreal fixedDescent(qreal descent, qreal ascent, qreal targetSize) |
|
78 |
{ |
|
79 |
if (descent < 0.0) |
|
80 |
return -1.0; |
|
81 |
||
82 |
Q_ASSERT(descent >= 0.0); |
|
83 |
Q_ASSERT(ascent >= 0.0); |
|
84 |
Q_ASSERT(targetSize >= ascent + descent); |
|
85 |
||
86 |
qreal extra = targetSize - (ascent + descent); |
|
87 |
return descent + (extra / 2.0); |
|
88 |
} |
|
89 |
||
90 |
static qreal compare(const QGridLayoutBox &box1, const QGridLayoutBox &box2, int which) |
|
91 |
{ |
|
92 |
qreal size1 = box1.q_sizes(which); |
|
93 |
qreal size2 = box2.q_sizes(which); |
|
94 |
||
95 |
if (which == MaximumSize) { |
|
96 |
return size2 - size1; |
|
97 |
} else { |
|
98 |
return size1 - size2; |
|
99 |
} |
|
100 |
} |
|
101 |
||
102 |
void QGridLayoutBox::add(const QGridLayoutBox &other, int stretch, qreal spacing) |
|
103 |
{ |
|
104 |
Q_ASSERT(q_minimumDescent < 0.0); |
|
105 |
||
106 |
q_minimumSize += other.q_minimumSize + spacing; |
|
107 |
q_preferredSize += other.q_preferredSize + spacing; |
|
108 |
q_maximumSize += ((stretch == 0) ? other.q_preferredSize : other.q_maximumSize) + spacing; |
|
109 |
} |
|
110 |
||
111 |
void QGridLayoutBox::combine(const QGridLayoutBox &other) |
|
112 |
{ |
|
113 |
q_minimumDescent = qMax(q_minimumDescent, other.q_minimumDescent); |
|
114 |
q_minimumAscent = qMax(q_minimumAscent, other.q_minimumAscent); |
|
115 |
||
116 |
q_minimumSize = qMax(q_minimumAscent + q_minimumDescent, |
|
117 |
qMax(q_minimumSize, other.q_minimumSize)); |
|
118 |
qreal maxMax; |
|
119 |
if (q_maximumSize == FLT_MAX && other.q_maximumSize != FLT_MAX) |
|
120 |
maxMax = other.q_maximumSize; |
|
121 |
else if (other.q_maximumSize == FLT_MAX && q_maximumSize != FLT_MAX) |
|
122 |
maxMax = q_maximumSize; |
|
123 |
else |
|
124 |
maxMax = qMax(q_maximumSize, other.q_maximumSize); |
|
125 |
||
126 |
q_maximumSize = qMax(q_minimumSize, maxMax); |
|
127 |
q_preferredSize = qBound(q_minimumSize, qMax(q_preferredSize, other.q_preferredSize), |
|
128 |
q_maximumSize); |
|
129 |
} |
|
130 |
||
131 |
void QGridLayoutBox::normalize() |
|
132 |
{ |
|
133 |
q_maximumSize = qMax(qreal(0.0), q_maximumSize); |
|
134 |
q_minimumSize = qBound(qreal(0.0), q_minimumSize, q_maximumSize); |
|
135 |
q_preferredSize = qBound(q_minimumSize, q_preferredSize, q_maximumSize); |
|
136 |
q_minimumDescent = qMin(q_minimumDescent, q_minimumSize); |
|
137 |
||
138 |
Q_ASSERT((q_minimumDescent < 0.0) == (q_minimumAscent < 0.0)); |
|
139 |
} |
|
140 |
||
141 |
#ifdef QT_DEBUG |
|
142 |
void QGridLayoutBox::dump(int indent) const |
|
143 |
{ |
|
144 |
qDebug("%*sBox (%g <= %g <= %g [%g/%g])", indent, "", q_minimumSize, q_preferredSize, |
|
145 |
q_maximumSize, q_minimumAscent, q_minimumDescent); |
|
146 |
} |
|
147 |
#endif |
|
148 |
||
149 |
bool operator==(const QGridLayoutBox &box1, const QGridLayoutBox &box2) |
|
150 |
{ |
|
151 |
for (int i = 0; i < NSizes; ++i) { |
|
152 |
if (box1.q_sizes(i) != box2.q_sizes(i)) |
|
153 |
return false; |
|
154 |
} |
|
155 |
return box1.q_minimumDescent == box2.q_minimumDescent |
|
156 |
&& box1.q_minimumAscent == box2.q_minimumAscent; |
|
157 |
} |
|
158 |
||
159 |
void QGridLayoutRowData::reset(int count) |
|
160 |
{ |
|
161 |
ignore.fill(false, count); |
|
162 |
boxes.fill(QGridLayoutBox(), count); |
|
163 |
multiCellMap.clear(); |
|
164 |
stretches.fill(0, count); |
|
165 |
spacings.fill(0.0, count); |
|
166 |
hasIgnoreFlag = false; |
|
167 |
} |
|
168 |
||
169 |
void QGridLayoutRowData::distributeMultiCells() |
|
170 |
{ |
|
171 |
MultiCellMap::const_iterator i = multiCellMap.constBegin(); |
|
172 |
for (; i != multiCellMap.constEnd(); ++i) { |
|
173 |
int start = i.key().first; |
|
174 |
int span = i.key().second; |
|
175 |
int end = start + span; |
|
176 |
const QGridLayoutBox &box = i.value().q_box; |
|
177 |
int stretch = i.value().q_stretch; |
|
178 |
||
179 |
QGridLayoutBox totalBox = this->totalBox(start, end); |
|
180 |
QVarLengthArray<QGridLayoutBox> extras(span); |
|
181 |
QVarLengthArray<qreal> dummy(span); |
|
182 |
QVarLengthArray<qreal> newSizes(span); |
|
183 |
||
184 |
for (int j = 0; j < NSizes; ++j) { |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
185 |
qreal extra = compare(box, totalBox, j); |
0 | 186 |
if (extra > 0.0) { |
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
187 |
calculateGeometries(start, end, box.q_sizes(j), dummy.data(), newSizes.data(), |
0 | 188 |
0, totalBox); |
189 |
||
190 |
for (int k = 0; k < span; ++k) |
|
191 |
extras[k].q_sizes(j) = newSizes[k]; |
|
192 |
} |
|
193 |
} |
|
194 |
||
195 |
for (int k = 0; k < span; ++k) { |
|
196 |
boxes[start + k].combine(extras[k]); |
|
197 |
stretches[start + k] = qMax(stretches[start + k], stretch); |
|
198 |
} |
|
199 |
} |
|
200 |
multiCellMap.clear(); |
|
201 |
} |
|
202 |
||
203 |
void QGridLayoutRowData::calculateGeometries(int start, int end, qreal targetSize, qreal *positions, |
|
204 |
qreal *sizes, qreal *descents, |
|
205 |
const QGridLayoutBox &totalBox) |
|
206 |
{ |
|
207 |
Q_ASSERT(end > start); |
|
208 |
||
209 |
targetSize = qBound(totalBox.q_minimumSize, targetSize, totalBox.q_maximumSize); |
|
210 |
||
211 |
int n = end - start; |
|
212 |
QVarLengthArray<qreal> newSizes(n); |
|
213 |
QVarLengthArray<qreal> factors(n); |
|
214 |
qreal sumFactors = 0.0; |
|
215 |
int sumStretches = 0; |
|
216 |
qreal sumAvailable; |
|
217 |
||
218 |
for (int i = 0; i < n; ++i) { |
|
219 |
if (stretches[start + i] > 0) |
|
220 |
sumStretches += stretches[start + i]; |
|
221 |
} |
|
222 |
||
223 |
if (targetSize < totalBox.q_preferredSize) { |
|
224 |
stealBox(start, end, MinimumSize, positions, sizes); |
|
225 |
||
226 |
sumAvailable = targetSize - totalBox.q_minimumSize; |
|
227 |
if (sumAvailable > 0.0) { |
|
228 |
qreal sumDesired = totalBox.q_preferredSize - totalBox.q_minimumSize; |
|
229 |
||
230 |
for (int i = 0; i < n; ++i) { |
|
231 |
if (ignore.testBit(start + i)) { |
|
232 |
factors[i] = 0.0; |
|
233 |
continue; |
|
234 |
} |
|
235 |
||
236 |
const QGridLayoutBox &box = boxes.at(start + i); |
|
237 |
qreal desired = box.q_preferredSize - box.q_minimumSize; |
|
238 |
factors[i] = growthFactorBelowPreferredSize(desired, sumAvailable, sumDesired); |
|
239 |
sumFactors += factors[i]; |
|
240 |
} |
|
241 |
||
242 |
for (int i = 0; i < n; ++i) { |
|
243 |
Q_ASSERT(sumFactors > 0.0); |
|
244 |
qreal delta = sumAvailable * factors[i] / sumFactors; |
|
245 |
newSizes[i] = sizes[i] + delta; |
|
246 |
} |
|
247 |
} |
|
248 |
} else { |
|
249 |
stealBox(start, end, PreferredSize, positions, sizes); |
|
250 |
||
251 |
sumAvailable = targetSize - totalBox.q_preferredSize; |
|
252 |
if (sumAvailable > 0.0) { |
|
37
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
253 |
qreal sumCurrentAvailable = sumAvailable; |
0 | 254 |
bool somethingHasAMaximumSize = false; |
255 |
||
256 |
qreal sumPreferredSizes = 0.0; |
|
257 |
for (int i = 0; i < n; ++i) |
|
258 |
sumPreferredSizes += sizes[i]; |
|
259 |
||
260 |
for (int i = 0; i < n; ++i) { |
|
261 |
if (ignore.testBit(start + i)) { |
|
262 |
newSizes[i] = 0.0; |
|
263 |
factors[i] = 0.0; |
|
264 |
continue; |
|
265 |
} |
|
266 |
||
267 |
const QGridLayoutBox &box = boxes.at(start + i); |
|
268 |
qreal desired = box.q_maximumSize - box.q_preferredSize; |
|
269 |
if (desired == 0.0) { |
|
270 |
newSizes[i] = sizes[i]; |
|
271 |
factors[i] = 0.0; |
|
272 |
} else { |
|
273 |
Q_ASSERT(desired > 0.0); |
|
274 |
||
275 |
int stretch = stretches[start + i]; |
|
276 |
if (sumStretches == 0) { |
|
277 |
if (hasIgnoreFlag) { |
|
278 |
factors[i] = (stretch < 0) ? 1.0 : 0.0; |
|
279 |
} else { |
|
280 |
factors[i] = (stretch < 0) ? sizes[i] : 0.0; |
|
281 |
} |
|
282 |
} else if (stretch == sumStretches) { |
|
283 |
factors[i] = 1.0; |
|
284 |
} else if (stretch <= 0) { |
|
285 |
factors[i] = 0.0; |
|
286 |
} else { |
|
287 |
qreal ultimatePreferredSize; |
|
288 |
qreal ultimateSumPreferredSizes; |
|
289 |
qreal x = ((stretch * sumPreferredSizes) |
|
290 |
- (sumStretches * box.q_preferredSize)) |
|
291 |
/ (sumStretches - stretch); |
|
292 |
if (x >= 0.0) { |
|
293 |
ultimatePreferredSize = box.q_preferredSize + x; |
|
294 |
ultimateSumPreferredSizes = sumPreferredSizes + x; |
|
295 |
} else { |
|
296 |
ultimatePreferredSize = box.q_preferredSize; |
|
297 |
ultimateSumPreferredSizes = (sumStretches * box.q_preferredSize) |
|
298 |
/ stretch; |
|
299 |
} |
|
300 |
||
301 |
/* |
|
302 |
We multiply these by 1.5 to give some space for a smooth transition |
|
303 |
(at the expense of the stretch factors, which are not fully respected |
|
304 |
during the transition). |
|
305 |
*/ |
|
306 |
ultimatePreferredSize = ultimatePreferredSize * 3 / 2; |
|
307 |
ultimateSumPreferredSizes = ultimateSumPreferredSizes * 3 / 2; |
|
308 |
||
309 |
qreal ultimateFactor = (stretch * ultimateSumPreferredSizes |
|
310 |
/ sumStretches) |
|
311 |
- (box.q_preferredSize); |
|
37
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
312 |
qreal transitionalFactor = sumCurrentAvailable |
0 | 313 |
* (ultimatePreferredSize - box.q_preferredSize) |
314 |
/ (ultimateSumPreferredSizes |
|
315 |
- sumPreferredSizes); |
|
316 |
||
37
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
317 |
qreal alpha = qMin(sumCurrentAvailable, |
0 | 318 |
ultimateSumPreferredSizes - sumPreferredSizes); |
319 |
qreal beta = ultimateSumPreferredSizes - sumPreferredSizes; |
|
320 |
||
321 |
factors[i] = ((alpha * ultimateFactor) |
|
322 |
+ ((beta - alpha) * transitionalFactor)) / beta; |
|
323 |
} |
|
324 |
sumFactors += factors[i]; |
|
37
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
325 |
if (desired < sumCurrentAvailable) |
0 | 326 |
somethingHasAMaximumSize = true; |
327 |
||
328 |
newSizes[i] = -1.0; |
|
329 |
} |
|
330 |
} |
|
331 |
||
332 |
bool keepGoing = somethingHasAMaximumSize; |
|
333 |
while (keepGoing) { |
|
334 |
keepGoing = false; |
|
335 |
||
336 |
for (int i = 0; i < n; ++i) { |
|
337 |
if (newSizes[i] >= 0.0) |
|
338 |
continue; |
|
339 |
||
340 |
const QGridLayoutBox &box = boxes.at(start + i); |
|
37
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
341 |
qreal avail = sumCurrentAvailable * factors[i] / sumFactors; |
0 | 342 |
if (sizes[i] + avail >= box.q_maximumSize) { |
343 |
newSizes[i] = box.q_maximumSize; |
|
37
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
344 |
sumCurrentAvailable -= box.q_maximumSize - sizes[i]; |
0 | 345 |
sumFactors -= factors[i]; |
37
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
346 |
keepGoing = (sumCurrentAvailable > 0.0); |
0 | 347 |
if (!keepGoing) |
348 |
break; |
|
349 |
} |
|
350 |
} |
|
351 |
} |
|
352 |
||
353 |
for (int i = 0; i < n; ++i) { |
|
354 |
if (newSizes[i] < 0.0) { |
|
355 |
qreal delta = (sumFactors == 0.0) ? 0.0 |
|
37
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
356 |
: sumCurrentAvailable * factors[i] / sumFactors; |
0 | 357 |
newSizes[i] = sizes[i] + delta; |
358 |
} |
|
359 |
} |
|
360 |
} |
|
361 |
} |
|
362 |
||
363 |
if (sumAvailable > 0) { |
|
364 |
qreal offset = 0; |
|
365 |
for (int i = 0; i < n; ++i) { |
|
366 |
qreal delta = newSizes[i] - sizes[i]; |
|
367 |
positions[i] += offset; |
|
368 |
sizes[i] += delta; |
|
369 |
offset += delta; |
|
370 |
} |
|
371 |
||
372 |
#if 0 // some "pixel allocation" |
|
373 |
int surplus = targetSize - (positions[n - 1] + sizes[n - 1]); |
|
374 |
Q_ASSERT(surplus >= 0 && surplus <= n); |
|
375 |
||
376 |
int prevSurplus = -1; |
|
377 |
while (surplus > 0 && surplus != prevSurplus) { |
|
378 |
prevSurplus = surplus; |
|
379 |
||
380 |
int offset = 0; |
|
381 |
for (int i = 0; i < n; ++i) { |
|
382 |
const QGridLayoutBox &box = boxes.at(start + i); |
|
383 |
int delta = (!ignore.testBit(start + i) && surplus > 0 |
|
384 |
&& factors[i] > 0 && sizes[i] < box.q_maximumSize) |
|
385 |
? 1 : 0; |
|
386 |
||
387 |
positions[i] += offset; |
|
388 |
sizes[i] += delta; |
|
389 |
offset += delta; |
|
390 |
surplus -= delta; |
|
391 |
} |
|
392 |
} |
|
393 |
Q_ASSERT(surplus == 0); |
|
394 |
#endif |
|
395 |
} |
|
396 |
||
397 |
if (descents) { |
|
398 |
for (int i = 0; i < n; ++i) { |
|
399 |
if (ignore.testBit(start + i)) |
|
400 |
continue; |
|
401 |
const QGridLayoutBox &box = boxes.at(start + i); |
|
402 |
descents[i] = fixedDescent(box.q_minimumDescent, box.q_minimumAscent, sizes[i]); |
|
403 |
} |
|
404 |
} |
|
405 |
} |
|
406 |
||
407 |
QGridLayoutBox QGridLayoutRowData::totalBox(int start, int end) const |
|
408 |
{ |
|
409 |
QGridLayoutBox result; |
|
410 |
if (start < end) { |
|
411 |
result.q_maximumSize = 0.0; |
|
412 |
qreal nextSpacing = 0.0; |
|
413 |
for (int i = start; i < end; ++i) { |
|
414 |
result.add(boxes.at(i), stretches.at(i), nextSpacing); |
|
415 |
nextSpacing = spacings.at(i); |
|
416 |
} |
|
417 |
} |
|
418 |
return result; |
|
419 |
} |
|
420 |
||
421 |
void QGridLayoutRowData::stealBox(int start, int end, int which, qreal *positions, qreal *sizes) |
|
422 |
{ |
|
423 |
qreal offset = 0.0; |
|
424 |
qreal nextSpacing = 0.0; |
|
425 |
||
426 |
for (int i = start; i < end; ++i) { |
|
427 |
qreal avail = 0.0; |
|
428 |
||
429 |
if (!ignore.testBit(i)) { |
|
430 |
const QGridLayoutBox &box = boxes.at(i); |
|
431 |
avail = box.q_sizes(which); |
|
432 |
offset += nextSpacing; |
|
433 |
nextSpacing = spacings.at(i); |
|
434 |
} |
|
435 |
||
436 |
*positions++ = offset; |
|
437 |
*sizes++ = avail; |
|
438 |
offset += avail; |
|
439 |
} |
|
440 |
} |
|
441 |
||
442 |
#ifdef QT_DEBUG |
|
443 |
void QGridLayoutRowData::dump(int indent) const |
|
444 |
{ |
|
445 |
qDebug("%*sData", indent, ""); |
|
446 |
||
447 |
for (int i = 0; i < ignore.count(); ++i) { |
|
448 |
qDebug("%*s Row %d (stretch %d, spacing %g)", indent, "", i, stretches.at(i), |
|
449 |
spacings.at(i)); |
|
450 |
if (ignore.testBit(i)) |
|
451 |
qDebug("%*s Ignored", indent, ""); |
|
452 |
boxes.at(i).dump(indent + 2); |
|
453 |
} |
|
454 |
||
455 |
MultiCellMap::const_iterator it = multiCellMap.constBegin(); |
|
456 |
while (it != multiCellMap.constEnd()) { |
|
457 |
qDebug("%*s Multi-cell entry <%d, %d> (stretch %d)", indent, "", it.key().first, |
|
458 |
it.key().second, it.value().q_stretch); |
|
459 |
it.value().q_box.dump(indent + 2); |
|
460 |
} |
|
461 |
} |
|
462 |
#endif |
|
463 |
||
464 |
QGridLayoutItem::QGridLayoutItem(QGridLayoutEngine *engine, QGraphicsLayoutItem *layoutItem, |
|
465 |
int row, int column, int rowSpan, int columnSpan, |
|
466 |
Qt::Alignment alignment, int itemAtIndex) |
|
467 |
: q_engine(engine), q_layoutItem(layoutItem), q_alignment(alignment) |
|
468 |
{ |
|
469 |
q_firstRows[Hor] = column; |
|
470 |
q_firstRows[Ver] = row; |
|
471 |
q_rowSpans[Hor] = columnSpan; |
|
472 |
q_rowSpans[Ver] = rowSpan; |
|
473 |
q_stretches[Hor] = -1; |
|
474 |
q_stretches[Ver] = -1; |
|
475 |
||
476 |
q_engine->insertItem(this, itemAtIndex); |
|
477 |
} |
|
478 |
||
479 |
int QGridLayoutItem::firstRow(Qt::Orientation orientation) const |
|
480 |
{ |
|
481 |
return q_firstRows[orientation == Qt::Vertical]; |
|
482 |
} |
|
483 |
||
484 |
int QGridLayoutItem::firstColumn(Qt::Orientation orientation) const |
|
485 |
{ |
|
486 |
return q_firstRows[orientation == Qt::Horizontal]; |
|
487 |
} |
|
488 |
||
489 |
int QGridLayoutItem::lastRow(Qt::Orientation orientation) const |
|
490 |
{ |
|
491 |
return firstRow(orientation) + rowSpan(orientation) - 1; |
|
492 |
} |
|
493 |
||
494 |
int QGridLayoutItem::lastColumn(Qt::Orientation orientation) const |
|
495 |
{ |
|
496 |
return firstColumn(orientation) + columnSpan(orientation) - 1; |
|
497 |
} |
|
498 |
||
499 |
int QGridLayoutItem::rowSpan(Qt::Orientation orientation) const |
|
500 |
{ |
|
501 |
return q_rowSpans[orientation == Qt::Vertical]; |
|
502 |
} |
|
503 |
||
504 |
int QGridLayoutItem::columnSpan(Qt::Orientation orientation) const |
|
505 |
{ |
|
506 |
return q_rowSpans[orientation == Qt::Horizontal]; |
|
507 |
} |
|
508 |
||
509 |
void QGridLayoutItem::setFirstRow(int row, Qt::Orientation orientation) |
|
510 |
{ |
|
511 |
q_firstRows[orientation == Qt::Vertical] = row; |
|
512 |
} |
|
513 |
||
514 |
void QGridLayoutItem::setRowSpan(int rowSpan, Qt::Orientation orientation) |
|
515 |
{ |
|
516 |
q_rowSpans[orientation == Qt::Vertical] = rowSpan; |
|
517 |
} |
|
518 |
||
519 |
int QGridLayoutItem::stretchFactor(Qt::Orientation orientation) const |
|
520 |
{ |
|
521 |
int stretch = q_stretches[orientation == Qt::Vertical]; |
|
522 |
if (stretch >= 0) |
|
523 |
return stretch; |
|
524 |
||
525 |
QSizePolicy::Policy policy = sizePolicy(orientation); |
|
526 |
||
527 |
if (policy & QSizePolicy::ExpandFlag) { |
|
528 |
return 1; |
|
529 |
} else if (policy & QSizePolicy::GrowFlag) { |
|
530 |
return -1; // because we max it up |
|
531 |
} else { |
|
532 |
return 0; |
|
533 |
} |
|
534 |
} |
|
535 |
||
536 |
void QGridLayoutItem::setStretchFactor(int stretch, Qt::Orientation orientation) |
|
537 |
{ |
|
538 |
Q_ASSERT(stretch >= 0); // ### deal with too big stretches |
|
539 |
q_stretches[orientation == Qt::Vertical] = stretch; |
|
540 |
} |
|
541 |
||
542 |
QSizePolicy::Policy QGridLayoutItem::sizePolicy(Qt::Orientation orientation) const |
|
543 |
{ |
|
544 |
QSizePolicy sizePolicy(q_layoutItem->sizePolicy()); |
|
545 |
return (orientation == Qt::Horizontal) ? sizePolicy.horizontalPolicy() |
|
546 |
: sizePolicy.verticalPolicy(); |
|
547 |
} |
|
548 |
||
37
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
549 |
/* |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
550 |
returns true if the size policy returns true for either hasHeightForWidth() |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
551 |
or hasWidthForHeight() |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
552 |
*/ |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
553 |
bool QGridLayoutItem::hasDynamicConstraint() const |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
554 |
{ |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
555 |
return QGraphicsLayoutItemPrivate::get(q_layoutItem)->hasHeightForWidth() |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
556 |
|| QGraphicsLayoutItemPrivate::get(q_layoutItem)->hasWidthForHeight(); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
557 |
} |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
558 |
|
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
559 |
Qt::Orientation QGridLayoutItem::dynamicConstraintOrientation() const |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
560 |
{ |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
561 |
if (QGraphicsLayoutItemPrivate::get(q_layoutItem)->hasHeightForWidth()) |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
562 |
return Qt::Vertical; |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
563 |
else //if (QGraphicsLayoutItemPrivate::get(q_layoutItem)->hasWidthForHeight()) |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
564 |
return Qt::Horizontal; |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
565 |
} |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
566 |
|
0 | 567 |
QSizePolicy::ControlTypes QGridLayoutItem::controlTypes(LayoutSide /* side */) const |
568 |
{ |
|
569 |
return q_layoutItem->sizePolicy().controlType(); |
|
570 |
} |
|
571 |
||
572 |
QSizeF QGridLayoutItem::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const |
|
573 |
{ |
|
574 |
return q_layoutItem->effectiveSizeHint(which, constraint); |
|
575 |
} |
|
576 |
||
577 |
QGridLayoutBox QGridLayoutItem::box(Qt::Orientation orientation, qreal constraint) const |
|
578 |
{ |
|
579 |
QGridLayoutBox result; |
|
580 |
QSizePolicy::Policy policy = sizePolicy(orientation); |
|
581 |
||
582 |
if (orientation == Qt::Horizontal) { |
|
583 |
QSizeF constraintSize(-1.0, constraint); |
|
584 |
||
585 |
result.q_preferredSize = sizeHint(Qt::PreferredSize, constraintSize).width(); |
|
586 |
||
587 |
if (policy & QSizePolicy::ShrinkFlag) { |
|
588 |
result.q_minimumSize = sizeHint(Qt::MinimumSize, constraintSize).width(); |
|
589 |
} else { |
|
590 |
result.q_minimumSize = result.q_preferredSize; |
|
591 |
} |
|
592 |
||
593 |
if (policy & (QSizePolicy::GrowFlag | QSizePolicy::ExpandFlag)) { |
|
594 |
result.q_maximumSize = sizeHint(Qt::MaximumSize, constraintSize).width(); |
|
595 |
} else { |
|
596 |
result.q_maximumSize = result.q_preferredSize; |
|
597 |
} |
|
598 |
} else { |
|
599 |
QSizeF constraintSize(constraint, -1.0); |
|
600 |
||
601 |
result.q_preferredSize = sizeHint(Qt::PreferredSize, constraintSize).height(); |
|
602 |
||
603 |
if (policy & QSizePolicy::ShrinkFlag) { |
|
604 |
result.q_minimumSize = sizeHint(Qt::MinimumSize, constraintSize).height(); |
|
605 |
} else { |
|
606 |
result.q_minimumSize = result.q_preferredSize; |
|
607 |
} |
|
608 |
||
609 |
if (policy & (QSizePolicy::GrowFlag | QSizePolicy::ExpandFlag)) { |
|
610 |
result.q_maximumSize = sizeHint(Qt::MaximumSize, constraintSize).height(); |
|
611 |
} else { |
|
612 |
result.q_maximumSize = result.q_preferredSize; |
|
613 |
} |
|
614 |
||
615 |
result.q_minimumDescent = sizeHint(Qt::MinimumDescent, constraintSize).height(); |
|
616 |
if (result.q_minimumDescent >= 0.0) |
|
617 |
result.q_minimumAscent = result.q_minimumSize - result.q_minimumDescent; |
|
618 |
} |
|
619 |
if (policy & QSizePolicy::IgnoreFlag) |
|
620 |
result.q_preferredSize = result.q_minimumSize; |
|
621 |
||
622 |
return result; |
|
623 |
} |
|
624 |
||
625 |
QRectF QGridLayoutItem::geometryWithin(qreal x, qreal y, qreal width, qreal height, |
|
626 |
qreal rowDescent) const |
|
627 |
{ |
|
628 |
rowDescent = -1.0; // ### This disables the descent |
|
629 |
||
630 |
QGridLayoutBox vBox = box(Qt::Vertical); |
|
631 |
if (vBox.q_minimumDescent < 0.0 || rowDescent < 0.0) { |
|
632 |
qreal cellWidth = width; |
|
633 |
qreal cellHeight = height; |
|
634 |
||
37
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
635 |
QSize constraint; |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
636 |
if (hasDynamicConstraint()) { |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
637 |
if (dynamicConstraintOrientation() == Qt::Vertical) |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
638 |
constraint.setWidth(cellWidth); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
639 |
else |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
640 |
constraint.setHeight(cellHeight); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
641 |
} |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
642 |
QSizeF size = effectiveMaxSize(constraint).boundedTo(QSizeF(cellWidth, cellHeight)); |
0 | 643 |
width = size.width(); |
644 |
height = size.height(); |
|
645 |
||
646 |
Qt::Alignment align = q_engine->effectiveAlignment(this); |
|
647 |
switch (align & Qt::AlignHorizontal_Mask) { |
|
648 |
case Qt::AlignHCenter: |
|
649 |
x += (cellWidth - width)/2; |
|
650 |
break; |
|
651 |
case Qt::AlignRight: |
|
652 |
x += cellWidth - width; |
|
653 |
break; |
|
654 |
default: |
|
655 |
break; |
|
656 |
} |
|
657 |
switch (align & Qt::AlignVertical_Mask) { |
|
658 |
case Qt::AlignVCenter: |
|
659 |
y += (cellHeight - height)/2; |
|
660 |
break; |
|
661 |
case Qt::AlignBottom: |
|
662 |
y += cellHeight - height; |
|
663 |
break; |
|
664 |
default: |
|
665 |
break; |
|
666 |
} |
|
667 |
return QRectF(x, y, width, height); |
|
668 |
} else { |
|
669 |
qreal descent = vBox.q_minimumDescent; |
|
670 |
qreal ascent = vBox.q_minimumSize - descent; |
|
671 |
return QRectF(x, y + height - rowDescent - ascent, width, ascent + descent); |
|
672 |
} |
|
673 |
} |
|
674 |
||
675 |
void QGridLayoutItem::setGeometry(const QRectF &rect) |
|
676 |
{ |
|
677 |
q_layoutItem->setGeometry(rect); |
|
678 |
} |
|
679 |
||
680 |
void QGridLayoutItem::transpose() |
|
681 |
{ |
|
682 |
qSwap(q_firstRows[Hor], q_firstRows[Ver]); |
|
683 |
qSwap(q_rowSpans[Hor], q_rowSpans[Ver]); |
|
684 |
qSwap(q_stretches[Hor], q_stretches[Ver]); |
|
685 |
} |
|
686 |
||
687 |
void QGridLayoutItem::insertOrRemoveRows(int row, int delta, Qt::Orientation orientation) |
|
688 |
{ |
|
689 |
int oldFirstRow = firstRow(orientation); |
|
690 |
if (oldFirstRow >= row) { |
|
691 |
setFirstRow(oldFirstRow + delta, orientation); |
|
692 |
} else if (lastRow(orientation) >= row) { |
|
693 |
setRowSpan(rowSpan(orientation) + delta, orientation); |
|
694 |
} |
|
695 |
} |
|
696 |
/*! |
|
697 |
\internal |
|
698 |
returns the effective maximumSize, will take the sizepolicy into |
|
699 |
consideration. (i.e. if sizepolicy does not have QSizePolicy::Grow, then |
|
700 |
maxSizeHint will be the preferredSize) |
|
701 |
Note that effectiveSizeHint does not take sizePolicy into consideration, |
|
702 |
(since it only evaluates the hints, as the name implies) |
|
703 |
*/ |
|
37
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
704 |
QSizeF QGridLayoutItem::effectiveMaxSize(const QSizeF &constraint) const |
0 | 705 |
{ |
37
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
706 |
QSizeF size = constraint; |
0 | 707 |
bool vGrow = (sizePolicy(Qt::Vertical) & QSizePolicy::GrowFlag) == QSizePolicy::GrowFlag; |
708 |
bool hGrow = (sizePolicy(Qt::Horizontal) & QSizePolicy::GrowFlag) == QSizePolicy::GrowFlag; |
|
709 |
if (!vGrow || !hGrow) { |
|
37
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
710 |
QSizeF pref = layoutItem()->effectiveSizeHint(Qt::PreferredSize, constraint); |
0 | 711 |
if (!vGrow) |
712 |
size.setHeight(pref.height()); |
|
713 |
if (!hGrow) |
|
714 |
size.setWidth(pref.width()); |
|
715 |
} |
|
716 |
||
717 |
if (!size.isValid()) { |
|
37
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
718 |
QSizeF maxSize = layoutItem()->effectiveSizeHint(Qt::MaximumSize, constraint); |
0 | 719 |
if (size.width() == -1) |
720 |
size.setWidth(maxSize.width()); |
|
721 |
if (size.height() == -1) |
|
722 |
size.setHeight(maxSize.height()); |
|
723 |
} |
|
724 |
return size; |
|
725 |
} |
|
726 |
||
727 |
#ifdef QT_DEBUG |
|
728 |
void QGridLayoutItem::dump(int indent) const |
|
729 |
{ |
|
730 |
qDebug("%*s%p (%d, %d) %d x %d", indent, "", q_layoutItem, firstRow(), firstColumn(), |
|
731 |
rowSpan(), columnSpan()); |
|
732 |
||
733 |
if (q_stretches[Hor] >= 0) |
|
734 |
qDebug("%*s Horizontal stretch: %d", indent, "", q_stretches[Hor]); |
|
735 |
if (q_stretches[Ver] >= 0) |
|
736 |
qDebug("%*s Vertical stretch: %d", indent, "", q_stretches[Ver]); |
|
737 |
if (q_alignment != 0) |
|
738 |
qDebug("%*s Alignment: %x", indent, "", uint(q_alignment)); |
|
739 |
qDebug("%*s Horizontal size policy: %x Vertical size policy: %x", |
|
740 |
indent, "", sizePolicy(Qt::Horizontal), sizePolicy(Qt::Vertical)); |
|
741 |
} |
|
742 |
#endif |
|
743 |
||
744 |
void QGridLayoutRowInfo::insertOrRemoveRows(int row, int delta) |
|
745 |
{ |
|
746 |
count += delta; |
|
747 |
||
748 |
insertOrRemoveItems(stretches, row, delta); |
|
749 |
insertOrRemoveItems(spacings, row, delta); |
|
750 |
insertOrRemoveItems(alignments, row, delta); |
|
751 |
insertOrRemoveItems(boxes, row, delta); |
|
752 |
} |
|
753 |
||
754 |
#ifdef QT_DEBUG |
|
755 |
void QGridLayoutRowInfo::dump(int indent) const |
|
756 |
{ |
|
757 |
qDebug("%*sInfo (count: %d)", indent, "", count); |
|
758 |
for (int i = 0; i < count; ++i) { |
|
759 |
QString message; |
|
760 |
||
761 |
if (stretches.value(i).value() >= 0) |
|
762 |
message += QString::fromAscii(" stretch %1").arg(stretches.value(i).value()); |
|
763 |
if (spacings.value(i).value() >= 0.0) |
|
764 |
message += QString::fromAscii(" spacing %1").arg(spacings.value(i).value()); |
|
765 |
if (alignments.value(i) != 0) |
|
766 |
message += QString::fromAscii(" alignment %1").arg(int(alignments.value(i)), 16); |
|
767 |
||
768 |
if (!message.isEmpty() || boxes.value(i) != QGridLayoutBox()) { |
|
769 |
qDebug("%*s Row %d:%s", indent, "", i, qPrintable(message)); |
|
770 |
if (boxes.value(i) != QGridLayoutBox()) |
|
771 |
boxes.value(i).dump(indent + 1); |
|
772 |
} |
|
773 |
} |
|
774 |
} |
|
775 |
#endif |
|
776 |
||
777 |
QGridLayoutEngine::QGridLayoutEngine() |
|
778 |
{ |
|
779 |
m_visualDirection = Qt::LeftToRight; |
|
780 |
invalidate(); |
|
781 |
} |
|
782 |
||
783 |
int QGridLayoutEngine::rowCount(Qt::Orientation orientation) const |
|
784 |
{ |
|
785 |
return q_infos[orientation == Qt::Vertical].count; |
|
786 |
} |
|
787 |
||
788 |
int QGridLayoutEngine::columnCount(Qt::Orientation orientation) const |
|
789 |
{ |
|
790 |
return q_infos[orientation == Qt::Horizontal].count; |
|
791 |
} |
|
792 |
||
793 |
int QGridLayoutEngine::itemCount() const |
|
794 |
{ |
|
795 |
return q_items.count(); |
|
796 |
} |
|
797 |
||
798 |
QGridLayoutItem *QGridLayoutEngine::itemAt(int index) const |
|
799 |
{ |
|
800 |
Q_ASSERT(index >= 0 && index < itemCount()); |
|
801 |
return q_items.at(index); |
|
802 |
} |
|
803 |
||
804 |
int QGridLayoutEngine::effectiveFirstRow(Qt::Orientation orientation) const |
|
805 |
{ |
|
806 |
ensureEffectiveFirstAndLastRows(); |
|
807 |
return q_cachedEffectiveFirstRows[orientation == Qt::Vertical]; |
|
808 |
} |
|
809 |
||
810 |
int QGridLayoutEngine::effectiveLastRow(Qt::Orientation orientation) const |
|
811 |
{ |
|
812 |
ensureEffectiveFirstAndLastRows(); |
|
813 |
return q_cachedEffectiveLastRows[orientation == Qt::Vertical]; |
|
814 |
} |
|
815 |
||
816 |
void QGridLayoutEngine::setSpacing(qreal spacing, Qt::Orientations orientations) |
|
817 |
{ |
|
818 |
Q_ASSERT(spacing >= 0.0); |
|
819 |
if (orientations & Qt::Horizontal) |
|
820 |
q_defaultSpacings[Hor].setUserValue(spacing); |
|
821 |
if (orientations & Qt::Vertical) |
|
822 |
q_defaultSpacings[Ver].setUserValue(spacing); |
|
823 |
||
824 |
invalidate(); |
|
825 |
} |
|
826 |
||
827 |
qreal QGridLayoutEngine::spacing(const QLayoutStyleInfo &styleInfo, Qt::Orientation orientation) const |
|
828 |
{ |
|
829 |
if (q_defaultSpacings[orientation == Qt::Vertical].isDefault()) { |
|
830 |
QStyle *style = styleInfo.style(); |
|
831 |
QStyleOption option; |
|
832 |
option.initFrom(styleInfo.widget()); |
|
833 |
qreal defaultSpacing = (qreal)style->pixelMetric(orientation == Qt::Vertical ? QStyle::PM_LayoutVerticalSpacing |
|
834 |
: QStyle::PM_LayoutHorizontalSpacing, &option, styleInfo.widget()); |
|
835 |
q_defaultSpacings[orientation == Qt::Vertical].setCachedValue(defaultSpacing); |
|
836 |
} |
|
837 |
return q_defaultSpacings[orientation == Qt::Vertical].value(); |
|
838 |
} |
|
839 |
||
840 |
void QGridLayoutEngine::setRowSpacing(int row, qreal spacing, Qt::Orientation orientation) |
|
841 |
{ |
|
842 |
Q_ASSERT(row >= 0); |
|
843 |
||
844 |
QGridLayoutRowInfo &rowInfo = q_infos[orientation == Qt::Vertical]; |
|
845 |
if (row >= rowInfo.spacings.count()) |
|
846 |
rowInfo.spacings.resize(row + 1); |
|
847 |
if (spacing >= 0) |
|
848 |
rowInfo.spacings[row].setUserValue(spacing); |
|
849 |
else |
|
850 |
rowInfo.spacings[row] = QLayoutParameter<qreal>(); |
|
851 |
invalidate(); |
|
852 |
} |
|
853 |
||
854 |
qreal QGridLayoutEngine::rowSpacing(int row, Qt::Orientation orientation) const |
|
855 |
{ |
|
856 |
QLayoutParameter<qreal> spacing = q_infos[orientation == Qt::Vertical].spacings.value(row); |
|
857 |
if (!spacing.isDefault()) |
|
858 |
return spacing.value(); |
|
859 |
return q_defaultSpacings[orientation == Qt::Vertical].value(); |
|
860 |
} |
|
861 |
||
862 |
void QGridLayoutEngine::setRowStretchFactor(int row, int stretch, Qt::Orientation orientation) |
|
863 |
{ |
|
864 |
Q_ASSERT(row >= 0); |
|
865 |
Q_ASSERT(stretch >= 0); |
|
866 |
||
867 |
maybeExpandGrid(row, -1, orientation); |
|
868 |
||
869 |
QGridLayoutRowInfo &rowInfo = q_infos[orientation == Qt::Vertical]; |
|
870 |
if (row >= rowInfo.stretches.count()) |
|
871 |
rowInfo.stretches.resize(row + 1); |
|
872 |
rowInfo.stretches[row].setUserValue(stretch); |
|
873 |
} |
|
874 |
||
875 |
int QGridLayoutEngine::rowStretchFactor(int row, Qt::Orientation orientation) const |
|
876 |
{ |
|
877 |
QStretchParameter stretch = q_infos[orientation == Qt::Vertical].stretches.value(row); |
|
878 |
if (!stretch.isDefault()) |
|
879 |
return stretch.value(); |
|
880 |
return 0; |
|
881 |
} |
|
882 |
||
883 |
void QGridLayoutEngine::setStretchFactor(QGraphicsLayoutItem *layoutItem, int stretch, |
|
884 |
Qt::Orientation orientation) |
|
885 |
{ |
|
886 |
Q_ASSERT(stretch >= 0); |
|
887 |
||
888 |
if (QGridLayoutItem *item = findLayoutItem(layoutItem)) |
|
889 |
item->setStretchFactor(stretch, orientation); |
|
890 |
} |
|
891 |
||
892 |
int QGridLayoutEngine::stretchFactor(QGraphicsLayoutItem *layoutItem, Qt::Orientation orientation) const |
|
893 |
{ |
|
894 |
if (QGridLayoutItem *item = findLayoutItem(layoutItem)) |
|
895 |
return item->stretchFactor(orientation); |
|
896 |
return 0; |
|
897 |
} |
|
898 |
||
899 |
void QGridLayoutEngine::setRowSizeHint(Qt::SizeHint which, int row, qreal size, |
|
900 |
Qt::Orientation orientation) |
|
901 |
{ |
|
902 |
Q_ASSERT(row >= 0); |
|
903 |
Q_ASSERT(size >= 0.0); |
|
904 |
||
905 |
maybeExpandGrid(row, -1, orientation); |
|
906 |
||
907 |
QGridLayoutRowInfo &rowInfo = q_infos[orientation == Qt::Vertical]; |
|
908 |
if (row >= rowInfo.boxes.count()) |
|
909 |
rowInfo.boxes.resize(row + 1); |
|
910 |
rowInfo.boxes[row].q_sizes(which) = size; |
|
911 |
} |
|
912 |
||
913 |
qreal QGridLayoutEngine::rowSizeHint(Qt::SizeHint which, int row, Qt::Orientation orientation) const |
|
914 |
{ |
|
915 |
return q_infos[orientation == Qt::Vertical].boxes.value(row).q_sizes(which); |
|
916 |
} |
|
917 |
||
918 |
void QGridLayoutEngine::setRowAlignment(int row, Qt::Alignment alignment, |
|
919 |
Qt::Orientation orientation) |
|
920 |
{ |
|
921 |
Q_ASSERT(row >= 0); |
|
922 |
||
923 |
maybeExpandGrid(row, -1, orientation); |
|
924 |
||
925 |
QGridLayoutRowInfo &rowInfo = q_infos[orientation == Qt::Vertical]; |
|
926 |
if (row >= rowInfo.alignments.count()) |
|
927 |
rowInfo.alignments.resize(row + 1); |
|
928 |
rowInfo.alignments[row] = alignment; |
|
929 |
} |
|
930 |
||
931 |
Qt::Alignment QGridLayoutEngine::rowAlignment(int row, Qt::Orientation orientation) const |
|
932 |
{ |
|
933 |
Q_ASSERT(row >= 0); |
|
934 |
return q_infos[orientation == Qt::Vertical].alignments.value(row); |
|
935 |
} |
|
936 |
||
937 |
void QGridLayoutEngine::setAlignment(QGraphicsLayoutItem *layoutItem, Qt::Alignment alignment) |
|
938 |
{ |
|
939 |
if (QGridLayoutItem *item = findLayoutItem(layoutItem)) |
|
940 |
item->setAlignment(alignment); |
|
941 |
invalidate(); |
|
942 |
} |
|
943 |
||
944 |
Qt::Alignment QGridLayoutEngine::alignment(QGraphicsLayoutItem *layoutItem) const |
|
945 |
{ |
|
946 |
if (QGridLayoutItem *item = findLayoutItem(layoutItem)) |
|
947 |
return item->alignment(); |
|
948 |
return 0; |
|
949 |
} |
|
950 |
||
951 |
Qt::Alignment QGridLayoutEngine::effectiveAlignment(const QGridLayoutItem *layoutItem) const |
|
952 |
{ |
|
953 |
Qt::Alignment align = layoutItem->alignment(); |
|
954 |
if (!(align & Qt::AlignVertical_Mask)) { |
|
955 |
// no vertical alignment, respect the row alignment |
|
956 |
int y = layoutItem->firstRow(); |
|
957 |
align |= (rowAlignment(y, Qt::Vertical) & Qt::AlignVertical_Mask); |
|
958 |
} |
|
959 |
if (!(align & Qt::AlignHorizontal_Mask)) { |
|
960 |
// no horizontal alignment, respect the column alignment |
|
961 |
int x = layoutItem->firstColumn(); |
|
962 |
align |= (rowAlignment(x, Qt::Horizontal) & Qt::AlignHorizontal_Mask); |
|
963 |
} |
|
964 |
return align; |
|
965 |
} |
|
966 |
||
967 |
/*! |
|
968 |
\internal |
|
969 |
The \a index is only used by QGraphicsLinearLayout to ensure that itemAt() reflects the order |
|
970 |
of visual arrangement. Strictly speaking it does not have to, but most people expect it to. |
|
971 |
(And if it didn't we would have to add itemArrangedAt(int index) or something..) |
|
972 |
*/ |
|
973 |
void QGridLayoutEngine::insertItem(QGridLayoutItem *item, int index) |
|
974 |
{ |
|
975 |
maybeExpandGrid(item->lastRow(), item->lastColumn()); |
|
976 |
||
977 |
if (index == -1) |
|
978 |
q_items.append(item); |
|
979 |
else |
|
980 |
q_items.insert(index, item); |
|
981 |
||
982 |
for (int i = item->firstRow(); i <= item->lastRow(); ++i) { |
|
983 |
for (int j = item->firstColumn(); j <= item->lastColumn(); ++j) { |
|
984 |
if (itemAt(i, j)) |
|
985 |
qWarning("QGridLayoutEngine::addItem: Cell (%d, %d) already taken", i, j); |
|
986 |
setItemAt(i, j, item); |
|
987 |
} |
|
988 |
} |
|
989 |
} |
|
990 |
||
991 |
void QGridLayoutEngine::addItem(QGridLayoutItem *item) |
|
992 |
{ |
|
993 |
insertItem(item, -1); |
|
994 |
} |
|
995 |
||
996 |
void QGridLayoutEngine::removeItem(QGridLayoutItem *item) |
|
997 |
{ |
|
998 |
Q_ASSERT(q_items.contains(item)); |
|
999 |
||
1000 |
invalidate(); |
|
1001 |
||
1002 |
for (int i = item->firstRow(); i <= item->lastRow(); ++i) { |
|
1003 |
for (int j = item->firstColumn(); j <= item->lastColumn(); ++j) { |
|
1004 |
if (itemAt(i, j) == item) |
|
1005 |
setItemAt(i, j, 0); |
|
1006 |
} |
|
1007 |
} |
|
1008 |
||
1009 |
q_items.removeAll(item); |
|
1010 |
} |
|
1011 |
||
1012 |
QGridLayoutItem *QGridLayoutEngine::findLayoutItem(QGraphicsLayoutItem *layoutItem) const |
|
1013 |
{ |
|
1014 |
for (int i = q_items.count() - 1; i >= 0; --i) { |
|
1015 |
QGridLayoutItem *item = q_items.at(i); |
|
1016 |
if (item->layoutItem() == layoutItem) |
|
1017 |
return item; |
|
1018 |
} |
|
1019 |
return 0; |
|
1020 |
} |
|
1021 |
||
1022 |
QGridLayoutItem *QGridLayoutEngine::itemAt(int row, int column, Qt::Orientation orientation) const |
|
1023 |
{ |
|
1024 |
if (orientation == Qt::Horizontal) |
|
1025 |
qSwap(row, column); |
|
1026 |
if (uint(row) >= uint(rowCount()) || uint(column) >= uint(columnCount())) |
|
1027 |
return 0; |
|
1028 |
return q_grid.at((row * internalGridColumnCount()) + column); |
|
1029 |
} |
|
1030 |
||
1031 |
void QGridLayoutEngine::invalidate() |
|
1032 |
{ |
|
1033 |
q_cachedEffectiveFirstRows[Hor] = -1; |
|
1034 |
q_cachedEffectiveFirstRows[Ver] = -1; |
|
1035 |
q_cachedEffectiveLastRows[Hor] = -1; |
|
1036 |
q_cachedEffectiveLastRows[Ver] = -1; |
|
1037 |
q_cachedDataForStyleInfo.invalidate(); |
|
1038 |
q_cachedSize = QSizeF(); |
|
37
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1039 |
q_cachedConstraintOrientation = UnknownConstraint; |
0 | 1040 |
} |
1041 |
||
1042 |
static void visualRect(QRectF *geom, Qt::LayoutDirection dir, const QRectF &contentsRect) |
|
1043 |
{ |
|
1044 |
if (dir == Qt::RightToLeft) |
|
1045 |
geom->moveRight(contentsRect.right() - (geom->left() - contentsRect.left())); |
|
1046 |
} |
|
1047 |
||
1048 |
void QGridLayoutEngine::setGeometries(const QLayoutStyleInfo &styleInfo, |
|
1049 |
const QRectF &contentsGeometry) |
|
1050 |
{ |
|
1051 |
if (rowCount() < 1 || columnCount() < 1) |
|
1052 |
return; |
|
1053 |
||
1054 |
ensureGeometries(styleInfo, contentsGeometry.size()); |
|
1055 |
||
1056 |
for (int i = q_items.count() - 1; i >= 0; --i) { |
|
1057 |
QGridLayoutItem *item = q_items.at(i); |
|
1058 |
||
1059 |
qreal x = q_xx[item->firstColumn()]; |
|
1060 |
qreal y = q_yy[item->firstRow()]; |
|
1061 |
qreal width = q_widths[item->lastColumn()]; |
|
1062 |
qreal height = q_heights[item->lastRow()]; |
|
1063 |
||
1064 |
if (item->columnSpan() != 1) |
|
1065 |
width += q_xx[item->lastColumn()] - x; |
|
1066 |
if (item->rowSpan() != 1) |
|
1067 |
height += q_yy[item->lastRow()] - y; |
|
1068 |
||
1069 |
QRectF geom = item->geometryWithin(contentsGeometry.x() + x, contentsGeometry.y() + y, |
|
1070 |
width, height, q_descents[item->lastRow()]); |
|
1071 |
visualRect(&geom, visualDirection(), contentsGeometry); |
|
1072 |
item->setGeometry(geom); |
|
1073 |
} |
|
1074 |
} |
|
1075 |
||
1076 |
// ### candidate for deletion |
|
1077 |
QRectF QGridLayoutEngine::cellRect(const QLayoutStyleInfo &styleInfo, |
|
1078 |
const QRectF &contentsGeometry, int row, int column, int rowSpan, |
|
1079 |
int columnSpan) const |
|
1080 |
{ |
|
1081 |
if (uint(row) >= uint(rowCount()) || uint(column) >= uint(columnCount()) |
|
1082 |
|| rowSpan < 1 || columnSpan < 1) |
|
1083 |
return QRectF(); |
|
1084 |
||
1085 |
ensureGeometries(styleInfo, contentsGeometry.size()); |
|
1086 |
||
1087 |
int lastColumn = qMax(column + columnSpan, columnCount()) - 1; |
|
1088 |
int lastRow = qMax(row + rowSpan, rowCount()) - 1; |
|
1089 |
||
1090 |
qreal x = q_xx[column]; |
|
1091 |
qreal y = q_yy[row]; |
|
1092 |
qreal width = q_widths[lastColumn]; |
|
1093 |
qreal height = q_heights[lastRow]; |
|
1094 |
||
1095 |
if (columnSpan != 1) |
|
1096 |
width += q_xx[lastColumn] - x; |
|
1097 |
if (rowSpan != 1) |
|
1098 |
height += q_yy[lastRow] - y; |
|
1099 |
||
1100 |
return QRectF(contentsGeometry.x() + x, contentsGeometry.y() + y, width, height); |
|
1101 |
} |
|
1102 |
||
1103 |
QSizeF QGridLayoutEngine::sizeHint(const QLayoutStyleInfo &styleInfo, Qt::SizeHint which, |
|
37
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1104 |
const QSizeF &constraint) const |
0 | 1105 |
{ |
1106 |
ensureColumnAndRowData(styleInfo); |
|
1107 |
||
37
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1108 |
if (hasDynamicConstraint()) |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1109 |
return dynamicallyConstrainedSizeHint(which, constraint); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1110 |
|
0 | 1111 |
switch (which) { |
1112 |
case Qt::MinimumSize: |
|
1113 |
return QSizeF(q_totalBoxes[Hor].q_minimumSize, q_totalBoxes[Ver].q_minimumSize); |
|
1114 |
case Qt::PreferredSize: |
|
1115 |
return QSizeF(q_totalBoxes[Hor].q_preferredSize, q_totalBoxes[Ver].q_preferredSize); |
|
1116 |
case Qt::MaximumSize: |
|
1117 |
return QSizeF(q_totalBoxes[Hor].q_maximumSize, q_totalBoxes[Ver].q_maximumSize); |
|
1118 |
case Qt::MinimumDescent: |
|
1119 |
return QSizeF(-1.0, q_totalBoxes[Hor].q_minimumDescent); // ### doesn't work |
|
1120 |
default: |
|
1121 |
break; |
|
1122 |
} |
|
1123 |
return QSizeF(); |
|
1124 |
} |
|
1125 |
||
1126 |
QSizePolicy::ControlTypes QGridLayoutEngine::controlTypes(LayoutSide side) const |
|
1127 |
{ |
|
1128 |
Qt::Orientation orientation = (side == Top || side == Bottom) ? Qt::Vertical : Qt::Horizontal; |
|
1129 |
int row = (side == Top || side == Left) ? effectiveFirstRow(orientation) |
|
1130 |
: effectiveLastRow(orientation); |
|
1131 |
QSizePolicy::ControlTypes result = 0; |
|
1132 |
||
1133 |
for (int column = columnCount(orientation) - 1; column >= 0; --column) { |
|
1134 |
if (QGridLayoutItem *item = itemAt(row, column, orientation)) |
|
1135 |
result |= item->controlTypes(side); |
|
1136 |
} |
|
1137 |
return result; |
|
1138 |
} |
|
1139 |
||
1140 |
void QGridLayoutEngine::transpose() |
|
1141 |
{ |
|
1142 |
invalidate(); |
|
1143 |
||
1144 |
for (int i = q_items.count() - 1; i >= 0; --i) |
|
1145 |
q_items.at(i)->transpose(); |
|
1146 |
||
1147 |
qSwap(q_defaultSpacings[Hor], q_defaultSpacings[Ver]); |
|
1148 |
qSwap(q_infos[Hor], q_infos[Ver]); |
|
1149 |
||
1150 |
regenerateGrid(); |
|
1151 |
} |
|
1152 |
||
1153 |
void QGridLayoutEngine::setVisualDirection(Qt::LayoutDirection direction) |
|
1154 |
{ |
|
1155 |
m_visualDirection = direction; |
|
1156 |
} |
|
1157 |
||
1158 |
Qt::LayoutDirection QGridLayoutEngine::visualDirection() const |
|
1159 |
{ |
|
1160 |
return m_visualDirection; |
|
1161 |
} |
|
1162 |
||
1163 |
#ifdef QT_DEBUG |
|
1164 |
void QGridLayoutEngine::dump(int indent) const |
|
1165 |
{ |
|
1166 |
qDebug("%*sEngine", indent, ""); |
|
1167 |
||
1168 |
qDebug("%*s Items (%d)", indent, "", q_items.count()); |
|
1169 |
int i; |
|
1170 |
for (i = 0; i < q_items.count(); ++i) |
|
1171 |
q_items.at(i)->dump(indent + 2); |
|
1172 |
||
1173 |
qDebug("%*s Grid (%d x %d)", indent, "", internalGridRowCount(), |
|
1174 |
internalGridColumnCount()); |
|
1175 |
for (int row = 0; row < internalGridRowCount(); ++row) { |
|
1176 |
QString message = QLatin1String("[ "); |
|
1177 |
for (int column = 0; column < internalGridColumnCount(); ++column) { |
|
1178 |
message += QString::number(q_items.indexOf(itemAt(row, column))).rightJustified(3); |
|
1179 |
message += QLatin1Char(' '); |
|
1180 |
} |
|
1181 |
message += QLatin1Char(']'); |
|
1182 |
qDebug("%*s %s", indent, "", qPrintable(message)); |
|
1183 |
} |
|
1184 |
||
1185 |
if (q_defaultSpacings[Hor].value() >= 0.0 || q_defaultSpacings[Ver].value() >= 0.0) |
|
1186 |
qDebug("%*s Default spacings: %g %g", indent, "", q_defaultSpacings[Hor].value(), |
|
1187 |
q_defaultSpacings[Ver].value()); |
|
1188 |
||
1189 |
qDebug("%*s Column and row info", indent, ""); |
|
1190 |
q_infos[Hor].dump(indent + 2); |
|
1191 |
q_infos[Ver].dump(indent + 2); |
|
1192 |
||
1193 |
qDebug("%*s Column and row data", indent, ""); |
|
1194 |
q_columnData.dump(indent + 2); |
|
1195 |
q_rowData.dump(indent + 2); |
|
1196 |
||
1197 |
qDebug("%*s Geometries output", indent, ""); |
|
1198 |
QVector<qreal> *cellPos = &q_yy; |
|
1199 |
for (int pass = 0; pass < 2; ++pass) { |
|
1200 |
QString message; |
|
1201 |
for (i = 0; i < cellPos->count(); ++i) { |
|
1202 |
message += QLatin1String((message.isEmpty() ? "[" : ", ")); |
|
1203 |
message += QString::number(cellPos->at(i)); |
|
1204 |
} |
|
1205 |
message += QLatin1Char(']'); |
|
1206 |
qDebug("%*s %s %s", indent, "", (pass == 0 ? "rows:" : "columns:"), qPrintable(message)); |
|
1207 |
cellPos = &q_xx; |
|
1208 |
} |
|
1209 |
} |
|
1210 |
#endif |
|
1211 |
||
1212 |
void QGridLayoutEngine::maybeExpandGrid(int row, int column, Qt::Orientation orientation) |
|
1213 |
{ |
|
1214 |
invalidate(); // ### move out of here? |
|
1215 |
||
1216 |
if (orientation == Qt::Horizontal) |
|
1217 |
qSwap(row, column); |
|
1218 |
||
1219 |
if (row < rowCount() && column < columnCount()) |
|
1220 |
return; |
|
1221 |
||
1222 |
int oldGridRowCount = internalGridRowCount(); |
|
1223 |
int oldGridColumnCount = internalGridColumnCount(); |
|
1224 |
||
1225 |
q_infos[Ver].count = qMax(row + 1, rowCount()); |
|
1226 |
q_infos[Hor].count = qMax(column + 1, columnCount()); |
|
1227 |
||
1228 |
int newGridRowCount = internalGridRowCount(); |
|
1229 |
int newGridColumnCount = internalGridColumnCount(); |
|
1230 |
||
1231 |
int newGridSize = newGridRowCount * newGridColumnCount; |
|
1232 |
if (newGridSize != q_grid.count()) { |
|
1233 |
q_grid.resize(newGridSize); |
|
1234 |
||
1235 |
if (newGridColumnCount != oldGridColumnCount) { |
|
1236 |
for (int i = oldGridRowCount - 1; i >= 1; --i) { |
|
1237 |
for (int j = oldGridColumnCount - 1; j >= 0; --j) { |
|
1238 |
int oldIndex = (i * oldGridColumnCount) + j; |
|
1239 |
int newIndex = (i * newGridColumnCount) + j; |
|
1240 |
||
1241 |
Q_ASSERT(newIndex > oldIndex); |
|
1242 |
q_grid[newIndex] = q_grid[oldIndex]; |
|
1243 |
q_grid[oldIndex] = 0; |
|
1244 |
} |
|
1245 |
} |
|
1246 |
} |
|
1247 |
} |
|
1248 |
} |
|
1249 |
||
1250 |
void QGridLayoutEngine::regenerateGrid() |
|
1251 |
{ |
|
1252 |
q_grid.fill(0); |
|
1253 |
||
1254 |
for (int i = q_items.count() - 1; i >= 0; --i) { |
|
1255 |
QGridLayoutItem *item = q_items.at(i); |
|
1256 |
||
1257 |
for (int j = item->firstRow(); j <= item->lastRow(); ++j) { |
|
1258 |
for (int k = item->firstColumn(); k <= item->lastColumn(); ++k) { |
|
1259 |
setItemAt(j, k, item); |
|
1260 |
} |
|
1261 |
} |
|
1262 |
} |
|
1263 |
} |
|
1264 |
||
1265 |
void QGridLayoutEngine::setItemAt(int row, int column, QGridLayoutItem *item) |
|
1266 |
{ |
|
1267 |
Q_ASSERT(row >= 0 && row < rowCount()); |
|
1268 |
Q_ASSERT(column >= 0 && column < columnCount()); |
|
1269 |
q_grid[(row * internalGridColumnCount()) + column] = item; |
|
1270 |
} |
|
1271 |
||
1272 |
void QGridLayoutEngine::insertOrRemoveRows(int row, int delta, Qt::Orientation orientation) |
|
1273 |
{ |
|
1274 |
int oldRowCount = rowCount(orientation); |
|
1275 |
Q_ASSERT(uint(row) <= uint(oldRowCount)); |
|
1276 |
||
1277 |
invalidate(); |
|
1278 |
||
1279 |
// appending rows (or columns) is easy |
|
1280 |
if (row == oldRowCount && delta > 0) { |
|
1281 |
maybeExpandGrid(oldRowCount + delta - 1, -1, orientation); |
|
1282 |
return; |
|
1283 |
} |
|
1284 |
||
1285 |
q_infos[orientation == Qt::Vertical].insertOrRemoveRows(row, delta); |
|
1286 |
||
1287 |
for (int i = q_items.count() - 1; i >= 0; --i) |
|
1288 |
q_items.at(i)->insertOrRemoveRows(row, delta, orientation); |
|
1289 |
||
1290 |
q_grid.resize(internalGridRowCount() * internalGridColumnCount()); |
|
1291 |
regenerateGrid(); |
|
1292 |
} |
|
1293 |
||
1294 |
void QGridLayoutEngine::fillRowData(QGridLayoutRowData *rowData, const QLayoutStyleInfo &styleInfo, |
|
1295 |
Qt::Orientation orientation) const |
|
1296 |
{ |
|
1297 |
const int ButtonMask = QSizePolicy::ButtonBox | QSizePolicy::PushButton; |
|
1298 |
const QGridLayoutRowInfo &rowInfo = q_infos[orientation == Qt::Vertical]; |
|
1299 |
const QGridLayoutRowInfo &columnInfo = q_infos[orientation == Qt::Horizontal]; |
|
1300 |
LayoutSide top = (orientation == Qt::Vertical) ? Top : Left; |
|
1301 |
LayoutSide bottom = (orientation == Qt::Vertical) ? Bottom : Right; |
|
1302 |
||
1303 |
QStyle *style = styleInfo.style(); |
|
1304 |
QStyleOption option; |
|
1305 |
option.initFrom(styleInfo.widget()); |
|
1306 |
||
1307 |
const QLayoutParameter<qreal> &defaultSpacing = q_defaultSpacings[orientation == Qt::Vertical]; |
|
1308 |
qreal innerSpacing = 0.0; |
|
1309 |
if (style) |
|
1310 |
innerSpacing = (qreal)style->pixelMetric(orientation == Qt::Vertical ? QStyle::PM_LayoutVerticalSpacing |
|
1311 |
: QStyle::PM_LayoutHorizontalSpacing, |
|
1312 |
&option, styleInfo.widget()); |
|
1313 |
if (innerSpacing >= 0.0) |
|
1314 |
defaultSpacing.setCachedValue(innerSpacing); |
|
1315 |
||
1316 |
for (int row = 0; row < rowInfo.count; ++row) { |
|
1317 |
bool rowIsEmpty = true; |
|
1318 |
bool rowIsIdenticalToPrevious = (row > 0); |
|
1319 |
||
1320 |
for (int column = 0; column < columnInfo.count; ++column) { |
|
1321 |
QGridLayoutItem *item = itemAt(row, column, orientation); |
|
1322 |
||
1323 |
if (rowIsIdenticalToPrevious && item != itemAt(row - 1, column, orientation)) |
|
1324 |
rowIsIdenticalToPrevious = false; |
|
1325 |
||
1326 |
if (item) |
|
1327 |
rowIsEmpty = false; |
|
1328 |
} |
|
1329 |
||
1330 |
if ((rowIsEmpty || rowIsIdenticalToPrevious) |
|
1331 |
&& rowInfo.spacings.value(row).isDefault() |
|
1332 |
&& rowInfo.stretches.value(row).isDefault() |
|
1333 |
&& rowInfo.boxes.value(row) == QGridLayoutBox()) |
|
1334 |
rowData->ignore.setBit(row, true); |
|
1335 |
||
1336 |
if (rowInfo.spacings.value(row).isUser()) { |
|
1337 |
rowData->spacings[row] = rowInfo.spacings.at(row).value(); |
|
1338 |
} else if (!defaultSpacing.isDefault()) { |
|
1339 |
rowData->spacings[row] = defaultSpacing.value(); |
|
1340 |
} |
|
1341 |
||
1342 |
rowData->stretches[row] = rowInfo.stretches.value(row).value(); |
|
1343 |
} |
|
1344 |
||
1345 |
struct RowAdHocData { |
|
1346 |
int q_row; |
|
1347 |
unsigned int q_hasButtons : 8; |
|
1348 |
unsigned int q_hasNonButtons : 8; |
|
1349 |
||
1350 |
inline RowAdHocData() : q_row(-1), q_hasButtons(false), q_hasNonButtons(false) {} |
|
1351 |
inline void init(int row) { |
|
1352 |
this->q_row = row; |
|
1353 |
q_hasButtons = false; |
|
1354 |
q_hasNonButtons = false; |
|
1355 |
} |
|
1356 |
inline bool hasOnlyButtons() const { return q_hasButtons && !q_hasNonButtons; } |
|
1357 |
inline bool hasOnlyNonButtons() const { return q_hasNonButtons && !q_hasButtons; } |
|
1358 |
}; |
|
1359 |
RowAdHocData lastRowAdHocData; |
|
1360 |
RowAdHocData nextToLastRowAdHocData; |
|
1361 |
RowAdHocData nextToNextToLastRowAdHocData; |
|
1362 |
||
1363 |
rowData->hasIgnoreFlag = false; |
|
1364 |
for (int row = 0; row < rowInfo.count; ++row) { |
|
1365 |
if (rowData->ignore.testBit(row)) |
|
1366 |
continue; |
|
1367 |
||
1368 |
QGridLayoutBox &rowBox = rowData->boxes[row]; |
|
1369 |
if (option.state & QStyle::State_Window) { |
|
1370 |
nextToNextToLastRowAdHocData = nextToLastRowAdHocData; |
|
1371 |
nextToLastRowAdHocData = lastRowAdHocData; |
|
1372 |
lastRowAdHocData.init(row); |
|
1373 |
} |
|
1374 |
||
1375 |
bool userRowStretch = rowInfo.stretches.value(row).isUser(); |
|
1376 |
int &rowStretch = rowData->stretches[row]; |
|
1377 |
||
1378 |
bool hasIgnoreFlag = true; |
|
1379 |
for (int column = 0; column < columnInfo.count; ++column) { |
|
1380 |
QGridLayoutItem *item = itemAt(row, column, orientation); |
|
1381 |
if (item) { |
|
1382 |
int itemRow = item->firstRow(orientation); |
|
1383 |
int itemColumn = item->firstColumn(orientation); |
|
1384 |
||
1385 |
if (itemRow == row && itemColumn == column) { |
|
1386 |
int itemStretch = item->stretchFactor(orientation); |
|
1387 |
if (!(item->sizePolicy(orientation) & QSizePolicy::IgnoreFlag)) |
|
1388 |
hasIgnoreFlag = false; |
|
1389 |
int itemRowSpan = item->rowSpan(orientation); |
|
1390 |
||
1391 |
int effectiveRowSpan = 1; |
|
1392 |
for (int i = 1; i < itemRowSpan; ++i) { |
|
1393 |
if (!rowData->ignore.testBit(i)) |
|
1394 |
++effectiveRowSpan; |
|
1395 |
} |
|
1396 |
||
1397 |
QGridLayoutBox *box; |
|
1398 |
if (effectiveRowSpan == 1) { |
|
1399 |
box = &rowBox; |
|
1400 |
if (!userRowStretch) |
|
1401 |
rowStretch = qMax(rowStretch, itemStretch); |
|
1402 |
} else { |
|
1403 |
QGridLayoutMultiCellData &multiCell = |
|
1404 |
rowData->multiCellMap[qMakePair(row, effectiveRowSpan)]; |
|
1405 |
box = &multiCell.q_box; |
|
1406 |
multiCell.q_stretch = itemStretch; |
|
1407 |
} |
|
37
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1408 |
// Items with constraints are not included in the orientation that |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1409 |
// they are constrained (since it depends on the hfw/constraint function). |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1410 |
// They must be combined at a later stage. |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1411 |
if (!item->hasDynamicConstraint() || orientation != item->dynamicConstraintOrientation()) |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1412 |
box->combine(item->box(orientation)); |
0 | 1413 |
|
1414 |
if (effectiveRowSpan == 1) { |
|
1415 |
QSizePolicy::ControlTypes controls = item->controlTypes(top); |
|
1416 |
if (controls & ButtonMask) |
|
1417 |
lastRowAdHocData.q_hasButtons = true; |
|
1418 |
if (controls & ~ButtonMask) |
|
1419 |
lastRowAdHocData.q_hasNonButtons = true; |
|
1420 |
} |
|
1421 |
} |
|
1422 |
} |
|
1423 |
} |
|
1424 |
if (row < rowInfo.boxes.count()) { |
|
1425 |
QGridLayoutBox rowBoxInfo = rowInfo.boxes.at(row); |
|
1426 |
rowBoxInfo.normalize(); |
|
1427 |
rowBox.q_minimumSize = qMax(rowBox.q_minimumSize, rowBoxInfo.q_minimumSize); |
|
1428 |
rowBox.q_maximumSize = qMax(rowBox.q_minimumSize, |
|
1429 |
(rowBoxInfo.q_maximumSize != FLT_MAX ? |
|
1430 |
rowBoxInfo.q_maximumSize : rowBox.q_maximumSize)); |
|
1431 |
rowBox.q_preferredSize = qBound(rowBox.q_minimumSize, |
|
1432 |
qMax(rowBox.q_preferredSize, rowBoxInfo.q_preferredSize), |
|
1433 |
rowBox.q_maximumSize); |
|
1434 |
} |
|
1435 |
if (hasIgnoreFlag) |
|
1436 |
rowData->hasIgnoreFlag = true; |
|
1437 |
} |
|
1438 |
||
1439 |
/* |
|
1440 |
Heuristic: Detect button boxes that don't use QSizePolicy::ButtonBox. |
|
1441 |
This is somewhat ad hoc but it usually does the trick. |
|
1442 |
*/ |
|
1443 |
bool lastRowIsButtonBox = (lastRowAdHocData.hasOnlyButtons() |
|
1444 |
&& nextToLastRowAdHocData.hasOnlyNonButtons()); |
|
1445 |
bool lastTwoRowsIsButtonBox = (lastRowAdHocData.hasOnlyButtons() |
|
1446 |
&& nextToLastRowAdHocData.hasOnlyButtons() |
|
1447 |
&& nextToNextToLastRowAdHocData.hasOnlyNonButtons() |
|
1448 |
&& orientation == Qt::Vertical); |
|
1449 |
||
1450 |
if (defaultSpacing.isDefault()) { |
|
1451 |
int prevRow = -1; |
|
1452 |
for (int row = 0; row < rowInfo.count; ++row) { |
|
1453 |
if (rowData->ignore.testBit(row)) |
|
1454 |
continue; |
|
1455 |
||
1456 |
if (prevRow != -1 && !rowInfo.spacings.value(prevRow).isUser()) { |
|
1457 |
qreal &rowSpacing = rowData->spacings[prevRow]; |
|
1458 |
for (int column = 0; column < columnInfo.count; ++column) { |
|
1459 |
QGridLayoutItem *item1 = itemAt(prevRow, column, orientation); |
|
1460 |
QGridLayoutItem *item2 = itemAt(row, column, orientation); |
|
1461 |
||
1462 |
if (item1 && item2 && item1 != item2) { |
|
1463 |
QSizePolicy::ControlTypes controls1 = item1->controlTypes(bottom); |
|
1464 |
QSizePolicy::ControlTypes controls2 = item2->controlTypes(top); |
|
1465 |
||
1466 |
if (controls2 & QSizePolicy::PushButton) { |
|
1467 |
if ((row == nextToLastRowAdHocData.q_row && lastTwoRowsIsButtonBox) |
|
1468 |
|| (row == lastRowAdHocData.q_row && lastRowIsButtonBox)) { |
|
1469 |
controls2 &= ~QSizePolicy::PushButton; |
|
1470 |
controls2 |= QSizePolicy::ButtonBox; |
|
1471 |
} |
|
1472 |
} |
|
1473 |
||
1474 |
qreal spacing = style->combinedLayoutSpacing(controls1, controls2, |
|
1475 |
orientation, &option, |
|
1476 |
styleInfo.widget()); |
|
1477 |
if (orientation == Qt::Horizontal) { |
|
1478 |
qreal width1 = rowData->boxes.at(prevRow).q_minimumSize; |
|
1479 |
qreal width2 = rowData->boxes.at(row).q_minimumSize; |
|
1480 |
QRectF rect1 = item1->geometryWithin(0.0, 0.0, width1, FLT_MAX, -1.0); |
|
1481 |
QRectF rect2 = item2->geometryWithin(0.0, 0.0, width2, FLT_MAX, -1.0); |
|
1482 |
spacing -= (width1 - (rect1.x() + rect1.width())) + rect2.x(); |
|
1483 |
} else { |
|
1484 |
const QGridLayoutBox &box1 = rowData->boxes.at(prevRow); |
|
1485 |
const QGridLayoutBox &box2 = rowData->boxes.at(row); |
|
1486 |
qreal height1 = box1.q_minimumSize; |
|
1487 |
qreal height2 = box2.q_minimumSize; |
|
1488 |
qreal rowDescent1 = fixedDescent(box1.q_minimumDescent, |
|
1489 |
box1.q_minimumAscent, height1); |
|
1490 |
qreal rowDescent2 = fixedDescent(box2.q_minimumDescent, |
|
1491 |
box2.q_minimumAscent, height2); |
|
1492 |
QRectF rect1 = item1->geometryWithin(0.0, 0.0, FLT_MAX, height1, |
|
1493 |
rowDescent1); |
|
1494 |
QRectF rect2 = item2->geometryWithin(0.0, 0.0, FLT_MAX, height2, |
|
1495 |
rowDescent2); |
|
1496 |
spacing -= (height1 - (rect1.y() + rect1.height())) + rect2.y(); |
|
1497 |
} |
|
1498 |
rowSpacing = qMax(spacing, rowSpacing); |
|
1499 |
} |
|
1500 |
} |
|
1501 |
} |
|
1502 |
prevRow = row; |
|
1503 |
} |
|
1504 |
} else if (lastRowIsButtonBox || lastTwoRowsIsButtonBox) { |
|
1505 |
/* |
|
1506 |
Even for styles that define a uniform spacing, we cheat a |
|
1507 |
bit and use the window margin as the spacing. This |
|
1508 |
significantly improves the look of dialogs. |
|
1509 |
*/ |
|
1510 |
int prevRow = lastRowIsButtonBox ? nextToLastRowAdHocData.q_row |
|
1511 |
: nextToNextToLastRowAdHocData.q_row; |
|
1512 |
if (!defaultSpacing.isUser() && !rowInfo.spacings.value(prevRow).isUser()) { |
|
1513 |
qreal windowMargin = style->pixelMetric(orientation == Qt::Vertical |
|
1514 |
? QStyle::PM_LayoutBottomMargin |
|
1515 |
: QStyle::PM_LayoutRightMargin, |
|
1516 |
&option, styleInfo.widget()); |
|
1517 |
||
1518 |
qreal &rowSpacing = rowData->spacings[prevRow]; |
|
1519 |
rowSpacing = qMax(windowMargin, rowSpacing); |
|
1520 |
} |
|
1521 |
} |
|
1522 |
} |
|
1523 |
||
1524 |
void QGridLayoutEngine::ensureEffectiveFirstAndLastRows() const |
|
1525 |
{ |
|
1526 |
if (q_cachedEffectiveFirstRows[Hor] == -1 && !q_items.isEmpty()) { |
|
1527 |
int rowCount = this->rowCount(); |
|
1528 |
int columnCount = this->columnCount(); |
|
1529 |
||
1530 |
q_cachedEffectiveFirstRows[Ver] = rowCount; |
|
1531 |
q_cachedEffectiveFirstRows[Hor] = columnCount; |
|
1532 |
q_cachedEffectiveLastRows[Ver] = -1; |
|
1533 |
q_cachedEffectiveLastRows[Hor] = -1; |
|
1534 |
||
1535 |
for (int i = q_items.count() - 1; i >= 0; --i) { |
|
1536 |
const QGridLayoutItem *item = q_items.at(i); |
|
1537 |
||
1538 |
for (int j = 0; j < NOrientations; ++j) { |
|
1539 |
Qt::Orientation orientation = (j == Hor) ? Qt::Horizontal : Qt::Vertical; |
|
1540 |
if (item->firstRow(orientation) < q_cachedEffectiveFirstRows[j]) |
|
1541 |
q_cachedEffectiveFirstRows[j] = item->firstRow(orientation); |
|
1542 |
if (item->lastRow(orientation) > q_cachedEffectiveLastRows[j]) |
|
1543 |
q_cachedEffectiveLastRows[j] = item->lastRow(orientation); |
|
1544 |
} |
|
1545 |
} |
|
1546 |
} |
|
1547 |
} |
|
1548 |
||
1549 |
void QGridLayoutEngine::ensureColumnAndRowData(const QLayoutStyleInfo &styleInfo) const |
|
1550 |
{ |
|
1551 |
if (q_cachedDataForStyleInfo == styleInfo) |
|
1552 |
return; |
|
1553 |
||
1554 |
q_columnData.reset(columnCount()); |
|
1555 |
q_rowData.reset(rowCount()); |
|
1556 |
||
1557 |
fillRowData(&q_columnData, styleInfo, Qt::Horizontal); |
|
1558 |
fillRowData(&q_rowData, styleInfo, Qt::Vertical); |
|
1559 |
||
1560 |
q_columnData.distributeMultiCells(); |
|
1561 |
q_rowData.distributeMultiCells(); |
|
1562 |
||
1563 |
q_totalBoxes[Hor] = q_columnData.totalBox(0, columnCount()); |
|
1564 |
q_totalBoxes[Ver] = q_rowData.totalBox(0, rowCount()); |
|
1565 |
||
1566 |
q_cachedDataForStyleInfo = styleInfo; |
|
1567 |
} |
|
1568 |
||
37
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1569 |
QSizeF QGridLayoutEngine::dynamicallyConstrainedSizeHint(Qt::SizeHint which, |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1570 |
const QSizeF &constraint) const |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1571 |
{ |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1572 |
Q_ASSERT(hasDynamicConstraint()); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1573 |
if (constraint.width() < 0 && constraint.height() < 0) { |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1574 |
// Process the hfw / wfh items that we did not process in fillRowData() |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1575 |
const Qt::Orientation constraintOrient = constraintOrientation(); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1576 |
|
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1577 |
QGridLayoutRowData rowData = constraintOrient == Qt::Vertical ? q_rowData : q_columnData; |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1578 |
for (int i = q_items.count() - 1; i >= 0; --i) { |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1579 |
QGridLayoutItem *item = q_items.at(i); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1580 |
if (item->hasDynamicConstraint()) { |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1581 |
QGridLayoutBox box = item->box(constraintOrient); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1582 |
QGridLayoutBox &rowBox = rowData.boxes[item->firstRow(constraintOrient)]; |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1583 |
rowBox.combine(box); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1584 |
} |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1585 |
} |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1586 |
|
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1587 |
QGridLayoutBox totalBoxes[2]; |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1588 |
if (constraintOrient == Qt::Vertical) { |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1589 |
totalBoxes[Hor] = q_columnData.totalBox(0, columnCount()); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1590 |
totalBoxes[Ver] = rowData.totalBox(0, rowCount()); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1591 |
} else { |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1592 |
totalBoxes[Hor] = rowData.totalBox(0, columnCount()); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1593 |
totalBoxes[Ver] = q_rowData.totalBox(0, rowCount()); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1594 |
} |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1595 |
return QSizeF(totalBoxes[Hor].q_sizes(which), totalBoxes[Ver].q_sizes(which)); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1596 |
} |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1597 |
|
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1598 |
|
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1599 |
Q_ASSERT(constraint.width() >= 0 || constraint.height() >= 0); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1600 |
q_xx.resize(columnCount()); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1601 |
q_yy.resize(rowCount()); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1602 |
q_widths.resize(columnCount()); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1603 |
q_heights.resize(rowCount()); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1604 |
q_descents.resize(rowCount()); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1605 |
|
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1606 |
|
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1607 |
const Qt::Orientation orientation = constraintOrientation(); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1608 |
QGridLayoutRowData *colData; |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1609 |
QGridLayoutRowData constrainedRowData; |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1610 |
QGridLayoutBox *totalBox; |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1611 |
qreal *sizes; |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1612 |
qreal *pos; |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1613 |
qreal *descents; |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1614 |
qreal targetSize; |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1615 |
qreal cCount; |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1616 |
qreal rCount; |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1617 |
|
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1618 |
if (orientation == Qt::Vertical) { |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1619 |
// height for width |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1620 |
colData = &q_columnData; |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1621 |
totalBox = &q_totalBoxes[Hor]; |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1622 |
sizes = q_widths.data(); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1623 |
pos = q_xx.data(); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1624 |
descents = 0; |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1625 |
targetSize = constraint.width(); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1626 |
cCount = columnCount(); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1627 |
rCount = rowCount(); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1628 |
constrainedRowData = q_rowData; |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1629 |
} else { |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1630 |
// width for height |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1631 |
colData = &q_rowData; |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1632 |
totalBox = &q_totalBoxes[Ver]; |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1633 |
sizes = q_heights.data(); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1634 |
pos = q_yy.data(); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1635 |
descents = q_descents.data(); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1636 |
targetSize = constraint.height(); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1637 |
cCount = rowCount(); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1638 |
rCount = columnCount(); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1639 |
constrainedRowData = q_columnData; |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1640 |
} |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1641 |
colData->calculateGeometries(0, cCount, targetSize, pos, sizes, descents, *totalBox); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1642 |
for (int i = q_items.count() - 1; i >= 0; --i) { |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1643 |
QGridLayoutItem *item = q_items.at(i); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1644 |
|
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1645 |
if (item->hasDynamicConstraint()) { |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1646 |
const qreal size = sizes[item->firstColumn(orientation)]; |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1647 |
QGridLayoutBox box = item->box(orientation, size); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1648 |
QGridLayoutBox &rowBox = constrainedRowData.boxes[item->firstRow(orientation)]; |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1649 |
rowBox.combine(box); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1650 |
} |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1651 |
} |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1652 |
const qreal newSize = constrainedRowData.totalBox(0, rCount).q_sizes(which); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1653 |
|
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1654 |
return (orientation == Qt::Vertical) ? QSizeF(targetSize, newSize) : QSizeF(newSize, targetSize); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1655 |
} |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1656 |
|
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1657 |
|
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1658 |
/** |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1659 |
returns false if the layout has contradicting constraints (i.e. some items with a horizontal |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1660 |
constraint and other items with a vertical constraint) |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1661 |
*/ |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1662 |
bool QGridLayoutEngine::ensureDynamicConstraint() const |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1663 |
{ |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1664 |
if (q_cachedConstraintOrientation == UnknownConstraint) { |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1665 |
for (int i = q_items.count() - 1; i >= 0; --i) { |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1666 |
QGridLayoutItem *item = q_items.at(i); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1667 |
if (item->hasDynamicConstraint()) { |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1668 |
Qt::Orientation itemConstraintOrientation = item->dynamicConstraintOrientation(); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1669 |
if (q_cachedConstraintOrientation == UnknownConstraint) { |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1670 |
q_cachedConstraintOrientation = itemConstraintOrientation; |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1671 |
} else if (q_cachedConstraintOrientation != itemConstraintOrientation) { |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1672 |
q_cachedConstraintOrientation = UnfeasibleConstraint; |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1673 |
qWarning("QGridLayoutEngine: Unfeasible, cannot mix horizontal and" |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1674 |
" vertical constraint in the same layout"); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1675 |
return false; |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1676 |
} |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1677 |
} |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1678 |
} |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1679 |
if (q_cachedConstraintOrientation == UnknownConstraint) |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1680 |
q_cachedConstraintOrientation = NoConstraint; |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1681 |
} |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1682 |
return true; |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1683 |
} |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1684 |
|
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1685 |
bool QGridLayoutEngine::hasDynamicConstraint() const |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1686 |
{ |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1687 |
if (!ensureDynamicConstraint()) |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1688 |
return false; |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1689 |
return q_cachedConstraintOrientation != NoConstraint; |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1690 |
} |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1691 |
|
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1692 |
/* |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1693 |
* return value is only valid if hasConstraint() returns true |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1694 |
*/ |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1695 |
Qt::Orientation QGridLayoutEngine::constraintOrientation() const |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1696 |
{ |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1697 |
(void)ensureDynamicConstraint(); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1698 |
return (Qt::Orientation)q_cachedConstraintOrientation; |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1699 |
} |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1700 |
|
0 | 1701 |
void QGridLayoutEngine::ensureGeometries(const QLayoutStyleInfo &styleInfo, |
1702 |
const QSizeF &size) const |
|
1703 |
{ |
|
1704 |
ensureColumnAndRowData(styleInfo); |
|
1705 |
if (q_cachedSize == size) |
|
1706 |
return; |
|
1707 |
||
1708 |
q_xx.resize(columnCount()); |
|
1709 |
q_yy.resize(rowCount()); |
|
1710 |
q_widths.resize(columnCount()); |
|
1711 |
q_heights.resize(rowCount()); |
|
1712 |
q_descents.resize(rowCount()); |
|
37
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1713 |
|
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1714 |
|
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1715 |
Qt::Orientation orientation = Qt::Vertical; |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1716 |
if (hasDynamicConstraint()) |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1717 |
orientation = constraintOrientation(); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1718 |
|
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1719 |
/* |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1720 |
In order to do hfw we need to first distribute the columns, then the rows. |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1721 |
In order to do wfh we need to first distribute the rows, then the columns. |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1722 |
|
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1723 |
If there is no constraint, the order of distributing the rows or columns first is irrelevant. |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1724 |
We choose horizontal just to keep the same behaviour as before (however, there shouldn't |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1725 |
be any behaviour difference). |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1726 |
*/ |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1727 |
|
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1728 |
QGridLayoutRowData *colData; |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1729 |
QGridLayoutRowData rowData; |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1730 |
qreal *widths; |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1731 |
qreal *heights; |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1732 |
qreal *xx; |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1733 |
qreal *yy; |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1734 |
qreal *xdescents = 0; |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1735 |
qreal *ydescents = 0; |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1736 |
qreal cCount; |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1737 |
qreal rCount; |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1738 |
QSizeF oSize = size; |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1739 |
if (orientation == Qt::Vertical) { |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1740 |
// height for width |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1741 |
colData = &q_columnData; |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1742 |
rowData = q_rowData; |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1743 |
widths = q_widths.data(); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1744 |
heights = q_heights.data(); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1745 |
xx = q_xx.data(); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1746 |
yy = q_yy.data(); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1747 |
cCount = columnCount(); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1748 |
rCount = rowCount(); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1749 |
ydescents = q_descents.data(); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1750 |
} else { |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1751 |
// width for height |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1752 |
colData = &q_rowData; |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1753 |
rowData = q_columnData; |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1754 |
widths = q_heights.data(); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1755 |
heights = q_widths.data(); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1756 |
xx = q_yy.data(); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1757 |
yy = q_xx.data(); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1758 |
cCount = rowCount(); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1759 |
rCount = columnCount(); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1760 |
xdescents = q_descents.data(); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1761 |
oSize.transpose(); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1762 |
} |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1763 |
|
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1764 |
colData->calculateGeometries(0, cCount, oSize.width(), xx, widths, |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1765 |
xdescents, q_totalBoxes[orientation == Qt::Horizontal]); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1766 |
for (int i = q_items.count() - 1; i >= 0; --i) { |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1767 |
QGridLayoutItem *item = q_items.at(i); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1768 |
const int col = item->firstColumn(orientation); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1769 |
const int row = item->firstRow(orientation); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1770 |
if (item->hasDynamicConstraint()) { |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1771 |
const qreal sz = widths[col]; |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1772 |
QGridLayoutBox box = item->box(orientation, sz); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1773 |
rowData.boxes[row].combine(box); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1774 |
} |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1775 |
} |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1776 |
|
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1777 |
QGridLayoutBox &totalBox = q_totalBoxes[orientation == Qt::Vertical]; |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1778 |
totalBox = rowData.totalBox(0, rCount); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1779 |
rowData.calculateGeometries(0, rCount, oSize.height(), yy, heights, |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1780 |
ydescents, totalBox); |
0 | 1781 |
|
1782 |
q_cachedSize = size; |
|
1783 |
} |
|
1784 |
||
1785 |
QT_END_NAMESPACE |
|
1786 |
||
1787 |
#endif //QT_NO_GRAPHICSVIEW |