forked from jahnf/Projecteur
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings.h
145 lines (131 loc) · 5.78 KB
/
settings.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
// This file is part of Projecteur - https://github.com/jahnf/projecteur - See LICENSE.md and README.md
# pragma once
#include <QColor>
#include <QObject>
#include <QVariant>
class QSettings;
class QQmlPropertyMap;
class Settings : public QObject
{
Q_OBJECT
Q_PROPERTY(bool showSpot READ showSpot WRITE setShowSpot NOTIFY showSpotChanged)
Q_PROPERTY(int spotSize READ spotSize WRITE setSpotSize NOTIFY spotSizeChanged)
Q_PROPERTY(bool showCenterDot READ showCenterDot WRITE setShowCenterDot NOTIFY showCenterDotChanged)
Q_PROPERTY(int dotSize READ dotSize WRITE setDotSize NOTIFY dotSizeChanged)
Q_PROPERTY(QColor dotColor READ dotColor WRITE setDotColor NOTIFY dotColorChanged)
Q_PROPERTY(QColor shadeColor READ shadeColor WRITE setShadeColor NOTIFY shadeColorChanged)
Q_PROPERTY(double shadeOpacity READ shadeOpacity WRITE setShadeOpacity NOTIFY shadeOpacityChanged)
Q_PROPERTY(int screen READ screen WRITE setScreen NOTIFY screenChanged)
Q_PROPERTY(Qt::CursorShape cursor READ cursor WRITE setCursor NOTIFY cursorChanged)
Q_PROPERTY(QString spotShape READ spotShape WRITE setSpotShape NOTIFY spotShapeChanged)
Q_PROPERTY(double spotRotation READ spotRotation WRITE setSpotRotation NOTIFY spotRotationChanged)
Q_PROPERTY(QObject* shapes READ shapeSettingsRootObject CONSTANT)
Q_PROPERTY(bool spotRotationAllowed READ spotRotationAllowed NOTIFY spotRotationAllowedChanged)
public:
explicit Settings(QObject* parent = nullptr);
virtual ~Settings() override;
void setDefaults();
bool showSpot() const { return m_showSpot; }
void setShowSpot(bool show);
int spotSize() const { return m_spotSize; }
void setSpotSize(int size);
bool showCenterDot() const { return m_showCenterDot; }
void setShowCenterDot(bool show);
int dotSize() const { return m_dotSize; }
void setDotSize(int size);
QColor dotColor() const { return m_dotColor; }
void setDotColor(const QColor& color);
QColor shadeColor() const { return m_shadeColor; }
void setShadeColor(const QColor& color);
double shadeOpacity() const { return m_shadeOpacity; }
void setShadeOpacity(double opacity);
int screen() const { return m_screen; }
void setScreen(int screen);
Qt::CursorShape cursor() const { return m_cursor; }
void setCursor(Qt::CursorShape cursor);
QString spotShape() const { return m_spotShape; }
void setSpotShape(const QString& spotShapeQmlComponent);
double spotRotation() const { return m_spotRotation; }
void setSpotRotation(double rotation);
bool spotRotationAllowed() const;
class SpotShapeSetting {
public:
SpotShapeSetting(const QString& displayName, const QString& key, const QVariant& defaultValue,
const QVariant& minValue, const QVariant& maxValue, int decimals = 0)
: m_displayName(displayName), m_settingsKey(key), m_minValue(minValue),
m_maxValue(maxValue), m_defaultValue(defaultValue), m_decimals(decimals) {}
const QString& displayName() const { return m_displayName; }
const QString& settingsKey() const { return m_settingsKey; }
const QVariant& minValue() const { return m_minValue; }
const QVariant& maxValue() const { return m_maxValue; }
const QVariant& defaultValue() const { return m_defaultValue; }
int decimals() const { return m_decimals; }
private:
QString m_displayName;
QString m_settingsSection;
QString m_settingsKey;
QVariant m_minValue = 0;
QVariant m_maxValue = 100;
QVariant m_defaultValue = m_minValue;
int m_decimals = 0;
};
class SpotShape {
public:
QString qmlComponent() const { return m_qmlComponent; }
QString name() const { return m_name; }
QString displayName() const { return m_displayName; }
bool allowRotation() const { return m_allowRotation; }
const QList<SpotShapeSetting>& shapeSettings() const { return m_shapeSettings; }
private:
SpotShape(const QString& qmlComponent, const QString& name,
const QString& displayName, bool allowRotation, QList<SpotShapeSetting> shapeSettings= {})
: m_qmlComponent(qmlComponent), m_name(name), m_displayName(displayName), m_allowRotation(allowRotation),
m_shapeSettings(std::move(shapeSettings)){}
QString m_qmlComponent;
QString m_name;
QString m_displayName;
bool m_allowRotation = true;
QList<SpotShapeSetting> m_shapeSettings;
friend class Settings;
};
const QList<SpotShape>& spotShapes() const { return m_spotShapes; }
QQmlPropertyMap* shapeSettings(const QString& shapeName);
signals:
void showSpotChanged(bool show);
void spotSizeChanged(int size);
void dotSizeChanged(int size);
void showCenterDotChanged(bool show);
void dotColorChanged(const QColor& color);
void shadeColorChanged(const QColor& color);
void shadeOpacityChanged(double opcacity);
void screenChanged(int screen);
void cursorChanged(Qt::CursorShape cursor);
void spotShapeChanged(const QString& spotShapeQmlComponent);
void spotRotationChanged(double rotation);
void spotRotationAllowedChanged(bool allowed);
private:
QSettings* m_settings = nullptr;
QMap<QString, QQmlPropertyMap*> m_shapeSettings;
QQmlPropertyMap* m_shapeSettingsRoot;
bool m_showSpot = true;
int m_spotSize = 30; ///< Spot size in percentage of available screen height, but at least 50 pixels.
bool m_showCenterDot = false;
int m_dotSize = 5; ///< Center Dot Size (3-100 pixels)
QColor m_dotColor;
QColor m_shadeColor;
double m_shadeOpacity = 0.3;
int m_screen = 0;
Qt::CursorShape m_cursor = Qt::BlankCursor;
QString m_spotShape;
double m_spotRotation = 0.0;
const QList<SpotShape> m_spotShapes;
bool m_spotRotationAllowed = false;
private:
void load();
QObject* shapeSettingsRootObject();
void shapeSettingsPopulateRoot();
void shapeSettingsInitialize();
void shapeSettingsSetDefaults();
void shapeSettingsLoad();
void setSpotRotationAllowed(bool allowed);
};