SettingsWindow.cpp 7.44 KB
Newer Older
Anakin's avatar
Anakin committed
1
#include "..\Header\SettingsWindow.h"
2
#include "..\Header\SettingsManager.h"
3 4 5 6


/////////////////////////////////////////////////////////////////////////
// constructor/destructor
Anakin's avatar
Anakin committed
7

8
SettingsWindow::SettingsWindow(QWidget * parent)
Anakin's avatar
Anakin committed
9 10 11 12 13 14 15
	: QWidget(parent)
	, ui(new Ui::SettingsWindow)
{
	ui->setupUi(this);

	setWindowFlags(Qt::Tool | Qt::NoDropShadowWindowHint);

16 17 18
	setupConnections();

	// set default values
19
	SettingsManager* sm = SettingsManager::getInstance(this);
20

21 22 23
	ui->lightOff_R_SB->setValue((int)(sm->getBgColorOff()[0]));
	ui->lightOff_G_SB->setValue((int)(sm->getBgColorOff()[1]));
	ui->lightOff_B_SB->setValue((int)(sm->getBgColorOff()[2]));
24

25 26 27
	ui->lightOn_R_SB->setValue((int)(sm->getBgColorOn()[0]));
	ui->lightOn_G_SB->setValue((int)(sm->getBgColorOn()[1]));
	ui->lightOn_B_SB->setValue((int)(sm->getBgColorOn()[2]));
28

29 30 31
	ui->light_R_SB->setValue((int)(sm->getLightColor()[0]));
	ui->light_G_SB->setValue((int)(sm->getLightColor()[1]));
	ui->light_B_SB->setValue((int)(sm->getLightColor()[2]));
32

33 34 35 36 37 38 39 40
	ui->ambCoef->setValue(sm->getAmbient());
	ui->attFac->setValue(sm->getAttenuation());

	ui->checkBackfaceCulling->setChecked(sm->isBfCulling());
	ui->checkAutoColor->setChecked(sm->isAutoColor());
	ui->checkHeadlight->setChecked(sm->isHeadlight());

	if (sm->getLightType() == 1)
41
		ui->radioDirectLight->setChecked(true);
42 43 44 45 46 47 48 49 50 51 52 53
	else
		ui->radioPointLight->setChecked(true);

	connect(this, &SettingsWindow::updateBGColorOff, sm, &SettingsManager::setBgColorOff);
	connect(this, &SettingsWindow::updateBGColorOn, sm, &SettingsManager::setBgColorOn);
	connect(this, &SettingsWindow::updateLightColor, sm, &SettingsManager::setLightColor);
	connect(this, &SettingsWindow::updateAttFac, sm, &SettingsManager::setAttenuation);
	connect(this, &SettingsWindow::updateAmbCoef, sm, &SettingsManager::setAmbient);
	connect(this, &SettingsWindow::sendHeadlight, sm, &SettingsManager::setHeadlight);
	connect(this, &SettingsWindow::sendBackfaceCulling, sm, &SettingsManager::setBfCulling);
	connect(ui->checkAutoColor, &QCheckBox::stateChanged, sm, &SettingsManager::setAutoColor);
	connect(this, &SettingsWindow::changeLightType, sm, &SettingsManager::setLightType);
54 55 56 57 58 59 60 61

}

SettingsWindow::~SettingsWindow()
{
	delete ui;
}

62 63 64 65

/////////////////////////////////////////////////////////////////////////
// functions

