1/*
2 * Copyright (C) 2020-2022 Roy Qu (royqh1979@gmail.com)
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17#ifndef ENVIRONMENTSHORTCUTWIDGET_H
18#define ENVIRONMENTSHORTCUTWIDGET_H
19
20#include <QAbstractTableModel>
21#include <QStyledItemDelegate>
22#include <QWidget>
23#include "settingswidget.h"
24#include "../shortcutmanager.h"
25
26namespace Ui {
27class EnvironmentShortcutWidget;
28}
29
30class QMenu;
31class EnvironmentShortcutModel: public QAbstractTableModel {
32 Q_OBJECT
33 // QAbstractItemModel interface
34public:
35 explicit EnvironmentShortcutModel(QObject* parent=nullptr);
36 void reload();
37
38 int rowCount(const QModelIndex &parent) const override;
39 int columnCount(const QModelIndex &parent) const override;
40 QVariant data(const QModelIndex &index, int role) const override;
41 bool setData(const QModelIndex &index, const QVariant &value, int role) override;
42 QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
43 Qt::ItemFlags flags(const QModelIndex &index) const override;
44 const QList<PEnvironmentShortcut> &shortcuts() const;
45signals:
46 void shortcutChanged();
47public slots:
48 void shortcutsUpdated();
49private:
50 void loadShortCutsOfMenu(const QMenu * menu, QList<QAction*>& globalActions);
51private:
52 QList<PEnvironmentShortcut> mShortcuts;
53
54};
55
56class EnvironmentShortcutDelegate: public QStyledItemDelegate {
57 Q_OBJECT
58public:
59 explicit EnvironmentShortcutDelegate(QObject *parent = nullptr);
60
61public:
62 QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
63protected slots:
64 void onEditingFinished(QWidget* editor);
65};
66
67class EnvironmentShortcutWidget : public SettingsWidget
68{
69 Q_OBJECT
70
71public:
72 explicit EnvironmentShortcutWidget(const QString& name, const QString& group, QWidget *parent = nullptr);
73 ~EnvironmentShortcutWidget();
74
75private:
76 Ui::EnvironmentShortcutWidget *ui;
77
78 // SettingsWidget interface
79protected:
80 void doLoad() override;
81 void doSave() override;
82private:
83 EnvironmentShortcutModel mModel;
84 EnvironmentShortcutDelegate* mDelegate;
85};
86
87#endif // ENVIRONMENTSHORTCUTWIDGET_H
88