Debian Codegraph @

Source/Core/DolphinQt/Settings.cpp

raw symbols SCIP
1 // Copyright 2015 Dolphin Emulator Project
2 // SPDX-License-Identifier: GPL-2.0-or-later
3
4 #include "DolphinQt/Settings.h"
5
6 #include <atomic>
7 #include <memory>
8
9 #include <QApplication>
10 #include <QColor>
11 #include <QDir>
12 #include <QFile>
13 #include <QFileInfo>
14 #include <QFontDatabase>
15 #include <QPalette>
16 #include <QRadioButton>
17 #include <QSize>
18 #include <QStyle>
19 #include <QStyleHints>
20 #include <QThread>
21 #include <QWidget>
22
23 #include "AudioCommon/AudioCommon.h"
24
25 #include "Common/Config/Config.h"
26 #include "Common/Contains.h"
27 #include "Common/FileUtil.h"
28
29 #include "Core/AchievementManager.h"
30 #include "Core/Config/GraphicsSettings.h"
31 #include "Core/Config/MainSettings.h"
32 #include "Core/ConfigManager.h"
33 #include "Core/Core.h"
34 #include "Core/IOS/IOS.h"
35 #include "Core/NetPlayClient.h"
36 #include "Core/NetPlayServer.h"
37 #include "Core/System.h"
38
39 #include "DolphinQt/QtUtils/QueueOnObject.h"
40
41 #include "InputCommon/ControllerInterface/ControllerInterface.h"
42
43 #include "VideoCommon/NetPlayChatUI.h"
44 #include "VideoCommon/NetPlayGolfUI.h"
45
46 static std::unique_ptr<QPalette> s_default_palette;
47
48 Settings::Settings()
49 {
50 qRegisterMetaType<Core::State>();
51 m_core_state_changed_hook = Core::AddOnStateChangedCallback([this](Core::State new_state) {
52 QueueOnObject(this, [this, new_state] {
53 // Avoid signal spam while continuously frame stepping. Will still send a signal for the first
54 // and last framestep.
55 if (!m_continuously_frame_stepping)
56 emit EmulationStateChanged(new_state);
57 });
58 });
59
60 m_config_changed_callback_id = Config::AddConfigChangedCallback([this] {
61 static std::atomic<bool> do_once{true};
62 if (do_once.exchange(false))
63 {
64 // Calling ConfigChanged() with a "delay" can have risks, for example, if from
65 // code we change some configs that result in Qt greying out some setting, we could
66 // end up editing that setting before its greyed out, sending out an event,
67 // which might not be expected or handled by the code, potentially crashing.
68 // The only safe option would be to wait on the Qt thread to have finished executing this.
69 QueueOnObject(this, [this] {
70 do_once = true;
71 emit ConfigChanged();
72 });
73 }
74 });
75
76 m_hotplug_event_hook = g_controller_interface.RegisterDevicesChangedCallback([this] {
77 if (qApp->thread() == QThread::currentThread())
78 {
79 emit DevicesChanged();
80 }
81 else
82 {
83 // Any device shared_ptr in the host thread needs to be released immediately as otherwise
84 // they'd continue living until the queued event has run, but some devices can't be recreated
85 // until they are destroyed.
86 // This is safe from any thread. Devices will be refreshed and re-acquired and in
87 // DevicesChanged(). Calling it without queueing shouldn't cause any deadlocks but is slow.
88 emit ReleaseDevices();
89
90 QueueOnObject(this, [this] { emit DevicesChanged(); });
91 }
92 });
93 }
94
95 Settings::~Settings()
96 {
97 Config::RemoveConfigChangedCallback(m_config_changed_callback_id);
98 }
99
100 void Settings::UnregisterDevicesChangedCallback()
101 {
102 m_hotplug_event_hook.reset();
103 }
104
105 Settings& Settings::Instance()
106 {
107 static Settings settings;
108 return settings;
109 }
110
111 QSettings& Settings::GetQSettings()
112 {
113 static QSettings settings(
114 QStringLiteral("%1/Qt.ini").arg(QString::fromStdString(File::GetUserPath(D_CONFIG_IDX))),
115 QSettings::IniFormat);
116 return settings;
117 }
118
119 void Settings::TriggerThemeChanged()
120 {
121 emit ThemeChanged();
122 }
123
124 QString Settings::GetUserStyleName() const
125 {
126 if (GetQSettings().contains(QStringLiteral("userstyle/name")))
127 return GetQSettings().value(QStringLiteral("userstyle/name")).toString();
128
129 // Migration code for the old way of storing this setting
130 return QFileInfo(GetQSettings().value(QStringLiteral("userstyle/path")).toString()).fileName();
131 }
132
133 void Settings::SetUserStyleName(const QString& stylesheet_name)
134 {
135 GetQSettings().setValue(QStringLiteral("userstyle/name"), stylesheet_name);
136 }
137
138 void Settings::InitDefaultPalette()
139 {
140 s_default_palette = std::make_unique<QPalette>(qApp->palette());
141 }
142
143 bool Settings::IsSystemDark()
144 {
145 #if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
146 return (qApp->styleHints()->colorScheme() == Qt::ColorScheme::Dark);
147 #else
148 return false;
149 #endif
150 }
151
152 bool Settings::IsThemeDark()
153 {
154 return qApp->palette().color(QPalette::Base).valueF() < 0.5;
155 }
156
157 // Calling this before the main window has been created breaks the style of some widgets.
158 void Settings::ApplyStyle()
159 {
160 const StyleType style_type = GetStyleType();
161
162 const bool use_fusion{style_type == StyleType::FusionLight ||
163 style_type == StyleType::FusionDarkGray ||
164 style_type == StyleType::FusionDark};
165 static const QString s_initial_style_name{QApplication::style()->name()};
166 const QString style_name{use_fusion ? QStringLiteral("fusion") : s_initial_style_name};
167 if (QApplication::style()->name() != style_name)
168 QApplication::setStyle(style_name);
169
170 const QString stylesheet_name = GetUserStyleName();
171 QString stylesheet_contents;
172
173 // If we haven't found one, we continue with an empty (default) style
174 if (!stylesheet_name.isEmpty() && style_type == StyleType::User)
175 {
176 // Load custom user stylesheet
177 QDir directory = QDir(QString::fromStdString(File::GetUserPath(D_STYLES_IDX)));
178 QFile stylesheet(directory.filePath(stylesheet_name));
179
180 if (stylesheet.open(QFile::ReadOnly))
181 stylesheet_contents = QString::fromUtf8(stylesheet.readAll().data());
182 }
183
184 QPalette palette;
185
186 if (style_type == StyleType::FusionLight)
187 {
188 palette.setColor(QPalette::All, QPalette::Window, QColor(239, 239, 239));
189 palette.setColor(QPalette::Disabled, QPalette::Window, QColor(239, 239, 239));
190 palette.setColor(QPalette::All, QPalette::WindowText, QColor(0, 0, 0));
191 palette.setColor(QPalette::Disabled, QPalette::WindowText, QColor(190, 190, 190));
192 palette.setColor(QPalette::All, QPalette::Base, QColor(255, 255, 255));
193 palette.setColor(QPalette::Disabled, QPalette::Base, QColor(239, 239, 239));
194 palette.setColor(QPalette::All, QPalette::AlternateBase, QColor(247, 247, 247));
195 palette.setColor(QPalette::Disabled, QPalette::AlternateBase, QColor(247, 247, 247));
196 palette.setColor(QPalette::All, QPalette::ToolTipBase, QColor(255, 255, 220));
197 palette.setColor(QPalette::Disabled, QPalette::ToolTipBase, QColor(255, 255, 220));
198 palette.setColor(QPalette::All, QPalette::ToolTipText, QColor(0, 0, 0));
199 palette.setColor(QPalette::Disabled, QPalette::ToolTipText, QColor(0, 0, 0));
200 palette.setColor(QPalette::All, QPalette::PlaceholderText, QColor(119, 119, 119));
201 palette.setColor(QPalette::Disabled, QPalette::PlaceholderText, QColor(119, 119, 119));
202 palette.setColor(QPalette::All, QPalette::Text, QColor(0, 0, 0));
203 palette.setColor(QPalette::Disabled, QPalette::Text, QColor(190, 190, 190));
204 palette.setColor(QPalette::All, QPalette::Button, QColor(239, 239, 239));
205 palette.setColor(QPalette::Disabled, QPalette::Button, QColor(239, 239, 239));
206 palette.setColor(QPalette::All, QPalette::ButtonText, QColor(0, 0, 0));
207 palette.setColor(QPalette::Disabled, QPalette::ButtonText, QColor(190, 190, 190));
208 palette.setColor(QPalette::All, QPalette::BrightText, QColor(255, 255, 255));
209 palette.setColor(QPalette::Disabled, QPalette::BrightText, QColor(255, 255, 255));
210 palette.setColor(QPalette::All, QPalette::Light, QColor(255, 255, 255));
211 palette.setColor(QPalette::Disabled, QPalette::Light, QColor(255, 255, 255));
212 palette.setColor(QPalette::All, QPalette::Midlight, QColor(202, 202, 202));
213 palette.setColor(QPalette::Disabled, QPalette::Midlight, QColor(202, 202, 202));
214 palette.setColor(QPalette::All, QPalette::Dark, QColor(159, 159, 159));
215 palette.setColor(QPalette::Disabled, QPalette::Dark, QColor(190, 190, 190));
216 palette.setColor(QPalette::All, QPalette::Mid, QColor(184, 184, 184));
217 palette.setColor(QPalette::Disabled, QPalette::Mid, QColor(184, 184, 184));
218 palette.setColor(QPalette::All, QPalette::Shadow, QColor(118, 118, 118));
219 palette.setColor(QPalette::Disabled, QPalette::Shadow, QColor(177, 177, 177));
220 palette.setColor(QPalette::All, QPalette::Highlight, QColor(48, 140, 198));
221 palette.setColor(QPalette::Disabled, QPalette::Highlight, QColor(145, 145, 145));
222 #if QT_VERSION >= QT_VERSION_CHECK(6, 6, 0)
223 palette.setColor(QPalette::All, QPalette::Accent, QColor(48, 140, 198));
224 palette.setColor(QPalette::Disabled, QPalette::Accent, QColor(145, 145, 145).darker());
225 #endif
226 palette.setColor(QPalette::All, QPalette::HighlightedText, QColor(255, 255, 255));
227 palette.setColor(QPalette::Disabled, QPalette::HighlightedText, QColor(255, 255, 255));
228 palette.setColor(QPalette::All, QPalette::Link, QColor(0, 0, 255));
229 palette.setColor(QPalette::Disabled, QPalette::Link, QColor(0, 0, 255));
230 palette.setColor(QPalette::All, QPalette::LinkVisited, QColor(255, 0, 255));
231 palette.setColor(QPalette::Disabled, QPalette::LinkVisited, QColor(255, 0, 255));
232 }
233 else if (style_type == StyleType::FusionDarkGray)
234 {
235 palette.setColor(QPalette::All, QPalette::Window, QColor(50, 50, 50));
236 palette.setColor(QPalette::Disabled, QPalette::Window, QColor(55, 55, 55));
237 palette.setColor(QPalette::All, QPalette::WindowText, QColor(200, 200, 200));
238 palette.setColor(QPalette::Disabled, QPalette::WindowText, QColor(108, 108, 108));
239 palette.setColor(QPalette::All, QPalette::Base, QColor(25, 25, 25));
240 palette.setColor(QPalette::Disabled, QPalette::Base, QColor(30, 30, 30));
241 palette.setColor(QPalette::All, QPalette::AlternateBase, QColor(38, 38, 38));
242 palette.setColor(QPalette::Disabled, QPalette::AlternateBase, QColor(42, 42, 42));
243 palette.setColor(QPalette::All, QPalette::ToolTipBase, QColor(45, 45, 45));
244 palette.setColor(QPalette::Disabled, QPalette::ToolTipBase, QColor(45, 45, 45));
245 palette.setColor(QPalette::All, QPalette::ToolTipText, QColor(200, 200, 200));
246 palette.setColor(QPalette::Disabled, QPalette::ToolTipText, QColor(200, 200, 200));
247 palette.setColor(QPalette::All, QPalette::PlaceholderText, QColor(90, 90, 90));
248 palette.setColor(QPalette::Disabled, QPalette::PlaceholderText, QColor(90, 90, 90));
249 palette.setColor(QPalette::All, QPalette::Text, QColor(200, 200, 200));
250 palette.setColor(QPalette::Disabled, QPalette::Text, QColor(108, 108, 108));
251 palette.setColor(QPalette::All, QPalette::Button, QColor(54, 54, 54));
252 palette.setColor(QPalette::Disabled, QPalette::Button, QColor(54, 54, 54));
253 palette.setColor(QPalette::All, QPalette::ButtonText, QColor(200, 200, 200));
254 palette.setColor(QPalette::Disabled, QPalette::ButtonText, QColor(108, 108, 108));
255 palette.setColor(QPalette::All, QPalette::BrightText, QColor(75, 75, 75));
256 palette.setColor(QPalette::Disabled, QPalette::BrightText, QColor(255, 255, 255));
257 palette.setColor(QPalette::All, QPalette::Light, QColor(26, 26, 26));
258 palette.setColor(QPalette::Disabled, QPalette::Light, QColor(26, 26, 26));
259 palette.setColor(QPalette::All, QPalette::Midlight, QColor(40, 40, 40));
260 palette.setColor(QPalette::Disabled, QPalette::Midlight, QColor(40, 40, 40));
261 palette.setColor(QPalette::All, QPalette::Dark, QColor(108, 108, 108));
262 palette.setColor(QPalette::Disabled, QPalette::Dark, QColor(108, 108, 108));
263 palette.setColor(QPalette::All, QPalette::Mid, QColor(71, 71, 71));
264 palette.setColor(QPalette::Disabled, QPalette::Mid, QColor(71, 71, 71));
265 palette.setColor(QPalette::All, QPalette::Shadow, QColor(25, 25, 25));
266 palette.setColor(QPalette::Disabled, QPalette::Shadow, QColor(37, 37, 37));
267 palette.setColor(QPalette::All, QPalette::Highlight, QColor(45, 140, 225));
268 palette.setColor(QPalette::Disabled, QPalette::Highlight, QColor(45, 140, 225).darker());
269 #if QT_VERSION >= QT_VERSION_CHECK(6, 6, 0)
270 palette.setColor(QPalette::All, QPalette::Accent, QColor(45, 140, 225));
271 palette.setColor(QPalette::Disabled, QPalette::Accent, QColor(45, 140, 225).darker());
272 #endif
273 palette.setColor(QPalette::All, QPalette::HighlightedText, QColor(255, 255, 255));
274 palette.setColor(QPalette::Disabled, QPalette::HighlightedText, QColor(40, 40, 40));
275 palette.setColor(QPalette::All, QPalette::Link, QColor(40, 130, 220));
276 palette.setColor(QPalette::Disabled, QPalette::Link, QColor(40, 130, 220).darker());
277 palette.setColor(QPalette::All, QPalette::LinkVisited, QColor(110, 70, 150));
278 palette.setColor(QPalette::Disabled, QPalette::LinkVisited, QColor(110, 70, 150).darker());
279 }
280 else if (style_type == StyleType::FusionDark)
281 {
282 palette.setColor(QPalette::All, QPalette::Window, QColor(22, 22, 22));
283 palette.setColor(QPalette::Disabled, QPalette::Window, QColor(30, 30, 30));
284 palette.setColor(QPalette::All, QPalette::WindowText, QColor(180, 180, 180));
285 palette.setColor(QPalette::Disabled, QPalette::WindowText, QColor(90, 90, 90));
286 palette.setColor(QPalette::All, QPalette::Base, QColor(35, 35, 35));
287 palette.setColor(QPalette::Disabled, QPalette::Base, QColor(30, 30, 30));
288 palette.setColor(QPalette::All, QPalette::AlternateBase, QColor(40, 40, 40));
289 palette.setColor(QPalette::Disabled, QPalette::AlternateBase, QColor(35, 35, 35));
290 palette.setColor(QPalette::All, QPalette::ToolTipBase, QColor(0, 0, 0));
291 palette.setColor(QPalette::Disabled, QPalette::ToolTipBase, QColor(0, 0, 0));
292 palette.setColor(QPalette::All, QPalette::ToolTipText, QColor(170, 170, 170));
293 palette.setColor(QPalette::Disabled, QPalette::ToolTipText, QColor(170, 170, 170));
294 palette.setColor(QPalette::All, QPalette::PlaceholderText, QColor(100, 100, 100));
295 palette.setColor(QPalette::Disabled, QPalette::PlaceholderText, QColor(100, 100, 100));
296 palette.setColor(QPalette::All, QPalette::Text, QColor(200, 200, 200));
297 palette.setColor(QPalette::Disabled, QPalette::Text, QColor(90, 90, 90));
298 palette.setColor(QPalette::All, QPalette::Button, QColor(30, 30, 30));
299 palette.setColor(QPalette::Disabled, QPalette::Button, QColor(20, 20, 20));
300 palette.setColor(QPalette::All, QPalette::ButtonText, QColor(180, 180, 180));
301 palette.setColor(QPalette::Disabled, QPalette::ButtonText, QColor(90, 90, 90));
302 palette.setColor(QPalette::All, QPalette::BrightText, QColor(75, 75, 75));
303 palette.setColor(QPalette::Disabled, QPalette::BrightText, QColor(255, 255, 255));
304 palette.setColor(QPalette::All, QPalette::Light, QColor(0, 0, 0));
305 palette.setColor(QPalette::Disabled, QPalette::Light, QColor(0, 0, 0));
306 palette.setColor(QPalette::All, QPalette::Midlight, QColor(40, 40, 40));
307 palette.setColor(QPalette::Disabled, QPalette::Midlight, QColor(40, 40, 40));
308 palette.setColor(QPalette::All, QPalette::Dark, QColor(90, 90, 90));
309 palette.setColor(QPalette::Disabled, QPalette::Dark, QColor(90, 90, 90));
310 palette.setColor(QPalette::All, QPalette::Mid, QColor(60, 60, 60));
311 palette.setColor(QPalette::Disabled, QPalette::Mid, QColor(60, 60, 60));
312 palette.setColor(QPalette::All, QPalette::Shadow, QColor(10, 10, 10));
313 palette.setColor(QPalette::Disabled, QPalette::Shadow, QColor(20, 20, 20));
314 palette.setColor(QPalette::All, QPalette::Highlight, QColor(35, 130, 200));
315 palette.setColor(QPalette::Disabled, QPalette::Highlight, QColor(35, 130, 200).darker());
316 #if QT_VERSION >= QT_VERSION_CHECK(6, 6, 0)
317 palette.setColor(QPalette::All, QPalette::Accent, QColor(35, 130, 200));
318 palette.setColor(QPalette::Disabled, QPalette::Accent, QColor(35, 130, 200).darker());
319 #endif
320 palette.setColor(QPalette::All, QPalette::HighlightedText, QColor(240, 240, 240));
321 palette.setColor(QPalette::Disabled, QPalette::HighlightedText, QColor(35, 35, 35));
322 palette.setColor(QPalette::All, QPalette::Link, QColor(40, 130, 220));
323 palette.setColor(QPalette::Disabled, QPalette::Link, QColor(40, 130, 220).darker());
324 palette.setColor(QPalette::All, QPalette::LinkVisited, QColor(110, 70, 150));
325 palette.setColor(QPalette::Disabled, QPalette::LinkVisited, QColor(110, 70, 150).darker());
326 }
327 #ifdef _WIN32
328 // Unlike other OSes we don't automatically get a default dark theme on Windows.
329 // We manually load a dark palette for our included "(Dark)" style,
330 // and for *any* external style when the system is in "Dark" mode.
331 // Unfortunately it doesn't seem trivial to load a palette based on the stylesheet itself.
332 else if (style_type == StyleType::Dark || (style_type != StyleType::Light && IsSystemDark()))
333 {
334 if (stylesheet_contents.isEmpty())
335 {
336 QFile file(QStringLiteral(":/dolphin_dark_win/dark.qss"));
337 if (file.open(QFile::ReadOnly))
338 stylesheet_contents = QString::fromUtf8(file.readAll().data());
339 }
340
341 palette = qApp->style()->standardPalette();
342 palette.setColor(QPalette::Window, QColor(32, 32, 32));
343 palette.setColor(QPalette::WindowText, QColor(220, 220, 220));
344 palette.setColor(QPalette::Base, QColor(32, 32, 32));
345 palette.setColor(QPalette::AlternateBase, QColor(48, 48, 48));
346 palette.setColor(QPalette::PlaceholderText, QColor(126, 126, 126));
347 palette.setColor(QPalette::Text, QColor(220, 220, 220));
348 palette.setColor(QPalette::Button, QColor(48, 48, 48));
349 palette.setColor(QPalette::ButtonText, QColor(220, 220, 220));
350 palette.setColor(QPalette::BrightText, QColor(255, 255, 255));
351 palette.setColor(QPalette::Highlight, QColor(0, 120, 215));
352 palette.setColor(QPalette::HighlightedText, QColor(255, 255, 255));
353 palette.setColor(QPalette::Link, QColor(100, 160, 220));
354 palette.setColor(QPalette::LinkVisited, QColor(100, 160, 220));
355 }
356 #endif
357 else
358 {
359 if (s_default_palette)
360 palette = *s_default_palette;
361 }
362
363 qApp->setPalette(palette);
364
365 // Define tooltips style if not already defined
366 if (!stylesheet_contents.contains(QStringLiteral("QToolTip"), Qt::CaseSensitive))
367 {
368 QColor window_color;
369 QColor text_color;
370 QColor unused_text_emphasis_color;
371 QColor border_color;
372 GetToolTipStyle(window_color, text_color, unused_text_emphasis_color, border_color, palette,
373 palette);
374
375 const int padding{QFontMetrics(QFont()).height() / 2};
376
377 const auto tooltip_stylesheet =
378 QStringLiteral("QToolTip { background-color: #%1; color: #%2; padding: %3px; "
379 "border: 1px; border-style: solid; border-color: #%4; }")
380 .arg(window_color.rgba(), 0, 16)
381 .arg(text_color.rgba(), 0, 16)
382 .arg(padding)
383 .arg(border_color.rgba(), 0, 16);
384 stylesheet_contents.append(QStringLiteral("%1").arg(tooltip_stylesheet));
385 }
386
387 #if QT_VERSION >= QT_VERSION_CHECK(6, 6, 0)
388 // For Fusion, define group box style if not already defined.
389 if (style_name.compare(QStringLiteral("fusion"), Qt::CaseInsensitive) == 0 &&
390 !stylesheet_contents.contains(QStringLiteral("QGroupBox")))
391 {
392 stylesheet_contents.append(QStringLiteral("QGroupBox {"
393 " margin-top: 0.6em;"
394 " padding-top: 0.5em;"
395 " padding-bottom: 0;"
396 " padding-left: 1px;"
397 " padding-right: 1px;"
398 "} "
399 "QGroupBox::title {"
400 " subcontrol-origin: margin;"
401 " subcontrol-position: top left;"
402 " left: 0.7em;"
403 " padding-top: 1px;"
404 " min-width: 0;"
405 "}"));
406 }
407 #endif
408
409 qApp->setStyleSheet(stylesheet_contents);
410 }
411
412 Settings::StyleType Settings::GetStyleType() const
413 {
414 if (GetQSettings().contains(QStringLiteral("userstyle/styletype")))
415 {
416 bool ok = false;
417 const int type_int = GetQSettings().value(QStringLiteral("userstyle/styletype")).toInt(&ok);
418 if (ok && type_int >= static_cast<int>(StyleType::MinValue) &&
419 type_int <= static_cast<int>(StyleType::MaxValue))
420 {
421 return static_cast<StyleType>(type_int);
422 }
423 }
424
425 // if the style type is unset or invalid, try the old enabled flag instead
426 const bool enabled = GetQSettings().value(QStringLiteral("userstyle/enabled"), false).toBool();
427 return enabled ? StyleType::User : StyleType::System;
428 }
429
430 void Settings::SetStyleType(StyleType type)
431 {
432 GetQSettings().setValue(QStringLiteral("userstyle/styletype"), static_cast<int>(type));
433
434 // also set the old setting so that the config is correctly interpreted by older Dolphin builds
435 GetQSettings().setValue(QStringLiteral("userstyle/enabled"), type == StyleType::User);
436 }
437
438 void Settings::GetToolTipStyle(QColor& window_color, QColor& text_color,
439 QColor& emphasis_text_color, QColor& border_color,
440 const QPalette& palette, const QPalette& high_contrast_palette) const
441 {
442 const auto theme_window_color = palette.color(QPalette::Base);
443 const auto theme_window_hsv = theme_window_color.toHsv();
444 const auto brightness = theme_window_hsv.value();
445 const bool brightness_over_threshold = brightness > 128;
446 const QColor emphasis_text_color_1 = Qt::yellow;
447 const QColor emphasis_text_color_2 = QColor(QStringLiteral("#0090ff")); // ~light blue
448 if (Config::Get(Config::MAIN_USE_HIGH_CONTRAST_TOOLTIPS))
449 {
450 window_color = brightness_over_threshold ? QColor(72, 72, 72) : Qt::white;
451 text_color = brightness_over_threshold ? Qt::white : Qt::black;
452 emphasis_text_color = brightness_over_threshold ? emphasis_text_color_1 : emphasis_text_color_2;
453 border_color = high_contrast_palette.color(QPalette::Window).darker(160);
454 }
455 else
456 {
457 window_color = palette.color(QPalette::Window);
458 text_color = palette.color(QPalette::Text);
459 emphasis_text_color = brightness_over_threshold ? emphasis_text_color_2 : emphasis_text_color_1;
460 border_color = palette.color(QPalette::Text);
461 }
462 }
463
464 QStringList Settings::GetPaths() const
465 {
466 QStringList list;
467 for (const auto& path : Config::GetIsoPaths())
468 list << QString::fromStdString(path);
469 return list;
470 }
471
472 void Settings::AddPath(const QString& qpath)
473 {
474 std::string path = qpath.toStdString();
475 std::vector<std::string> paths = Config::GetIsoPaths();
476
477 if (Common::Contains(paths, path))
478 return;
479
480 paths.emplace_back(path);
481 Config::SetIsoPaths(paths);
482 emit PathAdded(qpath);
483 }
484
485 void Settings::RemovePath(const QString& qpath)
486 {
487 std::string path = qpath.toStdString();
488 std::vector<std::string> paths = Config::GetIsoPaths();
489
490 if (std::erase(paths, path) == 0)
491 return;
492
493 Config::SetIsoPaths(paths);
494 emit PathRemoved(qpath);
495 }
496
497 void Settings::RefreshGameList()
498 {
499 emit GameListRefreshRequested();
500 }
501
502 void Settings::NotifyRefreshGameListStarted()
503 {
504 emit GameListRefreshStarted();
505 }
506
507 void Settings::NotifyRefreshGameListComplete()
508 {
509 emit GameListRefreshCompleted();
510 }
511
512 void Settings::NotifyMetadataRefreshComplete()
513 {
514 emit MetadataRefreshCompleted();
515 }
516
517 void Settings::ReloadTitleDB()
518 {
519 emit TitleDBReloadRequested();
520 }
521
522 bool Settings::IsAutoRefreshEnabled() const
523 {
524 return GetQSettings().value(QStringLiteral("gamelist/autorefresh"), true).toBool();
525 }
526
527 void Settings::SetAutoRefreshEnabled(bool enabled)
528 {
529 if (IsAutoRefreshEnabled() == enabled)
530 return;
531
532 GetQSettings().setValue(QStringLiteral("gamelist/autorefresh"), enabled);
533
534 emit AutoRefreshToggled(enabled);
535 }
536
537 bool Settings::IsGameCountVisible() const
538 {
539 return GetQSettings().value(QStringLiteral("GameCount/Visible"), true).toBool();
540 }
541
542 void Settings::SetGameCountVisible(const bool visible)
543 {
544 if (IsGameCountVisible() == visible)
545 return;
546
547 GetQSettings().setValue(QStringLiteral("GameCount/Visible"), visible);
548
549 emit GameCountVisibilityChanged(visible);
550 }
551
552 QString Settings::GetDefaultGame() const
553 {
554 return QString::fromStdString(Config::Get(Config::MAIN_DEFAULT_ISO));
555 }
556
557 void Settings::SetDefaultGame(const QString& path)
558 {
559 if (GetDefaultGame() != path)
560 {
561 Config::SetBase(Config::MAIN_DEFAULT_ISO, path.toStdString());
562 emit DefaultGameChanged(path);
563 }
564 }
565
566 bool Settings::GetPreferredView() const
567 {
568 return GetQSettings().value(QStringLiteral("PreferredView"), true).toBool();
569 }
570
571 void Settings::SetPreferredView(bool list)
572 {
573 GetQSettings().setValue(QStringLiteral("PreferredView"), list);
574 }
575
576 int Settings::GetStateSlot() const
577 {
578 return GetQSettings().value(QStringLiteral("Emulation/StateSlot"), 1).toInt();
579 }
580
581 void Settings::SetStateSlot(int slot)
582 {
583 GetQSettings().setValue(QStringLiteral("Emulation/StateSlot"), slot);
584 }
585
586 Config::ShowCursor Settings::GetCursorVisibility() const
587 {
588 return Config::Get(Config::MAIN_SHOW_CURSOR);
589 }
590
591 bool Settings::GetLockCursor() const
592 {
593 return Config::Get(Config::MAIN_LOCK_CURSOR);
594 }
595
596 void Settings::SetKeepWindowOnTop(bool top)
597 {
598 if (IsKeepWindowOnTopEnabled() == top)
599 return;
600
601 emit KeepWindowOnTopChanged(top);
602 }
603
604 bool Settings::IsKeepWindowOnTopEnabled() const
605 {
606 return Config::Get(Config::MAIN_KEEP_WINDOW_ON_TOP);
607 }
608
609 bool Settings::GetGraphicModsEnabled() const
610 {
611 return Config::Get(Config::GFX_MODS_ENABLE);
612 }
613
614 void Settings::SetGraphicModsEnabled(bool enabled)
615 {
616 if (GetGraphicModsEnabled() == enabled)
617 {
618 return;
619 }
620
621 Config::SetBaseOrCurrent(Config::GFX_MODS_ENABLE, enabled);
622 emit EnableGfxModsChanged(enabled);
623 }
624
625 int Settings::GetVolume() const
626 {
627 return Config::Get(Config::MAIN_AUDIO_VOLUME);
628 }
629
630 void Settings::SetVolume(int volume)
631 {
632 if (GetVolume() != volume)
633 Config::SetBaseOrCurrent(Config::MAIN_AUDIO_VOLUME, volume);
634 }
635
636 void Settings::IncreaseVolume(int volume)
637 {
638 AudioCommon::IncreaseVolume(Core::System::GetInstance(), volume);
639 }
640
641 void Settings::DecreaseVolume(int volume)
642 {
643 AudioCommon::DecreaseVolume(Core::System::GetInstance(), volume);
644 }
645
646 bool Settings::IsLogVisible() const
647 {
648 return GetQSettings().value(QStringLiteral("logging/logvisible")).toBool();
649 }
650
651 void Settings::SetLogVisible(bool visible)
652 {
653 if (IsLogVisible() != visible)
654 {
655 GetQSettings().setValue(QStringLiteral("logging/logvisible"), visible);
656 emit LogVisibilityChanged(visible);
657 }
658 }
659
660 bool Settings::IsLogConfigVisible() const
661 {
662 return GetQSettings().value(QStringLiteral("logging/logconfigvisible")).toBool();
663 }
664
665 void Settings::SetLogConfigVisible(bool visible)
666 {
667 if (IsLogConfigVisible() != visible)
668 {
669 GetQSettings().setValue(QStringLiteral("logging/logconfigvisible"), visible);
670 emit LogConfigVisibilityChanged(visible);
671 }
672 }
673
674 std::shared_ptr<NetPlay::NetPlayClient> Settings::GetNetPlayClient()
675 {
676 return m_client;
677 }
678
679 void Settings::ResetNetPlayClient(NetPlay::NetPlayClient* client)
680 {
681 m_client.reset(client);
682
683 g_netplay_chat_ui.reset();
684 g_netplay_golf_ui.reset();
685 }
686
687 std::shared_ptr<NetPlay::NetPlayServer> Settings::GetNetPlayServer()
688 {
689 return m_server;
690 }
691
692 void Settings::ResetNetPlayServer(NetPlay::NetPlayServer* server)
693 {
694 m_server.reset(server);
695 }
696
697 bool Settings::GetCheatsEnabled() const
698 {
699 return Config::Get(Config::MAIN_ENABLE_CHEATS);
700 }
701
702 void Settings::SetDebugModeEnabled(bool enabled)
703 {
704 if (AchievementManager::GetInstance().IsHardcoreModeActive())
705 enabled = false;
706 if (IsDebugModeEnabled() != enabled)
707 {
708 Config::SetBaseOrCurrent(Config::MAIN_ENABLE_DEBUGGING, enabled);
709 emit DebugModeToggled(enabled);
710 }
711 }
712
713 bool Settings::IsDebugModeEnabled() const
714 {
715 return Config::Get(Config::MAIN_ENABLE_DEBUGGING);
716 }
717
718 void Settings::SetRegistersVisible(bool enabled)
719 {
720 if (IsRegistersVisible() != enabled)
721 {
722 GetQSettings().setValue(QStringLiteral("debugger/showregisters"), enabled);
723
724 emit RegistersVisibilityChanged(enabled);
725 }
726 }
727
728 bool Settings::IsThreadsVisible() const
729 {
730 return GetQSettings().value(QStringLiteral("debugger/showthreads")).toBool();
731 }
732
733 void Settings::SetThreadsVisible(bool enabled)
734 {
735 if (IsThreadsVisible() == enabled)
736 return;
737
738 GetQSettings().setValue(QStringLiteral("debugger/showthreads"), enabled);
739 emit ThreadsVisibilityChanged(enabled);
740 }
741
742 bool Settings::IsRegistersVisible() const
743 {
744 return GetQSettings().value(QStringLiteral("debugger/showregisters")).toBool();
745 }
746
747 void Settings::SetWatchVisible(bool enabled)
748 {
749 if (IsWatchVisible() != enabled)
750 {
751 GetQSettings().setValue(QStringLiteral("debugger/showwatch"), enabled);
752
753 emit WatchVisibilityChanged(enabled);
754 }
755 }
756
757 bool Settings::IsWatchVisible() const
758 {
759 return GetQSettings().value(QStringLiteral("debugger/showwatch")).toBool();
760 }
761
762 void Settings::SetBreakpointsVisible(bool enabled)
763 {
764 if (IsBreakpointsVisible() != enabled)
765 {
766 GetQSettings().setValue(QStringLiteral("debugger/showbreakpoints"), enabled);
767
768 emit BreakpointsVisibilityChanged(enabled);
769 }
770 }
771
772 bool Settings::IsBreakpointsVisible() const
773 {
774 return GetQSettings().value(QStringLiteral("debugger/showbreakpoints")).toBool();
775 }
776
777 void Settings::SetCodeVisible(bool enabled)
778 {
779 if (IsCodeVisible() != enabled)
780 {
781 GetQSettings().setValue(QStringLiteral("debugger/showcode"), enabled);
782
783 emit CodeVisibilityChanged(enabled);
784 }
785 }
786
787 bool Settings::IsCodeVisible() const
788 {
789 return GetQSettings().value(QStringLiteral("debugger/showcode"), true).toBool();
790 }
791
792 void Settings::SetMemoryVisible(bool enabled)
793 {
794 if (IsMemoryVisible() == enabled)
795 return;
796 GetQSettings().setValue(QStringLiteral("debugger/showmemory"), enabled);
797
798 emit MemoryVisibilityChanged(enabled);
799 }
800
801 bool Settings::IsMemoryVisible() const
802 {
803 return GetQSettings().value(QStringLiteral("debugger/showmemory")).toBool();
804 }
805
806 void Settings::SetNetworkVisible(bool enabled)
807 {
808 if (IsNetworkVisible() == enabled)
809 return;
810
811 GetQSettings().setValue(QStringLiteral("debugger/shownetwork"), enabled);
812 emit NetworkVisibilityChanged(enabled);
813 }
814
815 bool Settings::IsNetworkVisible() const
816 {
817 return GetQSettings().value(QStringLiteral("debugger/shownetwork")).toBool();
818 }
819
820 void Settings::SetJITVisible(bool enabled)
821 {
822 if (IsJITVisible() == enabled)
823 return;
824 GetQSettings().setValue(QStringLiteral("debugger/showjit"), enabled);
825
826 emit JITVisibilityChanged(enabled);
827 }
828
829 bool Settings::IsJITVisible() const
830 {
831 return GetQSettings().value(QStringLiteral("debugger/showjit")).toBool();
832 }
833
834 void Settings::SetAssemblerVisible(bool enabled)
835 {
836 if (IsAssemblerVisible() == enabled)
837 return;
838 GetQSettings().setValue(QStringLiteral("debugger/showassembler"), enabled);
839
840 emit AssemblerVisibilityChanged(enabled);
841 }
842
843 bool Settings::IsAssemblerVisible() const
844 {
845 return GetQSettings().value(QStringLiteral("debugger/showassembler")).toBool();
846 }
847
848 void Settings::RefreshWidgetVisibility()
849 {
850 emit DebugModeToggled(IsDebugModeEnabled());
851 emit LogVisibilityChanged(IsLogVisible());
852 emit LogConfigVisibilityChanged(IsLogConfigVisible());
853 emit GameCountVisibilityChanged(IsGameCountVisible());
854 }
855
856 void Settings::SetDebugFont(const QFont& font)
857 {
858 if (GetDebugFont() != font)
859 {
860 GetQSettings().setValue(QStringLiteral("debugger/font"), font);
861
862 emit DebugFontChanged(font);
863 }
864 }
865
866 QFont Settings::GetDebugFont() const
867 {
868 QFont default_font = QFont(QFontDatabase::systemFont(QFontDatabase::FixedFont).family());
869 default_font.setPointSizeF(9.0);
870
871 return GetQSettings().value(QStringLiteral("debugger/font"), default_font).value<QFont>();
872 }
873
874 void Settings::SetAutoUpdateTrack(const QString& mode)
875 {
876 if (mode == GetAutoUpdateTrack())
877 return;
878
879 Config::SetBase(Config::MAIN_AUTOUPDATE_UPDATE_TRACK, mode.toStdString());
880
881 emit AutoUpdateTrackChanged(mode);
882 }
883
884 QString Settings::GetAutoUpdateTrack() const
885 {
886 return QString::fromStdString(Config::Get(Config::MAIN_AUTOUPDATE_UPDATE_TRACK));
887 }
888
889 void Settings::SetFallbackRegion(const DiscIO::Region& region)
890 {
891 if (region == GetFallbackRegion())
892 return;
893
894 Config::SetBase(Config::MAIN_FALLBACK_REGION, region);
895
896 emit FallbackRegionChanged(region);
897 }
898
899 DiscIO::Region Settings::GetFallbackRegion() const
900 {
901 return Config::Get(Config::MAIN_FALLBACK_REGION);
902 }
903
904 void Settings::SetAnalyticsEnabled(bool enabled)
905 {
906 if (enabled == IsAnalyticsEnabled())
907 return;
908
909 Config::SetBase(Config::MAIN_ANALYTICS_ENABLED, enabled);
910
911 emit AnalyticsToggled(enabled);
912 }
913
914 bool Settings::IsAnalyticsEnabled() const
915 {
916 return Config::Get(Config::MAIN_ANALYTICS_ENABLED);
917 }
918
919 void Settings::SetToolBarVisible(bool visible)
920 {
921 if (IsToolBarVisible() == visible)
922 return;
923
924 GetQSettings().setValue(QStringLiteral("toolbar/visible"), visible);
925
926 emit ToolBarVisibilityChanged(visible);
927 }
928
929 bool Settings::IsToolBarVisible() const
930 {
931 return GetQSettings().value(QStringLiteral("toolbar/visible"), true).toBool();
932 }
933
934 void Settings::SetWidgetsLocked(bool locked)
935 {
936 if (AreWidgetsLocked() == locked)
937 return;
938
939 GetQSettings().setValue(QStringLiteral("widgets/locked"), locked);
940
941 emit WidgetLockChanged(locked);
942 }
943
944 bool Settings::AreWidgetsLocked() const
945 {
946 return GetQSettings().value(QStringLiteral("widgets/locked"), true).toBool();
947 }
948
949 bool Settings::IsBatchModeEnabled() const
950 {
951 return m_batch;
952 }
953 void Settings::SetBatchModeEnabled(bool batch)
954 {
955 m_batch = batch;
956 }
957
958 bool Settings::IsSDCardInserted() const
959 {
960 return Config::Get(Config::MAIN_WII_SD_CARD);
961 }
962
963 void Settings::SetSDCardInserted(bool inserted)
964 {
965 if (IsSDCardInserted() != inserted)
966 Config::SetBaseOrCurrent(Config::MAIN_WII_SD_CARD, inserted);
967 }
968
969 bool Settings::IsUSBKeyboardConnected() const
970 {
971 return Config::Get(Config::MAIN_WII_KEYBOARD);
972 }
973
974 void Settings::SetUSBKeyboardConnected(bool connected)
975 {
976 if (IsUSBKeyboardConnected() != connected)
977 Config::SetBaseOrCurrent(Config::MAIN_WII_KEYBOARD, connected);
978 }
979
980 bool Settings::IsWiiSpeakMuted() const
981 {
982 return Config::Get(Config::MAIN_WII_SPEAK_MUTED);
983 }
984
985 void Settings::SetWiiSpeakMuted(bool muted)
986 {
987 if (IsWiiSpeakMuted() == muted)
988 return;
989
990 Config::SetBaseOrCurrent(Config::MAIN_WII_SPEAK_MUTED, muted);
991 emit WiiSpeakMuteChanged(muted);
992 }
993
994 void Settings::SetIsContinuouslyFrameStepping(bool is_stepping)
995 {
996 m_continuously_frame_stepping = is_stepping;
997 }
998
999 bool Settings::GetIsContinuouslyFrameStepping() const
1000 {
1001 return m_continuously_frame_stepping;
1002 }