From c01d748e2afcf6cf31957d78c08f95bf9ec7da6e Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Fri, 17 Jul 2009 13:58:02 +1000 Subject: Basic inputMethodQuery support for KeyProxy. --- src/declarative/fx/qfxitem.cpp | 5 +++++ src/declarative/fx/qfxitem.h | 2 ++ src/declarative/fx/qfxkeyproxy.cpp | 46 +++++++++++++++++++++++++++----------- src/declarative/fx/qfxkeyproxy.h | 1 + 4 files changed, 41 insertions(+), 13 deletions(-) diff --git a/src/declarative/fx/qfxitem.cpp b/src/declarative/fx/qfxitem.cpp index 3386faf..481733b 100644 --- a/src/declarative/fx/qfxitem.cpp +++ b/src/declarative/fx/qfxitem.cpp @@ -2556,4 +2556,9 @@ QPixmap QFxItem::string(const QString &str, const QColor &c, const QFont &f) return img; } +QVariant QFxItem::inputMethodQuery(Qt::InputMethodQuery query) const +{ + return QGraphicsItem::inputMethodQuery(query); +} + QT_END_NAMESPACE diff --git a/src/declarative/fx/qfxitem.h b/src/declarative/fx/qfxitem.h index c125514..67b60c1 100644 --- a/src/declarative/fx/qfxitem.h +++ b/src/declarative/fx/qfxitem.h @@ -273,6 +273,8 @@ public: static QPixmap string(const QString &, const QColor & = Qt::black, const QFont & = QFont()); + QVariant inputMethodQuery(Qt::InputMethodQuery query) const; //### for KeyProxy + public Q_SLOTS: void newChild(const QString &url); diff --git a/src/declarative/fx/qfxkeyproxy.cpp b/src/declarative/fx/qfxkeyproxy.cpp index f234a0f..e4b4269 100644 --- a/src/declarative/fx/qfxkeyproxy.cpp +++ b/src/declarative/fx/qfxkeyproxy.cpp @@ -82,13 +82,15 @@ QML_DEFINE_TYPE(QFxKeyProxy,KeyProxy) class QFxKeyProxyPrivate { public: - QFxKeyProxyPrivate() : inPress(false), inRelease(false), inIM(false) {} + QFxKeyProxyPrivate() : inPress(false), inRelease(false), inIM(false), imeItem(0) {} QList targets; //loop detection bool inPress:1; bool inRelease:1; bool inIM:1; + + QFxItem *imeItem; }; QFxKeyProxy::QFxKeyProxy(QFxItem *parent) @@ -124,11 +126,12 @@ void QFxKeyProxy::keyPressEvent(QKeyEvent *e) d->inPress = true; for (int ii = 0; ii < d->targets.count(); ++ii) { QFxItem *i = qobject_cast(scene()->focusItem(d->targets.at(ii))); - if (i) + if (i) { scene()->sendEvent(i, e); - if (e->isAccepted()) { - d->inPress = false; - return; + if (e->isAccepted()) { + d->inPress = false; + return; + } } } d->inPress = false; @@ -143,11 +146,12 @@ void QFxKeyProxy::keyReleaseEvent(QKeyEvent *e) d->inRelease = true; for (int ii = 0; ii < d->targets.count(); ++ii) { QFxItem *i = qobject_cast(scene()->focusItem(d->targets.at(ii))); - if (i) + if (i) { scene()->sendEvent(i, e); - if (e->isAccepted()) { - d->inRelease = false; - return; + if (e->isAccepted()) { + d->inRelease = false; + return; + } } } d->inRelease = false; @@ -162,15 +166,31 @@ void QFxKeyProxy::inputMethodEvent(QInputMethodEvent *e) d->inIM = true; for (int ii = 0; ii < d->targets.count(); ++ii) { QFxItem *i = qobject_cast(scene()->focusItem(d->targets.at(ii))); - if (i) + if (i && (i->options() & AcceptsInputMethods)) { scene()->sendEvent(i, e); - if (e->isAccepted()) { - d->inIM = false; - return; + if (e->isAccepted()) { + d->imeItem = i; + d->inIM = false; + return; + } } } d->inIM = false; } } +QVariant QFxKeyProxy::inputMethodQuery(Qt::InputMethodQuery query) const +{ + for (int ii = 0; ii < d->targets.count(); ++ii) { + QFxItem *i = qobject_cast(scene()->focusItem(d->targets.at(ii))); + if (i && (i->options() & AcceptsInputMethods) && i == d->imeItem) { //### how robust is i == d->imeItem check? + QVariant v = i->inputMethodQuery(query); + if (v.type() == QVariant::RectF) + v = mapRectFromItem(i, v.toRectF()); //### cost? + return v; + } + } + return QFxItem::inputMethodQuery(query); +} + QT_END_NAMESPACE diff --git a/src/declarative/fx/qfxkeyproxy.h b/src/declarative/fx/qfxkeyproxy.h index 8bcdc26..e77ffac 100644 --- a/src/declarative/fx/qfxkeyproxy.h +++ b/src/declarative/fx/qfxkeyproxy.h @@ -65,6 +65,7 @@ protected: virtual void keyPressEvent(QKeyEvent *); virtual void keyReleaseEvent(QKeyEvent *); virtual void inputMethodEvent(QInputMethodEvent *); + virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const; private: Q_DISABLE_COPY(QFxKeyProxy) -- cgit v0.12