diff options
author | Lars Knoll <lars.knoll@nokia.com> | 2011-09-08 14:37:22 +0200 |
---|---|---|
committer | Lars Knoll <lars.knoll@nokia.com> | 2011-09-08 14:47:39 +0200 |
commit | b002e21d15ec8ecf6455c75055c6ca3112d5f756 (patch) | |
tree | ac7ed8a89a50b4d881bad0f29da9ab5c22cae37c /src | |
parent | 49bb37e05d9b7047a80c93667d43657395bdec73 (diff) |
Change the QInputMethodQueryEvent to be able to query a set of properties
The event now takes a Qt::InputMethodQueries bitfield. Like this the
editor can set all properties in one go on the event instead of
having to process many query events.
Change-Id: Ifd9d7328a9fce0c21625371ec744ea2090e163be
Reviewed-on: http://codereview.qt-project.org/4448
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/kernel/qevent.cpp | 25 | ||||
-rw-r--r-- | src/gui/kernel/qevent.h | 17 | ||||
-rw-r--r-- | src/gui/kernel/qinputpanel.cpp | 2 | ||||
-rw-r--r-- | src/widgets/kernel/qwidget.cpp | 11 |
4 files changed, 43 insertions, 12 deletions
diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp index 8208f6e04a..ea19a0548d 100644 --- a/src/gui/kernel/qevent.cpp +++ b/src/gui/kernel/qevent.cpp @@ -1787,9 +1787,9 @@ void QInputMethodEvent::setCommitString(const QString &commitString, int replace The object should call setValue() on the event to fill in the requested data before calling accept(). */ -QInputMethodQueryEvent::QInputMethodQueryEvent(Qt::InputMethodQuery query) +QInputMethodQueryEvent::QInputMethodQueryEvent(Qt::InputMethodQueries queries) : QEvent(InputMethodQuery), - m_query(query) + m_queries(queries) { } @@ -1797,6 +1797,27 @@ QInputMethodQueryEvent::~QInputMethodQueryEvent() { } + +void QInputMethodQueryEvent::setValue(Qt::InputMethodQuery q, const QVariant &v) +{ + for (int i = 0; i < m_values.size(); ++i) { + if (m_values.at(i).query == q) { + m_values[i].value = v; + return; + } + } + QueryPair pair = { q, v }; + m_values.append(pair); +} + +QVariant QInputMethodQueryEvent::value(Qt::InputMethodQuery q) const +{ + for (int i = 0; i < m_values.size(); ++i) + if (m_values.at(i).query == q) + return m_values.at(i).value; + return QVariant(); +} + /*! \fn Qt::InputMethodQuery QInputMethodQueryEvent::query() const diff --git a/src/gui/kernel/qevent.h b/src/gui/kernel/qevent.h index 6f180f6365..faa80d5c7d 100644 --- a/src/gui/kernel/qevent.h +++ b/src/gui/kernel/qevent.h @@ -52,6 +52,7 @@ #include <QtGui/qmime.h> #include <QtCore/qvariant.h> #include <QtCore/qmap.h> +#include <QtCore/qvector.h> #include <QtCore/qset.h> #include <QtCore/qfile.h> @@ -451,16 +452,20 @@ private: class Q_GUI_EXPORT QInputMethodQueryEvent : public QEvent { public: - QInputMethodQueryEvent(Qt::InputMethodQuery query); + QInputMethodQueryEvent(Qt::InputMethodQueries queries); ~QInputMethodQueryEvent(); - Qt::InputMethodQuery query() const { return m_query; } + Qt::InputMethodQueries queries() const { return m_queries; } - void setValue(const QVariant &v) { m_value = v; } - QVariant value() const { return m_value; } + void setValue(Qt::InputMethodQuery q, const QVariant &v); + QVariant value(Qt::InputMethodQuery q) const; private: - Qt::InputMethodQuery m_query; - QVariant m_value; + Qt::InputMethodQueries m_queries; + struct QueryPair { + Qt::InputMethodQuery query; + QVariant value; + }; + QVector<QueryPair> m_values; }; #endif // QT_NO_INPUTMETHOD diff --git a/src/gui/kernel/qinputpanel.cpp b/src/gui/kernel/qinputpanel.cpp index eda93e005c..233ac93cb8 100644 --- a/src/gui/kernel/qinputpanel.cpp +++ b/src/gui/kernel/qinputpanel.cpp @@ -101,7 +101,7 @@ QRectF QInputPanel::cursorRectangle() const QInputMethodQueryEvent query(Qt::ImCursorRectangle); QGuiApplication::sendEvent(d->inputItem.data(), &query); - QRect r = query.value().toRect(); + QRect r = query.value(Qt::ImCursorRectangle).toRect(); if (!r.isValid()) return QRect(); diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index 125e33f0da..76544d2524 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -8358,9 +8358,14 @@ bool QWidget::event(QEvent *event) case QEvent::InputMethodQuery: if (testAttribute(Qt::WA_InputMethodEnabled)) { QInputMethodQueryEvent *query = static_cast<QInputMethodQueryEvent *>(event); - QVariant v = inputMethodQuery(query->query()); - - query->setValue(v); + Qt::InputMethodQueries queries = query->queries(); + for (uint i = 0; i < 32; ++i) { + Qt::InputMethodQuery q = (Qt::InputMethodQuery)(int)(queries & (1<<i)); + if (q) { + QVariant v = inputMethodQuery(q); + query->setValue(q, v); + } + } query->accept(); break; } |