Cockatrice 2025-11-30-Development-2.11.0-beta.38
A cross-platform virtual tabletop for multiplayer card games
Loading...
Searching...
No Matches
OverlapLayout Class Reference

Custom layout class to arrange widgets with overlapping positions. More...

#include <overlap_layout.h>

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

Public Member Functions

 OverlapLayout (QWidget *parent=nullptr, int overlapPercentage=10, int maxColumns=2, int maxRows=2, Qt::Orientation overlapDirection=Qt::Vertical, Qt::Orientation flowDirection=Qt::Horizontal)
 Constructs an OverlapLayout with the specified parameters.
 ~OverlapLayout ()
 Destructor for OverlapLayout, ensuring cleanup of all layout items.
void insertWidgetAtIndex (QWidget *toInsert, int index)
void addItem (QLayoutItem *item) override
 Adds a new item to the layout.
int count () const override
 Retrieves the total count of items within the layout.
QLayoutItem * itemAt (int index) const override
 Provides access to a layout item at a specified index.
QLayoutItem * takeAt (int index) override
 Removes and returns a layout item at the specified index.
void setGeometry (const QRect &rect) override
 Sets the geometry for the layout items, arranging them with the specified overlap.
QSize minimumSize () const override
 Provides the minimum size hint for the layout, ensuring functionality within constraints.
QSize sizeHint () const override
 Returns the size hint for the layout, based on preferred size calculations.
void setMaxColumns (int _maxColumns)
 Sets the maximum number of columns for horizontal orientation.
void setMaxRows (int _maxRows)
 Sets the maximum number of rows for vertical orientation.
int calculateMaxColumns () const
 Calculates the maximum number of columns for a vertical overlap layout based on the current width.
int calculateRowsForColumns (int columns) const
 Calculates the maximum number of rows needed for a given number of columns in a vertical overlap layout.
int calculateMaxRows () const
 Calculates the maximum number of rows for a horizontal overlap layout based on the current height.
int calculateColumnsForRows (int rows) const
 Calculates the maximum number of columns needed for a given number of rows in a horizontal overlap layout.
void setDirection (Qt::Orientation _direction)
 Sets the layout's orientation direction.

Private Member Functions

QSize calculatePreferredSize () const
 Calculates the preferred size for the layout, considering overlap and orientation.

Private Attributes

QList< QLayoutItem * > itemList
int overlapPercentage
int maxColumns
int maxRows
Qt::Orientation overlapDirection
Qt::Orientation flowDirection

Detailed Description

Custom layout class to arrange widgets with overlapping positions.

The OverlapLayout class is a QLayout subclass that arranges child widgets in an overlapping configuration, allowing control over the overlap percentage and the number of rows or columns based on the chosen layout direction. This layout is particularly useful for visualizing elements that need to partially stack over one another, either horizontally or vertically.

Constructor & Destructor Documentation

◆ OverlapLayout()

OverlapLayout::OverlapLayout ( QWidget * parent = nullptr,
int overlapPercentage = 10,
int maxColumns = 2,
int maxRows = 2,
Qt::Orientation overlapDirection = Qt::Vertical,
Qt::Orientation flowDirection = Qt::Horizontal )

Constructs an OverlapLayout with the specified parameters.

Initializes a new OverlapLayout with the given overlap percentage, row or column limit, and layout direction. The overlap percentage determines how much each widget will overlap with the previous one. If maxColumns or maxRows are set to zero, it implies no limit in that respective dimension.

Parameters
overlapPercentageAn integer representing the percentage of overlap between items (0-100).
maxColumnsThe maximum number of columns allowed in the layout when in horizontal orientation (0 for unlimited).
maxRowsThe maximum number of rows allowed in the layout when in vertical orientation (0 for unlimited).
directionThe orientation direction of the layout, either Qt::Horizontal or Qt::Vertical.
parentThe parent widget of this layout.

◆ ~OverlapLayout()

OverlapLayout::~OverlapLayout ( )

Destructor for OverlapLayout, ensuring cleanup of all layout items.

Iterates through all layout items and deletes them. This prevents memory leaks by removing all child QLayoutItems stored in the layout.

Here is the call graph for this function:

Member Function Documentation

◆ addItem()

void OverlapLayout::addItem ( QLayoutItem * item)
override

Adds a new item to the layout.

Appends a QLayoutItem to the internal list, allowing it to be positioned within the layout during the next geometry update. This method does not directly arrange the items; it merely adds them to the layout’s tracking.

Parameters
itemPointer to the QLayoutItem being added to this layout.

◆ calculateColumnsForRows()

