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
qapplekeymapper_p.h
Go to the documentation of this file.
1// Copyright (C) 2021 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
4#ifndef QAPPLEKEYMAPPER_H
5#define QAPPLEKEYMAPPER_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#ifdef Q_OS_MACOS
19#include <Carbon/Carbon.h>
20#endif
21
22#include <qpa/qplatformkeymapper.h>
23
24#include <QtCore/QList>
25#include <QtCore/QHash>
26#include <QtGui/QKeyEvent>
27
28#include <QtCore/private/qcore_mac_p.h>
29
31
32class Q_GUI_EXPORT QAppleKeyMapper : public QPlatformKeyMapper
33{
34public:
35 Qt::KeyboardModifiers queryKeyboardModifiers() const override;
36 QList<QKeyCombination> possibleKeyCombinations(const QKeyEvent *event) const override;
37
38#ifdef Q_OS_MACOS
39 static Qt::KeyboardModifiers fromCocoaModifiers(NSEventModifierFlags cocoaModifiers);
40 static NSEventModifierFlags toCocoaModifiers(Qt::KeyboardModifiers);
41
42 static QChar toCocoaKey(Qt::Key key);
43 static Qt::Key fromCocoaKey(QChar keyCode);
44#else
45 static Qt::Key fromNSString(Qt::KeyboardModifiers qtMods, NSString *characters,
46 NSString *charactersIgnoringModifiers, QString &text);
47
48 static Qt::Key fromUIKitKey(NSString *keyCode);
49 static Qt::KeyboardModifiers fromUIKitModifiers(ulong uikitModifiers);
50 static ulong toUIKitModifiers(Qt::KeyboardModifiers);
51#endif
52private:
53#ifdef Q_OS_MACOS
54 static constexpr int kNumModifierCombinations = 16;
55 struct KeyMap : std::array<char32_t, kNumModifierCombinations>
56 {
57 // Initialize first element to a sentinel that allows us
58 // to distinguish an uninitialized map from an initialized.
59 // Using 0 would not allow us to map U+0000 (NUL), however
60 // unlikely that is.
61 KeyMap() : std::array<char32_t, 16>{Qt::Key_unknown} {}
62 };
63
64 bool updateKeyboard();
65
66 using VirtualKeyCode = unsigned short;
67 const KeyMap &keyMapForKey(VirtualKeyCode virtualKey) const;
68
69 QCFType<TISInputSourceRef> m_currentInputSource = nullptr;
70
71 enum { NullMode, UnicodeMode, OtherMode } m_keyboardMode = NullMode;
72 const UCKeyboardLayout *m_keyboardLayoutFormat = nullptr;
73 KeyboardLayoutKind m_keyboardKind = kKLKCHRuchrKind;
74
75 mutable QHash<VirtualKeyCode, KeyMap> m_keyMap;
76#endif
77};
78
80
81#endif
82
static Qt::Key fromUIKitKey(NSString *keyCode)
QList< QKeyCombination > possibleKeyCombinations(const QKeyEvent *event) const override
Qt::KeyboardModifiers queryKeyboardModifiers() const override
\inmodule QtCore
The QKeyEvent class describes a key event.
Definition qevent.h:424
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
QString text
Combined button and popup list for selecting options.
@ Key_unknown
GLuint64 key
struct _cl_event * event
GLenum array
unsigned long ulong
Definition qtypes.h:35
QList< QChar > characters