66 67
void SettingsWindow::setupConnections()
{
Anakin's avatar
Anakin committed
68
	// light off
69 70
	connect(ui->lightOff_R_SB, SIGNAL(valueChanged(int)), ui->lightOff_R_S, SLOT(setValue(int)));
	connect(ui->lightOff_R_S, SIGNAL(valueChanged(int)), ui->lightOff_R_SB, SLOT(setValue(int)));
71
	connect(ui->lightOff_R_S, &QSlider::valueChanged, this, &SettingsWindow::backgroundColorOffChanged);
Anakin's avatar
Anakin committed
72

73 74
	connect(ui->lightOff_G_SB, SIGNAL(valueChanged(int)), ui->lightOff_G_S, SLOT(setValue(int)));
	connect(ui->lightOff_G_S, SIGNAL(valueChanged(int)), ui->lightOff_G_SB, SLOT(setValue(int)));
75
	connect(ui->lightOff_G_S, &QSlider::valueChanged, this, &SettingsWindow::backgroundColorOffChanged);
Anakin's avatar
Anakin committed
76

77 78
	connect(ui->lightOff_B_SB, SIGNAL(valueChanged(int)), ui->lightOff_B_S, SLOT(setValue(int)));
	connect(ui->lightOff_B_S, SIGNAL(valueChanged(int)), ui->lightOff_B_SB, SLOT(setValue(int)));
79
	connect(ui->lightOff_B_S, &QSlider::valueChanged, this, &SettingsWindow::backgroundColorOffChanged);
Anakin's avatar
Anakin committed
80 81

	// light on
82 83
	connect(ui->lightOn_R_SB, SIGNAL(valueChanged(int)), ui->lightOn_R_S, SLOT(setValue(int)));
	connect(ui->lightOn_R_S, SIGNAL(valueChanged(int)), ui->lightOn_R_SB, SLOT(setValue(int)));
84
	connect(ui->lightOn_R_S, &QSlider::valueChanged, this, &SettingsWindow::backgroundColorOnChanged);
Anakin's avatar
Anakin committed
85

86 87
	connect(ui->lightOn_G_SB, SIGNAL(valueChanged(int)), ui->lightOn_G_S, SLOT(setValue(int)));
	connect(ui->lightOn_G_S, SIGNAL(valueChanged(int)), ui->lightOn_G_SB, SLOT(setValue(int)));
88
	connect(ui->lightOn_G_S, &QSlider::valueChanged, this, &SettingsWindow::backgroundColorOnChanged);
Anakin's avatar
Anakin committed
89

90 91
	connect(ui->lightOn_B_SB, SIGNAL(valueChanged(int)), ui->lightOn_B_S, SLOT(setValue(int)));
	connect(ui->lightOn_B_S, SIGNAL(valueChanged(int)), ui->lightOn_B_SB, SLOT(setValue(int)));
92
	connect(ui->lightOn_B_S, &QSlider::valueChanged, this, &SettingsWindow::backgroundColorOnChanged);
Anakin's avatar
Anakin committed
93 94

	// light
95 96
	connect(ui->light_R_SB, SIGNAL(valueChanged(int)), ui->light_R_S, SLOT(setValue(int)));
	connect(ui->light_R_S, SIGNAL(valueChanged(int)), ui->light_R_SB, SLOT(setValue(int)));
97
	connect(ui->light_R_S, &QSlider::valueChanged, this, &SettingsWindow::lightColorChanged);
Anakin's avatar
Anakin committed
98

99 100
	connect(ui->light_G_SB, SIGNAL(valueChanged(int)), ui->light_G_S, SLOT(setValue(int)));
	connect(ui->light_G_S, SIGNAL(valueChanged(int)), ui->light_G_SB, SLOT(setValue(int)));
101
	connect(ui->light_G_S, &QSlider::valueChanged, this, &SettingsWindow::lightColorChanged);
Anakin's avatar
Anakin committed
102

103 104
	connect(ui->light_B_SB, SIGNAL(valueChanged(int)), ui->light_B_S, SLOT(setValue(int)));
	connect(ui->light_B_S, SIGNAL(valueChanged(int)), ui->light_B_SB, SLOT(setValue(int)));
105
	connect(ui->light_B_S, &QSlider::valueChanged, this, &SettingsWindow::lightColorChanged);
Anakin's avatar
Anakin committed
106 107 108 109


	connect(ui->checkAutoColor, &QCheckBox::toggled, this, &SettingsWindow::autoColorToggled);
	connect(ui->radioDirectLight, &QRadioButton::toggled, this, &SettingsWindow::radioToggled);
110 111
	connect(ui->ambCoef, static_cast<void(QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), [this](double value) {emit updateAmbCoef(value); });
	connect(ui->attFac, static_cast<void(QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), [this](double value) {emit updateAttFac(value); });
112 113 114

	connect(ui->checkBackfaceCulling, &QCheckBox::toggled, [this]() {emit sendBackfaceCulling(ui->checkBackfaceCulling->isChecked()); });
	connect(ui->spinZSpeed, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), [this](int value) {emit sendZommSpeed(value); });
