BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
ComboSelectorDialog.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/View/Info/ComboSelectorDialog.cpp
6 //! @brief Implements class ComboSelectorDialog
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> // qApp
17 #include <QComboBox>
18 #include <QLabel>
19 #include <QMessageBox>
20 #include <QPushButton>
21 #include <QVBoxLayout>
22 
24  : QDialog(parent)
25  , m_topLabel(new QLabel)
26  , m_comboSelector(new QComboBox)
27  , m_bottomLabel(new QLabel)
28 {
29  QColor bgColor(240, 240, 240, 255);
30  QPalette palette;
31  palette.setColor(QPalette::Window, bgColor);
32  setAutoFillBackground(true);
33  setPalette(palette);
34 
35  setFixedSize(500, 250);
36  setWindowTitle("Please make a selection");
37  setWindowFlags(Qt::Dialog);
38 
39  auto* topLayout = new QHBoxLayout;
40  topLayout->addLayout(createLogoLayout(), 0);
41  topLayout->addLayout(createInfoLayout(), 1);
42 
43  auto* mainLayout = new QVBoxLayout;
44  mainLayout->addLayout(topLayout);
45  mainLayout->addLayout(createButtonLayout());
46 
47  setLayout(mainLayout);
48 }
49 
50 void ComboSelectorDialog::addItems(const QStringList& selection, const QString& currentItem)
51 {
52  m_comboSelector->addItems(selection);
53 
54  if (selection.contains(currentItem))
55  m_comboSelector->setCurrentIndex(selection.indexOf(currentItem));
56 }
57 
58 void ComboSelectorDialog::setTextTop(const QString& text)
59 {
60  m_topLabel->setText(text);
61 }
62 
63 void ComboSelectorDialog::setTextBottom(const QString& text)
64 {
65  m_bottomLabel->setText(text);
66 }
67 
69 {
70  return m_comboSelector->currentText();
71 }
72 
73 //! Returns layout with icon for left part of the widget.
74 
76 {
77  auto* result = new QVBoxLayout;
78 
79  QIcon icon = qApp->style()->standardIcon(QStyle::SP_MessageBoxQuestion);
80 
81  auto* label = new QLabel;
82  label->setPixmap(icon.pixmap(100));
83 
84  result->addWidget(label);
85  result->addStretch(1);
86  result->setContentsMargins(0, 5, 0, 5);
87 
88  return result;
89 }
90 
91 //! Creates right layout with text and QComboBox selection.
92 
94 {
95  auto* result = new QVBoxLayout;
96 
97  m_topLabel->setWordWrap(true);
98  m_bottomLabel->setWordWrap(true);
99 
100  result->addWidget(m_topLabel);
101  result->addStretch(1);
102  result->addWidget(m_comboSelector);
103  result->addStretch(1);
104  result->addWidget(m_bottomLabel);
105  result->addStretch(1);
106  result->setContentsMargins(0, 5, 5, 5);
107 
108  return result;
109 }
110 
111 //! Creates button layout with buttons.
112 
114 {
115  auto* result = new QHBoxLayout;
116 
117  auto* cancelButton = new QPushButton("Cancel");
118  connect(cancelButton, &QPushButton::clicked, this, &ComboSelectorDialog::reject);
119 
120  auto* okButton = new QPushButton("Try current selection");
121  connect(okButton, &QPushButton::clicked, this, &ComboSelectorDialog::accept);
122 
123  result->addStretch(1);
124  result->addWidget(okButton);
125  result->addWidget(cancelButton);
126 
127  return result;
128 }
Defines class ComboSelectorDialog.
void addItems(const QStringList &selection, const QString &currentItem="")
QBoxLayout * createLogoLayout()
Returns layout with icon for left part of the widget.
QBoxLayout * createButtonLayout()
Creates button layout with buttons.
ComboSelectorDialog(QWidget *parent=nullptr)
void setTextTop(const QString &text)
void setTextBottom(const QString &text)
QString currentText() const
QBoxLayout * createInfoLayout()
Creates right layout with text and QComboBox selection.