diff --git a/toonz/sources/include/tools/tooloptions.h b/toonz/sources/include/tools/tooloptions.h index f393606..5bbd9b0 100644 --- a/toonz/sources/include/tools/tooloptions.h +++ b/toonz/sources/include/tools/tooloptions.h @@ -254,6 +254,10 @@ class ArrowToolOptionsBox final : public ToolOptionsBox { ToolOptionCheckbox *m_globalKey; + // Flip buttons + QPushButton *m_hFlipButton, *m_vFlipButton, *m_leftRotateButton, + *m_rightRotateButton; + // enables adjusting value by dragging on the label void connectLabelAndField(ClickableLabel *label, MeasuredValueField *field); @@ -282,6 +286,11 @@ protected slots: void onCurrentStageObjectComboActivated(int index); void onCurrentAxisChanged(int); + + void onFlipHorizontal(); + void onFlipVertical(); + void onRotateLeft(); + void onRotateRight(); }; //============================================================================= @@ -378,6 +387,9 @@ class SelectionToolOptionsBox final : public ToolOptionsBox, ToolOptionPopupButton *m_joinStyle; ToolOptionIntSlider *m_miterField; + QPushButton *m_hFlipButton, *m_vFlipButton, *m_leftRotateButton, + *m_rightRotateButton; + public: SelectionToolOptionsBox(QWidget *parent, TTool *tool, TPaletteHandle *pltHandle, ToolHandle *toolHandle); @@ -391,6 +403,10 @@ protected slots: void onScaleXValueChanged(bool addToUndo = true); void onScaleYValueChanged(bool addToUndo = true); void onSetSaveboxCheckboxChanged(bool); + void onFlipHorizontal(); + void onFlipVertical(); + void onRotateLeft(); + void onRotateRight(); }; //============================================================================= 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 dc9d41a..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 --- */ @@ -549,6 +552,32 @@ ArrowToolOptionsBox::ArrowToolOptionsBox( m_zField->setPrecision(4); m_noScaleZField->setPrecision(4); + m_hFlipButton = new QPushButton(this); + m_vFlipButton = new QPushButton(this); + + m_leftRotateButton = new QPushButton(this); + m_rightRotateButton = new QPushButton(this); + + m_hFlipButton->setFixedSize(QSize(20, 20)); + m_vFlipButton->setFixedSize(QSize(20, 20)); + + m_leftRotateButton->setFixedSize(QSize(20, 20)); + m_rightRotateButton->setFixedSize(QSize(20, 20)); + + m_hFlipButton->setIcon(createQIcon("fliphoriz")); + m_hFlipButton->setIconSize(QSize(20, 20)); + m_vFlipButton->setIcon(createQIcon("flipvert")); + m_vFlipButton->setIconSize(QSize(20, 20)); + m_leftRotateButton->setIcon(createQIcon("rotateleft")); + m_leftRotateButton->setIconSize(QSize(20, 20)); + m_rightRotateButton->setIcon(createQIcon("rotateright")); + m_rightRotateButton->setIconSize(QSize(20, 20)); + + m_hFlipButton->setToolTip(tr("Flip Object Horizontally")); + m_vFlipButton->setToolTip(tr("Flip Object Vertically")); + m_leftRotateButton->setToolTip(tr("Rotate Object Left")); + m_rightRotateButton->setToolTip(tr("Rotate Object Right")); + bool splined = isCurrentObjectSplined(); if (splined != m_splined) m_splined = splined; setSplined(m_splined); @@ -637,6 +666,8 @@ ArrowToolOptionsBox::ArrowToolOptionsBox( rotLay->addWidget(m_rotationLabel, 0); rotLay->addSpacing(LABEL_SPACING); rotLay->addWidget(m_rotationField, 10); + rotLay->addWidget(m_leftRotateButton); + rotLay->addWidget(m_rightRotateButton); rotLay->addSpacing(ITEM_SPACING); rotLay->addWidget(new DVGui::Separator("", this, false)); @@ -666,6 +697,7 @@ ArrowToolOptionsBox::ArrowToolOptionsBox( scaleLay->addWidget(m_scaleHLabel, 0); scaleLay->addSpacing(LABEL_SPACING); scaleLay->addWidget(m_scaleHField, 10); + scaleLay->addWidget(m_hFlipButton); scaleLay->addWidget(m_lockScaleHCheckbox, 0); scaleLay->addSpacing(ITEM_SPACING); @@ -673,6 +705,7 @@ ArrowToolOptionsBox::ArrowToolOptionsBox( scaleLay->addWidget(m_scaleVLabel, 0); scaleLay->addSpacing(LABEL_SPACING); scaleLay->addWidget(m_scaleVField, 10); + scaleLay->addWidget(m_vFlipButton); scaleLay->addWidget(m_lockScaleVCheckbox, 0); scaleLay->addSpacing(ITEM_SPACING); @@ -793,6 +826,16 @@ ArrowToolOptionsBox::ArrowToolOptionsBox( connectLabelAndField(m_nsCenterLabel, m_nsCenterField); onCurrentAxisChanged(activeAxisProp->getIndex()); + + connect(m_hFlipButton, SIGNAL(clicked()), SLOT(onFlipHorizontal())); + 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())); } //----------------------------------------------------------------------------- @@ -998,6 +1041,36 @@ void ArrowToolOptionsBox::onCurrentAxisChanged(int axisId) { m_pickWidget->setVisible(axisId == AllAxis); } +//----------------------------------------------------------------------------- + +void ArrowToolOptionsBox::onFlipHorizontal() { + m_scaleHField->setValue(m_scaleHField->getValue() * -1); + emit m_scaleHField->measuredValueChanged(m_scaleHField->getMeasuredValue()); +} + +//----------------------------------------------------------------------------- + +void ArrowToolOptionsBox::onFlipVertical() { + m_scaleVField->setValue(m_scaleVField->getValue() * -1); + emit m_scaleVField->measuredValueChanged(m_scaleVField->getMeasuredValue()); +} + +//----------------------------------------------------------------------------- + +void ArrowToolOptionsBox::onRotateLeft() { + m_rotationField->setValue(m_rotationField->getValue() + 90); + emit m_rotationField->measuredValueChanged( + m_rotationField->getMeasuredValue()); +} + +//----------------------------------------------------------------------------- + +void ArrowToolOptionsBox::onRotateRight() { + m_rotationField->setValue(m_rotationField->getValue() - 90); + emit m_rotationField->measuredValueChanged( + m_rotationField->getMeasuredValue()); +} + //============================================================================= // // SelectionToolOptionsBox @@ -1070,11 +1143,42 @@ SelectionToolOptionsBox::SelectionToolOptionsBox(QWidget *parent, TTool *tool, new ToolOptionCheckbox(rasterSelectionTool, modifySetSaveboxProp); } + m_hFlipButton = new QPushButton(this); + m_vFlipButton = new QPushButton(this); + + m_leftRotateButton = new QPushButton(this); + m_rightRotateButton = new QPushButton(this); + + m_hFlipButton->setFixedSize(QSize(20, 20)); + m_vFlipButton->setFixedSize(QSize(20, 20)); + + m_leftRotateButton->setFixedSize(QSize(20, 20)); + m_rightRotateButton->setFixedSize(QSize(20, 20)); + + m_hFlipButton->setIcon(createQIcon("fliphoriz")); + m_hFlipButton->setIconSize(QSize(20, 20)); + m_vFlipButton->setIcon(createQIcon("flipvert")); + m_vFlipButton->setIconSize(QSize(20, 20)); + m_leftRotateButton->setIcon(createQIcon("rotateleft")); + m_leftRotateButton->setIconSize(QSize(20, 20)); + m_rightRotateButton->setIcon(createQIcon("rotateright")); + m_rightRotateButton->setIconSize(QSize(20, 20)); + + m_hFlipButton->setToolTip(tr("Flip Selection Horizontally")); + m_vFlipButton->setToolTip(tr("Flip Selection Vertically")); + m_leftRotateButton->setToolTip(tr("Rotate Selection Left")); + m_rightRotateButton->setToolTip(tr("Rotate Selection Right")); + m_scaleXLabel->setEnabled(false); m_scaleYLabel->setEnabled(false); m_moveXLabel->setEnabled(false); m_moveYLabel->setEnabled(false); + m_hFlipButton->setEnabled(false); + m_vFlipButton->setEnabled(false); + m_leftRotateButton->setEnabled(false); + m_rightRotateButton->setEnabled(false); + //--- layout ---- addSeparator(); @@ -1083,8 +1187,10 @@ SelectionToolOptionsBox::SelectionToolOptionsBox(QWidget *parent, TTool *tool, 0); hLayout()->addWidget(m_scaleXLabel, 0); hLayout()->addWidget(m_scaleXField, 10); + hLayout()->addWidget(m_hFlipButton); hLayout()->addWidget(m_scaleYLabel, 0); hLayout()->addWidget(m_scaleYField, 10); + hLayout()->addWidget(m_vFlipButton); hLayout()->addSpacing(4); hLayout()->addWidget(m_scaleLink, 0); @@ -1092,6 +1198,8 @@ SelectionToolOptionsBox::SelectionToolOptionsBox(QWidget *parent, TTool *tool, hLayout()->addWidget(rotIconView, 0); hLayout()->addWidget(m_rotationField, 10); + hLayout()->addWidget(m_leftRotateButton); + hLayout()->addWidget(m_rightRotateButton); addSeparator(); @@ -1185,6 +1293,18 @@ SelectionToolOptionsBox::SelectionToolOptionsBox(QWidget *parent, TTool *tool, SLOT(receiveMouseMove(QMouseEvent *))); connect(m_moveYLabel, SIGNAL(onMouseRelease(QMouseEvent *)), m_moveYField, SLOT(receiveMouseRelease(QMouseEvent *))); + connect(m_hFlipButton, SIGNAL(clicked()), SLOT(onFlipHorizontal())); + connect(m_vFlipButton, SIGNAL(clicked()), SLOT(onFlipVertical())); + 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(); @@ -1216,6 +1336,11 @@ void SelectionToolOptionsBox::updateStatus() { m_moveYField->updateStatus(); m_moveYLabel->setEnabled(m_moveYField->isEnabled()); + m_hFlipButton->setEnabled(m_scaleXField->isEnabled()); + m_vFlipButton->setEnabled(m_scaleXField->isEnabled()); + m_leftRotateButton->setEnabled(m_rotationField->isEnabled()); + m_rightRotateButton->setEnabled(m_rotationField->isEnabled()); + if (m_isVectorSelction) { m_thickChangeField->updateStatus(); onPropertyChanged(); @@ -1250,6 +1375,38 @@ void SelectionToolOptionsBox::onSetSaveboxCheckboxChanged(bool) { //----------------------------------------------------------------------------- +void SelectionToolOptionsBox::onFlipHorizontal() { + m_scaleXField->setValue(m_scaleXField->getValue() * -1); + m_scaleXField->applyChange(true); + + onScaleXValueChanged(true); +} + +//----------------------------------------------------------------------------- + +void SelectionToolOptionsBox::onFlipVertical() { + m_scaleYField->setValue(m_scaleYField->getValue() * -1); + m_scaleYField->applyChange(true); + + onScaleYValueChanged(true); +} + +//----------------------------------------------------------------------------- + +void SelectionToolOptionsBox::onRotateLeft() { + m_rotationField->setValue(m_rotationField->getValue() + 90); + m_rotationField->applyChange(true); +} + +//----------------------------------------------------------------------------- + +void SelectionToolOptionsBox::onRotateRight() { + m_rotationField->setValue(m_rotationField->getValue() - 90); + m_rotationField->applyChange(true); +} + +//----------------------------------------------------------------------------- + void SelectionToolOptionsBox::onPropertyChanged() { // Check the selection's outline styles group. VectorSelectionTool *tool = (VectorSelectionTool *)m_tool; @@ -2800,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/tnztools/tooloptionscontrols.cpp b/toonz/sources/tnztools/tooloptionscontrols.cpp index f197f9c..96775c9 100644 --- a/toonz/sources/tnztools/tooloptionscontrols.cpp +++ b/toonz/sources/tnztools/tooloptionscontrols.cpp @@ -1340,10 +1340,10 @@ SelectionRotationField::SelectionRotationField(SelectionTool *tool, //----------------------------------------------------------------------------- -void SelectionRotationField::onChange(TMeasuredValue *fld, bool addToUndo) { +bool SelectionRotationField::applyChange(bool addToUndo) { if (!m_tool || !m_tool->isEnabled() || (m_tool->isSelectionEmpty() && !m_tool->isLevelType())) - return; + return false; DragSelectionTool::DragTool *rotationTool = createNewRotationTool(m_tool); @@ -1359,6 +1359,15 @@ void SelectionRotationField::onChange(TMeasuredValue *fld, bool addToUndo) { if (!m_tool->isLevelType() && addToUndo) rotationTool->addTransformUndo(); setCursorPosition(0); + + return true; +} + +//----------------------------------------------------------------------------- + +void SelectionRotationField::onChange(TMeasuredValue *fld, bool addToUndo) { + if (!m_tool->isEnabled()) return; + if (!applyChange(addToUndo)) return; } //----------------------------------------------------------------------------- diff --git a/toonz/sources/tnztools/tooloptionscontrols.h b/toonz/sources/tnztools/tooloptionscontrols.h index 074d42a..78fad5b 100644 --- a/toonz/sources/tnztools/tooloptionscontrols.h +++ b/toonz/sources/tnztools/tooloptionscontrols.h @@ -519,6 +519,7 @@ public: ~SelectionRotationField() {} void updateStatus(); + bool applyChange(bool addToUndo = true); protected slots: // add to undo is only false if mouse dragging to change the value diff --git a/toonz/sources/toonz/icons/dark/actions/16/rotateleft.svg b/toonz/sources/toonz/icons/dark/actions/16/rotateleft.svg new file mode 100644 index 0000000..94b8d89 --- /dev/null +++ b/toonz/sources/toonz/icons/dark/actions/16/rotateleft.svg @@ -0,0 +1,70 @@ + +image/svg+xml + + \ No newline at end of file diff --git a/toonz/sources/toonz/icons/dark/actions/16/rotateright.svg b/toonz/sources/toonz/icons/dark/actions/16/rotateright.svg new file mode 100644 index 0000000..78d304e --- /dev/null +++ b/toonz/sources/toonz/icons/dark/actions/16/rotateright.svg @@ -0,0 +1,70 @@ + +image/svg+xml + + \ No newline at end of file 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"), "-"); diff --git a/toonz/sources/toonz/toonz.qrc b/toonz/sources/toonz/toonz.qrc index 8cd89a3..527f116 100644 --- a/toonz/sources/toonz/toonz.qrc +++ b/toonz/sources/toonz/toonz.qrc @@ -50,7 +50,10 @@ icons/dark/actions/16/butt_cap.svg icons/dark/actions/16/miter_join.svg - + icons/dark/actions/16/rotateleft.svg + icons/dark/actions/16/rotateright.svg + + icons/dark/actions/16/menu.svg icons/dark/actions/16/export.svg icons/dark/actions/16/import.svg