Add Utility Layouts and corresponding Widgets (#5177)

* Add FlowWidget class with flexible layout and scroll handling

- Implemented FlowWidget class to organize widgets in a flow layout with scrollable options.
- Integrated QScrollArea to handle overflow with configurable horizontal and vertical scroll policies.
- Incorporated dynamic layout selection (FlowLayout, HorizontalFlowLayout, VerticalFlowLayout) based on scroll policy.

* Add OverlapWidget and OverlapLayout for managing overlapping child widgets

- Implemented the OverlapWidget class to manage child widgets in an overlapping manner, supporting configurable overlap percentage, maximum columns, maximum rows, and layout direction.
- Introduced the OverlapLayout class, which arranges widgets with overlapping positions, allowing flexible stacking based on specified parameters.

* Add OverlapControlWidget.

* Delete FlowLayout items later to allow them to finish their event loop.

* Allow OverlapWidgets to adjust their rows/columns on resize.

* Clamp vertical FlowLayout to any available parent scrollAreas.

* Implement margins and spacing for FlowLayouts.

* Adjust/revert some things.

* Address pull request comments (nullptr checks and additional comments, mostly.)

* Reformat code so the linter will stop yelling at me.

* Remove undefined methods from FlowLayouts.

* Fix the build.

* Revert FlowLayout::takeAt to index check.

* Commits will continue until linter morale improves.

* Fix various warnings in FlowLayout.

* Fix various warnings in FlowLayout.h.

* Fix various warnings in the FlowLayout classes.

* Fix [[nodiscard]] warning.

* Fix more warnings.

* Final round of yellow squiggle fixing.

* Linter formatting.

* Refactor column/row calculation to be more readable.

* Code style.

* Address PR comments.

* Combine if-statements.

* Replace std::math functions with Qt equivalents.

* Fix non-consts and QtMath.

---------

Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
BruebachL 2024-11-17 19:32:31 +01:00 committed by GitHub
parent c8336df49d
commit 8ef92d26c5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
18 changed files with 1832 additions and 42 deletions

View file

@ -0,0 +1,44 @@
#ifndef OVERLAP_LAYOUT_H
#define OVERLAP_LAYOUT_H
#include <QLayout>
#include <QList>
#include <QWidget>
class OverlapLayout : public QLayout
{
public:
OverlapLayout(QWidget *parent = nullptr,
int overlapPercentage = 10,
int maxColumns = 2,
int maxRows = 2,
Qt::Orientation direction = Qt::Horizontal);
~OverlapLayout();
void addItem(QLayoutItem *item) override;
int count() const override;
QLayoutItem *itemAt(int index) const override;
QLayoutItem *takeAt(int index) override;
void setGeometry(const QRect &rect) override;
QSize minimumSize() const override;
QSize sizeHint() const override;
void setMaxColumns(int _maxColumns);
void setMaxRows(int _maxRows);
int calculateMaxColumns() const;
int calculateRowsForColumns(int columns) const;
int calculateMaxRows() const;
int calculateColumnsForRows(int rows) const;
void setDirection(Qt::Orientation _direction);
private:
QList<QLayoutItem *> itemList;
int overlapPercentage;
int maxColumns;
int maxRows;
Qt::Orientation direction;
// Calculate the preferred size of the layout
QSize calculatePreferredSize() const;
};
#endif // OVERLAP_LAYOUT_H