Cockatrice 2026-06-01-Development-3.1.0-beta.3
A virtual tabletop for multiplayer card games
Loading...
Searching...
No Matches
FlowLayout Class Reference

#include <flow_layout.h>

Inheritance diagram for FlowLayout:
[legend]
Collaboration diagram for FlowLayout:
[legend]

Public Member Functions

 FlowLayout (QWidget *parent=nullptr)
 FlowLayout (QWidget *parent, Qt::Orientation flowDirection, int margin=0, int hSpacing=0, int vSpacing=0)
 ~FlowLayout () override
void insertWidgetAtIndex (QWidget *toInsert, int index)
void addItem (QLayoutItem *item) override
 Adds a new item to the layout.
int count () const override
 Retrieves the count of items in the layout.
QLayoutItem * itemAt (int index) const override
 Returns the layout item at the specified index.
QLayoutItem * takeAt (int index) override
 Removes and returns the item at the specified index.
void setGeometry (const QRect &rect) override
 Places all children within rect.
Qt::Orientations expandingDirections () const override
 Reports which axis the layout can expand along.
bool hasHeightForWidth () const override
 Height-for-width is only meaningful for horizontal (wrapping) flow.
int heightForWidth (int width) const override
 Returns the height required to display all items within width.
QSize sizeHint () const override
QSize minimumSize () const override
void setHorizontalMargin (int margin)
int horizontalSpacing () const
 Gets the horizontal spacing between items.
void setVerticalMargin (int margin)
int verticalSpacing () const
 Gets the vertical spacing between items.
int smartSpacing (QStyle::PixelMetric pm) const
 Calculates smart spacing based on the parent widget style.
virtual int layoutAllRows (int originX, int originY, int availableWidth)
 Places all items into wrapping rows within availableWidth.
virtual void layoutSingleRow (const QVector< QLayoutItem * > &rowItems, int x, int y, int availableWidth)
 Sets the geometry for every item in rowItems, starting at (x, y).
int layoutAllColumns (int originX, int originY, int availableHeight)
 Places all items into wrapping columns within availableHeight.
void layoutSingleColumn (const QVector< QLayoutItem * > &colItems, int x, int y)
 Sets the geometry for every item in colItems, starting at (x, y).

Protected Member Functions

QSize calculateSizeHintHorizontal () const
 Preferred size for horizontal flow: all items in a single row (unconstrained).
QSize calculateMinimumSizeHorizontal () const
 Minimum size for horizontal flow: the largest single item.
QSize calculateSizeHintVertical () const
 Preferred size for vertical flow: all items in a single column (unconstrained).
QSize calculateMinimumSizeVertical () const
 Minimum size for vertical flow: the largest single item.

Protected Attributes

QList< QLayoutItem * > items
Qt::Orientation flowDirection
int horizontalMargin
 Horizontal spacing between items (-1 = use style default).
int verticalMargin
 Vertical spacing between items (-1 = use style default).

Constructor & Destructor Documentation

◆ FlowLayout() [1/2]

FlowLayout::FlowLayout ( QWidget * parent = nullptr)
explicit

◆ FlowLayout() [2/2]

FlowLayout::FlowLayout ( QWidget * parent,
Qt::Orientation flowDirection,
int margin = 0,
int hSpacing = 0,
int vSpacing = 0 )

◆ ~FlowLayout()

FlowLayout::~FlowLayout ( )
override
Here is the call graph for this function:

Member Function Documentation

◆ addItem()

void FlowLayout::addItem ( QLayoutItem * item)
override

Adds a new item to the layout.

Parameters
itemThe layout item to add.

◆ calculateMinimumSizeHorizontal()

QSize FlowLayout::calculateMinimumSizeHorizontal ( ) const
nodiscardprotected

Minimum size for horizontal flow: the largest single item.

This guarantees we can always display at least one item per row.

Here is the caller graph for this function:

◆ calculateMinimumSizeVertical()

QSize FlowLayout::calculateMinimumSizeVertical ( ) const
nodiscardprotected

Minimum size for vertical flow: the largest single item.

Here is the caller graph for this function:

◆ calculateSizeHintHorizontal()

QSize FlowLayout::calculateSizeHintHorizontal ( ) const
nodiscardprotected

Preferred size for horizontal flow: all items in a single row (unconstrained).

The actual displayed height is determined by heightForWidth() once Qt knows the real available width.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ calculateSizeHintVertical()

QSize FlowLayout::calculateSizeHintVertical ( ) const
nodiscardprotected

Preferred size for vertical flow: all items in a single column (unconstrained).

Here is the call graph for this function:
Here is the caller graph for this function:

◆ count()

