mirror of
https://github.com/huderlem/porymap.git
synced 2026-08-14 21:07:44 -05:00
Redesign ShortcutsEditor to take an obj list and refactor config to reflect that
This commit is contained in:
@@ -201,53 +201,49 @@ class ShortcutsConfig : public KeyValueConfigBase
|
||||
{
|
||||
public:
|
||||
ShortcutsConfig() :
|
||||
userShortcuts(QMultiMap<QString, QKeySequence>()),
|
||||
defaultShortcuts(QMultiMap<QString, QKeySequence>())
|
||||
{ }
|
||||
|
||||
virtual void reset() override { userShortcuts.clear(); }
|
||||
user_shortcuts({ }),
|
||||
default_shortcuts({ })
|
||||
{ }
|
||||
|
||||
void setDefaultShortcuts(const QList<QAction *> &actions);
|
||||
void setDefaultShortcuts(const QList<Shortcut *> &shortcuts);
|
||||
void setDefaultShortcuts(const QList<QAction *> &actions, const QList<Shortcut *> &shortcuts);
|
||||
QList<QKeySequence> getDefaultShortcuts(QAction *action) const;
|
||||
QList<QKeySequence> getDefaultShortcuts(Shortcut *shortcut) const;
|
||||
virtual void reset() override { user_shortcuts.clear(); }
|
||||
|
||||
void setUserShortcuts(const QList<QAction *> &actions);
|
||||
void setUserShortcuts(const QList<Shortcut *> &shortcuts);
|
||||
void setUserShortcuts(const QList<QAction *> &actions, const QList<Shortcut *> &shortcuts);
|
||||
QList<QKeySequence> getUserShortcuts(QAction *action) const;
|
||||
QList<QKeySequence> getUserShortcuts(Shortcut *shortcut) const;
|
||||
void setDefaultShortcuts(const QObjectList &objects);
|
||||
void setDefaultShortcuts(const QMultiMap<const QObject *, QKeySequence> &objects_keySequences);
|
||||
QList<QKeySequence> defaultShortcuts(const QObject *object) const;
|
||||
|
||||
void setUserShortcuts(const QObjectList &objects);
|
||||
void setUserShortcuts(const QMultiMap<const QObject *, QKeySequence> &objects_keySequences);
|
||||
QList<QKeySequence> userShortcuts(const QObject *object) const;
|
||||
|
||||
static bool objectNameIsValid(const QObject *object);
|
||||
|
||||
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 {};
|
||||
virtual void onNewConfigFileCreated() override { };
|
||||
virtual void setUnreadKeys() override { };
|
||||
|
||||
private:
|
||||
QMultiMap<QString, QKeySequence> userShortcuts;
|
||||
QMultiMap<QString, QKeySequence> defaultShortcuts;
|
||||
QMultiMap<QString, QKeySequence> user_shortcuts;
|
||||
QMultiMap<QString, QKeySequence> default_shortcuts;
|
||||
|
||||
enum StoreType {
|
||||
User,
|
||||
Default
|
||||
};
|
||||
|
||||
QString cfgKey(const QObject *object) const;
|
||||
QList<QKeySequence> currentShortcuts(const QObject *object) const;
|
||||
|
||||
void storeShortcutsFromList(StoreType storeType, const QObjectList &objects);
|
||||
void storeShortcuts(
|
||||
StoreType storeType,
|
||||
const QList<QAction *> &actions);
|
||||
void storeShortcuts(
|
||||
StoreType storeType,
|
||||
const QList<Shortcut *> &shortcuts);
|
||||
void storeShortcut(
|
||||
StoreType storeType,
|
||||
const QString &cfgKey,
|
||||
const QList<QKeySequence> &keySequences);
|
||||
QString cfgKey(QObject *object) const;
|
||||
};
|
||||
|
||||
// Call setDefaultShortcuts() prior to applying user shortcuts.
|
||||
extern ShortcutsConfig shortcutsConfig;
|
||||
|
||||
#endif // CONFIG_H
|
||||
|
||||
@@ -129,6 +129,7 @@ private slots:
|
||||
void openNewMapPopupWindow(int, QVariant);
|
||||
void onNewMapCreated();
|
||||
void onMapCacheCleared();
|
||||
void applyUserShortcuts();
|
||||
|
||||
void on_action_NewMap_triggered();
|
||||
void on_actionNew_Tileset_triggered();
|
||||
@@ -292,12 +293,12 @@ private:
|
||||
|
||||
void initWindow();
|
||||
void initCustomUI();
|
||||
void initExtraShortcuts();
|
||||
void initExtraSignals();
|
||||
void initEditor();
|
||||
void initMiscHeapObjects();
|
||||
void initMapSortOrder();
|
||||
void initUserShortcuts();
|
||||
void initShortcuts();
|
||||
void initExtraShortcuts();
|
||||
void setProjectSpecificUIVisibility();
|
||||
void loadUserSettings();
|
||||
void applyMapListFilter(QString filterText);
|
||||
@@ -312,6 +313,8 @@ private:
|
||||
bool isProjectOpen();
|
||||
void showExportMapImageWindow(bool stitchMode);
|
||||
void redrawMetatileSelection();
|
||||
|
||||
QObjectList shortcutableObjects() const;
|
||||
};
|
||||
|
||||
enum MapListUserRoles {
|
||||
|
||||
@@ -6,11 +6,17 @@
|
||||
#include <QShortcut>
|
||||
|
||||
|
||||
// Alternative to QShortcut that adds support for multiple QKeySequences.
|
||||
// Alternative to QShortcut that adds support for multiple key sequences.
|
||||
// Use this to allow the shortcut to be editable in ShortcutsEditor.
|
||||
class Shortcut : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_DECLARE_PRIVATE(QShortcut)
|
||||
Q_PROPERTY(QKeySequence key READ key WRITE setKey)
|
||||
Q_PROPERTY(QString whatsThis READ whatsThis WRITE setWhatsThis)
|
||||
Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled)
|
||||
Q_PROPERTY(bool autoRepeat READ autoRepeat WRITE setAutoRepeat)
|
||||
Q_PROPERTY(Qt::ShortcutContext context READ context WRITE setContext)
|
||||
|
||||
public:
|
||||
explicit Shortcut(QWidget *parent);
|
||||
|
||||
@@ -1,80 +1,57 @@
|
||||
#ifndef SHORTCUTSEDITOR_H
|
||||
#define SHORTCUTSEDITOR_H
|
||||
|
||||
#include "shortcut.h"
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QDialog>
|
||||
#include <QMap>
|
||||
#include <QHash>
|
||||
#include <QAction>
|
||||
|
||||
class QFormLayout;
|
||||
class MultiKeyEdit;
|
||||
class QAbstractButton;
|
||||
class QAction;
|
||||
class QKeySequenceEdit;
|
||||
class ActionShortcutEdit;
|
||||
|
||||
|
||||
namespace Ui {
|
||||
class ShortcutsEditor;
|
||||
}
|
||||
|
||||
class ShortcutsEditor : public QDialog
|
||||
class ShortcutsEditor : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ShortcutsEditor(QWidget *parent = nullptr);
|
||||
explicit ShortcutsEditor(const QObjectList &objectList, QWidget *parent = nullptr);
|
||||
~ShortcutsEditor();
|
||||
|
||||
signals:
|
||||
void shortcutsSaved();
|
||||
|
||||
private:
|
||||
Ui::ShortcutsEditor *ui;
|
||||
QMap<QString, QAction *> actions;
|
||||
QWidget *ase_container;
|
||||
QWidget *main_container;
|
||||
QMultiMap<QString, const QObject *> labels_objects;
|
||||
QHash<QString, QFormLayout *> contexts_layouts;
|
||||
QHash<MultiKeyEdit *, const QObject *> multiKeyEdits_objects;
|
||||
|
||||
void populateShortcuts();
|
||||
void parseObjectList(const QObjectList &objectList);
|
||||
QString getLabel(const QObject *object) const;
|
||||
bool stringPropertyIsNotEmpty(const QObject *object, const char *name) const;
|
||||
void populateMainContainer();
|
||||
QString getShortcutContext(const QObject *object) const;
|
||||
void addNewContextGroup(const QString &shortcutContext);
|
||||
void addNewMultiKeyEdit(const QObject *object, const QString &shortcutContext);
|
||||
QList<MultiKeyEdit *> siblings(MultiKeyEdit *multiKeyEdit) const;
|
||||
void promptUserOnDuplicateFound(MultiKeyEdit *current, MultiKeyEdit *sender);
|
||||
void removeKeySequence(const QKeySequence &keySequence, MultiKeyEdit *multiKeyEdit);
|
||||
void saveShortcuts();
|
||||
void resetShortcuts();
|
||||
void promptUser(ActionShortcutEdit *current, ActionShortcutEdit *sender);
|
||||
|
||||
private slots:
|
||||
void checkForDuplicates();
|
||||
void checkForDuplicates(const QKeySequence &keySequence);
|
||||
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