2021-12-26 23:18:28 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2020-2022 Roy Qu (royqh1979@gmail.com)
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2021-10-06 12:19:46 +08:00
|
|
|
#ifndef ENVIRONMENTSHORTCUTWIDGET_H
|
|
|
|
#define ENVIRONMENTSHORTCUTWIDGET_H
|
|
|
|
|
|
|
|
#include <QAbstractTableModel>
|
2023-05-31 08:52:59 +08:00
|
|
|
#include <QSortFilterProxyModel>
|
2022-04-01 21:09:24 +08:00
|
|
|
#include <QStyledItemDelegate>
|
2021-10-06 12:19:46 +08:00
|
|
|
#include <QWidget>
|
|
|
|
#include "settingswidget.h"
|
2021-10-06 23:19:18 +08:00
|
|
|
#include "../shortcutmanager.h"
|
2021-10-06 12:19:46 +08:00
|
|
|
|
|
|
|
namespace Ui {
|
|
|
|
class EnvironmentShortcutWidget;
|
|
|
|
}
|
|
|
|
|
|
|
|
class QMenu;
|
|
|
|
class EnvironmentShortcutModel: public QAbstractTableModel {
|
2021-10-06 23:19:18 +08:00
|
|
|
Q_OBJECT
|
2021-10-06 12:19:46 +08:00
|
|
|
// QAbstractItemModel interface
|
|
|
|
public:
|
|
|
|
explicit EnvironmentShortcutModel(QObject* parent=nullptr);
|
|
|
|
void reload();
|
|
|
|
|
|
|
|
int rowCount(const QModelIndex &parent) const override;
|
|
|
|
int columnCount(const QModelIndex &parent) const override;
|
|
|
|
QVariant data(const QModelIndex &index, int role) const override;
|
|
|
|
bool setData(const QModelIndex &index, const QVariant &value, int role) override;
|
|
|
|
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
|
|
|
|
Qt::ItemFlags flags(const QModelIndex &index) const override;
|
2021-10-06 23:19:18 +08:00
|
|
|
const QList<PEnvironmentShortcut> &shortcuts() const;
|
|
|
|
signals:
|
|
|
|
void shortcutChanged();
|
|
|
|
public slots:
|
|
|
|
void shortcutsUpdated();
|
2021-10-06 12:19:46 +08:00
|
|
|
private:
|
|
|
|
void loadShortCutsOfMenu(const QMenu * menu, QList<QAction*>& globalActions);
|
|
|
|
private:
|
2021-10-06 23:19:18 +08:00
|
|
|
QList<PEnvironmentShortcut> mShortcuts;
|
2022-04-01 21:09:24 +08:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
class EnvironmentShortcutDelegate: public QStyledItemDelegate {
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
explicit EnvironmentShortcutDelegate(QObject *parent = nullptr);
|
|
|
|
|
|
|
|
public:
|
|
|
|
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
|
|
|
|
protected slots:
|
|
|
|
void onEditingFinished(QWidget* editor);
|
2021-10-06 12:19:46 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class EnvironmentShortcutWidget : public SettingsWidget
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit EnvironmentShortcutWidget(const QString& name, const QString& group, QWidget *parent = nullptr);
|
|
|
|
~EnvironmentShortcutWidget();
|
|
|
|
|
|
|
|
private:
|
|
|
|
Ui::EnvironmentShortcutWidget *ui;
|
|
|
|
|
|
|
|
// SettingsWidget interface
|
|
|
|
protected:
|
|
|
|
void doLoad() override;
|
|
|
|
void doSave() override;
|
2023-05-31 08:52:59 +08:00
|
|
|
private slots:
|
|
|
|
void on_txtKeyword_textChanged(const QString &arg1);
|
|
|
|
|
2021-10-06 12:19:46 +08:00
|
|
|
private:
|
|
|
|
EnvironmentShortcutModel mModel;
|
2023-05-31 08:52:59 +08:00
|
|
|
QSortFilterProxyModel* mFilterProxy;
|
2022-04-01 21:09:24 +08:00
|
|
|
EnvironmentShortcutDelegate* mDelegate;
|
2021-10-06 12:19:46 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // ENVIRONMENTSHORTCUTWIDGET_H
|