Support input method tentative commit string in QLineControl
Implements similar behavior as 8bd40fef07
did for QLineEdit.
Change-Id: I55de1f9a6703aca629f2e84398e481636c96eeca
Reviewed-by: Joona Petrell <joona.t.petrell@nokia.com>
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
This commit is contained in:
parent
9eba201a48
commit
7a0c060268
@ -347,6 +347,30 @@ QRect QLineControl::cursorRect() const
|
||||
return QRect(cix-5, 0, w+9, ch);
|
||||
}
|
||||
|
||||
QString QLineControl::text() const
|
||||
{
|
||||
QString content = m_text;
|
||||
if (!m_tentativeCommit.isEmpty())
|
||||
content.insert(m_cursor, m_tentativeCommit);
|
||||
QString res = m_maskData ? stripString(content) : content;
|
||||
return (res.isNull() ? QString::fromLatin1("") : res);
|
||||
}
|
||||
|
||||
// like text() but doesn't include preedit
|
||||
QString QLineControl::realText() const
|
||||
{
|
||||
QString res = m_maskData ? stripString(m_text) : m_text;
|
||||
return (res.isNull() ? QString::fromLatin1("") : res);
|
||||
}
|
||||
|
||||
void QLineControl::setText(const QString &txt)
|
||||
{
|
||||
if (composeMode())
|
||||
qApp->inputPanel()->reset();
|
||||
m_tentativeCommit.clear();
|
||||
internalSetText(txt, -1, false);
|
||||
}
|
||||
|
||||
/*!
|
||||
\internal
|
||||
|
||||
@ -414,7 +438,7 @@ void QLineControl::moveCursor(int pos, bool mark)
|
||||
*/
|
||||
void QLineControl::processInputMethodEvent(QInputMethodEvent *event)
|
||||
{
|
||||
int priorState = 0;
|
||||
int priorState = -1;
|
||||
bool isGettingInput = !event->commitString().isEmpty()
|
||||
|| event->preeditString() != preeditAreaText()
|
||||
|| event->replacementLength() > 0;
|
||||
@ -499,7 +523,15 @@ void QLineControl::processInputMethodEvent(QInputMethodEvent *event)
|
||||
emitCursorPositionChanged();
|
||||
else if (m_preeditCursor != oldPreeditCursor)
|
||||
emit updateMicroFocus();
|
||||
if (isGettingInput)
|
||||
|
||||
bool tentativeCommitChanged = (m_tentativeCommit != event->tentativeCommitString());
|
||||
|
||||
if (tentativeCommitChanged) {
|
||||
m_textDirty = true;
|
||||
m_tentativeCommit = event->tentativeCommitString();
|
||||
}
|
||||
|
||||
if (isGettingInput || tentativeCommitChanged)
|
||||
finishChange(priorState);
|
||||
|
||||
if (selectionChange)
|
||||
@ -598,7 +630,6 @@ bool QLineControl::finishChange(int validateFromState, bool update, bool edited)
|
||||
m_validInput = true;
|
||||
#ifndef QT_NO_VALIDATOR
|
||||
if (m_validator) {
|
||||
m_validInput = false;
|
||||
QString textCopy = m_text;
|
||||
int cursorCopy = m_cursor;
|
||||
m_validInput = (m_validator->validate(textCopy, cursorCopy) != QValidator::Invalid);
|
||||
@ -608,6 +639,15 @@ bool QLineControl::finishChange(int validateFromState, bool update, bool edited)
|
||||
return true;
|
||||
}
|
||||
m_cursor = cursorCopy;
|
||||
|
||||
if (!m_tentativeCommit.isEmpty()) {
|
||||
textCopy.insert(m_cursor, m_tentativeCommit);
|
||||
bool validInput = (m_validator->validate(textCopy, cursorCopy) != QValidator::Invalid);
|
||||
if (!validInput)
|
||||
m_tentativeCommit.clear();
|
||||
}
|
||||
} else {
|
||||
m_tentativeCommit.clear();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -61,6 +61,7 @@
|
||||
#include "QtGui/qvalidator.h"
|
||||
#include "QtGui/qpalette.h"
|
||||
#include "QtGui/qguiapplication.h"
|
||||
#include "QtGui/qinputpanel.h"
|
||||
#include "QtCore/qpoint.h"
|
||||
|
||||
QT_BEGIN_HEADER
|
||||
@ -205,12 +206,10 @@ public:
|
||||
bool isReadOnly() const { return m_readOnly; }
|
||||
void setReadOnly(bool enable) { m_readOnly = enable; }
|
||||
|
||||
QString text() const
|
||||
{
|
||||
QString res = m_maskData ? stripString(m_text) : m_text;
|
||||
return (res.isNull() ? QString::fromLatin1("") : res);
|
||||
}
|
||||
void setText(const QString &txt) { internalSetText(txt, -1, false); }
|
||||
QString text() const;
|
||||
QString realText() const;
|
||||
void setText(const QString &txt);
|
||||
|
||||
QString displayText() const { return m_textLayout.text(); }
|
||||
|
||||
void backspace();
|
||||
@ -347,6 +346,7 @@ private:
|
||||
int m_cursor;
|
||||
int m_preeditCursor;
|
||||
int m_cursorWidth;
|
||||
QString m_tentativeCommit;
|
||||
Qt::LayoutDirection m_layoutDirection;
|
||||
uint m_hideCursor : 1; // used to hide the m_cursor inside preedit areas
|
||||
uint m_separator : 1;
|
||||
|
Loading…
Reference in New Issue
Block a user