int OverlapLayout::calculateColumnsForRows ( int rows) const
nodiscard

Calculates the maximum number of columns needed for a given number of rows in a horizontal overlap layout.

Determines how many columns are required to arrange all items given the calculated or specified number of rows.

Parameters
rowsThe number of rows available.
Returns
The total number of columns required.

◆ calculateMaxColumns()

int OverlapLayout::calculateMaxColumns ( ) const
nodiscard

Calculates the maximum number of columns for a vertical overlap layout based on the current width.

This function determines the maximum number of columns that can fit within the layout's width given the overlap percentage and item size, based on the current layout direction.

Returns
Maximum number of columns that can fit within the layout width.

◆ calculateMaxRows()

int OverlapLayout::calculateMaxRows ( ) const
nodiscard

Calculates the maximum number of rows for a horizontal overlap layout based on the current height.

This function determines the maximum number of rows that can fit within the layout's height given the overlap percentage and item size, based on the current layout direction.

Returns
Maximum number of rows that can fit within the layout height.

◆ calculatePreferredSize()

QSize OverlapLayout::calculatePreferredSize ( ) const
nodiscardprivate

Calculates the preferred size for the layout, considering overlap and orientation.

Returns
The preferred layout size as a QSize object.
Here is the caller graph for this function:

◆ calculateRowsForColumns()

int OverlapLayout::calculateRowsForColumns ( int columns) const
nodiscard

Calculates the maximum number of rows needed for a given number of columns in a vertical overlap layout.

Determines how many rows are required to arrange all items given the calculated or specified number of columns.

Parameters
columnsThe number of columns available.
Returns
The total number of rows required.

◆ count()

int OverlapLayout::count ( ) const
nodiscardoverride

Retrieves the total count of items within the layout.

Returns the number of items stored in the layout's internal item list. This count reflects how many widgets or spacers the layout is currently managing.

Returns
Integer count of items in the layout.

◆ insertWidgetAtIndex()

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

◆ itemAt()

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

Provides access to a layout item at a specified index.

Allows retrieval of a QLayoutItem from the layout’s internal list by index. If the index is out of bounds, this function will return nullptr.

Parameters
indexThe index of the desired item.
Returns
Pointer to the QLayoutItem at the specified index, or nullptr if index is invalid.

◆ minimumSize()

QSize OverlapLayout::minimumSize ( ) const
nodiscardoverride

Provides the minimum size hint for the layout, ensuring functionality within constraints.

Defines a minimum workable size for the layout to prevent excessive compression that could distort item arrangement.

Returns
The minimum QSize for this layout.
Here is the call graph for this function:

◆ setDirection()

void OverlapLayout::setDirection ( Qt::Orientation _direction)

Sets the layout's orientation direction.

Parameters
_directionThe new orientation direction (Qt::Horizontal or Qt::Vertical).

◆ setGeometry()

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

Sets the geometry for the layout items, arranging them with the specified overlap.

Parameters
rectThe rectangle defining the area within which the layout should arrange items.

◆ setMaxColumns()

void OverlapLayout::setMaxColumns ( int _maxColumns)

Sets the maximum number of columns for horizontal orientation.

Parameters
_maxColumnsNew maximum column count.

◆ setMaxRows()

void OverlapLayout::setMaxRows ( int _maxRows)

Sets the maximum number of rows for vertical orientation.

Parameters
_maxRowsNew maximum row count.

◆ sizeHint()

QSize OverlapLayout::sizeHint ( ) const
nodiscardoverride

Returns the size hint for the layout, based on preferred size calculations.

Provides a recommended size for the layout, useful for layouts that need to fit within a specific parent container size. This takes into account the preferred size and any specific item size requirements.

Returns
The layout's recommended QSize.
Here is the call graph for this function:

◆ takeAt()

QLayoutItem * OverlapLayout::takeAt ( int index)
override

Removes and returns a layout item at the specified index.

Removes a QLayoutItem from the layout at the given index, reducing the layout's count. If the index is invalid, this function returns nullptr without any effect.

Parameters
indexThe index of the item to remove.
Returns
Pointer to the removed QLayoutItem, or nullptr if index is invalid.
Here is the caller graph for this function:

Member Data Documentation

◆ flowDirection

Qt::Orientation OverlapLayout::flowDirection
private

◆ itemList

QList<QLayoutItem *> OverlapLayout::itemList
private

◆ maxColumns

int OverlapLayout::maxColumns
private

◆ maxRows

int OverlapLayout::maxRows
private

◆ overlapDirection

Qt::Orientation OverlapLayout::overlapDirection
private

◆ overlapPercentage

int OverlapLayout::overlapPercentage
private

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