summaryrefslogtreecommitdiffstats
path: root/src/gui/kernel/qplatforminputcontext.cpp
diff options
context:
space:
mode:
authorJan Arve Sæther <jan-arve.saether@theqtcompany.com>2015-11-26 10:37:24 +0100
committerJan Arve Sæther <jan-arve.saether@theqtcompany.com>2016-04-06 12:26:34 +0000
commit0bb645b1ccc5a9d57b21cf0b2c4306b8e48c611c (patch)
treebf868b455287bffb5b0cab804765802bd3214f1f /src/gui/kernel/qplatforminputcontext.cpp
parent9b699fa839f560a9ea9da69c8975b9aa4654ab8b (diff)
Add support for ImhAnchorRectangle
Adds the following API: * QInputMethod::anchorRectangle() * QPlatformInputContext::setSelectionOnFocusObject() This will be used for determining how to display selection handles. Change-Id: If57e3fd58ff0f1ba7899f7dd62bfa9c006028667 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@theqtcompany.com>
Diffstat (limited to 'src/gui/kernel/qplatforminputcontext.cpp')
-rw-r--r--src/gui/kernel/qplatforminputcontext.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/gui/kernel/qplatforminputcontext.cpp b/src/gui/kernel/qplatforminputcontext.cpp
index bad6422cb8..3f59116e9a 100644
--- a/src/gui/kernel/qplatforminputcontext.cpp
+++ b/src/gui/kernel/qplatforminputcontext.cpp
@@ -43,6 +43,8 @@
#include "private/qkeymapper_p.h"
#include <qpa/qplatforminputcontext_p.h>
+#include <QtGui/qtransform.h>
+
QT_BEGIN_NAMESPACE
/*!
@@ -267,5 +269,30 @@ void QPlatformInputContextPrivate::setInputMethodAccepted(bool accepted)
QPlatformInputContextPrivate::s_inputMethodAccepted = accepted;
}
+/*!
+ * \brief QPlatformInputContext::setSelectionOnFocusObject
+ * \param anchorPos Beginning of selection in currently active window coordinates
+ * \param cursorPos End of selection in currently active window coordinates
+ */
+void QPlatformInputContext::setSelectionOnFocusObject(const QPointF &anchorPos, const QPointF &cursorPos)
+{
+ QObject *focus = qApp->focusObject();
+ if (!focus)
+ return;
+
+ QInputMethod *im = QGuiApplication::inputMethod();
+ const QTransform mapToLocal = im->inputItemTransform().inverted();
+ bool success;
+ int anchor = QInputMethod::queryFocusObject(Qt::ImCursorPosition, anchorPos * mapToLocal).toInt(&success);
+ if (success) {
+ int cursor = QInputMethod::queryFocusObject(Qt::ImCursorPosition, cursorPos * mapToLocal).toInt(&success);
+ if (success) {
+ QList<QInputMethodEvent::Attribute> imAttributes;
+ imAttributes.append(QInputMethodEvent::Attribute(QInputMethodEvent::Selection, anchor, cursor - anchor, QVariant()));
+ QInputMethodEvent event(QString(), imAttributes);
+ QGuiApplication::sendEvent(focus, &event);
+ }
+ }
+}
QT_END_NAMESPACE