BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
DetailedMessageBox.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/View/Info/DetailedMessageBox.cpp
6 //! @brief Implements class DetailedMessageBox
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 <QLabel>
18 #include <QMessageBox>
19 #include <QPushButton>
20 #include <QStyle>
21 #include <QTextEdit>
22 #include <QVBoxLayout>
23 
24 namespace {
25 
26 const QSize default_dialog_size(512, 300);
27 }
28 
29 DetailedMessageBox::DetailedMessageBox(QWidget* parent, const QString& title, const QString& text,
30  const QString& details)
31  : QDialog(parent)
32  , m_topLabel(new QLabel)
33  , m_textEdit(new QTextEdit)
34 {
35  setWindowTitle(title);
36  m_topLabel->setText(text);
37  m_textEdit->setText(details);
38  m_textEdit->setReadOnly(true);
39  m_textEdit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
40  setWindowFlags(Qt::Dialog);
41 
42  resize(default_dialog_size);
43  setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
44 
45  QColor bgColor(240, 240, 240, 255);
46  QPalette palette;
47  palette.setColor(QPalette::Window, bgColor);
48  setAutoFillBackground(true);
49  setPalette(palette);
50 
51  auto* topLayout = new QHBoxLayout;
52  topLayout->addLayout(createLogoLayout());
53  topLayout->addLayout(createInfoLayout());
54  topLayout->addStretch(1);
55 
56  auto* mainLayout = new QVBoxLayout;
57  mainLayout->addLayout(topLayout);
58  mainLayout->addWidget(m_textEdit);
59  mainLayout->addLayout(createButtonLayout());
60 
61  setLayout(mainLayout);
62 
63  setSizeGripEnabled(true);
64 }
65 
66 void DetailedMessageBox::setText(const QString& text)
67 {
68  m_topLabel->setText(text);
69 }
70 
71 void DetailedMessageBox::setDetailedText(const QString& text)
72 {
73  m_textEdit->setText(text);
74 }
75 
76 //! Returns layout with icon for left part of the widget.
77 
79 {
80  auto* result = new QVBoxLayout;
81 
82  QIcon icon = QApplication::style()->standardIcon(QStyle::SP_MessageBoxWarning);
83 
84  auto* label = new QLabel;
85  label->setPixmap(icon.pixmap(128));
86 
87  result->addWidget(label);
88  result->setContentsMargins(5, 5, 5, 5);
89 
90  return result;
91 }
92 
93 //! Creates right layout with text and QComboBox selection.
94 
96 {
97  m_topLabel->setWordWrap(true);
98 
99  auto* result = new QVBoxLayout;
100  result->addWidget(m_topLabel);
101  result->setContentsMargins(5, 5, 5, 5);
102  return result;
103 }
104 
105 //! Creates button layout with buttons.
106 
108 {
109  auto* result = new QHBoxLayout;
110 
111  auto* okButton = new QPushButton("Ok");
112  connect(okButton, &QPushButton::clicked, this, &DetailedMessageBox::reject);
113 
114  result->addStretch(1);
115  result->addWidget(okButton);
116 
117  return result;
118 }
Defines class DetailedMessageBox.
void setText(const QString &text)
void setDetailedText(const QString &text)
DetailedMessageBox(QWidget *parent, const QString &title, const QString &text, const QString &details)
QBoxLayout * createButtonLayout()
Creates button layout with buttons.
QBoxLayout * createInfoLayout()
Creates right layout with text and QComboBox selection.
QBoxLayout * createLogoLayout()
Returns layout with icon for left part of the widget.