Skip to content

OpenToonz - An open-source full-featured 2D animation creation software

C

Add rotate left/right shortcuts, context menu options and panelbar buttons

Abel Youbc501449744e
diff --git a/toonz/sources/include/toonzqt/flipconsole.h b/toonz/sources/include/toonzqt/flipconsole.h
index 19967a507..b70429ddd 100644
--- a/toonz/sources/include/toonzqt/flipconsole.h
+++ b/toonz/sources/include/toonzqt/flipconsole.h
@@ -223,6 +223,8 @@ public:
eZoomOut,
eFlipHorizontal,
eFlipVertical,
+ eRotateLeft,
+ eRotateRight,
eResetView,
eBlankFrames,
eDecreaseGain,
diff --git a/toonz/sources/include/toonzqt/imageutils.h b/toonz/sources/include/toonzqt/imageutils.h
index ed80be4f5..478d8e333 100644
--- a/toonz/sources/include/toonzqt/imageutils.h
+++ b/toonz/sources/include/toonzqt/imageutils.h
@@ -216,7 +216,7 @@ public:
ShortcutZoomer(
QWidget *viewerWidget); //!< Constructs on the specified viewer widget.
- virtual ~ShortcutZoomer() { }
+ virtual ~ShortcutZoomer() {}
QWidget *getWidget() {
return m_widget;
@@ -242,6 +242,9 @@ protected:
virtual bool setFlipY() {
return false;
} //!< Handler for 'flip viewer horizontally' commands.
+ // Handler for 'rotate viewer left/right' commands.
+ virtual bool rotateLeft() { return false; }
+ virtual bool rotateRight() { return false; }
virtual bool resetZoom() {
return false;
} //!< Handler for 'reset zoom' commands.
diff --git a/toonz/sources/include/toonzqt/viewcommandids.h b/toonz/sources/include/toonzqt/viewcommandids.h
index 41ef0d88b..dface1165 100644
--- a/toonz/sources/include/toonzqt/viewcommandids.h
+++ b/toonz/sources/include/toonzqt/viewcommandids.h
@@ -12,6 +12,8 @@
#define V_ActualPixelSize "T_ActualPixelSize"
#define V_FlipX "T_FlipX"
#define V_FlipY "T_FlipY"
+#define V_RotateLeft "V_RotateLeft"
+#define V_RotateRight "V_RotateRight"
#define V_RotateReset "T_RotateReset"
#define V_PositionReset "T_PositionReset"
@@ -24,5 +26,7 @@
#define VB_ActualPixelSize "VB_ActualPixelSize"
#define VB_FlipX "VB_FlipX"
#define VB_FlipY "VB_FlipY"
+#define VB_RotateLeft "VB_RotateLeft"
+#define VB_RotateRight "VB_RotateRight"
#endif // VIEWCOMMANDIDS_H
diff --git a/toonz/sources/toonz/flipbook.h b/toonz/sources/toonz/flipbook.h
index 2d1322eab..a09df65d7 100644
--- a/toonz/sources/toonz/flipbook.h
+++ b/toonz/sources/toonz/flipbook.h
@@ -190,13 +190,14 @@ protected:
public:
enum Flags { eDontKeepFilesOpened = 0x1 };
-
+
FlipBook(QWidget *parent = 0, QString viewerTitle = QString(),
std::vector<int> flipConsoleButtonMask =
{FlipConsole::eFilledRaster, FlipConsole::eDefineSubCamera,
FlipConsole::eLocator, FlipConsole::eZoomIn,
FlipConsole::eZoomOut, FlipConsole::eFlipHorizontal,
- FlipConsole::eFlipVertical, FlipConsole::eResetView},
+ FlipConsole::eFlipVertical, FlipConsole::eResetView,
+ FlipConsole::eRotateLeft, FlipConsole::eRotateRight},
UCHAR flags = 0, bool isColorModel = false);
~FlipBook();
void setLevel(const TFilePath &path, TPalette *palette = 0, int from = -1,
diff --git a/toonz/sources/toonz/mainwindow.cpp b/toonz/sources/toonz/mainwindow.cpp
index 939887aa4..cea04f827 100644
--- a/toonz/sources/toonz/mainwindow.cpp
+++ b/toonz/sources/toonz/mainwindow.cpp
@@ -2950,6 +2950,8 @@ void MainWindow::defineActions() {
createViewerAction(V_ActualPixelSize, QT_TR_NOOP("Actual Pixel Size"), "N");
createViewerAction(V_FlipX, QT_TR_NOOP("Flip Viewer Horizontally"), "");
createViewerAction(V_FlipY, QT_TR_NOOP("Flip Viewer Vertically"), "");
+ createViewerAction(V_RotateLeft, QT_TR_NOOP("Rotate Viewer 90° Left"), "");
+ createViewerAction(V_RotateRight, QT_TR_NOOP("Rotate Viewer 90° Right"), "");
createViewerAction(V_ShowHideFullScreen, QT_TR_NOOP("Show//Hide Full Screen"),
"Alt+F");
CommandManager::instance()->setToggleTexts(V_ShowHideFullScreen,
@@ -2986,6 +2988,10 @@ void MainWindow::defineActions() {
VB_FlipX, QT_TR_NOOP("Flip Viewer Horizontally"), "fliphoriz");
createVisualizationButtonAction(
VB_FlipY, QT_TR_NOOP("Flip Viewer Vertically"), "flipvert");
+ createVisualizationButtonAction(
+ VB_RotateLeft, QT_TR_NOOP("Rotate Viewer 90° Left"), "rotateleft");
+ createVisualizationButtonAction(
+ VB_RotateRight, QT_TR_NOOP("Rotate Viewer 90° Right"), "rotateright");
// Misc
diff --git a/toonz/sources/toonz/sceneviewer.cpp b/toonz/sources/toonz/sceneviewer.cpp
index 408768dc2..2e6e2aaf7 100644
--- a/toonz/sources/toonz/sceneviewer.cpp
+++ b/toonz/sources/toonz/sceneviewer.cpp
@@ -79,6 +79,7 @@
#include "trasterimage.h"
#include "tstroke.h"
#include "ttoonzimage.h"
+#include "tenv.h"
// Qt includes
#include <QMenu>
@@ -91,6 +92,8 @@
#include "sceneviewer.h"
+TEnv::IntVar RotateOnCameraCenter("RotateOnCameraCenter", 0);
+
void drawSpline(const TAffine &viewMatrix, const TRect &clipRect, bool camera3d,
double pixelSize);
@@ -543,6 +546,28 @@ public:
}
} flipViewerYCommand;
+class TRotateViewerLeftCommand final : public MenuItemHandler {
+public:
+ TRotateViewerLeftCommand() : MenuItemHandler(VB_RotateLeft) {}
+ void execute() override {
+ SceneViewer *viewer = TApp::instance()->getActiveViewer();
+ if (viewer) {
+ viewer->rotateLeft();
+ }
+ }
+} rotateViewerLeftCommand;
+
+class TRotateViewerRightCommand final : public MenuItemHandler {
+public:
+ TRotateViewerRightCommand() : MenuItemHandler(VB_RotateRight) {}
+ void execute() override {
+ SceneViewer *viewer = TApp::instance()->getActiveViewer();
+ if (viewer) {
+ viewer->rotateRight();
+ }
+ }
+} rotateViewerRightCommand;
+
class TRotateResetCommand final : public MenuItemHandler {
public:
TRotateResetCommand() : MenuItemHandler(VB_RotateReset) {}
@@ -759,7 +784,7 @@ public:
//-----------------------------------------------------------------------------
SceneViewer::SceneViewer(ImageUtils::FullScreenWidget *parent)
- : TToolViewer(this,parent)
+ : TToolViewer(this, parent)
, m_pressure(0)
, m_lastMousePos(0, 0)
, m_mouseButton(Qt::NoButton)
@@ -1194,7 +1219,7 @@ void SceneViewer::hideEvent(QHideEvent *) {
disconnect(m_stopMotion, SIGNAL(liveViewStopped()), this,
SLOT(onStopMotionLiveViewStopped()));
}
- #endif
+#endif
}
int SceneViewer::getVGuideCount() {
@@ -1827,7 +1852,7 @@ void SceneViewer::drawOverlay() {
!app->getCurrentObject()->isSpline())
glScaled(m_dpiScale.x, m_dpiScale.y, 1);
m_pixelSize = sqrt(tglGetPixelSize2()) * getDevPixRatio();
-
+
unsigned int hints = tool->getToolHints();
// draw assistans and guidelines
@@ -1835,43 +1860,42 @@ void SceneViewer::drawOverlay() {
if (hints & TTool::HintAssistantsAll) {
bool markEnabled = hints & TTool::HintAssistantsEnabled;
bool drawGuidelines = hints & TTool::HintAssistantsGuidelines;
-
- m_toolHasAssistants = TAssistant::scanAssistants(
- tool, // tool
- &m_toolPos, 1, // pointer positions
- nullptr, // out guidelines
- true, // draw
- false, // enabled only
- markEnabled, // mark enabled
- drawGuidelines, // draw guidelines
- nullptr ); // skip image
+
+ m_toolHasAssistants =
+ TAssistant::scanAssistants(tool, // tool
+ &m_toolPos, 1, // pointer positions
+ nullptr, // out guidelines
+ true, // draw
+ false, // enabled only
+ markEnabled, // mark enabled
+ drawGuidelines, // draw guidelines
+ nullptr); // skip image
}
-
+
// draw replicators
m_toolReplicatedPoints.clear();
if (hints & TTool::HintReplicatorsAll) {
- bool drawPoints = hints & TTool::HintReplicatorsPoints;
- bool markEnabled = hints & TTool::HintReplicatorsEnabled;
+ bool drawPoints = hints & TTool::HintReplicatorsPoints;
+ bool markEnabled = hints & TTool::HintReplicatorsEnabled;
TReplicator::PointList *points = nullptr;
if (drawPoints) {
m_toolReplicatedPoints.push_back(m_toolPos);
points = &m_toolReplicatedPoints;
}
-
- TReplicator::scanReplicators(
- tool, // tool
- points, // in/out points
- nullptr, // out modifiers
- true, // draw
- false, // enabled only
- markEnabled, // mark enabled
- drawPoints, // draw points
- nullptr ); // skip image
+
+ TReplicator::scanReplicators(tool, // tool
+ points, // in/out points
+ nullptr, // out modifiers
+ true, // draw
+ false, // enabled only
+ markEnabled, // mark enabled
+ drawPoints, // draw points
+ nullptr); // skip image
}
-
+
// draw tool
tool->draw();
-
+
glPopMatrix();
// Used (only in the T_RGBPicker tool) to notify and set the currentColor
// outside the draw() methods:
@@ -2275,8 +2299,8 @@ void SceneViewer::drawScene() {
if (ToonzCheck::instance()->getChecks() & ToonzCheck::eAutoclose) {
TXshSimpleLevel *sl = app->getCurrentLevel()->getSimpleLevel();
if (sl && sl->getType() & TXshLevelType::RASTER_TYPE) {
- TFrameId fid = app->getCurrentTool()->getTool()->getCurrentFid();
- painter.setCurrentImageId(sl->getImageId(fid, 0));
+ TFrameId fid = app->getCurrentTool()->getTool()->getCurrentFid();
+ painter.setCurrentImageId(sl->getImageId(fid, 0));
}
}
painter.flushRasterImages();
@@ -2355,7 +2379,8 @@ TRect SceneViewer::getActualClipRect(const TAffine &aff) {
clipRect = aff * (m_clipRect.enlarge(3));
}
- clipRect *= TRectD(viewerSize) - TPointD(viewerSize.lx/2, viewerSize.ly/2);
+ clipRect *=
+ TRectD(viewerSize) - TPointD(viewerSize.lx / 2, viewerSize.ly / 2);
return convert(clipRect);
}
@@ -2363,16 +2388,16 @@ TRect SceneViewer::getActualClipRect(const TAffine &aff) {
TAffine4 SceneViewer::get3dViewMatrix() const {
if (is3DView()) {
- TXsheet *xsh = TApp::instance()->getCurrentXsheet()->getXsheet();
+ TXsheet *xsh = TApp::instance()->getCurrentXsheet()->getXsheet();
TStageObjectId cameraId = xsh->getStageObjectTree()->getCurrentCameraId();
- double z = xsh->getStageObject(cameraId)->getZ(
- TApp::instance()->getCurrentFrame()->getFrame());
+ double z = xsh->getStageObject(cameraId)->getZ(
+ TApp::instance()->getCurrentFrame()->getFrame());
TAffine4 affine;
affine *= TAffine4::translation(m_pan3D.x, m_pan3D.y, z);
affine *= TAffine4::scale(m_zoomScale3D, m_zoomScale3D, m_zoomScale3D);
- affine *= TAffine4::rotationX(M_PI_180*m_theta3D);
- affine *= TAffine4::rotationY(M_PI_180*m_phi3D);
+ affine *= TAffine4::rotationX(M_PI_180 * m_theta3D);
+ affine *= TAffine4::rotationY(M_PI_180 * m_phi3D);
return affine;
}
@@ -2758,6 +2783,34 @@ void SceneViewer::flipY() {
emit onFlipVChanged(m_isFlippedY);
}
+void SceneViewer::rotateLeft() {
+ double rotationAngle = 90.0;
+ if (m_isFlippedX != m_isFlippedY) rotationAngle *= -1;
+
+ TPointD center;
+
+ if (RotateOnCameraCenter)
+ center = TPointD(0, 0);
+ else
+ center = m_viewAff[m_viewMode].inv() * TPointD(0, 0);
+
+ rotate(center, rotationAngle);
+}
+
+void SceneViewer::rotateRight() {
+ double rotationAngle = -90.0;
+ if (m_isFlippedX != m_isFlippedY) rotationAngle *= -1;
+
+ TPointD center;
+
+ if (RotateOnCameraCenter)
+ center = TPointD(0, 0);
+ else
+ center = m_viewAff[m_viewMode].inv() * TPointD(0, 0);
+
+ rotate(center, rotationAngle);
+}
+
//-----------------------------------------------------------------------------
void SceneViewer::zoomIn() {
@@ -2956,13 +3009,14 @@ void SceneViewer::resetRotation() {
double reverseRotatation = m_rotationAngle[m_viewMode] * -1;
if (m_isFlippedX) reverseRotatation *= -1;
if (m_isFlippedY) reverseRotatation *= -1;
- TTool *tool = TApp::instance()->getCurrentTool()->getTool();
- TPointD center = m_viewAff[m_viewMode].inv() * TPointD(0, 0);
- if (tool->getName() == "T_Rotate" &&
- tool->getProperties(0)
- ->getProperty("Rotate On Camera Center")
- ->getValueAsString() == "1")
+
+ TPointD center;
+
+ if (RotateOnCameraCenter)
center = TPointD(0, 0);
+ else
+ center = m_viewAff[m_viewMode].inv() * TPointD(0, 0);
+
rotate(center, reverseRotatation);
}
@@ -3413,7 +3467,7 @@ TAffine SceneViewer::getNormalZoomScale() {
void SceneViewer::invalidateToolStatus() {
m_toolHasAssistants = false;
- TTool *tool = TApp::instance()->getCurrentTool()->getTool();
+ TTool *tool = TApp::instance()->getCurrentTool()->getTool();
if (tool) {
m_toolDisableReason = tool->updateEnabled();
if (tool->isEnabled()) {
diff --git a/toonz/sources/toonz/sceneviewer.h b/toonz/sources/toonz/sceneviewer.h
index 82946cf7f..d866a2a03 100644
--- a/toonz/sources/toonz/sceneviewer.h
+++ b/toonz/sources/toonz/sceneviewer.h
@@ -417,6 +417,8 @@ public slots:
void setActualPixelSize();
void flipX();
void flipY();
+ void rotateLeft();
+ void rotateRight();
void zoomIn();
void zoomOut();
void onXsheetChanged();
diff --git a/toonz/sources/toonz/sceneviewercontextmenu.cpp b/toonz/sources/toonz/sceneviewercontextmenu.cpp
index bee5caa18..c724093dd 100644
--- a/toonz/sources/toonz/sceneviewercontextmenu.cpp
+++ b/toonz/sources/toonz/sceneviewercontextmenu.cpp
@@ -51,7 +51,7 @@ SceneViewerContextMenu::SceneViewerContextMenu(SceneViewer *parent)
if (parent->isEditPreviewSubcamera()) {
action = addAction(tr("Reset Subcamera"));
ret = ret && parent->connect(action, SIGNAL(triggered()),
- SLOT(doDeleteSubCamera()));
+ SLOT(doDeleteSubCamera()));
addSeparator();
}
@@ -99,6 +99,20 @@ SceneViewerContextMenu::SceneViewerContextMenu(SceneViewer *parent)
flipViewMenu->addAction(action);
ret = ret && parent->connect(action, SIGNAL(triggered()), SLOT(flipY()));
+ QMenu *rotateViewMenu = addMenu(tr("Rotate View"));
+
+ // Rotate Left
+ action = commandManager->createAction(V_RotateLeft, this);
+ rotateViewMenu->addAction(action);
+ ret = ret && connect(action, &QAction::triggered, parent,
+ &SceneViewer::rotateLeft);
+
+ // Rotate Right
+ action = commandManager->createAction(V_RotateRight, this);
+ rotateViewMenu->addAction(action);
+ ret = ret && connect(action, &QAction::triggered, parent,
+ &SceneViewer::rotateRight);
+
QMenu *resetViewMenu = addMenu(tr("Reset View"));
// reset
@@ -288,8 +302,8 @@ void SceneViewerContextMenu::addShowHideCommand(QMenu *menu,
TXsheet *xsh = TApp::instance()->getCurrentXsheet()->getXsheet();
TStageObject *stageObject =
xsh->getStageObject(TStageObjectId::ColumnId(column->getIndex()));
- QString text = isHidden ? tr("Show %1").arg(getName(stageObject))
- : tr("Hide %1").arg(getName(stageObject));
+ QString text = isHidden ? tr("Show %1").arg(getName(stageObject))
+ : tr("Hide %1").arg(getName(stageObject));
QAction *action = new QAction(text, this);
action->setData(column->getIndex());
connect(action, SIGNAL(triggered()), this, SLOT(onShowHide()));
diff --git a/toonz/sources/toonz/sceneviewerevents.cpp b/toonz/sources/toonz/sceneviewerevents.cpp
index 05092925e..1de05a9bd 100644
--- a/toonz/sources/toonz/sceneviewerevents.cpp
+++ b/toonz/sources/toonz/sceneviewerevents.cpp
@@ -234,6 +234,12 @@ void SceneViewer::onButtonPressed(FlipConsole::EGadget button) {
case FlipConsole::eFlipVertical:
flipY();
break;
+ case FlipConsole::eRotateLeft:
+ rotateLeft();
+ break;
+ case FlipConsole::eRotateRight:
+ rotateRight();
+ break;
case FlipConsole::eResetView:
resetSceneViewer();
break;
@@ -1350,6 +1356,16 @@ public:
return true;
}
+ bool rotateLeft() override {
+ static_cast<SceneViewer *>(getWidget())->rotateLeft();
+ return true;
+ }
+
+ bool rotateRight() override {
+ static_cast<SceneViewer *>(getWidget())->rotateRight();
+ return true;
+ }
+
bool resetZoom() override {
static_cast<SceneViewer *>(getWidget())->resetZoom();
return true;
diff --git a/toonz/sources/toonzqt/flipconsole.cpp b/toonz/sources/toonzqt/flipconsole.cpp
index 7111fcd28..418efa6d5 100644
--- a/toonz/sources/toonzqt/flipconsole.cpp
+++ b/toonz/sources/toonzqt/flipconsole.cpp
@@ -1367,6 +1367,10 @@ void FlipConsole::createPlayToolBar(QWidget *customWidget) {
createButton(eFlipHorizontal, "fliphoriz", tr("&Flip Horizontally"), true);
if (hasButton(m_gadgetsMask, eFlipVertical))
createButton(eFlipVertical, "flipvert", tr("&Flip Vertically"), true);
+ if (hasButton(m_gadgetsMask, eRotateLeft))
+ createButton(eRotateLeft, "rotateleft", tr("&Rotate Left"), false);
+ if (hasButton(m_gadgetsMask, eRotateRight))
+ createButton(eRotateRight, "rotateright", tr("&Rotate Right"), false);
if (hasButton(m_gadgetsMask, eResetView))
createButton(eResetView, "reset", tr("&Reset View"), false);
m_viewerSep = m_playToolBar->addSeparator();
@@ -1782,6 +1786,8 @@ void FlipConsole::doButtonPressed(UINT button) {
case eFlipHorizontal:
case eFlipVertical:
+ case eRotateLeft:
+ case eRotateRight:
case eZoomIn:
case eZoomOut:
case eResetView:
diff --git a/toonz/sources/toonzqt/imageutils.cpp b/toonz/sources/toonzqt/imageutils.cpp
index 49ca3509b..f27b5fc36 100644
--- a/toonz/sources/toonzqt/imageutils.cpp
+++ b/toonz/sources/toonzqt/imageutils.cpp
@@ -871,8 +871,8 @@ namespace {
void getViewerShortcuts(int &zoomIn, int &zoomOut, int &viewReset, int &zoomFit,
int &showHideFullScreen, int &actualPixelSize,
- int &flipX, int &flipY, int &zoomReset,
- int &rotateReset, int &positionReset) {
+ int &flipX, int &flipY, int &rotateL, int &rotateR,
+ int &zoomReset, int &rotateReset, int &positionReset) {
CommandManager *cManager = CommandManager::instance();
zoomIn = cManager->getKeyFromShortcut(cManager->getShortcutFromId(V_ZoomIn));
@@ -888,6 +888,10 @@ void getViewerShortcuts(int &zoomIn, int &zoomOut, int &viewReset, int &zoomFit,
cManager->getShortcutFromId(V_ActualPixelSize));
flipX = cManager->getKeyFromShortcut(cManager->getShortcutFromId(V_FlipX));
flipY = cManager->getKeyFromShortcut(cManager->getShortcutFromId(V_FlipY));
+ rotateL =
+ cManager->getKeyFromShortcut(cManager->getShortcutFromId(V_RotateLeft));
+ rotateR =
+ cManager->getKeyFromShortcut(cManager->getShortcutFromId(V_RotateRight));
zoomReset =
cManager->getKeyFromShortcut(cManager->getShortcutFromId(V_ZoomReset));
rotateReset =
@@ -909,10 +913,11 @@ ShortcutZoomer::ShortcutZoomer(QWidget *zoomingWidget)
bool ShortcutZoomer::exec(QKeyEvent *event) {
int zoomInKey, zoomOutKey, viewResetKey, zoomFitKey, showHideFullScreenKey,
- actualPixelSize, flipX, flipY, zoomReset, rotateReset, positionReset;
+ actualPixelSize, flipX, flipY, rotateL, rotateR, zoomReset, rotateReset,
+ positionReset;
getViewerShortcuts(zoomInKey, zoomOutKey, viewResetKey, zoomFitKey,
showHideFullScreenKey, actualPixelSize, flipX, flipY,
- zoomReset, rotateReset, positionReset);
+ rotateL, rotateR, zoomReset, rotateReset, positionReset);
int key = event->key();
if (key == Qt::Key_Control || key == Qt::Key_Shift || key == Qt::Key_Alt)
@@ -929,6 +934,8 @@ bool ShortcutZoomer::exec(QKeyEvent *event) {
? zoom(key == zoomInKey, key == viewResetKey)
: (key == flipX) ? setFlipX()
: (key == flipY) ? setFlipY()
+ : (key == rotateL) ? rotateLeft()
+ : (key == rotateR) ? rotateRight()
: (key == zoomReset) ? resetZoom()
: (key == rotateReset) ? resetRotation()
: (key == positionReset) ? resetPosition()