BornAgain  1.19.0
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/coregui/Views/InfoWidgets/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 
17 #include <QApplication>
18 #include <QLabel>
19 #include <QMessageBox>
20 #include <QPushButton>
21 #include <QStyle>
22 #include <QTextEdit>
23 #include <QVBoxLayout>
24 
25 namespace {
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), m_topLabel(new QLabel), m_textEdit(new QTextEdit)
32 {
33  setWindowTitle(title);
34  m_topLabel->setText(text);
35  m_textEdit->setText(details);
36  m_textEdit->setReadOnly(true);
37  m_textEdit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
38  setWindowFlags(Qt::Dialog);
39 
40  resize(default_dialog_size);
41  setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
42 
43  QColor bgColor(240, 240, 240, 255);
44  QPalette palette;
45  palette.setColor(QPalette::Window, bgColor);
46  setAutoFillBackground(true);
47  setPalette(palette);
48 
49  auto topLayout = new QHBoxLayout;
50  topLayout->addLayout(createLogoLayout());
51  topLayout->addLayout(createInfoLayout());
52  topLayout->addStretch(1);
53 
54  auto mainLayout = new QVBoxLayout;
55  mainLayout->addLayout(topLayout);
56  mainLayout->addWidget(m_textEdit);
57  mainLayout->addLayout(createButtonLayout());
58 
59  setLayout(mainLayout);
60 
61  setSizeGripEnabled(true);
62 }
63 
64 void DetailedMessageBox::setText(const QString& text)
65 {
66  m_topLabel->setText(text);
67 }
68 
69 void DetailedMessageBox::setDetailedText(const QString& text)
70 {
71  m_textEdit->setText(text);
72 }
73 
74 //! Returns layout with icon for left part of the widget.
75 
77 {
78  auto result = new QVBoxLayout;
79 
80  QIcon icon = QApplication::style()->standardIcon(QStyle::SP_MessageBoxWarning);
81 
82  auto label = new QLabel;
83  label->setPixmap(icon.pixmap(128));
84 
85  result->addWidget(label);
86  result->setContentsMargins(5, 5, 5, 5);
87 
88  return result;
89 }
90 
91 //! Creates right layout with text and QComboBox selection.
92 
94 {
95  m_topLabel->setWordWrap(true);
96 
97  auto result = new QVBoxLayout;
98  result->addWidget(m_topLabel);
99  result->setContentsMargins(5, 5, 5, 5);
100  return result;
101 }
102 
103 //! Creates button layout with buttons.
104 
106 {
107  auto result = new QHBoxLayout;
108 
109  auto okButton = new QPushButton("Ok");
110  connect(okButton, &QPushButton::clicked, this, &DetailedMessageBox::reject);
111 
112  result->addStretch(1);
113  result->addWidget(okButton);
114 
115  return result;
116 }
Defines class DesignerHelper.
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.