Dismiss modal by clicking on the overlay

This commit is contained in:
Konstantinos Sideris 2018-01-11 18:10:18 +02:00
parent 9521efab7e
commit 8beef5e61f
2 changed files with 12 additions and 0 deletions

View File

@ -19,6 +19,7 @@
#include <QGraphicsOpacityEffect>
#include <QKeyEvent>
#include <QMouseEvent>
#include <QPaintEvent>
#include <QPropertyAnimation>
@ -39,8 +40,11 @@ public:
protected:
void paintEvent(QPaintEvent *event) override;
void keyPressEvent(QKeyEvent *event) override;
void mousePressEvent(QMouseEvent *event) override;
private:
QWidget *content_;
int duration_;
QColor color_;

View File

@ -22,6 +22,7 @@
OverlayModal::OverlayModal(QWidget *parent, QWidget *content)
: OverlayWidget(parent)
, content_{content}
, duration_{500}
, color_{QColor(55, 55, 55)}
{
@ -60,6 +61,13 @@ OverlayModal::paintEvent(QPaintEvent *event)
painter.fillRect(rect(), color_);
}
void
OverlayModal::mousePressEvent(QMouseEvent *e)
{
if (content_ && !content_->geometry().contains(e->pos()))
fadeOut();
}
void
OverlayModal::fadeIn()
{