File: ComboSelectorDialog.cpp

package info (click to toggle)
bornagain 23.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 103,936 kB
  • sloc: cpp: 423,131; python: 40,997; javascript: 11,167; awk: 630; sh: 318; ruby: 173; xml: 130; makefile: 51; ansic: 24
file content (125 lines) | stat: -rw-r--r-- 3,508 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
//  ************************************************************************************************
//
//  BornAgain: simulate and fit reflection and scattering
//
//! @file      GUI/View/Info/ComboSelectorDialog.cpp
//! @brief     Implements class ComboSelectorDialog.
//!
//! @homepage  http://www.bornagainproject.org
//! @license   GNU General Public License v3 or higher (see COPYING)
//! @copyright Forschungszentrum Jülich GmbH 2018
//! @authors   Scientific Computing Group at MLZ (see CITATION, AUTHORS)
//
//  ************************************************************************************************

#include "GUI/View/Info/ComboSelectorDialog.h"
#include <QApplication> // qApp
#include <QPushButton>
#include <QVBoxLayout>

ComboSelectorDialog::ComboSelectorDialog(QWidget* parent)
    : QDialog(parent)
    , m_top_label(new QLabel)
    , m_combo_selector(new QComboBox)
    , m_bottom_label(new QLabel)
{
    QColor bgColor(240, 240, 240, 255);
    QPalette palette;
    palette.setColor(QPalette::Window, bgColor);
    setAutoFillBackground(true);
    setPalette(palette);

    setFixedSize(500, 250);
    setWindowTitle("Please make a selection");
    setWindowFlags(Qt::Dialog);

    auto* topLayout = new QHBoxLayout;
    topLayout->addLayout(createLogoLayout(), 0);
    topLayout->addLayout(createInfoLayout(), 1);

    auto* mainLayout = new QVBoxLayout;
    mainLayout->addLayout(topLayout);
    mainLayout->addLayout(createButtonLayout());

    setLayout(mainLayout);
}

void ComboSelectorDialog::addItems(const QStringList& selection, const QString& currentItem)
{
    m_combo_selector->addItems(selection);

    if (selection.contains(currentItem))
        m_combo_selector->setCurrentIndex(selection.indexOf(currentItem));
}

void ComboSelectorDialog::setTextTop(const QString& text)
{
    m_top_label->setText(text);
}

void ComboSelectorDialog::setTextBottom(const QString& text)
{
    m_bottom_label->setText(text);
}

QString ComboSelectorDialog::currentText() const
{
    return m_combo_selector->currentText();
}

//! Returns layout with icon for left part of the widget.

QBoxLayout* ComboSelectorDialog::createLogoLayout()
{
    auto* result = new QVBoxLayout;
    result->setContentsMargins(0, 5, 0, 5);

    QIcon icon = qApp->style()->standardIcon(QStyle::SP_MessageBoxQuestion);

    auto* label = new QLabel;
    label->setPixmap(icon.pixmap(100));

    result->addWidget(label);
    result->addStretch(1);

    return result;
}

//! Creates right layout with text and QComboBox selection.

QBoxLayout* ComboSelectorDialog::createInfoLayout()
{
    auto* result = new QVBoxLayout;
    result->setContentsMargins(0, 5, 5, 5);

    m_top_label->setWordWrap(true);
    m_bottom_label->setWordWrap(true);

    result->addWidget(m_top_label);
    result->addStretch(1);
    result->addWidget(m_combo_selector);
    result->addStretch(1);
    result->addWidget(m_bottom_label);
    result->addStretch(1);

    return result;
}

//! Creates button layout with buttons.

QBoxLayout* ComboSelectorDialog::createButtonLayout()
{
    auto* result = new QHBoxLayout;

    auto* cancelButton = new QPushButton("Cancel");
    connect(cancelButton, &QPushButton::clicked, this, &ComboSelectorDialog::reject);

    auto* okButton = new QPushButton("Try current selection");
    connect(okButton, &QPushButton::clicked, this, &ComboSelectorDialog::accept);

    result->addStretch(1);
    result->addWidget(okButton);
    result->addWidget(cancelButton);

    return result;
}