Newer
Older
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
126
127
128
129
130
131
132
133
134
135
136
137
// ************************************************************************************************
//
// BornAgain: simulate and fit reflection and scattering
//
//! @file GUI/View/SampleDesigner/HeinzFormLayout.cpp
//! @brief Implements class HeinzFormLayout
//!
//! @homepage http://www.bornagainproject.org
//! @license GNU General Public License v3 or higher (see COPYING)
//! @copyright Forschungszentrum Jülich GmbH 2021
//! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
//
// ************************************************************************************************
#include "GUI/View/SampleDesigner/HeinzFormLayout.h"
#include "Base/Util/Assert.h"
#include "GUI/Model/Descriptor/VectorProperty.h"
#include "GUI/View/Numeric/DoubleSpinBox.h"
#include "GUI/View/SampleDesigner/LayerEditorUtil.h"
#include "GUI/View/SampleDesigner/SampleEditorController.h"
#include "GUI/View/Widget/GroupBoxes.h"
#include <QGroupBox>
#include <QLabel>
#include <QPushButton>
namespace {
QLabel* createBoldLabel(const QString& text)
{
auto* l = new QLabel(text);
QFont f = l->font();
f.setBold(true);
l->setFont(f);
return l;
}
} // namespace
HeinzFormLayout::HeinzFormLayout(QWidget* parent, SampleEditorController* ec)
: QFormLayout(parent)
, m_ec(ec)
{
ASSERT(!parent->layout());
QFormLayout::setFormAlignment(Qt::AlignLeft | Qt::AlignBottom);
QFormLayout::setFieldGrowthPolicy(QFormLayout::FieldsStayAtSizeHint);
}
void HeinzFormLayout::insertRow(int row, QString label, QWidget* w)
{
if (!label.endsWith(":"))
label += ":";
QFormLayout::insertRow(row, ::createBoldLabel(label), w);
}
void HeinzFormLayout::addGroupOfValues(const QString& labelText, const DoubleProperties& values)
{
auto* w = new QWidget(QFormLayout::parentWidget());
w->setObjectName("PropertyBaseWidget");
w->setAttribute(Qt::WA_StyledBackground, true);
w->setStyleSheet("#PropertyBaseWidget {background-color: transparent}");
auto* gridLayout = new QGridLayout(w);
gridLayout->setContentsMargins(0, 0, 0, 0);
gridLayout->setSpacing(6);
LayerEditorUtil::addMultiPropertyToGrid(gridLayout, 0, values, m_ec, true);
QFormLayout::addRow(labelText, w);
}
void HeinzFormLayout::addVector(VectorProperty& d, bool vertically /*= true*/)
{
auto* w = new QWidget(QFormLayout::parentWidget());
w->setObjectName("PropertyBaseWidget");
w->setAttribute(Qt::WA_StyledBackground, true);
w->setStyleSheet("#PropertyBaseWidget {background-color: transparent}");
auto* gridLayout = new QGridLayout(w);
gridLayout->setContentsMargins(0, 0, 0, 0);
gridLayout->setSpacing(6);
LayerEditorUtil::addMultiPropertyToGrid(gridLayout, 0, {&d.x(), &d.y(), &d.z()}, m_ec,
vertically, true);
QFormLayout::addRow(d.label(), w);
}
void HeinzFormLayout::setRowVisible(int row, bool visible)
{
QFormLayout::itemAt(row, QFormLayout::LabelRole)->widget()->setVisible(visible);
QFormLayout::itemAt(row, QFormLayout::FieldRole)->widget()->setVisible(visible);
}
void HeinzFormLayout::addStructureEditingRow(QPushButton* button)
{
auto* w = new QWidget(QFormLayout::parentWidget());
auto* l = new QHBoxLayout(w);
l->setContentsMargins(0, 0, 0, 0);
l->setAlignment(Qt::AlignLeft);
l->setSizeConstraint(QLayout::SetMinimumSize);
l->addWidget(button);
l->addStretch();
QFormLayout::addRow(w);
}
void HeinzFormLayout::addValue(DoubleProperty& d)
{
insertValue(QFormLayout::rowCount(), d);
}
void HeinzFormLayout::addValue(DoubleProperty& d, std::function<void(double)> onValueChange)
{
insertValue(QFormLayout::rowCount(), d, onValueChange);
}
void HeinzFormLayout::insertValue(int row, DoubleProperty& d)
{
insertValue(row, d, [ec = m_ec, &d](double newValue) { ec->setDouble(newValue, d); });
}
void HeinzFormLayout::insertValue(int row, DoubleProperty& d, std::function<void(double)> onValueChange)
{
auto* editor = new DoubleSpinBox(d);
QObject::connect(editor, &DoubleSpinBox::baseValueChanged, onValueChange);
QString labelText = d.label();
if (!labelText.endsWith(":"))
labelText += ":";
QLabel* label = ::createBoldLabel(labelText);
label->setAlignment(Qt::AlignLeft | Qt::AlignBottom);
label->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::MinimumExpanding);
label->setBuddy(editor);
QFormLayout::insertRow(row, label, editor);
}