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>bb10
parent
49bb37e05d
commit
b002e21d15
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue