From 8beef5e61f6210714a0247b334da3426c6724ec3 Mon Sep 17 00:00:00 2001 From: Konstantinos Sideris Date: Thu, 11 Jan 2018 18:10:18 +0200 Subject: [PATCH] Dismiss modal by clicking on the overlay --- include/ui/OverlayModal.h | 4 ++++ src/ui/OverlayModal.cc | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/include/ui/OverlayModal.h b/include/ui/OverlayModal.h index 5f6b6ee..2ac5eb6 100644 --- a/include/ui/OverlayModal.h +++ b/include/ui/OverlayModal.h @@ -19,6 +19,7 @@ #include #include +#include #include #include @@ -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_; diff --git a/src/ui/OverlayModal.cc b/src/ui/OverlayModal.cc index 290d28e..62d31f2 100644 --- a/src/ui/OverlayModal.cc +++ b/src/ui/OverlayModal.cc @@ -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() {