mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-05 09:33:25 -08:00
[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:
parent
1e0fc35d94
commit
ab13a6748f
25 changed files with 60 additions and 178 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue