BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
MessageBox.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/View/Info/MessageBox.cpp
6 //! @brief Implements GUIHelpers functions
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
16 #include <QApplication>
17 #include <QMessageBox>
18 #include <QPushButton>
19 
20 namespace GUI::View::Helpers {
21 
22 void information(QWidget* parent, const QString& title, const QString& text,
23  const QString& detailedText)
24 {
25  QScopedPointer<QMessageBox> messageBox(new QMessageBox(parent));
26  if (parent)
27  messageBox->setWindowModality(Qt::WindowModal);
28  messageBox->setWindowTitle(QString("%1 - %2").arg(QApplication::applicationName()).arg(title));
29  messageBox->setText(text);
30  if (!detailedText.isEmpty())
31  messageBox->setInformativeText(detailedText);
32  messageBox->setIcon(QMessageBox::Information);
33  messageBox->addButton(QMessageBox::Ok);
34  messageBox->exec();
35 }
36 
37 void warning(QWidget* parent, const QString& title, const QString& text,
38  const QString& detailedText)
39 {
40  QScopedPointer<QMessageBox> messageBox(new QMessageBox(parent));
41  if (parent)
42  messageBox->setWindowModality(Qt::WindowModal);
43  messageBox->setWindowTitle(QString("%1 - %2").arg(QApplication::applicationName()).arg(title));
44  messageBox->setText(text);
45  if (!detailedText.isEmpty())
46  messageBox->setInformativeText(detailedText);
47  messageBox->setIcon(QMessageBox::Warning);
48  messageBox->addButton(QMessageBox::Ok);
49  messageBox->exec();
50 }
51 
52 bool question(QWidget* parent, const QString& title, const QString& text,
53  const QString& detailedText, const QString& yesText, const QString& noText)
54 {
55  QScopedPointer<QMessageBox> messageBox(new QMessageBox(parent));
56  if (parent)
57  messageBox->setWindowModality(Qt::WindowModal);
58  messageBox->setWindowTitle(QString("%1 - %2").arg(QApplication::applicationName()).arg(title));
59  messageBox->setText(text);
60  if (!detailedText.isEmpty())
61  messageBox->setInformativeText(detailedText);
62  messageBox->setIcon(QMessageBox::Question);
63  QAbstractButton* yesButton = messageBox->addButton(yesText, QMessageBox::AcceptRole);
64  messageBox->addButton(noText, QMessageBox::RejectRole);
65  messageBox->setDefaultButton(qobject_cast<QPushButton*>(yesButton));
66  messageBox->exec();
67  return messageBox->clickedButton() == yesButton;
68 }
69 
70 bool okToDelete(QWidget* parent, const QString& title, const QString& text,
71  const QString& detailedText)
72 {
73  QScopedPointer<QMessageBox> messageBox(new QMessageBox(parent));
74  if (parent)
75  messageBox->setWindowModality(Qt::WindowModal);
76  messageBox->setIcon(QMessageBox::Question);
77  messageBox->setWindowTitle(QString("%1 - %2").arg(QApplication::applicationName()).arg(title));
78  messageBox->setText(text);
79  if (!detailedText.isEmpty())
80  messageBox->setInformativeText(detailedText);
81  QAbstractButton* deleteButton = messageBox->addButton("&Delete", QMessageBox::AcceptRole);
82  messageBox->addButton("Do &Not Delete", QMessageBox::RejectRole);
83  messageBox->setDefaultButton(qobject_cast<QPushButton*>(deleteButton));
84  messageBox->exec();
85  return messageBox->clickedButton() == deleteButton;
86 }
87 
88 } // namespace GUI::View::Helpers
Defines class GUIHelpers functions.
void information(QWidget *parent, const QString &title, const QString &text, const QString &detailedText)
Definition: MessageBox.cpp:22
bool okToDelete(QWidget *parent, const QString &title, const QString &text, const QString &detailedText)
Definition: MessageBox.cpp:70
void warning(QWidget *parent, const QString &title, const QString &text, const QString &detailedText)
Definition: MessageBox.cpp:37
bool question(QWidget *parent, const QString &title, const QString &text, const QString &detailedText, const QString &yesText, const QString &noText)
Definition: MessageBox.cpp:52