[Game] Use native title bar height for ZoneViewWidget close button (#7450)

* [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 <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
BruebachL 2026-10-09 06:08:15 +02:00 • committed by GitHub
parent 56c456414b
commit aaafa72c0e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -51,7 +51,13 @@
namespace namespace
{ {
constexpr qreal kTitleBarHeight = 24.0; qreal titleBarHeight(QWidget *styleWidget)
{
if (styleWidget) {
return static_cast<qreal>(styleWidget->style()->pixelMetric(QStyle::PM_TitleBarHeight, nullptr, styleWidget));
}
return 24.0;
}
constexpr qreal kMinVisibleWidth = 100.0; constexpr qreal kMinVisibleWidth = 100.0;
} // namespace } // namespace
@ -315,7 +321,8 @@ QRectF ZoneViewWidget::closeButtonRect(QWidget *styleWidget) const
// query the style for the close button position (handles macOS top-left placement) // query the style for the close button position (handles macOS top-left placement)
// Title bar rect MUST be local (0,0-based) for QStyle // Title bar rect MUST be local (0,0-based) for QStyle
const QRect titleBarRect(0, 0, static_cast<int>(frameRectF.width()), static_cast<int>(kTitleBarHeight)); const qreal tbh = titleBarHeight(styleWidget);
const QRect titleBarRect(0, 0, static_cast<int>(frameRectF.width()), static_cast<int>(tbh));
if (styleWidget) { if (styleWidget) {
QStyleOptionTitleBar opt; QStyleOptionTitleBar opt;
@ -344,7 +351,7 @@ QRectF ZoneViewWidget::closeButtonRect(QWidget *styleWidget) const
} }
// Fallback: frame-relative top-right // 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 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 minX = sceneRect.left();
const qreal maxX = qMax(minX, sceneRect.right() - kMinVisibleWidth); const qreal maxX = qMax(minX, sceneRect.right() - kMinVisibleWidth);
const qreal minY = sceneRect.top() + kTitleBarHeight; const qreal tbh = titleBarHeight(nullptr);
const qreal maxY = qMax(minY, sceneRect.bottom() - kTitleBarHeight); const qreal minY = sceneRect.top() + tbh;
const qreal maxY = qMax(minY, sceneRect.bottom() - tbh);
desiredPos.setX(qBound(minX, desiredPos.x(), maxX)); desiredPos.setX(qBound(minX, desiredPos.x(), maxX));
desiredPos.setY(qBound(minY, desiredPos.y(), maxY)); desiredPos.setY(qBound(minY, desiredPos.y(), maxY));