From 47e0ff88edd4660513f1d4f3d731008461532a13 Mon Sep 17 00:00:00 2001 From: Dominick Allen Date: Wed, 2 Oct 2024 15:07:24 -0500 Subject: Get and save user keybinds. --- src/settings.hpp | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 src/settings.hpp (limited to 'src/settings.hpp') 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 +#include +#include +#include +#include +#include +#include +#include + +#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 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 -- cgit v1.2.3