mirror of
https://github.com/huderlem/porymap.git
synced 2026-10-02 04:46:42 -05:00
Add ShortcutsEditor to customize shortcuts for QAction's
This commit is contained in:
@@ -5,6 +5,8 @@
|
||||
#include <QObject>
|
||||
#include <QByteArrayList>
|
||||
#include <QSize>
|
||||
#include <QKeySequence>
|
||||
#include <QMultiMap>
|
||||
|
||||
enum MapSortOrder {
|
||||
Group = 0,
|
||||
@@ -192,4 +194,37 @@ private:
|
||||
|
||||
extern ProjectConfig projectConfig;
|
||||
|
||||
class QAction;
|
||||
|
||||
class ShortcutsConfig : public KeyValueConfigBase
|
||||
{
|
||||
public:
|
||||
ShortcutsConfig() :
|
||||
shortcuts(QMultiMap<QString, QKeySequence>()),
|
||||
defaultShortcuts(QMultiMap<QString, QKeySequence>())
|
||||
{
|
||||
reset();
|
||||
}
|
||||
virtual void reset() override { shortcuts.clear(); }
|
||||
void setDefaultShortcuts(const QList<QAction *> &actions);
|
||||
QList<QKeySequence> getDefaultShortcuts(QAction *action) const;
|
||||
void setUserShortcuts(const QList<QAction *> &actions);
|
||||
QList<QKeySequence> getUserShortcuts(QAction *action) const;
|
||||
|
||||
protected:
|
||||
virtual QString getConfigFilepath() override;
|
||||
virtual void parseConfigKeyValue(QString key, QString value) override;
|
||||
virtual QMap<QString, QString> getKeyValueMap() override;
|
||||
virtual void onNewConfigFileCreated() override {};
|
||||
virtual void setUnreadKeys() override {};
|
||||
|
||||
private:
|
||||
QMultiMap<QString, QKeySequence> shortcuts;
|
||||
QMultiMap<QString, QKeySequence> defaultShortcuts;
|
||||
|
||||
QString getKey(QObject *object) const;
|
||||
};
|
||||
|
||||
extern ShortcutsConfig shortcutsConfig;
|
||||
|
||||
#endif // CONFIG_H
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "filterchildrenproxymodel.h"
|
||||
#include "newmappopup.h"
|
||||
#include "newtilesetdialog.h"
|
||||
#include "shortcutseditor.h"
|
||||
|
||||
namespace Ui {
|
||||
class MainWindow;
|
||||
@@ -147,6 +148,7 @@ private slots:
|
||||
void on_actionUse_Encounter_Json_triggered(bool checked);
|
||||
void on_actionMonitor_Project_Files_triggered(bool checked);
|
||||
void on_actionUse_Poryscript_triggered(bool checked);
|
||||
void on_actionEdit_Shortcuts_triggered();
|
||||
|
||||
void on_mainTabBar_tabBarClicked(int index);
|
||||
|
||||
@@ -231,6 +233,7 @@ private:
|
||||
Ui::MainWindow *ui;
|
||||
TilesetEditor *tilesetEditor = nullptr;
|
||||
RegionMapEditor *regionMapEditor = nullptr;
|
||||
ShortcutsEditor *shortcutsEditor = nullptr;
|
||||
MapImageExporter *mapImageExporter = nullptr;
|
||||
FilterChildrenProxyModel *mapListProxyModel;
|
||||
NewMapPopup *newmapprompt = nullptr;
|
||||
@@ -294,6 +297,7 @@ private:
|
||||
void initEditor();
|
||||
void initMiscHeapObjects();
|
||||
void initMapSortOrder();
|
||||
void initUserShortcuts();
|
||||
void setProjectSpecificUIVisibility();
|
||||
void loadUserSettings();
|
||||
void applyMapListFilter(QString filterText);
|
||||
|
||||
80
include/ui/shortcutseditor.h
Normal file
80
include/ui/shortcutseditor.h
Normal file
@@ -0,0 +1,80 @@
|
||||
#ifndef SHORTCUTSEDITOR_H
|
||||
#define SHORTCUTSEDITOR_H
|
||||
|
||||
#include <QDialog>
|
||||
#include <QMap>
|
||||
|
||||
class QAbstractButton;
|
||||
class QAction;
|
||||
class QKeySequenceEdit;
|
||||
class ActionShortcutEdit;
|
||||
|
||||
|
||||
namespace Ui {
|
||||
class ShortcutsEditor;
|
||||
}
|
||||
|
||||
class ShortcutsEditor : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ShortcutsEditor(QWidget *parent = nullptr);
|
||||
~ShortcutsEditor();
|
||||
|
||||
private:
|
||||
Ui::ShortcutsEditor *ui;
|
||||
QMap<QString, QAction *> actions;
|
||||
QWidget *ase_container;
|
||||
|
||||
void populateShortcuts();
|
||||
void saveShortcuts();
|
||||
void resetShortcuts();
|
||||
void promptUser(ActionShortcutEdit *current, ActionShortcutEdit *sender);
|
||||
|
||||
private slots:
|
||||
void checkForDuplicates();
|
||||
void dialogButtonClicked(QAbstractButton *button);
|
||||
};
|
||||
|
||||
|
||||
// A collection of QKeySequenceEdit's in a QHBoxLayout with a cooresponding QAction
|
||||
class ActionShortcutEdit : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ActionShortcutEdit(QWidget *parent = nullptr, QAction *action = nullptr, int count = 1);
|
||||
|
||||
bool eventFilter(QObject *watched, QEvent *event) override;
|
||||
|
||||
int count() const { return kse_children.count(); }
|
||||
void setCount(int count);
|
||||
QList<QKeySequence> shortcuts() const;
|
||||
void setShortcuts(const QList<QKeySequence> &keySequences);
|
||||
void applyShortcuts();
|
||||
bool removeOne(const QKeySequence &keySequence);
|
||||
bool contains(const QKeySequence &keySequence);
|
||||
bool contains(QKeySequenceEdit *keySequenceEdit);
|
||||
QKeySequence last() const { return shortcuts().last(); }
|
||||
|
||||
QAction *action;
|
||||
|
||||
public slots:
|
||||
void clear();
|
||||
|
||||
signals:
|
||||
void editingFinished();
|
||||
|
||||
private:
|
||||
QVector<QKeySequenceEdit *> kse_children;
|
||||
QList<QKeySequence> ks_list;
|
||||
|
||||
void updateShortcuts() { setShortcuts(shortcuts()); }
|
||||
void focusLast();
|
||||
|
||||
private slots:
|
||||
void onEditingFinished();
|
||||
};
|
||||
|
||||
#endif // SHORTCUTSEDITOR_H
|
||||
Reference in New Issue
Block a user