Add extra shortcuts to main window and sub-editors
This commit is contained in:
parent
f044672d2e
commit
bb6786f24e
7 changed files with 69 additions and 44 deletions
|
@ -207,16 +207,14 @@ public:
|
|||
|
||||
virtual void reset() override { user_shortcuts.clear(); }
|
||||
|
||||
// Call this before applying user shortcuts so that the user can restore defaults.
|
||||
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;
|
||||
|
@ -243,7 +241,6 @@ private:
|
|||
const QList<QKeySequence> &keySequences);
|
||||
};
|
||||
|
||||
// Call setDefaultShortcuts() prior to applying user shortcuts.
|
||||
extern ShortcutsConfig shortcutsConfig;
|
||||
|
||||
#endif // CONFIG_H
|
||||
|
|
|
@ -108,6 +108,7 @@ private:
|
|||
void initSelectedTileItem();
|
||||
void initMetatileLayersItem();
|
||||
void initShortcuts();
|
||||
void initExtraShortcuts();
|
||||
void restoreWindowState();
|
||||
void initMetatileHistory();
|
||||
void setTilesets(QString primaryTilesetLabel, QString secondaryTilesetLabel);
|
||||
|
|
|
@ -730,11 +730,10 @@ QMap<QString, QString> ShortcutsConfig::getKeyValueMap() {
|
|||
QMap<QString, QString> map;
|
||||
for (auto cfg_key : user_shortcuts.uniqueKeys()) {
|
||||
auto keySequences = user_shortcuts.values(cfg_key);
|
||||
QStringList values;
|
||||
QStringList keySequenceStrings;
|
||||
for (auto keySequence : keySequences)
|
||||
values.append(keySequence.toString());
|
||||
QString value = values.join(' ');
|
||||
map.insert(cfg_key, value);
|
||||
keySequenceStrings.append(keySequence.toString());
|
||||
map.insert(cfg_key, keySequenceStrings.join(' '));
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
@ -744,12 +743,6 @@ void ShortcutsConfig::setDefaultShortcuts(const QObjectList &objects) {
|
|||
save();
|
||||
}
|
||||
|
||||
void ShortcutsConfig::setDefaultShortcuts(const QMultiMap<const QObject *, QKeySequence> &objects_keySequences) {
|
||||
for (auto *object : objects_keySequences.uniqueKeys())
|
||||
storeShortcuts(StoreType::Default, cfgKey(object), objects_keySequences.values(object));
|
||||
save();
|
||||
}
|
||||
|
||||
QList<QKeySequence> ShortcutsConfig::defaultShortcuts(const QObject *object) const {
|
||||
return default_shortcuts.values(cfgKey(object));
|
||||
}
|
||||
|
@ -761,7 +754,8 @@ void ShortcutsConfig::setUserShortcuts(const QObjectList &objects) {
|
|||
|
||||
void ShortcutsConfig::setUserShortcuts(const QMultiMap<const QObject *, QKeySequence> &objects_keySequences) {
|
||||
for (auto *object : objects_keySequences.uniqueKeys())
|
||||
storeShortcuts(StoreType::User, cfgKey(object), objects_keySequences.values(object));
|
||||
if (!object->objectName().isEmpty() && !object->objectName().startsWith("_q_"))
|
||||
storeShortcuts(StoreType::User, cfgKey(object), objects_keySequences.values(object));
|
||||
save();
|
||||
}
|
||||
|
||||
|
@ -771,7 +765,7 @@ QList<QKeySequence> ShortcutsConfig::userShortcuts(const QObject *object) const
|
|||
|
||||
void ShortcutsConfig::storeShortcutsFromList(StoreType storeType, const QObjectList &objects) {
|
||||
for (const auto *object : objects)
|
||||
if (objectNameIsValid(object))
|
||||
if (!object->objectName().isEmpty() && !object->objectName().startsWith("_q_"))
|
||||
storeShortcuts(storeType, cfgKey(object), currentShortcuts(object));
|
||||
}
|
||||
|
||||
|
@ -802,11 +796,6 @@ void ShortcutsConfig::storeShortcuts(
|
|||
}
|
||||
}
|
||||
|
||||
bool ShortcutsConfig::objectNameIsValid(const QObject *object) {
|
||||
// Qt internal action names start with "_q_" so we filter those out.
|
||||
return !object->objectName().isEmpty() && !object->objectName().startsWith("_q_");
|
||||
}
|
||||
|
||||
/* Creates a config key from the object's name prepended with the parent
|
||||
* window's object name, and converts camelCase to snake_case. */
|
||||
QString ShortcutsConfig::cfgKey(const QObject *object) const {
|
||||
|
@ -830,9 +819,6 @@ QList<QKeySequence> ShortcutsConfig::currentShortcuts(const QObject *object) con
|
|||
if (object->inherits("QAction")) {
|
||||
const auto *action = qobject_cast<const QAction *>(object);
|
||||
return action->shortcuts();
|
||||
} else if (object->inherits("QAbstractButton")) {
|
||||
const auto *button = qobject_cast<const QAbstractButton *>(object);
|
||||
return { button->shortcut() };
|
||||
} else if (object->inherits("Shortcut")) {
|
||||
const auto *shortcut = qobject_cast<const Shortcut *>(object);
|
||||
return shortcut->keys();
|
||||
|
|
|
@ -106,6 +106,8 @@ void MainWindow::initShortcuts() {
|
|||
}
|
||||
|
||||
void MainWindow::initExtraShortcuts() {
|
||||
ui->actionZoom_In->setShortcuts({ui->actionZoom_In->shortcut(), QKeySequence("Ctrl+=")});
|
||||
|
||||
auto *shortcutReset_Zoom = new Shortcut(QKeySequence("Ctrl+0"), this, SLOT(resetMapViewScale()));
|
||||
shortcutReset_Zoom->setObjectName("shortcutZoom_Reset");
|
||||
shortcutReset_Zoom->setWhatsThis("Zoom Reset");
|
||||
|
@ -123,16 +125,35 @@ void MainWindow::initExtraShortcuts() {
|
|||
shortcutDelete_Object->setObjectName("shortcutDelete_Object");
|
||||
shortcutDelete_Object->setWhatsThis("Delete Selected Event(s)");
|
||||
|
||||
ui->actionZoom_In->setShortcuts({ui->actionZoom_In->shortcut(), QKeySequence("Ctrl+=")});
|
||||
auto *shortcutToggle_Border = new Shortcut(QKeySequence(), ui->checkBox_ToggleBorder, SLOT(toggle()));
|
||||
shortcutToggle_Border->setObjectName("shortcutToggle_Border");
|
||||
shortcutToggle_Border->setWhatsThis("Toggle Border");
|
||||
|
||||
auto *shortcutToggle_Smart_Paths = new Shortcut(QKeySequence(), ui->checkBox_smartPaths, SLOT(toggle()));
|
||||
shortcutToggle_Smart_Paths->setObjectName("shortcutToggle_Smart_Paths");
|
||||
shortcutToggle_Smart_Paths->setWhatsThis("Toggle Smart Paths");
|
||||
|
||||
auto *shortcutExpand_All = new Shortcut(QKeySequence(), this, SLOT(on_toolButton_ExpandAll_clicked()));
|
||||
shortcutExpand_All->setObjectName("shortcutExpand_All");
|
||||
shortcutExpand_All->setWhatsThis("Map List: Expand all folders");
|
||||
|
||||
auto *shortcutCollapse_All = new Shortcut(QKeySequence(), this, SLOT(on_toolButton_CollapseAll_clicked()));
|
||||
shortcutCollapse_All->setObjectName("shortcutCollapse_All");
|
||||
shortcutCollapse_All->setWhatsThis("Map List: Collapse all folders");
|
||||
|
||||
auto *shortcutNew_Event = new Shortcut(QKeySequence(), this, SLOT(on_toolButton_Open_Scripts_clicked()));
|
||||
shortcutNew_Event->setObjectName("shortcut_Open_Scripts");
|
||||
shortcutNew_Event->setWhatsThis("Open Map Scripts");
|
||||
}
|
||||
|
||||
QObjectList MainWindow::shortcutableObjects() const {
|
||||
QObjectList shortcutable_objects;
|
||||
|
||||
for (auto *action : findChildren<QAction *>())
|
||||
if (ShortcutsConfig::objectNameIsValid(action))
|
||||
if (!action->objectName().isEmpty())
|
||||
shortcutable_objects.append(qobject_cast<QObject *>(action));
|
||||
for (auto *shortcut : findChildren<Shortcut *>())
|
||||
if (ShortcutsConfig::objectNameIsValid(shortcut))
|
||||
if (!shortcut->objectName().isEmpty())
|
||||
shortcutable_objects.append(qobject_cast<QObject *>(shortcut));
|
||||
|
||||
return shortcutable_objects;
|
||||
|
@ -140,10 +161,10 @@ QObjectList MainWindow::shortcutableObjects() const {
|
|||
|
||||
void MainWindow::applyUserShortcuts() {
|
||||
for (auto *action : findChildren<QAction *>())
|
||||
if (ShortcutsConfig::objectNameIsValid(action))
|
||||
if (!action->objectName().isEmpty())
|
||||
action->setShortcuts(shortcutsConfig.userShortcuts(action));
|
||||
for (auto *shortcut : findChildren<Shortcut *>())
|
||||
if (ShortcutsConfig::objectNameIsValid(shortcut))
|
||||
if (!shortcut->objectName().isEmpty())
|
||||
shortcut->setKeys(shortcutsConfig.userShortcuts(shortcut));
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ RegionMapEditor::RegionMapEditor(QWidget *parent, Project *project_) :
|
|||
this->project = project_;
|
||||
this->region_map = new RegionMap;
|
||||
this->ui->action_RegionMap_Resize->setVisible(false);
|
||||
this->initShortcuts();
|
||||
this->restoreWindowState();
|
||||
}
|
||||
|
||||
|
@ -94,6 +95,11 @@ bool RegionMapEditor::loadCityMaps() {
|
|||
}
|
||||
|
||||
void RegionMapEditor::initShortcuts() {
|
||||
auto *shortcut_RM_Options_delete = new Shortcut(
|
||||
{QKeySequence("Del"), QKeySequence("Backspace")}, this, SLOT(on_pushButton_RM_Options_delete_clicked()));
|
||||
shortcut_RM_Options_delete->setObjectName("shortcut_RM_Options_delete");
|
||||
shortcut_RM_Options_delete->setWhatsThis("Map Layout: Delete Square");
|
||||
|
||||
shortcutsConfig.load();
|
||||
shortcutsConfig.setDefaultShortcuts(shortcutableObjects());
|
||||
applyUserShortcuts();
|
||||
|
@ -101,11 +107,12 @@ void RegionMapEditor::initShortcuts() {
|
|||
|
||||
QObjectList RegionMapEditor::shortcutableObjects() const {
|
||||
QObjectList shortcutable_objects;
|
||||
|
||||
for (auto *action : findChildren<QAction *>())
|
||||
if (ShortcutsConfig::objectNameIsValid(action))
|
||||
if (!action->objectName().isEmpty())
|
||||
shortcutable_objects.append(qobject_cast<QObject *>(action));
|
||||
for (auto *shortcut : findChildren<Shortcut *>())
|
||||
if (ShortcutsConfig::objectNameIsValid(shortcut))
|
||||
if (!shortcut->objectName().isEmpty())
|
||||
shortcutable_objects.append(qobject_cast<QObject *>(shortcut));
|
||||
|
||||
return shortcutable_objects;
|
||||
|
@ -113,10 +120,10 @@ QObjectList RegionMapEditor::shortcutableObjects() const {
|
|||
|
||||
void RegionMapEditor::applyUserShortcuts() {
|
||||
for (auto *action : findChildren<QAction *>())
|
||||
if (ShortcutsConfig::objectNameIsValid(action))
|
||||
if (!action->objectName().isEmpty())
|
||||
action->setShortcuts(shortcutsConfig.userShortcuts(action));
|
||||
for (auto *shortcut : findChildren<Shortcut *>())
|
||||
if (ShortcutsConfig::objectNameIsValid(shortcut))
|
||||
if (!shortcut->objectName().isEmpty())
|
||||
shortcut->setKeys(shortcutsConfig.userShortcuts(shortcut));
|
||||
}
|
||||
|
||||
|
|
|
@ -21,8 +21,8 @@ ShortcutsEditor::ShortcutsEditor(QWidget *parent) :
|
|||
ui->setupUi(this);
|
||||
setAttribute(Qt::WA_DeleteOnClose);
|
||||
main_container = ui->scrollAreaWidgetContents_Shortcuts;
|
||||
auto *formLayout = new QVBoxLayout(main_container);
|
||||
formLayout->setSpacing(12);
|
||||
auto *main_layout = new QVBoxLayout(main_container);
|
||||
main_layout->setSpacing(12);
|
||||
connect(ui->buttonBox, &QDialogButtonBox::clicked,
|
||||
this, &ShortcutsEditor::dialogButtonClicked);
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ void ShortcutsEditor::resetShortcuts() {
|
|||
void ShortcutsEditor::parseObjectList(const QObjectList &objectList) {
|
||||
for (auto *object : objectList) {
|
||||
const auto label = getLabel(object);
|
||||
if (!label.isEmpty() && ShortcutsConfig::objectNameIsValid(object))
|
||||
if (!label.isEmpty() && !object->objectName().isEmpty() && !object->objectName().startsWith("_q_"))
|
||||
labels_objects.insert(label, object);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -211,20 +211,33 @@ void TilesetEditor::initSelectedTileItem() {
|
|||
}
|
||||
|
||||
void TilesetEditor::initShortcuts() {
|
||||
ui->actionRedo->setShortcuts({ui->actionRedo->shortcut(), QKeySequence("Ctrl+Shift+Z")});
|
||||
initExtraShortcuts();
|
||||
|
||||
shortcutsConfig.load();
|
||||
shortcutsConfig.setDefaultShortcuts(shortcutableObjects());
|
||||
applyUserShortcuts();
|
||||
}
|
||||
|
||||
void TilesetEditor::initExtraShortcuts() {
|
||||
ui->actionRedo->setShortcuts({ui->actionRedo->shortcut(), QKeySequence("Ctrl+Shift+Z")});
|
||||
|
||||
auto *shortcut_xFlip = new Shortcut(QKeySequence(), ui->checkBox_xFlip, SLOT(toggle()));
|
||||
shortcut_xFlip->setObjectName("shortcut_xFlip");
|
||||
shortcut_xFlip->setWhatsThis("X Flip");
|
||||
|
||||
auto *shortcut_yFlip = new Shortcut(QKeySequence(), ui->checkBox_yFlip, SLOT(toggle()));
|
||||
shortcut_yFlip->setObjectName("shortcut_yFlip");
|
||||
shortcut_yFlip->setWhatsThis("Y Flip");
|
||||
}
|
||||
|
||||
QObjectList TilesetEditor::shortcutableObjects() const {
|
||||
QObjectList shortcutable_objects;
|
||||
|
||||
for (auto *action : findChildren<QAction *>())
|
||||
if (ShortcutsConfig::objectNameIsValid(action))
|
||||
if (!action->objectName().isEmpty())
|
||||
shortcutable_objects.append(qobject_cast<QObject *>(action));
|
||||
for (auto *shortcut : findChildren<Shortcut *>())
|
||||
if (ShortcutsConfig::objectNameIsValid(shortcut))
|
||||
if (!shortcut->objectName().isEmpty())
|
||||
shortcutable_objects.append(qobject_cast<QObject *>(shortcut));
|
||||
|
||||
return shortcutable_objects;
|
||||
|
@ -232,10 +245,10 @@ QObjectList TilesetEditor::shortcutableObjects() const {
|
|||
|
||||
void TilesetEditor::applyUserShortcuts() {
|
||||
for (auto *action : findChildren<QAction *>())
|
||||
if (ShortcutsConfig::objectNameIsValid(action))
|
||||
if (!action->objectName().isEmpty())
|
||||
action->setShortcuts(shortcutsConfig.userShortcuts(action));
|
||||
for (auto *shortcut : findChildren<Shortcut *>())
|
||||
if (ShortcutsConfig::objectNameIsValid(shortcut))
|
||||
if (!shortcut->objectName().isEmpty())
|
||||
shortcut->setKeys(shortcutsConfig.userShortcuts(shortcut));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue