aboutsummaryrefslogtreecommitdiff
path: root/src/keymap/KeymapEvaluator.hpp
blob: 4f8184b0803b8185f96aa053aa8db265b492eed0 (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
42
#pragma once

#include <QWidget>
#include <QtCore>
#include <cstdint>
#include <functional>

#include "keymap/KeySeqParser.hpp"
#include "utils.hpp"

using KeyAction = std::function<void()>;

struct KeyMap {
  KeySequence key_sequence;
  KeyAction action;
};

enum KeyMode : uint8_t { Normal, Insert };

class KeymapEvaluator : public QObject {
  Q_OBJECT

public:
  KeymapEvaluator() = default;

  void add_keymap(KeyMode mode, const QString &key, KeyAction action);
  bool evaluate(Qt::KeyboardModifiers modifiers, Qt::Key key);
  KeyMode mode_from_string(const QString &mode_string);

  DEFINE_SETTER(set_current_mode, current_mode)
  DEFINE_GETTER(get_current_mode, current_mode)

protected:
  const QList<KeyMap> *current_mode_keys();
  bool is_insertable_mode();

private:
  QMap<KeyMode, QList<KeyMap>> modal_keys;
  KeySeqParser key_seq_parser;
  KeyMode current_mode = KeyMode::Normal;
  KeySequence active_key_sequence;
};