/home/docs/checkouts/readthedocs.org/user_builds/mathvizanimator/checkouts/latest/libs/mva_gui/include/animations/abstract_animation.h Source File

MathVizAnimator: /home/docs/checkouts/readthedocs.org/user_builds/mathvizanimator/checkouts/latest/libs/mva_gui/include/animations/abstract_animation.h Source File
MathVizAnimator  0.0.1
abstract_animation.h
1 /* mathvizanimator
2  * Copyright (C) 2023 codingwithmagga
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef LIBS_MVA_GUI_INCLUDE_ANIMATIONS_ABSTRACT_ANIMATION_H_
19 #define LIBS_MVA_GUI_INCLUDE_ANIMATIONS_ABSTRACT_ANIMATION_H_
20 
21 #include <QObject>
22 #include <QString>
23 
24 #include "abstractitem.h"
25 
26 class AbstractAnimation : public QObject {
27  Q_OBJECT
28 
29  Q_PROPERTY(qreal start_time READ startTime WRITE setStartTime NOTIFY startTimeChanged FINAL)
30  Q_PROPERTY(qreal duration READ duration WRITE setDuration NOTIFY durationChanged FINAL)
31 
32  public:
33  enum class State { NOT_STARTED, RUNNING, DONE };
34 
35  explicit AbstractAnimation(QObject* parent = Q_NULLPTR);
36 
37  qreal startTime() const { return m_start_time; }
38  qreal duration() const { return m_duration; }
39 
40  void setStartTime(const qreal start_time);
41  void setDuration(const qreal duration);
42 
43  State state(const qreal time) const;
44 
45  void setFrameTime(const qreal frame_time);
46 
47  void setProperties(const QVariantMap& properties);
48 
49  virtual QJsonObject toJson() const;
50  virtual void applyAnimation(AbstractItem* item, const qreal time) const = 0;
51 
52  inline bool operator<(const AbstractAnimation& rhs) { return startTime() < rhs.startTime(); }
53 
54  signals:
55  void startTimeChanged(const qreal new_start_time);
56  void durationChanged(const qreal new_duration);
57 
58  private:
59  bool isStarted(const qreal time) const;
60  bool isDone(const qreal time) const;
61 
62  qreal m_start_time = 0.0;
63  qreal m_duration = 1.0;
64 
65  qreal m_frame_time = 1.0 / 24.0;
66 };
67 
68 #endif // LIBS_MVA_GUI_INCLUDE_ANIMATIONS_ABSTRACT_ANIMATION_H_
Definition: abstract_animation.h:26
An abstract class representing a visible item like a circle or a rectangle.
Definition: abstractitem.h:56