mirror of
				https://github.com/PabloMK7/citra.git
				synced 2025-10-31 13:50:03 +00:00 
			
		
		
		
	Merge pull request #4700 from zhaowenlan1779/swkbd-2
applets/swkbd: Add callback support
This commit is contained in:
		
						commit
						536e4de499
					
				
					 9 changed files with 156 additions and 94 deletions
				
			
		|  | @ -14,20 +14,6 @@ | |||
| #include "core/file_sys/file_backend.h" | ||||
| #include "core/hle/service/ptm/ptm.h" | ||||
| 
 | ||||
| /**
 | ||||
|  * Converts a UTF-16 text in a container to a UTF-8 std::string. | ||||
|  */ | ||||
| template <typename T> | ||||
| std::string TextFromBuffer(const T& text) { | ||||
|     const auto text_end = std::find(text.begin(), text.end(), u'\0'); | ||||
|     const std::size_t text_size = std::distance(text.begin(), text_end); | ||||
|     std::u16string buffer(text_size, 0); | ||||
|     std::transform(text.begin(), text_end, buffer.begin(), [](u16_le character) { | ||||
|         return static_cast<char16_t>(static_cast<u16>(character)); | ||||
|     }); | ||||
|     return Common::UTF16ToUTF8(buffer); | ||||
| } | ||||
| 
 | ||||
| QtMiiSelectorDialog::QtMiiSelectorDialog(QWidget* parent, QtMiiSelector* mii_selector_) | ||||
|     : QDialog(parent), mii_selector(mii_selector_) { | ||||
|     using namespace Frontend; | ||||
|  | @ -71,7 +57,7 @@ QtMiiSelectorDialog::QtMiiSelectorDialog(QWidget* parent, QtMiiSelector* mii_sel | |||
|                 file->Read(saved_miis_offset, sizeof(mii), mii_raw.data()); | ||||
|                 std::memcpy(&mii, mii_raw.data(), sizeof(mii)); | ||||
|                 if (mii.mii_id != 0) { | ||||
|                     std::string name = TextFromBuffer(mii.mii_name); | ||||
|                     std::string name = Common::UTF16BufferToUTF8(mii.mii_name); | ||||
|                     miis.push_back(mii); | ||||
|                     combobox->addItem(QString::fromStdString(name)); | ||||
|                 } | ||||
|  |  | |||
|  | @ -109,14 +109,20 @@ void QtKeyboardDialog::HandleValidationError(Frontend::ValidationError error) { | |||
| 
 | ||||
| QtKeyboard::QtKeyboard(QWidget& parent_) : parent(parent_) {} | ||||
| 
 | ||||
| void QtKeyboard::Setup(const Frontend::KeyboardConfig& config) { | ||||
|     SoftwareKeyboard::Setup(config); | ||||
| void QtKeyboard::Execute(const Frontend::KeyboardConfig& config) { | ||||
|     SoftwareKeyboard::Execute(config); | ||||
|     if (this->config.button_config != Frontend::ButtonConfig::None) { | ||||
|         ok_id = static_cast<u8>(this->config.button_config); | ||||
|     } | ||||
|     QMetaObject::invokeMethod(this, "OpenInputDialog", Qt::BlockingQueuedConnection); | ||||
| } | ||||
| 
 | ||||
| void QtKeyboard::ShowError(const std::string& error) { | ||||
|     QString message = QString::fromStdString(error); | ||||
|     QMetaObject::invokeMethod(this, "ShowErrorDialog", Qt::BlockingQueuedConnection, | ||||
|                               Q_ARG(QString, message)); | ||||
| } | ||||
| 
 | ||||
| void QtKeyboard::OpenInputDialog() { | ||||
|     QtKeyboardDialog dialog(&parent, this); | ||||
|     dialog.setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | | ||||
|  | @ -127,3 +133,7 @@ void QtKeyboard::OpenInputDialog() { | |||
|              dialog.button); | ||||
|     Finalize(dialog.text.toStdString(), dialog.button); | ||||
| } | ||||
| 
 | ||||
| void QtKeyboard::ShowErrorDialog(QString message) { | ||||
|     QMessageBox::critical(&parent, tr("Software Keyboard"), message); | ||||
| } | ||||
|  |  | |||
|  | @ -48,10 +48,12 @@ class QtKeyboard final : public QObject, public Frontend::SoftwareKeyboard { | |||
| 
 | ||||
| public: | ||||
|     explicit QtKeyboard(QWidget& parent); | ||||
|     void Setup(const Frontend::KeyboardConfig& config) override; | ||||
|     void Execute(const Frontend::KeyboardConfig& config) override; | ||||
|     void ShowError(const std::string& error) override; | ||||
| 
 | ||||
| private: | ||||
|     Q_INVOKABLE void OpenInputDialog(); | ||||
|     Q_INVOKABLE void ShowErrorDialog(QString message); | ||||
| 
 | ||||
|     /// Index of the buttons
 | ||||
|     u8 ok_id; | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue