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