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#ifndef QSHORTCUTMAP_P_H
5#define QSHORTCUTMAP_P_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#include <QtGui/private/qtguiglobal_p.h>
19#include "QtGui/qkeysequence.h"
20#include "QtCore/qlist.h"
21#include "QtCore/qscopedpointer.h"
22
23QT_REQUIRE_CONFIG(shortcut);
24
25QT_BEGIN_NAMESPACE
26
27// To enable dump output uncomment below
28//#define Dump_QShortcutMap
29
30class QKeyEvent;
31struct QShortcutEntry;
32class QShortcutMapPrivate;
33class QObject;
34
35class Q_GUI_EXPORT QShortcutMap
36{
37 Q_DECLARE_PRIVATE(QShortcutMap)
38public:
39 QShortcutMap();
40 ~QShortcutMap();
41
42 typedef bool (*ContextMatcher)(QObject *object, Qt::ShortcutContext context);
43
44 int addShortcut(QObject *owner, const QKeySequence &key, Qt::ShortcutContext context, ContextMatcher matcher);
45 int removeShortcut(int id, QObject *owner, const QKeySequence &key = QKeySequence());
46 int setShortcutEnabled(bool enable, int id, QObject *owner, const QKeySequence &key = QKeySequence());
47 int setShortcutAutoRepeat(bool on, int id, QObject *owner, const QKeySequence &key = QKeySequence());
48
49 QKeySequence::SequenceMatch state();
50
51 bool tryShortcut(QKeyEvent *e);
52 bool hasShortcutForKeySequence(const QKeySequence &seq) const;
53 QList<QKeySequence> keySequences(bool getAll = false) const;
54
55#ifdef Dump_QShortcutMap
56 void dumpMap() const;
57#endif
58
59private:
60 void resetState();
61 QKeySequence::SequenceMatch nextState(QKeyEvent *e);
62 void dispatchEvent(QKeyEvent *e);
63
64 QKeySequence::SequenceMatch find(QKeyEvent *e, int ignoredModifiers = 0);
65 QKeySequence::SequenceMatch matches(const QKeySequence &seq1, const QKeySequence &seq2) const;
66 QList<const QShortcutEntry *> matches() const;
67 void createNewSequences(QKeyEvent *e, QList<QKeySequence> &ksl, int ignoredModifiers);
68 void clearSequence(QList<QKeySequence> &ksl);
69 int translateModifiers(Qt::KeyboardModifiers modifiers);
70
71 QScopedPointer<QShortcutMapPrivate> d_ptr;
72};
73
74QT_END_NAMESPACE
75
76#endif // QSHORTCUTMAP_P_H
77

source code of qtbase/src/gui/kernel/qshortcutmap_p.h