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

A dialog similar to standard QMessageBox with combo box selector. More...

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

Public Member Functions

 ComboSelectorDialog (QWidget *parent=0)
 
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
 

Detailed Description

A dialog similar to standard QMessageBox with combo box selector.

Definition at line 27 of file ComboSelectorDialog.h.

Constructor & Destructor Documentation

◆ ComboSelectorDialog()

ComboSelectorDialog::ComboSelectorDialog ( QWidget *  parent = 0)

Definition at line 24 of file ComboSelectorDialog.cpp.

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 }
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 51 of file ComboSelectorDialog.cpp.

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

References m_comboSelector.

Referenced by PyImportAssistant::selectPySampleFunction().

◆ createButtonLayout()

QBoxLayout * ComboSelectorDialog::createButtonLayout ( )
private

Creates button layout with buttons.

Definition at line 114 of file ComboSelectorDialog.cpp.

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 }

Referenced by ComboSelectorDialog().

◆ createInfoLayout()

QBoxLayout * ComboSelectorDialog::createInfoLayout ( )
private

Creates right layout with text and QComboBox selection.

Definition at line 94 of file ComboSelectorDialog.cpp.

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 }

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 76 of file ComboSelectorDialog.cpp.

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 }

Referenced by ComboSelectorDialog().

◆ currentText()

QString ComboSelectorDialog::currentText ( ) const

Definition at line 69 of file ComboSelectorDialog.cpp.

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

References m_comboSelector.

Referenced by PyImportAssistant::selectPySampleFunction().

◆ setTextBottom()

void ComboSelectorDialog::setTextBottom ( const QString &  text)

Definition at line 64 of file ComboSelectorDialog.cpp.

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

References m_bottomLabel.

Referenced by PyImportAssistant::selectPySampleFunction().

◆ setTextTop()

void ComboSelectorDialog::setTextTop ( const QString &  text)

Definition at line 59 of file ComboSelectorDialog.cpp.

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

References m_topLabel.

Referenced by PyImportAssistant::selectPySampleFunction().

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: