1/*
2 SPDX-FileCopyrightText: 2008 Erlend Hamberg <ehamberg@gmail.com>
3 SPDX-FileCopyrightText: 2008 Evgeniy Ivanov <powerfox@kde.ru>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
8#ifndef KATEVI_KEY_PARSER_H
9#define KATEVI_KEY_PARSER_H
10
11#include <QChar>
12#include <QHash>
13#include <QString>
14#include <ktexteditor_export.h>
15
16class QKeyEvent;
17
18namespace KateVi
19{
20
21class KeyEvent;
22
23/**
24 * for encoding keypresses w/ modifiers into an internal QChar representation and back again to a
25 * descriptive text string
26 */
27class KeyParser
28{
29private:
30 KeyParser();
31
32public:
33 KTEXTEDITOR_EXPORT static KeyParser *self();
34 ~KeyParser()
35 {
36 m_instance = nullptr;
37 }
38 KeyParser(const KeyParser &) = delete;
39 KeyParser &operator=(const KeyParser &) = delete;
40
41 KTEXTEDITOR_EXPORT const QString encodeKeySequence(const QString &keys) const;
42 KTEXTEDITOR_EXPORT const QString decodeKeySequence(const QString &keys) const;
43 QString qt2vi(int key) const;
44 KTEXTEDITOR_EXPORT int vi2qt(const QString &keypress) const;
45 int encoded2qt(const QString &keypress) const;
46 KTEXTEDITOR_EXPORT const QChar KeyEventToQChar(const QKeyEvent &keyEvent);
47 const QChar KeyEventToQChar(const KeyEvent &keyEvent);
48
49private:
50 void initKeyTables();
51 const QChar KeyEventToQChar(int keyCode, const QString &text, Qt::KeyboardModifiers mods) const;
52
53 QHash<int, QString> m_qt2katevi;
54 QHash<QString, int> m_katevi2qt;
55 QHash<QString, int> m_nameToKeyCode;
56 QHash<int, QString> m_keyCodeToName;
57
58 static KeyParser *m_instance;
59};
60
61}
62
63#endif /* KATEVI_KEY_PARSER_H */
64

source code of ktexteditor/src/vimode/keyparser.h