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#ifndef QIBUSPLATFORMINPUTCONTEXT_H
4#define QIBUSPLATFORMINPUTCONTEXT_H
5
6#include <qpa/qplatforminputcontext.h>
7
8#include <QtCore/qpointer.h>
9#include <QtCore/QLocale>
10#include <QtDBus/qdbuspendingreply.h>
11#if QT_CONFIG(filesystemwatcher)
12#include <QFileSystemWatcher>
13#endif
14#include <QTimer>
15#include <QWindow>
16
17QT_BEGIN_NAMESPACE
18
19class QIBusPlatformInputContextPrivate;
20class QDBusVariant;
21
22class QIBusFilterEventWatcher: public QDBusPendingCallWatcher
23{
24public:
25 explicit QIBusFilterEventWatcher(const QDBusPendingCall &call,
26 QObject *parent = nullptr,
27 QWindow *window = nullptr,
28 const Qt::KeyboardModifiers modifiers = { },
29 const QVariantList arguments = QVariantList())
30 : QDBusPendingCallWatcher(call, parent)
31 , m_window(window)
32 , m_modifiers(modifiers)
33 , m_arguments(arguments)
34 {}
35 ~QIBusFilterEventWatcher()
36 {}
37
38 inline QWindow *window() const { return m_window; }
39 inline const Qt::KeyboardModifiers modifiers() const { return m_modifiers; }
40 inline const QVariantList arguments() const { return m_arguments; }
41
42private:
43 QPointer<QWindow> m_window;
44 const Qt::KeyboardModifiers m_modifiers;
45 const QVariantList m_arguments;
46};
47
48class QIBusPlatformInputContext : public QPlatformInputContext
49{
50 Q_OBJECT
51public:
52 QIBusPlatformInputContext();
53 ~QIBusPlatformInputContext();
54
55 bool isValid() const override;
56 void setFocusObject(QObject *object) override;
57
58 void invokeAction(QInputMethod::Action a, int x) override;
59 void reset() override;
60 void commit() override;
61 void update(Qt::InputMethodQueries) override;
62 bool filterEvent(const QEvent *event) override;
63 QLocale locale() const override;
64 bool hasCapability(Capability capability) const override;
65
66public Q_SLOTS:
67 void commitText(const QDBusVariant &text);
68 void updatePreeditText(const QDBusVariant &text, uint cursor_pos, bool visible);
69 void forwardKeyEvent(uint keyval, uint keycode, uint state);
70 void cursorRectChanged();
71 void deleteSurroundingText(int offset, uint n_chars);
72 void surroundingTextRequired();
73 void hidePreeditText();
74 void showPreeditText();
75 void filterEventFinished(QDBusPendingCallWatcher *call);
76 void socketChanged(const QString &str);
77 void busRegistered(const QString &str);
78 void busUnregistered(const QString &str);
79 void connectToBus();
80 void globalEngineChanged(const QString &engine_name);
81
82private:
83 QIBusPlatformInputContextPrivate *d;
84 bool m_eventFilterUseSynchronousMode;
85#if QT_CONFIG(filesystemwatcher)
86 QFileSystemWatcher m_socketWatcher;
87#endif
88 QTimer m_timer;
89
90 void connectToContextSignals();
91};
92
93QT_END_NAMESPACE
94
95#endif
96

source code of qtbase/src/plugins/platforminputcontexts/ibus/qibusplatforminputcontext.h