From 30d41f7d85a7e52d6aa69b461f2a3e81fa26a97d Mon Sep 17 00:00:00 2001 From: Anakin Date: Tue, 24 Jan 2017 17:09:51 +0100 Subject: [PATCH] connected settings window with software --- QtMeshViewer/Form Files/SettingsWindow.ui | 3 ++ QtMeshViewer/Header/OglViewerWidget.h | 8 ++- QtMeshViewer/Header/SettingsWindow.h | 11 ++++ QtMeshViewer/Source/OglViewerWidget.cpp | 62 ++++++++++++++++++++--- QtMeshViewer/Source/SettingsWindow.cpp | 38 +++++++++++--- 5 files changed, 108 insertions(+), 14 deletions(-) diff --git a/QtMeshViewer/Form Files/SettingsWindow.ui b/QtMeshViewer/Form Files/SettingsWindow.ui index 6a0973f..b8ae54f 100644 --- a/QtMeshViewer/Form Files/SettingsWindow.ui +++ b/QtMeshViewer/Form Files/SettingsWindow.ui @@ -442,6 +442,9 @@ + + false + 55 diff --git a/QtMeshViewer/Header/OglViewerWidget.h b/QtMeshViewer/Header/OglViewerWidget.h index bdd04d9..3c84a3b 100644 --- a/QtMeshViewer/Header/OglViewerWidget.h +++ b/QtMeshViewer/Header/OglViewerWidget.h @@ -46,7 +46,8 @@ private: SettingsWindow* m_settings; - QVector4D m_backgroundColor = {0.5f, 0.8f, 1.0f, 1.0f}; + QVector4D m_backgroundColorOn = {0.02f, 0.02f, 0.02f, 1.0f}; + QVector4D m_backgroundColorOff = { 0.5f, 0.8f, 1.0f, 1.0f }; QOpenGLShaderProgram m_program; GeometryEngine *m_dataEngine; @@ -86,6 +87,11 @@ public slots: void toggleWireframe(); void toggleLight(); void showSettings(); + void setBGColorOff(QVector3D value); + void setBGColorOn(QVector3D value); + void setLightColor(QVector3D value); + void setAttFac(double value); + void setAmbCoef(double value); signals: void sendMessage(QString message, int severity); diff --git a/QtMeshViewer/Header/SettingsWindow.h b/QtMeshViewer/Header/SettingsWindow.h index 785219d..24c3581 100644 --- a/QtMeshViewer/Header/SettingsWindow.h +++ b/QtMeshViewer/Header/SettingsWindow.h @@ -1,6 +1,7 @@ #pragma once #include #include "ui_SettingsWindow.h" +#include class SettingsWindow : public QWidget { @@ -16,4 +17,14 @@ private: private slots: void autoColorToggled(); void radioToggled(); + void backgroundColorOffChanged(); + void backgroundColorOnChanged(); + void lightColorChanged(); + +signals: + void updateBGColorOff(QVector3D value); + void updateBGColorOn(QVector3D value); + void updateLightColor(QVector3D value); + void updateAttFac(double value); + void updateAmbCoef(double value); }; \ No newline at end of file diff --git a/QtMeshViewer/Source/OglViewerWidget.cpp b/QtMeshViewer/Source/OglViewerWidget.cpp index 3d6a77a..9040908 100644 --- a/QtMeshViewer/Source/OglViewerWidget.cpp +++ b/QtMeshViewer/Source/OglViewerWidget.cpp @@ -21,6 +21,11 @@ OglViewerWidget::OglViewerWidget(QWidget *parent) m_translation.setZ(DEFAULT_Z_DISTANCE); setAcceptDrops(true); + connect(m_settings, &SettingsWindow::updateBGColorOff, this, &OglViewerWidget::setBGColorOff); + connect(m_settings, &SettingsWindow::updateBGColorOn, this, &OglViewerWidget::setBGColorOn); + connect(m_settings, &SettingsWindow::updateLightColor, this, &OglViewerWidget::setLightColor); + connect(m_settings, &SettingsWindow::updateAttFac, this, &OglViewerWidget::setAttFac); + connect(m_settings, &SettingsWindow::updateAmbCoef, this, &OglViewerWidget::setAmbCoef); } OglViewerWidget::~OglViewerWidget() @@ -233,10 +238,15 @@ void OglViewerWidget::resizeGL(int w, int h) void OglViewerWidget::paintGL() { - if (m_backgroundColor[3] == 1.0) + if (m_lightOn && m_backgroundColorOn[3] == 1.0) { - glClearColor(m_backgroundColor[0], m_backgroundColor[1], m_backgroundColor[2], 0.0000f); - m_backgroundColor[3] = 0.0; + glClearColor(m_backgroundColorOn[0], m_backgroundColorOn[1], m_backgroundColorOn[2], 0.0000f); + m_backgroundColorOn[3] = 0.0; + } + else if(!m_lightOn && m_backgroundColorOff[3] == 1.0) + { + glClearColor(m_backgroundColorOff[0], m_backgroundColorOff[1], m_backgroundColorOff[2], 0.0000f); + m_backgroundColorOff[3] = 0.0; } // Clear color and depth buffer @@ -355,15 +365,13 @@ void OglViewerWidget::toggleLight() if (m_lightOn) { - m_backgroundColor = { m_light.intensities.x() / 50, m_light.intensities.y() / 50, m_light.intensities.z() / 50, 1.0 }; - + m_backgroundColorOn[3] = 1.0; updateLightPosition(); } else { - m_backgroundColor = { 0.5f, 0.8f, 1.0f, 1.0 }; + m_backgroundColorOff[3] = 1.0; } - update(); } @@ -371,3 +379,43 @@ void OglViewerWidget::showSettings() { m_settings->show(); } + +void OglViewerWidget::setBGColorOff(QVector3D value) +{ + m_backgroundColorOff = QVector4D(value / 255, 1.0f); + + if (!m_lightOn) + update(); +} + +void OglViewerWidget::setBGColorOn(QVector3D value) +{ + m_backgroundColorOn = QVector4D(value / 255, 1.0f); + + if (m_lightOn) + update(); +} + +void OglViewerWidget::setLightColor(QVector3D value) +{ + m_light.intensities = value / 255; + + if (m_lightOn) + update(); +} + +void OglViewerWidget::setAttFac(double value) +{ + m_light.attenuationFactor = (float)value; + + if (m_lightOn) + update(); +} + +void OglViewerWidget::setAmbCoef(double value) +{ + m_light.ambientCoefficient = (float)value; + + if (m_lightOn) + update(); +} diff --git a/QtMeshViewer/Source/SettingsWindow.cpp b/QtMeshViewer/Source/SettingsWindow.cpp index c32a4e7..183c027 100644 --- a/QtMeshViewer/Source/SettingsWindow.cpp +++ b/QtMeshViewer/Source/SettingsWindow.cpp @@ -1,7 +1,5 @@ #include "..\Header\SettingsWindow.h" #include -#include -#include SettingsWindow::SettingsWindow(QWidget * parent) : QWidget(parent) @@ -14,37 +12,47 @@ SettingsWindow::SettingsWindow(QWidget * parent) // light off connect(ui->lightOff_R_LE, &QLineEdit::textChanged, [this](const QString& value){ui->lightOff_R_S->setValue(value.toInt());}); connect(ui->lightOff_R_S, &QSlider::valueChanged, [this](const int& value){ui->lightOff_R_LE->setText(QString::number(value));}); + connect(ui->lightOff_R_S, &QSlider::valueChanged, this, &SettingsWindow::backgroundColorOffChanged); connect(ui->lightOff_G_LE, &QLineEdit::textChanged, [this](const QString& value){ui->lightOff_G_S->setValue(value.toInt());}); connect(ui->lightOff_G_S, &QSlider::valueChanged, [this](const int& value){ui->lightOff_G_LE->setText(QString::number(value));}); + connect(ui->lightOff_G_S, &QSlider::valueChanged, this, &SettingsWindow::backgroundColorOffChanged); connect(ui->lightOff_B_LE, &QLineEdit::textChanged, [this](const QString& value){ui->lightOff_B_S->setValue(value.toInt());}); connect(ui->lightOff_B_S, &QSlider::valueChanged, [this](const int& value){ui->lightOff_B_LE->setText(QString::number(value));}); + connect(ui->lightOff_B_S, &QSlider::valueChanged, this, &SettingsWindow::backgroundColorOffChanged); // light on connect(ui->lightOn_R_LE, &QLineEdit::textChanged, [this](const QString& value){ui->lightOn_R_S->setValue(value.toInt());}); connect(ui->lightOn_R_S, &QSlider::valueChanged, [this](const int& value){ui->lightOn_R_LE->setText(QString::number(value));}); + connect(ui->lightOn_R_S, &QSlider::valueChanged, this, &SettingsWindow::backgroundColorOnChanged); connect(ui->lightOn_G_LE, &QLineEdit::textChanged, [this](const QString& value){ui->lightOn_G_S->setValue(value.toInt());}); connect(ui->lightOn_G_S, &QSlider::valueChanged, [this](const int& value){ui->lightOn_G_LE->setText(QString::number(value));}); + connect(ui->lightOn_G_S, &QSlider::valueChanged, this, &SettingsWindow::backgroundColorOnChanged); connect(ui->lightOn_B_LE, &QLineEdit::textChanged, [this](const QString& value){ui->lightOn_B_S->setValue(value.toInt());}); connect(ui->lightOn_B_S, &QSlider::valueChanged, [this](const int& value){ui->lightOn_B_LE->setText(QString::number(value));}); + connect(ui->lightOn_B_S, &QSlider::valueChanged, this, &SettingsWindow::backgroundColorOnChanged); // light connect(ui->light_R_LE, &QLineEdit::textChanged, [this](const QString& value){ui->light_R_S->setValue(value.toInt());}); - connect(ui->light_R_S, &QSlider::valueChanged, [this](const int& value){ui->light_R_LE->setText(QString::number(value)); if(ui->checkAutoColor->isCecked()) ui->lightOn_R_S->setValue((int)(value / 50));}); + connect(ui->light_R_S, &QSlider::valueChanged, [this](const int& value){ui->light_R_LE->setText(QString::number(value)); if(ui->checkAutoColor->isChecked()) ui->lightOn_R_S->setValue((int)(value / 50));}); + connect(ui->light_R_S, &QSlider::valueChanged, this, &SettingsWindow::lightColorChanged); connect(ui->light_G_LE, &QLineEdit::textChanged, [this](const QString& value){ui->light_G_S->setValue(value.toInt());}); - connect(ui->light_G_S, &QSlider::valueChanged, [this](const int& value){ui->light_G_LE->setText(QString::number(value)); if(ui->checkAutoColor->isCecked()) ui->lightOn_G_S->setValue((int)(value / 50));}); + connect(ui->light_G_S, &QSlider::valueChanged, [this](const int& value){ui->light_G_LE->setText(QString::number(value)); if(ui->checkAutoColor->isChecked()) ui->lightOn_G_S->setValue((int)(value / 50));}); + connect(ui->light_G_S, &QSlider::valueChanged, this, &SettingsWindow::lightColorChanged); connect(ui->light_B_LE, &QLineEdit::textChanged, [this](const QString& value){ui->light_B_S->setValue(value.toInt());}); - connect(ui->light_B_S, &QSlider::valueChanged, [this](const int& value){ui->light_B_LE->setText(QString::number(value)); if(ui->checkAutoColor->isCecked()) ui->lightOn_B_S->setValue((int)(value / 50));}); + connect(ui->light_B_S, &QSlider::valueChanged, [this](const int& value){ui->light_B_LE->setText(QString::number(value)); if(ui->checkAutoColor->isChecked()) ui->lightOn_B_S->setValue((int)(value / 50));}); + connect(ui->light_B_S, &QSlider::valueChanged, this, &SettingsWindow::lightColorChanged); connect(ui->checkAutoColor, &QCheckBox::toggled, this, &SettingsWindow::autoColorToggled); - connect(ui->radioDirectLight, &QRadioButton::toggled, this, &SettingsWindow::radioToggled); + connect(ui->ambCoef, static_cast(&QDoubleSpinBox::valueChanged), [this](double value) {emit updateAmbCoef(value); }); + connect(ui->attFac, static_cast(&QDoubleSpinBox::valueChanged), [this](double value) {emit updateAttFac(value); }); } SettingsWindow::~SettingsWindow() @@ -90,9 +98,27 @@ void SettingsWindow::radioToggled() { ui->attFac->setValue(0.0); ui->attFac->setEnabled(false); + ui->ambCoef->setEnabled(false); } else { ui->attFac->setEnabled(true); + ui->ambCoef->setEnabled(true); } } + +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())); +} +