git repos / SagoImageBrowser

blame: src/shortcutmanager.h

normal view · raw

14cf904f Poul Sander 2026-06-22 18:18 1
/*
14cf904f Poul Sander 2026-06-22 18:18 2
MIT License
14cf904f Poul Sander 2026-06-22 18:18 3
14cf904f Poul Sander 2026-06-22 18:18 4
Copyright (c) 2026 Poul Sander
14cf904f Poul Sander 2026-06-22 18:18 5
14cf904f Poul Sander 2026-06-22 18:18 6
Permission is hereby granted, free of charge, to any person obtaining a copy
14cf904f Poul Sander 2026-06-22 18:18 7
of this software and associated documentation files (the "Software"), to deal
14cf904f Poul Sander 2026-06-22 18:18 8
in the Software without restriction, including without limitation the rights
14cf904f Poul Sander 2026-06-22 18:18 9
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14cf904f Poul Sander 2026-06-22 18:18 10
copies of the Software, and to permit persons to whom the Software is
14cf904f Poul Sander 2026-06-22 18:18 11
furnished to do so, subject to the following conditions:
14cf904f Poul Sander 2026-06-22 18:18 12
14cf904f Poul Sander 2026-06-22 18:18 13
The above copyright notice and this permission notice shall be included in all
14cf904f Poul Sander 2026-06-22 18:18 14
copies or substantial portions of the Software.
14cf904f Poul Sander 2026-06-22 18:18 15
14cf904f Poul Sander 2026-06-22 18:18 16
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14cf904f Poul Sander 2026-06-22 18:18 17
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14cf904f Poul Sander 2026-06-22 18:18 18
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14cf904f Poul Sander 2026-06-22 18:18 19
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
14cf904f Poul Sander 2026-06-22 18:18 20
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
14cf904f Poul Sander 2026-06-22 18:18 21
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
14cf904f Poul Sander 2026-06-22 18:18 22
SOFTWARE.
14cf904f Poul Sander 2026-06-22 18:18 23
14cf904f Poul Sander 2026-06-22 18:18 24
*/
14cf904f Poul Sander 2026-06-22 18:18 25
83f0e0bc Poul Sander 2026-05-30 17:59 26
#pragma once
83f0e0bc Poul Sander 2026-05-30 17:59 27
83f0e0bc Poul Sander 2026-05-30 17:59 28
#include <QKeySequence>
83f0e0bc Poul Sander 2026-05-30 17:59 29
#include <QString>
83f0e0bc Poul Sander 2026-05-30 17:59 30
#include <array>
83f0e0bc Poul Sander 2026-05-30 17:59 31
83f0e0bc Poul Sander 2026-05-30 17:59 32
class QSettings;
83f0e0bc Poul Sander 2026-05-30 17:59 33
class QKeyEvent;
83f0e0bc Poul Sander 2026-05-30 17:59 34
83f0e0bc Poul Sander 2026-05-30 17:59 35
class ShortcutManager
83f0e0bc Poul Sander 2026-05-30 17:59 36
{
83f0e0bc Poul Sander 2026-05-30 17:59 37
public:
83f0e0bc Poul Sander 2026-05-30 17:59 38
    enum Action {
83f0e0bc Poul Sander 2026-05-30 17:59 39
        ToggleHelp,
83f0e0bc Poul Sander 2026-05-30 17:59 40
        CloseViewer,
83f0e0bc Poul Sander 2026-05-30 17:59 41
        CloseViewerAlt,
83f0e0bc Poul Sander 2026-05-30 17:59 42
        NextImage,
83f0e0bc Poul Sander 2026-05-30 17:59 43
        PrevImage,
83f0e0bc Poul Sander 2026-05-30 17:59 44
        PanLeft,
83f0e0bc Poul Sander 2026-05-30 17:59 45
        PanRight,
83f0e0bc Poul Sander 2026-05-30 17:59 46
        PanUp,
83f0e0bc Poul Sander 2026-05-30 17:59 47
        PanDown,
83f0e0bc Poul Sander 2026-05-30 17:59 48
        ZoomOriginal,
83f0e0bc Poul Sander 2026-05-30 17:59 49
        ZoomFit,
83f0e0bc Poul Sander 2026-05-30 17:59 50
        ZoomIn,
83f0e0bc Poul Sander 2026-05-30 17:59 51
        ZoomOut,
83f0e0bc Poul Sander 2026-05-30 17:59 52
        ToggleExif,
83f0e0bc Poul Sander 2026-05-30 17:59 53
        EditCaption,
83f0e0bc Poul Sander 2026-05-30 17:59 54
        ToggleFullscreen,
83f0e0bc Poul Sander 2026-05-30 17:59 55
        ActivateEntry,
bf525669 Poul Sander 2026-05-30 23:18 56
        PrevFolder,
bf525669 Poul Sander 2026-05-30 23:18 57
        NextFolder,
a686d839 Poul Sander 2026-06-06 22:34 58
        MoveToTrash,
83f0e0bc Poul Sander 2026-05-30 17:59 59
        ActionCount
83f0e0bc Poul Sander 2026-05-30 17:59 60
    };
83f0e0bc Poul Sander 2026-05-30 17:59 61
83f0e0bc Poul Sander 2026-05-30 17:59 62
    enum Category {
83f0e0bc Poul Sander 2026-05-30 17:59 63
        CatBrowser,
83f0e0bc Poul Sander 2026-05-30 17:59 64
        CatImageViewer,
83f0e0bc Poul Sander 2026-05-30 17:59 65
        CatNotConfigurable
83f0e0bc Poul Sander 2026-05-30 17:59 66
    };
83f0e0bc Poul Sander 2026-05-30 17:59 67
83f0e0bc Poul Sander 2026-05-30 17:59 68
    static ShortcutManager &instance();
83f0e0bc Poul Sander 2026-05-30 17:59 69
83f0e0bc Poul Sander 2026-05-30 17:59 70
    QKeySequence shortcut(Action action) const;
83f0e0bc Poul Sander 2026-05-30 17:59 71
    QString displayKey(Action action) const;
83f0e0bc Poul Sander 2026-05-30 17:59 72
    QString description(Action action) const;
83f0e0bc Poul Sander 2026-05-30 17:59 73
83f0e0bc Poul Sander 2026-05-30 17:59 74
    void setShortcut(Action action, const QKeySequence &seq);
83f0e0bc Poul Sander 2026-05-30 17:59 75
    void resetToDefaults();
83f0e0bc Poul Sander 2026-05-30 17:59 76
83f0e0bc Poul Sander 2026-05-30 17:59 77
    void load(QSettings &settings);
83f0e0bc Poul Sander 2026-05-30 17:59 78
    void save(QSettings &settings) const;
83f0e0bc Poul Sander 2026-05-30 17:59 79
83f0e0bc Poul Sander 2026-05-30 17:59 80
    static QKeySequence defaultShortcut(Action action);
83f0e0bc Poul Sander 2026-05-30 17:59 81
    static QString actionName(Action action);
83f0e0bc Poul Sander 2026-05-30 17:59 82
    static QString actionDescription(Action action);
83f0e0bc Poul Sander 2026-05-30 17:59 83
    static Category actionCategory(Action action);
83f0e0bc Poul Sander 2026-05-30 17:59 84
83f0e0bc Poul Sander 2026-05-30 17:59 85
    /// Returns true if the key event matches the configured shortcut for the action.
83f0e0bc Poul Sander 2026-05-30 17:59 86
    bool matches(const QKeyEvent *event, Action action) const;
83f0e0bc Poul Sander 2026-05-30 17:59 87
83f0e0bc Poul Sander 2026-05-30 17:59 88
private:
83f0e0bc Poul Sander 2026-05-30 17:59 89
    ShortcutManager();
83f0e0bc Poul Sander 2026-05-30 17:59 90
83f0e0bc Poul Sander 2026-05-30 17:59 91
    struct Binding {
83f0e0bc Poul Sander 2026-05-30 17:59 92
        QKeySequence key;
83f0e0bc Poul Sander 2026-05-30 17:59 93
    };
83f0e0bc Poul Sander 2026-05-30 17:59 94
83f0e0bc Poul Sander 2026-05-30 17:59 95
    std::array<Binding, ActionCount> m_bindings;
83f0e0bc Poul Sander 2026-05-30 17:59 96
};
1970-01-01 00:00 97