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>
This commit is contained in:
parent
9b699fa839
commit
0bb645b1cc
@ -1338,6 +1338,7 @@ public:
|
|||||||
ImTextBeforeCursor = 0x800,
|
ImTextBeforeCursor = 0x800,
|
||||||
ImTextAfterCursor = 0x1000,
|
ImTextAfterCursor = 0x1000,
|
||||||
ImEnterKeyType = 0x2000,
|
ImEnterKeyType = 0x2000,
|
||||||
|
ImAnchorRectangle = 0x4000,
|
||||||
|
|
||||||
ImPlatformData = 0x80000000,
|
ImPlatformData = 0x80000000,
|
||||||
ImQueryInput = ImCursorRectangle | ImCursorPosition | ImSurroundingText |
|
ImQueryInput = ImCursorRectangle | ImCursorPosition | ImSurroundingText |
|
||||||
|
@ -97,6 +97,7 @@ void QInputMethod::setInputItemTransform(const QTransform &transform)
|
|||||||
|
|
||||||
d->inputItemTransform = transform;
|
d->inputItemTransform = transform;
|
||||||
emit cursorRectangleChanged();
|
emit cursorRectangleChanged();
|
||||||
|
emit anchorRectangleChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -126,6 +127,19 @@ void QInputMethod::setInputItemRectangle(const QRectF &rect)
|
|||||||
d->inputRectangle = rect;
|
d->inputRectangle = rect;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static QRectF inputMethodQueryRectangle_helper(Qt::InputMethodQuery imquery, const QTransform &xform)
|
||||||
|
{
|
||||||
|
QRectF r;
|
||||||
|
if (QObject *focusObject = qGuiApp->focusObject()) {
|
||||||
|
QInputMethodQueryEvent query(imquery);
|
||||||
|
QGuiApplication::sendEvent(focusObject, &query);
|
||||||
|
r = query.value(imquery).toRectF();
|
||||||
|
if (r.isValid())
|
||||||
|
r = xform.mapRect(r);
|
||||||
|
}
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\property QInputMethod::cursorRectangle
|
\property QInputMethod::cursorRectangle
|
||||||
\brief Input item's cursor rectangle in window coordinates.
|
\brief Input item's cursor rectangle in window coordinates.
|
||||||
@ -136,18 +150,20 @@ void QInputMethod::setInputItemRectangle(const QRectF &rect)
|
|||||||
QRectF QInputMethod::cursorRectangle() const
|
QRectF QInputMethod::cursorRectangle() const
|
||||||
{
|
{
|
||||||
Q_D(const QInputMethod);
|
Q_D(const QInputMethod);
|
||||||
|
return inputMethodQueryRectangle_helper(Qt::ImCursorRectangle, d->inputItemTransform);
|
||||||
|
}
|
||||||
|
|
||||||
QObject *focusObject = qGuiApp->focusObject();
|
/*!
|
||||||
if (!focusObject)
|
\property QInputMethod::anchorRectangle
|
||||||
return QRectF();
|
\brief Input item's anchor rectangle in window coordinates.
|
||||||
|
|
||||||
QInputMethodQueryEvent query(Qt::ImCursorRectangle);
|
Anchor rectangle is often used by various text editing controls
|
||||||
QGuiApplication::sendEvent(focusObject, &query);
|
like text prediction popups for following the text selection.
|
||||||
QRectF r = query.value(Qt::ImCursorRectangle).toRectF();
|
*/
|
||||||
if (!r.isValid())
|
QRectF QInputMethod::anchorRectangle() const
|
||||||
return QRectF();
|
{
|
||||||
|
Q_D(const QInputMethod);
|
||||||
return d->inputItemTransform.mapRect(r);
|
return inputMethodQueryRectangle_helper(Qt::ImAnchorRectangle, d->inputItemTransform);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@ -300,6 +316,10 @@ void QInputMethod::update(Qt::InputMethodQueries queries)
|
|||||||
|
|
||||||
if (queries & Qt::ImCursorRectangle)
|
if (queries & Qt::ImCursorRectangle)
|
||||||
emit cursorRectangleChanged();
|
emit cursorRectangleChanged();
|
||||||
|
|
||||||
|
if (queries & (Qt::ImAnchorRectangle))
|
||||||
|
emit anchorRectangleChanged();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -55,6 +55,7 @@ class Q_GUI_EXPORT QInputMethod : public QObject
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_DECLARE_PRIVATE(QInputMethod)
|
Q_DECLARE_PRIVATE(QInputMethod)
|
||||||
Q_PROPERTY(QRectF cursorRectangle READ cursorRectangle NOTIFY cursorRectangleChanged)
|
Q_PROPERTY(QRectF cursorRectangle READ cursorRectangle NOTIFY cursorRectangleChanged)
|
||||||
|
Q_PROPERTY(QRectF anchorRectangle READ anchorRectangle NOTIFY anchorRectangleChanged)
|
||||||
Q_PROPERTY(QRectF keyboardRectangle READ keyboardRectangle NOTIFY keyboardRectangleChanged)
|
Q_PROPERTY(QRectF keyboardRectangle READ keyboardRectangle NOTIFY keyboardRectangleChanged)
|
||||||
Q_PROPERTY(bool visible READ isVisible NOTIFY visibleChanged)
|
Q_PROPERTY(bool visible READ isVisible NOTIFY visibleChanged)
|
||||||
Q_PROPERTY(bool animating READ isAnimating NOTIFY animatingChanged)
|
Q_PROPERTY(bool animating READ isAnimating NOTIFY animatingChanged)
|
||||||
@ -70,6 +71,7 @@ public:
|
|||||||
|
|
||||||
// in window coordinates
|
// in window coordinates
|
||||||
QRectF cursorRectangle() const; // ### what if we have rotations for the item?
|
QRectF cursorRectangle() const; // ### what if we have rotations for the item?
|
||||||
|
QRectF anchorRectangle() const; // ### ditto
|
||||||
|
|
||||||
// keyboard geometry in window coords
|
// keyboard geometry in window coords
|
||||||
QRectF keyboardRectangle() const;
|
QRectF keyboardRectangle() const;
|
||||||
@ -102,6 +104,7 @@ public Q_SLOTS:
|
|||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void cursorRectangleChanged();
|
void cursorRectangleChanged();
|
||||||
|
void anchorRectangleChanged();
|
||||||
void keyboardRectangleChanged();
|
void keyboardRectangleChanged();
|
||||||
void visibleChanged();
|
void visibleChanged();
|
||||||
void animatingChanged();
|
void animatingChanged();
|
||||||
|
@ -43,6 +43,8 @@
|
|||||||
#include "private/qkeymapper_p.h"
|
#include "private/qkeymapper_p.h"
|
||||||
#include <qpa/qplatforminputcontext_p.h>
|
#include <qpa/qplatforminputcontext_p.h>
|
||||||
|
|
||||||
|
#include <QtGui/qtransform.h>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@ -267,5 +269,30 @@ void QPlatformInputContextPrivate::setInputMethodAccepted(bool accepted)
|
|||||||
QPlatformInputContextPrivate::s_inputMethodAccepted = 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
|
QT_END_NAMESPACE
|
||||||
|
@ -95,6 +95,8 @@ public:
|
|||||||
virtual void setFocusObject(QObject *object);
|
virtual void setFocusObject(QObject *object);
|
||||||
bool inputMethodAccepted() const;
|
bool inputMethodAccepted() const;
|
||||||
|
|
||||||
|
static void setSelectionOnFocusObject(const QPointF &anchorPos, const QPointF &cursorPos);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class QGuiApplication;
|
friend class QGuiApplication;
|
||||||
friend class QGuiApplicationPrivate;
|
friend class QGuiApplicationPrivate;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user