Skip to content

Commit

Permalink
generic: info button with options
Browse files Browse the repository at this point in the history
Signed-off-by: IonutMuthi <[email protected]>
  • Loading branch information
IonutMuthi committed Nov 21, 2024
1 parent 4a9267c commit 1adc020
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 2 deletions.
17 changes: 16 additions & 1 deletion gui/include/gui/widgets/toolbuttons.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@

#include <QPushButton>

#include <QBoxLayout>
#include <menu_anim.hpp>
#include <popupwidget.h>
#include <scopy-gui_export.h>
#include <utils.h>

Expand Down Expand Up @@ -63,7 +65,20 @@ class SCOPY_GUI_EXPORT InfoBtn : public QPushButton
{
Q_OBJECT
public:
InfoBtn(QWidget *parent = nullptr);
InfoBtn(QWidget *parent = nullptr, bool hasTutorial = false);

bool hasTutorial();
void setHasTutorial(bool hasTutorial);
QPushButton *getTutorialButton();
QPushButton *getDocumentationButton();

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

private:
QVBoxLayout *infoHoverWidgetLayout;
};

class SCOPY_GUI_EXPORT RunBtn : public QPushButton
Expand Down
46 changes: 45 additions & 1 deletion gui/src/widgets/toolbuttons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,11 @@ GearBtn::GearBtn(QWidget *parent)
Style::setStyle(this, style::properties::button::squareIconButton);
}

InfoBtn::InfoBtn(QWidget *parent)
InfoBtn::InfoBtn(QWidget *parent, bool hasTutorial)
: QPushButton(parent)
, m_hasTutorial(hasTutorial)
{

QString iconPath = ":/gui/icons/" + Style::getAttribute(json::theme::icon_theme_folder) + "/icons/info.svg";
setIcon(Style::getPixmap(iconPath, Style::getColor(json::theme::content_default)));

Expand All @@ -100,6 +102,48 @@ InfoBtn::InfoBtn(QWidget *parent)

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

if(hasTutorial) {
m_popupWidget = new PopupWidget(parent);
m_popupWidget->setVisible(false);
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->setVisible(false); });

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

connect(this, &QPushButton::clicked, this, &InfoBtn::showInfoPopup);
}
}

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

void InfoBtn::setHasTutorial(bool hasTutorial) { m_hasTutorial = hasTutorial; }

void InfoBtn::showInfoPopup() { m_popupWidget->setVisible(true); }

QPushButton *InfoBtn::getTutorialButton()
{
if(hasTutorial()) {
return m_popupWidget->getExitBtn();
}

return nullptr;
}

QPushButton *InfoBtn::getDocumentationButton()
{
if(hasTutorial()) {
return m_popupWidget->getContinueBtn();
}
return nullptr;
}

RunBtn::RunBtn(QWidget *parent)
Expand Down

0 comments on commit 1adc020

Please sign in to comment.