summaryrefslogtreecommitdiff
path: root/src/settings.hpp
diff options
context:
space:
mode:
authorDominick Allen <djallen@librehumanitas.org>2024-10-02 15:07:24 -0500
committerDominick Allen <djallen@librehumanitas.org>2024-10-02 15:07:24 -0500
commit47e0ff88edd4660513f1d4f3d731008461532a13 (patch)
tree5b73ad0920101190e6e7cb558833e24f31ccdc4d /src/settings.hpp
parent99c6c809b961f2eb3c8538bfa50de7f2f98587ea (diff)
Get and save user keybinds.
Diffstat (limited to 'src/settings.hpp')
-rw-r--r--src/settings.hpp80
1 files changed, 80 insertions, 0 deletions
diff --git a/src/settings.hpp b/src/settings.hpp
new file mode 100644
index 0000000..54e3486
--- /dev/null
+++ b/src/settings.hpp
@@ -0,0 +1,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