From aaafa72c0e28d54ae6dd1c4d1a74d1d829e46338 Mon Sep 17 00:00:00 2001 From: BruebachL <44814898+BruebachL@users.noreply.github.com> Date: Fri, 9 Oct 2026 06:08:15 +0200 Subject: [PATCH] [Game] Use native title bar height for ZoneViewWidget close button (#7450) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [Game] Use native title bar height for ZoneViewWidget close button Compute title bar height from style (PM_TitleBarHeight) instead of hardcoded 24.0 to align hit box with native close button. * [Game] Fix ZoneViewWidget title bar height compile errors Drop the redundant static on the anonymous namespace helper, stop redeclaring titleBarHeight's parameter and reuse tbh in the fallback path, and restore the position clamp that still referenced the removed kTitleBarHeight constant. --------- Co-authored-by: Lukas BrĂ¼bach --- .../game_graphics/zones/view_zone_widget.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/cockatrice/src/game_graphics/zones/view_zone_widget.cpp b/cockatrice/src/game_graphics/zones/view_zone_widget.cpp index b4f73d348..49d9955e0 100644 --- a/cockatrice/src/game_graphics/zones/view_zone_widget.cpp +++ b/cockatrice/src/game_graphics/zones/view_zone_widget.cpp @@ -51,7 +51,13 @@ namespace { -constexpr qreal kTitleBarHeight = 24.0; +qreal titleBarHeight(QWidget *styleWidget) +{ + if (styleWidget) { + return static_cast(styleWidget->style()->pixelMetric(QStyle::PM_TitleBarHeight, nullptr, styleWidget)); + } + return 24.0; +} constexpr qreal kMinVisibleWidth = 100.0; } // namespace @@ -315,7 +321,8 @@ QRectF ZoneViewWidget::closeButtonRect(QWidget *styleWidget) const // query the style for the close button position (handles macOS top-left placement) // Title bar rect MUST be local (0,0-based) for QStyle - const QRect titleBarRect(0, 0, static_cast(frameRectF.width()), static_cast(kTitleBarHeight)); + const qreal tbh = titleBarHeight(styleWidget); + const QRect titleBarRect(0, 0, static_cast(frameRectF.width()), static_cast(tbh)); if (styleWidget) { QStyleOptionTitleBar opt; @@ -344,7 +351,7 @@ QRectF ZoneViewWidget::closeButtonRect(QWidget *styleWidget) const } // Fallback: frame-relative top-right - return QRectF(frameRectF.right() - kTitleBarHeight, frameRectF.top(), kTitleBarHeight, kTitleBarHeight); + return QRectF(frameRectF.right() - tbh, frameRectF.top(), tbh, tbh); } QGraphicsView *ZoneViewWidget::findDragView(QWidget *eventWidget) const @@ -468,8 +475,9 @@ QVariant ZoneViewWidget::itemChange(GraphicsItemChange change, const QVariant &v const qreal minX = sceneRect.left(); const qreal maxX = qMax(minX, sceneRect.right() - kMinVisibleWidth); - const qreal minY = sceneRect.top() + kTitleBarHeight; - const qreal maxY = qMax(minY, sceneRect.bottom() - kTitleBarHeight); + const qreal tbh = titleBarHeight(nullptr); + const qreal minY = sceneRect.top() + tbh; + const qreal maxY = qMax(minY, sceneRect.bottom() - tbh); desiredPos.setX(qBound(minX, desiredPos.x(), maxX)); desiredPos.setY(qBound(minY, desiredPos.y(), maxY));