qt: Add Qt frontend for controller selector applet

This commit is contained in:
Zach Hilman
2018-12-24 17:35:40 -05:00
parent 0f82eb83f9
commit 56beb2c85b
5 changed files with 146 additions and 0 deletions

View File

@@ -7,6 +7,8 @@ add_executable(yuzu
Info.plist
about_dialog.cpp
about_dialog.h
applets/controller.cpp
applets/controller.h
applets/profile_select.cpp
applets/profile_select.h
applets/software_keyboard.cpp

View File

@@ -0,0 +1,65 @@
// Copyright 2018 yuzu Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#include <QDialogButtonBox>
#include <QLabel>
#include "core/hle/lock.h"
#include "core/hle/service/hid/hid.h"
#include "yuzu/applets/controller.h"
#include "yuzu/configuration/configure_input_simple.h"
#include "yuzu/main.h"
QtControllerAppletDialog::QtControllerAppletDialog(
QWidget* parent, Core::Frontend::ControllerParameters parameters) {
layout = new QVBoxLayout;
buttons = new QDialogButtonBox;
buttons->addButton(tr("Cancel"), QDialogButtonBox::RejectRole);
buttons->addButton(tr("OK"), QDialogButtonBox::AcceptRole);
connect(buttons, &QDialogButtonBox::accepted, this, &QtControllerAppletDialog::accept);
connect(buttons, &QDialogButtonBox::rejected, this, &QtControllerAppletDialog::reject);
input = new ConfigureInputSimple(this, parameters);
layout->addWidget(input);
layout->addWidget(buttons);
setLayout(layout);
}
QtControllerAppletDialog::~QtControllerAppletDialog() = default;
void QtControllerAppletDialog::accept() {
input->applyConfiguration();
ok = true;
QDialog::accept();
}
void QtControllerAppletDialog::reject() {
ok = false;
QDialog::reject();
}
bool QtControllerAppletDialog::GetStatus() const {
return ok;
}
QtControllerApplet::QtControllerApplet(GMainWindow& parent) {
connect(this, &QtControllerApplet::MainWindowReconfigureControllers, &parent,
&GMainWindow::ControllerAppletReconfigureControllers, Qt::QueuedConnection);
connect(&parent, &GMainWindow::ControllerAppletReconfigureFinished, this,
&QtControllerApplet::MainWindowReconfigureFinished, Qt::QueuedConnection);
}
QtControllerApplet::~QtControllerApplet() = default;
void QtControllerApplet::ReconfigureControllers(
std::function<void(bool)> completed, Core::Frontend::ControllerParameters parameters) const {
this->completed = std::move(completed);
emit MainWindowReconfigureControllers(parameters);
}
void QtControllerApplet::MainWindowReconfigureFinished(bool ok) {
// Acquire the HLE mutex
std::lock_guard<std::recursive_mutex> lock(HLE::g_hle_lock);
completed(ok);
}

View File

@@ -0,0 +1,55 @@
// Copyright 2018 yuzu Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#pragma once
#include <QDialog>
#include "core/frontend/applets/controller.h"
class ConfigureInputSimple;
class GMainWindow;
class QDialogButtonBox;
class QVBoxLayout;
class QtControllerAppletDialog final : public QDialog {
Q_OBJECT
public:
QtControllerAppletDialog(QWidget* parent, Core::Frontend::ControllerParameters parameters);
~QtControllerAppletDialog() override;
void accept() override;
void reject() override;
bool GetStatus() const;
private:
bool ok = false;
QVBoxLayout* layout;
QDialogButtonBox* buttons;
ConfigureInputSimple* input;
Core::Frontend::ControllerParameters parameters;
};
class QtControllerApplet final : public QObject, public Core::Frontend::ControllerApplet {
Q_OBJECT
public:
explicit QtControllerApplet(GMainWindow& parent);
~QtControllerApplet() override;
void ReconfigureControllers(std::function<void(bool)> completed,
Core::Frontend::ControllerParameters parameters) const override;
signals:
void MainWindowReconfigureControllers(Core::Frontend::ControllerParameters parameters) const;
private:
void MainWindowReconfigureFinished(bool ok);
mutable std::function<void(bool)> completed;
};

View File

@@ -8,12 +8,15 @@
#include <thread>
// VFS includes must be before glad as they will conflict with Windows file api, which uses defines.
#include "applets/controller.h"
#include "applets/profile_select.h"
#include "applets/software_keyboard.h"
#include "applets/web_browser.h"
#include "configuration/configure_input_simple.h"
#include "configuration/configure_per_general.h"
#include "core/file_sys/vfs.h"
#include "core/file_sys/vfs_real.h"
#include "core/frontend/applets/controller.h"
#include "core/frontend/scope_acquire_window_context.h"
#include "core/hle/service/acc/profile_manager.h"
#include "core/hle/service/am/applets/applets.h"
@@ -222,6 +225,17 @@ GMainWindow::~GMainWindow() {
delete render_window;
}
void GMainWindow::ControllerAppletReconfigureControllers(
const Core::Frontend::ControllerParameters& parameters) {
QtControllerAppletDialog dialog(this, parameters);
dialog.setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint |
Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint);
dialog.setWindowModality(Qt::WindowModal);
dialog.exec();
emit ControllerAppletReconfigureFinished(dialog.GetStatus());
}
void GMainWindow::ProfileSelectorSelectProfile() {
QtProfileSelectionDialog dialog(this);
dialog.setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint |
@@ -777,6 +791,7 @@ bool GMainWindow::LoadROM(const QString& filename) {
system.SetGPUDebugContext(debug_context);
system.SetControllerApplet(std::make_unique<QtControllerApplet>(*this));
system.SetProfileSelector(std::make_unique<QtProfileSelector>(*this));
system.SetSoftwareKeyboard(std::make_unique<QtSoftwareKeyboard>(*this));
system.SetWebBrowser(std::make_unique<QtWebBrowser>(*this));
@@ -1491,6 +1506,7 @@ void GMainWindow::OnMenuRecentFile() {
void GMainWindow::OnStartGame() {
emu_thread->SetRunning(true);
qRegisterMetaType<Core::Frontend::ControllerParameters>("Core::Frontend::ControllerParameters");
qRegisterMetaType<Core::Frontend::SoftwareKeyboardParameters>(
"Core::Frontend::SoftwareKeyboardParameters");
qRegisterMetaType<Core::System::ResultStatus>("Core::System::ResultStatus");

View File

@@ -33,6 +33,7 @@ class WaitTreeWidget;
enum class GameListOpenTarget;
namespace Core::Frontend {
struct ControllerParameters;
struct SoftwareKeyboardParameters;
} // namespace Core::Frontend
@@ -102,7 +103,10 @@ signals:
// Signal that tells widgets to update icons to use the current theme
void UpdateThemedIcons();
void ControllerAppletReconfigureFinished(bool ok);
void ProfileSelectorFinishedSelection(std::optional<Service::Account::UUID> uuid);
void SoftwareKeyboardFinishedText(std::optional<std::u16string> text);
void SoftwareKeyboardFinishedCheckDialog();
@@ -111,7 +115,11 @@ signals:
public slots:
void OnLoadComplete();
void ControllerAppletReconfigureControllers(
const Core::Frontend::ControllerParameters& parameters);
void ProfileSelectorSelectProfile();
void SoftwareKeyboardGetText(const Core::Frontend::SoftwareKeyboardParameters& parameters);
void SoftwareKeyboardInvokeCheckDialog(std::u16string error_message);
void WebBrowserOpenPage(std::string_view filename, std::string_view arguments);