-
-
Notifications
You must be signed in to change notification settings - Fork 877
Expand file tree
/
Copy pathApplicationSettings.cpp
More file actions
98 lines (83 loc) · 3.99 KB
/
ApplicationSettings.cpp
File metadata and controls
98 lines (83 loc) · 3.99 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
/*
* This file is part of Notepad Next.
* Copyright 2024 Justin Dailey
*
* Notepad Next 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.
*
* Notepad Next 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 Notepad Next. If not, see <https://www.gnu.org/licenses/>.
*/
#include "ApplicationSettings.h"
#include <QApplication>
#include <QFont>
#include <QStyleHints>
#define CREATE_SETTING(group, name, lname, type, default) \
ApplicationSetting<type> name{#group "/" #name, default};\
type ApplicationSettings::lname() const\
{\
return get(name);\
}\
void ApplicationSettings::set##name(type lname)\
{\
set(name, lname);\
emit lname##Changed(lname);\
}
ApplicationSettings::ApplicationSettings(QObject *parent)
: QSettings{parent}
{
// Translate user-facing theme changes and OS-level color-scheme changes
// into a single effectiveDarkModeChanged signal that consumers listen for.
connect(this, &ApplicationSettings::themeChanged, this, [this](ThemeMode) {
emit effectiveDarkModeChanged(effectiveDarkMode());
});
if (auto *hints = QGuiApplication::styleHints()) {
connect(hints, &QStyleHints::colorSchemeChanged, this, [this](Qt::ColorScheme) {
if (theme() == SystemTheme)
emit effectiveDarkModeChanged(effectiveDarkMode());
});
}
}
bool ApplicationSettings::effectiveDarkMode() const
{
switch (theme()) {
case LightTheme: return false;
case DarkTheme: return true;
case SystemTheme:
default:
return QGuiApplication::styleHints()->colorScheme() == Qt::ColorScheme::Dark;
}
}
CREATE_SETTING(Gui, ShowMenuBar, showMenuBar, bool, true)
CREATE_SETTING(Gui, ShowToolBar, showToolBar, bool, true)
CREATE_SETTING(Gui, ShowTabBar, showTabBar, bool, true)
CREATE_SETTING(Gui, ShowStatusBar, showStatusBar, bool, true)
CREATE_SETTING(Gui, CenterSearchDialog, centerSearchDialog, bool, true)
CREATE_SETTING(Gui, TabsClosable, tabsClosable, bool, true)
CREATE_SETTING(Gui, ExitOnLastTabClosed, exitOnLastTabClosed, bool, false)
CREATE_SETTING(Gui, CombineSearchResults, combineSearchResults, bool, false)
CREATE_SETTING(App, RestorePreviousSession, restorePreviousSession, bool, false)
CREATE_SETTING(App, RestoreUnsavedFiles, restoreUnsavedFiles, bool, false)
CREATE_SETTING(App, RestoreTempFiles, restoreTempFiles, bool, false)
CREATE_SETTING(App, DefaultDirectoryBehavior, defaultDirectoryBehavior, ApplicationSettings::DefaultDirectoryBehaviorEnum, ApplicationSettings::FollowCurrentDocument)
CREATE_SETTING(App, DefaultDirectory, defaultDirectory, QString, QString())
CREATE_SETTING(App, Translation, translation, QString, QStringLiteral(""))
CREATE_SETTING(Editor, ShowWhitespace, showWhitespace, bool, false);
CREATE_SETTING(Editor, ShowEndOfLine, showEndOfLine, bool, false);
CREATE_SETTING(Editor, ShowWrapSymbol, showWrapSymbol, bool, false);
CREATE_SETTING(Editor, ShowIndentGuide, showIndentGuide, bool, true);
CREATE_SETTING(Editor, WordWrap, wordWrap, bool, false)
CREATE_SETTING(Editor, FontName, fontName, QString, QStringLiteral("Courier New"))
CREATE_SETTING(Editor, FontSize, fontSize, int, []() { return qApp->font().pointSize() + 2; })
CREATE_SETTING(Editor, AdditionalWordChars, additionalWordChars, QString, QStringLiteral(""));
CREATE_SETTING(Editor, DefaultEOLMode, defaultEOLMode, QString, QStringLiteral(""))
CREATE_SETTING(Editor, URLHighlighting, urlHighlighting, bool, true)
CREATE_SETTING(Editor, ShowLineNumbers, showLineNumbers, bool, true)
CREATE_SETTING(Gui, Theme, theme, ApplicationSettings::ThemeMode, ApplicationSettings::SystemTheme)