-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathsettings.cpp
More file actions
158 lines (131 loc) · 5.21 KB
/
settings.cpp
File metadata and controls
158 lines (131 loc) · 5.21 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
// SPDX-FileCopyrightText: 2014-2025 Thorsten Roth
// SPDX-License-Identifier: GPL-3.0-or-later
#include "./settings.h"
#include <QDebug>
#include <QDir>
#include <QGuiApplication>
Settings *Settings::instance() {
static Settings _instance;
return &_instance;
}
Settings::Settings(QObject *pParent)
: QObject(pParent),
#if defined _WIN32
m_settings(QSettings::IniFormat, QSettings::UserScope,
qApp->applicationName().toLower(),
qApp->applicationName().toLower())
#else
m_settings(QSettings::NativeFormat, QSettings::UserScope,
qApp->applicationName().toLower(),
qApp->applicationName().toLower())
#endif
{
}
// ----------------------------------------------------------------------------
auto Settings::getSharePath() const -> QString { return m_sSharePath; }
void Settings::setSharePath(const QString &sPath) { m_sSharePath = sPath; }
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
auto Settings::getMouseControls() -> QList<uint> {
QList<uint> listMouseControls;
m_settings.beginGroup(QStringLiteral("MouseControls"));
listMouseControls
<< m_settings.value(QStringLiteral("MoveBlock"), Qt::LeftButton).toUInt();
listMouseControls << m_settings
.value(QStringLiteral("RotateBlock"),
(quint8(Qt::Vertical) | Settings::SHIFT))
.toUInt();
listMouseControls << m_settings
.value(QStringLiteral("FlipBlock"), Qt::RightButton)
.toUInt();
m_settings.endGroup();
return listMouseControls;
}
void Settings::setMouseControls(const QList<uint> &mouseControls) {
if (mouseControls.size() == 3) {
m_settings.beginGroup(QStringLiteral("MouseControls"));
m_settings.setValue(QStringLiteral("MoveBlock"), mouseControls[0]);
m_settings.setValue(QStringLiteral("RotateBlock"), mouseControls[1]);
m_settings.setValue(QStringLiteral("FlipBlock"), mouseControls[2]);
m_settings.remove(QStringLiteral("Enabled"));
m_settings.endGroup();
} else {
qWarning() << "Mouse controls couldn't be saved!";
}
}
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
auto Settings::getGuiLanguage() -> QString {
QString sGuiLanguage =
m_settings.value(QStringLiteral("GuiLanguage"), QStringLiteral("auto"))
.toString();
if ("auto" == sGuiLanguage) {
#ifdef Q_OS_UNIX
QByteArray lang = qgetenv("LANG");
if (!lang.isEmpty()) {
return QLocale(QString::fromLatin1(lang)).name();
}
#endif
return QLocale::system().name();
}
if (!QFile(":/" + qApp->applicationName().toLower() + "_" + sGuiLanguage +
".qm")
.exists() &&
!QFile(this->getSharePath() + "/lang/" +
qApp->applicationName().toLower() + "_" + sGuiLanguage + ".qm")
.exists()) {
sGuiLanguage = QStringLiteral("en");
m_settings.setValue(QStringLiteral("GuiLanguage"), sGuiLanguage);
return sGuiLanguage;
}
return sGuiLanguage;
}
void Settings::setGuiLanguage(const QString &sGuiLanguage) {
QString sOldGuiLang = this->getGuiLanguage();
m_settings.setValue(QStringLiteral("GuiLanguage"), sGuiLanguage);
if (sOldGuiLang != sGuiLanguage) {
emit changeGuiLanguage(this->getGuiLanguage());
}
}
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
auto Settings::getUseSystemBackground() const -> bool {
return m_settings.value(QStringLiteral("UseSystemBackground"), false)
.toBool();
}
void Settings::setUseSystemBackground(const bool bUseSystemBackground) {
bool bOldValue = this->getUseSystemBackground();
m_settings.setValue(QStringLiteral("UseSystemBackground"),
bUseSystemBackground);
if (bOldValue != bUseSystemBackground) {
emit updateUseSystemBackgroundColor(bUseSystemBackground);
}
}
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
auto Settings::getLastOpenedDir() -> QString {
return m_settings
.value(QStringLiteral("LastOpenedDir"), QString(QDir::homePath()))
.toString();
}
void Settings::setLastOpenedDir(const QString &sLastOpenedDir) {
m_settings.setValue(QStringLiteral("LastOpenedDir"), sLastOpenedDir);
}
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
auto Settings::getThresholdEasy() const -> uint {
uint nEasy =
m_settings
.value(QStringLiteral("ThresholdEasy"), Settings::THRESHOLD_EASY)
.toUInt();
if (0 == nEasy) nEasy = Settings::THRESHOLD_EASY;
return nEasy;
}
auto Settings::getThresholdHard() const -> uint {
uint nHard =
m_settings
.value(QStringLiteral("ThresholdHard"), Settings::THRESHOLD_HARD)
.toUInt();
if (0 == nHard) nHard = Settings::THRESHOLD_HARD;
return nHard;
}