aboutsummaryrefslogtreecommitdiff
path: root/qdeduper/preferencedialog.hpp
blob: 14cf8754ae7ae6627214c6a84ce439fefae2e20b (plain) (blame)
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
81
//Chris Xiong 2022
//License: MPL-2.0
#ifndef PREFERENCEDIALOG_HPP
#define PREFERENCEDIALOG_HPP

#include <vector>
#include <map>
#include <string>

#include <QPushButton>
#include <QDialog>
#include <QGridLayout>
#include <QStyledItemDelegate>

#include "settings.hpp"

class QTabWidget;
class QGridLayout;
class QDialogButtonBox;
class QTableView;
class QListView;
class QStandardItemModel;
class QSortFilterProxyModel;

class ModifierEdit : public QPushButton
{
    Q_OBJECT
public:
    ModifierEdit(QWidget *par = nullptr);
    Qt::Modifier get_modifier();
    void set_modifier(Qt::Modifier mod);
    bool event(QEvent *e) override;
protected:
    void keyPressEvent(QKeyEvent *e) override;
private:
    Qt::Modifier mod;
};

class PreferenceDialog : public QDialog
{
    Q_OBJECT
public:
    PreferenceDialog(SettingsRegistry *sr, QWidget *parent = nullptr);
    void setup_widgets();
    void set_hkactions(int tab, const std::vector<std::string> &actlist, const std::map<std::string, QAction*> &actmap);
    void set_toolbaractions(int tab, const std::map<std::string, QAction*> &actmap);
    void load_widget_status();
    void save_widget_status();

public Q_SLOTS:
    void open() override;
    void accept() override;
private:
    int verify_shortcuts(QKeySequence *bks);

    SettingsRegistry *sr;
    QTabWidget *tw;
    std::vector<QGridLayout*> tabs;
    QDialogButtonBox *bb;
    QTableView *hktv = nullptr;
    QStandardItemModel *hkim = nullptr;
    QListView *tbaav = nullptr;
    QStandardItemModel *tbaam = nullptr;
    QSortFilterProxyModel *tbapm = nullptr;
    QListView *tbeav = nullptr;
    QStandardItemModel *tbeam = nullptr;
    std::vector<std::string> actlist;
    std::map<std::string, QAction*> actmap;
    std::vector<ModifierEdit*> mes;
};

class ShortcutEditorDelegate : public QStyledItemDelegate
{
    Q_OBJECT
public:
    QWidget* createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
    void setEditorData(QWidget *editor, const QModelIndex &index) const override;
    void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override;
};

#endif