From 0dfb88ba99a5cc21a5bf402bfc2b0f6dc6fce586 Mon Sep 17 00:00:00 2001 From: RickyRister Date: Mon, 16 Dec 2024 23:41:08 -0800 Subject: [PATCH] implement feature --- cockatrice/src/game/zones/view_zone_widget.cpp | 17 +++++++++++++++-- cockatrice/src/game/zones/view_zone_widget.h | 3 ++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/cockatrice/src/game/zones/view_zone_widget.cpp b/cockatrice/src/game/zones/view_zone_widget.cpp index 531ca06df..4a7d92417 100644 --- a/cockatrice/src/game/zones/view_zone_widget.cpp +++ b/cockatrice/src/game/zones/view_zone_widget.cpp @@ -282,7 +282,7 @@ static qreal determineNewZoneHeight(qreal oldZoneHeight) return calcMaxInitialHeight(); } -void ZoneViewWidget::resizeToZoneContents() +void ZoneViewWidget::resizeToZoneContents(bool forceInitialHeight) { QRectF zoneRect = zone->getOptimumRect(); qreal totalZoneHeight = zoneRect.height(); @@ -293,7 +293,7 @@ void ZoneViewWidget::resizeToZoneContents() QSizeF maxSize(width, zoneRect.height() + extraHeight + 10); qreal currentZoneHeight = rect().height() - extraHeight - 10; - qreal newZoneHeight = determineNewZoneHeight(currentZoneHeight); + qreal newZoneHeight = forceInitialHeight ? calcMaxInitialHeight() : determineNewZoneHeight(currentZoneHeight); QSizeF initialSize(width, newZoneHeight + extraHeight + 10); @@ -335,3 +335,16 @@ void ZoneViewWidget::initStyleOption(QStyleOption *option) const if (titleBar) titleBar->icon = QPixmap("theme:cockatrice"); } + +void ZoneViewWidget::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) +{ + if (event->pos().y() <= 0) { + // expand window to full height and width if not currently at full height and width + // otherwise shrink window to initial max height + if (size().height() < maximumHeight() || size().width() < maximumWidth()) { + resize(maximumSize()); + } else { + resizeToZoneContents(true); + } + } +} \ No newline at end of file diff --git a/cockatrice/src/game/zones/view_zone_widget.h b/cockatrice/src/game/zones/view_zone_widget.h index af86fe624..41c59d5e8 100644 --- a/cockatrice/src/game/zones/view_zone_widget.h +++ b/cockatrice/src/game/zones/view_zone_widget.h @@ -63,7 +63,7 @@ private slots: void processGroupBy(int value); void processSortBy(int value); void processSetPileView(QT_STATE_CHANGED_T value); - void resizeToZoneContents(); + void resizeToZoneContents(bool forceInitialHeight = false); void handleScrollBarChange(int value); void zoneDeleted(); void moveEvent(QGraphicsSceneMoveEvent * /* event */) override; @@ -90,6 +90,7 @@ public: protected: void closeEvent(QCloseEvent *event) override; void initStyleOption(QStyleOption *option) const override; + void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) override; }; #endif