Debian Codegraph @

Source/Core/DolphinQt/Config/CommonControllersWidget.cpp

raw symbols SCIP
1 // Copyright 2021 Dolphin Emulator Project
2 // SPDX-License-Identifier: GPL-2.0-or-later
3
4 #include "DolphinQt/Config/CommonControllersWidget.h"
5
6 #include <QCheckBox>
7 #include <QGroupBox>
8 #include <QPushButton>
9 #include <QVBoxLayout>
10
11 #include "Core/Config/MainSettings.h"
12
13 #include "DolphinQt/Config/ControllerInterface/ControllerInterfaceWindow.h"
14 #include "DolphinQt/Config/SDLHints/SDLHintsWindow.h"
15 #include "DolphinQt/QtUtils/NonDefaultQPushButton.h"
16 #include "DolphinQt/QtUtils/SignalBlocking.h"
17 #include "DolphinQt/Settings.h"
18
19 CommonControllersWidget::CommonControllersWidget(QWidget* parent) : QWidget(parent)
20 {
21 CreateLayout();
22 LoadSettings();
23 ConnectWidgets();
24
25 connect(&Settings::Instance(), &Settings::ConfigChanged, this,
26 &CommonControllersWidget::LoadSettings);
27 }
28
29 void CommonControllersWidget::CreateLayout()
30 {
31 // i18n: This is "common" as in "shared", not the opposite of "uncommon"
32 m_common_box = new QGroupBox(tr("Common"));
33 m_common_layout = new QVBoxLayout();
34 m_common_bg_input = new QCheckBox(tr("Background Input"));
35 m_common_configure_controller_interface =
36 new NonDefaultQPushButton(tr("Alternate Input Sources"));
37 m_common_configure_sdl_hints = new NonDefaultQPushButton(tr("SDL Controller Settings"));
38
39 m_common_layout->addWidget(m_common_bg_input);
40 m_common_layout->addWidget(m_common_configure_controller_interface);
41 m_common_layout->addWidget(m_common_configure_sdl_hints);
42
43 m_common_box->setLayout(m_common_layout);
44
45 auto* layout = new QVBoxLayout;
46 layout->setContentsMargins(0, 0, 0, 0);
47 layout->setAlignment(Qt::AlignTop);
48 layout->addWidget(m_common_box);
49 setLayout(layout);
50 }
51
52 void CommonControllersWidget::ConnectWidgets()
53 {
54 connect(m_common_bg_input, &QCheckBox::toggled, this, &CommonControllersWidget::SaveSettings);
55 connect(m_common_configure_controller_interface, &QPushButton::clicked, this,
56 &CommonControllersWidget::OnControllerInterfaceConfigure);
57 connect(m_common_configure_sdl_hints, &QPushButton::clicked, this,
58 &CommonControllersWidget::OnSDLHintConfigure);
59 }
60
61 void CommonControllersWidget::OnControllerInterfaceConfigure()
62 {
63 ControllerInterfaceWindow* window = new ControllerInterfaceWindow(this);
64 window->setAttribute(Qt::WA_DeleteOnClose, true);
65 window->setWindowModality(Qt::WindowModality::WindowModal);
66 window->show();
67 }
68
69 void CommonControllersWidget::OnSDLHintConfigure()
70 {
71 SDLHintsWindow* window = new SDLHintsWindow(this);
72 window->setAttribute(Qt::WA_DeleteOnClose, true);
73 window->setWindowModality(Qt::WindowModality::WindowModal);
74 window->show();
75 }
76
77 void CommonControllersWidget::LoadSettings()
78 {
79 SignalBlocking(m_common_bg_input)->setChecked(Config::Get(Config::MAIN_INPUT_BACKGROUND_INPUT));
80 }
81
82 void CommonControllersWidget::SaveSettings()
83 {
84 Config::SetBaseOrCurrent(Config::MAIN_INPUT_BACKGROUND_INPUT, m_common_bg_input->isChecked());
85 Config::Save();
86 }