| | |
| | |
| |
|
| | #pragma once |
| |
|
| | #include <array> |
| | #include <atomic> |
| | #include <memory> |
| | #include <thread> |
| |
|
| | #include <QDialog> |
| | #include <QValidator> |
| |
|
| | #include "core/frontend/applets/software_keyboard.h" |
| |
|
| | class InputInterpreter; |
| |
|
| | namespace Core { |
| | class System; |
| | } |
| |
|
| | namespace Core::HID { |
| | enum class NpadButton : u64; |
| | } |
| |
|
| | namespace Ui { |
| | class QtSoftwareKeyboardDialog; |
| | } |
| |
|
| | class GMainWindow; |
| |
|
| | class QtSoftwareKeyboardDialog final : public QDialog { |
| | Q_OBJECT |
| |
|
| | public: |
| | QtSoftwareKeyboardDialog(QWidget* parent, Core::System& system_, bool is_inline_, |
| | Core::Frontend::KeyboardInitializeParameters initialize_parameters_); |
| | ~QtSoftwareKeyboardDialog() override; |
| |
|
| | void ShowNormalKeyboard(QPoint pos, QSize size); |
| |
|
| | void ShowTextCheckDialog(Service::AM::Frontend::SwkbdTextCheckResult text_check_result, |
| | std::u16string text_check_message); |
| |
|
| | void ShowInlineKeyboard(Core::Frontend::InlineAppearParameters appear_parameters, QPoint pos, |
| | QSize size); |
| |
|
| | void HideInlineKeyboard(); |
| |
|
| | void InlineTextChanged(Core::Frontend::InlineTextParameters text_parameters); |
| |
|
| | void ExitKeyboard(); |
| |
|
| | signals: |
| | void SubmitNormalText(Service::AM::Frontend::SwkbdResult result, std::u16string submitted_text, |
| | bool confirmed = false) const; |
| |
|
| | void SubmitInlineText(Service::AM::Frontend::SwkbdReplyType reply_type, |
| | std::u16string submitted_text, s32 cursor_position) const; |
| |
|
| | public slots: |
| | void open() override; |
| | void reject() override; |
| |
|
| | protected: |
| | |
| | void keyPressEvent(QKeyEvent* event) override; |
| |
|
| | private: |
| | enum class Direction { |
| | Left, |
| | Up, |
| | Right, |
| | Down, |
| | }; |
| |
|
| | enum class BottomOSKIndex { |
| | LowerCase, |
| | UpperCase, |
| | NumberPad, |
| | }; |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | void MoveAndResizeWindow(QPoint pos, QSize size); |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | void RescaleKeyboardElements(float width, float height, float dpi_scale); |
| |
|
| | |
| | void SetKeyboardType(); |
| |
|
| | |
| | void SetPasswordMode(); |
| |
|
| | |
| | void SetTextDrawType(); |
| |
|
| | |
| | void SetControllerImage(); |
| |
|
| | |
| | void DisableKeyboardButtons(); |
| |
|
| | |
| | void SetBackspaceOkEnabled(); |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | bool ValidateInputText(const QString& input_text); |
| |
|
| | |
| | void ChangeBottomOSKIndex(); |
| |
|
| | |
| | void NormalKeyboardButtonClicked(QPushButton* button); |
| |
|
| | |
| | void InlineKeyboardButtonClicked(QPushButton* button); |
| |
|
| | |
| | |
| | |
| | |
| | void InlineTextInsertString(std::u16string_view string); |
| |
|
| | |
| | void SetupMouseHover(); |
| |
|
| | |
| | |
| | |
| | |
| | |
| | template <Core::HID::NpadButton... T> |
| | void HandleButtonPressedOnce(); |
| |
|
| | |
| | |
| | |
| | |
| | |
| | template <Core::HID::NpadButton... T> |
| | void HandleButtonHold(); |
| |
|
| | |
| | |
| | |
| | |
| | |
| | void TranslateButtonPress(Core::HID::NpadButton button); |
| |
|
| | |
| | |
| | |
| | |
| | |
| | void MoveButtonDirection(Direction direction); |
| |
|
| | |
| | |
| | |
| | |
| | |
| | void MoveTextCursorDirection(Direction direction); |
| |
|
| | void StartInputThread(); |
| | void StopInputThread(); |
| |
|
| | |
| | void InputThread(); |
| |
|
| | std::unique_ptr<Ui::QtSoftwareKeyboardDialog> ui; |
| |
|
| | Core::System& system; |
| |
|
| | |
| | bool is_inline; |
| |
|
| | |
| | Core::Frontend::KeyboardInitializeParameters initialize_parameters; |
| |
|
| | |
| | std::u16string current_text; |
| | s32 cursor_position{0}; |
| |
|
| | static constexpr std::size_t NUM_ROWS_NORMAL = 5; |
| | static constexpr std::size_t NUM_COLUMNS_NORMAL = 12; |
| | static constexpr std::size_t NUM_ROWS_NUMPAD = 4; |
| | static constexpr std::size_t NUM_COLUMNS_NUMPAD = 4; |
| |
|
| | |
| | std::array<std::array<std::array<QPushButton*, NUM_COLUMNS_NORMAL>, NUM_ROWS_NORMAL>, 2> |
| | keyboard_buttons; |
| | |
| | std::array<std::array<QPushButton*, NUM_COLUMNS_NUMPAD>, NUM_ROWS_NUMPAD> numberpad_buttons; |
| |
|
| | |
| | std::array<QPushButton*, 112> all_buttons; |
| |
|
| | std::size_t row{0}; |
| | std::size_t column{0}; |
| |
|
| | BottomOSKIndex bottom_osk_index{BottomOSKIndex::LowerCase}; |
| | std::atomic<bool> caps_lock_enabled{false}; |
| |
|
| | std::unique_ptr<InputInterpreter> input_interpreter; |
| |
|
| | std::thread input_thread; |
| |
|
| | std::atomic<bool> input_thread_running{}; |
| | }; |
| |
|
| | class QtSoftwareKeyboard final : public QObject, public Core::Frontend::SoftwareKeyboardApplet { |
| | Q_OBJECT |
| |
|
| | public: |
| | explicit QtSoftwareKeyboard(GMainWindow& parent); |
| | ~QtSoftwareKeyboard() override; |
| |
|
| | void Close() const override { |
| | ExitKeyboard(); |
| | } |
| |
|
| | void InitializeKeyboard(bool is_inline, |
| | Core::Frontend::KeyboardInitializeParameters initialize_parameters, |
| | SubmitNormalCallback submit_normal_callback_, |
| | SubmitInlineCallback submit_inline_callback_) override; |
| |
|
| | void ShowNormalKeyboard() const override; |
| |
|
| | void ShowTextCheckDialog(Service::AM::Frontend::SwkbdTextCheckResult text_check_result, |
| | std::u16string text_check_message) const override; |
| |
|
| | void ShowInlineKeyboard( |
| | Core::Frontend::InlineAppearParameters appear_parameters) const override; |
| |
|
| | void HideInlineKeyboard() const override; |
| |
|
| | void InlineTextChanged(Core::Frontend::InlineTextParameters text_parameters) const override; |
| |
|
| | void ExitKeyboard() const override; |
| |
|
| | signals: |
| | void MainWindowInitializeKeyboard( |
| | bool is_inline, Core::Frontend::KeyboardInitializeParameters initialize_parameters) const; |
| |
|
| | void MainWindowShowNormalKeyboard() const; |
| |
|
| | void MainWindowShowTextCheckDialog( |
| | Service::AM::Frontend::SwkbdTextCheckResult text_check_result, |
| | std::u16string text_check_message) const; |
| |
|
| | void MainWindowShowInlineKeyboard( |
| | Core::Frontend::InlineAppearParameters appear_parameters) const; |
| |
|
| | void MainWindowHideInlineKeyboard() const; |
| |
|
| | void MainWindowInlineTextChanged(Core::Frontend::InlineTextParameters text_parameters) const; |
| |
|
| | void MainWindowExitKeyboard() const; |
| |
|
| | private: |
| | void SubmitNormalText(Service::AM::Frontend::SwkbdResult result, std::u16string submitted_text, |
| | bool confirmed) const; |
| |
|
| | void SubmitInlineText(Service::AM::Frontend::SwkbdReplyType reply_type, |
| | std::u16string submitted_text, s32 cursor_position) const; |
| |
|
| | mutable SubmitNormalCallback submit_normal_callback; |
| | mutable SubmitInlineCallback submit_inline_callback; |
| | }; |
| |
|