diff --git a/core/src/licenseoverlay.cpp b/core/src/licenseoverlay.cpp index 9edbadfe39..184f78bd22 100644 --- a/core/src/licenseoverlay.cpp +++ b/core/src/licenseoverlay.cpp @@ -37,6 +37,7 @@ LicenseOverlay::LicenseOverlay(QWidget *parent) m_popupWidget->enableTitleBar(false); m_popupWidget->enableTintedOverlay(true); m_popupWidget->setDescription(getLicense()); + m_popupWidget->enableCenterOnParent(true); connect(m_popupWidget->getContinueBtn(), &QAbstractButton::clicked, [&]() { Preferences::GetInstance()->set("general_first_run", false); @@ -55,7 +56,6 @@ void LicenseOverlay::showOverlay() { raise(); show(); - m_popupWidget->move(parent->rect().center() - m_popupWidget->rect().center()); } QPushButton *LicenseOverlay::getContinueBtn() { return m_popupWidget->getContinueBtn(); } diff --git a/gui/include/gui/tintedoverlay.h b/gui/include/gui/tintedoverlay.h index 207d3d3893..bdaa65bcfb 100644 --- a/gui/include/gui/tintedoverlay.h +++ b/gui/include/gui/tintedoverlay.h @@ -42,6 +42,7 @@ class SCOPY_GUI_EXPORT TintedOverlay : public QWidget const QList &getHoles() const; void setHoles(const QList &newHoles); void clearHoles(); + bool eventFilter(QObject *watched, QEvent *event) override; protected: void paintEvent(QPaintEvent *ev) override; diff --git a/gui/include/gui/widgets/popupwidget.h b/gui/include/gui/widgets/popupwidget.h index c9f5ce3b5d..6a055a2cc3 100644 --- a/gui/include/gui/widgets/popupwidget.h +++ b/gui/include/gui/widgets/popupwidget.h @@ -46,6 +46,7 @@ class SCOPY_GUI_EXPORT PopupWidget : public QWidget void enableTitleBar(bool enable = true); void enableTintedOverlay(bool enable = true); void setEnableExternalLinks(bool enable = true); + void enableCenterOnParent(bool enable = true); QString getDescription(); void setDescription(const QString &description); @@ -58,6 +59,8 @@ class SCOPY_GUI_EXPORT PopupWidget : public QWidget void enableCloseButton(bool en); + bool eventFilter(QObject *watched, QEvent *event) override; + Q_SIGNALS: void continueButtonClicked(); void exitButtonClicked(); diff --git a/gui/src/tintedoverlay.cpp b/gui/src/tintedoverlay.cpp index 70d1232433..132a81f1de 100644 --- a/gui/src/tintedoverlay.cpp +++ b/gui/src/tintedoverlay.cpp @@ -30,9 +30,10 @@ TintedOverlay::TintedOverlay(QWidget *parent, QColor color) this->parent = parent; holes.clear(); - QRect geo = parent->rect(); - setGeometry(geo); + setGeometry(parent->rect()); setAttribute(Qt::WA_TransparentForMouseEvents, false); + + parent->installEventFilter(this); } TintedOverlay::~TintedOverlay() {} @@ -65,6 +66,15 @@ void TintedOverlay::paintEvent(QPaintEvent *ev) painter.fillRect(rect(), color); } +bool TintedOverlay::eventFilter(QObject *watched, QEvent *event) +{ + if(event->type() == QEvent::Resize) { + setGeometry(parent->rect()); + } + + return QObject::eventFilter(watched, event); +} + void TintedOverlay::mousePressEvent(QMouseEvent *ev) { // prevent clicks from being sent to parents diff --git a/gui/src/widgets/popupwidget.cpp b/gui/src/widgets/popupwidget.cpp index eb4177b07c..39b0442a23 100644 --- a/gui/src/widgets/popupwidget.cpp +++ b/gui/src/widgets/popupwidget.cpp @@ -168,4 +168,23 @@ void PopupWidget::setEnableExternalLinks(bool enable) m_descriptionTextBrowser->setProperty("openExternalLinks", enable); } +bool PopupWidget::eventFilter(QObject *watched, QEvent *event) +{ + if(event->type() == QEvent::Resize) { + move(parentWidget()->rect().center() - rect().center()); + } + + return QObject::eventFilter(watched, event); +} + +void PopupWidget::enableCenterOnParent(bool enable) +{ + if(enable) { + move(parentWidget()->rect().center() - rect().center()); + parentWidget()->installEventFilter(this); + } else { + parentWidget()->removeEventFilter(this); + } +} + #include "moc_popupwidget.cpp" diff --git a/gui/src/widgets/toolbuttons.cpp b/gui/src/widgets/toolbuttons.cpp index 4a13e6cd96..a49e775773 100644 --- a/gui/src/widgets/toolbuttons.cpp +++ b/gui/src/widgets/toolbuttons.cpp @@ -109,7 +109,7 @@ bool InfoBtn::hasTutorial() { return m_hasTutorial; } void InfoBtn::generateInfoPopup(QWidget *parent) { m_popupWidget = new PopupWidget(parent); - m_popupWidget->move(parent->rect().center() - m_popupWidget->rect().center()); + m_popupWidget->enableCenterOnParent(true); m_popupWidget->setTitle("Plugin Information"); m_popupWidget->setDescription( "To learn more about this plugin, check out the tutorial or read the online documentation.");