| 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 TOOLSGENERALWIDGET_H |
| 18 | #define TOOLSGENERALWIDGET_H |
| 19 | |
| 20 | #include <QAbstractListModel> |
| 21 | #include <QWidget> |
| 22 | #include "settingswidget.h" |
| 23 | #include "../widgets/macroinfomodel.h" |
| 24 | #include "../toolsmanager.h" |
| 25 | |
| 26 | namespace Ui { |
| 27 | class ToolsGeneralWidget; |
| 28 | } |
| 29 | |
| 30 | class ToolsModel: public QAbstractListModel { |
| 31 | public: |
| 32 | explicit ToolsModel(QObject* parent = nullptr); |
| 33 | |
| 34 | const QList<PToolItem> &tools() const; |
| 35 | void setTools(const QList<PToolItem> &newTools); |
| 36 | void addTool(PToolItem item); |
| 37 | PToolItem getTool(int index); |
| 38 | void removeTool(int index); |
| 39 | |
| 40 | private: |
| 41 | QList<PToolItem> mTools; |
| 42 | |
| 43 | // QAbstractItemModel interface |
| 44 | public: |
| 45 | int rowCount(const QModelIndex &parent) const override; |
| 46 | QVariant data(const QModelIndex &index, int role) const override; |
| 47 | }; |
| 48 | |
| 49 | |
| 50 | class ToolsGeneralWidget : public SettingsWidget |
| 51 | { |
| 52 | Q_OBJECT |
| 53 | public: |
| 54 | enum class EditType { |
| 55 | Add, |
| 56 | Edit, |
| 57 | None |
| 58 | }; |
| 59 | explicit ToolsGeneralWidget(const QString& name, const QString& group, QWidget *parent = nullptr); |
| 60 | ~ToolsGeneralWidget(); |
| 61 | private: |
| 62 | void onToolsCurrentChanged(); |
| 63 | private: |
| 64 | void finishEditing(bool askSave); |
| 65 | void prepareEdit(); |
| 66 | private slots: |
| 67 | void updateDemo(); |
| 68 | void on_btnAdd_clicked(); |
| 69 | |
| 70 | void on_btnEditOk_clicked(); |
| 71 | |
| 72 | void on_btnEditCancel_clicked(); |
| 73 | |
| 74 | void on_btnRemove_clicked(); |
| 75 | |
| 76 | void on_btnInsertMacro_clicked(); |
| 77 | |
| 78 | void on_btnBrowseWorkingDirectory_clicked(); |
| 79 | |
| 80 | void on_btnBrowseProgram_clicked(); |
| 81 | |
| 82 | private: |
| 83 | Ui::ToolsGeneralWidget *ui; |
| 84 | MacroInfoModel mMacroInfoModel; |
| 85 | ToolsModel mToolsModel; |
| 86 | EditType mEditType; |
| 87 | |
| 88 | // SettingsWidget interface |
| 89 | protected: |
| 90 | void doLoad() override; |
| 91 | void doSave() override; |
| 92 | |
| 93 | // SettingsWidget interface |
| 94 | protected: |
| 95 | void updateIcons(const QSize &size) override; |
| 96 | }; |
| 97 | |
| 98 | #endif // TOOLSGENERALWIDGET_H |
| 99 | |