Wed, 15 Jun 2022 13:03:33 +0300
Add About Qt menu entry
218
63125c36de73
Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff
changeset
|
1 | #ifndef SETTINGS_H |
63125c36de73
Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff
changeset
|
2 | #define SETTINGS_H |
63125c36de73
Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff
changeset
|
3 | #include <QSettings> |
221
e28f89b8ccdf
simplify settings further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
220
diff
changeset
|
4 | #include <QMdiArea> |
e28f89b8ccdf
simplify settings further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
220
diff
changeset
|
5 | #include "libraries.h" |
e28f89b8ccdf
simplify settings further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
220
diff
changeset
|
6 | #include "gl/common.h" |
218
63125c36de73
Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff
changeset
|
7 | |
63125c36de73
Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff
changeset
|
8 | // SettingType - get type of setting by enumerator |
221
e28f89b8ccdf
simplify settings further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
220
diff
changeset
|
9 | template<typename> |
e28f89b8ccdf
simplify settings further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
220
diff
changeset
|
10 | struct SettingId{}; |
e28f89b8ccdf
simplify settings further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
220
diff
changeset
|
11 | |
e28f89b8ccdf
simplify settings further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
220
diff
changeset
|
12 | template<SettingId> |
220
a6d937f8c0ac
Further reduce settings.h
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
219
diff
changeset
|
13 | struct SettingInfo{}; |
218
63125c36de73
Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff
changeset
|
14 | |
63125c36de73
Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff
changeset
|
15 | #define SETTING(NAME, DEFVALUE) \ |
221
e28f89b8ccdf
simplify settings further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
220
diff
changeset
|
16 | namespace SettingIdTypes { class NAME; } \ |
e28f89b8ccdf
simplify settings further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
220
diff
changeset
|
17 | namespace Setting { constexpr SettingId<class NAME##_SettingType> NAME; } \ |
218
63125c36de73
Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff
changeset
|
18 | template<> \ |
220
a6d937f8c0ac
Further reduce settings.h
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
219
diff
changeset
|
19 | struct SettingInfo<Setting::NAME> \ |
218
63125c36de73
Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff
changeset
|
20 | { \ |
63125c36de73
Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff
changeset
|
21 | using type = decltype((DEFVALUE)); \ |
220
a6d937f8c0ac
Further reduce settings.h
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
219
diff
changeset
|
22 | static constexpr char name[] = #NAME; \ |
a6d937f8c0ac
Further reduce settings.h
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
219
diff
changeset
|
23 | static const auto& defaultValue() { \ |
a6d937f8c0ac
Further reduce settings.h
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
219
diff
changeset
|
24 | static const auto value = DEFVALUE; \ |
a6d937f8c0ac
Further reduce settings.h
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
219
diff
changeset
|
25 | return value; \ |
a6d937f8c0ac
Further reduce settings.h
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
219
diff
changeset
|
26 | }; \ |
218
63125c36de73
Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff
changeset
|
27 | }; |
221
e28f89b8ccdf
simplify settings further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
220
diff
changeset
|
28 | |
e28f89b8ccdf
simplify settings further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
220
diff
changeset
|
29 | // ----------------------------------------------------------------------------- |
e28f89b8ccdf
simplify settings further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
220
diff
changeset
|
30 | // Setting definitions |
e28f89b8ccdf
simplify settings further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
220
diff
changeset
|
31 | |
e28f89b8ccdf
simplify settings further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
220
diff
changeset
|
32 | // Rendering options |
224
54fd83d4db9c
GCC doesn't like me using QStringLiteral here
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
221
diff
changeset
|
33 | SETTING(Locale, QString{"system"}) |
221
e28f89b8ccdf
simplify settings further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
220
diff
changeset
|
34 | SETTING(BackgroundColor, (QColor{48, 48, 48})) |
e28f89b8ccdf
simplify settings further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
220
diff
changeset
|
35 | SETTING(MainColor, (QColor{255, 255, 64})) |
e28f89b8ccdf
simplify settings further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
220
diff
changeset
|
36 | SETTING(SelectedColor, (QColor{32, 32, 224})) |
e28f89b8ccdf
simplify settings further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
220
diff
changeset
|
37 | SETTING(LineThickness, 2.0f) |
e28f89b8ccdf
simplify settings further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
220
diff
changeset
|
38 | SETTING(LineAntiAliasing, true) |
e28f89b8ccdf
simplify settings further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
220
diff
changeset
|
39 | SETTING(RenderStyle, gl::RenderStyle::Normal) |
e28f89b8ccdf
simplify settings further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
220
diff
changeset
|
40 | SETTING(DrawWireframe, false) |
e28f89b8ccdf
simplify settings further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
220
diff
changeset
|
41 | SETTING(DrawAxes, true) |
e28f89b8ccdf
simplify settings further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
220
diff
changeset
|
42 | SETTING(MainWindowGeometry, QByteArray{}) |
e28f89b8ccdf
simplify settings further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
220
diff
changeset
|
43 | SETTING(MainSplitterState, QByteArray{}) |
e28f89b8ccdf
simplify settings further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
220
diff
changeset
|
44 | SETTING(RecentFiles, QStringList{}) |
e28f89b8ccdf
simplify settings further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
220
diff
changeset
|
45 | SETTING(ViewMode, QMdiArea::TabbedView) |
e28f89b8ccdf
simplify settings further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
220
diff
changeset
|
46 | |
e28f89b8ccdf
simplify settings further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
220
diff
changeset
|
47 | // File management options |
e28f89b8ccdf
simplify settings further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
220
diff
changeset
|
48 | SETTING(Libraries, QVector<Library>{}) |
e28f89b8ccdf
simplify settings further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
220
diff
changeset
|
49 | |
e28f89b8ccdf
simplify settings further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
220
diff
changeset
|
50 | // End of setting definitions |
e28f89b8ccdf
simplify settings further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
220
diff
changeset
|
51 | // ----------------------------------------------------------------------------- |
218
63125c36de73
Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff
changeset
|
52 | #undef SETTING |
63125c36de73
Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff
changeset
|
53 | |
221
e28f89b8ccdf
simplify settings further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
220
diff
changeset
|
54 | template<SettingId X> |
220
a6d937f8c0ac
Further reduce settings.h
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
219
diff
changeset
|
55 | using SettingType_t = typename SettingInfo<X>::type; |
218
63125c36de73
Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff
changeset
|
56 | static_assert(std::is_same_v<SettingType_t<Setting::DrawAxes>, bool>); |
63125c36de73
Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff
changeset
|
57 | |
221
e28f89b8ccdf
simplify settings further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
220
diff
changeset
|
58 | template<SettingId X> |
220
a6d937f8c0ac
Further reduce settings.h
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
219
diff
changeset
|
59 | const char* settingName = SettingInfo<X>::name; |
a6d937f8c0ac
Further reduce settings.h
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
219
diff
changeset
|
60 | |
221
e28f89b8ccdf
simplify settings further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
220
diff
changeset
|
61 | template<SettingId X> |
220
a6d937f8c0ac
Further reduce settings.h
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
219
diff
changeset
|
62 | inline auto settingDefaultValue() |
a6d937f8c0ac
Further reduce settings.h
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
219
diff
changeset
|
63 | { |
a6d937f8c0ac
Further reduce settings.h
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
219
diff
changeset
|
64 | return SettingInfo<X>::defaultValue(); |
a6d937f8c0ac
Further reduce settings.h
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
219
diff
changeset
|
65 | } |
a6d937f8c0ac
Further reduce settings.h
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
219
diff
changeset
|
66 | |
218
63125c36de73
Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff
changeset
|
67 | // get() - get setting by enumerator |
221
e28f89b8ccdf
simplify settings further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
220
diff
changeset
|
68 | template<SettingId X> |
218
63125c36de73
Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff
changeset
|
69 | inline SettingType_t<X> setting() |
63125c36de73
Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff
changeset
|
70 | { |
220
a6d937f8c0ac
Further reduce settings.h
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
219
diff
changeset
|
71 | static const QVariant defvariant = QVariant::fromValue(settingDefaultValue<X>()); |
a6d937f8c0ac
Further reduce settings.h
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
219
diff
changeset
|
72 | const QVariant var = QSettings{}.value(settingName<X>, defvariant); |
a6d937f8c0ac
Further reduce settings.h
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
219
diff
changeset
|
73 | return var.value<SettingType_t<X>>(); |
218
63125c36de73
Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff
changeset
|
74 | } |
63125c36de73
Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff
changeset
|
75 | |
219 | 76 | // setSetting() - set value of setting |
221
e28f89b8ccdf
simplify settings further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
220
diff
changeset
|
77 | template<SettingId X> |
218
63125c36de73
Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff
changeset
|
78 | inline void setSetting(const SettingType_t<X>& value) |
63125c36de73
Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff
changeset
|
79 | { |
220
a6d937f8c0ac
Further reduce settings.h
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
219
diff
changeset
|
80 | if (value == settingDefaultValue<X>()) { |
a6d937f8c0ac
Further reduce settings.h
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
219
diff
changeset
|
81 | QSettings{}.remove(settingName<X>); |
218
63125c36de73
Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff
changeset
|
82 | } |
63125c36de73
Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff
changeset
|
83 | else { |
220
a6d937f8c0ac
Further reduce settings.h
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
219
diff
changeset
|
84 | QSettings{}.setValue(settingName<X>, QVariant::fromValue(value)); |
218
63125c36de73
Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff
changeset
|
85 | } |
63125c36de73
Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff
changeset
|
86 | } |
63125c36de73
Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff
changeset
|
87 | |
63125c36de73
Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff
changeset
|
88 | #endif // SETTINGS_H |