dim the game behind dialogs and escape menu

This commit is contained in:
2026-07-13 22:11:21 +02:00
parent 6a8b6acd3b
commit 4b149d97a7
9 changed files with 130 additions and 0 deletions

View File

@@ -0,0 +1,46 @@
#include "ModalDimOverlay.h"
#include <QPainter>
ModalDimOverlay::ModalDimOverlay(const QColor& dimColor, QWidget* parent)
: QWidget(parent)
, m_dimColor(dimColor)
{
setAttribute(Qt::WA_TransparentForMouseEvents, true);
hide();
}
void ModalDimOverlay::pushModal()
{
if (m_modalDepth++ == 0)
{
raise();
show();
// Force an immediate synchronous paint so the scrim is visible before the
// caller enters a blocking dialog exec() (no undimmed frame flashes through).
repaint();
}
}
void ModalDimOverlay::popModal()
{
if (m_modalDepth > 0 && --m_modalDepth == 0)
{
hide();
}
}
void ModalDimOverlay::setDimColor(const QColor& dimColor)
{
m_dimColor = dimColor;
if (isVisible())
{
update();
}
}
void ModalDimOverlay::paintEvent(QPaintEvent* /*event*/)
{
QPainter painter(this);
painter.fillRect(rect(), m_dimColor);
}