Gui: Split stopAnimation() into onStop() and inherited stop()

This commit is contained in:
Rexbas
2023-10-22 14:23:14 +02:00
committed by wwmayer
parent b147e78cda
commit fdc07dba67
4 changed files with 17 additions and 35 deletions

View File

@@ -39,10 +39,8 @@ void NavigationAnimation::updateCurrentValue(const QVariant& value)
update(value);
}
void NavigationAnimation::stopAnimation()
{
QAbstractAnimation::stop();
}
void NavigationAnimation::onStop(bool finished)
{}
FixedTimeAnimation::FixedTimeAnimation(NavigationStyle* navigation, const SbRotation& orientation,
const SbVec3f& rotationCenter, const SbVec3f& translation,
@@ -139,9 +137,8 @@ void SpinningAnimation::update(const QVariant& value)
prevAngle = value.toFloat();
}
void SpinningAnimation::stopAnimation()
void SpinningAnimation::onStop(bool finished)
{
NavigationAnimation::stopAnimation();
if (navigation->getViewingMode() != NavigationStyle::SPINNING) {
return;
}

View File

@@ -42,7 +42,7 @@ protected:
virtual void initialize() = 0;
virtual void update(const QVariant& value) = 0;
virtual void stopAnimation();
virtual void onStop(bool finished);
private:
void updateCurrentValue(const QVariant& value) override;
@@ -85,7 +85,7 @@ private:
void initialize() override;
void update(const QVariant& value) override;
void stopAnimation() override;
void onStop(bool finished) override;
};
} // namespace Gui

View File

@@ -48,7 +48,11 @@ void NavigationAnimator::start(const std::shared_ptr<NavigationAnimation>& anima
activeAnimation = animation;
activeAnimation->initialize();
connect(activeAnimation.get(), &NavigationAnimation::finished, this, &NavigationAnimator::reset);
connect(activeAnimation.get(), &NavigationAnimation::finished, this, [this]() {
activeAnimation->onStop(true);
activeAnimation.reset();
});
activeAnimation->start();
}
@@ -63,37 +67,21 @@ bool NavigationAnimator::startAndWait(const std::shared_ptr<NavigationAnimation>
stop();
bool finished = true;
QEventLoop loop;
loop.connect(animation.get(), &NavigationAnimation::finished,
[&loop, &finished, &animation]() { // clazy:exclude=lambda-in-connect
if (animation->state() == QAbstractAnimation::State::Running) {
finished = false;
}
loop.quit();
});
connect(animation.get(), &NavigationAnimation::finished, &loop, &QEventLoop::quit);
start(animation);
loop.exec();
return finished;
}
/**
* @brief Stops an active animation
* @brief Stops an active animation and releases shared ownership of the animation
*/
void NavigationAnimator::stop()
{
if (activeAnimation != nullptr && activeAnimation->state() != QAbstractAnimation::State::Stopped) {
Q_EMIT activeAnimation->finished();
if (activeAnimation && activeAnimation->state() != QAbstractAnimation::State::Stopped) {
disconnect(activeAnimation.get(), &NavigationAnimation::finished, 0, 0);
activeAnimation->stop();
activeAnimation->onStop(false);
activeAnimation.reset();
}
}
/**
* @brief Stops the animation and releases ownership of the animation
*
* Is called when the animation finished() signal is received which is triggered when the animation
* is finished or when the animation is interrupted by NavigationAnimator::stop()
*/
void NavigationAnimator::reset() {
disconnect(activeAnimation.get(), &NavigationAnimation::finished, 0, 0);
activeAnimation->stopAnimation();
activeAnimation.reset();
}

View File

@@ -43,9 +43,6 @@ public:
bool startAndWait(const std::shared_ptr<NavigationAnimation>& animation);
void stop();
private Q_SLOTS:
void reset();
private:
std::shared_ptr<NavigationAnimation> activeAnimation;
};