From 407a6fe79824b722dbc1224a1be29d26b8fdb729 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Tue, 21 Jun 2011 16:45:00 +0200 Subject: [PATCH] add QInputMethodQueryEvent QInputMethodQueryEvent will replace the old inputMethodHints() and inputMethodQuery() APIs in QWidget. It has the advantage that it works nicely with any kind of QObject. --- src/corelib/global/qnamespace.h | 3 ++- src/corelib/kernel/qcoreevent.h | 2 ++ src/gui/kernel/qevent.cpp | 47 +++++++++++++++++++++++++++++++++++++++++ src/gui/kernel/qevent.h | 16 ++++++++++++++ src/widgets/kernel/qwidget.cpp | 17 +++++++++++++++ 5 files changed, 84 insertions(+), 1 deletion(-) diff --git a/src/corelib/global/qnamespace.h b/src/corelib/global/qnamespace.h index 4a663fc..38d4a85 100644 --- a/src/corelib/global/qnamespace.h +++ b/src/corelib/global/qnamespace.h @@ -1488,7 +1488,8 @@ public: ImSurroundingText, ImCurrentSelection, ImMaximumTextLength, - ImAnchorPosition + ImAnchorPosition, + ImHints }; enum InputMethodHint { diff --git a/src/corelib/kernel/qcoreevent.h b/src/corelib/kernel/qcoreevent.h index 432f6a8..791b207 100644 --- a/src/corelib/kernel/qcoreevent.h +++ b/src/corelib/kernel/qcoreevent.h @@ -296,6 +296,8 @@ public: Expose = 208, + InputMethodQuery = 209, + // 512 reserved for Qt Jambi's MetaCall event // 513 reserved for Qt Jambi's DeleteOnMainThread event diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp index 988d70c..9e6a8d6 100644 --- a/src/gui/kernel/qevent.cpp +++ b/src/gui/kernel/qevent.cpp @@ -1755,6 +1755,53 @@ void QInputMethodEvent::setCommitString(const QString &commitString, int replace \sa replacementStart(), setCommitString() */ + +/*! \class QInputMethodQueryEvent + + This event is sent by the input context to input objects. + + It is used by the + input method to query a set of properties of the object to be + able to support complex input method operations as support for + surrounding text and reconversions. + + query() specifies which property is queried. + + The object should call setValue() on the event to fill in the requested + data before calling accept(). +*/ +QInputMethodQueryEvent::QInputMethodQueryEvent(Qt::InputMethodQuery query) + : QEvent(InputMethodQuery), + m_query(query) +{ +} + +QInputMethodQueryEvent::~QInputMethodQueryEvent() +{ +} + +/*! + \fn Qt::InputMethodQuery QInputMethodQueryEvent::query() const + + returns the type of data queried. +*/ + +/*! + \fn QVariant QInputMethodQueryEvent::value() const + + returns the value set by the receiving object. Mainly used by the input method. + + \sa setValue() +*/ + +/*! + \fn QVariant QInputMethodQueryEvent::setValue() + + Used by the receiving object to set the value requested by query(). + + \sa setValue() +*/ + #ifndef QT_NO_TABLETEVENT /*! diff --git a/src/gui/kernel/qevent.h b/src/gui/kernel/qevent.h index 809a3d6..59d50df 100644 --- a/src/gui/kernel/qevent.h +++ b/src/gui/kernel/qevent.h @@ -427,6 +427,22 @@ private: int replace_from; int replace_length; }; + +class Q_GUI_EXPORT QInputMethodQueryEvent : public QEvent +{ +public: + QInputMethodQueryEvent(Qt::InputMethodQuery query); + ~QInputMethodQueryEvent(); + + Qt::InputMethodQuery query() const { return m_query; } + + void setValue(const QVariant &v) { m_value = v; } + QVariant value() const { return m_value; } +private: + Qt::InputMethodQuery m_query; + QVariant m_value; +}; + #endif // QT_NO_INPUTMETHOD #ifndef QT_NO_DRAGANDDROP diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index 0646983..a8bd5ca 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -8297,6 +8297,21 @@ bool QWidget::event(QEvent *event) inputMethodEvent((QInputMethodEvent *) event); break; + case QEvent::InputMethodQuery: + if (testAttribute(Qt::WA_InputMethodEnabled)) { + QInputMethodQueryEvent *query = static_cast(event); + QVariant v = inputMethodQuery(query->query()); + + if (query->query() == Qt::ImMicroFocus) { + QRect r = v.toRect(); + v = QRect(mapToGlobal(r.topLeft()), r.size()); + } + + query->setValue(v); + query->accept(); + break; + } + case QEvent::PolishRequest: ensurePolished(); break; @@ -9215,6 +9230,8 @@ QVariant QWidget::inputMethodQuery(Qt::InputMethodQuery query) const case Qt::ImAnchorPosition: // Fallback. return inputMethodQuery(Qt::ImCursorPosition); + case Qt::ImHints: + return (int)inputMethodHints(); default: return QVariant(); } -- 2.7.4