QQuickTextInput: added preeditText property
Task-number: QTBUG-49503 Change-Id: I803c9fc3bddba81d08e1dd450bc5a5f8a5605720 Reviewed-by: J-P Nurmi <jpnurmi@theqtcompany.com>
This commit is contained in:
parent
1c5dd75ee6
commit
1a4346d112
|
@ -277,6 +277,7 @@ static void qt_quickitems_defineModule(const char *uri, int major, int minor)
|
||||||
|
|
||||||
qmlRegisterType<QQuickListView, 7>(uri, 2, 7, "ListView");
|
qmlRegisterType<QQuickListView, 7>(uri, 2, 7, "ListView");
|
||||||
qmlRegisterType<QQuickGridView, 7>(uri, 2, 7, "GridView");
|
qmlRegisterType<QQuickGridView, 7>(uri, 2, 7, "GridView");
|
||||||
|
qmlRegisterType<QQuickTextInput, 7>(uri, 2, 7, "TextInput");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void initResources()
|
static void initResources()
|
||||||
|
|
|
@ -2184,6 +2184,7 @@ void QQuickTextInput::resetPasswordMaskDelay()
|
||||||
partial text input from an input method.
|
partial text input from an input method.
|
||||||
|
|
||||||
\readonly
|
\readonly
|
||||||
|
\sa preeditText
|
||||||
*/
|
*/
|
||||||
QString QQuickTextInput::displayText() const
|
QString QQuickTextInput::displayText() const
|
||||||
{
|
{
|
||||||
|
@ -2191,6 +2192,21 @@ QString QQuickTextInput::displayText() const
|
||||||
return d->m_textLayout.text().insert(d->m_textLayout.preeditAreaPosition(), d->m_textLayout.preeditAreaText());
|
return d->m_textLayout.text().insert(d->m_textLayout.preeditAreaPosition(), d->m_textLayout.preeditAreaText());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\qmlproperty string QtQuick::TextInput::preeditText
|
||||||
|
\readonly
|
||||||
|
\since 5.7
|
||||||
|
|
||||||
|
This property contains partial text input from an input method.
|
||||||
|
|
||||||
|
\sa displayText
|
||||||
|
*/
|
||||||
|
QString QQuickTextInput::preeditText() const
|
||||||
|
{
|
||||||
|
Q_D(const QQuickTextInput);
|
||||||
|
return d->m_textLayout.preeditAreaText();
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\qmlproperty bool QtQuick::TextInput::selectByMouse
|
\qmlproperty bool QtQuick::TextInput::selectByMouse
|
||||||
|
|
||||||
|
@ -3263,7 +3279,10 @@ void QQuickTextInputPrivate::processInputMethodEvent(QInputMethodEvent *event)
|
||||||
cursorPositionChanged = true;
|
cursorPositionChanged = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
QString oldPreeditString = m_textLayout.preeditAreaText();
|
||||||
m_textLayout.setPreeditArea(m_cursor, event->preeditString());
|
m_textLayout.setPreeditArea(m_cursor, event->preeditString());
|
||||||
|
if (oldPreeditString != m_textLayout.preeditAreaText())
|
||||||
|
emit q->preeditTextChanged();
|
||||||
const int oldPreeditCursor = m_preeditCursor;
|
const int oldPreeditCursor = m_preeditCursor;
|
||||||
m_preeditCursor = event->preeditString().length();
|
m_preeditCursor = event->preeditString().length();
|
||||||
hasImState = !event->preeditString().isEmpty();
|
hasImState = !event->preeditString().isEmpty();
|
||||||
|
|
|
@ -88,6 +88,7 @@ class Q_QUICK_PRIVATE_EXPORT QQuickTextInput : public QQuickImplicitSizeItem
|
||||||
Q_PROPERTY(QString passwordCharacter READ passwordCharacter WRITE setPasswordCharacter NOTIFY passwordCharacterChanged)
|
Q_PROPERTY(QString passwordCharacter READ passwordCharacter WRITE setPasswordCharacter NOTIFY passwordCharacterChanged)
|
||||||
Q_PROPERTY(int passwordMaskDelay READ passwordMaskDelay WRITE setPasswordMaskDelay RESET resetPasswordMaskDelay NOTIFY passwordMaskDelayChanged REVISION 3)
|
Q_PROPERTY(int passwordMaskDelay READ passwordMaskDelay WRITE setPasswordMaskDelay RESET resetPasswordMaskDelay NOTIFY passwordMaskDelayChanged REVISION 3)
|
||||||
Q_PROPERTY(QString displayText READ displayText NOTIFY displayTextChanged)
|
Q_PROPERTY(QString displayText READ displayText NOTIFY displayTextChanged)
|
||||||
|
Q_PROPERTY(QString preeditText READ preeditText NOTIFY preeditTextChanged REVISION 7)
|
||||||
Q_PROPERTY(bool autoScroll READ autoScroll WRITE setAutoScroll NOTIFY autoScrollChanged)
|
Q_PROPERTY(bool autoScroll READ autoScroll WRITE setAutoScroll NOTIFY autoScrollChanged)
|
||||||
Q_PROPERTY(bool selectByMouse READ selectByMouse WRITE setSelectByMouse NOTIFY selectByMouseChanged)
|
Q_PROPERTY(bool selectByMouse READ selectByMouse WRITE setSelectByMouse NOTIFY selectByMouseChanged)
|
||||||
Q_PROPERTY(SelectionMode mouseSelectionMode READ mouseSelectionMode WRITE setMouseSelectionMode NOTIFY mouseSelectionModeChanged)
|
Q_PROPERTY(SelectionMode mouseSelectionMode READ mouseSelectionMode WRITE setMouseSelectionMode NOTIFY mouseSelectionModeChanged)
|
||||||
|
@ -233,6 +234,7 @@ public:
|
||||||
void resetPasswordMaskDelay();
|
void resetPasswordMaskDelay();
|
||||||
|
|
||||||
QString displayText() const;
|
QString displayText() const;
|
||||||
|
Q_REVISION(7) QString preeditText() const;
|
||||||
|
|
||||||
QQmlComponent* cursorDelegate() const;
|
QQmlComponent* cursorDelegate() const;
|
||||||
void setCursorDelegate(QQmlComponent*);
|
void setCursorDelegate(QQmlComponent*);
|
||||||
|
@ -324,6 +326,7 @@ Q_SIGNALS:
|
||||||
void passwordCharacterChanged();
|
void passwordCharacterChanged();
|
||||||
Q_REVISION(3) void passwordMaskDelayChanged(int delay);
|
Q_REVISION(3) void passwordMaskDelayChanged(int delay);
|
||||||
void displayTextChanged();
|
void displayTextChanged();
|
||||||
|
Q_REVISION(7) void preeditTextChanged();
|
||||||
void activeFocusOnPressChanged(bool activeFocusOnPress);
|
void activeFocusOnPressChanged(bool activeFocusOnPress);
|
||||||
void autoScrollChanged(bool autoScroll);
|
void autoScrollChanged(bool autoScroll);
|
||||||
void selectByMouseChanged(bool selectByMouse);
|
void selectByMouseChanged(bool selectByMouse);
|
||||||
|
|
|
@ -2252,6 +2252,19 @@ void tst_qquicktextinput::inputMethods()
|
||||||
QGuiApplication::sendEvent(input, &preeditEvent);
|
QGuiApplication::sendEvent(input, &preeditEvent);
|
||||||
QCOMPARE(input->text(), QString("Our Goodbye world!"));
|
QCOMPARE(input->text(), QString("Our Goodbye world!"));
|
||||||
QCOMPARE(input->displayText(), QString("Our GooPREEDITdbye world!"));
|
QCOMPARE(input->displayText(), QString("Our GooPREEDITdbye world!"));
|
||||||
|
QCOMPARE(input->preeditText(), QString("PREEDIT"));
|
||||||
|
|
||||||
|
QInputMethodEvent preeditEvent2("PREEDIT2", QList<QInputMethodEvent::Attribute>());
|
||||||
|
QGuiApplication::sendEvent(input, &preeditEvent2);
|
||||||
|
QCOMPARE(input->text(), QString("Our Goodbye world!"));
|
||||||
|
QCOMPARE(input->displayText(), QString("Our GooPREEDIT2dbye world!"));
|
||||||
|
QCOMPARE(input->preeditText(), QString("PREEDIT2"));
|
||||||
|
|
||||||
|
QInputMethodEvent preeditEvent3("", QList<QInputMethodEvent::Attribute>());
|
||||||
|
QGuiApplication::sendEvent(input, &preeditEvent3);
|
||||||
|
QCOMPARE(input->text(), QString("Our Goodbye world!"));
|
||||||
|
QCOMPARE(input->displayText(), QString("Our Goodbye world!"));
|
||||||
|
QCOMPARE(input->preeditText(), QString(""));
|
||||||
|
|
||||||
// input should reset selection even if replacement parameters are out of bounds
|
// input should reset selection even if replacement parameters are out of bounds
|
||||||
input->setText("text");
|
input->setText("text");
|
||||||
|
|
Loading…
Reference in New Issue