62 inline int toRow(
int rr)
const {
return torow >= 0 ? torow : rr - 1; }
63 inline int toCol(
int cc)
const {
return tocol >= 0 ? tocol : cc - 1; }
77 void add(
QGridBox*,
int row1,
int row2,
int col1,
int col2);
87 inline void expand(
int rows,
int cols)
88 { setSize(
qMax(rows, rr),
qMax(cols, cc)); }
105 inline void setDirty() { needRecalc =
true; hfw_width = -1; }
106 inline bool isDirty()
const {
return needRecalc; }
128 if (l->parent() ==
q)
129 l->setParent(
nullptr);
144 item =
b->takeItem();
153 int toRow =
b->toRow(rr);
154 int toCol =
b->toCol(cc);
157 *rowSpan = toRow - *
row + 1;
158 *columnSpan = toCol - *
column +1;
164 void setNextPosAfter(
int r,
int c);
165 void recalcHFW(
int w);
170 void setSize(
int rows,
int cols);
173 void setupLayoutData(
int hSpacing,
int vSpacing);
174 void setupHfwLayoutData();
194 int horizontalSpacing;
205 uint addVertical : 1;
208void QGridLayoutPrivate::effectiveMargins(
int *
left,
int *
top,
int *
right,
int *
bottom)
const
213 int b = bottomMargin;
215 int leftMost = INT_MAX;
216 int topMost = INT_MAX;
221 const int n = things.
count();
222 for (
int i = 0;
i <
n; ++
i) {
227 bool visualHReversed = hReversed != (
w->layoutDirection() ==
Qt::RightToLeft);
230 if (
box->col <= leftMost) {
231 if (
box->col < leftMost) {
239 if (visualHReversed) {
245 if (
box->row <= topMost) {
246 if (
box->row < topMost) {
259 if (
box->toCol(cc) >= rightMost) {
260 if (
box->toCol(cc) > rightMost) {
262 rightMost =
box->toCol(cc);
268 if (visualHReversed) {
275 if (
box->toRow(rr) >= bottomMost) {
276 if (
box->toRow(rr) > bottomMost) {
278 bottomMost =
box->toRow(rr);
312 horizontalSpacing = -1;
313 verticalSpacing = -1;
318 : rowData(0), colData(0)
329 setSize(nRows, nCols);
342 setupLayoutData(hSpacing, vSpacing);
350void QGridLayoutPrivate::recalcHFW(
int w)
358 setupHfwLayoutData();
363 for (
int r = 0;
r < rr;
r++) {
376 setupLayoutData(hSpacing, vSpacing);
383 if (
w - hMargins != hfw_width) {
385 recalcHFW(
w - hMargins);
396 effectiveMargins(
nullptr, &
top,
nullptr, &
bottom);
403 that->setupLayoutData(hSpacing, vSpacing);
408 for (
int r = 0;
r < rr;
r++)
410 for (
int c = 0;
c < cc;
c++)
422 that->setupLayoutData(hSpacing, vSpacing);
423 Qt::Orientations
ret;
425 for (
int r = 0;
r < rr;
r++) {
431 for (
int c = 0;
c < cc;
c++) {
455void QGridLayoutPrivate::setSize(
int r,
int c)
457 if ((
int)rowData.
size() <
r) {
458 int newR =
qMax(
r, rr * 2);
462 for (
int i = rr;
i < newR;
i++) {
464 rowData[
i].maximumSize = 0;
471 if ((
int)colData.
size() <
c) {
472 int newC =
qMax(
c, cc * 2);
476 for (
int i = cc;
i < newC;
i++) {
478 colData[
i].maximumSize = 0;
486 if (hfwData && (
int)hfwData->
size() <
r) {
495void QGridLayoutPrivate::setNextPosAfter(
int row,
int col)
498 if (col > nextC || (col == nextC &&
row >= nextR)) {
507 if (
row > nextR || (
row == nextR && col >= nextC)) {
522 box->col =
box->tocol = col;
525 setNextPosAfter(
row, col);
531 qWarning(
"QGridLayout: Multi-cell fromRow greater than toRow");
533 qWarning(
"QGridLayout: Multi-cell fromCol greater than toCol");
534 if (row1 == row2 && col1 == col2) {
550 setNextPosAfter(row2, col2);
562 if (!cStretch.
at(
box->col))
572 if (!rStretch.
at(
box->row))
586 if (
data->empty &&
data->maximumSize == 0)
593 int sizeHint,
QList<int> &stretchArray,
int stretch)
602 w +=
data->minimumSize;
603 wh +=
data->sizeHint;
604 max +=
data->maximumSize;
605 if (stretchArray.
at(
i) == 0)
628 int nextPos = (
i ==
end) ? minSize : chain.
at(
i + 1).pos;
629 int realSize = nextPos -
pos;
631 realSize -=
data->spacing;
632 if (
data->minimumSize < realSize)
633 data->minimumSize = realSize;
634 if (
data->maximumSize <
data->minimumSize)
635 data->maximumSize =
data->minimumSize;
638 }
else if (
w < minSize) {
662 return grid[(
r * cc) +
c];
677 if (fixedSpacing < 0) {
679 style = parentWidget->style();
682 for (
int c = 0;
c < numColumns; ++
c) {
684 int previousRow = -1;
687 if (chain.
at(
r).empty)
691 if (previousRow != -1 && (!
box || previousBox !=
box)) {
699 controlTypes2 =
box->item()->controlTypes();
703 qSwap(controlTypes1, controlTypes2);
707 orientation,
nullptr,
q->parentWidget());
723 if (
spacing > chain.
at(previousRow).spacing)
724 chain[previousRow].spacing =
spacing;
735void QGridLayoutPrivate::setupLayoutData(
int hSpacing,
int vSpacing)
739#ifndef QT_LAYOUT_DISABLE_CACHING
746 for (
i = 0;
i < rr;
i++) {
747 rowData[
i].init(rStretch.
at(
i), rMinHeights.
at(
i));
750 for (
i = 0;
i < cc;
i++) {
751 colData[
i].init(cStretch.
at(
i), cMinWidths.
at(
i));
755 int n = things.
size();
758 bool has_multi =
false;
765 memset(grid.data(), 0, rr * cc *
sizeof(
QGridBox *));
771 for (
i = 0;
i <
n; ++
i) {
777 if (
box->hasHeightForWidth())
780 if (
box->row ==
box->toRow(rr)) {
787 if (
box->col ==
box->toCol(cc)) {
794 for (
int r =
box->row;
r <=
box->toRow(rr); ++
r) {
795 for (
int c =
box->col;
c <=
box->toCol(cc); ++
c) {
802 setupSpacings(rowData, grid.data(), vSpacing,
Qt::Vertical);
810 for (
i = 0;
i <
n; ++
i) {
813 if (
box->row !=
box->toRow(rr))
815 sizes[
i].hint.height(), rStretch,
box->vStretch());
816 if (
box->col !=
box->toCol(cc))
818 sizes[
i].hint.width(), cStretch,
box->hStretch());
822 for (
i = 0;
i < rr;
i++)
824 for (
i = 0;
i < cc;
i++)
827 q->getContentsMargins(&leftMargin, &topMargin, &rightMargin, &bottomMargin);
835 if (
box->hasHeightForWidth()) {
842 rData[
box->row].sizeHint =
qMax(
hint.height(), rData.
at(
box->row).sizeHint);
852void QGridLayoutPrivate::setupHfwLayoutData()
855 for (
int i = 0;
i < rr;
i++) {
856 rData[
i] = rowData.
at(
i);
857 rData[
i].minimumSize = rData[
i].sizeHint = rMinHeights.
at(
i);
860 for (
int pass = 0; pass < 2; ++pass) {
861 for (
int i = 0;
i < things.
size(); ++
i) {
865 int r2 =
box->toRow(rr);
866 int c2 =
box->toCol(cc);
878 if (
box->hasHeightForWidth()) {
879 int hfwh =
box->heightForWidth(
w);
880 if (hfwh >
hint.height())
881 hint.setHeight(hfwh);
882 if (hfwh >
min.height())
886 rStretch,
box->vStretch());
891 for (
int i = 0;
i < rr;
i++)
892 rData[
i].expansive = rData.
at(
i).expansive || rData.
at(
i).stretch > 0;
898 bool visualHReversed = hReversed;
901 visualHReversed = !visualHReversed;
903 setupLayoutData(hSpacing, vSpacing);
912 recalcHFW(
r.width());
923 && ((
r.right() >
rect.
right()) != visualHReversed)));
924 int n = things.
size();
925 for (
i = 0;
i <
n; ++
i) {
927 int r2 =
box->toRow(rr);
928 int c2 =
box->toCol(cc);
931 int y = rData.
at(
box->row).pos;
933 int y2p = rData.
at(
r2).pos + rData.
at(
r2).size;
938 x =
r.left() +
r.right() -
x -
w + 1;
940 y =
r.top() +
r.bottom() -
y -
h + 1;
948 if (row < 0 || row >= rr || col < 0 || col >= cc)
952 if (has_hfw && hfwData)
1071 d->addVertical =
false;
1074 d->addVertical =
true;
1112 if (
d->horizontalSpacing >= 0) {
1113 return d->horizontalSpacing;
1140 if (
d->verticalSpacing >= 0) {
1141 return d->verticalSpacing;
1156 d->horizontalSpacing =
d->verticalSpacing =
spacing;
1182 return d->numRows();
1191 return d->numCols();
1297 int n =
d->things.size();
1298 for (
int i = 0;
i <
n; ++
i) {
1300 if (
row >=
box->row && row <= box->toRow(
d->rr)
1301 &&
column >=
box->col && column <= box->toCol(
d->cc)) {
1368 d->getNextPos(
r,
c);
1387 d->add(
b,
row, (rowSpan < 0) ? -1 :
row + rowSpan - 1,
column, (columnSpan < 0) ? -1 :
column + columnSpan - 1);
1405 qWarning(
"QGridLayout: Cannot add %s/%s to %s/%s at row %d column %d",
1428 int rowSpan,
int columnSpan, Qt::Alignment
alignment)
1433 int toRow = (rowSpan < 0) ? -1 : fromRow + rowSpan - 1;
1434 int toColumn = (columnSpan < 0) ? -1 : fromColumn + columnSpan - 1;
1438 d->add(
b, fromRow, toRow, fromColumn, toColumn);
1485 int rowSpan,
int columnSpan, Qt::Alignment
alignment)
1494 d->add(
b,
row, (rowSpan < 0) ? -1 :
row + rowSpan - 1,
column, (columnSpan < 0) ? -1 :
column + columnSpan - 1);
1513 d->setRowStretch(
row, stretch);
1525 return d->rowStretch(
row);
1559 d->setColStretch(
column, stretch);
1573 d->setRowMinimumHeight(
row, minSize);
1585 return d->rowSpacing(
row);
1596 d->setColumnMinimumWidth(
column, minSize);
1637 if (
d->horReversed()) {
1656#include "moc_qgridlayout.cpp"
char * data()
\macro QT_NO_CAST_FROM_BYTEARRAY
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
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
The QGridLayout class lays out widgets in a grid.
void setGeometry(const QRect &) override
\reimp
void setHorizontalSpacing(int spacing)
void addWidget(QWidget *w)
This is an overloaded member function, provided for convenience. It differs from the above function o...
int horizontalSpacing() const
the spacing between widgets that are laid out side by side
int columnStretch(int column) const
Returns the stretch factor for column column.
void addLayout(QLayout *, int row, int column, Qt::Alignment=Qt::Alignment())
Places the layout at position (row, column) in the grid.
int columnMinimumWidth(int column) const
Returns the column spacing for column column.
int verticalSpacing() const
the spacing between widgets that are laid out on top of each other
void setRowMinimumHeight(int row, int minSize)
Sets the minimum height of row row to minSize pixels.
void setDefaultPositioning(int n, Qt::Orientation orient)
int count() const override
\reimp
~QGridLayout()
Destroys the grid layout.
void setColumnMinimumWidth(int column, int minSize)
Sets the minimum width of column column to minSize pixels.
void getItemPosition(int idx, int *row, int *column, int *rowSpan, int *columnSpan) const
Returns the position information of the item with the given index.
QSize maximumSize() const override
\reimp
Qt::Corner originCorner() const
Returns the corner that's used for the grid's origin, i.e.
bool hasHeightForWidth() const override
\reimp
void setSpacing(int spacing) override
This function sets both the vertical and horizontal spacing to spacing.
int rowStretch(int row) const
Returns the stretch factor for row row.
int heightForWidth(int) const override
\reimp
QLayoutItem * itemAt(int index) const override
\reimp
int rowCount() const
Returns the number of rows in this grid.
QGridLayout(QWidget *parent=nullptr)
Constructs a new QGridLayout with parent widget, parent.
void invalidate() override
\reimp
QLayoutItem * itemAtPosition(int row, int column) const
void addItem(QLayoutItem *item, int row, int column, int rowSpan=1, int columnSpan=1, Qt::Alignment=Qt::Alignment())
Adds item at position row, column, spanning rowSpan rows and columnSpan columns, and aligns it accord...
Qt::Orientations expandingDirections() const override
\reimp
int rowMinimumHeight(int row) const
Returns the minimum width set for row row.
void setVerticalSpacing(int spacing)
void setRowStretch(int row, int stretch)
Sets the stretch factor of row row to stretch.
int columnCount() const
Returns the number of columns in this grid.
QSize minimumSize() const override
\reimp
QRect cellRect(int row, int column) const
Returns the geometry of the cell with row row and column column in the grid.
QLayoutItem * takeAt(int index) override
\reimp
void setOriginCorner(Qt::Corner)
Sets the grid's origin corner, i.e.
int spacing() const override
If the vertical spacing is equal to the horizontal spacing, this function returns that value; otherwi...
int minimumHeightForWidth(int) const override
\reimp
QSize sizeHint() const override
\reimp
void setColumnStretch(int column, int stretch)
Sets the stretch factor of column column to stretch.
The QLayoutItem class provides an abstract item that a QLayout manipulates.
virtual Qt::Orientations expandingDirections() const =0
Returns whether this layout item can make use of more space than sizeHint().
virtual QSize minimumSize() const =0
Implemented in subclasses to return the minimum size of this item.
virtual bool isEmpty() const =0
Implemented in subclasses to return whether this item is empty, i.e.
virtual QRect geometry() const =0
Returns the rectangle covered by this layout item.
virtual QSizePolicy::ControlTypes controlTypes() const
Returns the control type(s) for the layout item.
virtual bool hasHeightForWidth() const
Returns true if this layout's preferred height depends on its width; otherwise returns false.
virtual int heightForWidth(int) const
Returns the preferred height for this layout item, given the width, which is not used in this default...
Qt::Alignment alignment() const
Returns the alignment of this item.
virtual void setGeometry(const QRect &)=0
Implemented in subclasses to set this item's geometry to r.
virtual QSize maximumSize() const =0
Implemented in subclasses to return the maximum size of this item.
virtual QWidget * widget() const
If this item manages a QWidget, returns that widget.
virtual QSize sizeHint() const =0
Implemented in subclasses to return the preferred size of this item.
void setAlignment(Qt::Alignment a)
Sets the alignment of this item to alignment.
static QWidgetItem * createWidgetItem(const QLayout *layout, QWidget *widget)
The QLayout class is the base class of geometry managers.
QRect geometry() const override
\reimp
void addChildWidget(QWidget *w)
This function is called from addWidget() functions in subclasses to add w as a managed widget of a la...
QRect alignmentRect(const QRect &) const
Returns the rectangle that should be covered when the geometry of this layout is set to r,...
void invalidate() override
\reimp
bool adoptLayout(QLayout *layout)
virtual void setGeometry(const QRect &) override
\reimp
QLayout * layout() override
\reimp
qsizetype size() const noexcept
bool isEmpty() const noexcept
const_reference at(qsizetype i) const noexcept
T value(qsizetype i) const
qsizetype count() const noexcept
void resize(qsizetype size)
void append(parameter_type t)
QString objectName
the name of this object
\inmodule QtCore\reentrant
constexpr int bottom() const noexcept
Returns the y-coordinate of the rectangle's bottom edge.
constexpr int top() const noexcept
Returns the y-coordinate of the rectangle's top edge.
constexpr int left() const noexcept
Returns the x-coordinate of the rectangle's left edge.
constexpr int right() const noexcept
Returns the x-coordinate of the rectangle's right edge.
constexpr int horizontalStretch() const noexcept
Returns the horizontal stretch factor of the size policy.
constexpr int verticalStretch() const noexcept
Returns the vertical stretch factor of the size policy.
constexpr int height() const noexcept
Returns the height.
QByteArray toLocal8Bit() const &
The QStyle class is an abstract base class that encapsulates the look and feel of a GUI.
int combinedLayoutSpacing(QSizePolicy::ControlTypes controls1, QSizePolicy::ControlTypes controls2, Qt::Orientation orientation, QStyleOption *option=nullptr, QWidget *widget=nullptr) const
@ PM_LayoutVerticalSpacing
@ PM_LayoutHorizontalSpacing
Combined button and popup list for selecting options.
constexpr const T & min(const T &a, const T &b)
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char const char return DBusMessage return DBusMessage const char return DBusMessage dbus_bool_t return DBusMessage dbus_uint32_t return DBusMessage void
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)
Q_WIDGETS_EXPORT int qSmartSpacing(const QLayout *layout, QStyle::PixelMetric pm)
void qGeomCalc(QList< QLayoutStruct > &chain, int start, int count, int pos, int space, int spacer)
static void qMaxExpCalc(int &max, bool &exp, bool &empty, int boxmax, bool boxexp, bool boxempty)
QT_BEGIN_NAMESPACE constexpr int QLAYOUTSIZE_MAX
constexpr const T & qMin(const T &a, const T &b)
constexpr const T & qMax(const T &a, const T &b)
GLboolean GLboolean GLboolean b
GLint GLint GLint GLint GLint x
[0]
GLfloat GLfloat GLfloat w
[0]
GLboolean GLboolean GLboolean GLboolean a
[7]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLdouble GLdouble GLdouble GLdouble top
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLsizei const GLint * box
GLfloat GLfloat GLfloat GLfloat h
GLenum GLenum GLsizei void GLsizei void * column
GLuint GLsizei const GLuint const GLintptr const GLsizeiptr * sizes
GLdouble GLdouble GLdouble GLdouble q
GLenum GLenum GLsizei void * row
static char * toLocal8Bit(char *out, QStringView in, QStringConverter::State *state)
static QT_BEGIN_NAMESPACE QVariant hint(QPlatformIntegration::StyleHint h)
const char className[16]
[1]
obj metaObject() -> className()
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent