The FlowLayout class implements a layout that arranges components in a directional flow, like lines of text in a paragraph. The layout adapts to changing window sizes, a little like the Swing FlowLayout. It is based on the Qt Flow Layout example.
More...
#include <flowlayout.h>
|
int | doLayout (const QRect &rect, bool testOnly) const |
|
int | smartSpacing (QStyle::PixelMetric pm) const |
|
The FlowLayout class implements a layout that arranges components in a directional flow, like lines of text in a paragraph. The layout adapts to changing window sizes, a little like the Swing FlowLayout. It is based on the Qt Flow Layout example.
◆ FlowLayout()
geometrize::layout::FlowLayout::FlowLayout |
( |
const int |
margin = -1 , |
|
|
const int |
hSpacing = -1 , |
|
|
const int |
vSpacing = -1 |
|
) |
| |
|
explicit |
45 setContentsMargins(margin, margin, margin, margin);
◆ ~FlowLayout()
geometrize::layout::FlowLayout::~FlowLayout |
( |
| ) |
|
|
virtual |
50 while (QLayoutItem* item =
takeAt(0)) {
◆ addItem()
void geometrize::layout::FlowLayout::addItem |
( |
QLayoutItem * |
item | ) |
|
|
override |
◆ count()
int geometrize::layout::FlowLayout::count |
( |
| ) |
const |
|
override |
◆ doLayout()
int geometrize::layout::FlowLayout::doLayout |
( |
const QRect & |
rect, |
|
|
bool |
testOnly |
|
) |
| const |
|
private |
144 int left, top, right, bottom;
145 getContentsMargins(&left, &top, &right, &bottom);
146 QRect effectiveRect = rect.adjusted(+left, +top, -right, -bottom);
147 int x{effectiveRect.x()};
148 int y{effectiveRect.y()};
153 const QWidget*
const wid{item->widget()};
154 if(wid->isHidden()) {
160 spaceX = wid->style()->layoutSpacing(QSizePolicy::PushButton, QSizePolicy::PushButton, Qt::Horizontal);
164 spaceY = wid->style()->layoutSpacing(QSizePolicy::PushButton, QSizePolicy::PushButton, Qt::Vertical);
166 int nextX{x + item->sizeHint().width() + spaceX};
167 if (nextX - spaceX > effectiveRect.right() && lineHeight > 0) {
168 x = effectiveRect.x();
169 y = y + lineHeight + spaceY;
170 nextX = x + item->sizeHint().width() + spaceX;
175 item->setGeometry(QRect(QPoint(x, y), item->sizeHint()));
179 lineHeight = qMax(lineHeight, item->sizeHint().height());
181 return y + lineHeight - rect.y() + bottom;
◆ expandingDirections()
Qt::Orientations geometrize::layout::FlowLayout::expandingDirections |
( |
| ) |
const |
|
override |
81 return Qt::Horizontal;
◆ hasHeightForWidth()
bool geometrize::layout::FlowLayout::hasHeightForWidth |
( |
| ) |
const |
|
override |
◆ heightForWidth()
int geometrize::layout::FlowLayout::heightForWidth |
( |
int |
width | ) |
const |
|
override |
91 return doLayout(QRect(0, 0, width, 0),
true);
◆ horizontalSpacing()
int geometrize::layout::FlowLayout::horizontalSpacing |
( |
| ) |
const |
◆ itemAt()
QLayoutItem * geometrize::layout::FlowLayout::itemAt |
( |
int |
index | ) |
const |
|
override |
◆ minimumSize()
QSize geometrize::layout::FlowLayout::minimumSize |
( |
| ) |
const |
|
override |
109 size = size.expandedTo(item->minimumSize());
116 getContentsMargins(&left, &top, &right, &bottom);
118 size += QSize(left + right, bottom + top);
◆ setGeometry()
void geometrize::layout::FlowLayout::setGeometry |
( |
const QRect & |
rect | ) |
|
|
override |
124 QLayout::setGeometry(rect);
◆ sizeHint()
QSize geometrize::layout::FlowLayout::sizeHint |
( |
| ) |
const |
|
override |
◆ smartSpacing()
int geometrize::layout::FlowLayout::smartSpacing |
( |
QStyle::PixelMetric |
pm | ) |
const |
|
private |
186 QObject* parent{this->parent()};
189 }
else if (parent->isWidgetType()) {
190 QWidget* pw{
static_cast<QWidget*
>(parent)};
191 return pw->style()->pixelMetric(pm, 0, pw);
193 return static_cast<QLayout*
>(parent)->spacing();
◆ takeAt()
QLayoutItem * geometrize::layout::FlowLayout::takeAt |
( |
int |
index | ) |
|
|
override |
135 if (index >= 0 && index <
m_itemList.size()) {
◆ verticalSpacing()
int geometrize::layout::FlowLayout::verticalSpacing |
( |
| ) |
const |
◆ m_hSpace
int geometrize::layout::FlowLayout::m_hSpace |
|
private |
◆ m_itemList
QList<QLayoutItem*> geometrize::layout::FlowLayout::m_itemList |
|
private |
◆ m_vSpace
int geometrize::layout::FlowLayout::m_vSpace |
|
private |
The documentation for this class was generated from the following files:
- /home/appveyor/projects/geometrize-docs/geometrize/geometrize/layout/flowlayout.h
- /home/appveyor/projects/geometrize-docs/geometrize/geometrize/layout/flowlayout.cpp