shortcut override for tool-specific keys

This commit is contained in:
shun_iwasawa 2017-11-09 11:51:36 +09:00
parent b000e2c687
commit d518217e82
6 changed files with 77 additions and 0 deletions

View file

@ -441,6 +441,11 @@ return true if the method execution can have changed the current tool
return 0; return 0;
} //!< Returns the type of cursor used by the tool. } //!< 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. TXsheet *getXsheet() const; //!< Returns a pointer to the actual Xsheet.
int getFrame(); //!< Returns the actual frame in use. int getFrame(); //!< Returns the actual frame in use.

View file

@ -25,6 +25,7 @@
// For Qt translation support // For Qt translation support
#include <QCoreApplication> #include <QCoreApplication>
#include <QKeyEvent>
using namespace ToolUtils; using namespace ToolUtils;
@ -197,6 +198,9 @@ public:
void onImageChanged() override; void onImageChanged() override;
int getCursorId() const override; int getCursorId() const override;
// returns true if the pressed key is recognized and processed.
bool isEventAcceptable(QEvent *e) override;
} controlPointEditorTool; } 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;} // TTool *getSplineEditorTool() {return &controlPointEditorTool;}

View file

@ -12,6 +12,8 @@
#include "toonz/tobjecthandle.h" #include "toonz/tobjecthandle.h"
#include "tw/keycodes.h" #include "tw/keycodes.h"
#include <QKeyEvent>
using namespace ToolUtils; using namespace ToolUtils;
using namespace DragSelectionTool; using namespace DragSelectionTool;
@ -1379,3 +1381,17 @@ void SelectionTool::closePolyline(const TPointD &pos) {
assert(m_stroke->getPoint(0) == m_stroke->getPoint(1)); assert(m_stroke->getPoint(0) == m_stroke->getPoint(1));
invalidate(); 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);
}

View file

@ -453,6 +453,9 @@ public:
TPropertyGroup *getProperties(int targetType) override { return &m_prop; } TPropertyGroup *getProperties(int targetType) override { return &m_prop; }
bool onPropertyChanged(std::string propertyName) override; bool onPropertyChanged(std::string propertyName) override;
// returns true if the pressed key is recognized and processed.
bool isEventAcceptable(QEvent *e) override;
}; };
#endif // SELECTIONTOOL_INCLUDED #endif // SELECTIONTOOL_INCLUDED

View file

@ -34,6 +34,7 @@
// For Qt translation support // For Qt translation support
#include <QCoreApplication> #include <QCoreApplication>
#include <QKeyEvent>
using namespace ToolUtils; using namespace ToolUtils;
@ -217,6 +218,9 @@ public:
int getCursorId() const override; int getCursorId() const override;
// returns true if the pressed key is recognized and processed.
bool isEventAcceptable(QEvent *e) override;
} trackerTool; } trackerTool;
//============================================================================= //=============================================================================
@ -847,6 +851,29 @@ void TrackerTool::onDeactivate() {
// TSelection::setCurrent(0); // 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; } static TTool *getTrackerToolTool() { return &trackerTool; }

View file

@ -802,6 +802,11 @@ bool SceneViewer::event(QEvent *e) {
if (tool && tool->isEnabled() && tool->getName() == T_Type && if (tool && tool->isEnabled() && tool->getName() == T_Type &&
tool->isActive()) tool->isActive())
e->accept(); 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; return true;
} }
if (e->type() == QEvent::KeyRelease) { if (e->type() == QEvent::KeyRelease) {