OpenToonz - An open-source full-featured 2D animation creation software
C
Interactive canvas size
Ahl7654ef7e634bdf
diff --git a/toonz/sources/include/tools/toolcommandids.h b/toonz/sources/include/tools/toolcommandids.hindex 9cc4462b5..ea4bf54d5 100644--- a/toonz/sources/include/tools/toolcommandids.h+++ b/toonz/sources/include/tools/toolcommandids.h@@ -31,6 +31,7 @@#define T_Ruler "T_Ruler"#define T_Finger "T_Finger"#define T_EditAssistants "T_EditAssistants"+#define T_CanvasSize "T_CanvasSize"// Viewer Navigation tools (available only during the shortcut key is pressed)#define T_ZoomView "T_ZoomView"diff --git a/toonz/sources/toonz/canvassizepopup.cpp b/toonz/sources/toonz/canvassizepopup.cppindex 318b1d752..40e7842c3 100644--- a/toonz/sources/toonz/canvassizepopup.cpp+++ b/toonz/sources/toonz/canvassizepopup.cpp@@ -15,6 +15,22 @@// TnzLib includes#include "toonz/txshlevelhandle.h"#include "toonz/levelproperties.h"+#include "toonz/txshleveltypes.h"+#include "toonz/tcamera.h"+#include "toonz/toonzscene.h"+#include "toonz/tscenehandle.h"+#include "toonz/txsheethandle.h"+#include "toonz/tstageobjectid.h"+#include "toonz/txsheet.h"+#include "toonz/tstageobject.h"+#include "toonz/tstageobjecttree.h"++// TnzTools includes+#include "tools/tool.h"+#include "tools/toolcommandids.h"+#include "tools/toolhandle.h"+#include "tools/cursors.h"+#include "tools/toolutils.h"// TnzBase includes#include "tunit.h"@@ -24,8 +40,11 @@#include "ttoonzimage.h"#include "trop.h"#include "tundo.h"-#include "tconvert.h"#include "timagecache.h"+#include "tgl.h"+#include "tcurveutil.h"+#include "tcurves.h"+#include "tenv.h"// Qt includes#include <QLabel>@@ -36,6 +55,11 @@#include <QButtonGroup>#include <QApplication>#include <QMainWindow>+#include <QHideEvent>+#include <QKeyEvent>+#include <algorithm>++TEnv::IntVar CanvasSizeShowCropConfirm("CanvasSizeShowCropConfirm", 1);namespace {@@ -120,6 +144,73 @@ int ResizeCanvasUndo::m_idCount = 0;//-----------------------------------------------------------------------------+class CanvasCameraUndo final : public TUndo {+ TStageObjectId m_cameraId;+ TDimensionD m_oldSize, m_newSize;+ TDimension m_oldRes, m_newRes;++ static void apply(TStageObjectId cameraId, const TDimensionD &size,+ const TDimension &res) {+ ToonzScene *scene = TApp::instance()->getCurrentScene()->getScene();+ if (!scene) return;+ TStageObject *obj = scene->getXsheet()->getStageObject(cameraId);+ if (!obj) return;+ TCamera *camera = obj->getCamera();+ if (!camera) return;+ camera->setSize(size);+ camera->setRes(res);+ TApp::instance()->getCurrentScene()->notifySceneChanged();+ TApp::instance()->getCurrentXsheet()->notifyXsheetChanged();+ }++public:+ CanvasCameraUndo(TStageObjectId cameraId, const TDimensionD &oldSize,+ const TDimension &oldRes, const TDimensionD &newSize,+ const TDimension &newRes)+ : m_cameraId(cameraId)+ , m_oldSize(oldSize)+ , m_newSize(newSize)+ , m_oldRes(oldRes)+ , m_newRes(newRes) {}++ void undo() const override { apply(m_cameraId, m_oldSize, m_oldRes); }+ void redo() const override { apply(m_cameraId, m_newSize, m_newRes); }+ int getSize() const override { return sizeof(*this); }+};++//-----------------------------------------------------------------------------++void applyCameraFromLevel(TXshSimpleLevel *sl) {+ if (!sl) return;+ TPointD dpi = sl->getDpi();+ TDimension res = sl->getResolution();+ if (res.lx <= 0 || res.ly <= 0 || dpi.x <= 0 || dpi.y <= 0) return;++ TDimensionD size(res.lx / dpi.x, res.ly / dpi.y);+ ToonzScene *scene = TApp::instance()->getCurrentScene()->getScene();+ TXsheet *xsh = scene->getXsheet();+ TStageObjectId cameraId = xsh->getStageObjectTree()->getCurrentCameraId();+ TStageObject *cameraObject = xsh->getStageObject(cameraId);+ if (!cameraObject) return;+ TCamera *camera = cameraObject->getCamera();+ if (!camera) return;+ TDimensionD oldSize = camera->getSize();+ TDimension oldRes = camera->getRes();+ if (oldRes == res && areAlmostEqual(oldSize.lx, size.lx) &&+ areAlmostEqual(oldSize.ly, size.ly))+ return;++ camera->setSize(size);+ camera->setRes(res);+ TUndoManager::manager()->add(+ new CanvasCameraUndo(cameraId, oldSize, oldRes, size, res));+ TApp::instance()->getCurrentScene()->setDirtyFlag(true);+ TApp::instance()->getCurrentScene()->notifySceneChanged();+ TApp::instance()->getCurrentXsheet()->notifyXsheetChanged();+}++//-----------------------------------------------------------------------------+double getMeasuredLength(int pixelLength, TMeasure *measure, double dpi,const QString &unit) {if (unit == "pixel") return pixelLength;@@ -137,6 +228,114 @@ int getPixelLength(double measuredLength, TMeasure *measure, double dpi,double inchValue = measure->getCurrentUnit()->convertFrom(measuredLength);return tround(inchValue * dpi);}++//-----------------------------------------------------------------------------++} // namespace++bool isRasterCanvasLevel(TXshSimpleLevel *sl) {+ if (!sl) return false;+ int type = sl->getType();+ return type == TZP_XSHLEVEL || type == OVL_XSHLEVEL || type == TZI_XSHLEVEL;+}++void updateCanvasSizeCommandEnabled() {+ TApp *app = TApp::instance();+ if (!app || !app->getCurrentLevel()) {+ CommandManager::instance()->enable(MI_CanvasSize, false);+ return;+ }+ CommandManager::instance()->enable(+ MI_CanvasSize,+ isRasterCanvasLevel(app->getCurrentLevel()->getSimpleLevel()));+}++namespace {++//-----------------------------------------------------------------------------++TRectD worldRectFromDim(const TDimension &dim) {+ if (dim.lx < 1 || dim.ly < 1) return TRectD();+ return TRectD(0.0, 0.0, (double)dim.lx, (double)dim.ly) -+ TPointD(0.5 * dim.lx, 0.5 * dim.ly);+}++//-----------------------------------------------------------------------------++TRectD snapRectToPixelGrid(const TRectD &rect, const TRectD &grid) {+ TRectD out;+ out.x0 = grid.x0 + tround(rect.x0 - grid.x0);+ out.y0 = grid.y0 + tround(rect.y0 - grid.y0);+ out.x1 = grid.x0 + tround(rect.x1 - grid.x0);+ out.y1 = grid.y0 + tround(rect.y1 - grid.y0);+ if (out.x1 < out.x0 + 1.0) out.x1 = out.x0 + 1.0;+ if (out.y1 < out.y0 + 1.0) out.y1 = out.y0 + 1.0;+ return out;+}++//-----------------------------------------------------------------------------++TRectD proposedRectFromPeg(const TRectD &oldR, int newLx, int newLy,+ PeggingPositions peg) {+ newLx = std::max(1, newLx);+ newLy = std::max(1, newLy);+ TRectD r;++ if (peg == e00 || peg == e10 || peg == e20) {+ r.x0 = oldR.x0;+ r.x1 = oldR.x0 + newLx;+ } else if (peg == e02 || peg == e12 || peg == e22) {+ r.x1 = oldR.x1;+ r.x0 = oldR.x1 - newLx;+ } else {+ double cx = 0.5 * (oldR.x0 + oldR.x1);+ r.x0 = cx - 0.5 * newLx;+ r.x1 = cx + 0.5 * newLx;+ }++ if (peg == e20 || peg == e21 || peg == e22) {+ r.y0 = oldR.y0;+ r.y1 = oldR.y0 + newLy;+ } else if (peg == e00 || peg == e01 || peg == e02) {+ r.y1 = oldR.y1;+ r.y0 = oldR.y1 - newLy;+ } else {+ double cy = 0.5 * (oldR.y0 + oldR.y1);+ r.y0 = cy - 0.5 * newLy;+ r.y1 = cy + 0.5 * newLy;+ }+ return r;+}++//-----------------------------------------------------------------------------++TDimension dimFromRect(const TRectD &rect) {+ return TDimension(std::max(1, tround(rect.x1 - rect.x0)),+ std::max(1, tround(rect.y1 - rect.y0)));+}++//-----------------------------------------------------------------------------++bool canvasCopyWouldCrop(const TDimension &srcDim, const TDimension &dstDim,+ const TPoint &pos) {+ return pos.x < 0 || pos.y < 0 || pos.x + srcDim.lx > dstDim.lx ||+ pos.y + srcDim.ly > dstDim.ly;+}++//-----------------------------------------------------------------------------++TRectD rectUnion(const TRectD &a, const TRectD &b) {+ if (a.isEmpty()) return b;+ if (b.isEmpty()) return a;+ return TRectD(std::min(a.x0, b.x0), std::min(a.y0, b.y0),+ std::max(a.x1, b.x1), std::max(a.y1, b.y1));+}++//-----------------------------------------------------------------------------++bool isNavigationToolName(const QString &name) {+ return name == T_HandView || name == T_ZoomView || name == T_RotateView;+}} // namespace//=============================================================================// PeggingWidget@@ -224,7 +423,8 @@ void PeggingWidget::createButton(QPushButton **button,QPixmap pix(1, 1);switch (position) {case e00:- pix = m_topRightPix.transformed(QTransform().rotate(-90), Qt::SmoothTransformation);+ pix = m_topRightPix.transformed(QTransform().rotate(-90),+ Qt::SmoothTransformation);break;case e01:pix = m_topPix;@@ -233,19 +433,24 @@ void PeggingWidget::createButton(QPushButton **button,pix = m_topRightPix;break;case e10:- pix = m_topPix.transformed(QTransform().rotate(-90), Qt::SmoothTransformation);+ pix = m_topPix.transformed(QTransform().rotate(-90),+ Qt::SmoothTransformation);break;case e12:- pix = m_topPix.transformed(QTransform().rotate(90), Qt::SmoothTransformation);+ pix =+ m_topPix.transformed(QTransform().rotate(90), Qt::SmoothTransformation);break;case e20:- pix = m_topRightPix.transformed(QTransform().rotate(180), Qt::SmoothTransformation);+ pix = m_topRightPix.transformed(QTransform().rotate(180),+ Qt::SmoothTransformation);break;case e21:- pix = m_topPix.transformed(QTransform().rotate(180), Qt::SmoothTransformation);+ pix = m_topPix.transformed(QTransform().rotate(180),+ Qt::SmoothTransformation);break;case e22:- pix = m_topRightPix.transformed(QTransform().rotate(90), Qt::SmoothTransformation);+ pix = m_topRightPix.transformed(QTransform().rotate(90),+ Qt::SmoothTransformation);break;default:break;@@ -257,14 +462,15 @@ void PeggingWidget::createButton(QPushButton **button,void PeggingWidget::on00() {m_pegging = e00;+ emit peggingChanged();QPixmap pix(30, 30);pix.fill(Qt::transparent);m_00->setIcon(pix);m_01->setIcon(m_topPix.transformed(QTransform().rotate(m_cutLx ? -90 : 90),Qt::SmoothTransformation));- m_11->setIcon(- m_topRightPix.transformed(QTransform().rotate(m_cutLx || m_cutLy ? -90 : 90),- Qt::SmoothTransformation));+ m_11->setIcon(m_topRightPix.transformed(+ QTransform().rotate(m_cutLx || m_cutLy ? -90 : 90),+ Qt::SmoothTransformation));m_10->setIcon(m_topPix.transformed(QTransform().rotate(m_cutLy ? 0 : 180),Qt::SmoothTransformation));@@ -279,19 +485,20 @@ void PeggingWidget::on00() {void PeggingWidget::on01() {m_pegging = e01;+ emit peggingChanged();QPixmap pix(30, 30);pix.fill(Qt::transparent);m_01->setIcon(pix);m_00->setIcon(m_topPix.transformed(QTransform().rotate(m_cutLx ? 90 : -90),Qt::SmoothTransformation));- m_10->setIcon(- m_topRightPix.transformed(QTransform().rotate(m_cutLx || m_cutLy ? 0 : 180),- Qt::SmoothTransformation));+ m_10->setIcon(m_topRightPix.transformed(+ QTransform().rotate(m_cutLx || m_cutLy ? 0 : 180),+ Qt::SmoothTransformation));m_11->setIcon(m_topPix.transformed(QTransform().rotate(m_cutLy ? 0 : 180),Qt::SmoothTransformation));- m_12->setIcon(- m_topRightPix.transformed(QTransform().rotate(m_cutLx || m_cutLy ? -90 : 90),- Qt::SmoothTransformation));+ m_12->setIcon(m_topRightPix.transformed(+ QTransform().rotate(m_cutLx || m_cutLy ? -90 : 90),+ Qt::SmoothTransformation));m_02->setIcon(m_topPix.transformed(QTransform().rotate(m_cutLx ? -90 : 90),Qt::SmoothTransformation));@@ -304,14 +511,15 @@ void PeggingWidget::on01() {void PeggingWidget::on02() {m_pegging = e02;+ emit peggingChanged();QPixmap pix(30, 30);pix.fill(Qt::transparent);m_02->setIcon(pix);m_01->setIcon(m_topPix.transformed(QTransform().rotate(m_cutLx ? 90 : -90),Qt::SmoothTransformation));- m_11->setIcon(- m_topRightPix.transformed(QTransform().rotate(m_cutLx || m_cutLy ? 0 : 180),- Qt::SmoothTransformation));+ m_11->setIcon(m_topRightPix.transformed(+ QTransform().rotate(m_cutLx || m_cutLy ? 0 : 180),+ Qt::SmoothTransformation));m_12->setIcon(m_topPix.transformed(QTransform().rotate(m_cutLy ? 0 : 180),Qt::SmoothTransformation));@@ -326,19 +534,20 @@ void PeggingWidget::on02() {void PeggingWidget::on10() {m_pegging = e10;+ emit peggingChanged();QPixmap pix(30, 30);pix.fill(Qt::transparent);m_10->setIcon(pix);m_00->setIcon(m_topPix.transformed(QTransform().rotate(m_cutLy ? 180 : 0),Qt::SmoothTransformation));- m_01->setIcon(- m_topRightPix.transformed(QTransform().rotate(m_cutLx || m_cutLy ? 180 : 0),- Qt::SmoothTransformation));+ m_01->setIcon(m_topRightPix.transformed(+ QTransform().rotate(m_cutLx || m_cutLy ? 180 : 0),+ Qt::SmoothTransformation));m_11->setIcon(m_topPix.transformed(QTransform().rotate(m_cutLx ? -90 : 90),Qt::SmoothTransformation));- m_21->setIcon(- m_topRightPix.transformed(QTransform().rotate(m_cutLx || m_cutLy ? -90 : 90),- Qt::SmoothTransformation));+ m_21->setIcon(m_topRightPix.transformed(+ QTransform().rotate(m_cutLx || m_cutLy ? -90 : 90),+ Qt::SmoothTransformation));m_20->setIcon(m_topPix.transformed(QTransform().rotate(m_cutLy ? 0 : 180),Qt::SmoothTransformation));@@ -351,48 +560,50 @@ void PeggingWidget::on10() {void PeggingWidget::on11() {m_pegging = e11;+ emit peggingChanged();QPixmap pix(30, 30);pix.fill(Qt::transparent);m_11->setIcon(pix);- m_00->setIcon(- m_topRightPix.transformed(QTransform().rotate(m_cutLx || m_cutLy ? 90 : -90),- Qt::SmoothTransformation));+ m_00->setIcon(m_topRightPix.transformed(+ QTransform().rotate(m_cutLx || m_cutLy ? 90 : -90),+ Qt::SmoothTransformation));m_01->setIcon(m_topPix.transformed(QTransform().rotate(m_cutLy ? 180 : 0),Qt::SmoothTransformation));- m_02->setIcon(- m_topRightPix.transformed(QTransform().rotate(m_cutLx || m_cutLy ? 180 : 0),- Qt::SmoothTransformation));+ m_02->setIcon(m_topRightPix.transformed(+ QTransform().rotate(m_cutLx || m_cutLy ? 180 : 0),+ Qt::SmoothTransformation));m_10->setIcon(m_topPix.transformed(QTransform().rotate(m_cutLx ? 90 : -90),Qt::SmoothTransformation));m_12->setIcon(m_topPix.transformed(QTransform().rotate(m_cutLx ? -90 : 90),Qt::SmoothTransformation));- m_20->setIcon(- m_topRightPix.transformed(QTransform().rotate(m_cutLx || m_cutLy ? 0 : 180),- Qt::SmoothTransformation));+ m_20->setIcon(m_topRightPix.transformed(+ QTransform().rotate(m_cutLx || m_cutLy ? 0 : 180),+ Qt::SmoothTransformation));m_21->setIcon(m_topPix.transformed(QTransform().rotate(m_cutLy ? 0 : 180),Qt::SmoothTransformation));- m_22->setIcon(- m_topRightPix.transformed(QTransform().rotate(m_cutLx || m_cutLy ? -90 : 90),- Qt::SmoothTransformation));+ m_22->setIcon(m_topRightPix.transformed(+ QTransform().rotate(m_cutLx || m_cutLy ? -90 : 90),+ Qt::SmoothTransformation));}//-----------------------------------------------------------------------------void PeggingWidget::on12() {m_pegging = e12;+ emit peggingChanged();QPixmap pix(30, 30);pix.fill(Qt::transparent);m_12->setIcon(pix);m_02->setIcon(m_topPix.transformed(QTransform().rotate(m_cutLy ? 180 : 0),Qt::SmoothTransformation));- m_01->setIcon(- m_topRightPix.transformed(QTransform().rotate(m_cutLx || m_cutLy ? 90 : -90),- Qt::SmoothTransformation));+ m_01->setIcon(m_topRightPix.transformed(+ QTransform().rotate(m_cutLx || m_cutLy ? 90 : -90),+ Qt::SmoothTransformation));m_11->setIcon(m_topPix.transformed(QTransform().rotate(m_cutLx ? 90 : -90),Qt::SmoothTransformation));- m_21->setIcon(- m_topRightPix.transformed(QTransform().rotate(m_cutLx || m_cutLy ? 0 : 180),- Qt::SmoothTransformation));+ m_21->setIcon(m_topRightPix.transformed(+ QTransform().rotate(m_cutLx || m_cutLy ? 0 : 180),+ Qt::SmoothTransformation));m_22->setIcon(m_topPix.transformed(QTransform().rotate(m_cutLy ? 0 : 180),Qt::SmoothTransformation));@@ -405,14 +616,15 @@ void PeggingWidget::on12() {void PeggingWidget::on20() {m_pegging = e20;+ emit peggingChanged();QPixmap pix(30, 30);pix.fill(Qt::transparent);m_20->setIcon(pix);m_10->setIcon(m_topPix.transformed(QTransform().rotate(m_cutLy ? 180 : 0),Qt::SmoothTransformation));- m_11->setIcon(- m_topRightPix.transformed(QTransform().rotate(m_cutLx || m_cutLy ? 180 : 0),- Qt::SmoothTransformation));+ m_11->setIcon(m_topRightPix.transformed(+ QTransform().rotate(m_cutLx || m_cutLy ? 180 : 0),+ Qt::SmoothTransformation));m_21->setIcon(m_topPix.transformed(QTransform().rotate(m_cutLx ? -90 : 90),Qt::SmoothTransformation));@@ -427,19 +639,20 @@ void PeggingWidget::on20() {void PeggingWidget::on21() {m_pegging = e21;+ emit peggingChanged();QPixmap pix(30, 30);pix.fill(Qt::transparent);m_21->setIcon(pix);m_20->setIcon(m_topPix.transformed(QTransform().rotate(m_cutLx ? 90 : -90),Qt::SmoothTransformation));- m_10->setIcon(- m_topRightPix.transformed(QTransform().rotate(m_cutLx || m_cutLy ? 90 : -90),- Qt::SmoothTransformation));+ m_10->setIcon(m_topRightPix.transformed(+ QTransform().rotate(m_cutLx || m_cutLy ? 90 : -90),+ Qt::SmoothTransformation));m_11->setIcon(m_topPix.transformed(QTransform().rotate(m_cutLy ? 180 : 0),Qt::SmoothTransformation));- m_12->setIcon(- m_topRightPix.transformed(QTransform().rotate(m_cutLx || m_cutLy ? 180 : 0),- Qt::SmoothTransformation));+ m_12->setIcon(m_topRightPix.transformed(+ QTransform().rotate(m_cutLx || m_cutLy ? 180 : 0),+ Qt::SmoothTransformation));m_22->setIcon(m_topPix.transformed(QTransform().rotate(m_cutLx ? -90 : 90),Qt::SmoothTransformation));@@ -452,14 +665,15 @@ void PeggingWidget::on21() {void PeggingWidget::on22() {m_pegging = e22;+ emit peggingChanged();QPixmap pix(30, 30);pix.fill(Qt::transparent);m_22->setIcon(pix);m_12->setIcon(m_topPix.transformed(QTransform().rotate(m_cutLy ? 180 : 0),Qt::SmoothTransformation));- m_11->setIcon(- m_topRightPix.transformed(QTransform().rotate(m_cutLx || m_cutLy ? 90 : -90),- Qt::SmoothTransformation));+ m_11->setIcon(m_topRightPix.transformed(+ QTransform().rotate(m_cutLx || m_cutLy ? 90 : -90),+ Qt::SmoothTransformation));m_21->setIcon(m_topPix.transformed(QTransform().rotate(m_cutLx ? 90 : -90),Qt::SmoothTransformation));@@ -504,15 +718,483 @@ void PeggingWidget::updateAnchor() {}}+//-----------------------------------------------------------------------------++void PeggingWidget::setPeggingPosition(PeggingPositions position) {+ if (m_pegging == position) return;+ switch (position) {+ case e00:+ m_00->setChecked(true);+ on00();+ break;+ case e01:+ m_01->setChecked(true);+ on01();+ break;+ case e02:+ m_02->setChecked(true);+ on02();+ break;+ case e10:+ m_10->setChecked(true);+ on10();+ break;+ case e11:+ m_11->setChecked(true);+ on11();+ break;+ case e12:+ m_12->setChecked(true);+ on12();+ break;+ case e20:+ m_20->setChecked(true);+ on20();+ break;+ case e21:+ m_21->setChecked(true);+ on21();+ break;+ case e22:+ m_22->setChecked(true);+ on22();+ break;+ }+}++//=============================================================================+// CanvasSizeTool+//-----------------------------------------------------------------------------++class CanvasSizeTool final : public TTool {+ TPointD m_firstPos;+ TRectD m_dragStartRect, m_lastInvalidateRect;+ int m_handle;+ bool m_dragging;++ enum { hNone, hMove, h00, h01, h10, h11, hM0, h1M, hM1, h0M };++public:+ static CanvasSizeTool *instance() { return s_instance; }++ CanvasSizeTool()+ : TTool(T_CanvasSize)+ , m_firstPos(-1, -1)+ , m_handle(hNone)+ , m_dragging(false) {+ s_instance = this;+ bind(TTool::ToonzImage | TTool::RasterImage);+ }++ ToolType getToolType() const override { return TTool::LevelReadTool; }+ unsigned int getToolHints() const override { return 0; }+ bool isDragging() const override { return m_dragging; }++ QString updateEnabled(int, int) override {+ TTool::Application *app = getApplication();+ if (!app || !app->getCurrentLevel()) return (enable(false), QString());+ if (isRasterCanvasLevel(app->getCurrentLevel()->getSimpleLevel()))+ return (enable(true), QString());+ return (enable(false), QString());+ }++ void draw() override;+ void mouseMove(const TPointD &p, const TMouseEvent &) override;+ void leftButtonDown(const TPointD &pos, const TMouseEvent &) override;+ void leftButtonDrag(const TPointD &pos, const TMouseEvent &e) override;+ void leftButtonUp(const TPointD &, const TMouseEvent &) override;+ int getCursorId() const override;+ void onActivate() override;+ void onDeactivate() override;+ bool isEventAcceptable(QEvent *e) override;++ void refresh(bool wholeViewer);++private:+ int pickHandle(const TPointD &p, const TRectD &r) const;+ PeggingPositions pegForHandle(int handle) const;+ TRectD dragRect(const TPointD &pos, const TMouseEvent &e) const;++ static CanvasSizeTool *s_instance;+};++CanvasSizeTool *CanvasSizeTool::s_instance = 0;+CanvasSizeTool canvasSizeTool;++//-----------------------------------------------------------------------------++int CanvasSizeTool::pickHandle(const TPointD &p, const TRectD &r) const {+ double pixelSize = getPixelSize();+ TPointD size(10 * pixelSize, 10 * pixelSize);+ double maxDist = 5 * pixelSize;++ if (TRectD(r.getP00() - size, r.getP00() + size).contains(p)) return h00;+ if (TRectD(r.getP01() - size, r.getP01() + size).contains(p)) return h01;+ if (TRectD(r.getP11() - size, r.getP11() + size).contains(p)) return h11;+ if (TRectD(r.getP10() - size, r.getP10() + size).contains(p)) return h10;+ if (isCloseToSegment(p, TSegment(r.getP00(), r.getP10()), maxDist))+ return hM0;+ if (isCloseToSegment(p, TSegment(r.getP10(), r.getP11()), maxDist))+ return h1M;+ if (isCloseToSegment(p, TSegment(r.getP11(), r.getP01()), maxDist))+ return hM1;+ if (isCloseToSegment(p, TSegment(r.getP01(), r.getP00()), maxDist))+ return h0M;+ if (r.contains(p)) return hMove;+ return hNone;+}++//-----------------------------------------------------------------------------++PeggingPositions CanvasSizeTool::pegForHandle(int handle) const {+ CanvasSizePopup *popup = CanvasSizePopup::instance();+ if (!popup) return ::e11;+ PeggingPositions cur = popup->peggingPosition();++ int row = (int)cur / 3;+ int col = (int)cur % 3;++ switch (handle) {+ case h00:+ return ::e02;+ case h01:+ return ::e22;+ case h10:+ return ::e00;+ case h11:+ return ::e20;+ case h0M:+ col = 2;+ break;+ case h1M:+ col = 0;+ break;+ case hM0:+ row = 0;+ break;+ case hM1:+ row = 2;+ break;+ default:+ return cur;+ }+ return (PeggingPositions)(row * 3 + col);+}++//-----------------------------------------------------------------------------++TRectD CanvasSizeTool::dragRect(const TPointD &pos,+ const TMouseEvent &e) const {+ TRectD r = m_dragStartRect;+ TPointD delta = pos - m_firstPos;++ if (m_handle == hMove) {+ if (e.isShiftPressed()) {+ if (fabs(delta.x) > fabs(delta.y))+ delta.y = 0;+ else+ delta.x = 0;+ }+ r.x0 += delta.x;+ r.x1 += delta.x;+ r.y0 += delta.y;+ r.y1 += delta.y;+ return r;+ }++ CanvasSizePopup *popup = CanvasSizePopup::instance();+ bool uniform = e.isShiftPressed();+ if (popup && popup->isPercentMode()) uniform = true;+ const bool fromCenter = e.isAltPressed();+ double W = r.x1 - r.x0;+ double H = r.y1 - r.y0;+ if (W < 1.0) W = 1.0;+ if (H < 1.0) H = 1.0;+ double ar = W / H;+ if (uniform && popup && popup->isPercentMode()) {+ const TDimension cur = popup->currentCanvasDim();+ if (cur.ly > 0) ar = (double)cur.lx / cur.ly;+ }+ const double cx = 0.5 * (r.x0 + r.x1);+ const double cy = 0.5 * (r.y0 + r.y1);++ const bool moveL = m_handle == h00 || m_handle == h01 || m_handle == h0M;+ const bool moveR = m_handle == h10 || m_handle == h11 || m_handle == h1M;+ const bool moveB = m_handle == h00 || m_handle == h10 || m_handle == hM0;+ const bool moveT = m_handle == h01 || m_handle == h11 || m_handle == hM1;++ double dW = 0, dH = 0;+ if (moveR) dW += delta.x;+ if (moveL) dW -= delta.x;+ if (moveT) dH += delta.y;+ if (moveB) dH -= delta.y;+ if (fromCenter) {+ dW *= 2.0;+ dH *= 2.0;+ }++ if (uniform) {+ const bool isCorner = (moveL || moveR) && (moveB || moveT);+ if (isCorner) {+ if (fabs(dW) * H >= fabs(dH) * W)+ dH = dW / ar;+ else+ dW = dH * ar;+ } else if (moveL || moveR)+ dH = dW / ar;+ else+ dW = dH * ar;+ }++ double newW = std::max(1.0, W + dW);+ double newH = std::max(1.0, H + dH);+ if (uniform) {+ if (moveL || moveR)+ newH = std::max(1.0, newW / ar);+ else+ newW = std::max(1.0, newH * ar);+ }++ if (fromCenter) {+ r.x0 = cx - 0.5 * newW;+ r.x1 = cx + 0.5 * newW;+ r.y0 = cy - 0.5 * newH;+ r.y1 = cy + 0.5 * newH;+ return r;+ }++ if (moveL && !moveR)+ r.x0 = r.x1 - newW;+ else if (moveR && !moveL)+ r.x1 = r.x0 + newW;+ else {+ r.x0 = cx - 0.5 * newW;+ r.x1 = cx + 0.5 * newW;+ }++ if (moveB && !moveT)+ r.y0 = r.y1 - newH;+ else if (moveT && !moveB)+ r.y1 = r.y0 + newH;+ else {+ r.y0 = cy - 0.5 * newH;+ r.y1 = cy + 0.5 * newH;+ }+ return r;+}++//-----------------------------------------------------------------------------++void CanvasSizeTool::draw() {+ CanvasSizePopup *popup = CanvasSizePopup::instance();+ if (!popup || !popup->isSessionActive()) return;++ TRectD currentR = popup->currentCanvasRect();+ TRectD proposedR = popup->proposedCanvasRect();+ if (currentR.isEmpty() && proposedR.isEmpty()) return;++ double pixelSize = getPixelSize();+ double handleR = 4.0 * pixelSize;++ glEnable(GL_BLEND);+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);+ glColor4d(0.15, 0.65, 0.95, 0.12);+ glBegin(GL_QUADS);+ glVertex2d(proposedR.x0, proposedR.y0);+ glVertex2d(proposedR.x1, proposedR.y0);+ glVertex2d(proposedR.x1, proposedR.y1);+ glVertex2d(proposedR.x0, proposedR.y1);+ glEnd();+ glDisable(GL_BLEND);++ glEnable(GL_LINE_STIPPLE);+ glLineStipple(1, 0xCCCC);+ glColor3d(0.85, 0.85, 0.85);+ glBegin(GL_LINE_LOOP);+ glVertex2d(currentR.x0, currentR.y0);+ glVertex2d(currentR.x1, currentR.y0);+ glVertex2d(currentR.x1, currentR.y1);+ glVertex2d(currentR.x0, currentR.y1);+ glEnd();+ glDisable(GL_LINE_STIPPLE);++ glColor3d(0.2, 0.85, 1.0);+ glBegin(GL_LINE_LOOP);+ glVertex2d(proposedR.x0, proposedR.y0);+ glVertex2d(proposedR.x1, proposedR.y0);+ glVertex2d(proposedR.x1, proposedR.y1);+ glVertex2d(proposedR.x0, proposedR.y1);+ glEnd();++ TPixel32 handleColor(70, 210, 255);+ ToolUtils::drawSquare(proposedR.getP00(), handleR, handleColor);+ ToolUtils::drawSquare(proposedR.getP01(), handleR, handleColor);+ ToolUtils::drawSquare(proposedR.getP10(), handleR, handleColor);+ ToolUtils::drawSquare(proposedR.getP11(), handleR, handleColor);+ TPointD center(0.5 * (proposedR.x0 + proposedR.x1),+ 0.5 * (proposedR.y0 + proposedR.y1));+ ToolUtils::drawSquare(TPointD(center.x, proposedR.y0), handleR, handleColor);+ ToolUtils::drawSquare(TPointD(proposedR.x1, center.y), handleR, handleColor);+ ToolUtils::drawSquare(TPointD(center.x, proposedR.y1), handleR, handleColor);+ ToolUtils::drawSquare(TPointD(proposedR.x0, center.y), handleR, handleColor);++ TPointD labelPos = proposedR.getP01() + TPointD(0, 4 * pixelSize);+ glPushMatrix();+ glTranslated(labelPos.x, labelPos.y, 0);+ glScaled(2, 2, 2);+ tglDrawText(TPointD(), "Canvas");+ glPopMatrix();+}++//-----------------------------------------------------------------------------++void CanvasSizeTool::mouseMove(const TPointD &p, const TMouseEvent &) {+ if (m_dragging) return;+ CanvasSizePopup *popup = CanvasSizePopup::instance();+ if (!popup || !popup->isSessionActive()) {+ m_handle = hNone;+ return;+ }+ m_handle = pickHandle(p, popup->proposedCanvasRect());+}++//-----------------------------------------------------------------------------++void CanvasSizeTool::leftButtonDown(const TPointD &pos, const TMouseEvent &) {+ CanvasSizePopup *popup = CanvasSizePopup::instance();+ if (!popup || !popup->isSessionActive()) return;++ m_firstPos = pos;+ m_dragStartRect = popup->proposedCanvasRect();+ m_handle = pickHandle(pos, m_dragStartRect);+ m_dragging = m_handle != hNone;+}++//-----------------------------------------------------------------------------++void CanvasSizeTool::leftButtonDrag(const TPointD &pos, const TMouseEvent &e) {+ if (!m_dragging) return;+ CanvasSizePopup *popup = CanvasSizePopup::instance();+ if (!popup || !popup->isSessionActive()) return;++ TRectD next = dragRect(pos, e);+ PeggingPositions peg = popup->peggingPosition();+ if (m_handle != hMove)+ peg = e.isAltPressed() ? ::e11 : pegForHandle(m_handle);+ popup->setProposedRectFromTool(next, peg);+}++//-----------------------------------------------------------------------------++void CanvasSizeTool::leftButtonUp(const TPointD &, const TMouseEvent &) {+ m_dragging = false;+ m_firstPos = TPointD(-1, -1);+ m_dragStartRect = TRectD();+}++//-----------------------------------------------------------------------------++int CanvasSizeTool::getCursorId() const {+ switch (m_handle) {+ case hMove:+ return ToolCursor::MoveCursor;+ case h11:+ case h00:+ return ToolCursor::ScaleCursor;+ case h10:+ case h01:+ return ToolCursor::ScaleInvCursor;+ case h1M:+ case h0M:+ return ToolCursor::ScaleHCursor;+ case hM1:+ case hM0:+ return ToolCursor::ScaleVCursor;+ default:+ return ToolCursor::CURSOR_ARROW;+ }+}++//-----------------------------------------------------------------------------++void CanvasSizeTool::onActivate() { refresh(true); }++//-----------------------------------------------------------------------------++void CanvasSizeTool::onDeactivate() {+ if (m_dragging) return;+ CanvasSizePopup *popup = CanvasSizePopup::instance();+ if (!popup || !popup->isSessionActive()) return;++ TTool::Application *app = getApplication();+ if (!app || !app->getCurrentTool()) return;+ QString next = app->getCurrentTool()->getRequestedToolName();+ if (isNavigationToolName(next) || next == T_CanvasSize) return;+ popup->cancelFromOutside();+}++//-----------------------------------------------------------------------------++bool CanvasSizeTool::isEventAcceptable(QEvent *e) {+ CanvasSizePopup *popup = CanvasSizePopup::instance();+ if (!popup || !popup->isSessionActive()) return false;+ if (e->type() != QEvent::KeyPress && e->type() != QEvent::ShortcutOverride)+ return false;+ int key = static_cast<QKeyEvent *>(e)->key();+ return key == Qt::Key_Shift || key == Qt::Key_Alt || key == Qt::Key_AltGr ||+ key == Qt::Key_Control;+}++//-----------------------------------------------------------------------------++void CanvasSizeTool::refresh(bool wholeViewer) {+ CanvasSizePopup *popup = CanvasSizePopup::instance();+ if (wholeViewer || !popup) {+ m_lastInvalidateRect = TRectD();+ invalidate();+ return;+ }++ TRectD box =+ rectUnion(popup->currentCanvasRect(), popup->proposedCanvasRect());+ box = box.enlarge(24.0 * getPixelSize());+ TRectD dirty = rectUnion(m_lastInvalidateRect, box);+ if (!dirty.isEmpty()) invalidate(dirty);+ m_lastInvalidateRect = box;+}+//=============================================================================// CanvasSizePopup//-----------------------------------------------------------------------------+namespace {+CanvasSizePopup *s_canvasSizePopup = 0;+}++CanvasSizePopup *CanvasSizePopup::instance() { return s_canvasSizePopup; }++PeggingPositions CanvasSizePopup::peggingPosition() const {+ return m_pegging->getPeggingPosition();+}++//-----------------------------------------------------------------------------+CanvasSizePopup::CanvasSizePopup()- : DVGui::Dialog(TApp::instance()->getMainWindow(), true, true,- "CanvasSize") {- m_sl = TApp::instance()->getCurrentLevel()->getSimpleLevel();- assert(m_sl);+ : DVGui::Dialog(TApp::instance()->getMainWindow(), true, true, "CanvasSize")+ , m_currentDim(1, 1)+ , m_sessionActive(false)+ , m_ignoreSync(false)+ , m_fromTool(false) {+ s_canvasSizePopup = this;+ TXshLevelHandle *lh = TApp::instance()->getCurrentLevel();+ m_sl = lh ? lh->getSimpleLevel() : TXshSimpleLevelP();+ TDimension dim = m_sl ? m_sl->getResolution() : TDimension(1, 1);+ m_currentDim = dim;+ m_currentRect = m_proposedRect = worldRectFromDim(dim);++ setModal(false);+ setWindowModality(Qt::NonModal);+ setWindowFlags(windowFlags() | Qt::Tool);setWindowTitle(tr("Canvas Size"));setMinimumSize(QSize(300, 350));@@ -520,15 +1202,11 @@ CanvasSizePopup::CanvasSizePopup()addSeparator(tr("Current Size"));- TDimension dim = m_sl->getResolution();-- // Current Xsizem_currentXSize = new QLabel(QString::number(dim.lx));m_currentXSize->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);m_currentXSize->setFixedHeight(DVGui::WidgetHeight);addWidget(tr("Width:"), m_currentXSize);- // Current Ysizem_currentYSize = new QLabel(QString::number(dim.ly));m_currentYSize->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);m_currentYSize->setFixedHeight(DVGui::WidgetHeight);@@ -536,122 +1214,393 @@ CanvasSizePopup::CanvasSizePopup()addSeparator(tr("New Size"));- // Unitm_unit = new QComboBox(this);m_unit->addItem(tr("pixel"), "pixel");m_unit->addItem(tr("mm"), "mm");m_unit->addItem(tr("cm"), "cm");m_unit->addItem(tr("field"), "field");m_unit->addItem(tr("inch"), "inch");- m_unit->setFixedHeight(DVGui::WidgetHeight);+ m_unit->setFixedSize(80, DVGui::WidgetHeight);addWidget(tr("Unit:"), m_unit);connect(m_unit, SIGNAL(currentIndexChanged(int)), this,SLOT(onUnitChanged(int)));- // New Xsizem_xSizeFld = new DVGui::DoubleLineEdit(this, dim.lx);m_xSizeFld->setFixedSize(80, DVGui::WidgetHeight);addWidget(tr("Width:"), m_xSizeFld);connect(m_xSizeFld, SIGNAL(textChanged(const QString &)), this,SLOT(onSizeChanged()));- // New Ysizem_ySizeFld = new DVGui::DoubleLineEdit(this, dim.ly);m_ySizeFld->setFixedSize(80, DVGui::WidgetHeight);addWidget(tr("Height:"), m_ySizeFld);connect(m_ySizeFld, SIGNAL(textChanged(const QString &)), this,SLOT(onSizeChanged()));- // Relative+ m_percentMode = new DVGui::CheckBox(tr("Percent"), this);+ m_percentMode->setFixedHeight(DVGui::WidgetHeight);+ m_percentMode->setChecked(false);+ m_percentFld = new DVGui::MeasuredDoubleLineEdit(this);+ m_percentFld->setMeasure("percentage");+ m_percentFld->setDecimals(2);+ m_percentFld->setValue(1.0);+ m_percentFld->setFixedSize(80, DVGui::WidgetHeight);+ m_percentFld->setEnabled(false);+ addWidgets(m_percentMode, m_percentFld);+ connect(m_percentMode, SIGNAL(toggled(bool)), this,+ SLOT(onPercentMode(bool)));+ connect(m_percentFld, SIGNAL(textChanged(const QString &)), this,+ SLOT(onSizeChanged()));+m_relative = new DVGui::CheckBox(tr("Relative"), this);m_relative->setFixedHeight(DVGui::WidgetHeight);m_relative->setChecked(false);connect(m_relative, SIGNAL(toggled(bool)), this, SLOT(onRelative(bool)));- addWidget(m_relative);++ m_updateCamera = new DVGui::CheckBox(tr("Set Camera"), this);+ m_updateCamera->setFixedHeight(DVGui::WidgetHeight);+ m_updateCamera->setChecked(false);++ addWidgets(m_updateCamera, m_relative);addSeparator(tr("Anchor"));+ m_confirmCrop = new DVGui::CheckBox(tr("Confirm crop"), this);+ m_confirmCrop->setFixedHeight(DVGui::WidgetHeight);+ m_confirmCrop->setChecked((int)CanvasSizeShowCropConfirm != 0);+ connect(m_confirmCrop, SIGNAL(toggled(bool)), this,+ SLOT(onConfirmCropToggled(bool)));+m_pegging = new PeggingWidget(this);- addWidget("", m_pegging);+ addWidgets(m_confirmCrop, m_pegging);+ connect(m_pegging, SIGNAL(peggingChanged()), this, SLOT(onPeggingChanged()));endVLayout();- // add buttonsQPushButton *okBtn = new QPushButton(tr("Resize"), this);okBtn->setDefault(true);+ QPushButton *resetBtn = new QPushButton(tr("Reset"), this);QPushButton *cancelBtn = new QPushButton(tr("Cancel"), this);connect(okBtn, SIGNAL(clicked()), this, SLOT(onOkBtn()));+ connect(resetBtn, SIGNAL(clicked()), this, SLOT(onReset()));connect(cancelBtn, SIGNAL(clicked()), this, SLOT(reject()));- addButtonBarWidget(okBtn, cancelBtn);+ addButtonBarWidget(okBtn, resetBtn, cancelBtn);+ setButtonBarSpacing(8);+ okBtn->setMinimumSize(50, 25);+ resetBtn->setMinimumSize(50, 25);+ cancelBtn->setMinimumSize(50, 25);m_xMeasure = TMeasureManager::instance()->get("canvas.lx");m_yMeasure = TMeasureManager::instance()->get("canvas.ly");++ connect(TApp::instance()->getCurrentLevel(),+ SIGNAL(xshLevelSwitched(TXshLevel *)), this,+ SLOT(onLevelSwitched(TXshLevel *)));+ connect(TApp::instance()->getCurrentScene(), SIGNAL(sceneSwitched()), this,+ SLOT(onSceneSwitched()));+ updateCanvasSizeCommandEnabled();}//------------------------------------------------------------------------------void CanvasSizePopup::showEvent(QShowEvent *e) {- m_sl = TApp::instance()->getCurrentLevel()->getSimpleLevel();- assert(m_sl);- TDimension dim = m_sl->getResolution();- TPointD dpi = m_sl->getDpi();- double dimLx = getMeasuredLength(dim.lx, m_xMeasure, dpi.x,- m_unit->currentData().toString());- double dimLy = getMeasuredLength(dim.ly, m_yMeasure, dpi.y,- m_unit->currentData().toString());+bool CanvasSizePopup::isPercentMode() const {+ return m_percentMode->isChecked();+}++//-----------------------------------------------------------------------------++void CanvasSizePopup::openSession() {+ if (isVisible()) {+ hide();+ return;+ }+ TApp *app = TApp::instance();+ if (!app || !app->getCurrentLevel()) return;+ TXshSimpleLevel *sl = app->getCurrentLevel()->getSimpleLevel();+ if (!isRasterCanvasLevel(sl)) return;+ show();+ raise();+ activateWindow();+}++//-----------------------------------------------------------------------------++void CanvasSizePopup::cancelFromOutside() {+ if (!isVisible()) return;+ hide();+}++//-----------------------------------------------------------------------------++void CanvasSizePopup::refreshOverlay(bool wholeViewer) {+ if (CanvasSizeTool::instance())+ CanvasSizeTool::instance()->refresh(wholeViewer);+}++//-----------------------------------------------------------------------------++void CanvasSizePopup::initFromLevel() {+ TXshLevelHandle *lh = TApp::instance()->getCurrentLevel();+ m_sl = lh ? lh->getSimpleLevel() : TXshSimpleLevelP();+ if (!isRasterCanvasLevel(m_sl.getPointer())) return;++ m_currentDim = m_sl->getResolution();+ m_currentRect = worldRectFromDim(m_currentDim);+ m_proposedRect = m_currentRect;++ TPointD dpi = m_sl->getDpi();+ QString unit = m_unit->currentData().toString();+ double dimLx = getMeasuredLength(m_currentDim.lx, m_xMeasure, dpi.x, unit);+ double dimLy = getMeasuredLength(m_currentDim.ly, m_yMeasure, dpi.y, unit);++ m_ignoreSync = true;m_currentXSize->setText(QString::number(dimLx));m_currentYSize->setText(QString::number(dimLy));m_relative->setChecked(false);+ m_percentMode->setChecked(false);+ m_percentFld->setValue(1.0);+ setSizeFieldsEnabled(true);m_xSizeFld->setValue(dimLx);m_ySizeFld->setValue(dimLy);m_pegging->resetWidget();+ m_ignoreSync = false;}//------------------------------------------------------------------------------void CanvasSizePopup::onSizeChanged() {- TDimension dim = m_sl->getResolution();- TPointD dpi = m_sl->getDpi();- QString unit = m_unit->currentData().toString();- double measuredXValue = m_relative->isChecked()- ? dim.lx + m_xSizeFld->getValue()- : m_xSizeFld->getValue();- double measuredYValue = m_relative->isChecked()- ? dim.ly + m_ySizeFld->getValue()- : m_ySizeFld->getValue();- double newXValue = getPixelLength(measuredXValue, m_xMeasure, dpi.x, unit);- double newYValue = getPixelLength(measuredYValue, m_yMeasure, dpi.y, unit);- m_pegging->cutLx(dim.lx > newXValue);- m_pegging->cutLy(dim.ly > newYValue);+void CanvasSizePopup::endSession() {+ if (!m_sessionActive) return;+ m_sessionActive = false;+ ToolHandle *th = TApp::instance()->getCurrentTool();+ if (th && th->getRequestedToolName() == T_CanvasSize) {+ if (!m_preSessionToolName.isEmpty())+ th->setTool(m_preSessionToolName);+ else+ th->unsetPseudoTool();+ }+ m_preSessionToolName.clear();+ refreshOverlay(true);+}++//-----------------------------------------------------------------------------++void CanvasSizePopup::setCropConfirmEnabled(bool on) {+ CanvasSizeShowCropConfirm = on ? 1 : 0;+ if (m_confirmCrop) {+ m_confirmCrop->blockSignals(true);+ m_confirmCrop->setChecked(on);+ m_confirmCrop->blockSignals(false);+ }+}++//-----------------------------------------------------------------------------++void CanvasSizePopup::onConfirmCropToggled(bool on) {+ setCropConfirmEnabled(on);+}++//-----------------------------------------------------------------------------++void CanvasSizePopup::showEvent(QShowEvent *e) {+ DVGui::Dialog::showEvent(e);+ initFromLevel();+ setCropConfirmEnabled((int)CanvasSizeShowCropConfirm != 0);+ if (!isRasterCanvasLevel(m_sl.getPointer())) {+ hide();+ return;+ }+ m_sessionActive = true;+ ToolHandle *th = TApp::instance()->getCurrentTool();+ m_preSessionToolName.clear();+ if (th) {+ const QString ¤tTool = th->getRequestedToolName();+ if (currentTool != T_CanvasSize && !isNavigationToolName(currentTool))+ m_preSessionToolName = currentTool;+ }+ if (th && th->getRequestedToolName() != T_CanvasSize)+ th->setPseudoTool(T_CanvasSize);+ if (th) th->storeTool();+ refreshOverlay(true);+}++//-----------------------------------------------------------------------------++void CanvasSizePopup::hideEvent(QHideEvent *e) {+ endSession();+ DVGui::Dialog::hideEvent(e);+}++//-----------------------------------------------------------------------------++void CanvasSizePopup::setSizeFieldsEnabled(bool absoluteOn) {+ m_unit->setEnabled(absoluteOn);+ m_xSizeFld->setEnabled(absoluteOn);+ m_ySizeFld->setEnabled(absoluteOn);+ m_relative->setEnabled(absoluteOn);+ m_percentFld->setEnabled(!absoluteOn);+}++//-----------------------------------------------------------------------------++TDimension CanvasSizePopup::proposedPixelSize() const {+ if (!m_sl) return TDimension(1, 1);+ if (m_percentMode->isChecked()) {+ const double scale = m_percentFld->getValue();+ const int nx = tround(m_currentDim.lx * scale);+ const int ny = tround(m_currentDim.ly * scale);+ return TDimension(std::max(1, nx), std::max(1, ny));+ }+ TPointD dpi = m_sl->getDpi();+ QString unit = m_unit->currentData().toString();+ int nx = getPixelLength(m_xSizeFld->getValue(), m_xMeasure, dpi.x, unit);+ int ny = getPixelLength(m_ySizeFld->getValue(), m_yMeasure, dpi.y, unit);+ if (m_relative->isChecked()) {+ nx += m_currentDim.lx;+ ny += m_currentDim.ly;+ }+ return TDimension(std::max(1, nx), std::max(1, ny));+}++//-----------------------------------------------------------------------------++void CanvasSizePopup::updateProposedFromFields() {+ if (!m_sl) return;+ TDimension newDim = proposedPixelSize();+ m_proposedRect = proposedRectFromPeg(m_currentRect, newDim.lx, newDim.ly,+ m_pegging->getPeggingPosition());+ m_pegging->cutLx(m_currentDim.lx > newDim.lx);+ m_pegging->cutLy(m_currentDim.ly > newDim.ly);+ m_ignoreSync = true;+ m_pegging->updateAnchor();+ m_ignoreSync = false;+ refreshOverlay();+}++//-----------------------------------------------------------------------------++void CanvasSizePopup::syncFieldsFromRect() {+ if (!m_sl) return;+ TDimension newDim = dimFromRect(m_proposedRect);+ TPointD dpi = m_sl->getDpi();+ QString unit = m_unit->currentData().toString();++ m_ignoreSync = true;+ m_xSizeFld->blockSignals(true);+ m_ySizeFld->blockSignals(true);+ m_percentFld->blockSignals(true);+ if (m_percentMode->isChecked()) {+ const double xFactor =+ m_currentDim.lx > 0 ? (double)newDim.lx / m_currentDim.lx : 1.0;+ m_percentFld->setValue(xFactor);+ } else {+ int xVal =+ m_relative->isChecked() ? newDim.lx - m_currentDim.lx : newDim.lx;+ int yVal =+ m_relative->isChecked() ? newDim.ly - m_currentDim.ly : newDim.ly;+ m_xSizeFld->setValue(getMeasuredLength(xVal, m_xMeasure, dpi.x, unit));+ m_ySizeFld->setValue(getMeasuredLength(yVal, m_yMeasure, dpi.y, unit));+ }+ m_xSizeFld->blockSignals(false);+ m_ySizeFld->blockSignals(false);+ m_percentFld->blockSignals(false);+ m_pegging->cutLx(m_currentDim.lx > newDim.lx);+ m_pegging->cutLy(m_currentDim.ly > newDim.ly);m_pegging->updateAnchor();+ m_ignoreSync = false;+}++//-----------------------------------------------------------------------------++void CanvasSizePopup::setProposedRectFromTool(const TRectD &rect,+ PeggingPositions peg) {+ m_proposedRect = snapRectToPixelGrid(rect, m_currentRect);+ m_fromTool = true;+ m_ignoreSync = true;+ m_pegging->setPeggingPosition(peg);+ syncFieldsFromRect();+ m_ignoreSync = false;+ m_fromTool = false;+ refreshOverlay();+}++//-----------------------------------------------------------------------------++void CanvasSizePopup::onSizeChanged() {+ if (m_ignoreSync || !m_sl) return;+ updateProposedFromFields();+}++//-----------------------------------------------------------------------------++void CanvasSizePopup::onPeggingChanged() {+ if (m_ignoreSync || m_fromTool || !m_sl) return;+ updateProposedFromFields();}//-----------------------------------------------------------------------------void CanvasSizePopup::onRelative(bool toggled) {+ if (m_ignoreSync || !m_sl) return;if (toggled) {- m_xSizeFld->setValue(0);- m_ySizeFld->setValue(0);+ m_percentMode->blockSignals(true);+ m_percentMode->setChecked(false);+ m_percentMode->blockSignals(false);+ setSizeFieldsEnabled(true);+ }+ TDimension prop = dimFromRect(m_proposedRect);+ TPointD dpi = m_sl->getDpi();+ QString unit = m_unit->currentData().toString();+ int xVal = toggled ? prop.lx - m_currentDim.lx : prop.lx;+ int yVal = toggled ? prop.ly - m_currentDim.ly : prop.ly;+ m_ignoreSync = true;+ m_xSizeFld->setValue(getMeasuredLength(xVal, m_xMeasure, dpi.x, unit));+ m_ySizeFld->setValue(getMeasuredLength(yVal, m_yMeasure, dpi.y, unit));+ m_ignoreSync = false;+}++//-----------------------------------------------------------------------------++void CanvasSizePopup::onPercentMode(bool on) {+ if (m_ignoreSync || !m_sl) return;+ if (on) {+ m_relative->blockSignals(true);+ m_relative->setChecked(false);+ m_relative->blockSignals(false);+ TDimension prop = dimFromRect(m_proposedRect);+ const double xFactor =+ m_currentDim.lx > 0 ? (double)prop.lx / m_currentDim.lx : 1.0;+ m_ignoreSync = true;+ m_percentFld->setValue(xFactor);+ m_ignoreSync = false;+ setSizeFieldsEnabled(false);+ updateProposedFromFields();} else {- TDimension dim = m_sl->getResolution();- TPointD dpi = m_sl->getDpi();- QString unit = m_unit->currentData().toString();- double dimLx = getMeasuredLength(dim.lx, m_xMeasure, dpi.x, unit);- double dimLy = getMeasuredLength(dim.ly, m_yMeasure, dpi.y, unit);- m_xSizeFld->setValue(dimLx);- m_ySizeFld->setValue(dimLy);+ setSizeFieldsEnabled(true);+ syncFieldsFromRect();}}//-----------------------------------------------------------------------------+void CanvasSizePopup::onReset() {+ if (!m_sl) return;+ m_proposedRect = m_currentRect;+ m_ignoreSync = true;+ m_relative->setChecked(false);+ m_percentMode->setChecked(false);+ m_percentFld->setValue(1.0);+ setSizeFieldsEnabled(true);+ m_pegging->resetWidget();+ m_ignoreSync = false;+ syncFieldsFromRect();+ refreshOverlay(true);+}++//-----------------------------------------------------------------------------+void CanvasSizePopup::onUnitChanged(int index) {- if (m_relative->isChecked()) {- m_xSizeFld->setValue(0);- m_ySizeFld->setValue(0);- return;- }+ if (!m_sl || m_percentMode->isChecked()) return;QString unit = m_unit->itemData(index).toString();if (unit != "pixel") {TUnit *measureUnit = m_xMeasure->getUnit(unit.toStdWString());@@ -659,115 +1608,141 @@ void CanvasSizePopup::onUnitChanged(int index) {measureUnit = m_yMeasure->getUnit(unit.toStdWString());m_yMeasure->setCurrentUnit(measureUnit);}- TDimension dim = m_sl->getResolution();- TPointD dpi = m_sl->getDpi();- double dimLx = getMeasuredLength(dim.lx, m_xMeasure, dpi.x, unit);- double dimLy = getMeasuredLength(dim.ly, m_yMeasure, dpi.y, unit);+ TPointD dpi = m_sl->getDpi();+ double dimLx = getMeasuredLength(m_currentDim.lx, m_xMeasure, dpi.x, unit);+ double dimLy = getMeasuredLength(m_currentDim.ly, m_yMeasure, dpi.y, unit);+ m_ignoreSync = true;m_currentXSize->setText(QString::number(dimLx));m_currentYSize->setText(QString::number(dimLy));- m_xSizeFld->setValue(dimLx);- m_ySizeFld->setValue(dimLy);+ m_ignoreSync = false;+ syncFieldsFromRect();+}++//-----------------------------------------------------------------------------++void CanvasSizePopup::onLevelSwitched(TXshLevel *) {+ updateCanvasSizeCommandEnabled();+ if (!m_sessionActive) return;+ TXshLevelHandle *lh = TApp::instance()->getCurrentLevel();+ TXshSimpleLevel *sl = lh ? lh->getSimpleLevel() : 0;+ if (sl == m_sl.getPointer() && isRasterCanvasLevel(sl)) return;+ hide();}//-----------------------------------------------------------------------------+void CanvasSizePopup::onSceneSwitched() { cancelFromOutside(); }++//-----------------------------------------------------------------------------+void CanvasSizePopup::onOkBtn() {- TDimension dim = m_sl->getResolution();- TPointD dpi = m_sl->getDpi();- QString unit = m_unit->currentData().toString();- int newXValue =- getPixelLength(m_xSizeFld->getValue(), m_xMeasure, dpi.x, unit);- int newYValue =- getPixelLength(m_ySizeFld->getValue(), m_yMeasure, dpi.y, unit);- bool relative = m_relative->isChecked();- newXValue = relative ? dim.lx + newXValue : newXValue;- newYValue = relative ? dim.ly + newYValue : newYValue;- newXValue = newXValue > 0 ? newXValue : 1;- newYValue = newYValue > 0 ? newYValue : 1;-- if ((relative && newXValue == 0 && newYValue == 0) ||- (!relative && dim.lx == newXValue && dim.ly == newYValue)) {- close();+ if (!m_sl) {+ hide();return;}- if (dim.lx > newXValue || dim.ly > newYValue) {- int ret = DVGui::MsgBox(tr("The new canvas size is smaller than the "- "current one.\nDo you want to crop the canvas?"),- tr("Crop"), tr("Cancel"));+ TDimension dim = m_currentDim;+ TDimension newDim = dimFromRect(m_proposedRect);+ newDim.lx = std::max(1, newDim.lx);+ newDim.ly = std::max(1, newDim.ly);++ TPoint pos;+ pos.x = tround(m_currentRect.x0 - m_proposedRect.x0);+ pos.y = tround(m_currentRect.y0 - m_proposedRect.y0);++ const bool sizeChanged = dim.lx != newDim.lx || dim.ly != newDim.ly;+ const bool posChanged = pos.x != 0 || pos.y != 0;+ const bool rasterChanged = sizeChanged || posChanged;+ bool updateCamera = m_updateCamera->isChecked();++ if (!rasterChanged && !updateCamera) {+ hide();+ return;+ }++ if (rasterChanged && canvasCopyWouldCrop(dim, newDim, pos) &&+ (int)CanvasSizeShowCropConfirm) {+ const bool smallerCanvas = newDim.lx < dim.lx || newDim.ly < dim.ly;+ const QString mainText = smallerCanvas+ ? tr("The new canvas size is smaller than the "+ "current one.\n"+ "Do you want to crop the canvas?")+ : tr("Part of the drawing would lie outside "+ "the new canvas.\n"+ "Do you want to crop the canvas?");+ int ret = DVGui::MsgBox(mainText, tr("Crop"), tr("Cancel"));if (ret == 2) return;}- close();- QApplication::setOverrideCursor(Qt::WaitCursor);- PeggingPositions pegPos = m_pegging->getPeggingPosition();- TDimension newDim(newXValue, newYValue);+ hide();- TPoint pos;- if (pegPos == e00 || pegPos == e10 || pegPos == e20) pos.x = 0;- if (pegPos == e01 || pegPos == e11 || pegPos == e21)- pos.x = (newDim.lx - dim.lx) * 0.5;- if (pegPos == e02 || pegPos == e12 || pegPos == e22)- pos.x = newDim.lx - dim.lx;-- if (pegPos == e20 || pegPos == e21 || pegPos == e22) pos.y = 0;- if (pegPos == e10 || pegPos == e11 || pegPos == e12)- pos.y = (newDim.ly - dim.ly) * 0.5;- if (pegPos == e00 || pegPos == e01 || pegPos == e02)- pos.y = newDim.ly - dim.ly;-- int i;- std::vector<TFrameId> fids;- m_sl->getFids(fids);+ QApplication::setOverrideCursor(Qt::WaitCursor);TUndoManager::manager()->beginBlock();- for (i = 0; i < (int)fids.size(); i++) {- TImageP img = m_sl->getFrame(fids[i], true);- TRasterImageP ri(img);- TToonzImageP ti(img);-- if (ri) {- TRasterP ras = ri->getRaster();- TRasterP newRas = ras->create(newDim.lx, newDim.ly);- if (newRas->getPixelSize() < 4)- memset(newRas->getRawData(), 255,- newRas->getPixelSize() * newRas->getWrap() * newRas->getLy());- // TRop::addBackground(newRas,TPixel32::White);- else++ if (rasterChanged) {+ int i;+ std::vector<TFrameId> fids;+ m_sl->getFids(fids);+ for (i = 0; i < (int)fids.size(); i++) {+ TImageP img = m_sl->getFrame(fids[i], true);+ TRasterImageP ri(img);+ TToonzImageP ti(img);++ if (ri) {+ TRasterP ras = ri->getRaster();+ TRasterP newRas = ras->create(newDim.lx, newDim.ly);+ if (newRas->getPixelSize() < 4)+ memset(newRas->getRawData(), 255,+ newRas->getPixelSize() * newRas->getWrap() * newRas->getLy());+ else+ newRas->clear();+ newRas->copy(ras, pos);+ TRasterImageP newImg(newRas);+ double xdpi, ydpi;+ ri->getDpi(xdpi, ydpi);+ newImg->setDpi(xdpi, ydpi);+ m_sl->setFrame(fids[i], newImg);+ TUndoManager::manager()->add(+ new ResizeCanvasUndo(m_sl, fids[i], img, newImg, dim, newDim));+ } else if (ti) {+ TRasterP ras = ti->getRaster();+ TRasterP newRas = ras->create(newDim.lx, newDim.ly);newRas->clear();- newRas->copy(ras, pos);- TRasterImageP newImg(newRas);- double xdpi, ydpi;- ri->getDpi(xdpi, ydpi);- newImg->setDpi(xdpi, ydpi);- m_sl->setFrame(fids[i], newImg);- TUndoManager::manager()->add(- new ResizeCanvasUndo(m_sl, fids[i], img, newImg, dim, newDim));- } else if (ti) {- TRasterP ras = ti->getRaster();- TRasterP newRas = ras->create(newDim.lx, newDim.ly);- newRas->clear();- newRas->copy(ras, pos);- TRect box;- TRop::computeBBox(newRas, box);- TToonzImageP newImg(newRas, box);- double xdpi, ydpi;- ti->getDpi(xdpi, ydpi);- newImg->setDpi(xdpi, ydpi);- m_sl->setFrame(fids[i], newImg);- TUndoManager::manager()->add(- new ResizeCanvasUndo(m_sl, fids[i], img, newImg, dim, newDim));- } else- assert(0);- IconGenerator::instance()->invalidate(m_sl.getPointer(), fids[i]);- m_sl->touchFrame(fids[i]);+ newRas->copy(ras, pos);+ TRect box;+ TRop::computeBBox(newRas, box);+ TToonzImageP newImg(newRas, box);+ double xdpi, ydpi;+ ti->getDpi(xdpi, ydpi);+ newImg->setDpi(xdpi, ydpi);+ m_sl->setFrame(fids[i], newImg);+ TUndoManager::manager()->add(+ new ResizeCanvasUndo(m_sl, fids[i], img, newImg, dim, newDim));+ } else+ assert(0);+ IconGenerator::instance()->invalidate(m_sl.getPointer(), fids[i]);+ m_sl->touchFrame(fids[i]);+ }+ if (sizeChanged) {+ m_sl->getProperties()->setImageRes(newDim);+ IconGenerator::instance()->invalidateSceneIcon();+ }}+ if (updateCamera) applyCameraFromLevel(m_sl.getPointer());TUndoManager::manager()->endBlock();- m_sl->getProperties()->setImageRes(newDim);- IconGenerator::instance()->invalidateSceneIcon();QApplication::restoreOverrideCursor();- TApp::instance()->getCurrentLevel()->notifyCanvasSizeChange();+ if (rasterChanged)+ TApp::instance()->getCurrentLevel()->notifyCanvasSizeChange();}//=============================================================================-OpenPopupCommandHandler<CanvasSizePopup> openCanvasSizePopup(MI_CanvasSize);+class CanvasSizeCommandHandler final : public MenuItemHandler {+public:+ CanvasSizeCommandHandler() : MenuItemHandler(MI_CanvasSize) {}+ void execute() override {+ CanvasSizePopup *popup = CanvasSizePopup::instance();+ if (!popup) popup = new CanvasSizePopup();+ popup->openSession();+ }+} canvasSizeCommandHandler;diff --git a/toonz/sources/toonz/canvassizepopup.h b/toonz/sources/toonz/canvassizepopup.hindex e4439259d..178f301d5 100644--- a/toonz/sources/toonz/canvassizepopup.h+++ b/toonz/sources/toonz/canvassizepopup.h@@ -5,17 +5,23 @@#include "toonzqt/dvdialog.h"#include "toonz/txshsimplelevel.h"+#include "tgeometry.h"#include <QPixmap>-// forward declarationclass QButtonGroup;class QComboBox;+class QHideEvent;+class QLabel;class TMeasure;+class TXshLevel;namespace DVGui {class DoubleLineEdit;+class MeasuredDoubleLineEdit;class CheckBox;-}+} // namespace DVGui++void updateCanvasSizeCommandEnabled();//=============================================================================@@ -39,6 +45,7 @@ class PeggingWidget final : public QWidget {public:PeggingWidget(QWidget *parent = 0);PeggingPositions getPeggingPosition() const { return m_pegging; }+ void setPeggingPosition(PeggingPositions position);void resetWidget();void cutLx(bool value) { m_cutLx = value; }void cutLy(bool value) { m_cutLy = value; }@@ -50,6 +57,9 @@ private:protected:void paintEvent(QPaintEvent *) override;+signals:+ void peggingChanged();+public slots:void on00();void on01();@@ -76,22 +86,62 @@ class CanvasSizePopup final : public DVGui::Dialog {QComboBox *m_unit;DVGui::DoubleLineEdit *m_xSizeFld;DVGui::DoubleLineEdit *m_ySizeFld;+ DVGui::CheckBox *m_percentMode;+ DVGui::MeasuredDoubleLineEdit *m_percentFld;DVGui::CheckBox *m_relative;+ DVGui::CheckBox *m_updateCamera;+ DVGui::CheckBox *m_confirmCrop;PeggingWidget *m_pegging;TMeasure *m_xMeasure, *m_yMeasure;+ TRectD m_currentRect, m_proposedRect;+ TDimension m_currentDim;+ bool m_sessionActive;+ bool m_ignoreSync;+ bool m_fromTool;+ QString m_preSessionToolName;+public:CanvasSizePopup();+ static CanvasSizePopup *instance();++ bool isSessionActive() const { return m_sessionActive; }+ bool isPercentMode() const;+ TDimension currentCanvasDim() const { return m_currentDim; }+ TRectD currentCanvasRect() const { return m_currentRect; }+ TRectD proposedCanvasRect() const { return m_proposedRect; }+ PeggingPositions peggingPosition() const;++ void openSession();+ void cancelFromOutside();+ void setProposedRectFromTool(const TRectD &rect, PeggingPositions peg);+protected:void showEvent(QShowEvent *e) override;+ void hideEvent(QHideEvent *e) override;++ TDimension proposedPixelSize() const;+ void initFromLevel();+ void endSession();+ void updateProposedFromFields();+ void syncFieldsFromRect();+ void refreshOverlay(bool wholeViewer = false);+ void setSizeFieldsEnabled(bool absoluteOn);public slots:void onOkBtn();void onSizeChanged();void onRelative(bool);+ void onPercentMode(bool);void onUnitChanged(int);+ void onPeggingChanged();+ void onLevelSwitched(TXshLevel *);+ void onSceneSwitched();+ void onReset();+ void setCropConfirmEnabled(bool on);+ void onConfirmCropToggled(bool on);};#endif // CANVASSIZEPOPUP_Hdiff --git a/toonz/sources/toonz/cellselection.cpp b/toonz/sources/toonz/cellselection.cppindex 20a39b645..f696ed377 100644--- a/toonz/sources/toonz/cellselection.cpp+++ b/toonz/sources/toonz/cellselection.cpp@@ -15,6 +15,7 @@#include "xsheetviewer.h"#include "levelcommand.h"#include "columncommand.h"+#include "canvassizepopup.h"// TnzTools includes#include "tools/toolutils.h"@@ -79,22 +80,6 @@namespace {//------------------------------------------------------------------------------// Check if the selection contains only one raster level-bool containsOnlyOneRasterLevel(int r0, int c0, int r1, int c1) {- TXsheet *xsh = TApp::instance()->getCurrentXsheet()->getXsheet();- int r, c;- TXshLevelP xl = xsh->getCell(r0, c0).m_level;- for (r = r0; r <= r1; r++) {- for (c = c0; c <= c1; c++)- if (xsh->getCell(r, c).m_level.getPointer() != xl.getPointer())- return false;- }- return xl && (xl->getType() == TZP_XSHLEVEL ||- xl->getType() == OVL_XSHLEVEL || xl->getType() == TZI_XSHLEVEL);-}--//------------------------------------------------------------------------------// Copy cells to clipboard without undovoid copyCellsWithoutUndo(int r0, int c0, int r1, int c1) {int colCount = c1 - c0 + 1;@@ -1665,24 +1650,22 @@ void TCellSelection::selectCells(int r0, int c0, int r1, int c1) {// cell selection won't contain the camera columnif (m_range.m_c0 < 0) m_range.m_c0 = 0;- bool onlyOneRasterLevel = containsOnlyOneRasterLevel(r0, c0, r1, c1);// set the nearest rowm_resizePivotRow =(std::abs(r0 - m_resizePivotRow) < std::abs(r1 - m_resizePivotRow)) ? r0: r1;- CommandManager::instance()->enable(MI_CanvasSize, onlyOneRasterLevel);+ updateCanvasSizeCommandEnabled();}//-----------------------------------------------------------------------------void TCellSelection::selectCell(int row, int col) {- m_range.m_r0 = row;- m_range.m_c0 = col;- m_range.m_r1 = row;- m_range.m_c1 = col;- bool onlyOneRasterLevel = containsOnlyOneRasterLevel(row, col, row, col);- m_resizePivotRow = row;- CommandManager::instance()->enable(MI_CanvasSize, onlyOneRasterLevel);+ m_range.m_r0 = row;+ m_range.m_c0 = col;+ m_range.m_r1 = row;+ m_range.m_c1 = col;+ m_resizePivotRow = row;+ updateCanvasSizeCommandEnabled();}//-----------------------------------------------------------------------------@@ -1690,7 +1673,7 @@ void TCellSelection::selectCell(int row, int col) {void TCellSelection::selectNone() {m_range = Range();m_resizePivotRow = -1;- CommandManager::instance()->enable(MI_CanvasSize, false);+ updateCanvasSizeCommandEnabled();}//-----------------------------------------------------------------------------diff --git a/toonz/sources/toonz/filmstripselection.cpp b/toonz/sources/toonz/filmstripselection.cppindex 8831aebfe..be2ef5a60 100644--- a/toonz/sources/toonz/filmstripselection.cpp+++ b/toonz/sources/toonz/filmstripselection.cpp@@ -25,6 +25,7 @@#include "toonz/txshlevel.h"#include "toonz/txshsimplelevel.h"#include "toonz/txshleveltypes.h"+#include "canvassizepopup.h"// TnzCore includes#include "tundo.h"@@ -143,12 +144,7 @@ void TFilmstripSelection::select(const TFrameId &fid, bool selected) {TTool *tool = app->getCurrentTool()->getTool();if (tool) tool->setSelectedFrames(m_selectedFrames);- TXshSimpleLevel *sl = app->getCurrentLevel()->getSimpleLevel();- bool rasterLevel = sl->getType() == TZP_XSHLEVEL ||- sl->getType() == OVL_XSHLEVEL ||- sl->getType() == TZI_XSHLEVEL;-- CommandManager::instance()->enable(MI_CanvasSize, rasterLevel);+ updateCanvasSizeCommandEnabled();}//-----------------------------------------------------------------------------@@ -162,8 +158,7 @@ bool TFilmstripSelection::isSelected(const TFrameId &fid) const {void TFilmstripSelection::selectNone() {m_selectedFrames.clear();updateInbetweenRange();- TXshSimpleLevel *sl = TApp::instance()->getCurrentLevel()->getSimpleLevel();- CommandManager::instance()->enable(MI_CanvasSize, false);+ updateCanvasSizeCommandEnabled();}//-----------------------------------------------------------------------------@@ -178,10 +173,7 @@ void TFilmstripSelection::selectAll() {updateInbetweenRange();TTool *tool = TApp::instance()->getCurrentTool()->getTool();tool->setSelectedFrames(m_selectedFrames);- bool rasterLevel = sl->getType() == TZP_XSHLEVEL ||- sl->getType() == OVL_XSHLEVEL ||- sl->getType() == TZI_XSHLEVEL;- CommandManager::instance()->enable(MI_CanvasSize, rasterLevel);+ updateCanvasSizeCommandEnabled();notifyView();}@@ -202,9 +194,7 @@ void TFilmstripSelection::invertSelection() {updateInbetweenRange();TTool *tool = TApp::instance()->getCurrentTool()->getTool();tool->setSelectedFrames(m_selectedFrames);- if (sl->getType() == TZP_XSHLEVEL || sl->getType() == OVL_XSHLEVEL ||- sl->getType() == TZI_XSHLEVEL)- CommandManager::instance()->enable(MI_CanvasSize, true);+ updateCanvasSizeCommandEnabled();notifyView();}diff --git a/toonz/sources/toonz/tapp.cpp b/toonz/sources/toonz/tapp.cppindex 8d6282a35..f6b2be271 100644--- a/toonz/sources/toonz/tapp.cpp+++ b/toonz/sources/toonz/tapp.cpp@@ -7,6 +7,7 @@#include "iocommand.h"#include "mainwindow.h"#include "cellselection.h"+#include "canvassizepopup.h"// TnzTools includes#include "tools/tool.h"@@ -418,6 +419,7 @@ void TApp::onSceneSwitched() {// update current toolm_currentTool->onImageChanged((TImage::Type)getCurrentImageType());+ updateCanvasSizeCommandEnabled();}//-----------------------------------------------------------------------------@@ -520,6 +522,7 @@ void TApp::onColumnIndexSwitched() {//-----------------------------------------------------------------------------void TApp::onXshLevelSwitched(TXshLevel *) {+ updateCanvasSizeCommandEnabled();TXshLevel *level = m_currentLevel->getLevel();if (level) {TXshSimpleLevel *simpleLevel = level->getSimpleLevel();