[QtUtils] Adopt shared Qt helpers across the client (#7618)

* [QtUtils] Add parent lookup, layout clearing, scroll area and monospace helpers

* [QtUtils] Adopt shared Qt helpers across the client

---------

Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
BruebachL 2026-10-24 08:26:21 +02:00 • committed by GitHub
parent 1e0fc35d94
commit ab13a6748f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
25 changed files with 60 additions and 178 deletions

View file

@ -19,6 +19,7 @@
#include <QSize>
#include <QSizePolicy>
#include <QWidget>
#include <libcockatrice/utility/qt_utils.h>
/**
* @brief Constructs a FlowWidget.
@ -55,13 +56,9 @@ FlowWidget::FlowWidget(QWidget *parent,
// Scroll area (optional)
if (useScrollArea) {
scrollArea = new QScrollArea(this);
scrollArea->setWidgetResizable(true);
scrollArea = QtUtils::makeScrollArea(this, verticalPolicy, horizontalPolicy);
scrollArea->setMinimumSize(0, 0);
scrollArea->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
// Set scrollbar policies
scrollArea->setHorizontalScrollBarPolicy(horizontalPolicy);
scrollArea->setVerticalScrollBarPolicy(verticalPolicy);
} else {
scrollArea = nullptr;
}
@ -136,13 +133,7 @@ void FlowWidget::removeWidget(QWidget *widgetToRemove) const
void FlowWidget::clearLayout()
{
if (flowLayout) {
QLayoutItem *item;
while ((item = flowLayout->takeAt(0))) {
if (item->widget()) {
item->widget()->deleteLater();
}
delete item;
}
QtUtils::clearLayoutRec(flowLayout);
} else {
// Defensive fallback: recreate the layout if it was deleted externally.
flowLayout = new FlowLayout(container, flowDirection);

View file

@ -4,6 +4,7 @@
#include <QLayoutItem>
#include <QWidget>
#include <libcockatrice/utility/qt_utils.h>
/**
* @class OverlapWidget
@ -80,11 +81,7 @@ void OverlapWidget::removeWidget(QWidget *widgetToRemove) const
void OverlapWidget::clearLayout()
{
if (overlapLayout != nullptr) {
QLayoutItem *item;
while ((item = overlapLayout->takeAt(0)) != nullptr) {
item->widget()->deleteLater();
delete item;
}
QtUtils::clearLayoutRec(overlapLayout);
}
// If layout is null, create a new layout; otherwise, reuse the existing one