diff --git a/toonz/sources/include/tools/pinchtool.h b/toonz/sources/include/tools/pinchtool.h index 233733b..ff3e657 100644 --- a/toonz/sources/include/tools/pinchtool.h +++ b/toonz/sources/include/tools/pinchtool.h @@ -86,7 +86,7 @@ public: bool moveCursor(const TPointD &pos); - bool keyDown(int key, TUINT32 flags, const TPoint &pos); + bool keyDown(QKeyEvent *) override; void onActivate(); void onDeactivate(); diff --git a/toonz/sources/include/tools/tool.h b/toonz/sources/include/tools/tool.h index 28f5e16..bf056c0 100644 --- a/toonz/sources/include/tools/tool.h +++ b/toonz/sources/include/tools/tool.h @@ -58,6 +58,7 @@ class TFxHandle; class ToolOptionsBox; class QMenu; +class QKeyEvent; //=================================================================== @@ -383,12 +384,7 @@ return true if the method execution can have changed the current tool virtual void leftButtonUp(const TPointD &, const TMouseEvent &) {} virtual void leftButtonDoubleClick(const TPointD &, const TMouseEvent &) {} virtual void rightButtonDown(const TPointD &, const TMouseEvent &) {} - - //! For keycodes list, \see keycodes.h. - virtual bool keyDown(int, TUINT32, const TPoint &) { return false; } - virtual bool keyDown(int, std::wstring, TUINT32, const TPoint &) { - return false; - } + virtual bool keyDown(QKeyEvent *) { return false; } virtual void onInputText(std::wstring, std::wstring, int, int){}; diff --git a/toonz/sources/include/tw/keycodes.h b/toonz/sources/include/tw/keycodes.h deleted file mode 100644 index 537a92f..0000000 --- a/toonz/sources/include/tw/keycodes.h +++ /dev/null @@ -1,62 +0,0 @@ -#pragma once - -#ifndef TW_KEYCODES_INCLUDED -#define TW_KEYCODES_INCLUDED - -#include "tw/tw.h" - -#undef DVAPI -#undef DVVAR -#ifdef TWIN_EXPORTS -#define DVAPI DV_EXPORT_API -#define DVVAR DV_EXPORT_VAR -#else -#define DVAPI DV_IMPORT_API -#define DVVAR DV_IMPORT_VAR -#endif - -namespace TwConsts { - -enum { - TK_Backspace = 8, - TK_Return = 13, - TK_LeftArrow = 1018, - TK_RightArrow = 1019, - TK_UpArrow = 1020, - TK_DownArrow = 1021, - TK_ShiftLeftArrow, - TK_ShiftRightArrow, - TK_ShiftUpArrow, - TK_ShiftDownArrow, - TK_Home = 22, - TK_End = 23, - TK_PageUp = 24, - TK_PageDown = 25, - TK_Esc = 27, - - TK_Delete = -22, - TK_Insert = -23, - TK_CapsLock = 1022, - - TK_F1 = -200, - TK_F2, - TK_F3, - TK_F4, - TK_F5, - TK_F6, - TK_F7, - TK_F8, - TK_F9, - TK_F10, - TK_F11, - TK_F12 - -}; - -enum { TK_ShiftPressed = 0x1, TK_CtrlPressed = 0x2, TK_AltPressed = 0x3 }; - -} // namespace - -DVAPI std::string getKeyName(int key, unsigned long flags); - -#endif diff --git a/toonz/sources/tnztools/brushtool.cpp b/toonz/sources/tnztools/brushtool.cpp index c3a461a..05bc488 100644 --- a/toonz/sources/tnztools/brushtool.cpp +++ b/toonz/sources/tnztools/brushtool.cpp @@ -27,7 +27,6 @@ #include "toonz/toonzimageutils.h" #include "toonz/palettecontroller.h" #include "toonz/stage2.h" -#include "tw/keycodes.h" #include "toonz/preferences.h" // TnzCore includes @@ -1575,8 +1574,8 @@ void BrushTool::leftButtonUp(const TPointD &pos, const TMouseEvent &e) { //-------------------------------------------------------------------------------------------------- -bool BrushTool::keyDown(int key, TUINT32 b, const TPoint &point) { - if (key == TwConsts::TK_Esc) { +bool BrushTool::keyDown(QKeyEvent *event) { + if (event->key() == Qt::Key_Escape) { resetFrameRange(); } return false; diff --git a/toonz/sources/tnztools/brushtool.h b/toonz/sources/tnztools/brushtool.h index 2c484d2..9e3a260 100644 --- a/toonz/sources/tnztools/brushtool.h +++ b/toonz/sources/tnztools/brushtool.h @@ -34,13 +34,13 @@ class BluredBrush; struct BrushData final : public TPersist { PERSIST_DECLARATION(BrushData) // frameRange, snapSensitivity and snap are not included - // Those options are not really a part of the brush settings, - //just the overall tool. + // Those options are not really a part of the brush settings, + // just the overall tool. std::wstring m_name; double m_min, m_max, m_acc, m_smooth, m_hardness, m_opacityMin, m_opacityMax; - bool m_selective, m_pencil, m_breakAngles, m_pressure; - int m_cap, m_join, m_miter; + bool m_selective, m_pencil, m_breakAngles, m_pressure; + int m_cap, m_join, m_miter; double m_modifierSize, m_modifierOpacity; bool m_modifierEraser, m_modifierLockAlpha; @@ -131,7 +131,7 @@ public: void leftButtonDrag(const TPointD &pos, const TMouseEvent &e) override; void leftButtonUp(const TPointD &pos, const TMouseEvent &e) override; void mouseMove(const TPointD &pos, const TMouseEvent &e) override; - bool keyDown(int key, TUINT32 b, const TPoint &point) override; + bool keyDown(QKeyEvent *event) override; void draw() override; diff --git a/toonz/sources/tnztools/controlpointeditortool.cpp b/toonz/sources/tnztools/controlpointeditortool.cpp index 9ae2ec8..fb58527 100644 --- a/toonz/sources/tnztools/controlpointeditortool.cpp +++ b/toonz/sources/tnztools/controlpointeditortool.cpp @@ -21,8 +21,6 @@ #include "toonz/stage2.h" #include "toonz/tstageobject.h" -#include "tw/keycodes.h" - // For Qt translation support #include #include @@ -188,7 +186,7 @@ public: void linkSpeedInOut(int index); void unlinkSpeedInOut(int pointIndex); - bool keyDown(int key, TUINT32 flags, const TPoint &pos) override; + bool keyDown(QKeyEvent *event) override; void onEnter() override; void onLeave() override; bool onPropertyChanged(std::string propertyName) override; @@ -783,8 +781,7 @@ void ControlPointEditorTool::unlinkSpeedInOut(int pointIndex) { //--------------------------------------------------------------------------- -bool ControlPointEditorTool::keyDown(int key, TUINT32 flags, - const TPoint &pos) { +bool ControlPointEditorTool::keyDown(QKeyEvent *event) { TVectorImageP vi(getImage(true)); if (!vi || (vi && m_selection.isEmpty())) return false; @@ -792,16 +789,23 @@ bool ControlPointEditorTool::keyDown(int key, TUINT32 flags, initUndo(); TPointD delta; - if (key == TwConsts::TK_UpArrow) + switch (event->key()) { + case Qt::Key_Up: delta.y = 1; - else if (key == TwConsts::TK_DownArrow) + break; + case Qt::Key_Down: delta.y = -1; - else if (key == TwConsts::TK_LeftArrow) + break; + case Qt::Key_Left: delta.x = -1; - else if (key == TwConsts::TK_RightArrow) + break; + case Qt::Key_Right: delta.x = 1; - else + break; + default: return false; + break; + } moveControlPoints(delta); invalidate(); diff --git a/toonz/sources/tnztools/geometrictool.cpp b/toonz/sources/tnztools/geometrictool.cpp index bef51c0..e2b9686 100644 --- a/toonz/sources/tnztools/geometrictool.cpp +++ b/toonz/sources/tnztools/geometrictool.cpp @@ -27,7 +27,6 @@ #include "toonzqt/dvdialog.h" #include "toonz/trasterimageutils.h" #include "toonz/preferences.h" -#include "tw/keycodes.h" #include "historytypes.h" // For Qt translation support @@ -446,7 +445,7 @@ public: virtual void leftButtonDoubleClick(const TPointD &, const TMouseEvent &e){}; virtual void rightButtonDown(const TPointD &p, const TMouseEvent &e){}; virtual void mouseMove(const TPointD &p, const TMouseEvent &e){}; - virtual bool keyDown(int key, const TPoint &point) { return false; } + virtual bool keyDown(QKeyEvent *event) { return false; } virtual void onEnter(){}; virtual void draw(){}; virtual void onActivate(){}; @@ -614,7 +613,7 @@ public: void leftButtonDoubleClick(const TPointD &, const TMouseEvent &e) override; void leftButtonUp(const TPointD &pos, const TMouseEvent &) override; void mouseMove(const TPointD &pos, const TMouseEvent &e) override; - bool keyDown(int key, const TPoint &point) override; + bool keyDown(QKeyEvent *event) override; TStroke *makeStroke() const override; void endLine(); void onActivate() override; @@ -854,8 +853,8 @@ public: invalidate(); } - bool keyDown(int key, TUINT32 b, const TPoint &point) override { - return m_primitive->keyDown(key, point); + bool keyDown(QKeyEvent *event) override { + return m_primitive->keyDown(event); } void onImageChanged() override { @@ -1454,8 +1453,8 @@ void CirclePrimitive::leftButtonDrag(const TPointD &pos, const TMouseEvent &e) { if (!m_isEditing) return; m_pos = pos; - m_pos = calculateSnap(pos); - m_pos = checkGuideSnapping(pos); + m_pos = calculateSnap(pos); + m_pos = checkGuideSnapping(pos); m_radius = tdistance(m_centre, m_pos); } @@ -1750,13 +1749,13 @@ void MultiLinePrimitive::mouseMove(const TPointD &pos, const TMouseEvent &e) { //----------------------------------------------------------------------------- -bool MultiLinePrimitive::keyDown(int key, const TPoint &point) { - if (key == TwConsts::TK_Return) { +bool MultiLinePrimitive::keyDown(QKeyEvent *event) { + if (event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter) { endLine(); return true; } - if (key != TwConsts::TK_Esc || !m_isEditing) return false; + if (event->key() != Qt::Key_Escape || !m_isEditing) return false; UINT size = m_vertex.size(); if (size <= 1) return 0; @@ -2285,8 +2284,8 @@ void PolygonPrimitive::leftButtonDrag(const TPointD &pos, const TMouseEvent &e) { if (!m_isEditing) return; TPointD newPos = calculateSnap(pos); - newPos = checkGuideSnapping(pos); - m_radius = tdistance(m_centre, newPos); + newPos = checkGuideSnapping(pos); + m_radius = tdistance(m_centre, newPos); } //----------------------------------------------------------------------------- diff --git a/toonz/sources/tnztools/morphtool.cpp b/toonz/sources/tnztools/morphtool.cpp index d5b6b5b..cddd628 100644 --- a/toonz/sources/tnztools/morphtool.cpp +++ b/toonz/sources/tnztools/morphtool.cpp @@ -13,6 +13,8 @@ #include "toonz/tframehandle.h" #include "toonz/txshsimplelevel.h" +#include + class Deformation { public: std::vector m_controlPoints; @@ -221,8 +223,8 @@ glEnd(); */ } -bool MorphTool::keyDown(int key, TUINT32 flags, const TPoint &pos) { - if (key == 'A') +bool MorphTool::keyDown(QKeyEvent *event) { + if (event->key() == Qt::Key_A) deformation.updateLevel(); else return false; diff --git a/toonz/sources/tnztools/morphtool.h b/toonz/sources/tnztools/morphtool.h index cd9f38e..33baaf8 100644 --- a/toonz/sources/tnztools/morphtool.h +++ b/toonz/sources/tnztools/morphtool.h @@ -29,7 +29,7 @@ public: void leftButtonDrag(const TPointD &pos, const TMouseEvent &e); void leftButtonUp(const TPointD &pos, const TMouseEvent &e); - bool keyDown(int key, TUINT32 flags, const TPoint &pos); + bool keyDown(QKeyEvent *event); void draw(); }; diff --git a/toonz/sources/tnztools/pinchtool.cpp b/toonz/sources/tnztools/pinchtool.cpp index c074263..cc8545b 100644 --- a/toonz/sources/tnztools/pinchtool.cpp +++ b/toonz/sources/tnztools/pinchtool.cpp @@ -482,7 +482,7 @@ void PinchTool::mouseMove(const TPointD &pos, const TMouseEvent &event) { //----------------------------------------------------------------------------- -bool PinchTool::keyDown(int key, TUINT32 flags, const TPoint &pos) { +bool PinchTool::keyDown(QKeyEvent *event) { if (!m_active) m_deformation->reset(); #if 0 diff --git a/toonz/sources/tnztools/plastictool.cpp b/toonz/sources/tnztools/plastictool.cpp index ea3c9c0..626073f 100644 --- a/toonz/sources/tnztools/plastictool.cpp +++ b/toonz/sources/tnztools/plastictool.cpp @@ -3,7 +3,6 @@ #include "plastictool.h" // TnzTools includes -#include "tw/keycodes.h" // Obsolete by now... still currently used though #include "tooloptionscontrols.h" #include "tools/toolcommandids.h" diff --git a/toonz/sources/tnztools/selectiontool.cpp b/toonz/sources/tnztools/selectiontool.cpp index 77b41d2..2a58f61 100644 --- a/toonz/sources/tnztools/selectiontool.cpp +++ b/toonz/sources/tnztools/selectiontool.cpp @@ -10,7 +10,6 @@ #include "tools/cursors.h" #include "toonz/stage2.h" #include "toonz/tobjecthandle.h" -#include "tw/keycodes.h" #include @@ -1106,28 +1105,36 @@ void SelectionTool::mouseMove(const TPointD &pos, const TMouseEvent &e) { //----------------------------------------------------------------------------- -bool SelectionTool::keyDown(int key, TUINT32 flags, const TPoint &pos) { +bool SelectionTool::keyDown(QKeyEvent *event) { if (isSelectionEmpty()) return false; TPointD delta; - if (key == TwConsts::TK_UpArrow) + + switch (event->key()) { + case Qt::Key_Up: delta.y = 1; - else if (key == TwConsts::TK_DownArrow) + break; + case Qt::Key_Down: delta.y = -1; - else if (key == TwConsts::TK_LeftArrow) + break; + case Qt::Key_Left: delta.x = -1; - else if (key == TwConsts::TK_RightArrow) + break; + case Qt::Key_Right: delta.x = 1; - else if (key == TwConsts::TK_ShiftUpArrow) - delta.y = 10; - else if (key == TwConsts::TK_ShiftDownArrow) - delta.y = -10; - else if (key == TwConsts::TK_ShiftLeftArrow) - delta.x = -10; - else if (key == TwConsts::TK_ShiftRightArrow) - delta.x = 10; - else + break; + default: return false; + break; + } + + if (event->modifiers() & Qt::ShiftModifier) { + delta.x *= 10.0; + delta.y *= 10.0; + } else if (event->modifiers() & Qt::ControlModifier) { + delta.x *= 0.1; + delta.y *= 0.1; + } TImageP image = getImage(true); @@ -1138,7 +1145,6 @@ bool SelectionTool::keyDown(int key, TUINT32 flags, const TPoint &pos) { if (!ti && !vi && !ri) return false; DragTool *dragTool = createNewMoveSelectionTool(this); - TPointD p = convert(pos); TAffine aff = TTranslation(delta); dragTool->transform(aff); double factor = 1.0 / Stage::inch; diff --git a/toonz/sources/tnztools/selectiontool.h b/toonz/sources/tnztools/selectiontool.h index a795e6a..f1f3c8a 100644 --- a/toonz/sources/tnztools/selectiontool.h +++ b/toonz/sources/tnztools/selectiontool.h @@ -435,7 +435,7 @@ public: void mouseMove(const TPointD &pos, const TMouseEvent &e) override; void leftButtonDoubleClick(const TPointD &, const TMouseEvent &e) override = 0; - bool keyDown(int key, TUINT32 flags, const TPoint &pos) override; + bool keyDown(QKeyEvent *) override; int getCursorId() const override; diff --git a/toonz/sources/tnztools/skeletontool.cpp b/toonz/sources/tnztools/skeletontool.cpp index 9f1290f..6cec4d9 100644 --- a/toonz/sources/tnztools/skeletontool.cpp +++ b/toonz/sources/tnztools/skeletontool.cpp @@ -35,7 +35,6 @@ #include "tools/tool.h" #include "tools/cursors.h" #include "tools/toolutils.h" -#include "tw/keycodes.h" // Qt includes #include // Qt translation support @@ -46,6 +45,7 @@ #include #include #include +#include #include "skeletonsubtools.h" #include "skeletontool.h" @@ -481,14 +481,19 @@ void SkeletonTool::leftButtonUp(const TPointD &pos, const TMouseEvent &e) { //------------------------------------------------------------------- -bool SkeletonTool::keyDown(int key, TUINT32 flags, const TPoint &pos) { +bool SkeletonTool::keyDown(QKeyEvent *event) { ChangeDrawingTool tool(this, 0); - if (key == TwConsts::TK_UpArrow) + switch (event->key()) { + case Qt::Key_Up: tool.changeDrawing(1); - else if (key == TwConsts::TK_DownArrow) + break; + case Qt::Key_Down: tool.changeDrawing(-1); - else + break; + default: return false; + break; + } invalidate(); return true; } diff --git a/toonz/sources/tnztools/skeletontool.h b/toonz/sources/tnztools/skeletontool.h index 5155286..f863a2c 100644 --- a/toonz/sources/tnztools/skeletontool.h +++ b/toonz/sources/tnztools/skeletontool.h @@ -120,7 +120,7 @@ public: void computeMagicLinks(); - bool keyDown(int key, TUINT32 flags, const TPoint &pos); + bool keyDown(QKeyEvent *event) override; void onActivate(); void onDeactivate(); diff --git a/toonz/sources/tnztools/trackertool.cpp b/toonz/sources/tnztools/trackertool.cpp index 0629c51..37fcba2 100644 --- a/toonz/sources/tnztools/trackertool.cpp +++ b/toonz/sources/tnztools/trackertool.cpp @@ -27,7 +27,6 @@ #include "toonz/txshsimplelevel.h" #include "toonz/levelproperties.h" #include "toonz/txsheethandle.h" -#include "tw/keycodes.h" #include #include @@ -199,7 +198,7 @@ public: void leftButtonUp(const TPointD &pos, const TMouseEvent &) override; void mouseMove(const TPointD &pos, const TMouseEvent &e) override; - bool keyDown(int key, TUINT32 flags, const TPoint &pos) override; + bool keyDown(QKeyEvent *event) override; // bool moveCursor(const TPointD &pos){} void onEnter() override; void onLeave() override; @@ -784,7 +783,7 @@ int TrackerTool::getCursorId() const { } return ToolCursor::TrackerCursor; } -bool TrackerTool::keyDown(int key, TUINT32 flags, const TPoint &pos) { +bool TrackerTool::keyDown(QKeyEvent *event) { TXshLevel *xl = TTool::getApplication()->getCurrentLevel()->getLevel(); if (!xl) return false; HookSet *hookSet = xl->getHookSet(); @@ -796,17 +795,23 @@ bool TrackerTool::keyDown(int key, TUINT32 flags, const TPoint &pos) { TPointD delta(0, 0); double pixelSize = getPixelSize(); - if (key == TwConsts::TK_UpArrow) + switch (event->key()) { + case Qt::Key_Up: delta.y = 1; - else if (key == TwConsts::TK_DownArrow) + break; + case Qt::Key_Down: delta.y = -1; - else if (key == TwConsts::TK_LeftArrow) + break; + case Qt::Key_Left: delta.x = -1; - else if (key == TwConsts::TK_RightArrow) + break; + case Qt::Key_0: delta.x = 1; - else if (key == TwConsts::TK_PageUp) // converto in Hook + break; + case Qt::Key_PageUp: // converto in Hook hook->setTrackerObjectId(-1); - else if (key == TwConsts::TK_PageDown) // converto in trackerRegion + break; + case Qt::Key_PageDown: // converto in trackerRegion { TrackerObjectsSet *trackerObjectsSet = getTrackerObjectsSet(); if (!trackerObjectsSet) return false; @@ -816,8 +821,11 @@ bool TrackerTool::keyDown(int key, TUINT32 flags, const TPoint &pos) { hook->setTrackerObjectId(trackerObjectId); hook->setTrackerRegionHeight(pixelSize * 20); hook->setTrackerRegionWidth(pixelSize * 20); - } else + } break; + default: return false; + break; + } hookPos += delta; hook->setAPos(fid, hookPos); diff --git a/toonz/sources/tnztools/typetool.cpp b/toonz/sources/tnztools/typetool.cpp index 31f9db4..3739c52 100644 --- a/toonz/sources/tnztools/typetool.cpp +++ b/toonz/sources/tnztools/typetool.cpp @@ -32,7 +32,6 @@ #include "toonz/stage.h" #include "tfont.h" -#include "tw/keycodes.h" // For Qt translation support #include @@ -42,7 +41,6 @@ //#include "tw/ime.h" using namespace ToolUtils; -using namespace TwConsts; namespace { @@ -256,7 +254,7 @@ public: , m_key(key) , m_styleId(styleId) {} - bool isReturn() const { return m_key == TK_Return; } + bool isReturn() const { return m_key == (int)(QChar('\r').unicode()); } void update(TAffine scale, int nextCode = 0) { if (!isReturn()) { @@ -359,8 +357,8 @@ public: void mouseMove(const TPointD &pos, const TMouseEvent &) override; void leftButtonDown(const TPointD &pos, const TMouseEvent &) override; void rightButtonDown(const TPointD &pos, const TMouseEvent &) override; - bool keyDown(int key, std::wstring unicodeChar, TUINT32 flags, - const TPoint &pos) override; + bool keyDown(QKeyEvent *event) override; + void onInputText(std::wstring preedit, std::wstring commit, int replacementStart, int replacementLen) override; @@ -1352,10 +1350,10 @@ void TypeTool::replaceText(std::wstring text, int from, int to) { void TypeTool::addReturn() { TVectorImageP vi(new TVectorImage); if ((UINT)m_cursorIndex == m_string.size()) - m_string.push_back(StrokeChar(vi, -1., (int)(TK_Return), 0)); + m_string.push_back(StrokeChar(vi, -1., (int)(QChar('\r').unicode()), 0)); else m_string.insert(m_string.begin() + m_cursorIndex, - StrokeChar(vi, -1., TK_Return, 0)); + StrokeChar(vi, -1., (int)(QChar('\r').unicode()), 0)); m_cursorIndex++; m_preeditRange = std::make_pair(m_cursorIndex, m_cursorIndex); @@ -1505,31 +1503,35 @@ void TypeTool::deleteKey() { //--------------------------------------------------------- -bool TypeTool::keyDown(int key, std::wstring unicodeChar, TUINT32 flags, - const TPoint &pos) { +bool TypeTool::keyDown(QKeyEvent *event) { + QString text = event->text(); + if ((event->modifiers() & Qt::ShiftModifier)) text.toUpper(); + std::wstring unicodeChar = text.toStdWString(); + // per sicurezza m_preeditRange = std::make_pair(0, 0); if (!m_validFonts || !m_active) return true; // Se ho premuto solo i tasti ALT, SHIFT e CTRL (da soli) esco - if (flags && (unicodeChar.empty())) return true; + if (event->modifiers() != Qt::NoModifier && (unicodeChar.empty())) + return true; - switch (key) { - case TK_Insert: - case TK_CapsLock: + switch (event->key()) { + case Qt::Key_Insert: + case Qt::Key_CapsLock: return true; - case TK_Home: - case TK_PageUp: + case Qt::Key_Home: + case Qt::Key_PageUp: m_cursorIndex = 0; m_preeditRange = std::make_pair(m_cursorIndex, m_cursorIndex); updateCursorPoint(); invalidate(); break; - case TK_End: - case TK_PageDown: + case Qt::Key_End: + case Qt::Key_PageDown: m_cursorIndex = (int)m_string.size(); m_preeditRange = std::make_pair(m_cursorIndex, m_cursorIndex); updateCursorPoint(); @@ -1537,7 +1539,7 @@ bool TypeTool::keyDown(int key, std::wstring unicodeChar, TUINT32 flags, break; /////////////////// cursors - case TK_UpArrow: + case Qt::Key_Up: if (!m_isVertical) cursorUp(); else if (m_cursorIndex > 0) { @@ -1548,7 +1550,7 @@ bool TypeTool::keyDown(int key, std::wstring unicodeChar, TUINT32 flags, invalidate(); break; - case TK_DownArrow: + case Qt::Key_Down: if (!m_isVertical) cursorDown(); else if ((UINT)m_cursorIndex < m_string.size()) { @@ -1559,7 +1561,7 @@ bool TypeTool::keyDown(int key, std::wstring unicodeChar, TUINT32 flags, invalidate(); break; - case TK_LeftArrow: + case Qt::Key_Left: if (m_isVertical) cursorLeft(); else if (m_cursorIndex > 0) { @@ -1570,7 +1572,7 @@ bool TypeTool::keyDown(int key, std::wstring unicodeChar, TUINT32 flags, invalidate(); break; - case TK_RightArrow: + case Qt::Key_Right: if (m_isVertical) cursorRight(); else if ((UINT)m_cursorIndex < m_string.size()) { @@ -1583,7 +1585,7 @@ bool TypeTool::keyDown(int key, std::wstring unicodeChar, TUINT32 flags, /////////////////// end cursors - case TK_Esc: + case Qt::Key_Escape: resetInputMethod(); if (!m_string.empty()) addTextToImage(); @@ -1591,11 +1593,11 @@ bool TypeTool::keyDown(int key, std::wstring unicodeChar, TUINT32 flags, stopEditing(); break; - case TK_Delete: + case Qt::Key_Delete: deleteKey(); break; - case TK_Backspace: + case Qt::Key_Backspace: if (m_cursorIndex > 0) { m_cursorIndex--; m_preeditRange = std::make_pair(m_cursorIndex, m_cursorIndex); @@ -1603,7 +1605,8 @@ bool TypeTool::keyDown(int key, std::wstring unicodeChar, TUINT32 flags, } break; - case TK_Return: + case Qt::Key_Return: + case Qt::Key_Enter: addReturn(); break; diff --git a/toonz/sources/tnztools/vectorselectiontool.cpp b/toonz/sources/tnztools/vectorselectiontool.cpp index 83f30c9..e1e71f3 100644 --- a/toonz/sources/tnztools/vectorselectiontool.cpp +++ b/toonz/sources/tnztools/vectorselectiontool.cpp @@ -789,8 +789,8 @@ void DragSelectionTool::VectorMoveSelectionTool::transform(TAffine aff) { int i; for (i = 0; i < (int)tool->getBBoxsCount(); i++) tool->setBBox(tool->getBBox(i) * aff, i); - applyTransform(tool->getBBox()); getTool()->setCenter(aff * tool->getCenter()); + applyTransform(tool->getBBox()); } //----------------------------------------------------------------------------- @@ -805,8 +805,11 @@ void DragSelectionTool::VectorMoveSelectionTool::leftButtonDown( void DragSelectionTool::VectorMoveSelectionTool::leftButtonDrag( const TPointD &pos, const TMouseEvent &e) { - if (norm2(pos - getStartPos()) > l_dragThreshold * getTool()->getPixelSize()) + if (e.isCtrlPressed() || + norm2(pos - getStartPos()) > l_dragThreshold * getTool()->getPixelSize()) m_moveSelection->leftButtonDrag(pos, e); + else // snap to the original position + m_moveSelection->leftButtonDrag(getStartPos(), e); } //============================================================================= diff --git a/toonz/sources/toonz/sceneviewerevents.cpp b/toonz/sources/toonz/sceneviewerevents.cpp index 108011b..d2ad5ab 100644 --- a/toonz/sources/toonz/sceneviewerevents.cpp +++ b/toonz/sources/toonz/sceneviewerevents.cpp @@ -48,8 +48,6 @@ #include "toonzqt/gutil.h" #include "subcameramanager.h" -#include "tw/keycodes.h" - // TnzCore includes #include "timagecache.h" #include "trasterimage.h" @@ -70,11 +68,6 @@ extern QString updateToolEnableStatus(TTool *tool); namespace { //----------------------------------------------------------------------------- -// ahime': baco di Qt. il tablet event non conosce i modificatori correnti -int modifiers = 0; - -//----------------------------------------------------------------------------- - void initToonzEvent(TMouseEvent &toonzEvent, QMouseEvent *event, int widgetHeight, double pressure, int devPixRatio) { toonzEvent.m_pos = TPointD(event->pos().x() * devPixRatio, @@ -104,7 +97,6 @@ void initToonzEvent(TMouseEvent &toonzEvent, QTabletEvent *event, toonzEvent.setModifiers(event->modifiers() & Qt::ShiftModifier, event->modifiers() & Qt::AltModifier, event->modifiers() & Qt::ControlModifier); - toonzEvent.m_buttons = event->buttons(); toonzEvent.m_button = event->button(); toonzEvent.m_isTablet = true; @@ -378,7 +370,6 @@ void SceneViewer::onEnter() { TApp *app = TApp::instance(); app->setActiveViewer(this); - modifiers = 0; TTool *tool = app->getCurrentTool()->getTool(); TXshLevel *level = app->getCurrentLevel()->getLevel(); if (level && level->getSimpleLevel()) @@ -1158,10 +1149,6 @@ void SceneViewer::keyPressEvent(QKeyEvent *event) { if (changeFrameSkippingHolds(event)) { return; } - if ((event->modifiers() & Qt::ShiftModifier) && - (key == Qt::Key_Down || key == Qt::Key_Up)) { - } - TTool *tool = TApp::instance()->getCurrentTool()->getTool(); if (!tool) return; @@ -1189,13 +1176,6 @@ void SceneViewer::keyPressEvent(QKeyEvent *event) { return; } - if (key == Qt::Key_Shift) - modifiers |= Qt::SHIFT; - else if (key == Qt::Key_Control) - modifiers |= Qt::CTRL; - else if (key == Qt::Key_Alt || key == Qt::Key_AltGr) - modifiers |= Qt::ALT; - if (key == Qt::Key_Shift || key == Qt::Key_Control || key == Qt::Key_Alt || key == Qt::Key_AltGr) { // quando l'utente preme shift/ctrl ecc. alcuni tool (es. pinch) devono @@ -1219,96 +1199,17 @@ void SceneViewer::keyPressEvent(QKeyEvent *event) { bool shiftButton = QApplication::keyboardModifiers() == Qt::ShiftModifier; - TUINT32 flags = 0; - TPoint pos; - if (key == Qt::Key_Shift) - flags = TwConsts::TK_ShiftPressed; - else if (key == Qt::Key_Control) - flags = TwConsts::TK_CtrlPressed; - else if (key == Qt::Key_Alt) - flags = TwConsts::TK_AltPressed; - else if (key == Qt::Key_CapsLock) - flags = TwConsts::TK_CapsLock; - else if (key == Qt::Key_Backspace) - key = TwConsts::TK_Backspace; - else if (key == Qt::Key_Return || key == Qt::Key_Enter) - key = TwConsts::TK_Return; - else if (key == Qt::Key_Left && !shiftButton) - key = TwConsts::TK_LeftArrow; - else if (key == Qt::Key_Right && !shiftButton) - key = TwConsts::TK_RightArrow; - else if (key == Qt::Key_Up && !shiftButton) - key = TwConsts::TK_UpArrow; - else if (key == Qt::Key_Down && !shiftButton) - key = TwConsts::TK_DownArrow; - else if (key == Qt::Key_Left && shiftButton) - key = TwConsts::TK_ShiftLeftArrow; - else if (key == Qt::Key_Right && shiftButton) - key = TwConsts::TK_ShiftRightArrow; - else if (key == Qt::Key_Up && shiftButton) - key = TwConsts::TK_ShiftUpArrow; - else if (key == Qt::Key_Down && shiftButton) - key = TwConsts::TK_ShiftDownArrow; - else if (key == Qt::Key_Home) - key = TwConsts::TK_Home; - else if (key == Qt::Key_End) - key = TwConsts::TK_End; - else if (key == Qt::Key_PageUp) - key = TwConsts::TK_PageUp; - else if (key == Qt::Key_PageDown) - key = TwConsts::TK_PageDown; - else if (key == Qt::Key_Insert) - key = TwConsts::TK_Insert; - else if (key == Qt::Key_Delete) - key = TwConsts::TK_Delete; - else if (key == Qt::Key_Escape) - key = TwConsts::TK_Esc; - else if (key == Qt::Key_F1) - key = TwConsts::TK_F1; - else if (key == Qt::Key_F2) - key = TwConsts::TK_F2; - else if (key == Qt::Key_F3) - key = TwConsts::TK_F3; - else if (key == Qt::Key_F4) - key = TwConsts::TK_F4; - else if (key == Qt::Key_F5) - key = TwConsts::TK_F5; - else if (key == Qt::Key_F6) - key = TwConsts::TK_F6; - else if (key == Qt::Key_F7) - key = TwConsts::TK_F7; - else if (key == Qt::Key_F8) - key = TwConsts::TK_F8; - else if (key == Qt::Key_F9) - key = TwConsts::TK_F9; - else if (key == Qt::Key_F10) - key = TwConsts::TK_F10; - else if (key == Qt::Key_F11) - key = TwConsts::TK_F11; - else if (key == Qt::Key_F12) - key = TwConsts::TK_F12; - else if (key == Qt::Key_Menu || key == Qt::Key_Meta) - return; + if (key == Qt::Key_Menu || key == Qt::Key_Meta) return; bool ret = false; if (tool) // && m_toolEnabled) - { - QString text = event->text(); - if ((event->modifiers() & Qt::ShiftModifier)) text.toUpper(); - std::wstring unicodeChar = text.toStdWString(); - ret = tool->keyDown(key, unicodeChar, flags, pos); // per il textTool - if (ret) { - update(); - return; - } - ret = tool->keyDown(key, flags, pos); // per gli altri tool - } + ret = tool->keyDown(event); if (!ret) { TFrameHandle *fh = TApp::instance()->getCurrentFrame(); - if (key == TwConsts::TK_UpArrow || key == TwConsts::TK_LeftArrow) + if (key == Qt::Key_Up || key == Qt::Key_Left) fh->prevFrame(); - else if (key == TwConsts::TK_DownArrow || key == TwConsts::TK_RightArrow) { + else if (key == Qt::Key_Down || key == Qt::Key_Right) { // If on a level frame pass the frame id after the last frame to allow // creating a new frame with the down arrow key TFrameId newId = 0; @@ -1326,9 +1227,9 @@ void SceneViewer::keyPressEvent(QKeyEvent *event) { } } fh->nextFrame(newId); - } else if (key == TwConsts::TK_Home) + } else if (key == Qt::Key_Home) fh->firstFrame(); - else if (key == TwConsts::TK_End) + else if (key == Qt::Key_End) fh->lastFrame(); } update(); @@ -1348,13 +1249,6 @@ void SceneViewer::keyReleaseEvent(QKeyEvent *event) { if (key == Qt::Key_Shift || key == Qt::Key_Control || key == Qt::Key_Alt || key == Qt::Key_AltGr) { - if (key == Qt::Key_Shift) - modifiers &= ~Qt::ShiftModifier; - else if (key == Qt::Key_Control) - modifiers &= ~Qt::ControlModifier; - else if (key == Qt::Key_Alt || key == Qt::Key_AltGr) - modifiers &= ~Qt::AltModifier; - // quando l'utente preme shift/ctrl ecc. alcuni tool (es. pinch) devono // cambiare subito la forma del cursore, senza aspettare il prossimo move TMouseEvent toonzEvent;