Qt 4.8
qgridlayout.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "qgridlayout.h"
43 #include "qapplication.h"
44 #include "qwidget.h"
45 #include "qlist.h"
46 #include "qsizepolicy.h"
47 #include "qvector.h"
48 #include "qvarlengtharray.h"
49 #include "qlayoutengine_p.h"
50 #include "qlayout_p.h"
51 
53 
55 {
59 };
60 
61 /*
62  Three internal classes related to QGridLayout: (1) QGridBox is a
63  QLayoutItem with (row, column) information and (torow, tocolumn) information; (3) QGridLayoutData is
64  the internal representation of a QGridLayout.
65 */
66 
67 class QGridBox
68 {
69 public:
70  QGridBox(QLayoutItem *lit) { item_ = lit; }
71 
72  QGridBox(const QLayout *l, QWidget *wid) { item_ = QLayoutPrivate::createWidgetItem(l, wid); }
73  ~QGridBox() { delete item_; }
74 
75  QSize sizeHint() const { return item_->sizeHint(); }
76  QSize minimumSize() const { return item_->minimumSize(); }
77  QSize maximumSize() const { return item_->maximumSize(); }
78  Qt::Orientations expandingDirections() const { return item_->expandingDirections(); }
79  bool isEmpty() const { return item_->isEmpty(); }
80 
81  bool hasHeightForWidth() const { return item_->hasHeightForWidth(); }
82  int heightForWidth(int w) const { return item_->heightForWidth(w); }
83 
84  void setAlignment(Qt::Alignment a) { item_->setAlignment(a); }
85  void setGeometry(const QRect &r) { item_->setGeometry(r); }
86  Qt::Alignment alignment() const { return item_->alignment(); }
87  QLayoutItem *item() { return item_; }
88  QLayoutItem *takeItem() { QLayoutItem *i = item_; item_ = 0; return i; }
89 
90  int hStretch() { return item_->widget() ?
91  item_->widget()->sizePolicy().horizontalStretch() : 0; }
92  int vStretch() { return item_->widget() ?
93  item_->widget()->sizePolicy().verticalStretch() : 0; }
94 
95 private:
96  friend class QGridLayoutPrivate;
97  friend class QGridLayout;
98 
99  inline int toRow(int rr) const { return torow >= 0 ? torow : rr - 1; }
100  inline int toCol(int cc) const { return tocol >= 0 ? tocol : cc - 1; }
101 
103  int row, col;
104  int torow, tocol;
105 };
106 
108 {
110 public:
112 
113  void add(QGridBox*, int row, int col);
114  void add(QGridBox*, int row1, int row2, int col1, int col2);
115  QSize sizeHint(int hSpacing, int vSpacing) const;
116  QSize minimumSize(int hSpacing, int vSpacing) const;
117  QSize maximumSize(int hSpacing, int vSpacing) const;
118 
119  Qt::Orientations expandingDirections(int hSpacing, int vSpacing) const;
120 
121  void distribute(QRect rect, int hSpacing, int vSpacing);
122  inline int numRows() const { return rr; }
123  inline int numCols() const { return cc; }
124  inline void expand(int rows, int cols)
125  { setSize(qMax(rows, rr), qMax(cols, cc)); }
126  inline void setRowStretch(int r, int s)
127  { expand(r + 1, 0); rStretch[r] = s; setDirty(); }
128  inline void setColStretch(int c, int s)
129  { expand(0, c + 1); cStretch[c] = s; setDirty(); }
130  inline int rowStretch(int r) const { return rStretch.at(r); }
131  inline int colStretch(int c) const { return cStretch.at(c); }
132  inline void setRowMinimumHeight(int r, int s)
133  { expand(r + 1, 0); rMinHeights[r] = s; setDirty(); }
134  inline void setColumnMinimumWidth(int c, int s)
135  { expand(0, c + 1); cMinWidths[c] = s; setDirty(); }
136  inline int rowSpacing(int r) const { return rMinHeights.at(r); }
137  inline int colSpacing(int c) const { return cMinWidths.at(c); }
138 
139  inline void setReversed(bool r, bool c) { hReversed = c; vReversed = r; }
140  inline bool horReversed() const { return hReversed; }
141  inline bool verReversed() const { return vReversed; }
142  inline void setDirty() { needRecalc = true; hfw_width = -1; }
143  inline bool isDirty() const { return needRecalc; }
144  bool hasHeightForWidth(int hSpacing, int vSpacing);
145  int heightForWidth(int width, int hSpacing, int vSpacing);
146  int minimumHeightForWidth(int width, int hSpacing, int vSpacing);
147 
148  inline void getNextPos(int &row, int &col) { row = nextR; col = nextC; }
149  inline int count() const { return things.count(); }
150  QRect cellRect(int row, int col) const;
151 
152  inline QLayoutItem *itemAt(int index) const {
153  if (index < things.count())
154  return things.at(index)->item();
155  else
156  return 0;
157  }
158  inline QLayoutItem *takeAt(int index) {
159  Q_Q(QGridLayout);
160  if (index < things.count()) {
161  if (QGridBox *b = things.takeAt(index)) {
162  QLayoutItem *item = b->takeItem();
163  if (QLayout *l = item->layout()) {
164  // sanity check in case the user passed something weird to QObject::setParent()
165  if (l->parent() == q)
166  l->setParent(0);
167  }
168  delete b;
169  return item;
170  }
171  }
172  return 0;
173  }
174 
175  void getItemPosition(int index, int *row, int *column, int *rowSpan, int *columnSpan) {
176  if (index < things.count()) {
177  QGridBox *b = things.at(index);
178  int toRow = b->toRow(rr);
179  int toCol = b->toCol(cc);
180  *row = b->row;
181  *column = b->col;
182  *rowSpan = toRow - *row + 1;
183  *columnSpan = toCol - *column +1;
184  }
185  }
186  void deleteAll();
187 
188 private:
189  void setNextPosAfter(int r, int c);
190  void recalcHFW(int w);
191  void addHfwData(QGridBox *box, int width);
192  void init();
193  QSize findSize(int QLayoutStruct::*, int hSpacing, int vSpacing) const;
194  void addData(QGridBox *b, const QGridLayoutSizeTriple &sizes, bool r, bool c);
195  void setSize(int rows, int cols);
196  void setupSpacings(QVector<QLayoutStruct> &chain, QGridBox *grid[], int fixedSpacing,
197  Qt::Orientation orientation);
198  void setupLayoutData(int hSpacing, int vSpacing);
199  void setupHfwLayoutData();
200  void effectiveMargins(int *left, int *top, int *right, int *bottom) const;
201 
202  int rr;
203  int cc;
212 
216  int nextR;
217  int nextC;
218 
225 
231 };
232 
233 void QGridLayoutPrivate::effectiveMargins(int *left, int *top, int *right, int *bottom) const
234 {
235  int l = leftMargin;
236  int t = topMargin;
237  int r = rightMargin;
238  int b = bottomMargin;
239 #ifdef Q_WS_MAC
240  int leftMost = INT_MAX;
241  int topMost = INT_MAX;
242  int rightMost = 0;
243  int bottomMost = 0;
244 
245  QWidget *w = 0;
246  const int n = things.count();
247  for (int i = 0; i < n; ++i) {
248  QGridBox *box = things.at(i);
249  QLayoutItem *itm = box->item();
250  w = itm->widget();
251  if (w) {
252  bool visualHReversed = hReversed != (w->layoutDirection() == Qt::RightToLeft);
253  QRect lir = itm->geometry();
254  QRect wr = w->geometry();
255  if (box->col <= leftMost) {
256  if (box->col < leftMost) {
257  // we found an item even closer to the margin, discard.
258  leftMost = box->col;
259  if (visualHReversed)
260  r = rightMargin;
261  else
262  l = leftMargin;
263  }
264  if (visualHReversed) {
265  r = qMax(r, wr.right() - lir.right());
266  } else {
267  l = qMax(l, lir.left() - wr.left());
268  }
269  }
270  if (box->row <= topMost) {
271  if (box->row < topMost) {
272  // we found an item even closer to the margin, discard.
273  topMost = box->row;
274  if (vReversed)
275  b = bottomMargin;
276  else
277  t = topMargin;
278  }
279  if (vReversed)
280  b = qMax(b, wr.bottom() - lir.bottom());
281  else
282  t = qMax(t, lir.top() - wr.top());
283  }
284  if (box->toCol(cc) >= rightMost) {
285  if (box->toCol(cc) > rightMost) {
286  // we found an item even closer to the margin, discard.
287  rightMost = box->toCol(cc);
288  if (visualHReversed)
289  l = leftMargin;
290  else
291  r = rightMargin;
292  }
293  if (visualHReversed) {
294  l = qMax(l, lir.left() - wr.left());
295  } else {
296  r = qMax(r, wr.right() - lir.right());
297  }
298 
299  }
300  if (box->toRow(rr) >= bottomMost) {
301  if (box->toRow(rr) > bottomMost) {
302  // we found an item even closer to the margin, discard.
303  bottomMost = box->toRow(rr);
304  if (vReversed)
305  t = topMargin;
306  else
307  b = bottomMargin;
308  }
309  if (vReversed)
310  t = qMax(t, lir.top() - wr.top());
311  else
312  b = qMax(b, wr.bottom() - lir.bottom());
313  }
314  }
315  }
316 
317 #endif
318  if (left)
319  *left = l;
320  if (top)
321  *top = t;
322  if (right)
323  *right = r;
324  if (bottom)
325  *bottom = b;
326 }
327 
329 {
330  addVertical = false;
331  setDirty();
332  rr = cc = 0;
333  nextR = nextC = 0;
334  hfwData = 0;
335  hReversed = false;
336  vReversed = false;
337  horizontalSpacing = -1;
338  verticalSpacing = -1;
339 }
340 
341 #if 0
342 QGridLayoutPrivate::QGridLayoutPrivate(int nRows, int nCols)
343  : rowData(0), colData(0)
344 {
345  init();
346  if (nRows < 0) {
347  nRows = 1;
348  addVertical = false;
349  }
350  if (nCols < 0) {
351  nCols = 1;
352  addVertical = true;
353  }
354  setSize(nRows, nCols);
355 }
356 #endif
357 
359 {
360  while (!things.isEmpty())
361  delete things.takeFirst();
362  delete hfwData;
363 }
364 
365 bool QGridLayoutPrivate::hasHeightForWidth(int hSpacing, int vSpacing)
366 {
367  setupLayoutData(hSpacing, vSpacing);
368  return has_hfw;
369 }
370 
371 /*
372  Assumes that setupLayoutData() has been called, and that
373  qGeomCalc() has filled in colData with appropriate values.
374 */
376 {
377  /*
378  Go through all children, using colData and heightForWidth()
379  and put the results in hfwData.
380  */
381  if (!hfwData)
382  hfwData = new QVector<QLayoutStruct>(rr);
383  setupHfwLayoutData();
384  QVector<QLayoutStruct> &rData = *hfwData;
385 
386  int h = 0;
387  int mh = 0;
388  for (int r = 0; r < rr; r++) {
389  int spacing = rData.at(r).spacing;
390  h += rData.at(r).sizeHint + spacing;
391  mh += rData.at(r).minimumSize + spacing;
392  }
393 
394  hfw_width = w;
395  hfw_height = qMin(QLAYOUTSIZE_MAX, h);
396  hfw_minheight = qMin(QLAYOUTSIZE_MAX, mh);
397 }
398 
399 int QGridLayoutPrivate::heightForWidth(int w, int hSpacing, int vSpacing)
400 {
401  setupLayoutData(hSpacing, vSpacing);
402  if (!has_hfw)
403  return -1;
404  int left, top, right, bottom;
405  effectiveMargins(&left, &top, &right, &bottom);
406 
407  int hMargins = left + right;
408  if (w - hMargins != hfw_width) {
409  qGeomCalc(colData, 0, cc, 0, w - hMargins);
410  recalcHFW(w - hMargins);
411  }
412  return hfw_height + top + bottom;
413 }
414 
415 int QGridLayoutPrivate::minimumHeightForWidth(int w, int hSpacing, int vSpacing)
416 {
417  (void)heightForWidth(w, hSpacing, vSpacing);
418  if (!has_hfw)
419  return -1;
420  int top, bottom;
421  effectiveMargins(0, &top, 0, &bottom);
422  return hfw_minheight + top + bottom;
423 }
424 
425 QSize QGridLayoutPrivate::findSize(int QLayoutStruct::*size, int hSpacing, int vSpacing) const
426 {
427  QGridLayoutPrivate *that = const_cast<QGridLayoutPrivate*>(this);
428  that->setupLayoutData(hSpacing, vSpacing);
429 
430  int w = 0;
431  int h = 0;
432 
433  for (int r = 0; r < rr; r++)
434  h += rowData.at(r).*size + rowData.at(r).spacing;
435  for (int c = 0; c < cc; c++)
436  w += colData.at(c).*size + colData.at(c).spacing;
437 
438  w = qMin(QLAYOUTSIZE_MAX, w);
439  h = qMin(QLAYOUTSIZE_MAX, h);
440 
441  return QSize(w, h);
442 }
443 
444 Qt::Orientations QGridLayoutPrivate::expandingDirections(int hSpacing, int vSpacing) const
445 {
446  QGridLayoutPrivate *that = const_cast<QGridLayoutPrivate*>(this);
447  that->setupLayoutData(hSpacing, vSpacing);
448  Qt::Orientations ret;
449 
450  for (int r = 0; r < rr; r++) {
451  if (rowData.at(r).expansive) {
452  ret |= Qt::Vertical;
453  break;
454  }
455  }
456  for (int c = 0; c < cc; c++) {
457  if (colData.at(c).expansive) {
458  ret |= Qt::Horizontal;
459  break;
460  }
461  }
462  return ret;
463 }
464 
465 QSize QGridLayoutPrivate::sizeHint(int hSpacing, int vSpacing) const
466 {
467  return findSize(&QLayoutStruct::sizeHint, hSpacing, vSpacing);
468 }
469 
470 QSize QGridLayoutPrivate::maximumSize(int hSpacing, int vSpacing) const
471 {
472  return findSize(&QLayoutStruct::maximumSize, hSpacing, vSpacing);
473 }
474 
475 QSize QGridLayoutPrivate::minimumSize(int hSpacing, int vSpacing) const
476 {
477  return findSize(&QLayoutStruct::minimumSize, hSpacing, vSpacing);
478 }
479 
481 {
482  if ((int)rowData.size() < r) {
483  int newR = qMax(r, rr * 2);
484  rowData.resize(newR);
485  rStretch.resize(newR);
486  rMinHeights.resize(newR);
487  for (int i = rr; i < newR; i++) {
488  rowData[i].init();
489  rowData[i].maximumSize = 0;
490  rowData[i].pos = 0;
491  rowData[i].size = 0;
492  rStretch[i] = 0;
493  rMinHeights[i] = 0;
494  }
495  }
496  if ((int)colData.size() < c) {
497  int newC = qMax(c, cc * 2);
498  colData.resize(newC);
499  cStretch.resize(newC);
500  cMinWidths.resize(newC);
501  for (int i = cc; i < newC; i++) {
502  colData[i].init();
503  colData[i].maximumSize = 0;
504  colData[i].pos = 0;
505  colData[i].size = 0;
506  cStretch[i] = 0;
507  cMinWidths[i] = 0;
508  }
509  }
510 
511  if (hfwData && (int)hfwData->size() < r) {
512  delete hfwData;
513  hfwData = 0;
514  hfw_width = -1;
515  }
516  rr = r;
517  cc = c;
518 }
519 
521 {
522  if (addVertical) {
523  if (col > nextC || (col == nextC && row >= nextR)) {
524  nextR = row + 1;
525  nextC = col;
526  if (nextR >= rr) {
527  nextR = 0;
528  nextC++;
529  }
530  }
531  } else {
532  if (row > nextR || (row == nextR && col >= nextC)) {
533  nextR = row;
534  nextC = col + 1;
535  if (nextC >= cc) {
536  nextC = 0;
537  nextR++;
538  }
539  }
540  }
541 }
542 
543 void QGridLayoutPrivate::add(QGridBox *box, int row, int col)
544 {
545  expand(row + 1, col + 1);
546  box->row = box->torow = row;
547  box->col = box->tocol = col;
548  things.append(box);
549  setDirty();
550  setNextPosAfter(row, col);
551 }
552 
553 void QGridLayoutPrivate::add(QGridBox *box, int row1, int row2, int col1, int col2)
554 {
555  if (row2 >= 0 && row2 < row1)
556  qWarning("QGridLayout: Multi-cell fromRow greater than toRow");
557  if (col2 >= 0 && col2 < col1)
558  qWarning("QGridLayout: Multi-cell fromCol greater than toCol");
559  if (row1 == row2 && col1 == col2) {
560  add(box, row1, col1);
561  return;
562  }
563  expand(row2 + 1, col2 + 1);
564  box->row = row1;
565  box->col = col1;
566 
567  box->torow = row2;
568  box->tocol = col2;
569 
570  things.append(box);
571  setDirty();
572  if (col2 < 0)
573  col2 = cc - 1;
574 
575  setNextPosAfter(row2, col2);
576 }
577 
578 void QGridLayoutPrivate::addData(QGridBox *box, const QGridLayoutSizeTriple &sizes, bool r, bool c)
579 {
580  const QWidget *widget = box->item()->widget();
581 
582  if (box->isEmpty() && widget)
583  return;
584 
585  if (c) {
586  QLayoutStruct *data = &colData[box->col];
587  if (!cStretch.at(box->col))
588  data->stretch = qMax(data->stretch, box->hStretch());
589  data->sizeHint = qMax(sizes.hint.width(), data->sizeHint);
590  data->minimumSize = qMax(sizes.minS.width(), data->minimumSize);
591 
592  qMaxExpCalc(data->maximumSize, data->expansive, data->empty, sizes.maxS.width(),
593  box->expandingDirections() & Qt::Horizontal, box->isEmpty());
594  }
595  if (r) {
596  QLayoutStruct *data = &rowData[box->row];
597  if (!rStretch.at(box->row))
598  data->stretch = qMax(data->stretch, box->vStretch());
599  data->sizeHint = qMax(sizes.hint.height(), data->sizeHint);
600  data->minimumSize = qMax(sizes.minS.height(), data->minimumSize);
601 
602  qMaxExpCalc(data->maximumSize, data->expansive, data->empty, sizes.maxS.height(),
603  box->expandingDirections() & Qt::Vertical, box->isEmpty());
604  }
605 }
606 
607 static void initEmptyMultiBox(QVector<QLayoutStruct> &chain, int start, int end)
608 {
609  for (int i = start; i <= end; i++) {
610  QLayoutStruct *data = &chain[i];
611  if (data->empty && data->maximumSize == 0) // truly empty box
613  data->empty = false;
614  }
615 }
616 
617 static void distributeMultiBox(QVector<QLayoutStruct> &chain, int start, int end, int minSize,
618  int sizeHint, QVector<int> &stretchArray, int stretch)
619 {
620  int i;
621  int w = 0;
622  int wh = 0;
623  int max = 0;
624 
625  for (i = start; i <= end; i++) {
626  QLayoutStruct *data = &chain[i];
627  w += data->minimumSize;
628  wh += data->sizeHint;
629  max += data->maximumSize;
630  if (stretchArray.at(i) == 0)
631  data->stretch = qMax(data->stretch, stretch);
632 
633  if (i != end) {
634  int spacing = data->spacing;
635  w += spacing;
636  wh += spacing;
637  max += spacing;
638  }
639  }
640 
641  if (max < minSize) { // implies w < minSize
642  /*
643  We must increase the maximum size of at least one of the
644  items. qGeomCalc() will put the extra space in between the
645  items. We must recover that extra space and put it
646  somewhere. It does not really matter where, since the user
647  can always specify stretch factors and avoid this code.
648  */
649  qGeomCalc(chain, start, end - start + 1, 0, minSize);
650  int pos = 0;
651  for (i = start; i <= end; i++) {
652  QLayoutStruct *data = &chain[i];
653  int nextPos = (i == end) ? minSize : chain.at(i + 1).pos;
654  int realSize = nextPos - pos;
655  if (i != end)
656  realSize -= data->spacing;
657  if (data->minimumSize < realSize)
658  data->minimumSize = realSize;
659  if (data->maximumSize < data->minimumSize)
660  data->maximumSize = data->minimumSize;
661  pos = nextPos;
662  }
663  } else if (w < minSize) {
664  qGeomCalc(chain, start, end - start + 1, 0, minSize);
665  for (i = start; i <= end; i++) {
666  QLayoutStruct *data = &chain[i];
667  if (data->minimumSize < data->size)
668  data->minimumSize = data->size;
669  }
670  }
671 
672  if (wh < sizeHint) {
673  qGeomCalc(chain, start, end - start + 1, 0, sizeHint);
674  for (i = start; i <= end; i++) {
675  QLayoutStruct *data = &chain[i];
676  if (data->sizeHint < data->size)
677  data->sizeHint = data->size;
678  }
679  }
680 }
681 
682 static QGridBox *&gridAt(QGridBox *grid[], int r, int c, int cc,
683  Qt::Orientation orientation = Qt::Vertical)
684 {
685  if (orientation == Qt::Horizontal)
686  qSwap(r, c);
687  return grid[(r * cc) + c];
688 }
689 
691  QGridBox *grid[], int fixedSpacing,
692  Qt::Orientation orientation)
693 {
694  Q_Q(QGridLayout);
695  int numRows = rr; // or columns if orientation is horizontal
696  int numColumns = cc; // or rows if orientation is horizontal
697 
698  if (orientation == Qt::Horizontal) {
699  qSwap(numRows, numColumns);
700  }
701 
702  QStyle *style = 0;
703  if (fixedSpacing < 0) {
704  if (QWidget *parentWidget = q->parentWidget())
705  style = parentWidget->style();
706  }
707 
708  for (int c = 0; c < numColumns; ++c) {
709  QGridBox *previousBox = 0;
710  int previousRow = -1; // previous *non-empty* row
711 
712  for (int r = 0; r < numRows; ++r) {
713  if (chain.at(r).empty)
714  continue;
715 
716  QGridBox *box = gridAt(grid, r, c, cc, orientation);
717  if (previousRow != -1 && (!box || previousBox != box)) {
718  int spacing = fixedSpacing;
719  if (spacing < 0) {
720  QSizePolicy::ControlTypes controlTypes1 = QSizePolicy::DefaultType;
721  QSizePolicy::ControlTypes controlTypes2 = QSizePolicy::DefaultType;
722  if (previousBox)
723  controlTypes1 = previousBox->item()->controlTypes();
724  if (box)
725  controlTypes2 = box->item()->controlTypes();
726 
727  if ((orientation == Qt::Horizontal && hReversed)
728  || (orientation == Qt::Vertical && vReversed))
729  qSwap(controlTypes1, controlTypes2);
730 
731  if (style)
732  spacing = style->combinedLayoutSpacing(controlTypes1, controlTypes2,
733  orientation, 0, q->parentWidget());
734  } else {
735  if (orientation == Qt::Vertical) {
736  QGridBox *sibling = vReversed ? previousBox : box;
737  if (sibling) {
738  QWidget *wid = sibling->item()->widget();
739  if (wid)
740  spacing = qMax(spacing, sibling->item()->geometry().top() - wid->geometry().top() );
741  }
742  }
743  }
744 
745  if (spacing > chain.at(previousRow).spacing)
746  chain[previousRow].spacing = spacing;
747  }
748 
749  previousBox = box;
750  previousRow = r;
751  }
752  }
753 }
754 
755 //#define QT_LAYOUT_DISABLE_CACHING
756 
757 void QGridLayoutPrivate::setupLayoutData(int hSpacing, int vSpacing)
758 {
759  Q_Q(QGridLayout);
760 
761 #ifndef QT_LAYOUT_DISABLE_CACHING
762  if (!needRecalc)
763  return;
764 #endif
765  has_hfw = false;
766  int i;
767 
768  for (i = 0; i < rr; i++) {
769  rowData[i].init(rStretch.at(i), rMinHeights.at(i));
770  rowData[i].maximumSize = rStretch.at(i) ? QLAYOUTSIZE_MAX : rMinHeights.at(i);
771  }
772  for (i = 0; i < cc; i++) {
773  colData[i].init(cStretch.at(i), cMinWidths.at(i));
774  colData[i].maximumSize = cStretch.at(i) ? QLAYOUTSIZE_MAX : cMinWidths.at(i);
775  }
776 
777  int n = things.size();
779 
780  bool has_multi = false;
781 
782  /*
783  Grid of items. We use it to determine which items are
784  adjacent to which and compute the spacings correctly.
785  */
786  QVarLengthArray<QGridBox *> grid(rr * cc);
787  qMemSet(grid.data(), 0, rr * cc * sizeof(QGridBox *));
788 
789  /*
790  Initialize 'sizes' and 'grid' data structures, and insert
791  non-spanning items to our row and column data structures.
792  */
793  for (i = 0; i < n; ++i) {
794  QGridBox * const box = things.at(i);
795  sizes[i].minS = box->minimumSize();
796  sizes[i].hint = box->sizeHint();
797  sizes[i].maxS = box->maximumSize();
798 
799  if (box->hasHeightForWidth())
800  has_hfw = true;
801 
802  if (box->row == box->toRow(rr)) {
803  addData(box, sizes[i], true, false);
804  } else {
805  initEmptyMultiBox(rowData, box->row, box->toRow(rr));
806  has_multi = true;
807  }
808 
809  if (box->col == box->toCol(cc)) {
810  addData(box, sizes[i], false, true);
811  } else {
812  initEmptyMultiBox(colData, box->col, box->toCol(cc));
813  has_multi = true;
814  }
815 
816  for (int r = box->row; r <= box->toRow(rr); ++r) {
817  for (int c = box->col; c <= box->toCol(cc); ++c) {
818  gridAt(grid.data(), r, c, cc) = box;
819  }
820  }
821  }
822 
823  setupSpacings(colData, grid.data(), hSpacing, Qt::Horizontal);
824  setupSpacings(rowData, grid.data(), vSpacing, Qt::Vertical);
825 
826  /*
827  Insert multicell items to our row and column data structures.
828  This must be done after the non-spanning items to obtain a
829  better distribution in distributeMultiBox().
830  */
831  if (has_multi) {
832  for (i = 0; i < n; ++i) {
833  QGridBox * const box = things.at(i);
834 
835  if (box->row != box->toRow(rr))
836  distributeMultiBox(rowData, box->row, box->toRow(rr), sizes[i].minS.height(),
837  sizes[i].hint.height(), rStretch, box->vStretch());
838  if (box->col != box->toCol(cc))
839  distributeMultiBox(colData, box->col, box->toCol(cc), sizes[i].minS.width(),
840  sizes[i].hint.width(), cStretch, box->hStretch());
841  }
842  }
843 
844  for (i = 0; i < rr; i++)
845  rowData[i].expansive = rowData.at(i).expansive || rowData.at(i).stretch > 0;
846  for (i = 0; i < cc; i++)
847  colData[i].expansive = colData.at(i).expansive || colData.at(i).stretch > 0;
848 
849  q->getContentsMargins(&leftMargin, &topMargin, &rightMargin, &bottomMargin);
850 
851  needRecalc = false;
852 }
853 
855 {
856  QVector<QLayoutStruct> &rData = *hfwData;
857  if (box->hasHeightForWidth()) {
858  int hint = box->heightForWidth(width);
859  rData[box->row].sizeHint = qMax(hint, rData.at(box->row).sizeHint);
860  rData[box->row].minimumSize = qMax(hint, rData.at(box->row).minimumSize);
861  } else {
862  QSize hint = box->sizeHint();
863  QSize minS = box->minimumSize();
864  rData[box->row].sizeHint = qMax(hint.height(), rData.at(box->row).sizeHint);
865  rData[box->row].minimumSize = qMax(minS.height(), rData.at(box->row).minimumSize);
866  }
867 }
868 
869 /*
870  Similar to setupLayoutData(), but uses heightForWidth(colData)
871  instead of sizeHint(). Assumes that setupLayoutData() and
872  qGeomCalc(colData) has been called.
873 */
875 {
876  QVector<QLayoutStruct> &rData = *hfwData;
877  for (int i = 0; i < rr; i++) {
878  rData[i] = rowData.at(i);
879  rData[i].minimumSize = rData[i].sizeHint = rMinHeights.at(i);
880  }
881 
882  for (int pass = 0; pass < 2; ++pass) {
883  for (int i = 0; i < things.size(); ++i) {
884  QGridBox *box = things.at(i);
885  int r1 = box->row;
886  int c1 = box->col;
887  int r2 = box->toRow(rr);
888  int c2 = box->toCol(cc);
889  int w = colData.at(c2).pos + colData.at(c2).size - colData.at(c1).pos;
890 
891  if (r1 == r2) {
892  if (pass == 0)
893  addHfwData(box, w);
894  } else {
895  if (pass == 0) {
896  initEmptyMultiBox(rData, r1, r2);
897  } else {
898  QSize hint = box->sizeHint();
899  QSize min = box->minimumSize();
900  if (box->hasHeightForWidth()) {
901  int hfwh = box->heightForWidth(w);
902  if (hfwh > hint.height())
903  hint.setHeight(hfwh);
904  if (hfwh > min.height())
905  min.setHeight(hfwh);
906  }
907  distributeMultiBox(rData, r1, r2, min.height(), hint.height(),
908  rStretch, box->vStretch());
909  }
910  }
911  }
912  }
913  for (int i = 0; i < rr; i++)
914  rData[i].expansive = rData.at(i).expansive || rData.at(i).stretch > 0;
915 }
916 
917 void QGridLayoutPrivate::distribute(QRect r, int hSpacing, int vSpacing)
918 {
919  Q_Q(QGridLayout);
920  bool visualHReversed = hReversed;
921  QWidget *parent = q->parentWidget();
922  if (parent && parent->isRightToLeft())
923  visualHReversed = !visualHReversed;
924 
925  setupLayoutData(hSpacing, vSpacing);
926 
927  int left, top, right, bottom;
928  effectiveMargins(&left, &top, &right, &bottom);
929  r.adjust(+left, +top, -right, -bottom);
930 
931  qGeomCalc(colData, 0, cc, r.x(), r.width());
932  QVector<QLayoutStruct> *rDataPtr;
933  if (has_hfw) {
934  recalcHFW(r.width());
935  qGeomCalc(*hfwData, 0, rr, r.y(), r.height());
936  rDataPtr = hfwData;
937  } else {
938  qGeomCalc(rowData, 0, rr, r.y(), r.height());
939  rDataPtr = &rowData;
940  }
941  QVector<QLayoutStruct> &rData = *rDataPtr;
942  int i;
943 
944  bool reverse = ((r.bottom() > rect.bottom()) || (r.bottom() == rect.bottom()
945  && ((r.right() > rect.right()) != visualHReversed)));
946  int n = things.size();
947  for (i = 0; i < n; ++i) {
948  QGridBox *box = things.at(reverse ? n-i-1 : i);
949  int r2 = box->toRow(rr);
950  int c2 = box->toCol(cc);
951 
952  int x = colData.at(box->col).pos;
953  int y = rData.at(box->row).pos;
954  int x2p = colData.at(c2).pos + colData.at(c2).size; // x2+1
955  int y2p = rData.at(r2).pos + rData.at(r2).size; // y2+1
956  int w = x2p - x;
957  int h = y2p - y;
958 
959  if (visualHReversed)
960  x = r.left() + r.right() - x - w + 1;
961  if (vReversed)
962  y = r.top() + r.bottom() - y - h + 1;
963 
964  box->setGeometry(QRect(x, y, w, h));
965  }
966 }
967 
968 QRect QGridLayoutPrivate::cellRect(int row, int col) const
969 {
970  if (row < 0 || row >= rr || col < 0 || col >= cc)
971  return QRect();
972 
973  const QVector<QLayoutStruct> *rDataPtr;
974  if (has_hfw && hfwData)
975  rDataPtr = hfwData;
976  else
977  rDataPtr = &rowData;
978  return QRect(colData.at(col).pos, rDataPtr->at(row).pos,
979  colData.at(col).size, rDataPtr->at(row).size);
980 }
981 
1066  : QLayout(*new QGridLayoutPrivate, 0, parent)
1067 {
1068  Q_D(QGridLayout);
1069  d->expand(1, 1);
1070 }
1071 
1080  : QLayout(*new QGridLayoutPrivate, 0, 0)
1081 {
1082  Q_D(QGridLayout);
1083  d->expand(1, 1);
1084 }
1085 
1086 
1087 #ifdef QT3_SUPPORT
1088 
1101 QGridLayout::QGridLayout(QWidget *parent, int nRows, int nCols, int margin,
1102  int space, const char *name)
1103  : QLayout(*new QGridLayoutPrivate, 0, parent)
1104 {
1105  Q_D(QGridLayout);
1106  d->expand(nRows, nCols);
1107  setMargin(margin);
1108  setSpacing(space < 0 ? margin : space);
1110 }
1111 
1127 QGridLayout::QGridLayout(QLayout *parentLayout, int nRows, int nCols,
1128  int spacing, const char *name)
1129  : QLayout(*new QGridLayoutPrivate, parentLayout, 0)
1130 {
1131  Q_D(QGridLayout);
1132  d->expand(nRows, nCols);
1135 }
1136 
1152 QGridLayout::QGridLayout(int nRows, int nCols, int spacing, const char *name)
1153  : QLayout(*new QGridLayoutPrivate, 0, 0)
1154 {
1155  Q_D(QGridLayout);
1156  d->expand(nRows, nCols);
1159 }
1160 #endif
1161 
1162 
1173 {
1174  Q_D(QGridLayout);
1175  if (orient == Qt::Horizontal) {
1176  d->expand(1, n);
1177  d->addVertical = false;
1178  } else {
1179  d->expand(n,1);
1180  d->addVertical = true;
1181  }
1182 }
1183 
1184 
1192 {
1193  Q_D(QGridLayout);
1194  d->deleteAll();
1195 }
1196 
1212 {
1213  Q_D(QGridLayout);
1214  d->horizontalSpacing = spacing;
1215  invalidate();
1216 }
1217 
1219 {
1220  Q_D(const QGridLayout);
1221  if (d->horizontalSpacing >= 0) {
1222  return d->horizontalSpacing;
1223  } else {
1225  }
1226 }
1227 
1243 {
1244  Q_D(QGridLayout);
1245  d->verticalSpacing = spacing;
1246  invalidate();
1247 }
1248 
1250 {
1251  Q_D(const QGridLayout);
1252  if (d->verticalSpacing >= 0) {
1253  return d->verticalSpacing;
1254  } else {
1256  }
1257 }
1258 
1266 {
1267  Q_D(QGridLayout);
1268  d->horizontalSpacing = d->verticalSpacing = spacing;
1269  invalidate();
1270 }
1271 
1279 {
1280  int hSpacing = horizontalSpacing();
1281  if (hSpacing == verticalSpacing()) {
1282  return hSpacing;
1283  } else {
1284  return -1;
1285  }
1286 }
1287 
1292 {
1293  Q_D(const QGridLayout);
1294  return d->numRows();
1295 }
1296 
1301 {
1302  Q_D(const QGridLayout);
1303  return d->numCols();
1304 }
1305 
1310 {
1311  Q_D(const QGridLayout);
1312  QSize result(d->sizeHint(horizontalSpacing(), verticalSpacing()));
1313  int left, top, right, bottom;
1314  d->effectiveMargins(&left, &top, &right, &bottom);
1315  result += QSize(left + right, top + bottom);
1316  return result;
1317 }
1318 
1323 {
1324  Q_D(const QGridLayout);
1325  QSize result(d->minimumSize(horizontalSpacing(), verticalSpacing()));
1326  int left, top, right, bottom;
1327  d->effectiveMargins(&left, &top, &right, &bottom);
1328  result += QSize(left + right, top + bottom);
1329  return result;
1330 }
1331 
1336 {
1337  Q_D(const QGridLayout);
1338 
1339  QSize s = d->maximumSize(horizontalSpacing(), verticalSpacing());
1340  int left, top, right, bottom;
1341  d->effectiveMargins(&left, &top, &right, &bottom);
1342  s += QSize(left + right, top + bottom);
1348  return s;
1349 }
1350 
1355 {
1356  return ((QGridLayout*)this)->d_func()->hasHeightForWidth(horizontalSpacing(), verticalSpacing());
1357 }
1358 
1363 {
1364  Q_D(const QGridLayout);
1365  QGridLayoutPrivate *dat = const_cast<QGridLayoutPrivate *>(d);
1366  return dat->heightForWidth(w, horizontalSpacing(), verticalSpacing());
1367 }
1368 
1373 {
1374  Q_D(const QGridLayout);
1375  QGridLayoutPrivate *dat = const_cast<QGridLayoutPrivate *>(d);
1377 }
1378 
1379 #ifdef QT3_SUPPORT
1380 
1393 bool QGridLayout::findWidget(QWidget* w, int *row, int *column)
1394 {
1395  Q_D(QGridLayout);
1396  int index = indexOf(w);
1397  if (index < 0)
1398  return false;
1399  int dummy1, dummy2;
1400  d->getItemPosition(index, row, column, &dummy1, &dummy2);
1401  return true;
1402 }
1403 #endif
1404 
1408 {
1409  Q_D(const QGridLayout);
1410  return d->count();
1411 }
1412 
1413 
1418 {
1419  Q_D(const QGridLayout);
1420  return d->itemAt(index);
1421 }
1422 
1434 QLayoutItem *QGridLayout::itemAtPosition(int row, int column) const
1435 {
1436  Q_D(const QGridLayout);
1437  int n = d->things.count();
1438  for (int i = 0; i < n; ++i) {
1439  QGridBox *box = d->things.at(i);
1440  if (row >= box->row && row <= box->toRow(d->rr)
1441  && column >= box->col && column <= box->toCol(d->cc)) {
1442  return box->item();
1443  }
1444  }
1445  return 0;
1446 }
1447 
1452 {
1453  Q_D(QGridLayout);
1454  return d->takeAt(index);
1455 }
1456 
1466 void QGridLayout::getItemPosition(int index, int *row, int *column, int *rowSpan, int *columnSpan)
1467 {
1468  Q_D(QGridLayout);
1469  d->getItemPosition(index, row, column, rowSpan, columnSpan);
1470 }
1471 
1472 
1477 {
1478  Q_D(QGridLayout);
1479  if (d->isDirty() || rect != geometry()) {
1480  QRect cr = alignment() ? alignmentRect(rect) : rect;
1481  d->distribute(cr, horizontalSpacing(), verticalSpacing());
1482  QLayout::setGeometry(rect);
1483  }
1484 }
1485 
1495 QRect QGridLayout::cellRect(int row, int column) const
1496 {
1497  Q_D(const QGridLayout);
1498  return d->cellRect(row, column);
1499 }
1500 #ifdef QT3_SUPPORT
1501 
1511 void QGridLayout::expand(int nRows, int nCols)
1512 {
1513  Q_D(QGridLayout);
1514  d->expand(nRows, nCols);
1515 }
1516 #endif
1517 
1522 {
1523  Q_D(QGridLayout);
1524  int r, c;
1525  d->getNextPos(r, c);
1526  addItem(item, r, c);
1527 }
1528 
1539 void QGridLayout::addItem(QLayoutItem *item, int row, int column, int rowSpan, int columnSpan, Qt::Alignment alignment)
1540 {
1541  Q_D(QGridLayout);
1542  QGridBox *b = new QGridBox(item);
1543  b->setAlignment(alignment);
1544  d->add(b, row, (rowSpan < 0) ? -1 : row + rowSpan - 1, column, (columnSpan < 0) ? -1 : column + columnSpan - 1);
1545  invalidate();
1546 }
1547 
1548 /*
1549  Returns true if the widget \a w can be added to the layout \a l;
1550  otherwise returns false.
1551 */
1552 static bool checkWidget(QLayout *l, QWidget *w)
1553 {
1554  if (!w) {
1555  qWarning("QLayout: Cannot add null widget to %s/%s", l->metaObject()->className(),
1556  l->objectName().toLocal8Bit().data());
1557  return false;
1558  }
1559  return true;
1560 }
1561 
1570 void QGridLayout::addWidget(QWidget *widget, int row, int column, Qt::Alignment alignment)
1571 {
1572  if (!checkWidget(this, widget))
1573  return;
1574  if (row < 0 || column < 0) {
1575  qWarning("QGridLayout: Cannot add %s/%s to %s/%s at row %d column %d",
1576  widget->metaObject()->className(), widget->objectName().toLocal8Bit().data(),
1577  metaObject()->className(), objectName().toLocal8Bit().data(), row, column);
1578  return;
1579  }
1580  addChildWidget(widget);
1581  QWidgetItem *b = QLayoutPrivate::createWidgetItem(this, widget);
1582  addItem(b, row, column, 1, 1, alignment);
1583 }
1584 
1600 void QGridLayout::addWidget(QWidget *widget, int fromRow, int fromColumn,
1601  int rowSpan, int columnSpan, Qt::Alignment alignment)
1602 {
1603  Q_D(QGridLayout);
1604  if (!checkWidget(this, widget))
1605  return;
1606  int toRow = (rowSpan < 0) ? -1 : fromRow + rowSpan - 1;
1607  int toColumn = (columnSpan < 0) ? -1 : fromColumn + columnSpan - 1;
1608  addChildWidget(widget);
1609  QGridBox *b = new QGridBox(this, widget);
1610  b->setAlignment(alignment);
1611  d->add(b, fromRow, toRow, fromColumn, toColumn);
1612  invalidate();
1613 }
1614 
1636 void QGridLayout::addLayout(QLayout *layout, int row, int column, Qt::Alignment alignment)
1637 {
1638  Q_D(QGridLayout);
1639  if (!adoptLayout(layout))
1640  return;
1641  QGridBox *b = new QGridBox(layout);
1642  b->setAlignment(alignment);
1643  d->add(b, row, column);
1644 }
1645 
1658 void QGridLayout::addLayout(QLayout *layout, int row, int column,
1659  int rowSpan, int columnSpan, Qt::Alignment alignment)
1660 {
1661  Q_D(QGridLayout);
1662  if (!adoptLayout(layout))
1663  return;
1664  QGridBox *b = new QGridBox(layout);
1665  b->setAlignment(alignment);
1666  d->add(b, row, (rowSpan < 0) ? -1 : row + rowSpan - 1, column, (columnSpan < 0) ? -1 : column + columnSpan - 1);
1667 }
1668 
1682 void QGridLayout::setRowStretch(int row, int stretch)
1683 {
1684  Q_D(QGridLayout);
1685  d->setRowStretch(row, stretch);
1686  invalidate();
1687 }
1688 
1694 int QGridLayout::rowStretch(int row) const
1695 {
1696  Q_D(const QGridLayout);
1697  return d->rowStretch(row);
1698 }
1699 
1705 int QGridLayout::columnStretch(int column) const
1706 {
1707  Q_D(const QGridLayout);
1708  return d->colStretch(column);
1709 }
1710 
1728 void QGridLayout::setColumnStretch(int column, int stretch)
1729 {
1730  Q_D(QGridLayout);
1731  d->setColStretch(column, stretch);
1732  invalidate();
1733 }
1734 
1735 
1736 
1742 void QGridLayout::setRowMinimumHeight(int row, int minSize)
1743 {
1744  Q_D(QGridLayout);
1745  d->setRowMinimumHeight(row, minSize);
1746  invalidate();
1747 }
1748 
1755 {
1756  Q_D(const QGridLayout);
1757  return d->rowSpacing(row);
1758 }
1759 
1765 void QGridLayout::setColumnMinimumWidth(int column, int minSize)
1766 {
1767  Q_D(QGridLayout);
1768  d->setColumnMinimumWidth(column, minSize);
1769  invalidate();
1770 }
1771 
1777 int QGridLayout::columnMinimumWidth(int column) const
1778 {
1779  Q_D(const QGridLayout);
1780  return d->colSpacing(column);
1781 }
1782 
1786 Qt::Orientations QGridLayout::expandingDirections() const
1787 {
1788  Q_D(const QGridLayout);
1789  return d->expandingDirections(horizontalSpacing(), verticalSpacing());
1790 }
1791 
1796 {
1797  Q_D(QGridLayout);
1798  d->setReversed(corner == Qt::BottomLeftCorner || corner == Qt::BottomRightCorner,
1799  corner == Qt::TopRightCorner || corner == Qt::BottomRightCorner);
1800 }
1801 
1807 {
1808  Q_D(const QGridLayout);
1809  if (d->horReversed()) {
1810  return d->verReversed() ? Qt::BottomRightCorner : Qt::TopRightCorner;
1811  } else {
1812  return d->verReversed() ? Qt::BottomLeftCorner : Qt::TopLeftCorner;
1813  }
1814 }
1815 
1820 {
1821  Q_D(QGridLayout);
1822  d->setDirty();
1824 }
1825 
QList< QGridBox * > things
int heightForWidth(int w) const
Definition: qgridlayout.cpp:82
double d
Definition: qnumeric_p.h:62
QWidget * parentWidget() const
Returns the parent of this widget, or 0 if it does not have any parent widget.
Definition: qwidget.h:1035
QSize maximumSize(int hSpacing, int vSpacing) const
QLayoutItem * itemAtPosition(int row, int column) const
Returns the layout item that occupies cell (row, column), or 0 if the cell is empty.
bool verReversed() const
static qreal minimumHeightForWidth(qreal width, qreal minh, qreal maxh, const QGraphicsWidget *widget, bool heightForWidth=true)
Used to calculate the Precondition: widget should support either hfw or wfh.
int horizontalSpacing() const
the spacing between widgets that are laid out side by side
unsigned char c[8]
Definition: qnumeric_p.h:62
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
Qt::Alignment alignment() const
Definition: qgridlayout.cpp:86
QGridBox(const QLayout *l, QWidget *wid)
Definition: qgridlayout.cpp:72
Qt::Orientations expandingDirections() const
Reimplemented Function
QPointer< QWidget > widget
static QString fromAscii(const char *, int size=-1)
Returns a QString initialized with the first size characters from the string str. ...
Definition: qstring.cpp:4276
virtual QRect geometry() const =0
Returns the rectangle covered by this layout item.
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
static void initEmptyMultiBox(QVector< QLayoutStruct > &chain, int start, int end)
#define add(aName)
int rowStretch(int r) const
QGridLayout()
Constructs a new grid layout.
int numRows() const
QVector< QLayoutStruct > * hfwData
void addLayout(QLayout *, int row, int column, Qt::Alignment=0)
Places the layout at position (row, column) in the grid.
int colSpacing(int c) const
void setReversed(bool r, bool c)
static C reverse(const C &l)
void addData(QGridBox *b, const QGridLayoutSizeTriple &sizes, bool r, bool c)
void recalcHFW(int w)
#define QWIDGETSIZE_MAX
Defines the maximum size for a QWidget object.
Definition: qwidget.h:1087
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
QSizePolicy::ControlTypes controlTypes() const
Returns the control type(s) for the layout item.
void setColumnMinimumWidth(int column, int minSize)
Sets the minimum width of column column to minSize pixels.
int left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:240
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
int minimumHeightForWidth(int width, int hSpacing, int vSpacing)
int count() const
Reimplemented Function
virtual void setGeometry(const QRect &)
Reimplemented Function
Definition: qlayout.cpp:655
long ASN1_INTEGER_get ASN1_INTEGER * a
QGridBox(QLayoutItem *lit)
Definition: qgridlayout.cpp:70
bool isDirty() const
QVector< QLayoutStruct > colData
QVector< int > rStretch
void invalidate()
Reimplemented Function
Definition: qlayout.cpp:673
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
int bottom() const
Returns the y-coordinate of the rectangle&#39;s bottom edge.
Definition: qrect.h:249
int rowStretch(int row) const
Returns the stretch factor for row row.
void setHeight(int h)
Sets the height to the given height.
Definition: qsize.h:135
int columnMinimumWidth(int column) const
Returns the column spacing for column column.
#define Q_D(Class)
Definition: qglobal.h:2482
QSize boundedTo(const QSize &) const
Returns a size holding the minimum width and height of this size and the given otherSize.
Definition: qsize.h:192
int rowCount() const
Returns the number of rows in this grid.
void setupLayoutData(int hSpacing, int vSpacing)
Qt::Orientations expandingDirections(int hSpacing, int vSpacing) const
int heightForWidth(int) const
Reimplemented Function
Q_CORE_EXPORT QTextStream & right(QTextStream &s)
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
void add(QGridBox *, int row, int col)
void setParent(QObject *)
Makes the object a child of parent.
Definition: qobject.cpp:1950
QStyle * style() const
Definition: qwidget.cpp:2742
void setObjectName(const QString &name)
Definition: qobject.cpp:1112
#define Q_Q(Class)
Definition: qglobal.h:2483
void setWidth(int w)
Sets the width to the given width.
Definition: qsize.h:132
int vStretch()
Definition: qgridlayout.cpp:92
void setupSpacings(QVector< QLayoutStruct > &chain, QGridBox *grid[], int fixedSpacing, Qt::Orientation orientation)
void setHorizontalSpacing(int spacing)
QLayoutItem * itemAt(int index) const
Reimplemented Function
void setOriginCorner(Qt::Corner)
Sets the grid&#39;s origin corner, i.e.
void setAlignment(Qt::Alignment a)
Definition: qgridlayout.cpp:84
int columnCount() const
Returns the number of columns in this grid.
QLayoutItem * takeAt(int index)
Reimplemented Function
int width() const
Returns the width.
Definition: qsize.h:126
~QGridLayout()
Destroys the grid layout.
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
The QLayoutItem class provides an abstract item that a QLayout manipulates.
Definition: qlayoutitem.h:64
int colStretch(int c) const
void setSize(int rows, int cols)
QLayout()
Constructs a new child QLayout.
Definition: qlayout.cpp:127
QLayoutItem * item_
bool adoptLayout(QLayout *layout)
Definition: qlayout.cpp:987
virtual int indexOf(QWidget *) const
Searches for widget widget in this layout (not including child layouts).
Definition: qlayout.cpp:1378
QSize minimumSize() const
Definition: qgridlayout.cpp:76
static bool init
The QLayout class is the base class of geometry managers.
Definition: qlayout.h:90
const char * name
void adjust(int x1, int y1, int x2, int y2)
Adds dx1, dy1, dx2 and dy2 respectively to the existing coordinates of the rectangle.
Definition: qrect.h:434
void getNextPos(int &row, int &col)
QSize maximumSize() const
Definition: qgridlayout.cpp:77
bool horReversed() const
void setRowMinimumHeight(int row, int minSize)
Sets the minimum height of row row to minSize pixels.
Q_CORE_EXPORT void qWarning(const char *,...)
static const char * data(const QByteArray &arr)
Qt::Corner originCorner() const
Returns the corner that&#39;s used for the grid&#39;s origin, i.e.
unsigned int uint
Definition: qglobal.h:996
int spacing() const
If the vertical spacing is equal to the horizontal spacing, this function returns that value; otherwi...
void effectiveMargins(int *left, int *top, int *right, int *bottom) const
void setVerticalSpacing(int spacing)
void expand(int rows, int cols)
The QWidgetItem class is a layout item that represents a widget.
Definition: qlayoutitem.h:122
int toRow(int rr) const
Definition: qgridlayout.cpp:99
QByteArray toLocal8Bit() const Q_REQUIRED_RESULT
Returns the local 8-bit representation of the string as a QByteArray.
Definition: qstring.cpp:4049
QVector< int > cStretch
QRect alignmentRect(const QRect &) const
Returns the rectangle that should be covered when the geometry of this layout is set to r...
Definition: qlayout.cpp:1459
void qSwap(T &value1, T &value2)
Definition: qglobal.h:2181
QSize minimumSize() const
Reimplemented Function
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
QSize findSize(int QLayoutStruct::*, int hSpacing, int vSpacing) const
static QWidget * parentWidget(const QWidget *w)
QLayoutItem * takeItem()
Definition: qgridlayout.cpp:88
bool hasHeightForWidth() const
Reimplemented Function
Corner
Definition: qnamespace.h:1456
Qt::LayoutDirection layoutDirection
the layout direction for this widget
Definition: qwidget.h:216
void qGeomCalc(QVector< QLayoutStruct > &chain, int start, int count, int pos, int space, int spacer)
void setNextPosAfter(int r, int c)
int columnStretch(int column) const
Returns the stretch factor for column column.
static QWidgetItem * createWidgetItem(const QLayout *layout, QWidget *widget)
Definition: qlayout.cpp:190
int hStretch()
Definition: qgridlayout.cpp:90
QVector< int > rMinHeights
Qt::Orientations expandingDirections() const
Definition: qgridlayout.cpp:78
int minimumHeightForWidth(int) const
Reimplemented Function
int top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:243
void * qMemSet(void *dest, int c, size_t n)
Definition: qglobal.cpp:2509
void getItemPosition(int index, int *row, int *column, int *rowSpan, int *columnSpan)
Q_GUI_EXPORT int qSmartSpacing(const QLayout *layout, QStyle::PixelMetric pm)
#define Q_DECLARE_PUBLIC(Class)
Definition: qglobal.h:2477
void setColStretch(int c, int s)
int right() const
Returns the x-coordinate of the rectangle&#39;s right edge.
Definition: qrect.h:246
void setColumnStretch(int column, int stretch)
Sets the stretch factor of column column to stretch.
int rowSpacing(int r) const
void setGeometry(const QRect &)
Reimplemented Function
int y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:255
void addChildWidget(QWidget *w)
This function is called from addWidget() functions in subclasses to add w as a managed widget of a la...
Definition: qlayout.cpp:1045
virtual QLayout * layout()
If this item is a QLayout, it is returned as a QLayout; otherwise 0 is returned.
int x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:252
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
QSize sizeHint(int hSpacing, int vSpacing) const
void invalidate()
Reimplemented Function
static bool checkWidget(QLayout *l, QWidget *w)
QSize maximumSize() const
Reimplemented Function
The QGridLayout class lays out widgets in a grid.
Definition: qgridlayout.h:60
bool isEmpty() const
Definition: qgridlayout.cpp:79
The QStyle class is an abstract base class that encapsulates the look and feel of a GUI...
Definition: qstyle.h:68
const char * className() const
Returns the class name.
Definition: qobjectdefs.h:491
QString objectName() const
int height() const
Returns the height.
Definition: qsize.h:129
void setDefaultPositioning(int n, Qt::Orientation orient)
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
QFactoryLoader * l
QSize sizeHint() const
Reimplemented Function
static QGridBox *& gridAt(QGridBox *grid[], int r, int c, int cc, Qt::Orientation orientation=Qt::Vertical)
Qt::Alignment alignment() const
Returns the alignment of this item.
Definition: qlayoutitem.h:85
void setColumnMinimumWidth(int c, int s)
quint16 index
virtual QWidget * widget()
If this item is a QWidget, it is returned as a QWidget; otherwise 0 is returned.
int toCol(int cc) const
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
void setRowStretch(int row, int stretch)
Sets the stretch factor of row row to stretch.
void addHfwData(QGridBox *box, int width)
bool isRightToLeft() const
Definition: qwidget.h:428
void setRowStretch(int r, int s)
QRect cellRect(int row, int column) const
Returns the geometry of the cell with row row and column column in the grid.
QSize minimumSize(int hSpacing, int vSpacing) const
QVector< QLayoutStruct > rowData
QLayoutItem * item()
Definition: qgridlayout.cpp:87
void getItemPosition(int idx, int *row, int *column, int *rowSpan, int *columnSpan)
Returns the position information of the item with the given index.
void addWidget(QWidget *w)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qgridlayout.h:116
QRect geometry() const
Reimplemented Function
Definition: qlayout.cpp:664
int margin() const
QSize sizeHint() const
Definition: qgridlayout.cpp:75
QLayout * layout()
Reimplemented Function
static const int QLAYOUTSIZE_MAX
Definition: qlayoutitem.h:56
void setRowMinimumHeight(int r, int s)
static const KeyPair *const end
void setMargin(int)
Definition: qlayout.cpp:464
Orientation
Definition: qnamespace.h:174
static void qMaxExpCalc(int &max, bool &exp, bool &empty, int boxmax, bool boxexp, bool boxempty)
QRect cellRect(int row, int col) const
Q_CORE_EXPORT QTextStream & left(QTextStream &s)
void setGeometry(const QRect &r)
Definition: qgridlayout.cpp:85
QRect geometry
the geometry of the widget relative to its parent and excluding the window frame
Definition: qwidget.h:158
void setSpacing(int spacing)
This function sets both the vertical and horizontal spacing to spacing.
QLayoutItem * takeAt(int index)
int combinedLayoutSpacing(QSizePolicy::ControlTypes controls1, QSizePolicy::ControlTypes controls2, Qt::Orientation orientation, QStyleOption *option=0, QWidget *widget=0) const
Returns the spacing that should be used between controls1 and controls2 in a layout.
Definition: qstyle.cpp:2438
int rowMinimumHeight(int row) const
Returns the minimum width set for row row.
#define INT_MAX
bool hasHeightForWidth(int hSpacing, int vSpacing)
static void distributeMultiBox(QVector< QLayoutStruct > &chain, int start, int end, int minSize, int sizeHint, QVector< int > &stretchArray, int stretch)
void addItem(QLayoutItem *item, int row, int column, int rowSpan=1, int columnSpan=1, Qt::Alignment=0)
Adds item at position row, column, spanning rowSpan rows and columnSpan columns, and aligns it accord...
int heightForWidth(int width, int hSpacing, int vSpacing)
bool hasHeightForWidth() const
Definition: qgridlayout.cpp:81
int verticalSpacing() const
the spacing between widgets that are laid out on top of each other
virtual const QMetaObject * metaObject() const
Returns a pointer to the meta-object of this object.
QLayoutItem * itemAt(int index) const
QVector< int > cMinWidths
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
int numCols() const
void distribute(QRect rect, int hSpacing, int vSpacing)