From d518217e821c425d3c262ea900f521f86cc42522 Mon Sep 17 00:00:00 2001 From: shun_iwasawa Date: Nov 09 2017 03:08:56 +0000 Subject: shortcut override for tool-specific keys --- diff --git a/toonz/sources/include/tools/tool.h b/toonz/sources/include/tools/tool.h index a2f66ef..d44e5cf 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 ea96420..9ae2ec8 100644 --- a/toonz/sources/tnztools/controlpointeditortool.cpp +++ b/toonz/sources/tnztools/controlpointeditortool.cpp @@ -25,6 +25,7 @@ // For Qt translation support #include +#include 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(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 406e8ca..2878e14 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 + 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(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 0775533..4af275a 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 33d8202..0629c51 100644 --- a/toonz/sources/tnztools/trackertool.cpp +++ b/toonz/sources/tnztools/trackertool.cpp @@ -34,6 +34,7 @@ // For Qt translation support #include +#include 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(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 c32f846..6d27d3a 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) {