mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-11 08:34:52 -07:00
[View Zone Widget] Properly calculate titleBar close rect on Windows. (#6468)
This commit is contained in:
parent
987fe9c9e2
commit
e7a1f86cbb
2 changed files with 15 additions and 7 deletions
|
|
@ -272,10 +272,11 @@ void ZoneViewWidget::startWindowDrag(QGraphicsSceneMouseEvent *event)
|
||||||
QRectF ZoneViewWidget::closeButtonRect(QWidget *styleWidget) const
|
QRectF ZoneViewWidget::closeButtonRect(QWidget *styleWidget) const
|
||||||
{
|
{
|
||||||
const QRectF frameRectF = windowFrameRect();
|
const QRectF frameRectF = windowFrameRect();
|
||||||
const QRect titleBarRect(frameRectF.toRect().x(), frameRectF.toRect().y(), frameRectF.toRect().width(),
|
|
||||||
static_cast<int>(kTitleBarHeight));
|
|
||||||
|
|
||||||
// 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
|
||||||
|
const QRect titleBarRect(0, 0, static_cast<int>(frameRectF.width()), static_cast<int>(kTitleBarHeight));
|
||||||
|
|
||||||
if (styleWidget) {
|
if (styleWidget) {
|
||||||
QStyleOptionTitleBar opt;
|
QStyleOptionTitleBar opt;
|
||||||
opt.initFrom(styleWidget);
|
opt.initFrom(styleWidget);
|
||||||
|
|
@ -283,19 +284,26 @@ QRectF ZoneViewWidget::closeButtonRect(QWidget *styleWidget) const
|
||||||
opt.text = windowTitle();
|
opt.text = windowTitle();
|
||||||
opt.icon = styleWidget->windowIcon();
|
opt.icon = styleWidget->windowIcon();
|
||||||
opt.titleBarFlags = Qt::Window | Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint;
|
opt.titleBarFlags = Qt::Window | Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint;
|
||||||
|
|
||||||
opt.subControls = QStyle::SC_TitleBarCloseButton;
|
opt.subControls = QStyle::SC_TitleBarCloseButton;
|
||||||
opt.activeSubControls = QStyle::SC_TitleBarCloseButton;
|
opt.activeSubControls = QStyle::SC_TitleBarCloseButton;
|
||||||
opt.titleBarState = styleWidget->isActiveWindow() ? Qt::WindowActive : Qt::WindowNoState;
|
opt.titleBarState = styleWidget->isActiveWindow() ? Qt::WindowActive : Qt::WindowNoState;
|
||||||
if (styleWidget->isActiveWindow())
|
|
||||||
|
if (styleWidget->isActiveWindow()) {
|
||||||
opt.state |= QStyle::State_Active;
|
opt.state |= QStyle::State_Active;
|
||||||
const QRect r = styleWidget->style()->subControlRect(QStyle::CC_TitleBar, &opt, QStyle::SC_TitleBarCloseButton,
|
}
|
||||||
styleWidget);
|
|
||||||
|
QRect r = styleWidget->style()->subControlRect(QStyle::CC_TitleBar, &opt, QStyle::SC_TitleBarCloseButton,
|
||||||
|
styleWidget);
|
||||||
|
|
||||||
if (r.isValid() && !r.isEmpty()) {
|
if (r.isValid() && !r.isEmpty()) {
|
||||||
|
// Translate from local-titlebar coords → frame coords
|
||||||
|
r.translate(frameRectF.topLeft().toPoint());
|
||||||
return QRectF(r);
|
return QRectF(r);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// fallback: square at right end of titlebar (Windows/Linux style)
|
// Fallback: frame-relative top-right
|
||||||
return QRectF(frameRectF.right() - kTitleBarHeight, frameRectF.top(), kTitleBarHeight, kTitleBarHeight);
|
return QRectF(frameRectF.right() - kTitleBarHeight, frameRectF.top(), kTitleBarHeight, kTitleBarHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -349,6 +357,7 @@ bool ZoneViewWidget::windowFrameEvent(QEvent *event)
|
||||||
close();
|
close();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
startWindowDrag(me);
|
startWindowDrag(me);
|
||||||
me->accept();
|
me->accept();
|
||||||
return true;
|
return true;
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,6 @@ private:
|
||||||
ZoneViewZone *zone;
|
ZoneViewZone *zone;
|
||||||
QGraphicsWidget *zoneContainer;
|
QGraphicsWidget *zoneContainer;
|
||||||
|
|
||||||
QPushButton *closeButton;
|
|
||||||
QScrollBar *scrollBar;
|
QScrollBar *scrollBar;
|
||||||
ScrollableGraphicsProxyWidget *scrollBarProxy;
|
ScrollableGraphicsProxyWidget *scrollBarProxy;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue