git repos / SagoImageBrowser

blame: src/shortcutmanager.h

normal view · raw

83f0e0bc Poul Sander 2026-05-30 17:59 1
#pragma once
83f0e0bc Poul Sander 2026-05-30 17:59 2
83f0e0bc Poul Sander 2026-05-30 17:59 3
#include <QKeySequence>
83f0e0bc Poul Sander 2026-05-30 17:59 4
#include <QString>
83f0e0bc Poul Sander 2026-05-30 17:59 5
#include <array>
83f0e0bc Poul Sander 2026-05-30 17:59 6
83f0e0bc Poul Sander 2026-05-30 17:59 7
class QSettings;
83f0e0bc Poul Sander 2026-05-30 17:59 8
class QKeyEvent;
83f0e0bc Poul Sander 2026-05-30 17:59 9
83f0e0bc Poul Sander 2026-05-30 17:59 10
class ShortcutManager
83f0e0bc Poul Sander 2026-05-30 17:59 11
{
83f0e0bc Poul Sander 2026-05-30 17:59 12
public:
83f0e0bc Poul Sander 2026-05-30 17:59 13
    enum Action {
83f0e0bc Poul Sander 2026-05-30 17:59 14
        ToggleHelp,
83f0e0bc Poul Sander 2026-05-30 17:59 15
        CloseViewer,
83f0e0bc Poul Sander 2026-05-30 17:59 16
        CloseViewerAlt,
83f0e0bc Poul Sander 2026-05-30 17:59 17
        NextImage,
83f0e0bc Poul Sander 2026-05-30 17:59 18
        PrevImage,
83f0e0bc Poul Sander 2026-05-30 17:59 19
        PanLeft,
83f0e0bc Poul Sander 2026-05-30 17:59 20
        PanRight,
83f0e0bc Poul Sander 2026-05-30 17:59 21
        PanUp,
83f0e0bc Poul Sander 2026-05-30 17:59 22
        PanDown,
83f0e0bc Poul Sander 2026-05-30 17:59 23
        ZoomOriginal,
83f0e0bc Poul Sander 2026-05-30 17:59 24
        ZoomFit,
83f0e0bc Poul Sander 2026-05-30 17:59 25
        ZoomIn,
83f0e0bc Poul Sander 2026-05-30 17:59 26
        ZoomOut,
83f0e0bc Poul Sander 2026-05-30 17:59 27
        ToggleExif,
83f0e0bc Poul Sander 2026-05-30 17:59 28
        EditCaption,
83f0e0bc Poul Sander 2026-05-30 17:59 29
        ToggleFullscreen,
83f0e0bc Poul Sander 2026-05-30 17:59 30
        ActivateEntry,
83f0e0bc Poul Sander 2026-05-30 17:59 31
        ActionCount
83f0e0bc Poul Sander 2026-05-30 17:59 32
    };
83f0e0bc Poul Sander 2026-05-30 17:59 33
83f0e0bc Poul Sander 2026-05-30 17:59 34
    enum Category {
83f0e0bc Poul Sander 2026-05-30 17:59 35
        CatBrowser,
83f0e0bc Poul Sander 2026-05-30 17:59 36
        CatImageViewer,
83f0e0bc Poul Sander 2026-05-30 17:59 37
        CatNotConfigurable
83f0e0bc Poul Sander 2026-05-30 17:59 38
    };
83f0e0bc Poul Sander 2026-05-30 17:59 39
83f0e0bc Poul Sander 2026-05-30 17:59 40
    static ShortcutManager &instance();
83f0e0bc Poul Sander 2026-05-30 17:59 41
83f0e0bc Poul Sander 2026-05-30 17:59 42
    QKeySequence shortcut(Action action) const;
83f0e0bc Poul Sander 2026-05-30 17:59 43
    QString displayKey(Action action) const;
83f0e0bc Poul Sander 2026-05-30 17:59 44
    QString description(Action action) const;
83f0e0bc Poul Sander 2026-05-30 17:59 45
83f0e0bc Poul Sander 2026-05-30 17:59 46
    void setShortcut(Action action, const QKeySequence &seq);
83f0e0bc Poul Sander 2026-05-30 17:59 47
    void resetToDefaults();
83f0e0bc Poul Sander 2026-05-30 17:59 48
83f0e0bc Poul Sander 2026-05-30 17:59 49
    void load(QSettings &settings);
83f0e0bc Poul Sander 2026-05-30 17:59 50
    void save(QSettings &settings) const;
83f0e0bc Poul Sander 2026-05-30 17:59 51
83f0e0bc Poul Sander 2026-05-30 17:59 52
    static QKeySequence defaultShortcut(Action action);
83f0e0bc Poul Sander 2026-05-30 17:59 53
    static QString actionName(Action action);
83f0e0bc Poul Sander 2026-05-30 17:59 54
    static QString actionDescription(Action action);
83f0e0bc Poul Sander 2026-05-30 17:59 55
    static Category actionCategory(Action action);
83f0e0bc Poul Sander 2026-05-30 17:59 56
83f0e0bc Poul Sander 2026-05-30 17:59 57
    /// Returns true if the key event matches the configured shortcut for the action.
83f0e0bc Poul Sander 2026-05-30 17:59 58
    bool matches(const QKeyEvent *event, Action action) const;
83f0e0bc Poul Sander 2026-05-30 17:59 59
83f0e0bc Poul Sander 2026-05-30 17:59 60
private:
83f0e0bc Poul Sander 2026-05-30 17:59 61
    ShortcutManager();
83f0e0bc Poul Sander 2026-05-30 17:59 62
83f0e0bc Poul Sander 2026-05-30 17:59 63
    struct Binding {
83f0e0bc Poul Sander 2026-05-30 17:59 64
        QKeySequence key;
83f0e0bc Poul Sander 2026-05-30 17:59 65
    };
83f0e0bc Poul Sander 2026-05-30 17:59 66
83f0e0bc Poul Sander 2026-05-30 17:59 67
    std::array<Binding, ActionCount> m_bindings;
83f0e0bc Poul Sander 2026-05-30 17:59 68
};
1970-01-01 00:00 69