From 67c9c4ea512fabd3e33522552332c385102c05e5 Mon Sep 17 00:00:00 2001 From: RickyRister Date: Mon, 2 Dec 2024 21:16:10 -0800 Subject: [PATCH] refactor resizing code --- .../src/game/zones/view_zone_widget.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/cockatrice/src/game/zones/view_zone_widget.cpp b/cockatrice/src/game/zones/view_zone_widget.cpp index e8276898b..b723b24a4 100644 --- a/cockatrice/src/game/zones/view_zone_widget.cpp +++ b/cockatrice/src/game/zones/view_zone_widget.cpp @@ -249,16 +249,19 @@ void ZoneViewWidget::resizeToZoneContents() { QRectF zoneRect = zone->getOptimumRect(); qreal totalZoneHeight = zoneRect.height(); - if (zoneRect.height() > 500) - zoneRect.setHeight(500); - QSizeF newSize(qMax(QGraphicsWidget::layout()->effectiveSizeHint(Qt::MinimumSize, QSizeF()).width(), - zoneRect.width() + scrollBar->width() + 10), - zoneRect.height() + extraHeight + 10); - setMaximumSize(newSize); - resize(newSize); + + qreal width = qMax(QGraphicsWidget::layout()->effectiveSizeHint(Qt::MinimumSize, QSizeF()).width(), + zoneRect.width() + scrollBar->width() + 10); + + QSizeF maxSize(width, zoneRect.height() + extraHeight + 10); + setMaximumSize(maxSize); + + qreal initialZoneHeight = qMin(zoneRect.height(), 500.0); + QSizeF initialSize(width, initialZoneHeight + extraHeight + 10); + resize(initialSize); zone->setGeometry(QRectF(0, -scrollBar->value(), zoneContainer->size().width(), totalZoneHeight)); - scrollBar->setMaximum(totalZoneHeight - zoneRect.height()); + scrollBar->setMaximum(totalZoneHeight - initialZoneHeight); if (layout()) layout()->invalidate();