most settings are saved and restored

This commit is contained in:
Anakin
2017-02-08 14:29:22 +01:00
parent 49585945c3
commit fa75e17d58
6 changed files with 376 additions and 26 deletions

View File

@@ -23,19 +23,19 @@ private:
QOpenGLShaderProgram m_program;
GeometryEngine *m_dataEngine;
QVector4D m_backgroundColorOn = { 0.02f, 0.02f, 0.02f, 1.0f };
QVector4D m_backgroundColorOff = { 0.5f, 0.8f, 1.0f, 1.0f };
QVector4D m_backgroundColorOn;
QVector4D m_backgroundColorOff;
bool m_wireframe = false;
bool m_lightOn = false;
bool m_backfaceCulling = false;
bool m_wireframe;
bool m_lightOn;
bool m_backfaceCulling;
struct {
QVector4D position = { 1,1,1,0 };
QVector3D intensities = { 1.0,1.0,1.0 };
float attenuationFactor = 0.0f;
float ambientCoefficient = 0.005f;
bool headlight = false;
QVector4D position;
QVector3D intensities;
float attenuationFactor;
float ambientCoefficient;
bool headlight;
} m_light;
struct {
@@ -51,6 +51,7 @@ private:
// functions
private:
void setDefaultValues();
void initShaders();
void resetView();
void updateLightPosition();
@@ -89,5 +90,10 @@ public slots:
void setHeadlight(bool value);
void setBackfaceCulling(bool value);
// signals
signals:
void lightChanged(bool value);
};

View File

@@ -0,0 +1,72 @@
#pragma once
#include <QObject>
#include <QFile>
#include <QVector3D>
#include <QVector4D>
class SettingsManager : public QObject
{
Q_OBJECT
private:
SettingsManager(QObject *parent = Q_NULLPTR);
public:
SettingsManager(SettingsManager const&) = delete;
void operator=(SettingsManager const&) = delete;
~SettingsManager();
static SettingsManager* getInstance(QObject *parent = Q_NULLPTR);
// attributes
private:
QFile file;
QVector3D m_bgColorOn = { 5, 5, 5 };
QVector3D m_bgColorOff = { 128, 204, 255 };
bool m_bfCulling = false;
bool m_light = false;
int m_lightType = 1; // 1 = direct, 2 = point
QVector3D m_lightColor = { 255,255,255 };
float m_attenuation = 0.0f;
float m_ambient = 0.005f;
bool m_headlight = false;
bool m_autoColor = true;
// functions
private:
void readFromFile();
void writeToFile();
public:
QVector3D getBgColorOn() const;
QVector3D getBgColorOff() const;
bool isBfCulling() const;
bool isLight() const;
int getLightType() const;
QVector3D getLightColor() const;
float getAttenuation() const;
float getAmbient() const;
bool isHeadlight() const;
bool isAutoColor() const;
// slots
public:
void setBgColorOn(QVector3D value);
void setBgColorOff(QVector3D value);
void setBfCulling(bool value);
void setLight(bool value);
void setLightType(int value);
void setLightColor(QVector3D value);
void setAttenuation(double value);
void setAmbient(double value);
void setHeadlight(bool value);
void setAutoColor(int value);
};

View File

@@ -9,7 +9,7 @@ class SettingsWindow : public QWidget
Q_OBJECT
public:
SettingsWindow(QVector3D bgOffColor, QVector3D bgOnColor, QVector3D lightColor, bool autoColor, double ambCoef, double attFac, int lightType, QWidget * parent = Q_NULLPTR);
SettingsWindow(QWidget * parent = Q_NULLPTR);
~SettingsWindow();
private:
@@ -33,5 +33,6 @@ signals:
void sendHeadlight(bool value);
void sendBackfaceCulling(bool value);
void sendZommSpeed(int percent);
void changeLightType(int value);
};