Block space and arrows as shortcuts (#373)

This commit is contained in:
Jeremy Bullock 2020-10-18 17:39:39 -06:00 committed by GitHub
parent 69acc777c2
commit e9edcf936d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 7 deletions

View file

@ -152,7 +152,7 @@ public:
int getKeyFromId(CommandId id);
void setShortcut(QAction *action, std::string shortcutString,
bool keepDefault = true);
bool canUseShortcut(QString shortcut);
QAction *getAction(CommandId id, bool createIfNeeded = false);
// createAction creates a new indepenent QAction with text and shortcut

View file

@ -58,7 +58,7 @@ public:
void updateText() {
QString text = m_action->text();
if (text.indexOf("&") == 0) {
text = text.remove(0, 1);
text = text.remove(0, 1);
}
text = text.replace("&&", "&");
setText(0, text);
@ -128,7 +128,7 @@ void ShortcutViewer::keyPressEvent(QKeyEvent *event) {
}
Qt::KeyboardModifiers modifiers = event->modifiers();
// Tasti che non possono essere utilizzati come shortcut
// Keys that cannot be used as shortcuts
if ((modifiers | (Qt::CTRL | Qt::SHIFT | Qt::ALT)) !=
(Qt::CTRL | Qt::SHIFT | Qt::ALT) ||
key == Qt::Key_Home || key == Qt::Key_End || key == Qt::Key_PageDown ||
@ -142,6 +142,15 @@ void ShortcutViewer::keyPressEvent(QKeyEvent *event) {
modifiers = 0;
}
// Block the arrows and space
int ctl = modifiers | Qt::CTRL;
if (key == Qt::Key_Space || ((modifiers == Qt::NoModifier) &&
(key == Qt::Key_Left || key == Qt::Key_Right ||
key == Qt::Key_Up || key == Qt::Key_Down))) {
event->ignore();
return;
}
// If "Use Numpad and Tab keys for Switching Styles" option is activated,
// then prevent to assign such keys
if (Preferences::instance()->isUseNumpadForSwitchingStylesEnabled() &&

View file

@ -97,14 +97,16 @@ CommandManager::Node *CommandManager::getNode(CommandId id,
void CommandManager::setShortcut(CommandId id, QAction *action,
std::string shortcutString) {
if (shortcutString != "")
action->setShortcut(QKeySequence(QString::fromStdString(shortcutString)));
QString shortcutQString = QString::fromStdString(shortcutString);
if (!canUseShortcut(shortcutQString)) shortcutQString = "";
if (shortcutQString != "")
action->setShortcut(QKeySequence(shortcutQString));
else
action->setShortcut(QKeySequence());
TFilePath fp = ToonzFolder::getMyModuleDir() + TFilePath("shortcuts.ini");
QSettings settings(toQString(fp), QSettings::IniFormat);
settings.beginGroup("shortcuts");
settings.setValue(QString(id), QString::fromStdString(shortcutString));
settings.setValue(QString(id), shortcutQString);
settings.endGroup();
}
@ -125,7 +127,7 @@ void CommandManager::define(CommandId id, CommandType type,
node->m_qaction = qaction;
node->m_qaction->setEnabled(
(node->m_enabled &&
(node->m_handler || node->m_qaction->actionGroup() != 0)) ||
(node->m_handler || node->m_qaction->actionGroup() != 0)) ||
node->m_type == MiscCommandType ||
node->m_type == ToolModifierCommandType);
@ -134,6 +136,7 @@ void CommandManager::define(CommandId id, CommandType type,
// user defined shortcuts will be loaded afterwards in loadShortcuts()
QString defaultShortcutQString =
QString::fromStdString(defaultShortcutString);
if (!canUseShortcut(defaultShortcutQString)) defaultShortcutQString = "";
if (!defaultShortcutQString.isEmpty()) {
qaction->setShortcut(QKeySequence(defaultShortcutQString));
m_shortcutTable[defaultShortcutString] = node;
@ -144,6 +147,17 @@ void CommandManager::define(CommandId id, CommandType type,
//---------------------------------------------------------
bool CommandManager::canUseShortcut(QString shortcut) {
shortcut = shortcut.toLower();
if (shortcut == "space" || shortcut == "left" || shortcut == "up" ||
shortcut == "right" || shortcut == "down") {
return false;
}
return true;
}
//---------------------------------------------------------
//
// set handler (id, handler)
// possibly changes enable/disable qaction state