| 1 | // SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. |
| 2 | // |
| 3 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 4 | |
| 5 | #ifndef SHORTCUTSETTINGWIDGET_H |
| 6 | #define SHORTCUTSETTINGWIDGET_H |
| 7 | |
| 8 | #include <QWidget> |
| 9 | #include <QAbstractTableModel> |
| 10 | #include <common/widget/pagewidget.h> |
| 11 | |
| 12 | enum ColumnID |
| 13 | { |
| 14 | kID, |
| 15 | kDescriptions, |
| 16 | kShortcut, |
| 17 | _KCount |
| 18 | }; |
| 19 | |
| 20 | class ShortcutTableModelPrivate; |
| 21 | class ShortcutTableModel : public QAbstractTableModel |
| 22 | { |
| 23 | Q_OBJECT |
| 24 | public: |
| 25 | explicit ShortcutTableModel(QObject *parent = nullptr); |
| 26 | virtual ~ShortcutTableModel(); |
| 27 | |
| 28 | int rowCount(const QModelIndex &parent = QModelIndex()) const; |
| 29 | int columnCount(const QModelIndex &parent = QModelIndex()) const; |
| 30 | QVariant data(const QModelIndex &index, int role) const; |
| 31 | QVariant (int section, Qt::Orientation orientation, int role) const; |
| 32 | |
| 33 | void updateShortcut(QString id, QString shortcut); |
| 34 | void resetShortcut(QString id); |
| 35 | void resetAllShortcut(); |
| 36 | void saveShortcut(); |
| 37 | void readShortcut(); |
| 38 | void importExternalJson(const QString &filePath); |
| 39 | void exportExternalJson(const QString &filePath); |
| 40 | bool shortcutRepeat(const QString &text) const; |
| 41 | bool keySequenceIsInvalid(const QKeySequence &sequence) const; |
| 42 | |
| 43 | signals: |
| 44 | |
| 45 | private: |
| 46 | ShortcutTableModelPrivate *d; |
| 47 | }; |
| 48 | |
| 49 | class ShortcutSettingWidgetPrivate; |
| 50 | class ShortcutSettingWidget : public PageWidget |
| 51 | { |
| 52 | Q_OBJECT |
| 53 | public: |
| 54 | explicit ShortcutSettingWidget(QWidget *parent = nullptr); |
| 55 | virtual ~ShortcutSettingWidget(); |
| 56 | void saveConfig(); |
| 57 | void readConfig(); |
| 58 | void checkShortcutValidity(const int row, const QString &shortcut); |
| 59 | bool shortcutIsRepeat(const int row, const QString &text); |
| 60 | |
| 61 | signals: |
| 62 | |
| 63 | public slots: |
| 64 | void onTableViewClicked(const QModelIndex &); |
| 65 | void onShortcutEditTextChanged(const QString &); |
| 66 | void onBtnResetAllClicked(); |
| 67 | void onBtnImportClicked(); |
| 68 | void onBtnExportClicked(); |
| 69 | void onBtnResetClicked(); |
| 70 | void onBtnRecordClicked(); |
| 71 | private: |
| 72 | void setupUi(); |
| 73 | void setSelectedShortcut(); |
| 74 | ShortcutSettingWidgetPrivate *const d; |
| 75 | }; |
| 76 | |
| 77 | #endif // SHORTCUTSETTINGWIDGET_H |
| 78 | |