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