Skip to content

Commit

Permalink
generic: add option to enable close btn for popup windet
Browse files Browse the repository at this point in the history
Signed-off-by: IonutMuthi <[email protected]>
  • Loading branch information
IonutMuthi committed Nov 22, 2024
1 parent 527d4a4 commit 43b6a2c
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 25 deletions.
5 changes: 5 additions & 0 deletions gui/include/gui/widgets/popupwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <QPushButton>
#include <QTextBrowser>
#include <QWidget>
#include <hoverwidget.h>

namespace scopy {
class SCOPY_GUI_EXPORT PopupWidget : public QWidget
Expand Down Expand Up @@ -55,6 +56,8 @@ class SCOPY_GUI_EXPORT PopupWidget : public QWidget
QPushButton *getExitBtn();
QPushButton *getContinueBtn();

void enableCloseButton(bool en);

Q_SIGNALS:
void continueButtonClicked();
void exitButtonClicked();
Expand All @@ -66,6 +69,8 @@ class SCOPY_GUI_EXPORT PopupWidget : public QWidget
QTextBrowser *m_descriptionTextBrowser;
QPushButton *m_exitButton;
QPushButton *m_continueButton;
QPushButton *m_closeButton;
HoverWidget *m_closeHover;
};
} // namespace scopy

Expand Down
2 changes: 1 addition & 1 deletion gui/include/gui/widgets/toolbuttons.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ class SCOPY_GUI_EXPORT InfoBtn : public QPushButton
bool hasTutorial();
QPushButton *getTutorialButton();
QPushButton *getDocumentationButton();
void generateInfoPopup(QWidget *parent);

private:
PopupWidget *m_popupWidget;
bool m_hasTutorial;
void showInfoPopup();
};

class SCOPY_GUI_EXPORT RunBtn : public QPushButton
Expand Down
30 changes: 30 additions & 0 deletions gui/src/widgets/popupwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,36 @@ void PopupWidget::initUI()
Style::setStyle(m_continueButton, style::properties::button::basicButton, true, true);
Style::setStyle(m_exitButton, style::properties::button::basicButton, true, true);
Style::setStyle(this, style::properties::widget::overlayMenu);

m_closeButton = nullptr;
m_closeHover = nullptr;
}

void PopupWidget::enableCloseButton(bool en)
{
if(en) {
m_closeButton = new QPushButton(this);
m_closeButton->setMaximumSize(20, 20);
m_closeButton->setIcon(Style::getPixmap(":/gui/icons/close_hovered.svg",
Style::getColor(json::theme::interactive_subtle_idle)));
Style::setStyle(m_closeButton, style::properties::widget::notInteractive);

m_closeHover = new HoverWidget(m_closeButton, this, this);
m_closeHover->setAnchorPos(HoverPosition::HP_TOPRIGHT);
m_closeHover->setContentPos(HoverPosition::HP_CENTER);
m_closeHover->setAnchorOffset(QPoint(-20, 20));
m_closeHover->setVisible(true);
m_closeHover->raise();

connect(m_closeButton, &QPushButton::clicked, this, [=]() { deleteLater(); });
} else {
if(m_closeButton != nullptr) {
delete m_closeButton;
}
if(m_closeHover != nullptr) {
delete m_closeHover;
}
}
}

void PopupWidget::setFocusOnContinueButton()
Expand Down
38 changes: 14 additions & 24 deletions gui/src/widgets/toolbuttons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,35 +102,25 @@ InfoBtn::InfoBtn(QWidget *parent, bool hasTutorial)

setCheckable(false);
Style::setStyle(this, style::properties::button::squareIconButton);

if(hasTutorial) {
m_popupWidget = new PopupWidget(parent);
m_popupWidget->move(parent->rect().center());
m_popupWidget->setTitle("Plugin Information");
m_popupWidget->setDescription(
"To learn more about this plugin, check out the tutorial or read the online documentation.");
m_popupWidget->getExitBtn()->setText("Tutorial");
m_popupWidget->getContinueBtn()->setText("Documentation");

connect(m_popupWidget->getExitBtn(), &QPushButton::clicked, this, [=]() {
m_popupWidget->hide();
m_popupWidget->enableTintedOverlay(false);
});

connect(m_popupWidget->getContinueBtn(), &QPushButton::clicked, this, [=]() {
m_popupWidget->hide();
m_popupWidget->enableTintedOverlay(false);
});

connect(this, &QPushButton::clicked, this, &InfoBtn::showInfoPopup);
m_popupWidget->hide();
}
}

bool InfoBtn::hasTutorial() { return m_hasTutorial; }

void InfoBtn::showInfoPopup()
void InfoBtn::generateInfoPopup(QWidget *parent)
{
m_popupWidget = new PopupWidget(parent);
m_popupWidget->move(parent->rect().center() - m_popupWidget->rect().center());
m_popupWidget->setTitle("Plugin Information");
m_popupWidget->setDescription(
"To learn more about this plugin, check out the tutorial or read the online documentation.");
m_popupWidget->getExitBtn()->setText("Tutorial");
m_popupWidget->getContinueBtn()->setText("Documentation");
m_popupWidget->enableCloseButton(true);

connect(m_popupWidget->getExitBtn(), &QPushButton::clicked, this, [=]() { m_popupWidget->deleteLater(); });

connect(m_popupWidget->getContinueBtn(), &QPushButton::clicked, this, [=]() { m_popupWidget->deleteLater(); });

m_popupWidget->enableTintedOverlay(true);
m_popupWidget->show();
m_popupWidget->raise();
Expand Down

0 comments on commit 43b6a2c

Please sign in to comment.