mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-07-06 06:51:26 +12:00
cellOskDialog: fixes for multi-line dialog
This commit is contained in:
parent
e5aede7aa7
commit
eb4d612bb9
2 changed files with 41 additions and 8 deletions
|
@ -1,4 +1,4 @@
|
||||||
|
|
||||||
#include "osk_dialog_frame.h"
|
#include "osk_dialog_frame.h"
|
||||||
#include "Emu/Cell/Modules/cellMsgDialog.h"
|
#include "Emu/Cell/Modules/cellMsgDialog.h"
|
||||||
|
|
||||||
|
@ -93,26 +93,58 @@ void osk_dialog_frame::Create(const std::string& title, const std::u16string& me
|
||||||
input->setFixedWidth(lineEditWidth());
|
input->setFixedWidth(lineEditWidth());
|
||||||
input->setText(text);
|
input->setText(text);
|
||||||
input->setFocus();
|
input->setFocus();
|
||||||
|
input->moveCursor(QTextCursor::End);
|
||||||
|
m_text_old = text;
|
||||||
|
|
||||||
connect(input, &QTextEdit::textChanged, [=]()
|
connect(input, &QTextEdit::textChanged, [=]()
|
||||||
{
|
{
|
||||||
QString text = input->toPlainText();
|
QString text = input->toPlainText();
|
||||||
text.chop(text.length() - charlimit);
|
|
||||||
|
|
||||||
if (options & CELL_OSKDIALOG_NO_SPACE)
|
if (text == m_text_old)
|
||||||
{
|
{
|
||||||
text.remove(QRegExp("\\s+"));
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
input->setPlainText(text);
|
|
||||||
|
|
||||||
QTextCursor cursor = input->textCursor();
|
QTextCursor cursor = input->textCursor();
|
||||||
cursor.setPosition(QTextCursor::End);
|
const int cursor_pos_new = cursor.position();
|
||||||
|
const int cursor_pos_old = cursor_pos_new + m_text_old.length() - text.length();
|
||||||
|
|
||||||
|
// Reset to old state if character limit was reached
|
||||||
|
if ((u32)m_text_old.length() >= charlimit && (u32)text.length() > charlimit)
|
||||||
|
{
|
||||||
|
input->blockSignals(true);
|
||||||
|
input->setPlainText(m_text_old);
|
||||||
|
cursor.setPosition(cursor_pos_old);
|
||||||
|
input->setTextCursor(cursor);
|
||||||
|
input->blockSignals(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int cursor_pos = cursor.position();
|
||||||
|
|
||||||
|
// Clear text of spaces if necessary
|
||||||
|
if (options & CELL_OSKDIALOG_NO_SPACE)
|
||||||
|
{
|
||||||
|
int trim_len = text.length();
|
||||||
|
text.remove(QRegExp("\\s+"));
|
||||||
|
trim_len -= text.length();
|
||||||
|
cursor_pos -= trim_len;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Crop if more than one character was pasted and the character limit was exceeded
|
||||||
|
text.chop(text.length() - charlimit);
|
||||||
|
|
||||||
|
// Set new text and block signals to prevent infinite loop
|
||||||
|
input->blockSignals(true);
|
||||||
|
input->setPlainText(text);
|
||||||
|
cursor.setPosition(cursor_pos);
|
||||||
input->setTextCursor(cursor);
|
input->setTextCursor(cursor);
|
||||||
|
input->blockSignals(false);
|
||||||
|
|
||||||
|
m_text_old = text;
|
||||||
|
|
||||||
inputCount->setText(QString("%1/%2").arg(text.length()).arg(charlimit));
|
inputCount->setText(QString("%1/%2").arg(text.length()).arg(charlimit));
|
||||||
SetOskText(text);
|
SetOskText(text);
|
||||||
|
|
||||||
on_osk_input_entered();
|
on_osk_input_entered();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -22,4 +22,5 @@ private:
|
||||||
void SetOskText(const QString& text);
|
void SetOskText(const QString& text);
|
||||||
|
|
||||||
custom_dialog* m_dialog = nullptr;
|
custom_dialog* m_dialog = nullptr;
|
||||||
|
QString m_text_old;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue