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
4
5#include "qguiapplication.h"
6
7#include <private/qobject_p.h>
8#include "qkeymapper_p.h"
9
10#include <private/qguiapplication_p.h>
11#include <qpa/qplatformintegration.h>
12#include <qpa/qplatformkeymapper.h>
13
14QT_BEGIN_NAMESPACE
15
16/*!
17 \class QKeyMapper
18 \since 4.2
19 \internal
20
21 \sa QObject
22*/
23
24/*!
25 Constructs a new key mapper.
26*/
27QKeyMapper::QKeyMapper() : QObject()
28{
29}
30
31/*!
32 Destroys the key mapper.
33*/
34QKeyMapper::~QKeyMapper()
35{
36}
37
38QList<QKeyCombination> QKeyMapper::possibleKeys(const QKeyEvent *e)
39{
40 qCDebug(lcQpaKeyMapper).verbosity(verbosityLevel: 3) << "Computing possible key combinations for" << e;
41
42 const auto *platformIntegration = QGuiApplicationPrivate::platformIntegration();
43 const auto *platformKeyMapper = platformIntegration->keyMapper();
44 QList<QKeyCombination> result = platformKeyMapper->possibleKeyCombinations(event: e);
45
46 if (result.isEmpty()) {
47 if (e->key() && (e->key() != Qt::Key_unknown))
48 result << e->keyCombination();
49 else if (!e->text().isEmpty())
50 result << (Qt::Key(e->text().at(i: 0).unicode()) | e->modifiers());
51 }
52
53#if QT_CONFIG(shortcut)
54 if (lcQpaKeyMapper().isDebugEnabled()) {
55 qCDebug(lcQpaKeyMapper) << "Resulting possible key combinations:";
56 for (auto keyCombination : result) {
57 auto keySequence = QKeySequence(keyCombination);
58 qCDebug(lcQpaKeyMapper).verbosity(verbosityLevel: 0) << "\t-"
59 << keyCombination << "/" << keySequence << "/"
60 << qUtf8Printable(keySequence.toString(QKeySequence::NativeText));
61 }
62 }
63#endif
64
65 return result;
66}
67
68Q_GLOBAL_STATIC(QKeyMapper, keymapper)
69/*!
70 Returns the pointer to the single instance of QKeyMapper in the application.
71 If none yet exists, the function ensures that one is created.
72*/
73QKeyMapper *QKeyMapper::instance()
74{
75 return keymapper();
76}
77
78void *QKeyMapper::resolveInterface(const char *name, int revision) const
79{
80 Q_UNUSED(name); Q_UNUSED(revision);
81 using namespace QNativeInterface::Private;
82
83#if QT_CONFIG(evdev)
84 QT_NATIVE_INTERFACE_RETURN_IF(QEvdevKeyMapper, QGuiApplicationPrivate::platformIntegration());
85#endif
86
87 return nullptr;
88}
89
90QT_END_NAMESPACE
91
92#include "moc_qkeymapper_p.cpp"
93

Provided by KDAB

Privacy Policy
Learn Advanced QML with KDAB
Find out more

source code of qtbase/src/gui/kernel/qkeymapper.cpp