1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the test suite of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT |
21 | ** included in the packaging of this file. Please review the following |
22 | ** information to ensure the GNU General Public License requirements will |
23 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
24 | ** |
25 | ** $QT_END_LICENSE$ |
26 | ** |
27 | ****************************************************************************/ |
28 | |
29 | #include <qpa/qplatforminputcontext.h> |
30 | |
31 | class PlatformInputContext : public QPlatformInputContext |
32 | { |
33 | public: |
34 | PlatformInputContext() : |
35 | m_animating(false), |
36 | m_visible(false), |
37 | m_updateCallCount(0), |
38 | m_resetCallCount(0), |
39 | m_commitCallCount(0), |
40 | m_localeCallCount(0), |
41 | m_inputDirectionCallCount(0), |
42 | m_lastQueries(Qt::ImhNone), |
43 | m_action(QInputMethod::Click), |
44 | m_cursorPosition(0), |
45 | m_lastEventType(QEvent::None), |
46 | m_setFocusObjectCallCount(0) |
47 | {} |
48 | |
49 | virtual QRectF keyboardRect() const { return m_keyboardRect; } |
50 | virtual bool isAnimating() const { return m_animating; } |
51 | virtual void reset() { m_resetCallCount++; } |
52 | virtual void commit() { |
53 | m_commitCallCount++; |
54 | if (m_commitString.isEmpty()) |
55 | return; |
56 | QInputMethodEvent commitEvent; |
57 | commitEvent.setCommitString(commitString: m_commitString); |
58 | if (qGuiApp->focusObject()) |
59 | qGuiApp->sendEvent(qGuiApp->focusObject(), event: &commitEvent); |
60 | else |
61 | qWarning(msg: "Test input context to commit without focused object" ); |
62 | } |
63 | void setCommitString(const QString &commitString) |
64 | { |
65 | m_commitString = commitString; |
66 | } |
67 | |
68 | virtual void update(Qt::InputMethodQueries queries) |
69 | { |
70 | m_updateCallCount++; |
71 | m_lastQueries = queries; |
72 | } |
73 | virtual void invokeAction(QInputMethod::Action action, int cursorPosition) |
74 | { |
75 | m_action = action; |
76 | m_cursorPosition = cursorPosition; |
77 | } |
78 | virtual bool filterEvent(const QEvent *event) |
79 | { |
80 | m_lastEventType = event->type(); return false; |
81 | } |
82 | virtual void showInputPanel() |
83 | { |
84 | m_visible = true; |
85 | } |
86 | virtual void hideInputPanel() |
87 | { |
88 | m_visible = false; |
89 | } |
90 | virtual bool isInputPanelVisible() const |
91 | { |
92 | return m_visible; |
93 | } |
94 | virtual QLocale locale() const |
95 | { |
96 | m_localeCallCount++; |
97 | return QLocale::c(); |
98 | } |
99 | virtual Qt::LayoutDirection inputDirection() const |
100 | { |
101 | m_inputDirectionCallCount++; |
102 | return Qt::LeftToRight; |
103 | } |
104 | virtual void setFocusObject(QObject *object) |
105 | { |
106 | Q_UNUSED(object); |
107 | m_setFocusObjectCallCount++; |
108 | } |
109 | |
110 | bool m_animating; |
111 | bool m_visible; |
112 | int m_updateCallCount; |
113 | int m_resetCallCount; |
114 | int m_commitCallCount; |
115 | QString m_commitString; |
116 | mutable int m_localeCallCount; |
117 | mutable int m_inputDirectionCallCount; |
118 | Qt::InputMethodQueries m_lastQueries; |
119 | QInputMethod::Action m_action; |
120 | int m_cursorPosition; |
121 | int m_lastEventType; |
122 | QRectF m_keyboardRect; |
123 | int m_setFocusObjectCallCount; |
124 | }; |
125 | |