Skip to content

Commit

Permalink
fixup! Introduce showKiwixMessageBox()
Browse files Browse the repository at this point in the history
  • Loading branch information
juuz0 committed Jun 17, 2024
1 parent bc0c97b commit df7c392
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
9 changes: 4 additions & 5 deletions src/kiwixmessagebox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ KiwixMessageBox::KiwixMessageBox(QString confirmTitle, QString confirmText, bool
{
ui->setupUi(this);
setWindowFlag(Qt::FramelessWindowHint, true);
setAttribute(Qt::WA_DeleteOnClose);
setStyleSheet(KiwixApp::instance()->parseStyleFromFile(":/css/messageBox.css"));
connect(ui->yesButton, &QPushButton::clicked, [=]() {
emit yesClicked();
Expand All @@ -24,10 +25,12 @@ KiwixMessageBox::KiwixMessageBox(QString confirmTitle, QString confirmText, bool
connect(ui->okButton, &QPushButton::clicked, [=]() {
emit okClicked();
m_result = OkClicked;
accept();
});
connect(ui->closeButton, &QPushButton::clicked, [=]() {
this->close();
m_result = CloseClicked;
reject();
});
ui->confirmText->setText(confirmText);
ui->confirmTitle->setText(confirmTitle);
Expand All @@ -50,15 +53,11 @@ KiwixMessageBox::~KiwixMessageBox()
void showInfoBox(QString title, QString text, QWidget *parent)
{
KiwixMessageBox *dialog = new KiwixMessageBox(title, text, true, parent);
dialog->show();
QObject::connect(dialog, &KiwixMessageBox::okClicked, [=]() {
dialog->deleteLater();
});
dialog->execDialog();
}

KiwixMessageBox::Result showKiwixMessageBox(QString title, QString text, QWidget *parent, QString leftTitle, QString rightTitle)
{
KiwixMessageBox *dialog = new KiwixMessageBox(title, text, false, parent, leftTitle, rightTitle);
dialog->setAttribute(Qt::WA_DeleteOnClose);
return dialog->execDialog();
}
10 changes: 3 additions & 7 deletions src/kiwixmessagebox.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,10 @@ void showConfirmBox(QString title, QString text, QWidget *parent,
YesAction yesAction)
{
KiwixMessageBox *dialog = new KiwixMessageBox(title, text, false, parent);
dialog->show();
QObject::connect(dialog, &KiwixMessageBox::yesClicked, [=]() {
auto res = dialog->execDialog();
if (res == KiwixMessageBox::Result::YesClicked) {
yesAction();
dialog->deleteLater();
});
QObject::connect(dialog, &KiwixMessageBox::noClicked, [=]() {
dialog->deleteLater();
});
}
}

#endif // KIWIXMESSAGEBOX_H

0 comments on commit df7c392

Please sign in to comment.