Skip to content

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

C

shortcut override for tool-specific keys

shun_iwasawad518217e821c
diff --git a/toonz/sources/include/tools/tool.h b/toonz/sources/include/tools/tool.h
index a2f66efae..d44e5cfa0 100644
--- a/toonz/sources/include/tools/tool.h
+++ b/toonz/sources/include/tools/tool.h
@@ -441,6 +441,11 @@ return true if the method execution can have changed the current tool
return 0;
} //!< Returns the type of cursor used by the tool.
+ // returns true if the pressed key is recognized and processed.
+ // used in SceneViewer::event(), reimplemented in SelectionTool
+ // and ControlPointEditorTool
+ virtual bool isEventAcceptable(QEvent *e) { return false; }
+
TXsheet *getXsheet() const; //!< Returns a pointer to the actual Xsheet.
int getFrame(); //!< Returns the actual frame in use.
diff --git a/toonz/sources/tnztools/controlpointeditortool.cpp b/toonz/sources/tnztools/controlpointeditortool.cpp
index ea9642060..9ae2ec8e0 100644
--- a/toonz/sources/tnztools/controlpointeditortool.cpp
+++ b/toonz/sources/tnztools/controlpointeditortool.cpp
@@ -25,6 +25,7 @@
// For Qt translation support
#include <QCoreApplication>
+#include <QKeyEvent>
using namespace ToolUtils;
@@ -197,6 +198,9 @@ public:
void onImageChanged() override;
int getCursorId() const override;
+ // returns true if the pressed key is recognized and processed.
+ bool isEventAcceptable(QEvent *e) override;
+
} controlPointEditorTool;
//=============================================================================
@@ -890,6 +894,23 @@ int ControlPointEditorTool::getCursorId() const {
}
}
+//-----------------------------------------------------------------------------
+
+// returns true if the pressed key is recognized and processed in the tool
+// instead of triggering the shortcut command.
+bool ControlPointEditorTool::isEventAcceptable(QEvent *e) {
+ if (!isEnabled()) return false;
+ TVectorImageP vi(getImage(false));
+ if (!vi || (vi && m_selection.isEmpty())) return false;
+ // arrow keys will be used for moving the selected points
+ QKeyEvent *keyEvent = static_cast<QKeyEvent *>(e);
+ // shift + arrow will not be recognized for now
+ if (keyEvent->modifiers() & Qt::ShiftModifier) return false;
+ int key = keyEvent->key();
+ return (key == Qt::Key_Up || key == Qt::Key_Down || key == Qt::Key_Left ||
+ key == Qt::Key_Right);
+}
+
//=============================================================================
// TTool *getSplineEditorTool() {return &controlPointEditorTool;}
diff --git a/toonz/sources/tnztools/selectiontool.cpp b/toonz/sources/tnztools/selectiontool.cpp
index 406e8cab5..2878e1421 100644
--- a/toonz/sources/tnztools/selectiontool.cpp
+++ b/toonz/sources/tnztools/selectiontool.cpp
@@ -12,6 +12,8 @@
#include "toonz/tobjecthandle.h"
#include "tw/keycodes.h"
+#include <QKeyEvent>
+
using namespace ToolUtils;
using namespace DragSelectionTool;
@@ -1379,3 +1381,17 @@ void SelectionTool::closePolyline(const TPointD &pos) {
assert(m_stroke->getPoint(0) == m_stroke->getPoint(1));
invalidate();
}
+
+//-----------------------------------------------------------------------------
+
+// returns true if the pressed key is recognized and processed in the tool
+// instead of triggering the shortcut command.
+bool SelectionTool::isEventAcceptable(QEvent *e) {
+ if (!isEnabled()) return false;
+ if (isSelectionEmpty()) return false;
+ // arrow keys will be used for moving the selected region
+ QKeyEvent *keyEvent = static_cast<QKeyEvent *>(e);
+ int key = keyEvent->key();
+ return (key == Qt::Key_Up || key == Qt::Key_Down || key == Qt::Key_Left ||
+ key == Qt::Key_Right);
+}
\ No newline at end of file
diff --git a/toonz/sources/tnztools/selectiontool.h b/toonz/sources/tnztools/selectiontool.h
index 077553347..4af275a26 100644
--- a/toonz/sources/tnztools/selectiontool.h
+++ b/toonz/sources/tnztools/selectiontool.h
@@ -453,6 +453,9 @@ public:
TPropertyGroup *getProperties(int targetType) override { return &m_prop; }
bool onPropertyChanged(std::string propertyName) override;
+
+ // returns true if the pressed key is recognized and processed.
+ bool isEventAcceptable(QEvent *e) override;
};
#endif // SELECTIONTOOL_INCLUDED
diff --git a/toonz/sources/tnztools/trackertool.cpp b/toonz/sources/tnztools/trackertool.cpp
index 33d82028b..0629c5169 100644
--- a/toonz/sources/tnztools/trackertool.cpp
+++ b/toonz/sources/tnztools/trackertool.cpp
@@ -34,6 +34,7 @@
// For Qt translation support
#include <QCoreApplication>
+#include <QKeyEvent>
using namespace ToolUtils;
@@ -217,6 +218,9 @@ public:
int getCursorId() const override;
+ // returns true if the pressed key is recognized and processed.
+ bool isEventAcceptable(QEvent *e) override;
+
} trackerTool;
//=============================================================================
@@ -847,6 +851,29 @@ void TrackerTool::onDeactivate() {
// TSelection::setCurrent(0);
}
+//-----------------------------------------------------------------------------
+
+// returns true if the pressed key is recognized and processed in the tool
+// instead of triggering the shortcut command.
+bool TrackerTool::isEventAcceptable(QEvent *e) {
+ if (!isEnabled()) return false;
+ TXshLevel *xl = TTool::getApplication()->getCurrentLevel()->getLevel();
+ if (!xl) return false;
+ HookSet *hookSet = xl->getHookSet();
+ if (!hookSet) return false;
+ Hook *hook = hookSet->getHook(m_hookSelectedIndex);
+ if (!hook || hook->isEmpty()) return false;
+
+ QKeyEvent *keyEvent = static_cast<QKeyEvent *>(e);
+ // shift + arrow will not be recognized for now
+ if (keyEvent->modifiers() & Qt::ShiftModifier) return false;
+ int key = keyEvent->key();
+ return (key == Qt::Key_Up || key == Qt::Key_Down || key == Qt::Key_Left ||
+ key == Qt::Key_Right);
+ // no need to override page up & down keys since they cannot be
+ // used as shortcut key for now
+}
+
//=============================================================================
static TTool *getTrackerToolTool() { return &trackerTool; }
diff --git a/toonz/sources/toonz/sceneviewerevents.cpp b/toonz/sources/toonz/sceneviewerevents.cpp
index c32f8462e..6d27d3ae8 100644
--- a/toonz/sources/toonz/sceneviewerevents.cpp
+++ b/toonz/sources/toonz/sceneviewerevents.cpp
@@ -802,6 +802,11 @@ bool SceneViewer::event(QEvent *e) {
if (tool && tool->isEnabled() && tool->getName() == T_Type &&
tool->isActive())
e->accept();
+ // for other tools, check if the pressed keys should be catched instead of
+ // triggering the shortcut command actions
+ else if (tool && tool->isEventAcceptable(e)) {
+ e->accept();
+ }
return true;
}
if (e->type() == QEvent::KeyRelease) {