1
// SPDX-License-Identifier: LGPL-2.1-or-later
2
/****************************************************************************
4
* Copyright (c) 2023 Bas Ruigrok (Rexbas) <Rexbas@proton.me> *
6
* This file is part of FreeCAD. *
8
* FreeCAD is free software: you can redistribute it and/or modify it *
9
* under the terms of the GNU Lesser General Public License as *
10
* published by the Free Software Foundation, either version 2.1 of the *
11
* License, or (at your option) any later version. *
13
* FreeCAD is distributed in the hope that it will be useful, but *
14
* WITHOUT ANY WARRANTY; without even the implied warranty of *
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
16
* Lesser General Public License for more details. *
18
* You should have received a copy of the GNU Lesser General Public *
19
* License along with FreeCAD. If not, see *
20
* <https://www.gnu.org/licenses/>. *
22
***************************************************************************/
24
#include "PreCompiled.h"
25
#include "NavigationAnimator.h"
26
#include "NavigationAnimation.h"
31
NavigationAnimator::NavigationAnimator()
32
: activeAnimation(nullptr)
35
NavigationAnimator::~NavigationAnimator()
41
* @brief Start an animation
43
* @param animation The animation to start
45
void NavigationAnimator::start(const std::shared_ptr<NavigationAnimation>& animation)
48
activeAnimation = animation;
49
activeAnimation->initialize();
51
connect(activeAnimation.get(), &NavigationAnimation::finished, this, [this]() {
52
activeAnimation->onStop(true);
53
activeAnimation.reset();
56
activeAnimation->start();
60
* @brief Start an animation and wait for it to finish
62
* @param animation The animation to start
63
* @return True if the animation finished, false if interrupted
65
bool NavigationAnimator::startAndWait(const std::shared_ptr<NavigationAnimation>& animation)
70
connect(animation.get(), &NavigationAnimation::finished, &loop, &QEventLoop::quit);
71
connect(animation.get(), &NavigationAnimation::interrupted, &loop, [&finished, &loop]() {
81
* @brief Stops an active animation and releases shared ownership of the animation
83
void NavigationAnimator::stop()
85
if (activeAnimation && activeAnimation->state() != QAbstractAnimation::State::Stopped) {
86
disconnect(activeAnimation.get(), &NavigationAnimation::finished, 0, 0);
87
Q_EMIT activeAnimation->interrupted();
88
activeAnimation->stop();
89
activeAnimation->onStop(false);
90
activeAnimation.reset();
95
* @return Whether or not an animation is active
97
bool NavigationAnimator::isAnimating() const
99
if (activeAnimation != nullptr) {
100
return activeAnimation->state() == QAbstractAnimation::State::Running;