diff --git a/cockatrice/src/game/zones/view_zone_widget.cpp b/cockatrice/src/game/zones/view_zone_widget.cpp index 83bea2be2..7dd21b9d5 100644 --- a/cockatrice/src/game/zones/view_zone_widget.cpp +++ b/cockatrice/src/game/zones/view_zone_widget.cpp @@ -347,29 +347,38 @@ void ZoneViewWidget::initStyleOption(QStyleOption *option) const titleBar->icon = QPixmap("theme:cockatrice"); } +/** + * Expands/shrinks the window, depending on the current height as well as the configured initial and expanded max + * heights. + */ +void ZoneViewWidget::expandWindow() +{ + qreal maxInitialHeight = calcMaxInitialHeight(); + qreal maxExpandedHeight = rowsToHeight(SettingsCache::instance().getCardViewExpandedRowsMax()); + qreal height = rect().height() - extraHeight - 10; + qreal maxHeight = maximumHeight() - extraHeight - 10; + + // reset window to initial max height if... + bool doResetSize = + // current height is less than that + (height < maxInitialHeight) || + // current height is at expanded max height + (height == maxExpandedHeight) || + // current height is at actual max height, and actual max height is less than expanded max height + (height == maxHeight && height > maxInitialHeight && height < maxExpandedHeight); + + if (doResetSize) { + resizeToZoneContents(true); + } else { + // expand/shrink window to expanded max height if current height is anywhere at or between initial max height + // and actual max height + resize(maximumSize().boundedTo({maximumWidth(), maxExpandedHeight + extraHeight + 10})); + } +} + void ZoneViewWidget::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) { if (event->pos().y() <= 0) { - qreal maxInitialHeight = calcMaxInitialHeight(); - qreal maxExpandedHeight = rowsToHeight(SettingsCache::instance().getCardViewExpandedRowsMax()); - qreal height = rect().height() - extraHeight - 10; - qreal maxHeight = maximumHeight() - extraHeight - 10; - - // reset window to initial max height if... - bool doResetSize = - // current height is less than that - (height < maxInitialHeight) || - // current height is at expanded max height - (height == maxExpandedHeight) || - // current height is at actual max height, and actual max height is less than expanded max height - (height == maxHeight && height > maxInitialHeight && height < maxExpandedHeight); - - if (doResetSize) { - resizeToZoneContents(true); - } else { - // expand/shrink window to expanded max height if current height is anywhere at or between initial max - // height and actual max height - resize(maximumSize().boundedTo({maximumWidth(), maxExpandedHeight + extraHeight + 10})); - } + expandWindow(); } } \ 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 41c59d5e8..177bcb92a 100644 --- a/cockatrice/src/game/zones/view_zone_widget.h +++ b/cockatrice/src/game/zones/view_zone_widget.h @@ -68,6 +68,7 @@ private slots: void zoneDeleted(); void moveEvent(QGraphicsSceneMoveEvent * /* event */) override; void resizeEvent(QGraphicsSceneResizeEvent * /* event */) override; + void expandWindow(); public: ZoneViewWidget(Player *_player,