Implement partial tentativeCommit support in QTextEdit
Available on plain text for now, html support still pending. Change-Id: I0818b97874e80c8c1b33a9127aa7bb3330a8761d Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
This commit is contained in:
parent
77082cd7c9
commit
1dbfbf4c66
@ -1099,13 +1099,17 @@ void QTextEdit::setPlainText(const QString &text)
|
||||
}
|
||||
|
||||
/*!
|
||||
\fn QString QTextEdit::toPlainText() const
|
||||
QString QTextEdit::toPlainText() const
|
||||
|
||||
Returns the text of the text edit as plain text.
|
||||
|
||||
\sa QTextEdit::setPlainText()
|
||||
*/
|
||||
|
||||
QString QTextEdit::toPlainText() const
|
||||
{
|
||||
Q_D(const QTextEdit);
|
||||
return d->control->toPlainText();
|
||||
}
|
||||
|
||||
/*!
|
||||
\property QTextEdit::html
|
||||
@ -1135,8 +1139,15 @@ void QTextEdit::setHtml(const QString &text)
|
||||
d->control->setHtml(text);
|
||||
d->preferRichText = true;
|
||||
}
|
||||
|
||||
QString QTextEdit::toHtml() const
|
||||
{
|
||||
Q_D(const QTextEdit);
|
||||
return d->control->toHtml();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/*! \reimp
|
||||
*/
|
||||
void QTextEdit::keyPressEvent(QKeyEvent *e)
|
||||
|
@ -162,11 +162,9 @@ public:
|
||||
|
||||
bool find(const QString &exp, QTextDocument::FindFlags options = 0);
|
||||
|
||||
inline QString toPlainText() const
|
||||
{ return document()->toPlainText(); }
|
||||
QString toPlainText() const;
|
||||
#ifndef QT_NO_TEXTHTMLPARSER
|
||||
inline QString toHtml() const
|
||||
{ return document()->toHtml(); }
|
||||
QString toHtml() const;
|
||||
#endif
|
||||
|
||||
void ensureCursorVisible();
|
||||
|
@ -1991,7 +1991,10 @@ void QWidgetTextControlPrivate::inputMethodEvent(QInputMethodEvent *e)
|
||||
}
|
||||
}
|
||||
layout->setAdditionalFormats(overrides);
|
||||
tentativeCommit = e->tentativeCommitString();
|
||||
|
||||
cursor.endEditBlock();
|
||||
|
||||
if (cursor.d)
|
||||
cursor.d->setX();
|
||||
if (oldPreeditCursor != preeditCursor)
|
||||
@ -2909,7 +2912,22 @@ bool QWidgetTextControl::find(const QString &exp, QTextDocument::FindFlags optio
|
||||
return true;
|
||||
}
|
||||
|
||||
QString QWidgetTextControl::toPlainText() const
|
||||
{
|
||||
Q_D(const QWidgetTextControl);
|
||||
QString plainText = document()->toPlainText();
|
||||
if (!d->tentativeCommit.isEmpty())
|
||||
plainText.insert(textCursor().position(), d->tentativeCommit);
|
||||
return plainText;
|
||||
}
|
||||
|
||||
#ifndef QT_NO_TEXTHTMLPARSER
|
||||
QString QWidgetTextControl::toHtml() const
|
||||
{
|
||||
// note: currently not including tentative commit
|
||||
return document()->toHtml();
|
||||
}
|
||||
#endif
|
||||
|
||||
void QWidgetTextControlPrivate::append(const QString &text, Qt::TextFormat format)
|
||||
{
|
||||
|
@ -114,11 +114,9 @@ public:
|
||||
|
||||
bool find(const QString &exp, QTextDocument::FindFlags options = 0);
|
||||
|
||||
inline QString toPlainText() const
|
||||
{ return document()->toPlainText(); }
|
||||
QString toPlainText() const;
|
||||
#ifndef QT_NO_TEXTHTMLPARSER
|
||||
inline QString toHtml() const
|
||||
{ return document()->toHtml(); }
|
||||
QString toHtml() const;
|
||||
#endif
|
||||
|
||||
virtual void ensureCursorVisible();
|
||||
|
@ -208,6 +208,7 @@ public:
|
||||
|
||||
int preeditCursor;
|
||||
bool hideCursor; // used to hide the cursor in the preedit area
|
||||
QString tentativeCommit;
|
||||
|
||||
QVector<QAbstractTextDocumentLayout::Selection> extraSelections;
|
||||
|
||||
|
@ -202,6 +202,7 @@ private slots:
|
||||
void bidiLogicalMovement_data();
|
||||
void bidiLogicalMovement();
|
||||
|
||||
void inputMethodEvent();
|
||||
void inputMethodSelection();
|
||||
void inputMethodQuery();
|
||||
|
||||
@ -2363,6 +2364,25 @@ void tst_QTextEdit::bidiLogicalMovement()
|
||||
} while (moved && i >= 0);
|
||||
}
|
||||
|
||||
void tst_QTextEdit::inputMethodEvent()
|
||||
{
|
||||
// test that text change with an input method event triggers change signal
|
||||
QSignalSpy spy(ed, SIGNAL(textChanged()));
|
||||
|
||||
QInputMethodEvent event;
|
||||
event.setCommitString("text");
|
||||
QApplication::sendEvent(ed, &event);
|
||||
QCOMPARE(spy.count(), 1);
|
||||
spy.clear();
|
||||
|
||||
QList<QInputMethodEvent::Attribute> attributes;
|
||||
QInputMethodEvent event2("preedit", attributes);
|
||||
event2.setTentativeCommitString("string");
|
||||
QApplication::sendEvent(ed, &event2);
|
||||
QCOMPARE(spy.count(), 1);
|
||||
QCOMPARE(ed->toPlainText(), QString("textstring"));
|
||||
}
|
||||
|
||||
void tst_QTextEdit::inputMethodSelection()
|
||||
{
|
||||
ed->setText("Lorem ipsum dolor sit amet, consectetur adipiscing elit.");
|
||||
|
Loading…
Reference in New Issue
Block a user