summaryrefslogtreecommitdiff
path: root/src/settings.hpp
blob: 54e34868d486357c15aea8cb665be6263080b37a (plain)
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#ifndef GETSUYOMI_SETTINGS_HPP
#define GETSUYOMI_SETTINGS_HPP

#include <QtWidgets>
#include <map>
#include <optional>
#include <qkeysequence.h>
#include <qlist.h>
#include <set>
#include <string>
#include <filesystem>

#include "config.hpp"

namespace getsuyomi {

class Settings : public QDialog {
    Q_OBJECT
  public:
    Settings(QWidget* parent, Shortcuts&& shortcuts);
    Settings(const Settings&) = delete;
    Settings(Settings&& rhs) = delete;
    ~Settings() = default;
    Settings& operator=(const Settings&) = delete;
    Settings& operator=(Settings&& rhs) = delete;

    [[nodiscard]] bool valid() const;

    const Shortcuts& shortcuts() const;

  private:
    Shortcuts m_shortcuts;
};

class ShortcutDisplay;

class ShortcutCollector : public QWidget {
    Q_OBJECT
  public:
    ShortcutCollector(QWidget* parent, ActionType action, Shortcuts& shortcuts);
    ~ShortcutCollector() = default;
    ShortcutCollector(const ShortcutCollector&) = delete;
    ShortcutCollector(ShortcutCollector&&) = delete;
    ShortcutCollector& operator=(const ShortcutCollector&) = delete;
    ShortcutCollector& operator=(ShortcutCollector&&) = delete;

  private:
    void createBinding(QKeySequence binding);

  private slots:
    void checkBinding();
    void addBinding();
    void removeBinding(QKeySequence shortcut);

  private:
    ActionType m_action;
    Shortcuts& m_shortcuts;
    std::map<QKeySequence, ShortcutDisplay*> m_bindings;
    QKeySequenceEdit* m_shortcutEditor{nullptr};
    QPushButton* m_acceptButton{nullptr};
    QVBoxLayout* m_layout{nullptr};
};

class ShortcutDisplay : public QWidget {
    Q_OBJECT
  public:
    ShortcutDisplay(QWidget* parent, QKeySequence shortcut);

  signals:
    void removeClicked(QKeySequence shortcut);

  private:
    QKeySequence m_binding;
  private slots:
    void removeOnClicked();
};

} // namespace getsuyomi

#endif