From af2135fbe2120b384d4c8664c8ed5c96dbb4ba9f Mon Sep 17 00:00:00 2001 From: Bas Ruigrok Date: Wed, 19 Feb 2025 20:12:16 +0100 Subject: [PATCH] Gui: Accumulate orientation for NaviCube flat button animations --- src/Gui/NaviCube.cpp | 20 +++++++++++++++----- src/Gui/Navigation/NavigationAnimation.cpp | 2 +- src/Gui/Navigation/NavigationAnimation.h | 1 + 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/Gui/NaviCube.cpp b/src/Gui/NaviCube.cpp index db95032839..d84e9ad2c2 100644 --- a/src/Gui/NaviCube.cpp +++ b/src/Gui/NaviCube.cpp @@ -54,6 +54,7 @@ #include "Command.h" #include "Action.h" #include "MainWindow.h" +#include "Navigation/NavigationAnimation.h" #include "View3DInventorViewer.h" #include "View3DInventor.h" #include "ViewParams.h" @@ -63,10 +64,6 @@ using namespace Eigen; using namespace std; using namespace Gui; - - - - class NaviCubeImplementation { public: explicit NaviCubeImplementation(Gui::View3DInventorViewer*); @@ -206,6 +203,9 @@ private: map m_LabelTextures; QMenu* m_Menu; + + std::shared_ptr m_flatButtonAnimation; + SbRotation m_flatButtonTargetOrientation; }; int NaviCubeImplementation::m_CubeWidgetSize = 132; @@ -1102,7 +1102,17 @@ bool NaviCubeImplementation::mouseReleased(short x, short y) else { rotation.scaleAngle(rotStepAngle); } - m_View3DInventorViewer->setCameraOrientation(rotation * m_View3DInventorViewer->getCameraOrientation()); + + // If the previous flat button animation is still active then apply the rotation to the + // previous target orientation, otherwise apply the rotation to the current camera orientation + if (m_flatButtonAnimation != nullptr && m_flatButtonAnimation->state() == QAbstractAnimation::Running) { + m_flatButtonTargetOrientation = rotation * m_flatButtonTargetOrientation; + } + else { + m_flatButtonTargetOrientation = rotation * m_View3DInventorViewer->getCameraOrientation(); + } + + m_flatButtonAnimation = m_View3DInventorViewer->setCameraOrientation(m_flatButtonTargetOrientation); } else { return false; diff --git a/src/Gui/Navigation/NavigationAnimation.cpp b/src/Gui/Navigation/NavigationAnimation.cpp index a4932d6825..943af87706 100644 --- a/src/Gui/Navigation/NavigationAnimation.cpp +++ b/src/Gui/Navigation/NavigationAnimation.cpp @@ -33,7 +33,7 @@ NavigationAnimation::NavigationAnimation(NavigationStyle* navigation) void NavigationAnimation::updateCurrentValue(const QVariant& value) { - if (state() == QAbstractAnimation::State::Stopped) { + if (state() != QAbstractAnimation::State::Running) { return; } update(value); diff --git a/src/Gui/Navigation/NavigationAnimation.h b/src/Gui/Navigation/NavigationAnimation.h index d14e8a366a..da337ce6ae 100644 --- a/src/Gui/Navigation/NavigationAnimation.h +++ b/src/Gui/Navigation/NavigationAnimation.h @@ -37,6 +37,7 @@ class GuiExport NavigationAnimation : protected QVariantAnimation Q_OBJECT public: explicit NavigationAnimation(NavigationStyle* navigation); + using QVariantAnimation::state; Q_SIGNALS: void interrupted();