qlayoutengine.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/widgets/kernel/qlayoutengine.cpp
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5-
6-
7-
8-
9-
10typedef qint64 Fixed64;-
11static inline Fixed64 toFixed(int i) { return
never executed: return (Fixed64)i * 256;
(Fixed64)i * 256;
never executed: return (Fixed64)i * 256;
}
0
12static inline int fRound(Fixed64 i) {-
13 return
never executed: return (i % 256 < 128) ? i / 256 : 1 + i / 256;
(i % 256 < 128) ? i / 256 : 1 + i / 256;
never executed: return (i % 256 < 128) ? i / 256 : 1 + i / 256;
0
14}-
15void qGeomCalc(QVector<QLayoutStruct> &chain, int start, int count,-
16 int pos, int space, int spacer)-
17{-
18 int cHint = 0;-
19 int cMin = 0;-
20 int cMax = 0;-
21 int sumStretch = 0;-
22 int sumSpacing = 0;-
23 int expandingCount = 0;-
24-
25 bool allEmptyNonstretch = true;-
26 int pendingSpacing = -1;-
27 int spacerCount = 0;-
28 int i;-
29-
30 for (i = start; i < start + count
i < start + countDescription
TRUEnever evaluated
FALSEnever evaluated
; i++) {
0
31 QLayoutStruct *data = &chain[i];-
32-
33 data->done = false;-
34 cHint += data->smartSizeHint();-
35 cMin += data->minimumSize;-
36 cMax += data->maximumSize;-
37 sumStretch += data->stretch;-
38 if (!data->empty
!data->emptyDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
39-
40-
41-
42-
43 if (pendingSpacing >= 0
pendingSpacing >= 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
44 sumSpacing += pendingSpacing;-
45 ++spacerCount;-
46 }
never executed: end of block
0
47 pendingSpacing = data->effectiveSpacer(spacer);-
48 }
never executed: end of block
0
49 if (data->expansive
data->expansiveDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
50 expandingCount++;
never executed: expandingCount++;
0
51 allEmptyNonstretch = allEmptyNonstretch
allEmptyNonstretchDescription
TRUEnever evaluated
FALSEnever evaluated
&& data->empty
data->emptyDescription
TRUEnever evaluated
FALSEnever evaluated
&& !data->expansive
!data->expansiveDescription
TRUEnever evaluated
FALSEnever evaluated
&& data->stretch <= 0
data->stretch <= 0Description
TRUEnever evaluated
FALSEnever evaluated
;
0
52 }
never executed: end of block
0
53-
54 int extraspace = 0;-
55-
56 if (space < cMin + sumSpacing
space < cMin + sumSpacingDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
57-
58-
59-
60-
61 int minSize = cMin + sumSpacing;-
62-
63-
64 if (spacer >= 0
spacer >= 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
65 spacer = minSize > 0
minSize > 0Description
TRUEnever evaluated
FALSEnever evaluated
? spacer * space / minSize : 0;
0
66 sumSpacing = spacer * spacerCount;-
67 }
never executed: end of block
0
68-
69 QVarLengthArray<int, 32> minimumSizes;-
70 minimumSizes.reserve(count);-
71-
72 for (i = start; i < start + count
i < start + countDescription
TRUEnever evaluated
FALSEnever evaluated
; i++)
0
73 minimumSizes << chain.at(i).minimumSize;
never executed: minimumSizes << chain.at(i).minimumSize;
0
74-
75 std::sort(minimumSizes.begin(), minimumSizes.end());-
76-
77 int space_left = space - sumSpacing;-
78-
79 int sum = 0;-
80 int idx = 0;-
81 int space_used=0;-
82 int current = 0;-
83 while (idx < count
idx < countDescription
TRUEnever evaluated
FALSEnever evaluated
&& space_used < space_left
space_used < space_leftDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
84 current = minimumSizes.at(idx);-
85 space_used = sum + current * (count - idx);-
86 sum += current;-
87 ++idx;-
88 }
never executed: end of block
0
89 --idx;-
90 int deficit = space_used - space_left;-
91-
92 int items = count - idx;-
93-
94-
95-
96-
97-
98 int deficitPerItem = deficit/items;-
99 int remainder = deficit % items;-
100 int maxval = current - deficitPerItem;-
101-
102 int rest = 0;-
103 for (i = start; i < start + count
i < start + countDescription
TRUEnever evaluated
FALSEnever evaluated
; i++) {
0
104 int maxv = maxval;-
105 rest += remainder;-
106 if (rest >= items
rest >= itemsDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
107 maxv--;-
108 rest-=items;-
109 }
never executed: end of block
0
110 QLayoutStruct *data = &chain[i];-
111 data->size = qMin(data->minimumSize, maxv);-
112 data->done = true;-
113 }
never executed: end of block
0
114 }
never executed: end of block
else if (space < cHint + sumSpacing
space < cHint + sumSpacingDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
115-
116-
117-
118-
119-
120-
121 int n = count;-
122 int space_left = space - sumSpacing;-
123 int overdraft = cHint - space_left;-
124-
125-
126 for (i = start; i < start + count
i < start + countDescription
TRUEnever evaluated
FALSEnever evaluated
; i++) {
0
127 QLayoutStruct *data = &chain[i];-
128 if (!data->done
!data->doneDescription
TRUEnever evaluated
FALSEnever evaluated
0
129 && data->minimumSize >= data->smartSizeHint()
data->minimumS...martSizeHint()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
130 data->size = data->smartSizeHint();-
131 data->done = true;-
132 space_left -= data->smartSizeHint();-
133-
134 n--;-
135 }
never executed: end of block
0
136 }
never executed: end of block
0
137 bool finished = n == 0;-
138 while (!finished
!finishedDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
139 finished = true;-
140 Fixed64 fp_over = toFixed(overdraft);-
141 Fixed64 fp_w = 0;-
142-
143 for (i = start; i < start+count
i < start+countDescription
TRUEnever evaluated
FALSEnever evaluated
; i++) {
0
144 QLayoutStruct *data = &chain[i];-
145 if (data->done
data->doneDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
146 continue;
never executed: continue;
0
147-
148 fp_w += fp_over / n;-
149-
150-
151 int w = fRound(fp_w);-
152 data->size = data->smartSizeHint() - w;-
153 fp_w -= toFixed(w);-
154 if (data->size < data->minimumSize
data->size < data->minimumSizeDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
155 data->done = true;-
156 data->size = data->minimumSize;-
157 finished = false;-
158 overdraft -= data->smartSizeHint() - data->minimumSize;-
159-
160 n--;-
161 break;
never executed: break;
0
162 }-
163 }
never executed: end of block
0
164 }
never executed: end of block
0
165 }
never executed: end of block
else {
0
166 int n = count;-
167 int space_left = space - sumSpacing;-
168-
169 for (i = start; i < start + count
i < start + countDescription
TRUEnever evaluated
FALSEnever evaluated
; i++) {
0
170 QLayoutStruct *data = &chain[i];-
171 if (!data->done
!data->doneDescription
TRUEnever evaluated
FALSEnever evaluated
0
172 && (data->maximumSize <= data->smartSizeHint()
data->maximumS...martSizeHint()Description
TRUEnever evaluated
FALSEnever evaluated
0
173 || (!allEmptyNonstretch
!allEmptyNonstretchDescription
TRUEnever evaluated
FALSEnever evaluated
&& data->empty
data->emptyDescription
TRUEnever evaluated
FALSEnever evaluated
&&
0
174 !data->expansive
!data->expansiveDescription
TRUEnever evaluated
FALSEnever evaluated
&& data->stretch == 0
data->stretch == 0Description
TRUEnever evaluated
FALSEnever evaluated
))) {
0
175 data->size = data->smartSizeHint();-
176 data->done = true;-
177 space_left -= data->size;-
178 sumStretch -= data->stretch;-
179 if (data->expansive
data->expansiveDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
180 expandingCount--;
never executed: expandingCount--;
0
181 n--;-
182 }
never executed: end of block
0
183 }
never executed: end of block
0
184 extraspace = space_left;-
185 int surplus, deficit;-
186 do {-
187 surplus = deficit = 0;-
188 Fixed64 fp_space = toFixed(space_left);-
189 Fixed64 fp_w = 0;-
190 for (i = start; i < start + count
i < start + countDescription
TRUEnever evaluated
FALSEnever evaluated
; i++) {
0
191 QLayoutStruct *data = &chain[i];-
192 if (data->done
data->doneDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
193 continue;
never executed: continue;
0
194 extraspace = 0;-
195 if (sumStretch > 0
sumStretch > 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
196 fp_w += (fp_space * data->stretch) / sumStretch;-
197 }
never executed: end of block
else if (expandingCount > 0
expandingCount > 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
198 fp_w += (fp_space * (data->expansive ? 1 : 0)) / expandingCount;-
199 }
never executed: end of block
else {
0
200 fp_w += fp_space * 1 / n;-
201 }
never executed: end of block
0
202 int w = fRound(fp_w);-
203 data->size = w;-
204 fp_w -= toFixed(w);-
205 if (w < data->smartSizeHint()
w < data->smartSizeHint()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
206 deficit += data->smartSizeHint() - w;-
207 }
never executed: end of block
else if (w > data->maximumSize
w > data->maximumSizeDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
208 surplus += w - data->maximumSize;-
209 }
never executed: end of block
0
210 }
never executed: end of block
0
211 if (deficit > 0
deficit > 0Description
TRUEnever evaluated
FALSEnever evaluated
&& surplus <= deficit
surplus <= deficitDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
212-
213 for (i = start; i < start+count
i < start+countDescription
TRUEnever evaluated
FALSEnever evaluated
; i++) {
0
214 QLayoutStruct *data = &chain[i];-
215 if (!data->done
!data->doneDescription
TRUEnever evaluated
FALSEnever evaluated
&& data->size < data->smartSizeHint()
data->size < d...martSizeHint()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
216 data->size = data->smartSizeHint();-
217 data->done = true;-
218 space_left -= data->smartSizeHint();-
219 sumStretch -= data->stretch;-
220 if (data->expansive
data->expansiveDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
221 expandingCount--;
never executed: expandingCount--;
0
222 n--;-
223 }
never executed: end of block
0
224 }
never executed: end of block
0
225 }
never executed: end of block
0
226 if (surplus > 0
surplus > 0Description
TRUEnever evaluated
FALSEnever evaluated
&& surplus >= deficit
surplus >= deficitDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
227-
228 for (i = start; i < start + count
i < start + countDescription
TRUEnever evaluated
FALSEnever evaluated
; i++) {
0
229 QLayoutStruct *data = &chain[i];-
230 if (!data->done
!data->doneDescription
TRUEnever evaluated
FALSEnever evaluated
&& data->size > data->maximumSize
data->size > data->maximumSizeDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
231 data->size = data->maximumSize;-
232 data->done = true;-
233 space_left -= data->maximumSize;-
234 sumStretch -= data->stretch;-
235 if (data->expansive
data->expansiveDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
236 expandingCount--;
never executed: expandingCount--;
0
237 n--;-
238 }
never executed: end of block
0
239 }
never executed: end of block
0
240 }
never executed: end of block
0
241 }
never executed: end of block
while (n > 0
n > 0Description
TRUEnever evaluated
FALSEnever evaluated
&& surplus != deficit
surplus != deficitDescription
TRUEnever evaluated
FALSEnever evaluated
);
0
242 if (n == 0
n == 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
243 extraspace = space_left;
never executed: extraspace = space_left;
0
244 }
never executed: end of block
0
245-
246-
247-
248-
249-
250-
251-
252 int extra = extraspace / (spacerCount + 2);-
253 int p = pos + extra;-
254 for (i = start; i < start+count
i < start+countDescription
TRUEnever evaluated
FALSEnever evaluated
; i++) {
0
255 QLayoutStruct *data = &chain[i];-
256 data->pos = p;-
257 p += data->size;-
258 if (!data->empty
!data->emptyDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
259 p += data->effectiveSpacer(spacer) + extra;
never executed: p += data->effectiveSpacer(spacer) + extra;
0
260 }
never executed: end of block
0
261}
never executed: end of block
0
262-
263__attribute__((visibility("default"))) QSize qSmartMinSize(const QSize &sizeHint, const QSize &minSizeHint,-
264 const QSize &minSize, const QSize &maxSize,-
265 const QSizePolicy &sizePolicy)-
266{-
267 QSize s(0, 0);-
268-
269 if (sizePolicy.horizontalPolicy() != QSizePolicy::Ignored
sizePolicy.hor...olicy::IgnoredDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
270 if (sizePolicy.horizontalPolicy() & QSizePolicy::ShrinkFlag
sizePolicy.hor...cy::ShrinkFlagDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
271 s.setWidth(minSizeHint.width());
never executed: s.setWidth(minSizeHint.width());
0
272 else-
273 s.setWidth(qMax(sizeHint.width(), minSizeHint.width()));
never executed: s.setWidth(qMax(sizeHint.width(), minSizeHint.width()));
0
274 }-
275-
276 if (sizePolicy.verticalPolicy() != QSizePolicy::Ignored
sizePolicy.ver...olicy::IgnoredDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
277 if (sizePolicy.verticalPolicy() & QSizePolicy::ShrinkFlag
sizePolicy.ver...cy::ShrinkFlagDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
278 s.setHeight(minSizeHint.height());-
279 }
never executed: end of block
else {
0
280 s.setHeight(qMax(sizeHint.height(), minSizeHint.height()));-
281 }
never executed: end of block
0
282 }-
283-
284 s = s.boundedTo(maxSize);-
285 if (minSize.width() > 0
minSize.width() > 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
286 s.setWidth(minSize.width());
never executed: s.setWidth(minSize.width());
0
287 if (minSize.height() > 0
minSize.height() > 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
288 s.setHeight(minSize.height());
never executed: s.setHeight(minSize.height());
0
289-
290 return
never executed: return s.expandedTo(QSize(0,0));
s.expandedTo(QSize(0,0));
never executed: return s.expandedTo(QSize(0,0));
0
291}-
292-
293__attribute__((visibility("default"))) QSize qSmartMinSize(const QWidgetItem *i)-
294{-
295 QWidget *w = const_cast<QWidgetItem *>(i)->widget();-
296 return
never executed: return qSmartMinSize(w->sizeHint(), w->minimumSizeHint(), w->minimumSize(), w->maximumSize(), w->sizePolicy());
qSmartMinSize(w->sizeHint(), w->minimumSizeHint(),
never executed: return qSmartMinSize(w->sizeHint(), w->minimumSizeHint(), w->minimumSize(), w->maximumSize(), w->sizePolicy());
0
297 w->minimumSize(), w->maximumSize(),
never executed: return qSmartMinSize(w->sizeHint(), w->minimumSizeHint(), w->minimumSize(), w->maximumSize(), w->sizePolicy());
0
298 w->sizePolicy());
never executed: return qSmartMinSize(w->sizeHint(), w->minimumSizeHint(), w->minimumSize(), w->maximumSize(), w->sizePolicy());
0
299}-
300-
301__attribute__((visibility("default"))) QSize qSmartMinSize(const QWidget *w)-
302{-
303 return
never executed: return qSmartMinSize(w->sizeHint(), w->minimumSizeHint(), w->minimumSize(), w->maximumSize(), w->sizePolicy());
qSmartMinSize(w->sizeHint(), w->minimumSizeHint(),
never executed: return qSmartMinSize(w->sizeHint(), w->minimumSizeHint(), w->minimumSize(), w->maximumSize(), w->sizePolicy());
0
304 w->minimumSize(), w->maximumSize(),
never executed: return qSmartMinSize(w->sizeHint(), w->minimumSizeHint(), w->minimumSize(), w->maximumSize(), w->sizePolicy());
0
305 w->sizePolicy());
never executed: return qSmartMinSize(w->sizeHint(), w->minimumSizeHint(), w->minimumSize(), w->maximumSize(), w->sizePolicy());
0
306}-
307-
308__attribute__((visibility("default"))) QSize qSmartMaxSize(const QSize &sizeHint,-
309 const QSize &minSize, const QSize &maxSize,-
310 const QSizePolicy &sizePolicy, Qt::Alignment align)-
311{-
312 if (align & Qt::AlignHorizontal_Mask
align & Qt::Al...orizontal_MaskDescription
TRUEnever evaluated
FALSEnever evaluated
&& align & Qt::AlignVertical_Mask
align & Qt::AlignVertical_MaskDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
313 return
never executed: return QSize(QLAYOUTSIZE_MAX, QLAYOUTSIZE_MAX);
QSize(QLAYOUTSIZE_MAX, QLAYOUTSIZE_MAX);
never executed: return QSize(QLAYOUTSIZE_MAX, QLAYOUTSIZE_MAX);
0
314 QSize s = maxSize;-
315 QSize hint = sizeHint.expandedTo(minSize);-
316 if (s.width() == ((1<<24)-1)
s.width() == ((1<<24)-1)Description
TRUEnever evaluated
FALSEnever evaluated
&& !(align & Qt::AlignHorizontal_Mask)
!(align & Qt::...rizontal_Mask)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
317 if (!(sizePolicy.horizontalPolicy() & QSizePolicy::GrowFlag)
!(sizePolicy.h...icy::GrowFlag)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
318 s.setWidth(hint.width());
never executed: s.setWidth(hint.width());
0
319-
320 if (s.height() == ((1<<24)-1)
s.height() == ((1<<24)-1)Description
TRUEnever evaluated
FALSEnever evaluated
&& !(align & Qt::AlignVertical_Mask)
!(align & Qt::...Vertical_Mask)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
321 if (!(sizePolicy.verticalPolicy() & QSizePolicy::GrowFlag)
!(sizePolicy.v...icy::GrowFlag)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
322 s.setHeight(hint.height());
never executed: s.setHeight(hint.height());
0
323-
324 if (align & Qt::AlignHorizontal_Mask
align & Qt::Al...orizontal_MaskDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
325 s.setWidth(QLAYOUTSIZE_MAX);
never executed: s.setWidth(QLAYOUTSIZE_MAX);
0
326 if (align & Qt::AlignVertical_Mask
align & Qt::AlignVertical_MaskDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
327 s.setHeight(QLAYOUTSIZE_MAX);
never executed: s.setHeight(QLAYOUTSIZE_MAX);
0
328 return
never executed: return s;
s;
never executed: return s;
0
329}-
330-
331__attribute__((visibility("default"))) QSize qSmartMaxSize(const QWidgetItem *i, Qt::Alignment align)-
332{-
333 QWidget *w = const_cast<QWidgetItem*>(i)->widget();-
334-
335 return
never executed: return qSmartMaxSize(w->sizeHint().expandedTo(w->minimumSizeHint()), w->minimumSize(), w->maximumSize(), w->sizePolicy(), align);
qSmartMaxSize(w->sizeHint().expandedTo(w->minimumSizeHint()), w->minimumSize(), w->maximumSize(),
never executed: return qSmartMaxSize(w->sizeHint().expandedTo(w->minimumSizeHint()), w->minimumSize(), w->maximumSize(), w->sizePolicy(), align);
0
336 w->sizePolicy(), align);
never executed: return qSmartMaxSize(w->sizeHint().expandedTo(w->minimumSizeHint()), w->minimumSize(), w->maximumSize(), w->sizePolicy(), align);
0
337}-
338-
339__attribute__((visibility("default"))) QSize qSmartMaxSize(const QWidget *w, Qt::Alignment align)-
340{-
341 return
never executed: return qSmartMaxSize(w->sizeHint().expandedTo(w->minimumSizeHint()), w->minimumSize(), w->maximumSize(), w->sizePolicy(), align);
qSmartMaxSize(w->sizeHint().expandedTo(w->minimumSizeHint()), w->minimumSize(), w->maximumSize(),
never executed: return qSmartMaxSize(w->sizeHint().expandedTo(w->minimumSizeHint()), w->minimumSize(), w->maximumSize(), w->sizePolicy(), align);
0
342 w->sizePolicy(), align);
never executed: return qSmartMaxSize(w->sizeHint().expandedTo(w->minimumSizeHint()), w->minimumSize(), w->maximumSize(), w->sizePolicy(), align);
0
343}-
344-
345__attribute__((visibility("default"))) int qSmartSpacing(const QLayout *layout, QStyle::PixelMetric pm)-
346{-
347 QObject *parent = layout->parent();-
348 if (!parent
!parentDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
349 return
never executed: return -1;
-1;
never executed: return -1;
0
350 } else if (parent->isWidgetType()
parent->isWidgetType()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
351 QWidget *pw = static_cast<QWidget *>(parent);-
352 return
never executed: return pw->style()->pixelMetric(pm, 0, pw);
pw->style()->pixelMetric(pm, 0, pw);
never executed: return pw->style()->pixelMetric(pm, 0, pw);
0
353 } else {-
354 return
never executed: return static_cast<QLayout *>(parent)->spacing();
static_cast<QLayout *>(parent)->spacing();
never executed: return static_cast<QLayout *>(parent)->spacing();
0
355 }-
356}-
357-
358-
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9