Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qplatforminputcontext.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
5#include <qguiapplication.h>
6#include <QRect>
7#include "private/qkeymapper_p.h"
8#include "private/qhighdpiscaling_p.h"
9#include <qpa/qplatforminputcontext_p.h>
10
11#include <QtGui/qtransform.h>
12
14
49{
50 // Delay initialization of cached input direction
51 // until super class has finished constructing.
52 QMetaObject::invokeMethod(this, [this]{
53 m_inputDirection = inputDirection();
55}
56
63
68{
69 return false;
70}
71
78{
79 Q_UNUSED(capability);
80 return true;
81}
82
90
94
98void QPlatformInputContext::update(Qt::InputMethodQueries)
99{
100}
101
108{
109 Q_UNUSED(cursorPosition);
110 // Default behavior for simple ephemeral input contexts. Some
111 // complex input contexts should not be reset here.
112 if (action == QInputMethod::Click)
113 reset();
114}
115
123{
125 return false;
126}
127
133{
134 return QRectF();
135}
136
143{
144 emit QGuiApplication::inputMethod()->keyboardRectangleChanged();
145}
146
152{
153 return false;
154}
155
165
172
179
184{
185 return false;
186}
187
197
202
204{
205 emit QGuiApplication::inputMethod()->localeChanged();
206
207 // Changing the locale might have updated the input direction
209}
210
212{
213 return locale().textDirection();
214}
215
217{
218 if (newDirection == m_inputDirection)
219 return;
220
221 emit QGuiApplication::inputMethod()->inputDirectionChanged(newDirection);
222 m_inputDirection = newDirection;
223}
224
230{
231 Q_UNUSED(object);
232}
233
241
243
248
254void QPlatformInputContext::setSelectionOnFocusObject(const QPointF &nativeAnchorPos, const QPointF &nativeCursorPos)
255{
256 QObject *focus = qApp->focusObject();
257 if (!focus)
258 return;
259
260 QWindow *window = qApp->focusWindow();
261 const QPointF &anchorPos = QHighDpi::fromNativePixels(nativeAnchorPos, window);
262 const QPointF &cursorPos = QHighDpi::fromNativePixels(nativeCursorPos, window);
263
265 const QTransform mapToLocal = im->inputItemTransform().inverted();
266 bool success;
267 int anchor = QInputMethod::queryFocusObject(Qt::ImCursorPosition, anchorPos * mapToLocal).toInt(&success);
268 if (success) {
269 int cursor = QInputMethod::queryFocusObject(Qt::ImCursorPosition, cursorPos * mapToLocal).toInt(&success);
270 if (success) {
271 if (anchor == cursor && anchorPos != cursorPos)
272 return;
273 QList<QInputMethodEvent::Attribute> imAttributes;
274 imAttributes.append(QInputMethodEvent::Attribute(QInputMethodEvent::Selection, anchor, cursor - anchor, QVariant()));
275 QInputMethodEvent event(QString(), imAttributes);
277 }
278 }
279}
280
293
301{
303 const QRectF deviceIndependentRectangle = im->inputItemTransform().mapRect(im->inputItemRectangle());
304 return QHighDpi::toNativePixels(deviceIndependentRectangle, QGuiApplication::focusWindow());
305}
306
318
330
342
354
356
357#include "moc_qplatforminputcontext.cpp"
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
\inmodule QtCore
Definition qcoreevent.h:45
static QWindow * focusWindow()
Returns the QWindow that receives events tied to focus, such as key events.
static QInputMethod * inputMethod()
returns the input method.
The QInputMethodEvent class provides parameters for input method events.
Definition qevent.h:625
The QInputMethod class provides access to the active text input method.
Action
Indicates the kind of action performed by the user.
static QVariant queryFocusObject(Qt::InputMethodQuery query, const QVariant &argument)
Send query to the current focus object with parameters argument and return the result.
QRectF inputItemRectangle() const
QTransform inputItemTransform() const
Returns the transformation from input item coordinates to the window coordinates.
static QLocale system()
Returns a QLocale object initialized to the system locale.
Definition qlocale.cpp:2862
\inmodule QtCore
Definition qobject.h:103
static void setInputMethodAccepted(bool accepted)
virtual bool isInputPanelVisible() const
Returns input panel visibility status.
virtual bool isAnimating() const
This function can be reimplemented to return true whenever input method is animating shown or hidden.
bool inputMethodAccepted() const
Returns true if current focus object supports input method events.
static QRectF anchorRectangle()
QPlatformInputContext::anchorRectangle.
virtual QLocale locale() const
void emitInputDirectionChanged(Qt::LayoutDirection newDirection)
void emitAnimatingChanged()
Active QPlatformInputContext is responsible for providing animating property to QInputMethod.
virtual bool hasCapability(Capability capability) const
Returns whether the implementation supports capability.
void emitInputPanelVisibleChanged()
Active QPlatformInputContext is responsible for providing visible property to QInputMethod.
virtual void update(Qt::InputMethodQueries)
Notification on editor updates.
static void setSelectionOnFocusObject(const QPointF &anchorPos, const QPointF &cursorPos)
QPlatformInputContext::setSelectionOnFocusObject.
static QVariant queryFocusObject(Qt::InputMethodQuery query, QPointF position)
QPlatformInputContext::queryFocusObject.
virtual bool filterEvent(const QEvent *event)
This function can be reimplemented to filter input events.
static QRectF keyboardRectangle()
QPlatformInputContext::keyboardRectangle.
virtual void setFocusObject(QObject *object)
This virtual method gets called to notify updated focus to object.
static QRectF inputItemClipRectangle()
QPlatformInputContext::inputItemClipRectangle.
virtual void invokeAction(QInputMethod::Action, int cursorPosition)
Called when the word currently being composed in the input item is tapped by the user.
virtual bool isValid() const
Returns input context validity.
void emitKeyboardRectChanged()
Active QPlatformInputContext is responsible for providing keyboardRectangle property to QInputMethod.
virtual void reset()
Method to be called when input method needs to be reset.
static QRectF cursorRectangle()
QPlatformInputContext::cursorRectangle.
static QRectF inputItemRectangle()
QPlatformInputContext::inputItemRectangle.
virtual void showInputPanel()
Request to show input panel.
virtual Qt::LayoutDirection inputDirection() const
virtual void hideInputPanel()
Request to hide input panel.
virtual QRectF keyboardRect() const
This function can be reimplemented to return virtual keyboard rectangle in currently active window co...
\inmodule QtCore\reentrant
Definition qpoint.h:217
\inmodule QtCore\reentrant
Definition qrect.h:484
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
The QTransform class specifies 2D transformations of a coordinate system.
Definition qtransform.h:20
QTransform inverted(bool *invertible=nullptr) const
Returns an inverted copy of this matrix.
QRect mapRect(const QRect &) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
\inmodule QtCore
Definition qvariant.h:65
\inmodule QtGui
Definition qwindow.h:63
bool focus
[0]
QCursor cursor
T toNativePixels(const T &value, const C *context)
T fromNativePixels(const T &value, const C *context)
Combined button and popup list for selecting options.
InputMethodQuery
@ ImCursorPosition
LayoutDirection
@ QueuedConnection
#define qApp
struct _cl_event * event
GLenum query
static qreal position(const QQuickItem *item, QQuickAnchors::Anchor anchorLine)
#define emit
#define Q_UNUSED(x)
aWidget window() -> setWindowTitle("New Window Title")
[2]
static bool invokeMethod(QObject *obj, const char *member, Qt::ConnectionType, QGenericReturnArgument ret, QGenericArgument val0=QGenericArgument(nullptr), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument(), QGenericArgument val4=QGenericArgument(), QGenericArgument val5=QGenericArgument(), QGenericArgument val6=QGenericArgument(), QGenericArgument val7=QGenericArgument(), QGenericArgument val8=QGenericArgument(), QGenericArgument val9=QGenericArgument())
\threadsafe This is an overloaded member function, provided for convenience. It differs from the abov...