Skip to content

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

C

rotate and zoom

konero28ba3ec5d5e4
diff --git a/toonz/sources/include/tools/toolhandle.h b/toonz/sources/include/tools/toolhandle.h
index a4b6aad4c..77199617d 100644
--- a/toonz/sources/include/tools/toolhandle.h
+++ b/toonz/sources/include/tools/toolhandle.h
@@ -39,17 +39,31 @@ class DVAPI ToolHandle final : public QObject {
QString m_oldToolName;
bool m_toolIsBusy;
+ // State tracking for intuitive viewer navigation
+ QString m_originalTool; // Store tool before navigation mode
+ bool m_inNavigationMode = false;
+ bool m_spacePressed = false;
+ bool m_shiftPressed = false;
+ bool m_ctrlPressed = false;
+
public:
ToolHandle();
~ToolHandle();
TTool *getTool() const;
void setTool(QString name);
- void setTargetType(int targetType);
+ void setTargetType(int targetType); // TODO: unused, remove?
+
+ const QString &getRequestedToolName() const { return m_toolName; }
+
+ // used to handle viewer navigation state
+ void setSpacePressed(bool pressed);
+ void setShiftPressed(bool pressed);
+ void setCtrlPressed(bool pressed);
+ bool isSpacePressed() const { return m_spacePressed; }
+ bool isShiftPressed() const { return m_shiftPressed; }
+ bool isCtrlPressed() const { return m_ctrlPressed; }
- const QString& getRequestedToolName() const
- { return m_toolName; }
-
// used to change tool for a short while (e.g. while keeping pressed a
// short-key)
void storeTool();
@@ -74,6 +88,9 @@ public:
emit toolComboBoxListChanged(id);
}
+private:
+ void updateNavigationState();
+
signals:
void toolComboBoxListChanged(std::string);
void toolSwitched();
diff --git a/toonz/sources/tnztools/toolhandle.cpp b/toonz/sources/tnztools/toolhandle.cpp
index 5e8bdf5eb..51036a140 100644
--- a/toonz/sources/tnztools/toolhandle.cpp
+++ b/toonz/sources/tnztools/toolhandle.cpp
@@ -63,6 +63,57 @@ void ToolHandle::setTool(QString name) {
//-----------------------------------------------------------------------------
+void ToolHandle::setSpacePressed(bool pressed) {
+ if (m_spacePressed == pressed) return;
+
+ m_spacePressed = pressed;
+ if (pressed) {
+ // Store current tool when entering navigation mode
+ m_originalTool = m_toolName;
+ m_inNavigationMode = true;
+ setTool("T_Hand");
+ } else {
+ // Restore original tool when exiting navigation mode
+ m_inNavigationMode = false;
+ if (!m_originalTool.isEmpty()) {
+ setTool(m_originalTool);
+ m_originalTool.clear();
+ }
+ }
+ updateNavigationState();
+}
+
+void ToolHandle::setShiftPressed(bool pressed) {
+ if (m_shiftPressed == pressed) return;
+
+ m_shiftPressed = pressed;
+ updateNavigationState();
+}
+
+void ToolHandle::setCtrlPressed(bool pressed) {
+ if (m_ctrlPressed == pressed) return;
+
+ m_ctrlPressed = pressed;
+ updateNavigationState();
+}
+
+void ToolHandle::updateNavigationState() {
+ // Only handle state changes when in navigation mode
+ if (!m_inNavigationMode) return;
+
+ if (m_spacePressed) {
+ if (m_ctrlPressed) {
+ setTool("T_Zoom");
+ } else if (m_shiftPressed) {
+ setTool("T_Rotate");
+ } else {
+ setTool("T_Hand");
+ }
+ }
+}
+
+//-----------------------------------------------------------------------------
+
void ToolHandle::storeTool() {
m_storedToolName = m_toolName;
m_storedToolTime.start();
diff --git a/toonz/sources/tnztools/tooloptions.cpp b/toonz/sources/tnztools/tooloptions.cpp
index e7d4b6580..282558374 100644
--- a/toonz/sources/tnztools/tooloptions.cpp
+++ b/toonz/sources/tnztools/tooloptions.cpp
@@ -2902,9 +2902,8 @@ void ToolOptions::onToolSwitched() {
ToolHandle *currTool = app->getCurrentTool();
TTool *tool = currTool->getTool();
- // Skip panel updates only when temporarily switching to Hand tool via
- // spacebar
- if (currTool->isTemporaryTool() && tool && tool->getName() == T_Hand) {
+ // Skip panel updates if we're in navigation mode
+ if (currTool && currTool->isSpacePressed()) {
return;
}
diff --git a/toonz/sources/toonz/sceneviewerevents.cpp b/toonz/sources/toonz/sceneviewerevents.cpp
index 06007e8db..404612197 100644
--- a/toonz/sources/toonz/sceneviewerevents.cpp
+++ b/toonz/sources/toonz/sceneviewerevents.cpp
@@ -655,18 +655,18 @@ void SceneViewer::onMove(const TMouseEvent &event) {
}
if (!cursorSet) setToolCursor(this, tool->getCursorId());
- if ( m_toolHasAssistants
- && (tool->getToolHints() & TTool::HintAssistantsGuidelines)
- && !areAlmostEqual(m_toolPos, pos) )
- invalidateAll();
-
- if ( m_toolReplicatedPoints.size() > 1
- && (tool->getToolHints() & TTool::HintReplicatorsPoints)
- && !areAlmostEqual(m_toolPos, pos) )
- invalidateAll();
+ if (m_toolHasAssistants &&
+ (tool->getToolHints() & TTool::HintAssistantsGuidelines) &&
+ !areAlmostEqual(m_toolPos, pos))
+ invalidateAll();
+
+ if (m_toolReplicatedPoints.size() > 1 &&
+ (tool->getToolHints() & TTool::HintReplicatorsPoints) &&
+ !areAlmostEqual(m_toolPos, pos))
+ invalidateAll();
m_toolPos = pos;
-
+
#ifdef WITH_CANON
if (StopMotion::instance()->m_canon->m_pickLiveViewZoom)
setToolCursor(this, ToolCursor::ZoomCursor);
@@ -1410,12 +1410,33 @@ void SceneViewer::keyPressEvent(QKeyEvent *event) {
if (m_freezedStatus != NO_FREEZED) return;
int key = event->key();
+ // Handle navigation keys first
+ if (!event->isAutoRepeat()) {
+ if (event->key() == Qt::Key_Space) {
+ TApp::instance()->getCurrentTool()->setSpacePressed(true);
+ event->accept();
+ return;
+ }
+ if (event->key() == Qt::Key_Control) {
+ TApp::instance()->getCurrentTool()->setCtrlPressed(true);
+ event->accept();
+ return;
+ }
+ if (event->key() == Qt::Key_Shift) {
+ TApp::instance()->getCurrentTool()->setShiftPressed(true);
+ event->accept();
+ return;
+ }
+ }
+
+ // Handle Canon camera controls if enabled
#ifdef WITH_CANON
if ((m_stopMotion->m_canon->m_pickLiveViewZoom ||
m_stopMotion->m_canon->m_zooming) &&
(key == Qt::Key_Left || key == Qt::Key_Right || key == Qt::Key_Up ||
key == Qt::Key_Down || key == Qt::Key_2 || key == Qt::Key_4 ||
key == Qt::Key_6 || key == Qt::Key_8)) {
+ // Handle camera zoom point adjustment
if (m_stopMotion->m_canon->m_liveViewZoomReadyToPick == true) {
if (key == Qt::Key_Left || key == Qt::Key_4) {
m_stopMotion->m_canon->m_liveViewZoomPickPoint.x -= 10;
@@ -1444,6 +1465,8 @@ void SceneViewer::keyPressEvent(QKeyEvent *event) {
return;
} else
#endif
+
+ // Handle stop motion capture
#if defined(x64)
if (m_stopMotion->m_liveViewStatus == 2 &&
(key == Qt::Key_Enter || key == Qt::Key_Return)) {
@@ -1453,19 +1476,19 @@ void SceneViewer::keyPressEvent(QKeyEvent *event) {
}
#endif
- // resolving priority and tool-specific key events in this lambda
+ // Handle tool-specific key events and viewer shortcuts
auto ret = [&]() -> bool {
TTool *tool = TApp::instance()->getCurrentTool()->getTool();
if (!tool) return false;
bool isTextToolActive = tool->getName() == T_Type && tool->isActive();
+ // Handle non-text tool shortcuts
if (!isTextToolActive) {
if (ViewerZoomer(this).exec(event)) return true;
if (SceneViewerShortcutReceiver(this).exec(event)) return true;
- // If this object is child of Viewer or ComboViewer
- // (m_isStyleShortcutSelective = true),
- // then consider about shortcut for the current style selection.
+
+ // Handle style switching shortcuts when appropriate
if (m_isStyleShortcutSwitchable &&
Preferences::instance()->isUseNumpadForSwitchingStylesEnabled() &&
(event->modifiers() == Qt::NoModifier ||
@@ -1473,9 +1496,7 @@ void SceneViewer::keyPressEvent(QKeyEvent *event) {
event->modifiers() == Qt::KeypadModifier) &&
((Qt::Key_0 <= key && key <= Qt::Key_9) || key == Qt::Key_Tab ||
key == Qt::Key_Backtab)) {
- // When the viewer is in full screen mode, directly call the style
- // shortcut function since the viewer is retrieved from the parent
- // panel.
+ // Handle fullscreen style shortcuts
if (parentWidget() &&
parentWidget()->windowState() & Qt::WindowFullScreen) {
StyleShortcutSwitchablePanel::onKeyPress(event);
@@ -1485,7 +1506,8 @@ void SceneViewer::keyPressEvent(QKeyEvent *event) {
event->ignore();
return true;
}
- // pressing F1, F2 or F3 key will flip between corresponding ghost
+
+ // Handle onion skin ghost flip keys
if (CommandManager::instance()->getAction(MI_ShiftTrace)->isChecked() &&
(Qt::Key_F1 <= key && key <= Qt::Key_F3)) {
OnionSkinMask osm =
@@ -1503,10 +1525,9 @@ void SceneViewer::keyPressEvent(QKeyEvent *event) {
tool->setViewer(this);
+ // Handle modifier keys that require immediate cursor updates
if (key == Qt::Key_Shift || key == Qt::Key_Control || key == Qt::Key_Alt ||
key == Qt::Key_AltGr) {
- // quando l'utente preme shift/ctrl ecc. alcuni tool (es. pinch) devono
- // cambiare subito la forma del cursore, senza aspettare il prossimo move
TMouseEvent toonzEvent;
initToonzEvent(toonzEvent, event);
toonzEvent.m_pos = TPointD(m_lastMousePos.x(),
@@ -1529,17 +1550,18 @@ void SceneViewer::keyPressEvent(QKeyEvent *event) {
return tool->keyDown(event);
}();
+ // Handle frame navigation if no tool handled the key
if (!ret) {
if (changeFrameSkippingHolds(event)) return;
TFrameHandle *fh = TApp::instance()->getCurrentFrame();
int origFrame = fh->getFrame();
+ // Handle frame navigation keys
if (key == Qt::Key_Up || key == Qt::Key_Left)
fh->prevFrame();
else if (key == Qt::Key_Down || key == Qt::Key_Right) {
- // If on a level frame pass the frame id after the last frame to allow
- // creating a new frame with the down arrow key
+ // Allow creating new frames with down arrow in level mode
TFrameId newId = 0;
if (Preferences::instance()->getDownArrowLevelStripNewFrame() &&
fh->getFrameType() == TFrameHandle::LevelFrame) {
@@ -1560,7 +1582,7 @@ void SceneViewer::keyPressEvent(QKeyEvent *event) {
else if (key == Qt::Key_End)
fh->lastFrame();
- // Use arrow keys to shift the cell selection.
+ // Handle cell selection movement with arrow keys
if (Preferences::instance()->isUseArrowKeyToShiftCellSelectionEnabled() &&
fh->getFrameType() != TFrameHandle::LevelFrame) {
TCellSelection *cellSel =
@@ -1575,13 +1597,16 @@ void SceneViewer::keyPressEvent(QKeyEvent *event) {
}
}
}
+
update();
- // TODO: devo accettare l'evento?
}
//-----------------------------------------------------------------------------
void SceneViewer::keyReleaseEvent(QKeyEvent *event) {
+ qDebug() << "Raw key release event:" << event->key()
+ << "AutoRepeat:" << event->isAutoRepeat();
+ // Skip if viewer is in frozen state
if (m_freezedStatus != NO_FREEZED) return;
TTool *tool = TApp::instance()->getCurrentTool()->getTool();
@@ -1590,10 +1615,28 @@ void SceneViewer::keyReleaseEvent(QKeyEvent *event) {
int key = event->key();
+ // Handle navigation keys first
+ if (!event->isAutoRepeat()) {
+ if (event->key() == Qt::Key_Space) {
+ TApp::instance()->getCurrentTool()->setSpacePressed(false);
+ event->accept();
+ return;
+ }
+ if (event->key() == Qt::Key_Control) {
+ TApp::instance()->getCurrentTool()->setCtrlPressed(false);
+ event->accept();
+ }
+ if (event->key() == Qt::Key_Shift) {
+ TApp::instance()->getCurrentTool()->setShiftPressed(false);
+ event->accept();
+ return;
+ }
+ }
+
+ // For modifier keys (shift/ctrl/etc), some tools (e.g. pinch) need to
+ // update their cursor immediately without waiting for the next mouse move
if (key == Qt::Key_Shift || key == Qt::Key_Control || key == Qt::Key_Alt ||
key == Qt::Key_AltGr) {
- // quando l'utente preme shift/ctrl ecc. alcuni tool (es. pinch) devono
- // cambiare subito la forma del cursore, senza aspettare il prossimo move
TMouseEvent toonzEvent;
initToonzEvent(toonzEvent, event);
toonzEvent.m_pos = TPointD(m_lastMousePos.x(),
@@ -1611,6 +1654,7 @@ void SceneViewer::keyReleaseEvent(QKeyEvent *event) {
setToolCursor(this, tool->getCursorId());
}
+ // Handle shift trace ghost flip keys
if (CommandManager::instance()->getAction(MI_ShiftTrace)->isChecked() &&
(Qt::Key_F1 <= key && key <= Qt::Key_F3)) {
OnionSkinMask osm =
@@ -1620,6 +1664,7 @@ void SceneViewer::keyReleaseEvent(QKeyEvent *event) {
TApp::instance()->getCurrentOnionSkin()->notifyOnionSkinMaskChanged();
}
+ // Accept key events only for text tool, ignore for others
if (tool->getName() == T_Type)
event->accept();
else
diff --git a/toonz/sources/toonz/shortcutpopup.cpp b/toonz/sources/toonz/shortcutpopup.cpp
index e600eb47c..adb4bb70a 100644
--- a/toonz/sources/toonz/shortcutpopup.cpp
+++ b/toonz/sources/toonz/shortcutpopup.cpp
@@ -129,6 +129,12 @@ void ShortcutViewer::keyPressEvent(QKeyEvent *event) {
//-----------------------------------------------------------------------------
void ShortcutViewer::onEditingFinished() {
+ if (keySequence().toString().contains("Space", Qt::CaseInsensitive)) {
+ setKeySequence(m_action->shortcut());
+ DVGui::warning(tr("The Space key is reserved for viewer navigation."));
+ return;
+ } // TODO: Check for Space + Shift (rotate), and Space + CTRL (zoom)
+
m_keysPressed = 0;
int seqCount = keySequence().count();