diff options
Diffstat (limited to 'src/yuzu')
-rw-r--r-- | src/yuzu/applets/software_keyboard.cpp | 55 | ||||
-rw-r--r-- | src/yuzu/applets/software_keyboard.h | 33 | ||||
-rw-r--r-- | src/yuzu/main.cpp | 7 | ||||
-rw-r--r-- | src/yuzu/main.h | 9 |
4 files changed, 70 insertions, 34 deletions
diff --git a/src/yuzu/applets/software_keyboard.cpp b/src/yuzu/applets/software_keyboard.cpp index bd8bd0dd0..fad150ec1 100644 --- a/src/yuzu/applets/software_keyboard.cpp +++ b/src/yuzu/applets/software_keyboard.cpp @@ -2,21 +2,20 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. -#include <locale> +#include <algorithm> #include <QDialogButtonBox> #include <QFont> #include <QLabel> #include <QLineEdit> #include <QVBoxLayout> -#include "common/logging/backend.h" -#include "common/string_util.h" #include "yuzu/applets/software_keyboard.h" +#include "yuzu/main.h" QtSoftwareKeyboardValidator::QtSoftwareKeyboardValidator( - Frontend::SoftwareKeyboardApplet::Parameters parameters) + Core::Frontend::SoftwareKeyboardParameters parameters) : parameters(std::move(parameters)) {} -QValidator::State QtSoftwareKeyboardValidator::validate(QString& input, int&) const { +QValidator::State QtSoftwareKeyboardValidator::validate(QString& input, int& pos) const { if (input.size() > parameters.max_length) return Invalid; if (parameters.disable_space && input.contains(' ')) @@ -28,18 +27,20 @@ QValidator::State QtSoftwareKeyboardValidator::validate(QString& input, int&) co if (parameters.disable_slash && (input.contains('/') || input.contains('\\'))) return Invalid; if (parameters.disable_number && - std::any_of(input.begin(), input.end(), [](QChar c) { return c.isDigit(); })) + std::any_of(input.begin(), input.end(), [](QChar c) { return c.isDigit(); })) { return Invalid; + } if (parameters.disable_download_code && - std::any_of(input.begin(), input.end(), [](QChar c) { return c == 'O' || c == 'I'; })) + std::any_of(input.begin(), input.end(), [](QChar c) { return c == 'O' || c == 'I'; })) { return Invalid; + } return Acceptable; } QtSoftwareKeyboardDialog::QtSoftwareKeyboardDialog( - QWidget* parent, Frontend::SoftwareKeyboardApplet::Parameters parameters_) + QWidget* parent, Core::Frontend::SoftwareKeyboardParameters parameters_) : QDialog(parent), parameters(std::move(parameters_)) { layout = new QVBoxLayout; @@ -79,9 +80,11 @@ QtSoftwareKeyboardDialog::QtSoftwareKeyboardDialog( layout->addWidget(line_edit); layout->addWidget(buttons); setLayout(layout); - setWindowTitle("Software Keyboard"); + setWindowTitle(tr("Software Keyboard")); } +QtSoftwareKeyboardDialog::~QtSoftwareKeyboardDialog() = default; + void QtSoftwareKeyboardDialog::Submit() { ok = true; text = line_edit->text().toStdU16String(); @@ -90,19 +93,33 @@ void QtSoftwareKeyboardDialog::Submit() { void QtSoftwareKeyboardDialog::Reject() { ok = false; - text = Common::UTF8ToUTF16(""); + text.clear(); accept(); } -QtSoftwareKeyboard::QtSoftwareKeyboard(QWidget& parent) : parent(parent) {} +std::u16string QtSoftwareKeyboardDialog::GetText() { + return text; +} + +bool QtSoftwareKeyboardDialog::GetStatus() { + return ok; +} -bool QtSoftwareKeyboard::GetText(Parameters parameters, std::u16string& text) { - QtSoftwareKeyboardDialog dialog(&parent, parameters); - dialog.setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | - Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint); - dialog.setWindowModality(Qt::WindowModal); - dialog.exec(); +QtSoftwareKeyboard::QtSoftwareKeyboard(GMainWindow& parent) : main_window(parent) {} + +QtSoftwareKeyboard::~QtSoftwareKeyboard() = default; + +bool QtSoftwareKeyboard::GetText(Core::Frontend::SoftwareKeyboardParameters parameters, + std::u16string& text) const { + bool success; + QMetaObject::invokeMethod(&main_window, "SoftwareKeyboardGetText", Qt::BlockingQueuedConnection, + Q_RETURN_ARG(bool, success), + Q_ARG(Core::Frontend::SoftwareKeyboardParameters, parameters), + Q_ARG(std::u16string&, text)); + return success; +} - text = dialog.text; - return dialog.ok; +void QtSoftwareKeyboard::SendTextCheckDialog(std::u16string error_message) const { + QMetaObject::invokeMethod(&main_window, "SoftwareKeyboardInvokeCheckDialog", + Qt::BlockingQueuedConnection, Q_ARG(std::u16string, error_message)); } diff --git a/src/yuzu/applets/software_keyboard.h b/src/yuzu/applets/software_keyboard.h index 2a18419db..1069c10ec 100644 --- a/src/yuzu/applets/software_keyboard.h +++ b/src/yuzu/applets/software_keyboard.h @@ -3,11 +3,13 @@ // Refer to the license.txt file included. #pragma once + #include <QDialog> #include <QValidator> #include "common/assert.h" #include "core/frontend/applets/software_keyboard.h" +class GMainWindow; class QDialogButtonBox; class QLabel; class QLineEdit; @@ -16,11 +18,11 @@ class QtSoftwareKeyboard; class QtSoftwareKeyboardValidator final : public QValidator { public: - explicit QtSoftwareKeyboardValidator(Frontend::SoftwareKeyboardApplet::Parameters parameters); - State validate(QString&, int&) const override; + explicit QtSoftwareKeyboardValidator(Core::Frontend::SoftwareKeyboardParameters parameters); + State validate(QString& input, int& pos) const override; private: - Frontend::SoftwareKeyboardApplet::Parameters parameters; + Core::Frontend::SoftwareKeyboardParameters parameters; }; class QtSoftwareKeyboardDialog final : public QDialog { @@ -28,10 +30,15 @@ class QtSoftwareKeyboardDialog final : public QDialog { public: QtSoftwareKeyboardDialog(QWidget* parent, - Frontend::SoftwareKeyboardApplet::Parameters parameters); + Core::Frontend::SoftwareKeyboardParameters parameters); + ~QtSoftwareKeyboardDialog() override; + void Submit(); void Reject(); + std::u16string GetText(); + bool GetStatus(); + private: bool ok = false; std::u16string text; @@ -43,20 +50,18 @@ private: QLineEdit* line_edit; QVBoxLayout* layout; - Frontend::SoftwareKeyboardApplet::Parameters parameters; - - friend class QtSoftwareKeyboard; + Core::Frontend::SoftwareKeyboardParameters parameters; }; -class QtSoftwareKeyboard final : public QObject, public Frontend::SoftwareKeyboardApplet { +class QtSoftwareKeyboard final : public QObject, public Core::Frontend::SoftwareKeyboardApplet { public: - explicit QtSoftwareKeyboard(QWidget& parent); - bool GetText(Parameters parameters, std::u16string& text) override; + explicit QtSoftwareKeyboard(GMainWindow& parent); + ~QtSoftwareKeyboard() override; - ~QtSoftwareKeyboard() { - UNREACHABLE(); - } + bool GetText(Core::Frontend::SoftwareKeyboardParameters parameters, + std::u16string& text) const override; + void SendTextCheckDialog(std::u16string error_message) const override; private: - QWidget& parent; + GMainWindow& main_window; }; diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index 7b2a01169..9b2c09f32 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -561,7 +561,7 @@ bool GMainWindow::LoadROM(const QString& filename) { system.SetGPUDebugContext(debug_context); - Service::AM::Applets::RegisterSoftwareKeyboard(std::make_shared<QtSoftwareKeyboard>(*this)); + system.SetSoftwareKeyboard(std::make_unique<QtSoftwareKeyboard>(*this)); const Core::System::ResultStatus result{system.Load(*render_window, filename.toStdString())}; @@ -1232,8 +1232,13 @@ void GMainWindow::OnMenuRecentFile() { void GMainWindow::OnStartGame() { emu_thread->SetRunning(true); + + qRegisterMetaType<Core::Frontend::SoftwareKeyboardParameters>( + "core::Frontend::SoftwareKeyboardParameters"); qRegisterMetaType<Core::System::ResultStatus>("Core::System::ResultStatus"); qRegisterMetaType<std::string>("std::string"); + qRegisterMetaType<std::u16string>("std::u16string"); + connect(emu_thread.get(), &EmuThread::ErrorThrown, this, &GMainWindow::OnCoreError); ui.action_Start->setEnabled(false); diff --git a/src/yuzu/main.h b/src/yuzu/main.h index 929250e8c..38074e3f0 100644 --- a/src/yuzu/main.h +++ b/src/yuzu/main.h @@ -29,6 +29,10 @@ class ProfilerWidget; class WaitTreeWidget; enum class GameListOpenTarget; +namespace Core::Frontend { +struct SoftwareKeyboardParameters; +} // namespace Core::Frontend + namespace FileSys { class RegisteredCacheUnion; class VfsFilesystem; @@ -95,6 +99,11 @@ signals: // Signal that tells widgets to update icons to use the current theme void UpdateThemedIcons(); +public slots: + bool SoftwareKeyboardGetText(const Core::Frontend::SoftwareKeyboardParameters& parameters, + std::u16string& text); + void SoftwareKeyboardInvokeCheckDialog(std::u16string error_message); + private: void InitializeWidgets(); void InitializeDebugWidgets(); |