25
26
27
28
35 QGridBox(
const QLayout *l, QWidget *wid) { item_ = QLayoutPrivate::createWidgetItem(l, wid); }
42 bool isEmpty()
const {
return item_->isEmpty(); }
50 QLayoutItem *
item() {
return item_; }
51 void setItem(QLayoutItem *newitem) { item_ = newitem; }
52 QLayoutItem *
takeItem() { QLayoutItem *i = item_; item_ =
nullptr;
return i; }
55 item_->widget()->sizePolicy().horizontalStretch() : 0; }
57 item_->widget()->sizePolicy().verticalStretch() : 0; }
61 friend class QGridLayout;
63 inline int toRow(
int rr)
const {
return torow >= 0 ? torow : rr - 1; }
64 inline int toCol(
int cc)
const {
return tocol >= 0 ? tocol : cc - 1; }
73 Q_DECLARE_PUBLIC(QGridLayout)
88 inline void expand(
int rows,
int cols)
89 { setSize(qMax(rows, rr), qMax(cols, cc)); }
94 inline int rowStretch(
int r)
const {
return rStretch.at(r); }
95 inline int colStretch(
int c)
const {
return cStretch.at(c); }
100 inline int rowSpacing(
int r)
const {
return rMinHeights.at(r); }
101 inline int colSpacing(
int c)
const {
return cMinWidths.at(c); }
103 inline void setReversed(
bool r,
bool c) { hReversed = c; vReversed = r; }
106 inline void setDirty() { needRecalc =
true; hfw_width = -1; }
107 inline bool isDirty()
const {
return needRecalc; }
112 inline void getNextPos(
int &row,
int &col) { row = nextR; col = nextC; }
113 inline int count()
const {
return things.size(); }
116 inline QLayoutItem *
itemAt(
int index)
const {
117 if (index >= 0 && index < things.size())
118 return things.at(index)->item();
124 if (index >= 0 && index < things.size()) {
125 if (
QGridBox *b = things.takeAt(index)) {
127 if (QLayout *l = item->layout()) {
129 if (l->parent() == q)
130 l->setParent(
nullptr);
142 QLayoutItem *item =
nullptr;
151 void getItemPosition(
int index,
int *row,
int *column,
int *rowSpan,
int *columnSpan)
const {
152 if (index >= 0 && index < things.size()) {
153 const QGridBox *b = things.at(index);
154 int toRow = b->toRow(rr);
155 int toCol = b->toCol(cc);
158 *rowSpan = toRow - *row + 1;
159 *columnSpan = toCol - *column +1;
165 void setNextPosAfter(
int r,
int c);
166 void recalcHFW(
int w);
167 void addHfwData(
QGridBox *box,
int width);
169 QSize findSize(
int QLayoutStruct::*,
int hSpacing,
int vSpacing)
const;
171 void setSize(
int rows,
int cols);
173 Qt::Orientation orientation);
174 void setupLayoutData(
int hSpacing,
int vSpacing);
175 void setupHfwLayoutData();
176 void effectiveMargins(
int *left,
int *top,
int *right,
int *bottom)
const;
185 QList<
int> rMinHeights;
186 QList<
int> cMinWidths;
195 int horizontalSpacing;
206 uint addVertical : 1;
209void QGridLayoutPrivate::effectiveMargins(
int *left,
int *top,
int *right,
int *bottom)
const
214 int b = bottomMargin;
216 int leftMost = INT_MAX;
217 int topMost = INT_MAX;
221 QWidget *w =
nullptr;
222 const int n = things.count();
223 for (
int i = 0; i < n; ++i) {
224 QGridBox *box = things.at(i);
225 QLayoutItem *itm = box->item();
228 bool visualHReversed = hReversed != (w->layoutDirection() == Qt::RightToLeft);
229 QRect lir = itm->geometry();
230 QRect wr = w->geometry();
231 if (box->col <= leftMost) {
232 if (box->col < leftMost) {
240 if (visualHReversed) {
241 r = qMax(r, wr.right() - lir.right());
243 l = qMax(l, lir.left() - wr.left());
246 if (box->row <= topMost) {
247 if (box->row < topMost) {
256 b = qMax(b, wr.bottom() - lir.bottom());
258 t = qMax(t, lir.top() - wr.top());
260 if (box->toCol(cc) >= rightMost) {
261 if (box->toCol(cc) > rightMost) {
263 rightMost = box->toCol(cc);
269 if (visualHReversed) {
270 l = qMax(l, lir.left() - wr.left());
272 r = qMax(r, wr.right() - lir.right());
276 if (box->toRow(rr) >= bottomMost) {
277 if (box->toRow(rr) > bottomMost) {
279 bottomMost = box->toRow(rr);
286 t = qMax(t, lir.top() - wr.top());
288 b = qMax(b, wr.bottom() - lir.bottom());
313 horizontalSpacing = -1;
314 verticalSpacing = -1;
318QGridLayoutPrivate::QGridLayoutPrivate(
int nRows,
int nCols)
319 : rowData(0), colData(0)
330 setSize(nRows, nCols);
336 while (!things.isEmpty())
337 delete things.takeFirst();
343 setupLayoutData(hSpacing, vSpacing);
348
349
350
354
355
356
358 hfwData =
new QList<QLayoutStruct>(rr);
359 setupHfwLayoutData();
364 for (
int r = 0; r < rr; r++) {
365 int spacing = rData.at(r).spacing;
366 h += rData.at(r).sizeHint + spacing;
367 mh += rData.at(r).minimumSize + spacing;
371 hfw_height = qMin(QLAYOUTSIZE_MAX, h);
372 hfw_minheight = qMin(QLAYOUTSIZE_MAX, mh);
377 setupLayoutData(hSpacing, vSpacing);
380 int left, top, right, bottom;
381 effectiveMargins(&left, &top, &right, &bottom);
383 int hMargins = left + right;
384 if (w - hMargins != hfw_width) {
385 qGeomCalc(colData, 0, cc, 0, w - hMargins);
386 recalcHFW(w - hMargins);
388 return hfw_height + top + bottom;
397 effectiveMargins(
nullptr, &top,
nullptr, &bottom);
398 return hfw_minheight + top + bottom;
401QSize
QGridLayoutPrivate::findSize(
int QLayoutStruct::*size,
int hSpacing,
int vSpacing)
const
404 that->setupLayoutData(hSpacing, vSpacing);
409 for (
int r = 0; r < rr; r++)
410 h += rowData.at(r).*size + rowData.at(r).spacing;
411 for (
int c = 0; c < cc; c++)
412 w += colData.at(c).*size + colData.at(c).spacing;
414 w = qMin(QLAYOUTSIZE_MAX, w);
415 h = qMin(QLAYOUTSIZE_MAX, h);
423 that->setupLayoutData(hSpacing, vSpacing);
424 Qt::Orientations ret;
426 for (
int r = 0; r < rr; r++) {
427 if (rowData.at(r).expansive) {
432 for (
int c = 0; c < cc; c++) {
433 if (colData.at(c).expansive) {
434 ret |= Qt::Horizontal;
443 return findSize(&QLayoutStruct::sizeHint, hSpacing, vSpacing);
448 return findSize(&QLayoutStruct::maximumSize, hSpacing, vSpacing);
453 return findSize(&QLayoutStruct::minimumSize, hSpacing, vSpacing);
458 if ((
int)rowData.size() < r) {
459 int newR = qMax(r, rr * 2);
460 rowData.resize(newR);
461 rStretch.resize(newR);
462 rMinHeights.resize(newR);
463 for (
int i = rr; i < newR; i++) {
465 rowData[i].maximumSize = 0;
472 if ((
int)colData.size() < c) {
473 int newC = qMax(c, cc * 2);
474 colData.resize(newC);
475 cStretch.resize(newC);
476 cMinWidths.resize(newC);
477 for (
int i = cc; i < newC; i++) {
479 colData[i].maximumSize = 0;
487 if (hfwData && (
int)hfwData->size() < r) {
499 if (col > nextC || (col == nextC && row >= nextR)) {
508 if (row > nextR || (row == nextR && col >= nextC)) {
522 box->row = box->torow = row;
523 box->col = box->tocol = col;
526 setNextPosAfter(row, col);
531 if (Q_UNLIKELY(row2 >= 0 && row2 < row1))
532 qWarning(
"QGridLayout: Multi-cell fromRow greater than toRow");
533 if (Q_UNLIKELY(col2 >= 0 && col2 < col1))
534 qWarning(
"QGridLayout: Multi-cell fromCol greater than toCol");
535 if (row1 == row2 && col1 == col2) {
539 expand(qMax(row1, row2) + 1
, qMax(col1, col2) + 1
);
551 setNextPosAfter(row2, col2);
556 const QWidget *widget = box
->item()->widget();
563 if (!cStretch.at(box->col))
568 qMaxExpCalc(data->maximumSize, data->expansive, data->empty, sizes.maxS.width(),
569 box->expandingDirections() & Qt::Horizontal, box->isEmpty());
573 if (!rStretch.at(box->row))
578 qMaxExpCalc(data->maximumSize, data->expansive, data->empty, sizes.maxS.height(),
579 box->expandingDirections() & Qt::Vertical, box->isEmpty());
585 for (
int i = start; i <= end; i++) {
594 int sizeHint,
QList<
int> &stretchArray,
int stretch)
601 for (i = start; i <= end; i++) {
606 if (stretchArray.at(i) == 0)
619
620
621
622
623
624
625 qGeomCalc(chain, start, end - start + 1, 0, minSize);
627 for (i = start; i <= end; i++) {
629 int nextPos = (i == end) ? minSize : chain.at(i + 1).pos;
630 int realSize = nextPos - pos;
639 }
else if (w < minSize) {
640 qGeomCalc(chain, start, end - start + 1, 0, minSize);
641 for (i = start; i <= end; i++) {
649 qGeomCalc(chain, start, end - start + 1, 0, sizeHint);
650 for (i = start; i <= end; i++) {
661 if (orientation == Qt::Horizontal)
663 return grid[(r * cc) + c];
667 int fixedSpacing, Qt::Orientation orientation)
673 if (orientation == Qt::Horizontal) {
674 qSwap(numRows, numColumns);
677 QStyle *style =
nullptr;
678 if (fixedSpacing < 0) {
679 if (QWidget *parentWidget = q->parentWidget())
680 style = parentWidget->style();
683 for (
int c = 0; c < numColumns; ++c) {
685 int previousRow = -1;
687 for (
int r = 0; r < numRows; ++r) {
688 if (chain.at(r).empty)
691 QGridBox *box = gridAt(grid, r, c, cc, orientation);
692 if (previousRow != -1 && (!box || previousBox != box)) {
693 int spacing = fixedSpacing;
695 QSizePolicy::ControlTypes controlTypes1 = QSizePolicy::DefaultType;
696 QSizePolicy::ControlTypes controlTypes2 = QSizePolicy::DefaultType;
698 controlTypes1 = previousBox
->item()->controlTypes();
700 controlTypes2 = box
->item()->controlTypes();
702 if ((orientation == Qt::Horizontal && hReversed)
703 || (orientation == Qt::Vertical && vReversed))
704 qSwap(controlTypes1, controlTypes2);
707 spacing = style->combinedLayoutSpacing(controlTypes1, controlTypes2,
708 orientation,
nullptr, q->parentWidget());
710 if (orientation == Qt::Vertical) {
711 QGridBox *sibling = vReversed ? previousBox : box;
716 QWidget *wid = sibling->item()->widget();
718 spacing = qMax(spacing, sibling->item()->geometry().top() - wid->geometry().top());
724 if (spacing > chain.at(previousRow).spacing)
725 chain[previousRow].spacing = spacing;
740#ifndef QT_LAYOUT_DISABLE_CACHING
747 for (i = 0; i < rr; i++) {
748 rowData[i].init(rStretch.at(i), rMinHeights.at(i));
749 rowData[i].maximumSize = rStretch.at(i) ? QLAYOUTSIZE_MAX : rMinHeights.at(i);
751 for (i = 0; i < cc; i++) {
752 colData[i].init(cStretch.at(i), cMinWidths.at(i));
753 colData[i].maximumSize = cStretch.at(i) ? QLAYOUTSIZE_MAX : cMinWidths.at(i);
756 int n = things.size();
757 QVarLengthArray<QGridLayoutSizeTriple> sizes(n);
759 bool has_multi =
false;
762
763
764
765 QVarLengthArray<QGridBox *> grid(rr * cc);
766 memset(grid.data(), 0, rr * cc *
sizeof(
QGridBox *));
769
770
771
772 for (i = 0; i < n; ++i) {
773 QGridBox *
const box = things.at(i);
774 sizes[i].minS = box->minimumSize();
775 sizes[i].hint = box->sizeHint();
776 sizes[i].maxS = box->maximumSize();
781 if (box->row == box->toRow(rr)) {
782 addData(box, sizes[i],
true,
false);
784 initEmptyMultiBox(rowData, box->row, box->toRow(rr));
788 if (box->col == box->toCol(cc)) {
789 addData(box, sizes[i],
false,
true);
791 initEmptyMultiBox(colData, box->col, box->toCol(cc));
795 for (
int r = box->row; r <= box->toRow(rr); ++r) {
796 for (
int c = box->col; c <= box->toCol(cc); ++c) {
797 gridAt(grid.data(), r, c, cc) = box;
802 setupSpacings(colData, grid.data(), hSpacing, Qt::Horizontal);
803 setupSpacings(rowData, grid.data(), vSpacing, Qt::Vertical);
806
807
808
809
811 for (i = 0; i < n; ++i) {
812 QGridBox *
const box = things.at(i);
814 if (box->row != box->toRow(rr))
815 distributeMultiBox(rowData, box->row, box->toRow(rr), sizes[i].minS.height(),
816 sizes[i].hint.height(), rStretch, box->vStretch());
817 if (box->col != box->toCol(cc))
818 distributeMultiBox(colData, box->col, box->toCol(cc), sizes[i].minS.width(),
819 sizes[i].hint.width(), cStretch, box->hStretch());
823 for (i = 0; i < rr; i++)
824 rowData[i].expansive = rowData.at(i).expansive || rowData.at(i).stretch > 0;
825 for (i = 0; i < cc; i++)
826 colData[i].expansive = colData.at(i).expansive || colData.at(i).stretch > 0;
828 q->getContentsMargins(&leftMargin, &topMargin, &rightMargin, &bottomMargin);
838 rData[box->row].sizeHint = qMax(hint, rData.at(box->row).sizeHint);
839 rData[box->row].minimumSize = qMax(hint, rData.at(box->row).minimumSize);
841 QSize hint = box->sizeHint();
842 QSize minS = box->minimumSize();
843 rData[box->row].sizeHint = qMax(hint.height(), rData.at(box->row).sizeHint);
844 rData[box->row].minimumSize = qMax(minS.height(), rData.at(box->row).minimumSize);
849
850
851
852
856 for (
int i = 0; i < rr; i++) {
857 rData[i] = rowData.at(i);
858 rData[i].minimumSize = rData[i].sizeHint = rMinHeights.at(i);
861 for (
int pass = 0; pass < 2; ++pass) {
862 for (
int i = 0; i < things.size(); ++i) {
866 int r2 = box->toRow(rr);
867 int c2 = box->toCol(cc);
868 int w = colData.at(c2).pos + colData.at(c2).size - colData.at(c1).pos;
877 QSize hint = box->sizeHint();
878 QSize min = box->minimumSize();
881 if (hfwh > hint.height())
882 hint.setHeight(hfwh);
883 if (hfwh > min.height())
886 distributeMultiBox(rData, r1, r2, min.height(), hint.height(),
887 rStretch, box->vStretch());
892 for (
int i = 0; i < rr; i++)
893 rData[i].expansive = rData.at(i).expansive || rData.at(i).stretch > 0;
899 bool visualHReversed = hReversed;
900 QWidget *parent = q->parentWidget();
901 if (parent && parent->isRightToLeft())
902 visualHReversed = !visualHReversed;
904 setupLayoutData(hSpacing, vSpacing);
906 int left, top, right, bottom;
907 effectiveMargins(&left, &top, &right, &bottom);
908 r.adjust(+left, +top, -right, -bottom);
910 qGeomCalc(colData, 0, cc, r.x(), r.width());
913 recalcHFW(r.width());
914 qGeomCalc(*hfwData, 0, rr, r.y(), r.height());
917 qGeomCalc(rowData, 0, rr, r.y(), r.height());
923 bool reverse = ((r.bottom() > rect.bottom()) || (r.bottom() == rect.bottom()
924 && ((r.right() > rect.right()) != visualHReversed)));
925 int n = things.size();
926 for (i = 0; i < n; ++i) {
927 QGridBox *box = things.at(reverse ? n-i-1 : i);
928 int r2 = box->toRow(rr);
929 int c2 = box->toCol(cc);
931 int x = colData.at(box->col).pos;
932 int y = rData.at(box->row).pos;
933 int x2p = colData.at(c2).pos + colData.at(c2).size;
934 int y2p = rData.at(r2).pos + rData.at(r2).size;
939 x = r.left() + r.right() - x - w + 1;
941 y = r.top() + r.bottom() - y - h + 1;
943 box->setGeometry(QRect(x, y, w, h));
949 if (row < 0 || row >= rr || col < 0 || col >= cc)
953 if (has_hfw && hfwData)
957 return QRect(colData.at(col).pos, rDataPtr->at(row).pos,
958 colData.at(col).size, rDataPtr->at(row).size);
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051QGridLayout::QGridLayout(QWidget *parent)
1052 : QLayout(*
new QGridLayoutPrivate,
nullptr, parent)
1059
1060
1061
1062
1063
1064
1065
1067void QGridLayout::setDefaultPositioning(
int n, Qt::Orientation orient)
1070 if (orient == Qt::Horizontal) {
1072 d->addVertical =
false;
1075 d->addVertical =
true;
1081
1082
1083
1084
1085
1086QGridLayout::~QGridLayout()
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103void QGridLayout::setHorizontalSpacing(
int spacing)
1106 d->horizontalSpacing = spacing;
1110int QGridLayout::horizontalSpacing()
const
1112 Q_D(
const QGridLayout);
1113 if (d->horizontalSpacing >= 0) {
1114 return d->horizontalSpacing;
1116 return qSmartSpacing(
this, QStyle::PM_LayoutHorizontalSpacing);
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131void QGridLayout::setVerticalSpacing(
int spacing)
1134 d->verticalSpacing = spacing;
1138int QGridLayout::verticalSpacing()
const
1140 Q_D(
const QGridLayout);
1141 if (d->verticalSpacing >= 0) {
1142 return d->verticalSpacing;
1144 return qSmartSpacing(
this, QStyle::PM_LayoutVerticalSpacing);
1149
1150
1151
1152
1153
1154void QGridLayout::setSpacing(
int spacing)
1157 d->horizontalSpacing = d->verticalSpacing = spacing;
1162
1163
1164
1165
1166
1167int QGridLayout::spacing()
const
1169 int hSpacing = horizontalSpacing();
1170 if (hSpacing == verticalSpacing()) {
1178
1179
1180int QGridLayout::rowCount()
const
1182 Q_D(
const QGridLayout);
1183 return d->numRows();
1187
1188
1189int QGridLayout::columnCount()
const
1191 Q_D(
const QGridLayout);
1192 return d->numCols();
1196
1197
1198QSize QGridLayout::sizeHint()
const
1200 Q_D(
const QGridLayout);
1201 QSize result(d->sizeHint(horizontalSpacing(), verticalSpacing()));
1202 int left, top, right, bottom;
1203 d->effectiveMargins(&left, &top, &right, &bottom);
1204 result += QSize(left + right, top + bottom);
1209
1210
1211QSize QGridLayout::minimumSize()
const
1213 Q_D(
const QGridLayout);
1214 QSize result(d->minimumSize(horizontalSpacing(), verticalSpacing()));
1215 int left, top, right, bottom;
1216 d->effectiveMargins(&left, &top, &right, &bottom);
1217 result += QSize(left + right, top + bottom);
1222
1223
1224QSize QGridLayout::maximumSize()
const
1226 Q_D(
const QGridLayout);
1228 QSize s = d->maximumSize(horizontalSpacing(), verticalSpacing());
1229 int left, top, right, bottom;
1230 d->effectiveMargins(&left, &top, &right, &bottom);
1231 s += QSize(left + right, top + bottom);
1232 s = s.boundedTo(QSize(QLAYOUTSIZE_MAX, QLAYOUTSIZE_MAX));
1233 if (alignment() & Qt::AlignHorizontal_Mask)
1234 s.setWidth(QLAYOUTSIZE_MAX);
1235 if (alignment() & Qt::AlignVertical_Mask)
1236 s.setHeight(QLAYOUTSIZE_MAX);
1241
1242
1243bool QGridLayout::hasHeightForWidth()
const
1245 return const_cast<QGridLayout*>(
this)->d_func()->hasHeightForWidth(horizontalSpacing(), verticalSpacing());
1249
1250
1251int QGridLayout::heightForWidth(
int w)
const
1253 Q_D(
const QGridLayout);
1254 QGridLayoutPrivate *dat =
const_cast<QGridLayoutPrivate *>(d);
1255 return dat->heightForWidth(w, horizontalSpacing(), verticalSpacing());
1259
1260
1261int QGridLayout::minimumHeightForWidth(
int w)
const
1263 Q_D(
const QGridLayout);
1264 QGridLayoutPrivate *dat =
const_cast<QGridLayoutPrivate *>(d);
1265 return dat->minimumHeightForWidth(w, horizontalSpacing(), verticalSpacing());
1269
1270
1271int QGridLayout::count()
const
1273 Q_D(
const QGridLayout);
1279
1280
1281QLayoutItem *QGridLayout::itemAt(
int index)
const
1283 Q_D(
const QGridLayout);
1284 return d->itemAt(index);
1288
1289
1290
1291
1292
1293
1294
1295QLayoutItem *QGridLayout::itemAtPosition(
int row,
int column)
const
1297 Q_D(
const QGridLayout);
1298 int n = d->things.size();
1299 for (
int i = 0; i < n; ++i) {
1300 QGridBox *box = d->things.at(i);
1301 if (row >= box->row && row <= box->toRow(d->rr)
1302 && column >= box->col && column <= box->toCol(d->cc)) {
1310
1311
1312QLayoutItem *QGridLayout::takeAt(
int index)
1315 return d->takeAt(index);
1319
1320
1321
1322
1323
1324
1325
1326
1327void QGridLayout::getItemPosition(
int index,
int *row,
int *column,
int *rowSpan,
int *columnSpan)
const
1329 Q_D(
const QGridLayout);
1330 d->getItemPosition(index, row, column, rowSpan, columnSpan);
1335
1336
1337void QGridLayout::setGeometry(
const QRect &rect)
1340 if (d->isDirty() || rect != geometry()) {
1341 QRect cr = alignment() ? alignmentRect(rect) : rect;
1342 d->distribute(cr, horizontalSpacing(), verticalSpacing());
1343 QLayout::setGeometry(rect);
1348
1349
1350
1351
1352
1353
1354
1355
1356QRect QGridLayout::cellRect(
int row,
int column)
const
1358 Q_D(
const QGridLayout);
1359 return d->cellRect(row, column);
1363
1364
1365void QGridLayout::addItem(QLayoutItem *item)
1369 d->getNextPos(r, c);
1370 addItem(item, r, c);
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383void QGridLayout::addItem(QLayoutItem *item,
int row,
int column,
int rowSpan,
int columnSpan, Qt::Alignment alignment)
1386 QGridBox *b =
new QGridBox(item);
1387 b->setAlignment(alignment);
1388 d->add(b, row, (rowSpan < 0) ? -1 : row + rowSpan - 1, column, (columnSpan < 0) ? -1 : column + columnSpan - 1);
1393
1394
1395
1396
1397
1398
1399
1400void QGridLayout::addWidget(QWidget *widget,
int row,
int column, Qt::Alignment alignment)
1403 if (!d->checkWidget(widget))
1405 if (Q_UNLIKELY(row < 0 || column < 0)) {
1406 qWarning(
"QGridLayout: Cannot add %s/%s to %s/%s at row %d column %d",
1407 widget->metaObject()->className(), widget->objectName().toLocal8Bit().data(),
1408 metaObject()->className(), objectName().toLocal8Bit().data(), row, column);
1411 addChildWidget(widget);
1412 QWidgetItem *b = QLayoutPrivate::createWidgetItem(
this, widget);
1413 addItem(b, row, column, 1, 1, alignment);
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428void QGridLayout::addWidget(QWidget *widget,
int fromRow,
int fromColumn,
1429 int rowSpan,
int columnSpan, Qt::Alignment alignment)
1432 if (!d->checkWidget(widget))
1434 int toRow = (rowSpan < 0) ? -1 : fromRow + rowSpan - 1;
1435 int toColumn = (columnSpan < 0) ? -1 : fromColumn + columnSpan - 1;
1436 addChildWidget(widget);
1437 QGridBox *b =
new QGridBox(
this, widget);
1438 b->setAlignment(alignment);
1439 d->add(b, fromRow, toRow, fromColumn, toColumn);
1444
1445
1446
1447
1448
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464void QGridLayout::addLayout(QLayout *layout,
int row,
int column, Qt::Alignment alignment)
1467 if (!d->checkLayout(layout))
1469 if (!adoptLayout(layout))
1471 QGridBox *b =
new QGridBox(layout);
1472 b->setAlignment(alignment);
1473 d->add(b, row, column);
1477
1478
1479
1480
1481
1482
1483
1484
1485void QGridLayout::addLayout(QLayout *layout,
int row,
int column,
1486 int rowSpan,
int columnSpan, Qt::Alignment alignment)
1489 if (!d->checkLayout(layout))
1491 if (!adoptLayout(layout))
1493 QGridBox *b =
new QGridBox(layout);
1494 b->setAlignment(alignment);
1495 d->add(b, row, (rowSpan < 0) ? -1 : row + rowSpan - 1, column, (columnSpan < 0) ? -1 : column + columnSpan - 1);
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511void QGridLayout::setRowStretch(
int row,
int stretch)
1514 d->setRowStretch(row, stretch);
1519
1520
1521
1522
1523int QGridLayout::rowStretch(
int row)
const
1525 Q_D(
const QGridLayout);
1526 return d->rowStretch(row);
1530
1531
1532
1533
1534int QGridLayout::columnStretch(
int column)
const
1536 Q_D(
const QGridLayout);
1537 return d->colStretch(column);
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557void QGridLayout::setColumnStretch(
int column,
int stretch)
1560 d->setColStretch(column, stretch);
1567
1568
1569
1570
1571void QGridLayout::setRowMinimumHeight(
int row,
int minSize)
1574 d->setRowMinimumHeight(row, minSize);
1579
1580
1581
1582
1583int QGridLayout::rowMinimumHeight(
int row)
const
1585 Q_D(
const QGridLayout);
1586 return d->rowSpacing(row);
1590
1591
1592
1593
1594void QGridLayout::setColumnMinimumWidth(
int column,
int minSize)
1597 d->setColumnMinimumWidth(column, minSize);
1602
1603
1604
1605
1606int QGridLayout::columnMinimumWidth(
int column)
const
1608 Q_D(
const QGridLayout);
1609 return d->colSpacing(column);
1613
1614
1615Qt::Orientations QGridLayout::expandingDirections()
const
1617 Q_D(
const QGridLayout);
1618 return d->expandingDirections(horizontalSpacing(), verticalSpacing());
1622
1623
1624void QGridLayout::setOriginCorner(Qt::Corner corner)
1627 d->setReversed(corner == Qt::BottomLeftCorner || corner == Qt::BottomRightCorner,
1628 corner == Qt::TopRightCorner || corner == Qt::BottomRightCorner);
1632
1633
1634
1635Qt::Corner QGridLayout::originCorner()
const
1637 Q_D(
const QGridLayout);
1638 if (d->horReversed()) {
1639 return d->verReversed() ? Qt::BottomRightCorner : Qt::TopRightCorner;
1641 return d->verReversed() ? Qt::BottomLeftCorner : Qt::TopLeftCorner;
1646
1647
1648void QGridLayout::invalidate()
1652 QLayout::invalidate();
1657#include "moc_qgridlayout.cpp"
Qt::Alignment alignment() const
void setAlignment(Qt::Alignment a)
Qt::Orientations expandingDirections() const
void setGeometry(const QRect &r)
QSize maximumSize() const
QSize minimumSize() const
void setItem(QLayoutItem *newitem)
QGridBox(QLayoutItem *lit)
QGridBox(const QLayout *l, QWidget *wid)
bool hasHeightForWidth() const
int heightForWidth(int w) const
int colSpacing(int c) const
void distribute(QRect rect, int hSpacing, int vSpacing)
QLayoutItem * replaceAt(int index, QLayoutItem *newitem) override
QRect cellRect(int row, int col) const
void setRowStretch(int r, int s)
void setRowMinimumHeight(int r, int s)
void setReversed(bool r, bool c)
void getNextPos(int &row, int &col)
Qt::Orientations expandingDirections(int hSpacing, int vSpacing) const
int rowSpacing(int r) const
void add(QGridBox *, int row, int col)
void expand(int rows, int cols)
QLayoutItem * takeAt(int index)
QLayoutItem * itemAt(int index) const
QSize sizeHint(int hSpacing, int vSpacing) const
bool hasHeightForWidth(int hSpacing, int vSpacing)
void setColStretch(int c, int s)
int colStretch(int c) const
void add(QGridBox *, int row1, int row2, int col1, int col2)
QSize minimumSize(int hSpacing, int vSpacing) const
int minimumHeightForWidth(int width, int hSpacing, int vSpacing)
int rowStretch(int r) const
void setColumnMinimumWidth(int c, int s)
int heightForWidth(int width, int hSpacing, int vSpacing)
void getItemPosition(int index, int *row, int *column, int *rowSpan, int *columnSpan) const
QSize maximumSize(int hSpacing, int vSpacing) const
static void initEmptyMultiBox(QList< QLayoutStruct > &chain, int start, int end)
static void distributeMultiBox(QList< QLayoutStruct > &chain, int start, int end, int minSize, int sizeHint, QList< int > &stretchArray, int stretch)
static QGridBox *& gridAt(QGridBox *grid[], int r, int c, int cc, Qt::Orientation orientation=Qt::Vertical)