Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Popup and overlay update on parent resize #1844

Merged
merged 1 commit into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/src/licenseoverlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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(); }
Expand Down
1 change: 1 addition & 0 deletions gui/include/gui/tintedoverlay.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class SCOPY_GUI_EXPORT TintedOverlay : public QWidget
const QList<QWidget *> &getHoles() const;
void setHoles(const QList<QWidget *> &newHoles);
void clearHoles();
bool eventFilter(QObject *watched, QEvent *event) override;

protected:
void paintEvent(QPaintEvent *ev) override;
Expand Down
3 changes: 3 additions & 0 deletions gui/include/gui/widgets/popupwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();
Expand Down
14 changes: 12 additions & 2 deletions gui/src/tintedoverlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
Expand Down Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions gui/src/widgets/popupwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion gui/src/widgets/toolbuttons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand Down
Loading