BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
ComboSelectorDialog Class Reference

Description

A dialog similar to standard QMessageBox with combo box selector.

Definition at line 27 of file ComboSelectorDialog.h.

Inheritance diagram for ComboSelectorDialog:
[legend]
Collaboration diagram for ComboSelectorDialog:
[legend]

Public Member Functions

 ComboSelectorDialog (QWidget *parent=nullptr)
 
void addItems (const QStringList &selection, const QString &currentItem="")
 
QString currentText () const
 
void setTextBottom (const QString &text)
 
void setTextTop (const QString &text)
 

Private Member Functions

QBoxLayout * createButtonLayout ()
 Creates button layout with buttons. More...
 
QBoxLayout * createInfoLayout ()
 Creates right layout with text and QComboBox selection. More...
 
QBoxLayout * createLogoLayout ()
 Returns layout with icon for left part of the widget. More...
 

Private Attributes

QLabel * m_bottomLabel
 
QComboBox * m_comboSelector
 
QLabel * m_topLabel
 

Constructor & Destructor Documentation

◆ ComboSelectorDialog()

ComboSelectorDialog::ComboSelectorDialog ( QWidget *  parent = nullptr)

Definition at line 23 of file ComboSelectorDialog.cpp.

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 }
QBoxLayout * createLogoLayout()
Returns layout with icon for left part of the widget.
QBoxLayout * createButtonLayout()
Creates button layout with buttons.
QBoxLayout * createInfoLayout()
Creates right layout with text and QComboBox selection.

References createButtonLayout(), createInfoLayout(), and createLogoLayout().

Here is the call graph for this function:

Member Function Documentation

◆ addItems()

void ComboSelectorDialog::addItems ( const QStringList &  selection,
const QString &  currentItem = "" 
)

Definition at line 50 of file ComboSelectorDialog.cpp.

51 {
52  m_comboSelector->addItems(selection);
53 
54  if (selection.contains(currentItem))
55  m_comboSelector->setCurrentIndex(selection.indexOf(currentItem));
56 }

References m_comboSelector.

◆ createButtonLayout()

QBoxLayout * ComboSelectorDialog::createButtonLayout ( )
private

Creates button layout with buttons.

Definition at line 113 of file ComboSelectorDialog.cpp.

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 }

Referenced by ComboSelectorDialog().

◆ createInfoLayout()

QBoxLayout * ComboSelectorDialog::createInfoLayout ( )
private

Creates right layout with text and QComboBox selection.

Definition at line 93 of file ComboSelectorDialog.cpp.

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 }

References m_bottomLabel, m_comboSelector, and m_topLabel.

Referenced by ComboSelectorDialog().

◆ createLogoLayout()

QBoxLayout * ComboSelectorDialog::createLogoLayout ( )
private

Returns layout with icon for left part of the widget.

Definition at line 75 of file ComboSelectorDialog.cpp.

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 }

Referenced by ComboSelectorDialog().

◆ currentText()

QString ComboSelectorDialog::currentText ( ) const

Definition at line 68 of file ComboSelectorDialog.cpp.

69 {
70  return m_comboSelector->currentText();
71 }

References m_comboSelector.

◆ setTextBottom()

void ComboSelectorDialog::setTextBottom ( const QString &  text)

Definition at line 63 of file ComboSelectorDialog.cpp.

64 {
65  m_bottomLabel->setText(text);
66 }

References m_bottomLabel.

◆ setTextTop()

void ComboSelectorDialog::setTextTop ( const QString &  text)

Definition at line 58 of file ComboSelectorDialog.cpp.

59 {
60  m_topLabel->setText(text);
61 }

References m_topLabel.

Member Data Documentation

◆ m_bottomLabel

QLabel* ComboSelectorDialog::m_bottomLabel
private

Definition at line 45 of file ComboSelectorDialog.h.

Referenced by createInfoLayout(), and setTextBottom().

◆ m_comboSelector

QComboBox* ComboSelectorDialog::m_comboSelector
private

Definition at line 44 of file ComboSelectorDialog.h.

Referenced by addItems(), createInfoLayout(), and currentText().

◆ m_topLabel

QLabel* ComboSelectorDialog::m_topLabel
private

Definition at line 43 of file ComboSelectorDialog.h.

Referenced by createInfoLayout(), and setTextTop().


The documentation for this class was generated from the following files: