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