forked from jahnf/Projecteur
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettings.cc
More file actions
195 lines (167 loc) · 6.11 KB
/
settings.cc
File metadata and controls
195 lines (167 loc) · 6.11 KB
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
// This file is part of Projecteur - https://github.com/jahnf/projecteur - See LICENSE.md and README.md
#include "settings.h"
#include <QCoreApplication>
#include <QQmlPropertyMap>
#include <QSettings>
namespace {
namespace settings {
constexpr char showSpot[] = "showSpot";
constexpr char spotSize[] = "spotSize";
constexpr char showCenterDot[] = "showCenterDot";
constexpr char dotSize[] = "dotSize";
constexpr char dotColor[] = "dotColor";
constexpr char shadeColor[] = "shadeColor";
constexpr char shadeOpacity[] = "shadeOpacity";
constexpr char screen[] = "screen";
constexpr char cursor[] = "cursor";
constexpr char spotShape[] = "spotShape";
constexpr char spotRotation[] ="spotRotation";
namespace defaultValue {
constexpr bool showSpot = true;
constexpr int spotSize = 32;
constexpr bool showCenterDot = false;
constexpr int dotSize = 5;
constexpr auto dotColor = Qt::red;
constexpr char shadeColor[] = "#222222";
constexpr double shadeOpacity = 0.3;
constexpr int screen = 0;
constexpr Qt::CursorShape cursor = Qt::BlankCursor;
constexpr char spotShape[] = "spotshapes/Circle.qml";
constexpr double spotRotation = 0.0;
}
}
}
Settings::Settings(QObject* parent)
: QObject(parent)
, m_settings(new QSettings(QCoreApplication::applicationName(),
QCoreApplication::applicationName(), this))
, m_dynamicShapeSettings(new QQmlPropertyMap(this))
, m_spotShapes{ SpotShape(::settings::defaultValue::spotShape, tr("Circle"), false),
SpotShape("spotshapes/Square.qml", tr("(Rounded) Square"), true)}
{
load();
}
Settings::~Settings()
{
}
void Settings::setDefaults()
{
setShowSpot(settings::defaultValue::showSpot);
setSpotSize(settings::defaultValue::spotSize);
setShowCenterDot(settings::defaultValue::showCenterDot);
setDotSize(settings::defaultValue::dotSize);
setDotColor(QColor(settings::defaultValue::dotColor));
setShadeColor(QColor(settings::defaultValue::shadeColor));
setShadeOpacity(settings::defaultValue::shadeOpacity);
setScreen(settings::defaultValue::screen);
setCursor(settings::defaultValue::cursor);
setSpotShape(settings::defaultValue::spotShape);
setSpotRotation(settings::defaultValue::spotRotation);
}
void Settings::load()
{
setShowSpot(m_settings->value(::settings::showSpot, settings::defaultValue::showSpot).toBool());
setSpotSize(m_settings->value(::settings::spotSize, settings::defaultValue::spotSize).toInt());
setShowCenterDot(m_settings->value(::settings::showCenterDot, settings::defaultValue::showCenterDot).toBool());
setDotSize(m_settings->value(::settings::dotSize, settings::defaultValue::dotSize).toInt());
setDotColor(m_settings->value(::settings::dotColor, QColor(settings::defaultValue::dotColor)).value<QColor>());
setShadeColor(m_settings->value(::settings::shadeColor, QColor(settings::defaultValue::shadeColor)).value<QColor>());
setShadeOpacity(m_settings->value(::settings::shadeOpacity, settings::defaultValue::shadeOpacity).toDouble());
setScreen(m_settings->value(::settings::screen, settings::defaultValue::screen).toInt());
setCursor(static_cast<Qt::CursorShape>(m_settings->value(::settings::cursor, static_cast<int>(settings::defaultValue::cursor)).toInt()));
setSpotShape(m_settings->value(::settings::spotShape, settings::defaultValue::spotShape).toString());
setSpotRotation(m_settings->value(::settings::spotRotation, settings::defaultValue::spotRotation).toDouble());
}
void Settings::setShowSpot(bool show)
{
if (show == m_showSpot)
return;
m_showSpot = show;
m_settings->setValue(::settings::showSpot, m_showSpot);
emit showSpotChanged(m_showSpot);
}
void Settings::setSpotSize(int size)
{
if (size == m_spotSize)
return;
m_spotSize = qMin(qMax(3, size), 100);
m_settings->setValue(::settings::spotSize, m_spotSize);
emit spotSizeChanged(m_spotSize);
}
void Settings::setShowCenterDot(bool show)
{
if (show == m_showCenterDot)
return;
m_showCenterDot = show;
m_settings->setValue(::settings::showCenterDot, m_showCenterDot);
emit showCenterDotChanged(m_showCenterDot);
}
void Settings::setDotSize(int size)
{
if (size == m_dotSize)
return;
m_dotSize = qMin(qMax(3, size), 100);
m_settings->setValue(::settings::dotSize, m_dotSize);
emit dotSizeChanged(m_dotSize);
}
void Settings::setDotColor(const QColor& color)
{
if (color == m_dotColor)
return;
m_dotColor = color;
m_settings->setValue(::settings::dotColor, m_dotColor);
emit dotColorChanged(m_dotColor);
}
void Settings::setShadeColor(const QColor& color)
{
if (color == m_shadeColor)
return;
m_shadeColor = color;
m_settings->setValue(::settings::shadeColor, m_shadeColor);
emit shadeColorChanged(m_shadeColor);
}
void Settings::setShadeOpacity(double opacity)
{
if (opacity > m_shadeOpacity || opacity < m_shadeOpacity)
{
m_shadeOpacity = qMin(qMax(0.0, opacity), 1.0);
m_settings->setValue(::settings::shadeOpacity, m_shadeOpacity);
emit shadeOpacityChanged(m_shadeOpacity);
}
}
void Settings::setScreen(int screen)
{
if (screen == m_screen)
return;
m_screen = qMin(qMax(0, screen), 10);
m_settings->setValue(::settings::screen, m_screen);
emit screenChanged(m_screen);
}
void Settings::setCursor(Qt::CursorShape cursor)
{
if (cursor == m_cursor)
return;
m_cursor = qMin(qMax(static_cast<Qt::CursorShape>(0), cursor), Qt::LastCursor);
m_settings->setValue(::settings::cursor, static_cast<int>(m_cursor));
emit cursorChanged(m_cursor);
}
void Settings::setSpotShape(const QString& spotShapeQmlComponent)
{
if (m_spotShape == spotShapeQmlComponent)
return;
m_spotShape = spotShapeQmlComponent;
m_settings->setValue(::settings::spotShape, m_spotShape);
emit spotShapeChanged(m_spotShape);
}
void Settings::setSpotRotation(double rotation)
{
if (rotation > m_spotRotation || rotation < m_spotRotation)
{
m_spotRotation = qMin(qMax(0.0, rotation), 360.0);
m_settings->setValue(::settings::spotRotation, m_spotRotation);
emit spotRotationChanged(m_spotRotation);
}
}
QObject* Settings::shapeSettings() const {
return m_dynamicShapeSettings;
}