qgridlayout.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/widgets/kernel/qgridlayout.cpp
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4struct QGridLayoutSizeTriple-
5{-
6 QSize minS;-
7 QSize hint;-
8 QSize maxS;-
9};-
10-
11-
12-
13-
14-
15-
16-
17class QGridBox-
18{-
19public:-
20 QGridBox(QLayoutItem *lit) { item_ = lit; }-
21-
22 QGridBox(const QLayout *l, QWidget *wid) { item_ = QLayoutPrivate::createWidgetItem(l, wid); }-
23 ~QGridBox() { delete item_; }-
24-
25 QSize sizeHint() const { return item_->sizeHint(); }-
26 QSize minimumSize() const { return item_->minimumSize(); }-
27 QSize maximumSize() const { return item_->maximumSize(); }-
28 Qt::Orientations expandingDirections() const { return item_->expandingDirections(); }-
29 bool isEmpty() const { return item_->isEmpty(); }-
30-
31 bool hasHeightForWidth() const { return item_->hasHeightForWidth(); }-
32 int heightForWidth(int w) const { return item_->heightForWidth(w); }-
33-
34 void setAlignment(Qt::Alignment a) { item_->setAlignment(a); }-
35 void setGeometry(const QRect &r) { item_->setGeometry(r); }-
36 Qt::Alignment alignment() const { return item_->alignment(); }-
37 QLayoutItem *item() { return item_; }-
38 void setItem(QLayoutItem *newitem) { item_ = newitem; }-
39 QLayoutItem *takeItem() { QLayoutItem *i = item_; item_ = 0; return i; }-
40-
41 int hStretch() { return item_->widget() ?-
42 item_->widget()->sizePolicy().horizontalStretch() : 0; }-
43 int vStretch() { return item_->widget() ?-
44 item_->widget()->sizePolicy().verticalStretch() : 0; }-
45-
46private:-
47 friend class QGridLayoutPrivate;-
48 friend class QGridLayout;-
49-
50 inline int toRow(int rr) const { return torow >= 0 ? torow : rr - 1; }-
51 inline int toCol(int cc) const { return tocol >= 0 ? tocol : cc - 1; }-
52-
53 QLayoutItem *item_;-
54 int row, col;-
55 int torow, tocol;-
56};-
57-
58class QGridLayoutPrivate : public QLayoutPrivate-
59{-
60 inline QGridLayout* q_func() { return static_cast<QGridLayout *>(q_ptr); } inline const QGridLayout* q_func() const { return static_cast<const QGridLayout *>(q_ptr); } friend class QGridLayout;-
61public:-
62 QGridLayoutPrivate();-
63-
64 void add(QGridBox*, int row, int col);-
65 void add(QGridBox*, int row1, int row2, int col1, int col2);-
66 QSize sizeHint(int hSpacing, int vSpacing) const;-
67 QSize minimumSize(int hSpacing, int vSpacing) const;-
68 QSize maximumSize(int hSpacing, int vSpacing) const;-
69-
70 Qt::Orientations expandingDirections(int hSpacing, int vSpacing) const;-
71-
72 void distribute(QRect rect, int hSpacing, int vSpacing);-
73 inline int numRows() const { return rr; }-
74 inline int numCols() const { return cc; }-
75 inline void expand(int rows, int cols)-
76 { setSize(qMax(rows, rr), qMax(cols, cc)); }-
77 inline void setRowStretch(int r, int s)-
78 { expand(r + 1, 0); rStretch[r] = s; setDirty(); }-
79 inline void setColStretch(int c, int s)-
80 { expand(0, c + 1); cStretch[c] = s; setDirty(); }-
81 inline int rowStretch(int r) const { return rStretch.at(r); }-
82 inline int colStretch(int c) const { return cStretch.at(c); }-
83 inline void setRowMinimumHeight(int r, int s)-
84 { expand(r + 1, 0); rMinHeights[r] = s; setDirty(); }-
85 inline void setColumnMinimumWidth(int c, int s)-
86 { expand(0, c + 1); cMinWidths[c] = s; setDirty(); }-
87 inline int rowSpacing(int r) const { return rMinHeights.at(r); }-
88 inline int colSpacing(int c) const { return cMinWidths.at(c); }-
89-
90 inline void setReversed(bool r, bool c) { hReversed = c; vReversed = r; }-
91 inline bool horReversed() const { return hReversed; }-
92 inline bool verReversed() const { return vReversed; }-
93 inline void setDirty() { needRecalc = true; hfw_width = -1; }-
94 inline bool isDirty() const { return needRecalc; }-
95 bool hasHeightForWidth(int hSpacing, int vSpacing);-
96 int heightForWidth(int width, int hSpacing, int vSpacing);-
97 int minimumHeightForWidth(int width, int hSpacing, int vSpacing);-
98-
99 inline void getNextPos(int &row, int &col) { row = nextR; col = nextC; }-
100 inline int count() const { return things.count(); }-
101 QRect cellRect(int row, int col) const;-
102-
103 inline QLayoutItem *itemAt(int index) const {-
104 if (index < things.count())-
105 return things.at(index)->item();-
106 else-
107 return 0;-
108 }-
109 inline QLayoutItem *takeAt(int index) {-
110 QGridLayout * const q = q_func();-
111 if (index < things.count()) {-
112 if (QGridBox *b = things.takeAt(index)) {-
113 QLayoutItem *item = b->takeItem();-
114 if (QLayout *l = item->layout()) {-
115-
116 if (l->parent() == q)-
117 l->setParent(0);-
118 }-
119 delete b;-
120 return item;-
121 }-
122 }-
123 return 0;-
124 }-
125 QLayoutItem* replaceAt(int index, QLayoutItem *newitem) override-
126 {-
127 if (!newitem)-
128 return 0;-
129 QLayoutItem *item = 0;-
130 QGridBox *b = things.value(index);-
131 if (b) {-
132 item = b->takeItem();-
133 b->setItem(newitem);-
134 }-
135 return item;-
136 }-
137-
138 void getItemPosition(int index, int *row, int *column, int *rowSpan, int *columnSpan) const {-
139 if (index < things.count()) {-
140 const QGridBox *b = things.at(index);-
141 int toRow = b->toRow(rr);-
142 int toCol = b->toCol(cc);-
143 *row = b->row;-
144 *column = b->col;-
145 *rowSpan = toRow - *row + 1;-
146 *columnSpan = toCol - *column +1;-
147 }-
148 }-
149 void deleteAll();-
150-
151private:-
152 void setNextPosAfter(int r, int c);-
153 void recalcHFW(int w);-
154 void addHfwData(QGridBox *box, int width);-
155 void init();-
156 QSize findSize(int QLayoutStruct::*, int hSpacing, int vSpacing) const;-
157 void addData(QGridBox *b, const QGridLayoutSizeTriple &sizes, bool r, bool c);-
158 void setSize(int rows, int cols);-
159 void setupSpacings(QVector<QLayoutStruct> &chain, QGridBox *grid[], int fixedSpacing,-
160 Qt::Orientation orientation);-
161 void setupLayoutData(int hSpacing, int vSpacing);-
162 void setupHfwLayoutData();-
163 void effectiveMargins(int *left, int *top, int *right, int *bottom) const;-
164-
165 int rr;-
166 int cc;-
167 QVector<QLayoutStruct> rowData;-
168 QVector<QLayoutStruct> colData;-
169 QVector<QLayoutStruct> *hfwData;-
170 QVector<int> rStretch;-
171 QVector<int> cStretch;-
172 QVector<int> rMinHeights;-
173 QVector<int> cMinWidths;-
174 QList<QGridBox *> things;-
175-
176 int hfw_width;-
177 int hfw_height;-
178 int hfw_minheight;-
179 int nextR;-
180 int nextC;-
181-
182 int horizontalSpacing;-
183 int verticalSpacing;-
184 int leftMargin;-
185 int topMargin;-
186 int rightMargin;-
187 int bottomMargin;-
188-
189 uint hReversed : 1;-
190 uint vReversed : 1;-
191 uint needRecalc : 1;-
192 uint has_hfw : 1;-
193 uint addVertical : 1;-
194};-
195-
196void QGridLayoutPrivate::effectiveMargins(int *left, int *top, int *right, int *bottom) const-
197{-
198 int l = leftMargin;-
199 int t = topMargin;-
200 int r = rightMargin;-
201 int b = bottomMargin;-
202 if (left)-
203 *left = l;-
204 if (top)-
205 *top = t;-
206 if (right)-
207 *right = r;-
208 if (bottom)-
209 *bottom = b;-
210}-
211-
212QGridLayoutPrivate::QGridLayoutPrivate()-
213{-
214 addVertical = false;-
215 setDirty();-
216 rr = cc = 0;-
217 nextR = nextC = 0;-
218 hfwData = 0;-
219 hReversed = false;-
220 vReversed = false;-
221 horizontalSpacing = -1;-
222 verticalSpacing = -1;-
223}-
224void QGridLayoutPrivate::deleteAll()-
225{-
226 while (!things.isEmpty())-
227 delete things.takeFirst();-
228 delete hfwData;-
229}-
230-
231bool QGridLayoutPrivate::hasHeightForWidth(int hSpacing, int vSpacing)-
232{-
233 setupLayoutData(hSpacing, vSpacing);-
234 return has_hfw;-
235}-
236-
237-
238-
239-
240-
241void QGridLayoutPrivate::recalcHFW(int w)-
242{-
243-
244-
245-
246-
247 if (!hfwData)-
248 hfwData = new QVector<QLayoutStruct>(rr);-
249 setupHfwLayoutData();-
250 QVector<QLayoutStruct> &rData = *hfwData;-
251-
252 int h = 0;-
253 int mh = 0;-
254 for (int r = 0; r < rr; r++) {-
255 int spacing = rData.at(r).spacing;-
256 h += rData.at(r).sizeHint + spacing;-
257 mh += rData.at(r).minimumSize + spacing;-
258 }-
259-
260 hfw_width = w;-
261 hfw_height = qMin(QLAYOUTSIZE_MAX, h);-
262 hfw_minheight = qMin(QLAYOUTSIZE_MAX, mh);-
263}-
264-
265int QGridLayoutPrivate::heightForWidth(int w, int hSpacing, int vSpacing)-
266{-
267 setupLayoutData(hSpacing, vSpacing);-
268 if (!has_hfw)-
269 return -1;-
270 int left, top, right, bottom;-
271 effectiveMargins(&left, &top, &right, &bottom);-
272-
273 int hMargins = left + right;-
274 if (w - hMargins != hfw_width) {-
275 qGeomCalc(colData, 0, cc, 0, w - hMargins);-
276 recalcHFW(w - hMargins);-
277 }-
278 return hfw_height + top + bottom;-
279}-
280-
281int QGridLayoutPrivate::minimumHeightForWidth(int w, int hSpacing, int vSpacing)-
282{-
283 (void)heightForWidth(w, hSpacing, vSpacing);-
284 if (!has_hfw)-
285 return -1;-
286 int top, bottom;-
287 effectiveMargins(0, &top, 0, &bottom);-
288 return hfw_minheight + top + bottom;-
289}-
290-
291QSize QGridLayoutPrivate::findSize(int QLayoutStruct::*size, int hSpacing, int vSpacing) const-
292{-
293 QGridLayoutPrivate *that = const_cast<QGridLayoutPrivate*>(this);-
294 that->setupLayoutData(hSpacing, vSpacing);-
295-
296 int w = 0;-
297 int h = 0;-
298-
299 for (int r = 0; r < rr; r++)-
300 h += rowData.at(r).*size + rowData.at(r).spacing;-
301 for (int c = 0; c < cc; c++)-
302 w += colData.at(c).*size + colData.at(c).spacing;-
303-
304 w = qMin(QLAYOUTSIZE_MAX, w);-
305 h = qMin(QLAYOUTSIZE_MAX, h);-
306-
307 return QSize(w, h);-
308}-
309-
310Qt::Orientations QGridLayoutPrivate::expandingDirections(int hSpacing, int vSpacing) const-
311{-
312 QGridLayoutPrivate *that = const_cast<QGridLayoutPrivate*>(this);-
313 that->setupLayoutData(hSpacing, vSpacing);-
314 Qt::Orientations ret;-
315-
316 for (int r = 0; r < rr; r++) {-
317 if (rowData.at(r).expansive) {-
318 ret |= Qt::Vertical;-
319 break;-
320 }-
321 }-
322 for (int c = 0; c < cc; c++) {-
323 if (colData.at(c).expansive) {-
324 ret |= Qt::Horizontal;-
325 break;-
326 }-
327 }-
328 return ret;-
329}-
330-
331QSize QGridLayoutPrivate::sizeHint(int hSpacing, int vSpacing) const-
332{-
333 return findSize(&QLayoutStruct::sizeHint, hSpacing, vSpacing);-
334}-
335-
336QSize QGridLayoutPrivate::maximumSize(int hSpacing, int vSpacing) const-
337{-
338 return findSize(&QLayoutStruct::maximumSize, hSpacing, vSpacing);-
339}-
340-
341QSize QGridLayoutPrivate::minimumSize(int hSpacing, int vSpacing) const-
342{-
343 return findSize(&QLayoutStruct::minimumSize, hSpacing, vSpacing);-
344}-
345-
346void QGridLayoutPrivate::setSize(int r, int c)-
347{-
348 if ((int)rowData.size() < r) {-
349 int newR = qMax(r, rr * 2);-
350 rowData.resize(newR);-
351 rStretch.resize(newR);-
352 rMinHeights.resize(newR);-
353 for (int i = rr; i < newR; i++) {-
354 rowData[i].init();-
355 rowData[i].maximumSize = 0;-
356 rowData[i].pos = 0;-
357 rowData[i].size = 0;-
358 rStretch[i] = 0;-
359 rMinHeights[i] = 0;-
360 }-
361 }-
362 if ((int)colData.size() < c) {-
363 int newC = qMax(c, cc * 2);-
364 colData.resize(newC);-
365 cStretch.resize(newC);-
366 cMinWidths.resize(newC);-
367 for (int i = cc; i < newC; i++) {-
368 colData[i].init();-
369 colData[i].maximumSize = 0;-
370 colData[i].pos = 0;-
371 colData[i].size = 0;-
372 cStretch[i] = 0;-
373 cMinWidths[i] = 0;-
374 }-
375 }-
376-
377 if (hfwData && (int)hfwData->size() < r) {-
378 delete hfwData;-
379 hfwData = 0;-
380 hfw_width = -1;-
381 }-
382 rr = r;-
383 cc = c;-
384}-
385-
386void QGridLayoutPrivate::setNextPosAfter(int row, int col)-
387{-
388 if (addVertical) {-
389 if (col > nextC || (col == nextC && row >= nextR)) {-
390 nextR = row + 1;-
391 nextC = col;-
392 if (nextR >= rr) {-
393 nextR = 0;-
394 nextC++;-
395 }-
396 }-
397 } else {-
398 if (row > nextR || (row == nextR && col >= nextC)) {-
399 nextR = row;-
400 nextC = col + 1;-
401 if (nextC >= cc) {-
402 nextC = 0;-
403 nextR++;-
404 }-
405 }-
406 }-
407}-
408-
409void QGridLayoutPrivate::add(QGridBox *box, int row, int col)-
410{-
411 expand(row + 1, col + 1);-
412 box->row = box->torow = row;-
413 box->col = box->tocol = col;-
414 things.append(box);-
415 setDirty();-
416 setNextPosAfter(row, col);-
417}-
418-
419void QGridLayoutPrivate::add(QGridBox *box, int row1, int row2, int col1, int col2)-
420{-
421 if (__builtin_expect(!!(
__builtin_expe... row1), false)Description
TRUEnever evaluated
FALSEnever evaluated
row2 >= 0 && row2 < row1)), false)
__builtin_expe... row1), false)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
422 QMessageLogger(__FILE__, 561567, __PRETTY_FUNCTION__).warning("QGridLayout: Multi-cell fromRow greater than toRow");
never executed: QMessageLogger(__FILE__, 567, __PRETTY_FUNCTION__).warning("QGridLayout: Multi-cell fromRow greater than toRow");
0
423 if (__builtin_expect(!!(
__builtin_expe... col1), false)Description
TRUEnever evaluated
FALSEnever evaluated
col2 >= 0 && col2 < col1)), false)
__builtin_expe... col1), false)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
424 QMessageLogger(__FILE__, 563569, __PRETTY_FUNCTION__).warning("QGridLayout: Multi-cell fromCol greater than toCol");
never executed: QMessageLogger(__FILE__, 569, __PRETTY_FUNCTION__).warning("QGridLayout: Multi-cell fromCol greater than toCol");
0
425 if (row1 == row2
row1 == row2Description
TRUEnever evaluated
FALSEnever evaluated
&& col1 == col2
col1 == col2Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
426 add(box, row1, col1);-
427 return;
never executed: return;
0
428 }-
429 expand(qMax(row1, row2) + 1, qMax(col1, col2) + 1);-
430 box->row = row1;-
431 box->col = col1;-
432-
433 box->torow = row2;-
434 box->tocol = col2;-
435-
436 things.append(box);-
437 setDirty();-
438 if (col2 < 0
col2 < 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
439 col2 = cc - 1;
never executed: col2 = cc - 1;
0
440-
441 setNextPosAfter(row2, col2);-
442}
never executed: end of block
0
443-
444void QGridLayoutPrivate::addData(QGridBox *box, const QGridLayoutSizeTriple &sizes, bool r, bool c)-
445{-
446 const QWidget *widget = box->item()->widget();-
447-
448 if (box->isEmpty() && widget)-
449 return;-
450-
451 if (c) {-
452 QLayoutStruct *data = &colData[box->col];-
453 if (!cStretch.at(box->col))-
454 data->stretch = qMax(data->stretch, box->hStretch());-
455 data->sizeHint = qMax(sizes.hint.width(), data->sizeHint);-
456 data->minimumSize = qMax(sizes.minS.width(), data->minimumSize);-
457-
458 qMaxExpCalc(data->maximumSize, data->expansive, data->empty, sizes.maxS.width(),-
459 box->expandingDirections() & Qt::Horizontal, box->isEmpty());-
460 }-
461 if (r) {-
462 QLayoutStruct *data = &rowData[box->row];-
463 if (!rStretch.at(box->row))-
464 data->stretch = qMax(data->stretch, box->vStretch());-
465 data->sizeHint = qMax(sizes.hint.height(), data->sizeHint);-
466 data->minimumSize = qMax(sizes.minS.height(), data->minimumSize);-
467-
468 qMaxExpCalc(data->maximumSize, data->expansive, data->empty, sizes.maxS.height(),-
469 box->expandingDirections() & Qt::Vertical, box->isEmpty());-
470 }-
471}-
472-
473static void initEmptyMultiBox(QVector<QLayoutStruct> &chain, int start, int end)-
474{-
475 for (int i = start; i <= end; i++) {-
476 QLayoutStruct *data = &chain[i];-
477 if (data->empty && data->maximumSize == 0)-
478 data->maximumSize = ((1<<24)-1);-
479 data->empty = false;-
480 }-
481}-
482-
483static void distributeMultiBox(QVector<QLayoutStruct> &chain, int start, int end, int minSize,-
484 int sizeHint, QVector<int> &stretchArray, int stretch)-
485{-
486 int i;-
487 int w = 0;-
488 int wh = 0;-
489 int max = 0;-
490-
491 for (i = start; i <= end; i++) {-
492 QLayoutStruct *data = &chain[i];-
493 w += data->minimumSize;-
494 wh += data->sizeHint;-
495 max += data->maximumSize;-
496 if (stretchArray.at(i) == 0)-
497 data->stretch = qMax(data->stretch, stretch);-
498-
499 if (i != end) {-
500 int spacing = data->spacing;-
501 w += spacing;-
502 wh += spacing;-
503 max += spacing;-
504 }-
505 }-
506-
507 if (max < minSize) {-
508-
509-
510-
511-
512-
513-
514-
515 qGeomCalc(chain, start, end - start + 1, 0, minSize);-
516 int pos = 0;-
517 for (i = start; i <= end; i++) {-
518 QLayoutStruct *data = &chain[i];-
519 int nextPos = (i == end) ? minSize : chain.at(i + 1).pos;-
520 int realSize = nextPos - pos;-
521 if (i != end)-
522 realSize -= data->spacing;-
523 if (data->minimumSize < realSize)-
524 data->minimumSize = realSize;-
525 if (data->maximumSize < data->minimumSize)-
526 data->maximumSize = data->minimumSize;-
527 pos = nextPos;-
528 }-
529 } else if (w < minSize) {-
530 qGeomCalc(chain, start, end - start + 1, 0, minSize);-
531 for (i = start; i <= end; i++) {-
532 QLayoutStruct *data = &chain[i];-
533 if (data->minimumSize < data->size)-
534 data->minimumSize = data->size;-
535 }-
536 }-
537-
538 if (wh < sizeHint) {-
539 qGeomCalc(chain, start, end - start + 1, 0, sizeHint);-
540 for (i = start; i <= end; i++) {-
541 QLayoutStruct *data = &chain[i];-
542 if (data->sizeHint < data->size)-
543 data->sizeHint = data->size;-
544 }-
545 }-
546}-
547-
548static QGridBox *&gridAt(QGridBox *grid[], int r, int c, int cc,-
549 Qt::Orientation orientation = Qt::Vertical)-
550{-
551 if (orientation == Qt::Horizontal)-
552 qSwap(r, c);-
553 return grid[(r * cc) + c];-
554}-
555-
556void QGridLayoutPrivate::setupSpacings(QVector<QLayoutStruct> &chain,-
557 QGridBox *grid[], int fixedSpacing,-
558 Qt::Orientation orientation)-
559{-
560 QGridLayout * const q = q_func();-
561 int numRows = rr;-
562 int numColumns = cc;-
563-
564 if (orientation == Qt::Horizontal) {-
565 qSwap(numRows, numColumns);-
566 }-
567-
568 QStyle *style = 0;-
569 if (fixedSpacing < 0) {-
570 if (QWidget *parentWidget = q->parentWidget())-
571 style = parentWidget->style();-
572 }-
573-
574 for (int c = 0; c < numColumns; ++c) {-
575 QGridBox *previousBox = 0;-
576 int previousRow = -1;-
577-
578 for (int r = 0; r < numRows; ++r) {-
579 if (chain.at(r).empty)-
580 continue;-
581-
582 QGridBox *box = gridAt(grid, r, c, cc, orientation);-
583 if (previousRow != -1 && (!box || previousBox != box)) {-
584 int spacing = fixedSpacing;-
585 if (spacing < 0) {-
586 QSizePolicy::ControlTypes controlTypes1 = QSizePolicy::DefaultType;-
587 QSizePolicy::ControlTypes controlTypes2 = QSizePolicy::DefaultType;-
588 if (previousBox)-
589 controlTypes1 = previousBox->item()->controlTypes();-
590 if (box)-
591 controlTypes2 = box->item()->controlTypes();-
592-
593 if ((orientation == Qt::Horizontal && hReversed)-
594 || (orientation == Qt::Vertical && vReversed))-
595 qSwap(controlTypes1, controlTypes2);-
596-
597 if (style)-
598 spacing = style->combinedLayoutSpacing(controlTypes1, controlTypes2,-
599 orientation, 0, q->parentWidget());-
600 } else {-
601 if (orientation == Qt::Vertical) {-
602 QGridBox *sibling = vReversed ? previousBox : box;-
603 if (sibling) {-
604 QWidget *wid = sibling->item()->widget();-
605 if (wid)-
606 spacing = qMax(spacing, sibling->item()->geometry().top() - wid->geometry().top() );-
607 }-
608 }-
609 }-
610-
611 if (spacing > chain.at(previousRow).spacing)-
612 chain[previousRow].spacing = spacing;-
613 }-
614-
615 previousBox = box;-
616 previousRow = r;-
617 }-
618 }-
619}-
620-
621-
622-
623void QGridLayoutPrivate::setupLayoutData(int hSpacing, int vSpacing)-
624{-
625 QGridLayout * const q = q_func();-
626-
627-
628 if (!needRecalc)-
629 return;-
630-
631 has_hfw = false;-
632 int i;-
633-
634 for (i = 0; i < rr; i++) {-
635 rowData[i].init(rStretch.at(i), rMinHeights.at(i));-
636 rowData[i].maximumSize = rStretch.at(i) ? QLAYOUTSIZE_MAX : rMinHeights.at(i);-
637 }-
638 for (i = 0; i < cc; i++) {-
639 colData[i].init(cStretch.at(i), cMinWidths.at(i));-
640 colData[i].maximumSize = cStretch.at(i) ? QLAYOUTSIZE_MAX : cMinWidths.at(i);-
641 }-
642-
643 int n = things.size();-
644 QVarLengthArray<QGridLayoutSizeTriple> sizes(n);-
645-
646 bool has_multi = false;-
647-
648-
649-
650-
651-
652 QVarLengthArray<QGridBox *> grid(rr * cc);-
653 memset(grid.data(), 0, rr * cc * sizeof(QGridBox *));-
654-
655-
656-
657-
658-
659 for (i = 0; i < n; ++i) {-
660 QGridBox * const box = things.at(i);-
661 sizes[i].minS = box->minimumSize();-
662 sizes[i].hint = box->sizeHint();-
663 sizes[i].maxS = box->maximumSize();-
664-
665 if (box->hasHeightForWidth())-
666 has_hfw = true;-
667-
668 if (box->row == box->toRow(rr)) {-
669 addData(box, sizes[i], true, false);-
670 } else {-
671 initEmptyMultiBox(rowData, box->row, box->toRow(rr));-
672 has_multi = true;-
673 }-
674-
675 if (box->col == box->toCol(cc)) {-
676 addData(box, sizes[i], false, true);-
677 } else {-
678 initEmptyMultiBox(colData, box->col, box->toCol(cc));-
679 has_multi = true;-
680 }-
681-
682 for (int r = box->row; r <= box->toRow(rr); ++r) {-
683 for (int c = box->col; c <= box->toCol(cc); ++c) {-
684 gridAt(grid.data(), r, c, cc) = box;-
685 }-
686 }-
687 }-
688-
689 setupSpacings(colData, grid.data(), hSpacing, Qt::Horizontal);-
690 setupSpacings(rowData, grid.data(), vSpacing, Qt::Vertical);-
691-
692-
693-
694-
695-
696-
697 if (has_multi) {-
698 for (i = 0; i < n; ++i) {-
699 QGridBox * const box = things.at(i);-
700-
701 if (box->row != box->toRow(rr))-
702 distributeMultiBox(rowData, box->row, box->toRow(rr), sizes[i].minS.height(),-
703 sizes[i].hint.height(), rStretch, box->vStretch());-
704 if (box->col != box->toCol(cc))-
705 distributeMultiBox(colData, box->col, box->toCol(cc), sizes[i].minS.width(),-
706 sizes[i].hint.width(), cStretch, box->hStretch());-
707 }-
708 }-
709-
710 for (i = 0; i < rr; i++)-
711 rowData[i].expansive = rowData.at(i).expansive || rowData.at(i).stretch > 0;-
712 for (i = 0; i < cc; i++)-
713 colData[i].expansive = colData.at(i).expansive || colData.at(i).stretch > 0;-
714-
715 q->getContentsMargins(&leftMargin, &topMargin, &rightMargin, &bottomMargin);-
716-
717 needRecalc = false;-
718}-
719-
720void QGridLayoutPrivate::addHfwData(QGridBox *box, int width)-
721{-
722 QVector<QLayoutStruct> &rData = *hfwData;-
723 if (box->hasHeightForWidth()) {-
724 int hint = box->heightForWidth(width);-
725 rData[box->row].sizeHint = qMax(hint, rData.at(box->row).sizeHint);-
726 rData[box->row].minimumSize = qMax(hint, rData.at(box->row).minimumSize);-
727 } else {-
728 QSize hint = box->sizeHint();-
729 QSize minS = box->minimumSize();-
730 rData[box->row].sizeHint = qMax(hint.height(), rData.at(box->row).sizeHint);-
731 rData[box->row].minimumSize = qMax(minS.height(), rData.at(box->row).minimumSize);-
732 }-
733}-
734-
735-
736-
737-
738-
739-
740void QGridLayoutPrivate::setupHfwLayoutData()-
741{-
742 QVector<QLayoutStruct> &rData = *hfwData;-
743 for (int i = 0; i < rr; i++) {-
744 rData[i] = rowData.at(i);-
745 rData[i].minimumSize = rData[i].sizeHint = rMinHeights.at(i);-
746 }-
747-
748 for (int pass = 0; pass < 2; ++pass) {-
749 for (int i = 0; i < things.size(); ++i) {-
750 QGridBox *box = things.at(i);-
751 int r1 = box->row;-
752 int c1 = box->col;-
753 int r2 = box->toRow(rr);-
754 int c2 = box->toCol(cc);-
755 int w = colData.at(c2).pos + colData.at(c2).size - colData.at(c1).pos;-
756-
757 if (r1 == r2) {-
758 if (pass == 0)-
759 addHfwData(box, w);-
760 } else {-
761 if (pass == 0) {-
762 initEmptyMultiBox(rData, r1, r2);-
763 } else {-
764 QSize hint = box->sizeHint();-
765 QSize min = box->minimumSize();-
766 if (box->hasHeightForWidth()) {-
767 int hfwh = box->heightForWidth(w);-
768 if (hfwh > hint.height())-
769 hint.setHeight(hfwh);-
770 if (hfwh > min.height())-
771 min.setHeight(hfwh);-
772 }-
773 distributeMultiBox(rData, r1, r2, min.height(), hint.height(),-
774 rStretch, box->vStretch());-
775 }-
776 }-
777 }-
778 }-
779 for (int i = 0; i < rr; i++)-
780 rData[i].expansive = rData.at(i).expansive || rData.at(i).stretch > 0;-
781}-
782-
783void QGridLayoutPrivate::distribute(QRect r, int hSpacing, int vSpacing)-
784{-
785 QGridLayout * const q = q_func();-
786 bool visualHReversed = hReversed;-
787 QWidget *parent = q->parentWidget();-
788 if (parent && parent->isRightToLeft())-
789 visualHReversed = !visualHReversed;-
790-
791 setupLayoutData(hSpacing, vSpacing);-
792-
793 int left, top, right, bottom;-
794 effectiveMargins(&left, &top, &right, &bottom);-
795 r.adjust(+left, +top, -right, -bottom);-
796-
797 qGeomCalc(colData, 0, cc, r.x(), r.width());-
798 QVector<QLayoutStruct> *rDataPtr;-
799 if (has_hfw) {-
800 recalcHFW(r.width());-
801 qGeomCalc(*hfwData, 0, rr, r.y(), r.height());-
802 rDataPtr = hfwData;-
803 } else {-
804 qGeomCalc(rowData, 0, rr, r.y(), r.height());-
805 rDataPtr = &rowData;-
806 }-
807 QVector<QLayoutStruct> &rData = *rDataPtr;-
808 int i;-
809-
810 bool reverse = ((r.bottom() > rect.bottom()) || (r.bottom() == rect.bottom()-
811 && ((r.right() > rect.right()) != visualHReversed)));-
812 int n = things.size();-
813 for (i = 0; i < n; ++i) {-
814 QGridBox *box = things.at(reverse ? n-i-1 : i);-
815 int r2 = box->toRow(rr);-
816 int c2 = box->toCol(cc);-
817-
818 int x = colData.at(box->col).pos;-
819 int y = rData.at(box->row).pos;-
820 int x2p = colData.at(c2).pos + colData.at(c2).size;-
821 int y2p = rData.at(r2).pos + rData.at(r2).size;-
822 int w = x2p - x;-
823 int h = y2p - y;-
824-
825 if (visualHReversed)-
826 x = r.left() + r.right() - x - w + 1;-
827 if (vReversed)-
828 y = r.top() + r.bottom() - y - h + 1;-
829-
830 box->setGeometry(QRect(x, y, w, h));-
831 }-
832}-
833-
834QRect QGridLayoutPrivate::cellRect(int row, int col) const-
835{-
836 if (row < 0 || row >= rr || col < 0 || col >= cc)-
837 return QRect();-
838-
839 const QVector<QLayoutStruct> *rDataPtr;-
840 if (has_hfw && hfwData)-
841 rDataPtr = hfwData;-
842 else-
843 rDataPtr = &rowData;-
844 return QRect(colData.at(col).pos, rDataPtr->at(row).pos,-
845 colData.at(col).size, rDataPtr->at(row).size);-
846}-
847QGridLayout::QGridLayout(QWidget *parent)-
848 : QLayout(*new QGridLayoutPrivate, 0, parent)-
849{-
850 QGridLayoutPrivate * const d = d_func();-
851 d->expand(1, 1);-
852}-
853QGridLayout::QGridLayout()-
854 : QLayout(*new QGridLayoutPrivate, 0, 0)-
855{-
856 QGridLayoutPrivate * const d = d_func();-
857 d->expand(1, 1);-
858}-
859void QGridLayout::setDefaultPositioning(int n, Qt::Orientation orient)-
860{-
861 QGridLayoutPrivate * const d = d_func();-
862 if (orient == Qt::Horizontal) {-
863 d->expand(1, n);-
864 d->addVertical = false;-
865 } else {-
866 d->expand(n,1);-
867 d->addVertical = true;-
868 }-
869}-
870QGridLayout::~QGridLayout()-
871{-
872 QGridLayoutPrivate * const d = d_func();-
873 d->deleteAll();-
874}-
875void QGridLayout::setHorizontalSpacing(int spacing)-
876{-
877 QGridLayoutPrivate * const d = d_func();-
878 d->horizontalSpacing = spacing;-
879 invalidate();-
880}-
881-
882int QGridLayout::horizontalSpacing() const-
883{-
884 const QGridLayoutPrivate * const d = d_func();-
885 if (d->horizontalSpacing >= 0) {-
886 return d->horizontalSpacing;-
887 } else {-
888 return qSmartSpacing(this, QStyle::PM_LayoutHorizontalSpacing);-
889 }-
890}-
891void QGridLayout::setVerticalSpacing(int spacing)-
892{-
893 QGridLayoutPrivate * const d = d_func();-
894 d->verticalSpacing = spacing;-
895 invalidate();-
896}-
897-
898int QGridLayout::verticalSpacing() const-
899{-
900 const QGridLayoutPrivate * const d = d_func();-
901 if (d->verticalSpacing >= 0) {-
902 return d->verticalSpacing;-
903 } else {-
904 return qSmartSpacing(this, QStyle::PM_LayoutVerticalSpacing);-
905 }-
906}-
907-
908-
909-
910-
911-
912-
913-
914void QGridLayout::setSpacing(int spacing)-
915{-
916 QGridLayoutPrivate * const d = d_func();-
917 d->horizontalSpacing = d->verticalSpacing = spacing;-
918 invalidate();-
919}-
920-
921-
922-
923-
924-
925-
926-
927int QGridLayout::spacing() const-
928{-
929 int hSpacing = horizontalSpacing();-
930 if (hSpacing == verticalSpacing()) {-
931 return hSpacing;-
932 } else {-
933 return -1;-
934 }-
935}-
936-
937-
938-
939-
940int QGridLayout::rowCount() const-
941{-
942 const QGridLayoutPrivate * const d = d_func();-
943 return d->numRows();-
944}-
945-
946-
947-
948-
949int QGridLayout::columnCount() const-
950{-
951 const QGridLayoutPrivate * const d = d_func();-
952 return d->numCols();-
953}-
954-
955-
956-
957-
958QSize QGridLayout::sizeHint() const-
959{-
960 const QGridLayoutPrivate * const d = d_func();-
961 QSize result(d->sizeHint(horizontalSpacing(), verticalSpacing()));-
962 int left, top, right, bottom;-
963 d->effectiveMargins(&left, &top, &right, &bottom);-
964 result += QSize(left + right, top + bottom);-
965 return result;-
966}-
967-
968-
969-
970-
971QSize QGridLayout::minimumSize() const-
972{-
973 const QGridLayoutPrivate * const d = d_func();-
974 QSize result(d->minimumSize(horizontalSpacing(), verticalSpacing()));-
975 int left, top, right, bottom;-
976 d->effectiveMargins(&left, &top, &right, &bottom);-
977 result += QSize(left + right, top + bottom);-
978 return result;-
979}-
980-
981-
982-
983-
984QSize QGridLayout::maximumSize() const-
985{-
986 const QGridLayoutPrivate * const d = d_func();-
987-
988 QSize s = d->maximumSize(horizontalSpacing(), verticalSpacing());-
989 int left, top, right, bottom;-
990 d->effectiveMargins(&left, &top, &right, &bottom);-
991 s += QSize(left + right, top + bottom);-
992 s = s.boundedTo(QSize(QLAYOUTSIZE_MAX, QLAYOUTSIZE_MAX));-
993 if (alignment() & Qt::AlignHorizontal_Mask)-
994 s.setWidth(QLAYOUTSIZE_MAX);-
995 if (alignment() & Qt::AlignVertical_Mask)-
996 s.setHeight(QLAYOUTSIZE_MAX);-
997 return s;-
998}-
999-
1000-
1001-
1002-
1003bool QGridLayout::hasHeightForWidth() const-
1004{-
1005 return const_cast<QGridLayout*>(this)->d_func()->hasHeightForWidth(horizontalSpacing(), verticalSpacing());-
1006}-
1007-
1008-
1009-
1010-
1011int QGridLayout::heightForWidth(int w) const-
1012{-
1013 const QGridLayoutPrivate * const d = d_func();-
1014 QGridLayoutPrivate *dat = const_cast<QGridLayoutPrivate *>(d);-
1015 return dat->heightForWidth(w, horizontalSpacing(), verticalSpacing());-
1016}-
1017-
1018-
1019-
1020-
1021int QGridLayout::minimumHeightForWidth(int w) const-
1022{-
1023 const QGridLayoutPrivate * const d = d_func();-
1024 QGridLayoutPrivate *dat = const_cast<QGridLayoutPrivate *>(d);-
1025 return dat->minimumHeightForWidth(w, horizontalSpacing(), verticalSpacing());-
1026}-
1027-
1028-
1029-
1030-
1031int QGridLayout::count() const-
1032{-
1033 const QGridLayoutPrivate * const d = d_func();-
1034 return d->count();-
1035}-
1036-
1037-
1038-
1039-
1040-
1041QLayoutItem *QGridLayout::itemAt(int index) const-
1042{-
1043 const QGridLayoutPrivate * const d = d_func();-
1044 return d->itemAt(index);-
1045}-
1046QLayoutItem *QGridLayout::itemAtPosition(int row, int column) const-
1047{-
1048 const QGridLayoutPrivate * const d = d_func();-
1049 int n = d->things.count();-
1050 for (int i = 0; i < n; ++i) {-
1051 QGridBox *box = d->things.at(i);-
1052 if (row >= box->row && row <= box->toRow(d->rr)-
1053 && column >= box->col && column <= box->toCol(d->cc)) {-
1054 return box->item();-
1055 }-
1056 }-
1057 return 0;-
1058}-
1059-
1060-
1061-
1062-
1063QLayoutItem *QGridLayout::takeAt(int index)-
1064{-
1065 QGridLayoutPrivate * const d = d_func();-
1066 return d->takeAt(index);-
1067}-
1068void QGridLayout::getItemPosition(int index, int *row, int *column, int *rowSpan, int *columnSpan) const-
1069{-
1070 const QGridLayoutPrivate * const d = d_func();-
1071 d->getItemPosition(index, row, column, rowSpan, columnSpan);-
1072}-
1073-
1074-
1075-
1076-
1077-
1078void QGridLayout::setGeometry(const QRect &rect)-
1079{-
1080 QGridLayoutPrivate * const d = d_func();-
1081 if (d->isDirty() || rect != geometry()) {-
1082 QRect cr = alignment() ? alignmentRect(rect) : rect;-
1083 d->distribute(cr, horizontalSpacing(), verticalSpacing());-
1084 QLayout::setGeometry(rect);-
1085 }-
1086}-
1087QRect QGridLayout::cellRect(int row, int column) const-
1088{-
1089 const QGridLayoutPrivate * const d = d_func();-
1090 return d->cellRect(row, column);-
1091}-
1092-
1093-
1094-
1095-
1096void QGridLayout::addItem(QLayoutItem *item)-
1097{-
1098 QGridLayoutPrivate * const d = d_func();-
1099 int r, c;-
1100 d->getNextPos(r, c);-
1101 addItem(item, r, c);-
1102}-
1103void QGridLayout::addItem(QLayoutItem *item, int row, int column, int rowSpan, int columnSpan, Qt::Alignment alignment)-
1104{-
1105 QGridLayoutPrivate * const d = d_func();-
1106 QGridBox *b = new QGridBox(item);-
1107 b->setAlignment(alignment);-
1108 d->add(b, row, (rowSpan < 0) ? -1 : row + rowSpan - 1, column, (columnSpan < 0) ? -1 : column + columnSpan - 1);-
1109 invalidate();-
1110}-
1111void QGridLayout::addWidget(QWidget *widget, int row, int column, Qt::Alignment alignment)-
1112{-
1113 QGridLayoutPrivate * const d = d_func();-
1114 if (!d->checkWidget(widget)
!d->checkWidget(widget)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
1115 return;
never executed: return;
0
1116 if (__builtin_expect(!!(
__builtin_expe...n < 0), false)Description
TRUEnever evaluated
FALSEnever evaluated
row < 0 || column < 0)), false)
__builtin_expe...n < 0), false)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
1117 QMessageLogger(__FILE__, 14391445, __PRETTY_FUNCTION__).warning("QGridLayout: Cannot add %s/%s to %s/%s at row %d column %d",-
1118 widget->metaObject()->className(), widget->objectName().toLocal8Bit().data(),-
1119 metaObject()->className(), objectName().toLocal8Bit().data(), row, column);-
1120 return;
never executed: return;
0
1121 }-
1122 addChildWidget(widget);-
1123 QWidgetItem *b = QLayoutPrivate::createWidgetItem(this, widget);-
1124 addItem(b, row, column, 1, 1, alignment);-
1125}
never executed: end of block
0
1126void QGridLayout::addWidget(QWidget *widget, int fromRow, int fromColumn,-
1127 int rowSpan, int columnSpan, Qt::Alignment alignment)-
1128{-
1129 QGridLayoutPrivate * const d = d_func();-
1130 if (!d->checkWidget(widget))-
1131 return;-
1132 int toRow = (rowSpan < 0) ? -1 : fromRow + rowSpan - 1;-
1133 int toColumn = (columnSpan < 0) ? -1 : fromColumn + columnSpan - 1;-
1134 addChildWidget(widget);-
1135 QGridBox *b = new QGridBox(this, widget);-
1136 b->setAlignment(alignment);-
1137 d->add(b, fromRow, toRow, fromColumn, toColumn);-
1138 invalidate();-
1139}-
1140void QGridLayout::addLayout(QLayout *layout, int row, int column, Qt::Alignment alignment)-
1141{-
1142 QGridLayoutPrivate * const d = d_func();-
1143 if (!d->checkLayout(layout))-
1144 return;-
1145 if (!adoptLayout(layout))-
1146 return;-
1147 QGridBox *b = new QGridBox(layout);-
1148 b->setAlignment(alignment);-
1149 d->add(b, row, column);-
1150}-
1151void QGridLayout::addLayout(QLayout *layout, int row, int column,-
1152 int rowSpan, int columnSpan, Qt::Alignment alignment)-
1153{-
1154 QGridLayoutPrivate * const d = d_func();-
1155 if (!d->checkLayout(layout))-
1156 return;-
1157 if (!adoptLayout(layout))-
1158 return;-
1159 QGridBox *b = new QGridBox(layout);-
1160 b->setAlignment(alignment);-
1161 d->add(b, row, (rowSpan < 0) ? -1 : row + rowSpan - 1, column, (columnSpan < 0) ? -1 : column + columnSpan - 1);-
1162}-
1163void QGridLayout::setRowStretch(int row, int stretch)-
1164{-
1165 QGridLayoutPrivate * const d = d_func();-
1166 d->setRowStretch(row, stretch);-
1167 invalidate();-
1168}-
1169-
1170-
1171-
1172-
1173-
1174-
1175int QGridLayout::rowStretch(int row) const-
1176{-
1177 const QGridLayoutPrivate * const d = d_func();-
1178 return d->rowStretch(row);-
1179}-
1180-
1181-
1182-
1183-
1184-
1185-
1186int QGridLayout::columnStretch(int column) const-
1187{-
1188 const QGridLayoutPrivate * const d = d_func();-
1189 return d->colStretch(column);-
1190}-
1191void QGridLayout::setColumnStretch(int column, int stretch)-
1192{-
1193 QGridLayoutPrivate * const d = d_func();-
1194 d->setColStretch(column, stretch);-
1195 invalidate();-
1196}-
1197void QGridLayout::setRowMinimumHeight(int row, int minSize)-
1198{-
1199 QGridLayoutPrivate * const d = d_func();-
1200 d->setRowMinimumHeight(row, minSize);-
1201 invalidate();-
1202}-
1203-
1204-
1205-
1206-
1207-
1208-
1209int QGridLayout::rowMinimumHeight(int row) const-
1210{-
1211 const QGridLayoutPrivate * const d = d_func();-
1212 return d->rowSpacing(row);-
1213}-
1214-
1215-
1216-
1217-
1218-
1219-
1220void QGridLayout::setColumnMinimumWidth(int column, int minSize)-
1221{-
1222 QGridLayoutPrivate * const d = d_func();-
1223 d->setColumnMinimumWidth(column, minSize);-
1224 invalidate();-
1225}-
1226-
1227-
1228-
1229-
1230-
1231-
1232int QGridLayout::columnMinimumWidth(int column) const-
1233{-
1234 const QGridLayoutPrivate * const d = d_func();-
1235 return d->colSpacing(column);-
1236}-
1237-
1238-
1239-
1240-
1241Qt::Orientations QGridLayout::expandingDirections() const-
1242{-
1243 const QGridLayoutPrivate * const d = d_func();-
1244 return d->expandingDirections(horizontalSpacing(), verticalSpacing());-
1245}-
1246-
1247-
1248-
1249-
1250void QGridLayout::setOriginCorner(Qt::Corner corner)-
1251{-
1252 QGridLayoutPrivate * const d = d_func();-
1253 d->setReversed(corner == Qt::BottomLeftCorner || corner == Qt::BottomRightCorner,-
1254 corner == Qt::TopRightCorner || corner == Qt::BottomRightCorner);-
1255}-
1256-
1257-
1258-
1259-
1260-
1261Qt::Corner QGridLayout::originCorner() const-
1262{-
1263 const QGridLayoutPrivate * const d = d_func();-
1264 if (d->horReversed()) {-
1265 return d->verReversed() ? Qt::BottomRightCorner : Qt::TopRightCorner;-
1266 } else {-
1267 return d->verReversed() ? Qt::BottomLeftCorner : Qt::TopLeftCorner;-
1268 }-
1269}-
1270-
1271-
1272-
1273-
1274void QGridLayout::invalidate()-
1275{-
1276 QGridLayoutPrivate * const d = d_func();-
1277 d->setDirty();-
1278 QLayout::invalidate();-
1279}-
1280-
1281-
1282-
Switch to Source codePreprocessed file

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