| 1 |
// SPDX-License-Identifier: LGPL-2.1-or-later |
| 2 |
/**************************************************************************** |
| 3 |
* * |
| 4 |
* Copyright (c) 2023 Bas Ruigrok (Rexbas) <[email protected]> * |
| 5 |
* * |
| 6 |
* This file is part of FreeCAD. * |
| 7 |
* * |
| 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. * |
| 12 |
* * |
| 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. * |
| 17 |
* * |
| 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/>. * |
| 21 |
* * |
| 22 |
***************************************************************************/ |
| 23 |
|
| 24 |
#ifndef GUI_NAVIGATIONANIMATION_H |
| 25 |
#define GUI_NAVIGATIONANIMATION_H |
| 26 |
|
| 27 |
#include "Navigation/NavigationStyle.h" |
| 28 |
#include <Inventor/SbRotation.h> |
| 29 |
#include <Inventor/SbVec3f.h> |
| 30 |
#include <QVariantAnimation> |
| 31 |
|
| 32 |
namespace Gui |
| 33 |
{ |
| 34 |
|
| 35 |
class GuiExport NavigationAnimation: protected QVariantAnimation |
| 36 |
{ |
| 37 |
Q_OBJECT |
| 38 |
public: |
| 39 |
explicit NavigationAnimation(NavigationStyle* navigation); |
| 40 |
using QVariantAnimation::state; |
| 41 |
|
| 42 |
Q_SIGNALS: |
| 43 |
void interrupted(); |
| 44 |
|
| 45 |
protected: |
| 46 |
NavigationStyle* navigation; |
| 47 |
|
| 48 |
virtual void initialize() = 0; |
| 49 |
virtual void update(const QVariant& value) = 0; |
| 50 |
virtual void onStop(bool finished); |
| 51 |
|
| 52 |
private: |
| 53 |
void updateCurrentValue(const QVariant& value) override; |
| 54 |
|
| 55 |
friend class NavigationAnimator; |
| 56 |
friend class QObject; |
| 57 |
}; |
| 58 |
|
| 59 |
class GuiExport FixedTimeAnimation: public NavigationAnimation |
| 60 |
{ |
| 61 |
public: |
| 62 |
explicit FixedTimeAnimation( |
| 63 |
NavigationStyle* navigation, |
| 64 |
const SbRotation& orientation, |
| 65 |
const SbVec3f& rotationCenter, |
| 66 |
const SbVec3f& translation, |
| 67 |
int duration, |
| 68 |
const QEasingCurve::Type easingCurve |
| 69 |
); |
| 70 |
|
| 71 |
private: |
| 72 |
float angularVelocity; // [rad/ms] |
| 73 |
SbVec3f linearVelocity; // [/ms] |
| 74 |
|
| 75 |
SbRotation targetOrientation; |
| 76 |
SbVec3f targetTranslation; |
| 77 |
|
| 78 |
float prevAngle; |
| 79 |
SbVec3f prevTranslation; |
| 80 |
|
| 81 |
SbVec3f rotationCenter; |
| 82 |
SbVec3f rotationAxis; |
| 83 |
|
| 84 |
void initialize() override; |
| 85 |
void update(const QVariant& value) override; |
| 86 |
void onStop(bool finished) override; |
| 87 |
}; |
| 88 |
|
| 89 |
class GuiExport SpinningAnimation: public NavigationAnimation |
| 90 |
{ |
| 91 |
public: |
| 92 |
explicit SpinningAnimation(NavigationStyle* navigation, const SbVec3f& axis, float velocity); |
| 93 |
|
| 94 |
private: |
| 95 |
SbVec3f rotationAxis; |
| 96 |
float prevAngle; |
| 97 |
|
| 98 |
void initialize() override; |
| 99 |
void update(const QVariant& value) override; |
| 100 |
void onStop(bool finished) override; |
| 101 |
}; |
| 102 |
|
| 103 |
} // namespace Gui |
| 104 |
|
| 105 |
#endif // GUI_NAVIGATIONANIMATION_H |