Skip to content

OpenToonz - An open-source full-featured 2D animation creation software

C

handle legacy

konero583f9d9a6ce4
diff --git a/toonz/sources/toonzqt/menubarcommand.cpp b/toonz/sources/toonzqt/menubarcommand.cpp
index 6afdf725b..f3b737b4d 100644
--- a/toonz/sources/toonzqt/menubarcommand.cpp
+++ b/toonz/sources/toonzqt/menubarcommand.cpp
@@ -1,7 +1,7 @@
#include "toonzqt/menubarcommand.h"
-//#include "menubarcommandids.h"
+// #include "menubarcommandids.h"
#include "toonzqt/dvdialog.h"
#include "toonzqt/gutil.h"
#include "toonz/toonzfolders.h"
@@ -12,6 +12,7 @@
#include <QSettings>
#include <QKeySequence>
#include <QApplication>
+#include <QDebug>
#include <sys/types.h>
@@ -411,45 +412,86 @@ void CommandManager::enlargeIcon(CommandId id, const QSize dstSize) {
}
addSpecifiedSizedImageToIcon(icon, iconSVGName, dstSize);
-
+
action->setIcon(icon);
}
//---------------------------------------------------------
// load user defined shortcuts
+// In menubarcommand.cpp
void CommandManager::loadShortcuts() {
+ // Define reserved navigation shortcuts
+ const std::vector<std::string> reservedKeys = {"Space", "Shift+Space",
+ "Ctrl+Space"};
+
+ // Load shortcuts file
TFilePath fp = ToonzFolder::getMyModuleDir() + TFilePath("shortcuts.ini");
+
if (!TFileStatus(fp).doesExist()) {
- // if user shortcut file does not exist, then try to load from template
TFilePath tmplFp =
ToonzFolder::getTemplateModuleDir() + TFilePath("shortcuts.ini");
- if (TFileStatus(tmplFp).doesExist()) TSystem::copyFile(fp, tmplFp);
- // if neither settings exist, do nothing and return
- else
+ if (TFileStatus(tmplFp).doesExist()) {
+ TSystem::copyFile(fp, tmplFp);
+ } else {
return;
+ }
}
QSettings settings(toQString(fp), QSettings::IniFormat);
settings.beginGroup("shortcuts");
QStringList ids = settings.allKeys();
+
for (int i = 0; i < ids.size(); i++) {
std::string id = ids.at(i).toStdString();
QString shortcut = settings.value(ids.at(i), "").toString();
- QAction *action = getAction(&id[0], false);
+
+ // Check if this is a reserved navigation shortcut
+ bool isReserved = false;
+ for (const std::string &reserved : reservedKeys) {
+ if (shortcut.toStdString() == reserved) {
+ isReserved = true;
+ break;
+ }
+ }
+
+ QAction *action = getAction(&id[0], false);
+
+ if (isReserved) {
+ // Remove reserved shortcuts
+ settings.remove(ids.at(i));
+ if (action) {
+ action->setShortcut(QKeySequence());
+ }
+ continue;
+ }
+
+ // Process non-reserved shortcuts
if (action) {
QString oldShortcut = action->shortcut().toString();
- if (oldShortcut == shortcut) continue;
- if (!oldShortcut.isEmpty())
+
+ if (oldShortcut == shortcut) {
+ continue;
+ }
+
+ // Remove old shortcut mapping
+ if (!oldShortcut.isEmpty()) {
m_shortcutTable.erase(oldShortcut.toStdString());
+ }
+
+ // Set new shortcut
if (!shortcut.isEmpty()) {
QAction *other = getActionFromShortcut(shortcut.toStdString());
- if (other) other->setShortcut(QKeySequence());
+ if (other) {
+ other->setShortcut(QKeySequence());
+ }
m_shortcutTable[shortcut.toStdString()] = getNode(&id[0]);
}
+
action->setShortcut(QKeySequence(shortcut));
}
}
+
settings.endGroup();
}