26 #include "ui_MaterialEditorDialog.h"
28 #include <QColorDialog>
29 #include <QMessageBox>
30 #include <QPushButton>
33 #include <QVBoxLayout>
57 auto* addRefractiveMaterialAction =
new QAction(
"Add material (refractive index)", parent);
58 addRefractiveMaterialAction->setIcon(QIcon(
":/images/shape-square-plus.svg"));
59 addRefractiveMaterialAction->setToolTip(
"Add new material");
60 connect(addRefractiveMaterialAction, &QAction::triggered,
this,
63 auto* addSldMaterialAction =
new QAction(
"Add material (SLD)", parent);
64 addSldMaterialAction->setIcon(QIcon(
":/images/shape-square-plus.svg"));
65 addSldMaterialAction->setToolTip(
"Add new material");
80 m_ui->treeView->addAction(addRefractiveMaterialAction);
81 m_ui->treeView->addAction(addSldMaterialAction);
83 auto* separator =
new QAction(
this);
84 separator->setSeparator(
true);
85 m_ui->treeView->addAction(separator);
88 m_ui->treeView->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
90 auto* toolbar =
new QToolBar(
this);
91 toolbar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
92 toolbar->addAction(addRefractiveMaterialAction);
93 toolbar->addAction(addSldMaterialAction);
96 m_ui->mainLayout->insertWidget(0, toolbar);
101 connect(
m_ui->treeView->selectionModel(), &QItemSelectionModel::currentChanged,
this,
104 connect(
m_ui->treeView->selectionModel(), &QItemSelectionModel::currentChanged,
this,
107 connect(
m_ui->selectColorButton, &QPushButton::clicked,
this,
110 connect(
m_ui->nameEdit, &QLineEdit::textEdited,
111 [&](
const QString& t) { m_model->setMaterialItemName(currentIndex(), t); });
113 connect(
m_ui->xSpinBox, qOverload<double>(&QDoubleSpinBox::valueChanged),
114 [&](
double value) { m_model->setX(currentIndex(), value); });
116 connect(
m_ui->ySpinBox, qOverload<double>(&QDoubleSpinBox::valueChanged),
117 [&](
double value) { m_model->setY(currentIndex(), value); });
119 connect(
m_ui->zSpinBox, qOverload<double>(&QDoubleSpinBox::valueChanged),
120 [&](
double value) { m_model->setZ(currentIndex(), value); });
122 connect(
m_ui->deltaEdit, &QLineEdit::editingFinished,
123 [&]() { m_model->setDelta(currentIndex(), m_ui->deltaEdit->text().toDouble()); });
125 connect(
m_ui->betaEdit, &QLineEdit::editingFinished,
126 [&]() { m_model->setBeta(currentIndex(), m_ui->betaEdit->text().toDouble()); });
128 connect(
m_ui->realEdit, &QLineEdit::editingFinished,
129 [&]() { m_model->setRe(currentIndex(), m_ui->realEdit->text().toDouble()); });
131 connect(
m_ui->imaginaryEdit, &QLineEdit::editingFinished,
132 [&]() { m_model->setIm(currentIndex(), m_ui->imaginaryEdit->text().toDouble()); });
138 m_ui->sldGroupBox->hide();
139 m_ui->propertiesWidget->setEnabled(
false);
155 const QString& identifierOfPreviousMaterial)
159 if (dialog.exec() == QDialog::Accepted)
161 return material->identifier();
191 if (material ==
nullptr)
196 "This material can't be removed - it is used in the current sample.");
205 if (
auto newColor = QColorDialog::getColor(
currentMaterial()->color()); newColor.isValid())
226 m_ui->propertiesWidget->setEnabled(materialItem !=
nullptr);
227 if (materialItem ==
nullptr) {
228 m_ui->refractiveGroupBox->show();
229 m_ui->sldGroupBox->hide();
230 for (
auto* lineEdit :
m_ui->propertiesWidget->findChildren<QLineEdit*>())
232 for (
auto* spinBox :
m_ui->propertiesWidget->findChildren<QDoubleSpinBox*>())
237 m_ui->refractiveGroupBox->setVisible(materialItem->hasRefractiveIndex());
238 m_ui->sldGroupBox->setVisible(!materialItem->hasRefractiveIndex());
240 m_ui->nameEdit->setText(materialItem->matItemName());
241 m_ui->colorInfo->setText(QString(
"[%1, %2, %3] (%4)")
242 .arg(materialItem->color().red())
243 .arg(materialItem->color().green())
244 .arg(materialItem->color().blue())
245 .arg(materialItem->color().alpha()));
246 QPixmap pixmap(
m_ui->selectColorButton->iconSize());
247 pixmap.fill(materialItem->color());
248 m_ui->selectColorButton->setIcon(pixmap);
250 if (materialItem->hasRefractiveIndex()) {
251 m_ui->deltaEdit->setText(QString::number(materialItem->delta().get(),
'g'));
252 m_ui->betaEdit->setText(QString::number(materialItem->beta().get(),
'g'));
254 m_ui->realEdit->setText(QString::number(materialItem->sldRe().get(),
'g'));
255 m_ui->imaginaryEdit->setText(QString::number(materialItem->sldIm().get(),
'g'));
258 m_ui->xSpinBox->setValue(materialItem->magnetization().x());
259 m_ui->ySpinBox->setValue(materialItem->magnetization().y());
260 m_ui->zSpinBox->setValue(materialItem->magnetization().z());
275 return m_ui->treeView->currentIndex();
282 result << p->materialIdentifier();
ApplicationSettings * appSettings
global pointer to the instance
Defines class ApplicationSettings.
Defines class DoubleDescriptor.
Defines class GUIHelpers functions.
Defines abstract item with a material property.
Defines class MaterialEditorDialog.
Defines class MaterialEditorModel.
Defines class MaterialItem.
Defines class MaterialItems.
Defines class MultiLayerItem.
Defines GUI::StyleUtils namespace.
void loadWindowSizeAndPos(QWidget *w)
void saveWindowSizeAndPos(const QWidget *w)
Dialog to select a material and also to edit the list of existing materials. The dialog operates on a...
void removeCurrentMaterial()
MaterialItems m_tmpMaterialItems
void cloneCurrentMaterial()
static QString chooseMaterial(QWidget *parent, MultiLayerItem *sample, const QString &identifierOfPreviousMaterial)
Use this to choose a material. identifierOfPreviousMaterial is the material which should be selected ...
QAction * m_cloneMaterialAction
Materials for working within this dialog.
void setCurrentMaterial(const MaterialItem *m)
MaterialEditorDialog(MultiLayerItem *sample, QWidget *parent=nullptr)
MaterialItem * currentMaterial()
Ui::MaterialEditorDialog * m_ui
void addRefractiveMaterial()
~MaterialEditorDialog() override
QModelIndex currentIndex() const
MaterialEditorModel * m_model
QAction * m_removeMaterialAction
MultiLayerItem * m_sample
Model for the left list. Works on m_tmpMaterialItems.
QStringList identifiersOfUsedMaterials() const
Returns the list of material identifiers of the materials currently used in the sample....
static void editMaterials(QWidget *parent, MultiLayerItem *sample)
Use this to edit the list of existing materials.
void updateActionEnabling()
void accept() override
updates original material model with the edited model
Model for list of materials, used in MaterialEditorDialog.
MaterialItem * materialFromIndex(const QModelIndex &index) const
QModelIndex indexFromMaterial(const MaterialItem *m) const
MaterialItem * addRefractiveMaterial(const QString &name, double delta, double beta)
void setColor(const QModelIndex &index, const QColor &color)
int rowCount(const QModelIndex &parent=QModelIndex()) const override
MaterialItem * addSLDMaterial(const QString &name, double sld, double abs_term)
MaterialItem * cloneMaterial(const QModelIndex &index)
void removeMaterial(const QModelIndex &index)
QModelIndex first() const
QString identifier() const
void initFrom(const MaterialItems &from)
Copies the complete content, emitting signals for existing and changed materials.
MaterialItems & materialItems()
QVector< ItemWithMaterial * > itemsWithMaterial() const
Defines namespace GUI::Constants.
void setResizable(QDialog *dialog)
Make modal dialog resizable.
void configSpinbox(QDoubleSpinBox *spinBox, int decimals, const RealLimits &limits)
void configScientificDoubleEdit(QLineEdit *edit, const RealLimits &limits)
void warning(QWidget *parent, const QString &title, const QString &text, const QString &detailedText)