Anakin's avatar
Anakin committed
115
	connect(ui->checkHeadlight, &QCheckBox::toggled, [this]() {emit sendHeadlight(ui->checkHeadlight->isChecked()); });
Anakin's avatar
Anakin committed
116 117 118
}


119 120
/////////////////////////////////////////////////////////////////////////
// slots
Anakin's avatar
Anakin committed
121 122 123 124 125

void SettingsWindow::autoColorToggled()
{
	if (!ui->checkAutoColor->isChecked())
	{
126
		ui->lightOn_R_SB->setEnabled(true);
Anakin's avatar
Anakin committed
127
		ui->lightOn_R_S->setEnabled(true);
128
		ui->lightOn_G_SB->setEnabled(true);
Anakin's avatar
Anakin committed
129
		ui->lightOn_G_S->setEnabled(true);
130
		ui->lightOn_B_SB->setEnabled(true);
Anakin's avatar
Anakin committed
131 132 133 134
		ui->lightOn_B_S->setEnabled(true);
	}
	else
	{
135
		ui->lightOn_R_SB->setEnabled(false);
Anakin's avatar
Anakin committed
136
		ui->lightOn_R_S->setEnabled(false);
137
		ui->lightOn_G_SB->setEnabled(false);
Anakin's avatar
Anakin committed
138
		ui->lightOn_G_S->setEnabled(false);
139
		ui->lightOn_B_SB->setEnabled(false);
Anakin's avatar
Anakin committed
140 141 142 143 144 145 146 147 148 149
		ui->lightOn_B_S->setEnabled(false);

		ui->lightOn_R_S->setValue((int)(ui->light_R_S->value() / 50));
		ui->lightOn_G_S->setValue((int)(ui->light_G_S->value() / 50));
		ui->lightOn_B_S->setValue((int)(ui->light_B_S->value() / 50));
	}
}

void SettingsWindow::radioToggled()
{
150
	if (ui->radioDirectLight->isChecked())
Anakin's avatar
Anakin committed
151 152 153
	{
		ui->attFac->setValue(0.0);
		ui->attFac->setEnabled(false);
154
		emit changeLightType(1);
Anakin's avatar
Anakin committed
155 156 157 158
	}
	else
	{
		ui->attFac->setEnabled(true);
159
		emit changeLightType(2);
Anakin's avatar
Anakin committed
160 161
	}
}
162 163 164 165 166 167 168 169 170 171 172 173 174 175

void SettingsWindow::backgroundColorOffChanged()
{
	emit updateBGColorOff(QVector3D(ui->lightOff_R_S->value(), ui->lightOff_G_S->value(), ui->lightOff_B_S->value()));
}

void SettingsWindow::backgroundColorOnChanged()
{
	emit updateBGColorOn(QVector3D(ui->lightOn_R_S->value(), ui->lightOn_G_S->value(), ui->lightOn_B_S->value()));
}

void SettingsWindow::lightColorChanged()
{
	emit updateLightColor(QVector3D(ui->light_R_S->value(), ui->light_G_S->value(), ui->light_B_S->value()));
176 177 178 179 180 181 182

	if (ui->checkAutoColor->isChecked())
	{
		ui->lightOn_R_S->setValue((int)(ui->light_R_S->value() / 50));
		ui->lightOn_G_S->setValue((int)(ui->light_G_S->value() / 50));
		ui->lightOn_B_S->setValue((int)(ui->light_B_S->value() / 50));
	}
183
}