Skip to content

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

C

fix crash with visualization commands

shun-iwasawa92d40c810bf3
diff --git a/toonz/sources/include/toonzqt/imageutils.h b/toonz/sources/include/toonzqt/imageutils.h
index 9db2d150c..ce355d90a 100644
--- a/toonz/sources/include/toonzqt/imageutils.h
+++ b/toonz/sources/include/toonzqt/imageutils.h
@@ -101,7 +101,7 @@ void DVAPI convert(
false /*-- ConvertPopup
での指定に合わせて、[レベル名].[フレーム番号].[拡張子]のうち、
[レベル名]と[フレーム番号]の間のドットを消す。 --*/
- ); //!< Converts a saved level to fullcolor, and saves the result.
+); //!< Converts a saved level to fullcolor, and saves the result.
void DVAPI convertNaa2Tlv(
const TFilePath &source, //!< Level path to convert from.
@@ -124,7 +124,7 @@ void DVAPI convertOldLevel2Tlv(
const TFrameId &to, //!< Last source frame to convert.
FrameTaskNotifier
*frameNotifier //!< Observer class for frame success notifications.
- );
+);
double DVAPI getQuantizedZoomFactor(double zf, bool forward);
@@ -140,8 +140,9 @@ void DVAPI assignFillingInformation(TVectorImage &vi,
const std::vector<TFilledRegionInf> &regs);
void DVAPI getStrokeStyleInformationInArea(
- const TVectorImageP &vi, std::vector<std::pair<int, int>>
- &strokesInfo, // pair:strokeIndex, styleIndex
+ const TVectorImageP &vi,
+ std::vector<std::pair<int, int>>
+ &strokesInfo, // pair:strokeIndex, styleIndex
const TRectD &area);
//*********************************************************************************************
@@ -221,7 +222,7 @@ public:
protected:
virtual bool zoom(
bool zoomin,
- bool resetZoom) = 0; //!< Handler for zoom commands. Required.
+ bool resetView) = 0; //!< Handler for zoom commands. Required.
virtual bool fit() {
return false;
} //!< Handler for 'fit to image' commands.
diff --git a/toonz/sources/include/toonzqt/menubarcommand.h b/toonz/sources/include/toonzqt/menubarcommand.h
index eb30a0723..a89fd7a6b 100644
--- a/toonz/sources/include/toonzqt/menubarcommand.h
+++ b/toonz/sources/include/toonzqt/menubarcommand.h
@@ -60,7 +60,8 @@ enum CommandType {
ToolModifierCommandType,
ZoomCommandType,
MiscCommandType,
- MenuCommandType
+ MenuCommandType,
+ VisualizationButtonCommandType
};
//-----------------------------------------------------------------------------
diff --git a/toonz/sources/include/toonzqt/schematicviewer.h b/toonz/sources/include/toonzqt/schematicviewer.h
index 071af6a61..52c6a1693 100644
--- a/toonz/sources/include/toonzqt/schematicviewer.h
+++ b/toonz/sources/include/toonzqt/schematicviewer.h
@@ -106,7 +106,7 @@ public:
SchematicSceneViewer(QWidget *parent);
~SchematicSceneViewer();
- void zoomQt(bool zoomin, bool resetZoom);
+ void zoomQt(bool zoomin, bool resetView);
QPointF getOldScenePos() { return m_oldScenePos; }
@@ -120,10 +120,13 @@ protected:
protected slots:
- void fitScene();
void centerOnCurrent();
void reorderScene();
+
+public slots:
+
void normalizeScene();
+ void fitScene();
private:
Qt::MouseButton m_buttonState;
diff --git a/toonz/sources/include/toonzqt/viewcommandids.h b/toonz/sources/include/toonzqt/viewcommandids.h
index 4fcfad189..c8a8b3aff 100644
--- a/toonz/sources/include/toonzqt/viewcommandids.h
+++ b/toonz/sources/include/toonzqt/viewcommandids.h
@@ -15,4 +15,14 @@
#define V_RotateReset "T_RotateReset"
#define V_PositionReset "T_PositionReset"
+// folloing command ids are for command bar
+#define VB_ViewReset "VB_ViewReset"
+#define VB_ZoomFit "VB_ZoomFit"
+#define VB_ZoomReset "VB_ZoomReset"
+#define VB_RotateReset "VB_RotateReset"
+#define VB_PositionReset "VB_PositionReset"
+#define VB_ActualPixelSize "VB_ActualPixelSize"
+#define VB_FlipX "VB_FlipX"
+#define VB_FlipY "VB_FlipY"
+
#endif // VIEWCOMMANDIDS_H
diff --git a/toonz/sources/toonz/commandbarpopup.cpp b/toonz/sources/toonz/commandbarpopup.cpp
index 8d0a9032a..1197c7711 100644
--- a/toonz/sources/toonz/commandbarpopup.cpp
+++ b/toonz/sources/toonz/commandbarpopup.cpp
@@ -316,7 +316,7 @@ CommandBarListTree::CommandBarListTree(QWidget* parent) : QTreeWidget(parent) {
addFolder(ShortcutTree::tr("Right-click Menu Commands"),
RightClickMenuCommandType);
addFolder(ShortcutTree::tr("Tool Modifiers"), ToolModifierCommandType);
- addFolder(ShortcutTree::tr("Visualization"), ZoomCommandType);
+ addFolder(ShortcutTree::tr("Visualization"), VisualizationButtonCommandType);
addFolder(ShortcutTree::tr("Misc"), MiscCommandType);
addFolder(ShortcutTree::tr("RGBA Channels"), RGBACommandType);
diff --git a/toonz/sources/toonz/imageviewer.cpp b/toonz/sources/toonz/imageviewer.cpp
index 3511aa9a3..661d3722e 100644
--- a/toonz/sources/toonz/imageviewer.cpp
+++ b/toonz/sources/toonz/imageviewer.cpp
@@ -119,8 +119,8 @@ class FlipZoomer final : public ImageUtils::ShortcutZoomer {
public:
FlipZoomer(ImageViewer *parent) : ShortcutZoomer(parent) {}
- bool zoom(bool zoomin, bool resetZoom) override {
- static_cast<ImageViewer *>(getWidget())->zoomQt(zoomin, resetZoom);
+ bool zoom(bool zoomin, bool resetView) override {
+ static_cast<ImageViewer *>(getWidget())->zoomQt(zoomin, resetView);
return true;
}
@@ -129,6 +129,11 @@ public:
return true;
}
+ bool resetZoom() override {
+ static_cast<ImageViewer *>(getWidget())->resetZoom();
+ return true;
+ }
+
bool toggleFullScreen(bool quit) override {
if (ImageUtils::FullScreenWidget *fsWidget =
dynamic_cast<ImageUtils::FullScreenWidget *>(
@@ -383,7 +388,7 @@ ImageViewer::~ImageViewer() {
//-----------------------------------------------------------------------------
/*! Set current image to \b image and update. If Histogram is visible set its
* image.
-*/
+ */
void ImageViewer::setImage(TImageP image) {
m_image = image;
@@ -573,7 +578,7 @@ void ImageViewer::paintGL() {
} else if (m_draggingZoomSelection || m_rectRGBPick) {
fromPos = TPoint(m_pressedMousePos.x - width() * 0.5,
height() * 0.5 - m_pressedMousePos.y);
- toPos = TPoint(m_pos.x() - width() * 0.5, height() * 0.5 - m_pos.y());
+ toPos = TPoint(m_pos.x() - width() * 0.5, height() * 0.5 - m_pos.y());
}
if (fromPos != TPoint() || toPos != TPoint()) {
if (m_rectRGBPick) {
@@ -612,7 +617,7 @@ void ImageViewer::paintGL() {
//------------------------------------------------------------------------------
/*! Add to current trasformation matrix a \b delta traslation.
-*/
+ */
void ImageViewer::panQt(const QPoint &delta) {
if (delta == QPoint()) return;
@@ -676,6 +681,14 @@ void ImageViewer::zoomQt(bool forward, bool reset) {
//-----------------------------------------------------------------------------
+void ImageViewer::resetZoom() {
+ double oldZoomScale = sqrt(m_viewAff.det());
+ setViewAff(TScale(1.0 / oldZoomScale) * m_viewAff);
+ update();
+}
+
+//-----------------------------------------------------------------------------
+
void ImageViewer::dragCompare(const QPoint &dp) {
if (m_compareSettings.m_dragCompareX)
m_compareSettings.m_compareX += ((double)dp.x()) / width();
@@ -746,7 +759,7 @@ void ImageViewer::updateCursor(const TPoint &curPos) {
//---------------------------------------------------------------------------------------------
/*! If middle button is pressed pan the image. Update current mouse position.
-*/
+ */
void ImageViewer::mouseMoveEvent(QMouseEvent *event) {
if (!m_image) return;
@@ -841,7 +854,7 @@ void ImageViewer::mouseMoveEvent(QMouseEvent *event) {
//---------------------------------------------------------------------------------------------
/*! notify the color picked by rgb picker to palette controller
-*/
+ */
void ImageViewer::setPickedColorToStyleEditor(const TPixel32 &color) {
// do not modify the style #0
TPaletteHandle *ph =
@@ -853,7 +866,7 @@ void ImageViewer::setPickedColorToStyleEditor(const TPixel32 &color) {
//---------------------------------------------------------------------------------------------
/*! rgb picking
-*/
+ */
void ImageViewer::pickColor(QMouseEvent *event, bool putValueToStyleEditor) {
if (!m_isHistogramEnable) return;
if (!m_histogramPopup->isVisible()) return;
@@ -897,7 +910,7 @@ void ImageViewer::pickColor(QMouseEvent *event, bool putValueToStyleEditor) {
//---------------------------------------------------------------------------------------------
/*! rectangular rgb picking. The picked color will be an average of pixels in
* specified rectangle
-*/
+ */
void ImageViewer::rectPickColor(bool putValueToStyleEditor) {
if (!m_isHistogramEnable) return;
if (!m_histogramPopup->isVisible()) return;
@@ -1031,7 +1044,7 @@ void ImageViewer::mousePressEvent(QMouseEvent *event) {
//-----------------------------------------------------------------------------
/*! Reset current mouse position and current mouse button event.
-*/
+ */
void ImageViewer::mouseReleaseEvent(QMouseEvent *event) {
if (!m_image) return;
if (m_draggingZoomSelection && !m_visualSettings.m_defineLoadbox) {
@@ -1072,7 +1085,7 @@ void ImageViewer::mouseReleaseEvent(QMouseEvent *event) {
//-----------------------------------------------------------------------------
/*! Apply zoom.
-*/
+ */
void ImageViewer::wheelEvent(QWheelEvent *event) {
if (!m_image) return;
if (event->orientation() == Qt::Horizontal) return;
@@ -1100,12 +1113,12 @@ void ImageViewer::wheelEvent(QWheelEvent *event) {
default: // Qt::MouseEventSynthesizedByQt,
// Qt::MouseEventSynthesizedByApplication
- {
- std::cout << "not supported event: Qt::MouseEventSynthesizedByQt, "
- "Qt::MouseEventSynthesizedByApplication"
- << std::endl;
- break;
- }
+ {
+ std::cout << "not supported event: Qt::MouseEventSynthesizedByQt, "
+ "Qt::MouseEventSynthesizedByApplication"
+ << std::endl;
+ break;
+ }
} // end switch
@@ -1404,10 +1417,9 @@ bool ImageViewer::event(QEvent *e) {
}
*/
- if (e->type() == QEvent::Gesture &&
- CommandManager::instance()
- ->getAction(MI_TouchGestureControl)
- ->isChecked()) {
+ if (e->type() == QEvent::Gesture && CommandManager::instance()
+ ->getAction(MI_TouchGestureControl)
+ ->isChecked()) {
gestureEvent(static_cast<QGestureEvent *>(e));
return true;
}
@@ -1425,7 +1437,7 @@ bool ImageViewer::event(QEvent *e) {
//-----------------------------------------------------------------------------
/*! load image from history
-*/
+ */
class LoadRecentFlipbookImagesCommandHandler final : public MenuItemHandler {
public:
LoadRecentFlipbookImagesCommandHandler()
@@ -1453,7 +1465,7 @@ public:
//-----------------------------------------------------------------------------
/*! clear the history
-*/
+ */
class ClearRecentFlipbookImagesCommandHandler final : public MenuItemHandler {
public:
ClearRecentFlipbookImagesCommandHandler()
diff --git a/toonz/sources/toonz/imageviewer.h b/toonz/sources/toonz/imageviewer.h
index 363af2c98..ecdb09524 100644
--- a/toonz/sources/toonz/imageviewer.h
+++ b/toonz/sources/toonz/imageviewer.h
@@ -109,6 +109,7 @@ public:
*/
void hideHistogram();
void zoomQt(bool forward, bool reset);
+ void resetZoom();
void setIsRemakingPreviewFx(bool on) {
m_isRemakingPreviewFx = on;
diff --git a/toonz/sources/toonz/mainwindow.cpp b/toonz/sources/toonz/mainwindow.cpp
index 3061ae741..e451ad204 100644
--- a/toonz/sources/toonz/mainwindow.cpp
+++ b/toonz/sources/toonz/mainwindow.cpp
@@ -527,7 +527,7 @@ Room *MainWindow::getRoom(int index) const {
//-----------------------------------------------------------------------------
/*! Roomを名前から探す
-*/
+ */
Room *MainWindow::getRoomByName(QString &roomName) {
for (int i = 0; i < getRoomCount(); i++) {
Room *room = dynamic_cast<Room *>(m_stackedWidget->widget(i));
@@ -1154,7 +1154,7 @@ void MainWindow::onMenuCheckboxChanged() {
#endif
else if (cm->getAction(MI_RasterizePli) == action) {
if (!QGLPixelBuffer::hasOpenGLPbuffers()) isChecked = 0;
- RasterizePliToggleAction = isChecked;
+ RasterizePliToggleAction = isChecked;
} else if (cm->getAction(MI_SafeArea) == action)
SafeAreaToggleAction = isChecked;
else if (cm->getAction(MI_ViewColorcard) == action)
@@ -1434,6 +1434,13 @@ QAction *MainWindow::createViewerAction(const char *id, const QString &name,
//-----------------------------------------------------------------------------
+QAction *MainWindow::createVisualizationButtonAction(const char *id,
+ const QString &name) {
+ return createAction(id, name, "", VisualizationButtonCommandType);
+}
+
+//-----------------------------------------------------------------------------
+
QAction *MainWindow::createMiscAction(const char *id, const QString &name,
const char *defaultShortcut) {
QAction *action = new DVAction(name, this);
@@ -2114,6 +2121,21 @@ void MainWindow::defineActions() {
tr("Full Screen Mode"),
tr("Exit Full Screen Mode"));
+ // Following actions are for adding "Visualization" menu items to the command
+ // bar. They are separated from the original actions in order to avoid
+ // assigning shortcut keys. They must be triggered only from pressing buttons
+ // in the command bar. Assinging shortcut keys and registering as MenuItem
+ // will break a logic of ShortcutZoomer. So here we register separate items
+ // and bypass the command.
+ createVisualizationButtonAction(VB_ViewReset, tr("Reset View"));
+ createVisualizationButtonAction(VB_ZoomFit, tr("Fit to Window"));
+ createVisualizationButtonAction(VB_ZoomReset, tr("Reset Zoom"));
+ createVisualizationButtonAction(VB_RotateReset, tr("Reset Rotation"));
+ createVisualizationButtonAction(VB_PositionReset, tr("Reset Position"));
+ createVisualizationButtonAction(VB_ActualPixelSize, tr("Actual Pixel Size"));
+ createVisualizationButtonAction(VB_FlipX, tr("Flip Viewer Horizontally"));
+ createVisualizationButtonAction(VB_FlipY, tr("Flip Viewer Vertically"));
+
QAction *refreshAct =
createMiscAction(MI_RefreshTree, tr("Refresh Folder Tree"), "");
refreshAct->setIconText(tr("Refresh"));
@@ -2345,9 +2367,9 @@ RecentFiles::~RecentFiles() {}
void RecentFiles::addFilePath(QString path, FileType fileType,
QString projectName) {
QList<QString> files =
- (fileType == Scene) ? m_recentScenes : (fileType == Level)
- ? m_recentLevels
- : m_recentFlipbookImages;
+ (fileType == Scene)
+ ? m_recentScenes
+ : (fileType == Level) ? m_recentLevels : m_recentFlipbookImages;
int i;
for (i = 0; i < files.size(); i++)
if (files.at(i) == path) {
@@ -2514,9 +2536,9 @@ void RecentFiles::saveRecentFiles() {
QList<QString> RecentFiles::getFilesNameList(FileType fileType) {
QList<QString> files =
- (fileType == Scene) ? m_recentScenes : (fileType == Level)
- ? m_recentLevels
- : m_recentFlipbookImages;
+ (fileType == Scene)
+ ? m_recentScenes
+ : (fileType == Level) ? m_recentLevels : m_recentFlipbookImages;
QList<QString> names;
int i;
for (i = 0; i < files.size(); i++) {
@@ -2543,9 +2565,9 @@ void RecentFiles::refreshRecentFilesMenu(FileType fileType) {
menu->setEnabled(false);
else {
CommandId clearActionId =
- (fileType == Scene) ? MI_ClearRecentScene : (fileType == Level)
- ? MI_ClearRecentLevel
- : MI_ClearRecentImage;
+ (fileType == Scene)
+ ? MI_ClearRecentScene
+ : (fileType == Level) ? MI_ClearRecentLevel : MI_ClearRecentImage;
menu->setActions(names);
menu->addSeparator();
QAction *clearAction = CommandManager::instance()->getAction(clearActionId);
diff --git a/toonz/sources/toonz/mainwindow.h b/toonz/sources/toonz/mainwindow.h
index 9c7d94e13..ebb09f4d9 100644
--- a/toonz/sources/toonz/mainwindow.h
+++ b/toonz/sources/toonz/mainwindow.h
@@ -175,6 +175,9 @@ private:
const QString &defaultShortcut);
QAction *createViewerAction(const char *id, const QString &name,
const QString &defaultShortcut);
+ // For command bar, no shortcut keys
+ QAction *createVisualizationButtonAction(const char *id, const QString &name);
+
QAction *createMiscAction(const char *id, const QString &name,
const char *defaultShortcut);
QAction *createToolOptionsAction(const char *id, const QString &name,
diff --git a/toonz/sources/toonz/sceneviewer.cpp b/toonz/sources/toonz/sceneviewer.cpp
index 008cf7bc9..774d04c6e 100644
--- a/toonz/sources/toonz/sceneviewer.cpp
+++ b/toonz/sources/toonz/sceneviewer.cpp
@@ -452,61 +452,80 @@ public:
}
} resetShiftTraceCommand;
+//-----------------------------------------------------------------------------
+// Following commands (VB_***) are registered for command bar buttons.
+// They are separatd from the original visalization commands
+// so that they will not break a logic of ShortcutZoomer.
+
class TViewResetCommand final : public MenuItemHandler {
public:
- TViewResetCommand() : MenuItemHandler(V_ViewReset) {}
+ TViewResetCommand() : MenuItemHandler(VB_ViewReset) {}
void execute() override {
- TApp::instance()->getActiveViewer()->resetSceneViewer();
+ if (TApp::instance()->getActiveViewer())
+ TApp::instance()->getActiveViewer()->resetSceneViewer();
}
} viewResetCommand;
class TZoomResetCommand final : public MenuItemHandler {
public:
- TZoomResetCommand() : MenuItemHandler(V_ZoomReset) {}
- void execute() override { TApp::instance()->getActiveViewer()->resetZoom(); }
+ TZoomResetCommand() : MenuItemHandler(VB_ZoomReset) {}
+ void execute() override {
+ if (TApp::instance()->getActiveViewer())
+ TApp::instance()->getActiveViewer()->resetZoom();
+ }
} zoomResetCommand;
class TZoomFitCommand final : public MenuItemHandler {
public:
- TZoomFitCommand() : MenuItemHandler(V_ZoomFit) {}
+ TZoomFitCommand() : MenuItemHandler(VB_ZoomFit) {}
void execute() override {
- TApp::instance()->getActiveViewer()->fitToCamera();
+ if (TApp::instance()->getActiveViewer())
+ TApp::instance()->getActiveViewer()->fitToCamera();
}
} zoomFitCommand;
class TActualPixelSizeCommand final : public MenuItemHandler {
public:
- TActualPixelSizeCommand() : MenuItemHandler(V_ActualPixelSize) {}
+ TActualPixelSizeCommand() : MenuItemHandler(VB_ActualPixelSize) {}
void execute() override {
- TApp::instance()->getActiveViewer()->setActualPixelSize();
+ if (TApp::instance()->getActiveViewer())
+ TApp::instance()->getActiveViewer()->setActualPixelSize();
}
-} aActualPixelSizeCommand;
+} actualPixelSizeCommand;
class TFlipViewerXCommand final : public MenuItemHandler {
public:
- TFlipViewerXCommand() : MenuItemHandler(V_FlipX) {}
- void execute() override { TApp::instance()->getActiveViewer()->flipX(); }
+ TFlipViewerXCommand() : MenuItemHandler(VB_FlipX) {}
+ void execute() override {
+ if (TApp::instance()->getActiveViewer())
+ TApp::instance()->getActiveViewer()->flipX();
+ }
} flipViewerXCommand;
class TFlipViewerYCommand final : public MenuItemHandler {
public:
- TFlipViewerYCommand() : MenuItemHandler(V_FlipY) {}
- void execute() override { TApp::instance()->getActiveViewer()->flipY(); }
+ TFlipViewerYCommand() : MenuItemHandler(VB_FlipY) {}
+ void execute() override {
+ if (TApp::instance()->getActiveViewer())
+ TApp::instance()->getActiveViewer()->flipY();
+ }
} flipViewerYCommand;
class TRotateResetCommand final : public MenuItemHandler {
public:
- TRotateResetCommand() : MenuItemHandler(V_RotateReset) {}
+ TRotateResetCommand() : MenuItemHandler(VB_RotateReset) {}
void execute() override {
- TApp::instance()->getActiveViewer()->resetRotation();
+ if (TApp::instance()->getActiveViewer())
+ TApp::instance()->getActiveViewer()->resetRotation();
}
} rotateResetCommand;
class TPositionResetCommand final : public MenuItemHandler {
public:
- TPositionResetCommand() : MenuItemHandler(V_PositionReset) {}
+ TPositionResetCommand() : MenuItemHandler(VB_PositionReset) {}
void execute() override {
- TApp::instance()->getActiveViewer()->resetPosition();
+ if (TApp::instance()->getActiveViewer())
+ TApp::instance()->getActiveViewer()->resetPosition();
}
} positionResetCommand;
@@ -1696,7 +1715,7 @@ double SceneViewer::projectToZ(const TPointD &delta) {
GLint viewport[4];
double modelview[16], projection[16];
glGetIntegerv(GL_VIEWPORT, viewport);
- for (int i = 0; i < 16; i++)
+ for (int i = 0; i < 16; i++)
projection[i] = (double)m_projectionMatrix.constData()[i];
glGetDoublev(GL_MODELVIEW_MATRIX, modelview);
@@ -1858,8 +1877,9 @@ void SceneViewer::zoomQt(bool forward, bool reset) {
if (reset || ((m_zoomScale3D < 500 || !forward) &&
(m_zoomScale3D > 0.01 || forward))) {
double oldZoomScale = m_zoomScale3D;
- m_zoomScale3D = reset ? 1 : ImageUtils::getQuantizedZoomFactor(
- m_zoomScale3D, forward);
+ m_zoomScale3D =
+ reset ? 1
+ : ImageUtils::getQuantizedZoomFactor(m_zoomScale3D, forward);
m_pan3D = -(m_zoomScale3D / oldZoomScale) * -m_pan3D;
}
@@ -1880,17 +1900,18 @@ void SceneViewer::zoomQt(bool forward, bool reset) {
int i;
for (i = 0; i < 2; i++) {
- TAffine &viewAff = m_viewAff[i];
+ TAffine &viewAff = m_viewAff[i];
if (m_isFlippedX) viewAff = viewAff * TScale(-1, 1);
if (m_isFlippedX) viewAff = viewAff * TScale(1, -1);
- double scale2 = std::abs(viewAff.det());
+ double scale2 = std::abs(viewAff.det());
if (m_isFlippedX) viewAff = viewAff * TScale(-1, 1);
if (m_isFlippedX) viewAff = viewAff * TScale(1, -1);
if (reset || ((scale2 < 100000 || !forward) &&
(scale2 > 0.001 * 0.05 || forward))) {
double oldZoomScale = sqrt(scale2) * dpiFactor;
- double zoomScale = reset ? 1 : ImageUtils::getQuantizedZoomFactor(
- oldZoomScale, forward);
+ double zoomScale =
+ reset ? 1
+ : ImageUtils::getQuantizedZoomFactor(oldZoomScale, forward);
// threshold value -0.001 is intended to absorb the error of calculation
if ((oldZoomScale - zoomScaleFittingWithScreen) *
@@ -2162,9 +2183,9 @@ void SceneViewer::fitToCamera() {
TPointD P11 = cameraAff * cameraRect.getP11();
TPointD p0 = TPointD(std::min({P00.x, P01.x, P10.x, P11.x}),
std::min({P00.y, P01.y, P10.y, P11.y}));
- TPointD p1 = TPointD(std::max({P00.x, P01.x, P10.x, P11.x}),
+ TPointD p1 = TPointD(std::max({P00.x, P01.x, P10.x, P11.x}),
std::max({P00.y, P01.y, P10.y, P11.y}));
- cameraRect = TRectD(p0.x, p0.y, p1.x, p1.y);
+ cameraRect = TRectD(p0.x, p0.y, p1.x, p1.y);
// Pan
if (!is3DView()) {
@@ -2213,8 +2234,8 @@ void SceneViewer::resetZoom() {
TPointD realCenter(m_viewAff[m_viewMode].a13, m_viewAff[m_viewMode].a23);
TAffine aff =
getNormalZoomScale() * TRotation(realCenter, m_rotationAngle[m_viewMode]);
- aff.a13 = realCenter.x;
- aff.a23 = realCenter.y;
+ aff.a13 = realCenter.x;
+ aff.a23 = realCenter.y;
if (m_isFlippedX) aff = aff * TScale(-1, 1);
if (m_isFlippedY) aff = aff * TScale(1, -1);
setViewMatrix(aff, m_viewMode);
@@ -2271,16 +2292,17 @@ void SceneViewer::setActualPixelSize() {
} else
dpi = sl->getDpi(fid);
- const double inch = Stage::inch;
- TAffine tempAff = getNormalZoomScale();
- if (m_isFlippedX) tempAff = tempAff * TScale(-1, 1);
- if (m_isFlippedY) tempAff = tempAff * TScale(1, -1);
- TPointD tempScale = dpi;
+ const double inch = Stage::inch;
+ TAffine tempAff = getNormalZoomScale();
+ if (m_isFlippedX) tempAff = tempAff * TScale(-1, 1);
+ if (m_isFlippedY) tempAff = tempAff * TScale(1, -1);
+ TPointD tempScale = dpi;
if (m_isFlippedX) tempScale.x = -tempScale.x;
if (m_isFlippedY) tempScale.y = -tempScale.y;
for (int i = 0; i < tArrayCount(m_viewAff); i++)
- setViewMatrix(dpi == TPointD(0, 0) ? tempAff : TScale(tempScale.x / inch,
- tempScale.y / inch),
+ setViewMatrix(dpi == TPointD(0, 0)
+ ? tempAff
+ : TScale(tempScale.x / inch, tempScale.y / inch),
i);
m_pos = QPoint(0, 0);
@@ -2563,7 +2585,7 @@ void drawSpline(const TAffine &viewMatrix, const TRect &clipRect, bool camera3d,
TStageObject *pegbar =
objId != TStageObjectId::NoneId ? xsh->getStageObject(objId) : 0;
- const TStroke *stroke = 0;
+ const TStroke *stroke = 0;
if (pegbar && pegbar->getSpline()) stroke = pegbar->getSpline()->getStroke();
if (!stroke) return;
diff --git a/toonz/sources/toonz/sceneviewerevents.cpp b/toonz/sources/toonz/sceneviewerevents.cpp
index 688db2e61..6fb6fea7b 100644
--- a/toonz/sources/toonz/sceneviewerevents.cpp
+++ b/toonz/sources/toonz/sceneviewerevents.cpp
@@ -70,7 +70,7 @@ namespace {
void initToonzEvent(TMouseEvent &toonzEvent, QMouseEvent *event,
int widgetHeight, double pressure, int devPixRatio) {
- toonzEvent.m_pos = TPointD(event->pos().x() * devPixRatio,
+ toonzEvent.m_pos = TPointD(event->pos().x() * devPixRatio,
widgetHeight - 1 - event->pos().y() * devPixRatio);
toonzEvent.m_mousePos = event->pos();
toonzEvent.m_pressure = 1.0;
@@ -813,9 +813,9 @@ quit:
// Don't clear it out table state so the tablePress event will process
// correctly.
if (m_tabletState != Touched) m_tabletState = None;
- m_mouseState = None;
- m_tabletMove = false;
- m_pressure = 0;
+ m_mouseState = None;
+ m_tabletMove = false;
+ m_pressure = 0;
// Leave m_tabletEvent as-is in order to check whether the onRelease is called
// from tabletEvent or not in mouseReleaseEvent.
if (m_tabletState == Released) // only clear if tabletRelease event
@@ -871,12 +871,12 @@ void SceneViewer::wheelEvent(QWheelEvent *event) {
default: // Qt::MouseEventSynthesizedByQt,
// Qt::MouseEventSynthesizedByApplication
- {
- std::cout << "not supported event: Qt::MouseEventSynthesizedByQt, "
- "Qt::MouseEventSynthesizedByApplication"
- << std::endl;
- break;
- }
+ {
+ std::cout << "not supported event: Qt::MouseEventSynthesizedByQt, "
+ "Qt::MouseEventSynthesizedByApplication"
+ << std::endl;
+ break;
+ }
} // end switch
@@ -968,8 +968,8 @@ void SceneViewer::gestureEvent(QGestureEvent *e) {
qreal rotationDelta =
gesture->rotationAngle() - gesture->lastRotationAngle();
if (m_isFlippedX != m_isFlippedY) rotationDelta = -rotationDelta;
- TAffine aff = getViewMatrix().inv();
- TPointD center = aff * TPointD(0, 0);
+ TAffine aff = getViewMatrix().inv();
+ TPointD center = aff * TPointD(0, 0);
if (!m_rotating && !m_zooming) {
m_rotationDelta += rotationDelta;
double absDelta = abs(m_rotationDelta);
@@ -1110,10 +1110,9 @@ bool SceneViewer::event(QEvent *e) {
break;
}
*/
- if (e->type() == QEvent::Gesture &&
- CommandManager::instance()
- ->getAction(MI_TouchGestureControl)
- ->isChecked()) {
+ if (e->type() == QEvent::Gesture && CommandManager::instance()
+ ->getAction(MI_TouchGestureControl)
+ ->isChecked()) {
gestureEvent(static_cast<QGestureEvent *>(e));
return true;
}
@@ -1183,11 +1182,11 @@ class ViewerZoomer final : public ImageUtils::ShortcutZoomer {
public:
ViewerZoomer(SceneViewer *parent) : ShortcutZoomer(parent) {}
- bool zoom(bool zoomin, bool resetZoom) override {
+ bool zoom(bool zoomin, bool resetView) override {
SceneViewer *sceneViewer = static_cast<SceneViewer *>(getWidget());
- resetZoom ? sceneViewer->resetSceneViewer()
- : sceneViewer->zoomQt(zoomin, resetZoom);
+ resetView ? sceneViewer->resetSceneViewer()
+ : sceneViewer->zoomQt(zoomin, resetView);
return true;
}
@@ -1212,6 +1211,21 @@ public:
return true;
}
+ bool resetZoom() override {
+ static_cast<SceneViewer *>(getWidget())->resetZoom();
+ return true;
+ }
+
+ bool resetRotation() override {
+ static_cast<SceneViewer *>(getWidget())->resetRotation();
+ return true;
+ }
+
+ bool resetPosition() override {
+ static_cast<SceneViewer *>(getWidget())->resetPosition();
+ return true;
+ }
+
bool toggleFullScreen(bool quit) override {
if (ImageUtils::FullScreenWidget *fsWidget =
dynamic_cast<ImageUtils::FullScreenWidget *>(
diff --git a/toonz/sources/toonzqt/schematicviewer.cpp b/toonz/sources/toonzqt/schematicviewer.cpp
index db61b9210..080723ec6 100644
--- a/toonz/sources/toonzqt/schematicviewer.cpp
+++ b/toonz/sources/toonzqt/schematicviewer.cpp
@@ -52,8 +52,16 @@ class SchematicZoomer final : public ImageUtils::ShortcutZoomer {
public:
SchematicZoomer(QWidget *parent) : ShortcutZoomer(parent) {}
- bool zoom(bool zoomin, bool resetZoom) override {
- static_cast<SchematicSceneViewer *>(getWidget())->zoomQt(zoomin, resetZoom);
+ bool zoom(bool zoomin, bool resetView) override {
+ static_cast<SchematicSceneViewer *>(getWidget())->zoomQt(zoomin, resetView);
+ return true;
+ }
+ bool resetZoom() override {
+ static_cast<SchematicSceneViewer *>(getWidget())->normalizeScene();
+ return true;
+ }
+ bool fit() override {
+ static_cast<SchematicSceneViewer *>(getWidget())->fitScene();
return true;
}
};
@@ -95,7 +103,7 @@ void SchematicScene::hideEvent(QHideEvent *se) {
//------------------------------------------------------------------
/*! Removes and then deletes all item in the scene.
-*/
+ */
void SchematicScene::clearAllItems() {
clearSelection();
@@ -143,7 +151,7 @@ void SchematicScene::clearAllItems() {
//------------------------------------------------------------------
/*! check if any item exists in the rect
-*/
+ */
bool SchematicScene::isAnEmptyZone(const QRectF &rect) {
QList<QGraphicsItem *> allItems = items();
for (auto const level : allItems) {
@@ -207,7 +215,7 @@ SchematicSceneViewer::~SchematicSceneViewer() {}
//------------------------------------------------------------------
/*! Reimplemets the QGraphicsView::mousePressEvent()
-*/
+ */
void SchematicSceneViewer::mousePressEvent(QMouseEvent *me) {
m_buttonState = me->button();
m_oldWinPos = me->pos();
@@ -233,7 +241,7 @@ void SchematicSceneViewer::mousePressEvent(QMouseEvent *me) {
//------------------------------------------------------------------
/*! Reimplemets the QGraphicsView::mouseMoveEvent()
-*/
+ */
void SchematicSceneViewer::mouseMoveEvent(QMouseEvent *me) {
QPoint currWinPos = me->pos();
QPointF currScenePos = mapToScene(currWinPos);
@@ -257,7 +265,7 @@ void SchematicSceneViewer::mouseMoveEvent(QMouseEvent *me) {
//------------------------------------------------------------------
/*! Reimplemets the QGraphicsView::mouseReleaseEvent()
-*/
+ */
void SchematicSceneViewer::mouseReleaseEvent(QMouseEvent *me) {
m_buttonState = Qt::NoButton;
QGraphicsView::mouseReleaseEvent(me);
@@ -276,7 +284,7 @@ void SchematicSceneViewer::keyPressEvent(QKeyEvent *ke) {
//------------------------------------------------------------------
/*! Reimplemets the QGraphicsView::wheelEvent()
-*/
+ */
void SchematicSceneViewer::wheelEvent(QWheelEvent *me) {
me->accept();
double factor = exp(me->delta() * 0.001);
@@ -285,33 +293,38 @@ void SchematicSceneViewer::wheelEvent(QWheelEvent *me) {
//------------------------------------------------------------------
-void SchematicSceneViewer::zoomQt(bool zoomin, bool resetZoom) {
+void SchematicSceneViewer::zoomQt(bool zoomin, bool resetView) {
+ if (resetView) {
+ resetMatrix();
+ // reseting will set view to the center of items bounding
+ centerOn(scene()->itemsBoundingRect().center());
+ return;
+ }
+
#if QT_VERSION >= 0x050000
double scale2 = matrix().determinant();
#else
double scale2 = matrix().det();
#endif
- if (resetZoom ||
- ((scale2 < 100000 || !zoomin) && (scale2 > 0.001 * 0.05 || zoomin))) {
+ if ((scale2 < 100000 || !zoomin) && (scale2 > 0.001 * 0.05 || zoomin)) {
double oldZoomScale = sqrt(scale2);
- double zoomScale = resetZoom ? 1 : ImageUtils::getQuantizedZoomFactor(
- oldZoomScale, zoomin);
+ double zoomScale =
+ resetView ? 1
+ : ImageUtils::getQuantizedZoomFactor(oldZoomScale, zoomin);
QMatrix scale =
QMatrix().scale(zoomScale / oldZoomScale, zoomScale / oldZoomScale);
// See QGraphicsView::mapToScene()'s doc for details
- QRect rect(0, 0, width(), height());
- QRectF sceneCenterRect(
- mapToScene(QRect(rect.center(), QSize(2, 2))).boundingRect());
+ QPointF sceneCenter(mapToScene(rect().center()));
setMatrix(scale, true);
- centerOn(sceneCenterRect.center());
+ centerOn(sceneCenter);
}
}
//------------------------------------------------------------------
/*! The view is scaled around the point \b winPos by \b scaleFactor;
-*/
+ */
void SchematicSceneViewer::changeScale(const QPoint &winPos,
qreal scaleFactor) {
QPointF startScenePos = mapToScene(winPos);
@@ -350,14 +363,12 @@ void SchematicSceneViewer::reorderScene() {
void SchematicSceneViewer::normalizeScene() {
// See QGraphicsView::mapToScene()'s doc for details
- QRect rect(0, 0, width(), height());
- QRectF sceneCenterRect(
- mapToScene(QRect(rect.center(), QSize(2, 2))).boundingRect());
+ QPointF sceneCenter(mapToScene(rect().center()));
resetMatrix();
#if defined(MACOSX)
scale(1.32, 1.32);
#endif
- centerOn(sceneCenterRect.center());
+ centerOn(sceneCenter);
}
//------------------------------------------------------------------
@@ -587,10 +598,10 @@ void SchematicViewer::createActions() {
QIcon nodeSizeIcon = createQIconOnOff(
m_maximizedNode ? "minimizenodes" : "maximizenodes", false);
- m_nodeSize =
- new QAction(nodeSizeIcon, m_maximizedNode ? tr("&Minimize Nodes")
- : tr("&Maximize Nodes"),
- m_commonToolbar);
+ m_nodeSize = new QAction(
+ nodeSizeIcon,
+ m_maximizedNode ? tr("&Minimize Nodes") : tr("&Maximize Nodes"),
+ m_commonToolbar);
connect(m_nodeSize, SIGNAL(triggered()), this, SLOT(changeNodeSize()));
if (m_fullSchematic) {