Custom layout class to arrange widgets with overlapping positions.
More...
#include <overlap_layout.h>
|
| | 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.
|
|
| QSize | calculatePreferredSize () const |
| | Calculates the preferred size for the layout, considering overlap and orientation.
|
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.
◆ 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
-
| overlapPercentage | An integer representing the percentage of overlap between items (0-100). |
| maxColumns | The maximum number of columns allowed in the layout when in horizontal orientation (0 for unlimited). |
| maxRows | The maximum number of rows allowed in the layout when in vertical orientation (0 for unlimited). |
| direction | The orientation direction of the layout, either Qt::Horizontal or Qt::Vertical. |
| parent | The 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.
◆ 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
-
| item | Pointer 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
-
| rows | The 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.
◆ 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
-
| columns | The 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
-
| index | The 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.
◆ setDirection()
| void OverlapLayout::setDirection |
( |
Qt::Orientation | _direction | ) |
|
Sets the layout's orientation direction.
- Parameters
-
| _direction | The 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
-
| rect | The 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
-
| _maxColumns | New maximum column count. |
◆ setMaxRows()
| void OverlapLayout::setMaxRows |
( |
int | _maxRows | ) |
|
Sets the maximum number of rows for vertical orientation.
- Parameters
-
| _maxRows | New 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.
◆ 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
-
| index | The index of the item to remove. |
- Returns
- Pointer to the removed QLayoutItem, or nullptr if index is invalid.
◆ 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: