1
/***************************************************************************
2
* Copyright (c) 2006 Werner Mayer <wmayer[at]users.sourceforge.net> *
4
* This file is part of the FreeCAD CAx development system. *
6
* This library is free software; you can redistribute it and/or *
7
* modify it under the terms of the GNU Library General Public *
8
* License as published by the Free Software Foundation; either *
9
* version 2 of the License, or (at your option) any later version. *
11
* This library is distributed in the hope that it will be useful, *
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14
* GNU Library General Public License for more details. *
16
* You should have received a copy of the GNU Library General Public *
17
* License along with this library; see the file COPYING.LIB. If not, *
18
* write to the Free Software Foundation, Inc., 59 Temple Place, *
19
* Suite 330, Boston, MA 02111-1307, USA *
21
***************************************************************************/
23
#include "PreCompiled.h"
25
#include <App/PropertyStandard.h>
27
#include "DlgMaterialPropertiesImp.h"
28
#include "ui_DlgMaterialProperties.h"
29
#include "ViewProvider.h"
32
using namespace Gui::Dialog;
35
/* TRANSLATOR Gui::Dialog::DlgMaterialPropertiesImp */
37
DlgMaterialPropertiesImp::DlgMaterialPropertiesImp(QWidget* parent, Qt::WindowFlags fl)
39
, ui(new Ui_DlgMaterialProperties)
44
ui->ambientColor->setAutoChangeColor(true);
45
ui->diffuseColor->setAutoChangeColor(true);
46
ui->emissiveColor->setAutoChangeColor(true);
47
ui->specularColor->setAutoChangeColor(true);
50
DlgMaterialPropertiesImp::~DlgMaterialPropertiesImp() = default;
52
void DlgMaterialPropertiesImp::setupConnections()
55
connect(ui->ambientColor, &ColorButton::changed,
56
this, &DlgMaterialPropertiesImp::onAmbientColorChanged);
57
connect(ui->diffuseColor, &ColorButton::changed,
58
this, &DlgMaterialPropertiesImp::onDiffuseColorChanged);
59
connect(ui->emissiveColor, &ColorButton::clicked,
60
this, &DlgMaterialPropertiesImp::onEmissiveColorChanged);
61
connect(ui->specularColor, &ColorButton::clicked,
62
this, &DlgMaterialPropertiesImp::onSpecularColorChanged);
63
connect(ui->shininess, qOverload<int>(&QSpinBox::valueChanged),
64
this, &DlgMaterialPropertiesImp::onShininessValueChanged);
65
connect(ui->transparency, qOverload<int>(&QSpinBox::valueChanged),
66
this, &DlgMaterialPropertiesImp::onTransparencyValueChanged);
67
connect(ui->buttonReset, &QPushButton::clicked,
68
this, &DlgMaterialPropertiesImp::onButtonReset);
69
connect(ui->buttonDefault, &QPushButton::clicked,
70
this, &DlgMaterialPropertiesImp::onButtonDefault);
74
void DlgMaterialPropertiesImp::setCustomMaterial(const App::Material& mat)
77
setButtonColors(customMaterial);
80
App::Material DlgMaterialPropertiesImp::getCustomMaterial() const
82
return customMaterial;
85
void DlgMaterialPropertiesImp::setDefaultMaterial(const App::Material& mat)
87
defaultMaterial = mat;
90
App::Material DlgMaterialPropertiesImp::getDefaultMaterial() const
92
return defaultMaterial;
96
* Sets the ambient color.
98
void DlgMaterialPropertiesImp::onAmbientColorChanged()
100
customMaterial.ambientColor.setValue(ui->ambientColor->color());
104
* Sets the diffuse color.
106
void DlgMaterialPropertiesImp::onDiffuseColorChanged()
108
customMaterial.diffuseColor.setValue(ui->diffuseColor->color());
112
* Sets the emissive color.
114
void DlgMaterialPropertiesImp::onEmissiveColorChanged()
116
customMaterial.emissiveColor.setValue(ui->emissiveColor->color());
120
* Sets the specular color.
122
void DlgMaterialPropertiesImp::onSpecularColorChanged()
124
customMaterial.specularColor.setValue(ui->specularColor->color());
128
* Sets the current shininess.
130
void DlgMaterialPropertiesImp::onShininessValueChanged(int sh)
132
customMaterial.shininess = (float)sh / 100.0F;
136
* Sets the current transparency.
138
void DlgMaterialPropertiesImp::onTransparencyValueChanged(int sh)
140
customMaterial.transparency = (float)sh / 100.0F;
144
* Reset the colors to the Coin3D defaults
146
void DlgMaterialPropertiesImp::onButtonReset()
148
setCustomMaterial(getDefaultMaterial());
152
* Reset the colors to the current default
154
void DlgMaterialPropertiesImp::onButtonDefault()
156
App::Material mat = App::Material::getDefaultAppearance();
157
setCustomMaterial(mat);
161
* Sets the button colors to match the current material settings.
163
void DlgMaterialPropertiesImp::setButtonColors(const App::Material& mat)
165
ui->ambientColor->setColor(mat.ambientColor.asValue<QColor>());
166
ui->diffuseColor->setColor(mat.diffuseColor.asValue<QColor>());
167
ui->emissiveColor->setColor(mat.emissiveColor.asValue<QColor>());
168
ui->specularColor->setColor(mat.specularColor.asValue<QColor>());
169
ui->shininess->blockSignals(true);
170
ui->shininess->setValue((int)(100.0F * (mat.shininess + 0.001F)));
171
ui->shininess->blockSignals(false);
172
ui->transparency->blockSignals(true);
173
ui->transparency->setValue((int)(100.0F * (mat.transparency + 0.001F)));
174
ui->transparency->blockSignals(false);
177
#include "moc_DlgMaterialPropertiesImp.cpp"