QLineEdit: add support for ImCursorPosition with position argument

Follow up f8dbed12, and implement support for IM queries that
can take an extra QVariant argument. We use this to implement
support for ImCursorPosition with a QPointF argument that
specifies that we should return the text position under
the given point rather than the current cursor pos (0bb645b).

Change-Id: I03ae7af698241f454d35dec84f248ecd5bb6ad51
Reviewed-by: Jan Arve Sæther <jan-arve.saether@theqtcompany.com>
This commit is contained in:
Richard Moe Gustavsen 2016-04-11 14:06:02 +02:00
parent 07a19c12a3
commit ab67a5b7b6
2 changed files with 12 additions and 3 deletions

View File

@ -1745,9 +1745,14 @@ void QLineEdit::inputMethodEvent(QInputMethodEvent *e)
#endif #endif
} }
QVariant QLineEdit::inputMethodQuery(Qt::InputMethodQuery property) const
{
return inputMethodQuery(property, QVariant());
}
/*!\reimp /*!\reimp
*/ */
QVariant QLineEdit::inputMethodQuery(Qt::InputMethodQuery property) const QVariant QLineEdit::inputMethodQuery(Qt::InputMethodQuery property, QVariant argument) const
{ {
Q_D(const QLineEdit); Q_D(const QLineEdit);
switch(property) { switch(property) {
@ -1755,8 +1760,11 @@ QVariant QLineEdit::inputMethodQuery(Qt::InputMethodQuery property) const
return d->cursorRect(); return d->cursorRect();
case Qt::ImFont: case Qt::ImFont:
return font(); return font();
case Qt::ImCursorPosition: case Qt::ImCursorPosition: {
return QVariant(d->control->cursor()); const QPointF pt = argument.toPointF();
if (!pt.isNull())
return QVariant(d->xToPos(pt.x(), QTextLine::CursorBetweenCharacters));
return QVariant(d->control->cursor()); }
case Qt::ImSurroundingText: case Qt::ImSurroundingText:
return QVariant(d->control->text()); return QVariant(d->control->text());
case Qt::ImCurrentSelection: case Qt::ImCurrentSelection:

View File

@ -228,6 +228,7 @@ protected:
void initStyleOption(QStyleOptionFrame *option) const; void initStyleOption(QStyleOptionFrame *option) const;
public: public:
QVariant inputMethodQuery(Qt::InputMethodQuery) const Q_DECL_OVERRIDE; QVariant inputMethodQuery(Qt::InputMethodQuery) const Q_DECL_OVERRIDE;
Q_INVOKABLE QVariant inputMethodQuery(Qt::InputMethodQuery property, QVariant argument) const;
bool event(QEvent *) Q_DECL_OVERRIDE; bool event(QEvent *) Q_DECL_OVERRIDE;
protected: protected:
QRect cursorRect() const; QRect cursorRect() const;