blob: eb878abf433fdaa8d96ffdc7f3bbe491aaa80621 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
#pragma once
#include <QtCore>
#include <cstdint>
struct KeyChord {
Qt::KeyboardModifiers mod;
Qt::Key key;
};
bool operator==(KeyChord chord1, KeyChord chord2);
using KeySequence = QList<KeyChord>;
enum KeyMatchType : uint8_t {
NoMatch,
Match,
Pending,
};
class KeySeqParser {
public:
static KeyMatchType key_sequence_match(const KeySequence &target,
const KeySequence ¤t) {
for (int i = 0; i < target.length(); i++) {
if (current.length() <= i)
return KeyMatchType::Pending;
if (target[i].key != current[i].key ||
!target[i].mod.testFlags(current[i].mod))
return KeyMatchType::NoMatch;
}
return KeyMatchType::Match;
}
KeySeqParser() = default;
KeySequence parse(QString key_sequence);
private:
Qt::Key parse_key(const QString &key_name);
};
|