Settings.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807
  1. // Copyright 2015 Dolphin Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #include "DolphinQt/Settings.h"
  4. #include <atomic>
  5. #include <memory>
  6. #include <QApplication>
  7. #include <QColor>
  8. #include <QDir>
  9. #include <QFile>
  10. #include <QFileInfo>
  11. #include <QFontDatabase>
  12. #include <QPalette>
  13. #include <QRadioButton>
  14. #include <QSize>
  15. #include <QStyle>
  16. #include <QStyleHints>
  17. #include <QWidget>
  18. #include "AudioCommon/AudioCommon.h"
  19. #include "Common/Config/Config.h"
  20. #include "Common/Contains.h"
  21. #include "Common/FileUtil.h"
  22. #include "Common/StringUtil.h"
  23. #include "Core/AchievementManager.h"
  24. #include "Core/Config/GraphicsSettings.h"
  25. #include "Core/Config/MainSettings.h"
  26. #include "Core/ConfigManager.h"
  27. #include "Core/Core.h"
  28. #include "Core/IOS/IOS.h"
  29. #include "Core/NetPlayClient.h"
  30. #include "Core/NetPlayServer.h"
  31. #include "Core/System.h"
  32. #include "DolphinQt/Host.h"
  33. #include "DolphinQt/QtUtils/QueueOnObject.h"
  34. #include "InputCommon/ControllerInterface/ControllerInterface.h"
  35. #include "InputCommon/InputConfig.h"
  36. #include "VideoCommon/NetPlayChatUI.h"
  37. #include "VideoCommon/NetPlayGolfUI.h"
  38. static std::unique_ptr<QPalette> s_default_palette;
  39. Settings::Settings()
  40. {
  41. qRegisterMetaType<Core::State>();
  42. Core::AddOnStateChangedCallback([this](Core::State new_state) {
  43. QueueOnObject(this, [this, new_state] {
  44. // Avoid signal spam while continuously frame stepping. Will still send a signal for the first
  45. // and last framestep.
  46. if (!m_continuously_frame_stepping)
  47. emit EmulationStateChanged(new_state);
  48. });
  49. });
  50. m_config_changed_callback_id = Config::AddConfigChangedCallback([this] {
  51. static std::atomic<bool> do_once{true};
  52. if (do_once.exchange(false))
  53. {
  54. // Calling ConfigChanged() with a "delay" can have risks, for example, if from
  55. // code we change some configs that result in Qt greying out some setting, we could
  56. // end up editing that setting before its greyed out, sending out an event,
  57. // which might not be expected or handled by the code, potentially crashing.
  58. // The only safe option would be to wait on the Qt thread to have finished executing this.
  59. QueueOnObject(this, [this] {
  60. do_once = true;
  61. emit ConfigChanged();
  62. });
  63. }
  64. });
  65. m_hotplug_callback_handle = g_controller_interface.RegisterDevicesChangedCallback([this] {
  66. if (Core::IsHostThread())
  67. {
  68. emit DevicesChanged();
  69. }
  70. else
  71. {
  72. // Any device shared_ptr in the host thread needs to be released immediately as otherwise
  73. // they'd continue living until the queued event has run, but some devices can't be recreated
  74. // until they are destroyed.
  75. // This is safe from any thread. Devices will be refreshed and re-acquired and in
  76. // DevicesChanged(). Calling it without queueing shouldn't cause any deadlocks but is slow.
  77. emit ReleaseDevices();
  78. QueueOnObject(this, [this] { emit DevicesChanged(); });
  79. }
  80. });
  81. }
  82. Settings::~Settings()
  83. {
  84. Config::RemoveConfigChangedCallback(m_config_changed_callback_id);
  85. }
  86. void Settings::UnregisterDevicesChangedCallback()
  87. {
  88. g_controller_interface.UnregisterDevicesChangedCallback(m_hotplug_callback_handle);
  89. }
  90. Settings& Settings::Instance()
  91. {
  92. static Settings settings;
  93. return settings;
  94. }
  95. QSettings& Settings::GetQSettings()
  96. {
  97. static QSettings settings(
  98. QStringLiteral("%1/Qt.ini").arg(QString::fromStdString(File::GetUserPath(D_CONFIG_IDX))),
  99. QSettings::IniFormat);
  100. return settings;
  101. }
  102. void Settings::TriggerThemeChanged()
  103. {
  104. emit ThemeChanged();
  105. }
  106. QString Settings::GetUserStyleName() const
  107. {
  108. if (GetQSettings().contains(QStringLiteral("userstyle/name")))
  109. return GetQSettings().value(QStringLiteral("userstyle/name")).toString();
  110. // Migration code for the old way of storing this setting
  111. return QFileInfo(GetQSettings().value(QStringLiteral("userstyle/path")).toString()).fileName();
  112. }
  113. void Settings::SetUserStyleName(const QString& stylesheet_name)
  114. {
  115. GetQSettings().setValue(QStringLiteral("userstyle/name"), stylesheet_name);
  116. }
  117. void Settings::InitDefaultPalette()
  118. {
  119. s_default_palette = std::make_unique<QPalette>(qApp->palette());
  120. }
  121. bool Settings::IsSystemDark()
  122. {
  123. #if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
  124. return (qApp->styleHints()->colorScheme() == Qt::ColorScheme::Dark);
  125. #else
  126. return false;
  127. #endif
  128. }
  129. bool Settings::IsThemeDark()
  130. {
  131. return qApp->palette().color(QPalette::Base).valueF() < 0.5;
  132. }
  133. // Calling this before the main window has been created breaks the style of some widgets.
  134. void Settings::ApplyStyle()
  135. {
  136. const StyleType style_type = GetStyleType();
  137. const QString stylesheet_name = GetUserStyleName();
  138. QString stylesheet_contents;
  139. // If we haven't found one, we continue with an empty (default) style
  140. if (!stylesheet_name.isEmpty() && style_type == StyleType::User)
  141. {
  142. // Load custom user stylesheet
  143. QDir directory = QDir(QString::fromStdString(File::GetUserPath(D_STYLES_IDX)));
  144. QFile stylesheet(directory.filePath(stylesheet_name));
  145. if (stylesheet.open(QFile::ReadOnly))
  146. stylesheet_contents = QString::fromUtf8(stylesheet.readAll().data());
  147. }
  148. #ifdef _WIN32
  149. if (stylesheet_contents.isEmpty())
  150. {
  151. // No theme selected or found. Usually we would just fallthrough and set an empty stylesheet
  152. // which would select Qt's default theme, but unlike other OSes we don't automatically get a
  153. // default dark theme on Windows when the user has selected dark mode in the Windows settings.
  154. // So manually check if the user wants dark mode and, if yes, load our embedded dark theme.
  155. if (style_type == StyleType::Dark || (style_type != StyleType::Light && IsSystemDark()))
  156. {
  157. QFile file(QStringLiteral(":/dolphin_dark_win/dark.qss"));
  158. if (file.open(QFile::ReadOnly))
  159. stylesheet_contents = QString::fromUtf8(file.readAll().data());
  160. QPalette palette = qApp->style()->standardPalette();
  161. palette.setColor(QPalette::Window, QColor(32, 32, 32));
  162. palette.setColor(QPalette::WindowText, QColor(220, 220, 220));
  163. palette.setColor(QPalette::Base, QColor(32, 32, 32));
  164. palette.setColor(QPalette::AlternateBase, QColor(48, 48, 48));
  165. palette.setColor(QPalette::PlaceholderText, QColor(126, 126, 126));
  166. palette.setColor(QPalette::Text, QColor(220, 220, 220));
  167. palette.setColor(QPalette::Button, QColor(48, 48, 48));
  168. palette.setColor(QPalette::ButtonText, QColor(220, 220, 220));
  169. palette.setColor(QPalette::BrightText, QColor(255, 255, 255));
  170. palette.setColor(QPalette::Highlight, QColor(0, 120, 215));
  171. palette.setColor(QPalette::HighlightedText, QColor(255, 255, 255));
  172. palette.setColor(QPalette::Link, QColor(100, 160, 220));
  173. palette.setColor(QPalette::LinkVisited, QColor(100, 160, 220));
  174. qApp->setPalette(palette);
  175. }
  176. else
  177. {
  178. // reset any palette changes that may exist from a previously set dark mode
  179. if (s_default_palette)
  180. qApp->setPalette(*s_default_palette);
  181. }
  182. }
  183. #endif
  184. // Define tooltips style if not already defined
  185. if (!stylesheet_contents.contains(QStringLiteral("QToolTip"), Qt::CaseSensitive))
  186. {
  187. const QPalette& palette = qApp->palette();
  188. QColor window_color;
  189. QColor text_color;
  190. QColor unused_text_emphasis_color;
  191. QColor border_color;
  192. GetToolTipStyle(window_color, text_color, unused_text_emphasis_color, border_color, palette,
  193. palette);
  194. const auto tooltip_stylesheet =
  195. QStringLiteral("QToolTip { background-color: #%1; color: #%2; padding: 8px; "
  196. "border: 1px; border-style: solid; border-color: #%3; }")
  197. .arg(window_color.rgba(), 0, 16)
  198. .arg(text_color.rgba(), 0, 16)
  199. .arg(border_color.rgba(), 0, 16);
  200. stylesheet_contents.append(QStringLiteral("%1").arg(tooltip_stylesheet));
  201. }
  202. qApp->setStyleSheet(stylesheet_contents);
  203. }
  204. Settings::StyleType Settings::GetStyleType() const
  205. {
  206. if (GetQSettings().contains(QStringLiteral("userstyle/styletype")))
  207. {
  208. bool ok = false;
  209. const int type_int = GetQSettings().value(QStringLiteral("userstyle/styletype")).toInt(&ok);
  210. if (ok && type_int >= static_cast<int>(StyleType::MinValue) &&
  211. type_int <= static_cast<int>(StyleType::MaxValue))
  212. {
  213. return static_cast<StyleType>(type_int);
  214. }
  215. }
  216. // if the style type is unset or invalid, try the old enabled flag instead
  217. const bool enabled = GetQSettings().value(QStringLiteral("userstyle/enabled"), false).toBool();
  218. return enabled ? StyleType::User : StyleType::System;
  219. }
  220. void Settings::SetStyleType(StyleType type)
  221. {
  222. GetQSettings().setValue(QStringLiteral("userstyle/styletype"), static_cast<int>(type));
  223. // also set the old setting so that the config is correctly intepreted by older Dolphin builds
  224. GetQSettings().setValue(QStringLiteral("userstyle/enabled"), type == StyleType::User);
  225. }
  226. void Settings::GetToolTipStyle(QColor& window_color, QColor& text_color,
  227. QColor& emphasis_text_color, QColor& border_color,
  228. const QPalette& palette, const QPalette& high_contrast_palette) const
  229. {
  230. const auto theme_window_color = palette.color(QPalette::Base);
  231. const auto theme_window_hsv = theme_window_color.toHsv();
  232. const auto brightness = theme_window_hsv.value();
  233. const bool brightness_over_threshold = brightness > 128;
  234. const QColor emphasis_text_color_1 = Qt::yellow;
  235. const QColor emphasis_text_color_2 = QColor(QStringLiteral("#0090ff")); // ~light blue
  236. if (Config::Get(Config::MAIN_USE_HIGH_CONTRAST_TOOLTIPS))
  237. {
  238. window_color = brightness_over_threshold ? QColor(72, 72, 72) : Qt::white;
  239. text_color = brightness_over_threshold ? Qt::white : Qt::black;
  240. emphasis_text_color = brightness_over_threshold ? emphasis_text_color_1 : emphasis_text_color_2;
  241. border_color = high_contrast_palette.color(QPalette::Window).darker(160);
  242. }
  243. else
  244. {
  245. window_color = palette.color(QPalette::Window);
  246. text_color = palette.color(QPalette::Text);
  247. emphasis_text_color = brightness_over_threshold ? emphasis_text_color_2 : emphasis_text_color_1;
  248. border_color = palette.color(QPalette::Text);
  249. }
  250. }
  251. QStringList Settings::GetPaths() const
  252. {
  253. QStringList list;
  254. for (const auto& path : Config::GetIsoPaths())
  255. list << QString::fromStdString(path);
  256. return list;
  257. }
  258. void Settings::AddPath(const QString& qpath)
  259. {
  260. std::string path = qpath.toStdString();
  261. std::vector<std::string> paths = Config::GetIsoPaths();
  262. if (Common::Contains(paths, path))
  263. return;
  264. paths.emplace_back(path);
  265. Config::SetIsoPaths(paths);
  266. emit PathAdded(qpath);
  267. }
  268. void Settings::RemovePath(const QString& qpath)
  269. {
  270. std::string path = qpath.toStdString();
  271. std::vector<std::string> paths = Config::GetIsoPaths();
  272. if (std::erase(paths, path) == 0)
  273. return;
  274. Config::SetIsoPaths(paths);
  275. emit PathRemoved(qpath);
  276. }
  277. void Settings::RefreshGameList()
  278. {
  279. emit GameListRefreshRequested();
  280. }
  281. void Settings::NotifyRefreshGameListStarted()
  282. {
  283. emit GameListRefreshStarted();
  284. }
  285. void Settings::NotifyRefreshGameListComplete()
  286. {
  287. emit GameListRefreshCompleted();
  288. }
  289. void Settings::NotifyMetadataRefreshComplete()
  290. {
  291. emit MetadataRefreshCompleted();
  292. }
  293. void Settings::ReloadTitleDB()
  294. {
  295. emit TitleDBReloadRequested();
  296. }
  297. bool Settings::IsAutoRefreshEnabled() const
  298. {
  299. return GetQSettings().value(QStringLiteral("gamelist/autorefresh"), true).toBool();
  300. }
  301. void Settings::SetAutoRefreshEnabled(bool enabled)
  302. {
  303. if (IsAutoRefreshEnabled() == enabled)
  304. return;
  305. GetQSettings().setValue(QStringLiteral("gamelist/autorefresh"), enabled);
  306. emit AutoRefreshToggled(enabled);
  307. }
  308. QString Settings::GetDefaultGame() const
  309. {
  310. return QString::fromStdString(Config::Get(Config::MAIN_DEFAULT_ISO));
  311. }
  312. void Settings::SetDefaultGame(QString path)
  313. {
  314. if (GetDefaultGame() != path)
  315. {
  316. Config::SetBase(Config::MAIN_DEFAULT_ISO, path.toStdString());
  317. emit DefaultGameChanged(path);
  318. }
  319. }
  320. bool Settings::GetPreferredView() const
  321. {
  322. return GetQSettings().value(QStringLiteral("PreferredView"), true).toBool();
  323. }
  324. void Settings::SetPreferredView(bool list)
  325. {
  326. GetQSettings().setValue(QStringLiteral("PreferredView"), list);
  327. }
  328. int Settings::GetStateSlot() const
  329. {
  330. return GetQSettings().value(QStringLiteral("Emulation/StateSlot"), 1).toInt();
  331. }
  332. void Settings::SetStateSlot(int slot)
  333. {
  334. GetQSettings().setValue(QStringLiteral("Emulation/StateSlot"), slot);
  335. }
  336. Config::ShowCursor Settings::GetCursorVisibility() const
  337. {
  338. return Config::Get(Config::MAIN_SHOW_CURSOR);
  339. }
  340. bool Settings::GetLockCursor() const
  341. {
  342. return Config::Get(Config::MAIN_LOCK_CURSOR);
  343. }
  344. void Settings::SetKeepWindowOnTop(bool top)
  345. {
  346. if (IsKeepWindowOnTopEnabled() == top)
  347. return;
  348. emit KeepWindowOnTopChanged(top);
  349. }
  350. bool Settings::IsKeepWindowOnTopEnabled() const
  351. {
  352. return Config::Get(Config::MAIN_KEEP_WINDOW_ON_TOP);
  353. }
  354. bool Settings::GetGraphicModsEnabled() const
  355. {
  356. return Config::Get(Config::GFX_MODS_ENABLE);
  357. }
  358. void Settings::SetGraphicModsEnabled(bool enabled)
  359. {
  360. if (GetGraphicModsEnabled() == enabled)
  361. {
  362. return;
  363. }
  364. Config::SetBaseOrCurrent(Config::GFX_MODS_ENABLE, enabled);
  365. emit EnableGfxModsChanged(enabled);
  366. }
  367. int Settings::GetVolume() const
  368. {
  369. return Config::Get(Config::MAIN_AUDIO_VOLUME);
  370. }
  371. void Settings::SetVolume(int volume)
  372. {
  373. if (GetVolume() != volume)
  374. Config::SetBaseOrCurrent(Config::MAIN_AUDIO_VOLUME, volume);
  375. }
  376. void Settings::IncreaseVolume(int volume)
  377. {
  378. AudioCommon::IncreaseVolume(Core::System::GetInstance(), volume);
  379. }
  380. void Settings::DecreaseVolume(int volume)
  381. {
  382. AudioCommon::DecreaseVolume(Core::System::GetInstance(), volume);
  383. }
  384. bool Settings::IsLogVisible() const
  385. {
  386. return GetQSettings().value(QStringLiteral("logging/logvisible")).toBool();
  387. }
  388. void Settings::SetLogVisible(bool visible)
  389. {
  390. if (IsLogVisible() != visible)
  391. {
  392. GetQSettings().setValue(QStringLiteral("logging/logvisible"), visible);
  393. emit LogVisibilityChanged(visible);
  394. }
  395. }
  396. bool Settings::IsLogConfigVisible() const
  397. {
  398. return GetQSettings().value(QStringLiteral("logging/logconfigvisible")).toBool();
  399. }
  400. void Settings::SetLogConfigVisible(bool visible)
  401. {
  402. if (IsLogConfigVisible() != visible)
  403. {
  404. GetQSettings().setValue(QStringLiteral("logging/logconfigvisible"), visible);
  405. emit LogConfigVisibilityChanged(visible);
  406. }
  407. }
  408. std::shared_ptr<NetPlay::NetPlayClient> Settings::GetNetPlayClient()
  409. {
  410. return m_client;
  411. }
  412. void Settings::ResetNetPlayClient(NetPlay::NetPlayClient* client)
  413. {
  414. m_client.reset(client);
  415. g_netplay_chat_ui.reset();
  416. g_netplay_golf_ui.reset();
  417. }
  418. std::shared_ptr<NetPlay::NetPlayServer> Settings::GetNetPlayServer()
  419. {
  420. return m_server;
  421. }
  422. void Settings::ResetNetPlayServer(NetPlay::NetPlayServer* server)
  423. {
  424. m_server.reset(server);
  425. }
  426. bool Settings::GetCheatsEnabled() const
  427. {
  428. return Config::Get(Config::MAIN_ENABLE_CHEATS);
  429. }
  430. void Settings::SetDebugModeEnabled(bool enabled)
  431. {
  432. if (AchievementManager::GetInstance().IsHardcoreModeActive())
  433. enabled = false;
  434. if (IsDebugModeEnabled() != enabled)
  435. {
  436. Config::SetBaseOrCurrent(Config::MAIN_ENABLE_DEBUGGING, enabled);
  437. emit DebugModeToggled(enabled);
  438. if (enabled)
  439. SetCodeVisible(true);
  440. }
  441. }
  442. bool Settings::IsDebugModeEnabled() const
  443. {
  444. return Config::Get(Config::MAIN_ENABLE_DEBUGGING);
  445. }
  446. void Settings::SetRegistersVisible(bool enabled)
  447. {
  448. if (IsRegistersVisible() != enabled)
  449. {
  450. GetQSettings().setValue(QStringLiteral("debugger/showregisters"), enabled);
  451. emit RegistersVisibilityChanged(enabled);
  452. }
  453. }
  454. bool Settings::IsThreadsVisible() const
  455. {
  456. return GetQSettings().value(QStringLiteral("debugger/showthreads")).toBool();
  457. }
  458. void Settings::SetThreadsVisible(bool enabled)
  459. {
  460. if (IsThreadsVisible() == enabled)
  461. return;
  462. GetQSettings().setValue(QStringLiteral("debugger/showthreads"), enabled);
  463. emit ThreadsVisibilityChanged(enabled);
  464. }
  465. bool Settings::IsRegistersVisible() const
  466. {
  467. return GetQSettings().value(QStringLiteral("debugger/showregisters")).toBool();
  468. }
  469. void Settings::SetWatchVisible(bool enabled)
  470. {
  471. if (IsWatchVisible() != enabled)
  472. {
  473. GetQSettings().setValue(QStringLiteral("debugger/showwatch"), enabled);
  474. emit WatchVisibilityChanged(enabled);
  475. }
  476. }
  477. bool Settings::IsWatchVisible() const
  478. {
  479. return GetQSettings().value(QStringLiteral("debugger/showwatch")).toBool();
  480. }
  481. void Settings::SetBreakpointsVisible(bool enabled)
  482. {
  483. if (IsBreakpointsVisible() != enabled)
  484. {
  485. GetQSettings().setValue(QStringLiteral("debugger/showbreakpoints"), enabled);
  486. emit BreakpointsVisibilityChanged(enabled);
  487. }
  488. }
  489. bool Settings::IsBreakpointsVisible() const
  490. {
  491. return GetQSettings().value(QStringLiteral("debugger/showbreakpoints")).toBool();
  492. }
  493. void Settings::SetCodeVisible(bool enabled)
  494. {
  495. if (IsCodeVisible() != enabled)
  496. {
  497. GetQSettings().setValue(QStringLiteral("debugger/showcode"), enabled);
  498. emit CodeVisibilityChanged(enabled);
  499. }
  500. }
  501. bool Settings::IsCodeVisible() const
  502. {
  503. return GetQSettings().value(QStringLiteral("debugger/showcode")).toBool();
  504. }
  505. void Settings::SetMemoryVisible(bool enabled)
  506. {
  507. if (IsMemoryVisible() == enabled)
  508. return;
  509. GetQSettings().setValue(QStringLiteral("debugger/showmemory"), enabled);
  510. emit MemoryVisibilityChanged(enabled);
  511. }
  512. bool Settings::IsMemoryVisible() const
  513. {
  514. return GetQSettings().value(QStringLiteral("debugger/showmemory")).toBool();
  515. }
  516. void Settings::SetNetworkVisible(bool enabled)
  517. {
  518. if (IsNetworkVisible() == enabled)
  519. return;
  520. GetQSettings().setValue(QStringLiteral("debugger/shownetwork"), enabled);
  521. emit NetworkVisibilityChanged(enabled);
  522. }
  523. bool Settings::IsNetworkVisible() const
  524. {
  525. return GetQSettings().value(QStringLiteral("debugger/shownetwork")).toBool();
  526. }
  527. void Settings::SetJITVisible(bool enabled)
  528. {
  529. if (IsJITVisible() == enabled)
  530. return;
  531. GetQSettings().setValue(QStringLiteral("debugger/showjit"), enabled);
  532. emit JITVisibilityChanged(enabled);
  533. }
  534. bool Settings::IsJITVisible() const
  535. {
  536. return GetQSettings().value(QStringLiteral("debugger/showjit")).toBool();
  537. }
  538. void Settings::SetAssemblerVisible(bool enabled)
  539. {
  540. if (IsAssemblerVisible() == enabled)
  541. return;
  542. GetQSettings().setValue(QStringLiteral("debugger/showassembler"), enabled);
  543. emit AssemblerVisibilityChanged(enabled);
  544. }
  545. bool Settings::IsAssemblerVisible() const
  546. {
  547. return GetQSettings().value(QStringLiteral("debugger/showassembler")).toBool();
  548. }
  549. void Settings::RefreshWidgetVisibility()
  550. {
  551. emit DebugModeToggled(IsDebugModeEnabled());
  552. emit LogVisibilityChanged(IsLogVisible());
  553. emit LogConfigVisibilityChanged(IsLogConfigVisible());
  554. }
  555. void Settings::SetDebugFont(QFont font)
  556. {
  557. if (GetDebugFont() != font)
  558. {
  559. GetQSettings().setValue(QStringLiteral("debugger/font"), font);
  560. emit DebugFontChanged(font);
  561. }
  562. }
  563. QFont Settings::GetDebugFont() const
  564. {
  565. QFont default_font = QFont(QFontDatabase::systemFont(QFontDatabase::FixedFont).family());
  566. default_font.setPointSizeF(9.0);
  567. return GetQSettings().value(QStringLiteral("debugger/font"), default_font).value<QFont>();
  568. }
  569. void Settings::SetAutoUpdateTrack(const QString& mode)
  570. {
  571. if (mode == GetAutoUpdateTrack())
  572. return;
  573. Config::SetBase(Config::MAIN_AUTOUPDATE_UPDATE_TRACK, mode.toStdString());
  574. emit AutoUpdateTrackChanged(mode);
  575. }
  576. QString Settings::GetAutoUpdateTrack() const
  577. {
  578. return QString::fromStdString(Config::Get(Config::MAIN_AUTOUPDATE_UPDATE_TRACK));
  579. }
  580. void Settings::SetFallbackRegion(const DiscIO::Region& region)
  581. {
  582. if (region == GetFallbackRegion())
  583. return;
  584. Config::SetBase(Config::MAIN_FALLBACK_REGION, region);
  585. emit FallbackRegionChanged(region);
  586. }
  587. DiscIO::Region Settings::GetFallbackRegion() const
  588. {
  589. return Config::Get(Config::MAIN_FALLBACK_REGION);
  590. }
  591. void Settings::SetAnalyticsEnabled(bool enabled)
  592. {
  593. if (enabled == IsAnalyticsEnabled())
  594. return;
  595. Config::SetBase(Config::MAIN_ANALYTICS_ENABLED, enabled);
  596. emit AnalyticsToggled(enabled);
  597. }
  598. bool Settings::IsAnalyticsEnabled() const
  599. {
  600. return Config::Get(Config::MAIN_ANALYTICS_ENABLED);
  601. }
  602. void Settings::SetToolBarVisible(bool visible)
  603. {
  604. if (IsToolBarVisible() == visible)
  605. return;
  606. GetQSettings().setValue(QStringLiteral("toolbar/visible"), visible);
  607. emit ToolBarVisibilityChanged(visible);
  608. }
  609. bool Settings::IsToolBarVisible() const
  610. {
  611. return GetQSettings().value(QStringLiteral("toolbar/visible"), true).toBool();
  612. }
  613. void Settings::SetWidgetsLocked(bool locked)
  614. {
  615. if (AreWidgetsLocked() == locked)
  616. return;
  617. GetQSettings().setValue(QStringLiteral("widgets/locked"), locked);
  618. emit WidgetLockChanged(locked);
  619. }
  620. bool Settings::AreWidgetsLocked() const
  621. {
  622. return GetQSettings().value(QStringLiteral("widgets/locked"), true).toBool();
  623. }
  624. bool Settings::IsBatchModeEnabled() const
  625. {
  626. return m_batch;
  627. }
  628. void Settings::SetBatchModeEnabled(bool batch)
  629. {
  630. m_batch = batch;
  631. }
  632. bool Settings::IsSDCardInserted() const
  633. {
  634. return Config::Get(Config::MAIN_WII_SD_CARD);
  635. }
  636. void Settings::SetSDCardInserted(bool inserted)
  637. {
  638. if (IsSDCardInserted() != inserted)
  639. {
  640. Config::SetBaseOrCurrent(Config::MAIN_WII_SD_CARD, inserted);
  641. emit SDCardInsertionChanged(inserted);
  642. }
  643. }
  644. bool Settings::IsUSBKeyboardConnected() const
  645. {
  646. return Config::Get(Config::MAIN_WII_KEYBOARD);
  647. }
  648. void Settings::SetUSBKeyboardConnected(bool connected)
  649. {
  650. if (IsUSBKeyboardConnected() != connected)
  651. {
  652. Config::SetBaseOrCurrent(Config::MAIN_WII_KEYBOARD, connected);
  653. emit USBKeyboardConnectionChanged(connected);
  654. }
  655. }
  656. void Settings::SetIsContinuouslyFrameStepping(bool is_stepping)
  657. {
  658. m_continuously_frame_stepping = is_stepping;
  659. }
  660. bool Settings::GetIsContinuouslyFrameStepping() const
  661. {
  662. return m_continuously_frame_stepping;
  663. }