-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSettings.h
119 lines (93 loc) · 3.28 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
/*
* Foreign Language Trainer is a program to study foreign languages through
* various exercises.
*
* Copyright (C) 2019 Sergey Kovalev
* https://github.com/skvl/flt
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef SETTINGS_H
#define SETTINGS_H
#include <QDateTime>
#include <QQmlApplicationEngine>
#include <QSettings>
#include <QTranslator>
class Settings : public QSettings
{
Q_OBJECT
Q_PROPERTY(QString userName READ userName WRITE setUserName NOTIFY userNameChanged)
Q_PROPERTY(QString userSirname READ userSirname WRITE setUserSirname NOTIFY userSirnameChanged)
Q_PROPERTY(QString theme READ theme WRITE setTheme NOTIFY themeChanged)
Q_PROPERTY(QVariant history READ history NOTIFY historyChanged)
Q_PROPERTY(int level READ level WRITE setLevel NOTIFY levelChanged)
Q_PROPERTY(QString levelDescription READ levelDescription NOTIFY levelDescriptionChanged)
Q_PROPERTY(QString language READ language WRITE setLanguage NOTIFY languageChanged)
public:
enum Levels {
Audio = 1,
Text,
NoClues,
};
Settings(QQmlApplicationEngine *engine, const QString &organization, const QString &application = QString(), QObject *parent = nullptr);
~Settings();
Q_INVOKABLE void save();
Q_INVOKABLE void load();
Q_INVOKABLE void saveResult(QDateTime date, int correct, int total, int elapsed);
QString userName() const;
void setUserName(const QString &userName);
QString userSirname() const;
void setUserSirname(const QString &userSirname);
QString theme() const;
void setTheme(const QString &theme);
QVariant history();
int level() const;
void setLevel(const int level);
static enum Levels toLevels(int level);
static QString toString(enum Levels level);
static QString toString(int level);
QString levelDescription() const;
QString language() const;
void setLanguage(const QString &language);
signals:
void userNameChanged();
void userSirnameChanged();
void themeChanged();
void historyChanged();
void levelChanged();
void levelDescriptionChanged();
void languageChanged();
private:
enum {
AppInfo,
Language,
Theme,
Level,
UserInfo,
UserName,
UserSirname,
HistoryInfo,
HistoryCount,
HistoryRecord,
};
static const QHash<int, QString> keys;
QString m_userName;
QString m_userSirname;
QString m_language;
QString m_theme;
enum Levels m_level;
QList<QString> m_levelDescription;
QTranslator m_translator;
QQmlApplicationEngine *m_engine;
QString parseValue(QString kv, QString key) const;
void loadTranslator();
};
#endif // SETTINGS_H