dim the game behind dialogs and escape menu
This commit is contained in:
46
src/ui/ModalDimOverlay.cpp
Normal file
46
src/ui/ModalDimOverlay.cpp
Normal 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);
|
||||
}
|
||||
Reference in New Issue
Block a user