int FlowLayout::count ( ) const
nodiscardoverride

Retrieves the count of items in the layout.

Returns
The number of layout items.

◆ expandingDirections()

Qt::Orientations FlowLayout::expandingDirections ( ) const
nodiscardoverride

Reports which axis the layout can expand along.

A horizontally-flowing layout expands horizontally (and wraps vertically, but that is governed by heightForWidth, not by this flag). A vertically-flowing layout expands vertically.

◆ hasHeightForWidth()

bool FlowLayout::hasHeightForWidth ( ) const
nodiscardoverride

Height-for-width is only meaningful for horizontal (wrapping) flow.

◆ heightForWidth()

int FlowLayout::heightForWidth ( int width) const
nodiscardoverride

Returns the height required to display all items within width.

Only valid for horizontal flow; returns -1 otherwise so Qt ignores it. Spacing is counted once between adjacent items, never before the first or after the last.

Here is the call graph for this function:

◆ horizontalSpacing()

int FlowLayout::horizontalSpacing ( ) const
nodiscard

Gets the horizontal spacing between items.

Returns
The horizontal spacing if set, otherwise a smart default.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ insertWidgetAtIndex()

void FlowLayout::insertWidgetAtIndex ( QWidget * toInsert,
int index )

◆ itemAt()

QLayoutItem * FlowLayout::itemAt ( int index) const
nodiscardoverride

Returns the layout item at the specified index.

Parameters
indexThe index of the item to retrieve.
Returns
A pointer to the item at the specified index, or nullptr if out of range.

◆ layoutAllColumns()

int FlowLayout::layoutAllColumns ( int originX,
int originY,
int availableHeight )

Places all items into wrapping columns within availableHeight.

Returns
The x-coordinate of the right edge of the last column.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ layoutAllRows()

int FlowLayout::layoutAllRows ( int originX,
int originY,
int availableWidth )
virtual

Places all items into wrapping rows within availableWidth.

Returns
The y-coordinate of the bottom edge of the last row.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ layoutSingleColumn()

void FlowLayout::layoutSingleColumn ( const QVector< QLayoutItem * > & colItems,
int x,
int y )

Sets the geometry for every item in colItems, starting at (x, y).

Each item is placed at its sizeHint, clamped to its maximumSize.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ layoutSingleRow()

void FlowLayout::layoutSingleRow ( const QVector< QLayoutItem * > & rowItems,
int x,
int y,
int availableWidth )
virtual

Sets the geometry for every item in rowItems, starting at (x, y).

Items whose horizontal size policy includes the Expand or MinimumExpanding flag share the leftover row width proportionally (like QHBoxLayout stretch), so that e.g. a QLineEdit can fill remaining space while fixed-size buttons stay compact.

Items without an expanding policy are placed at their sizeHint, clamped to maximumSize.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ minimumSize()

QSize FlowLayout::minimumSize ( ) const
nodiscardoverride
Here is the call graph for this function:

◆ setGeometry()

void FlowLayout::setGeometry ( const QRect & rect)
override

Places all children within rect.

This is the only method that may move/resize children. It does NOT resize the parent widget; that would break Qt's layout protocol.

Here is the call graph for this function:

◆ setHorizontalMargin()

void FlowLayout::setHorizontalMargin ( int margin)
inline

◆ setVerticalMargin()

void FlowLayout::setVerticalMargin ( int margin)
inline

◆ sizeHint()

QSize FlowLayout::sizeHint ( ) const
nodiscardoverride
Here is the call graph for this function:

◆ smartSpacing()

int FlowLayout::smartSpacing ( QStyle::PixelMetric pm) const
nodiscard

Calculates smart spacing based on the parent widget style.

Parameters
pmThe pixel metric to calculate.
Returns
The calculated spacing value.
Here is the caller graph for this function:

◆ takeAt()

QLayoutItem * FlowLayout::takeAt ( int index)
override

Removes and returns the item at the specified index.

Parameters
indexThe index of the item to remove.
Returns
A pointer to the removed item, or nullptr if out of range.
Here is the caller graph for this function:

◆ verticalSpacing()

int FlowLayout::verticalSpacing ( ) const
nodiscard

Gets the vertical spacing between items.

Returns
The vertical spacing if set, otherwise a smart default.
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ flowDirection

Qt::Orientation FlowLayout::flowDirection
protected

◆ horizontalMargin

int FlowLayout::horizontalMargin
protected

Horizontal spacing between items (-1 = use style default).

◆ items

QList<QLayoutItem *> FlowLayout::items
protected

◆ verticalMargin

int FlowLayout::verticalMargin
protected

Vertical spacing between items (-1 = use style default).


The documentation for this class was generated from the following files: