diff --git a/toonz/sources/tnztools/CMakeLists.txt b/toonz/sources/tnztools/CMakeLists.txt index c375266..d324715 100644 --- a/toonz/sources/tnztools/CMakeLists.txt +++ b/toonz/sources/tnztools/CMakeLists.txt @@ -9,6 +9,8 @@ set(MOC_HEADERS tooloptionscontrols.h toonzrasterbrushtool.h viewtools.h + selectiontool.h + edittool.h controlpointeditortool.h ../include/tools/imagegrouping.h ../include/tools/screenpicker.h @@ -25,7 +27,6 @@ set(HEADERS rasterselectiontool.h rgbpickertool.h rulertool.h - selectiontool.h setsaveboxtool.h shifttracetool.h stylepickertool.h diff --git a/toonz/sources/tnztools/edittool.cpp b/toonz/sources/tnztools/edittool.cpp index afc6b3d..6940b9c 100644 --- a/toonz/sources/tnztools/edittool.cpp +++ b/toonz/sources/tnztools/edittool.cpp @@ -1,5 +1,6 @@ +#include "edittool.h" #include "tools/tool.h" #include "tools/cursors.h" #include "tproperty.h" @@ -636,134 +637,6 @@ bool hasVisibleChildColumn(const TStageObject *obj, const TXsheet *xsh) { } // namespace //----------------------------------------------------------------------------- -//============================================================================= -// EditTool -//----------------------------------------------------------------------------- - -class EditTool final : public TTool { - Q_DECLARE_TR_FUNCTIONS(EditTool) - - DragTool *m_dragTool; - - bool m_firstTime; - - enum { - None = -1, - Translation = 1, - Rotation, - Scale, - ScaleX, - ScaleY, - ScaleXY, - Center, - ZTranslation, - Shear, - }; - - // DragInfo m_dragInfo; - - TPointD m_lastPos; - TPointD m_curPos; - TPointD m_firstPos; - TPointD m_curCenter; - - bool m_active; - bool m_keyFrameAdded; - int m_what; - int m_highlightedDevice; - - double m_oldValues[2]; - - double m_currentScaleFactor; - FxGadgetController *m_fxGadgetController; - - bool m_isAltPressed; - - TEnumProperty m_scaleConstraint; - TEnumProperty m_autoSelect; - TBoolProperty m_globalKeyframes; - - TBoolProperty m_lockCenterX; - TBoolProperty m_lockCenterY; - TBoolProperty m_lockPositionX; - TBoolProperty m_lockPositionY; - TBoolProperty m_lockRotation; - TBoolProperty m_lockShearH; - TBoolProperty m_lockShearV; - TBoolProperty m_lockScaleH; - TBoolProperty m_lockScaleV; - TBoolProperty m_lockGlobalScale; - - TBoolProperty m_showEWNSposition; - TBoolProperty m_showZposition; - TBoolProperty m_showSOposition; - TBoolProperty m_showRotation; - TBoolProperty m_showGlobalScale; - TBoolProperty m_showHVscale; - TBoolProperty m_showShear; - TBoolProperty m_showCenterPosition; - - TEnumProperty m_activeAxis; - - TPropertyGroup m_prop; - - void drawMainHandle(); - void onEditAllLeftButtonDown(TPointD &pos, const TMouseEvent &e); - -public: - EditTool(); - ~EditTool(); - - ToolType getToolType() const override { return TTool::ColumnTool; } - - bool doesApply() const; // ritorna vero se posso deformare l'oggetto corrente - void saveOldValues(); - bool transformEnabled() const; - - const TStroke *getSpline() const; - - void rotate(); - void move(); - void moveCenter(); - void scale(); - void isoScale(); - void squeeze(); - void shear(const TPointD &pos, bool single); - - void updateTranslation() override; - - void leftButtonDown(const TPointD &pos, const TMouseEvent &) override; - void leftButtonDrag(const TPointD &pos, const TMouseEvent &) override; - void leftButtonUp(const TPointD &pos, const TMouseEvent &) override; - - void mouseMove(const TPointD &, const TMouseEvent &e) override; - - void draw() override; - - void transform(const TAffine &aff); - - void onActivate() override; - void onDeactivate() override; - bool onPropertyChanged(std::string propertyName) override; - - void computeBBox(); - - int getCursorId() const override; - - TPropertyGroup *getProperties(int targetType) override { return &m_prop; } - - void updateMatrix() override { - setMatrix( - getCurrentObjectParentMatrix2()); // getCurrentObjectParentMatrix()); - } - - void drawText(const TPointD &p, double unit, std::string text); - - QString updateEnabled(int rowIndex, int columnIndex) override; -}; - -//----------------------------------------------------------------------------- - EditTool::EditTool() : TTool("T_Edit") , m_active(false) diff --git a/toonz/sources/tnztools/edittool.h b/toonz/sources/tnztools/edittool.h new file mode 100644 index 0000000..c2eec56 --- /dev/null +++ b/toonz/sources/tnztools/edittool.h @@ -0,0 +1,147 @@ +#pragma once + +#ifndef EDITTOOL_INCLUDED +#define EDITTOOL_INCLUDED + +#include "tool.h" +#include "tproperty.h" +#include "edittoolgadgets.h" + +// For Qt translation support +#include + +using EditToolGadgets::DragTool; + +//============================================================================= +// EditTool +//----------------------------------------------------------------------------- + +class EditTool final : public QObject, public TTool { + Q_OBJECT + + DragTool* m_dragTool; + + bool m_firstTime; + + enum { + None = -1, + Translation = 1, + Rotation, + Scale, + ScaleX, + ScaleY, + ScaleXY, + Center, + ZTranslation, + Shear, + }; + + // DragInfo m_dragInfo; + + TPointD m_lastPos; + TPointD m_curPos; + TPointD m_firstPos; + TPointD m_curCenter; + + bool m_active; + bool m_keyFrameAdded; + int m_what; + int m_highlightedDevice; + + double m_oldValues[2]; + + double m_currentScaleFactor; + FxGadgetController* m_fxGadgetController; + + bool m_isAltPressed; + + TEnumProperty m_scaleConstraint; + TEnumProperty m_autoSelect; + TBoolProperty m_globalKeyframes; + + TBoolProperty m_lockCenterX; + TBoolProperty m_lockCenterY; + TBoolProperty m_lockPositionX; + TBoolProperty m_lockPositionY; + TBoolProperty m_lockRotation; + TBoolProperty m_lockShearH; + TBoolProperty m_lockShearV; + TBoolProperty m_lockScaleH; + TBoolProperty m_lockScaleV; + TBoolProperty m_lockGlobalScale; + + TBoolProperty m_showEWNSposition; + TBoolProperty m_showZposition; + TBoolProperty m_showSOposition; + TBoolProperty m_showRotation; + TBoolProperty m_showGlobalScale; + TBoolProperty m_showHVscale; + TBoolProperty m_showShear; + TBoolProperty m_showCenterPosition; + + TEnumProperty m_activeAxis; + + TPropertyGroup m_prop; + + void drawMainHandle(); + void onEditAllLeftButtonDown(TPointD& pos, const TMouseEvent& e); + +public: + EditTool(); + ~EditTool(); + + ToolType getToolType() const override { return TTool::ColumnTool; } + + bool doesApply() const; // ritorna vero se posso deformare l'oggetto corrente + void saveOldValues(); + bool transformEnabled() const; + + const TStroke* getSpline() const; + + void rotate(); + void move(); + void moveCenter(); + void scale(); + void isoScale(); + void squeeze(); + void shear(const TPointD& pos, bool single); + + void updateTranslation() override; + + void leftButtonDown(const TPointD& pos, const TMouseEvent&) override; + void leftButtonDrag(const TPointD& pos, const TMouseEvent&) override; + void leftButtonUp(const TPointD& pos, const TMouseEvent&) override; + + void mouseMove(const TPointD&, const TMouseEvent& e) override; + + void draw() override; + + void transform(const TAffine& aff); + + void onActivate() override; + void onDeactivate() override; + bool onPropertyChanged(std::string propertyName) override; + + void computeBBox(); + + int getCursorId() const override; + + TPropertyGroup* getProperties(int targetType) override { return &m_prop; } + + void updateMatrix() override { + setMatrix( + getCurrentObjectParentMatrix2()); // getCurrentObjectParentMatrix()); + } + + void drawText(const TPointD& p, double unit, std::string text); + + QString updateEnabled(int rowIndex, int columnIndex) override; + +signals: + void clickFlipHorizontal(); + void clickFlipVertical(); + void clickRotateLeft(); + void clickRotateRight(); +}; + +#endif // EDITTOOL_INCLUDED diff --git a/toonz/sources/tnztools/selectiontool.h b/toonz/sources/tnztools/selectiontool.h index b469510..66d458b 100644 --- a/toonz/sources/tnztools/selectiontool.h +++ b/toonz/sources/tnztools/selectiontool.h @@ -322,8 +322,8 @@ DragSelectionTool::DragTool *createNewScaleTool( // SelectionTool //----------------------------------------------------------------------------- -class SelectionTool : public TTool, public TSelection::View { - Q_DECLARE_TR_FUNCTIONS(SelectionTool) +class SelectionTool : public QObject, public TTool, public TSelection::View { + Q_OBJECT protected: bool m_firstTime; @@ -467,6 +467,12 @@ public: bool isEventAcceptable(QEvent *e) override; virtual bool isSelectionEditable() { return true; } + +signals: + void clickFlipHorizontal(); + void clickFlipVertical(); + void clickRotateLeft(); + void clickRotateRight(); }; #endif // SELECTIONTOOL_INCLUDED diff --git a/toonz/sources/tnztools/tooloptions.cpp b/toonz/sources/tnztools/tooloptions.cpp index 138067f..f43ef3c 100644 --- a/toonz/sources/tnztools/tooloptions.cpp +++ b/toonz/sources/tnztools/tooloptions.cpp @@ -7,6 +7,7 @@ #include "tools/toolhandle.h" #include "tools/toolcommandids.h" +#include "edittool.h" #include "selectiontool.h" #include "vectorselectiontool.h" #include "rasterselectiontool.h" @@ -391,6 +392,8 @@ ArrowToolOptionsBox::ArrowToolOptionsBox( setObjectName("toolOptionsPanel"); setFixedHeight(26); + EditTool *editTool = dynamic_cast(tool); + m_axisOptionWidgets = new QWidget *[AllAxis]; /* --- General Parts --- */ @@ -552,7 +555,7 @@ ArrowToolOptionsBox::ArrowToolOptionsBox( m_hFlipButton = new QPushButton(this); m_vFlipButton = new QPushButton(this); - m_leftRotateButton = new QPushButton(this); + m_leftRotateButton = new QPushButton(this); m_rightRotateButton = new QPushButton(this); m_hFlipButton->setFixedSize(QSize(20, 20)); @@ -828,6 +831,11 @@ ArrowToolOptionsBox::ArrowToolOptionsBox( connect(m_vFlipButton, SIGNAL(clicked()), SLOT(onFlipVertical())); connect(m_leftRotateButton, SIGNAL(clicked()), SLOT(onRotateLeft())); connect(m_rightRotateButton, SIGNAL(clicked()), SLOT(onRotateRight())); + + connect(editTool, SIGNAL(clickFlipHorizontal()), SLOT(onFlipHorizontal())); + connect(editTool, SIGNAL(clickFlipVertical()), SLOT(onFlipVertical())); + connect(editTool, SIGNAL(clickRotateLeft()), SLOT(onRotateLeft())); + connect(editTool, SIGNAL(clickRotateRight()), SLOT(onRotateRight())); } //----------------------------------------------------------------------------- @@ -1051,14 +1059,16 @@ void ArrowToolOptionsBox::onFlipVertical() { void ArrowToolOptionsBox::onRotateLeft() { m_rotationField->setValue(m_rotationField->getValue() + 90); - emit m_rotationField->measuredValueChanged(m_rotationField->getMeasuredValue()); + emit m_rotationField->measuredValueChanged( + m_rotationField->getMeasuredValue()); } //----------------------------------------------------------------------------- void ArrowToolOptionsBox::onRotateRight() { m_rotationField->setValue(m_rotationField->getValue() - 90); - emit m_rotationField->measuredValueChanged(m_rotationField->getMeasuredValue()); + emit m_rotationField->measuredValueChanged( + m_rotationField->getMeasuredValue()); } //============================================================================= @@ -1288,6 +1298,13 @@ SelectionToolOptionsBox::SelectionToolOptionsBox(QWidget *parent, TTool *tool, connect(m_leftRotateButton, SIGNAL(clicked()), SLOT(onRotateLeft())); connect(m_rightRotateButton, SIGNAL(clicked()), SLOT(onRotateRight())); + + connect(selectionTool, SIGNAL(clickFlipHorizontal()), + SLOT(onFlipHorizontal())); + connect(selectionTool, SIGNAL(clickFlipVertical()), SLOT(onFlipVertical())); + connect(selectionTool, SIGNAL(clickRotateLeft()), SLOT(onRotateLeft())); + connect(selectionTool, SIGNAL(clickRotateRight()), SLOT(onRotateRight())); + // assert(ret); updateStatus(); @@ -2940,3 +2957,75 @@ void ToolOptions::onStageObjectChange() { ToolOptionsBox *panel = it->second; panel->onStageObjectChange(); } + +//*********************************************************************************** +// Command instantiation +//*********************************************************************************** + +class FlipHorizontalCommandHandler final : public MenuItemHandler { +public: + FlipHorizontalCommandHandler(CommandId cmdId) : MenuItemHandler(cmdId) {} + void execute() override { + TTool::Application *app = TTool::getApplication(); + TTool *tool = app->getCurrentTool()->getTool(); + if (!tool) return; + if (tool->getName() == T_Edit) { + EditTool *editTool = dynamic_cast(tool); + emit editTool->clickFlipHorizontal(); + } else if (tool->getName() == T_Selection) { + SelectionTool *selectionTool = dynamic_cast(tool); + emit selectionTool->clickFlipHorizontal(); + } + } +} flipHorizontalCHInstance("A_ToolOption_FlipHorizontal"); + +class FlipVerticalCommandHandler final : public MenuItemHandler { +public: + FlipVerticalCommandHandler(CommandId cmdId) : MenuItemHandler(cmdId) {} + void execute() override { + TTool::Application *app = TTool::getApplication(); + TTool *tool = app->getCurrentTool()->getTool(); + if (!tool) return; + if (tool->getName() == T_Edit) { + EditTool *editTool = dynamic_cast(tool); + emit editTool->clickFlipVertical(); + } else if (tool->getName() == T_Selection) { + SelectionTool *selectionTool = dynamic_cast(tool); + emit selectionTool->clickFlipVertical(); + } + } +} flipVerticalCHInstance("A_ToolOption_FlipVertical"); + +class RotateLeftCommandHandler final : public MenuItemHandler { +public: + RotateLeftCommandHandler(CommandId cmdId) : MenuItemHandler(cmdId) {} + void execute() override { + TTool::Application *app = TTool::getApplication(); + TTool *tool = app->getCurrentTool()->getTool(); + if (!tool) return; + if (tool->getName() == T_Edit) { + EditTool *editTool = dynamic_cast(tool); + emit editTool->clickRotateLeft(); + } else if (tool->getName() == T_Selection) { + SelectionTool *selectionTool = dynamic_cast(tool); + emit selectionTool->clickRotateLeft(); + } + } +} rotateLeftCHInstance("A_ToolOption_RotateLeft"); + +class RotateRightCommandHandler final : public MenuItemHandler { +public: + RotateRightCommandHandler(CommandId cmdId) : MenuItemHandler(cmdId) {} + void execute() override { + TTool::Application *app = TTool::getApplication(); + TTool *tool = app->getCurrentTool()->getTool(); + if (!tool) return; + if (tool->getName() == T_Edit) { + EditTool *editTool = dynamic_cast(tool); + emit editTool->clickRotateRight(); + } else if (tool->getName() == T_Selection) { + SelectionTool *selectionTool = dynamic_cast(tool); + emit selectionTool->clickRotateRight(); + } + } +} rotateRightCHInstance("A_ToolOption_RotateRight"); diff --git a/toonz/sources/toonz/mainwindow.cpp b/toonz/sources/toonz/mainwindow.cpp index e9d4e53..d1e31cc 100644 --- a/toonz/sources/toonz/mainwindow.cpp +++ b/toonz/sources/toonz/mainwindow.cpp @@ -2812,7 +2812,16 @@ void MainWindow::defineActions() { QT_TR_NOOP("Fill Tool - Autopaint Lines"), ""); menuAct->setIcon(createQIcon("fill_auto")); - // Visualization + createToolOptionsAction("A_ToolOption_FlipHorizontal", + QT_TR_NOOP("Flip Selection/Object Horizontally"), ""); + createToolOptionsAction("A_ToolOption_FlipVertical", + QT_TR_NOOP("Flip Selection/Object Vertically"), ""); + createToolOptionsAction("A_ToolOption_RotateLeft", + QT_TR_NOOP("Rotate Selection/Object Left"), ""); + createToolOptionsAction("A_ToolOption_RotateRight", + QT_TR_NOOP("Rotate Selection/Object Right"), ""); + +// Visualization createViewerAction(V_ZoomIn, QT_TR_NOOP("Zoom In"), "+"); createViewerAction(V_ZoomOut, QT_TR_NOOP("Zoom Out"), "-");