mirror of
https://github.com/yuzu-emu/yuzu-android.git
synced 2025-06-21 00:57:53 -05:00
am: Deglobalize software keyboard applet
This commit is contained in:
@ -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) {}
|
||||
|
||||
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();
|
||||
|
||||
text = dialog.text;
|
||||
return dialog.ok;
|
||||
std::u16string QtSoftwareKeyboardDialog::GetText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
bool QtSoftwareKeyboardDialog::GetStatus() {
|
||||
return ok;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
void QtSoftwareKeyboard::SendTextCheckDialog(std::u16string error_message) const {
|
||||
QMetaObject::invokeMethod(&main_window, "SoftwareKeyboardInvokeCheckDialog",
|
||||
Qt::BlockingQueuedConnection, Q_ARG(std::u16string, error_message));
|
||||
}
|
||||
|
@ -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;
|
||||
};
|
||||
|
Reference in New Issue
Block a user