CuteLogger
Fast and simple logging solution for Qt based applications
keyframesmodel.h
1 /*
2  * Copyright (c) 2018-2020 Meltytech, LLC
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 KEYFRAMESMODEL_H
19 #define KEYFRAMESMODEL_H
20 
21 #include <QAbstractItemModel>
22 #include <QString>
23 #include <MltProperties.h>
24 #include <MltAnimation.h>
25 
26 class QmlMetadata;
27 class QmlFilter;
28 
29 class KeyframesModel : public QAbstractItemModel
30 {
31  Q_OBJECT
32 
33 public:
34  enum InterpolationType {
35  DiscreteInterpolation,
36  LinearInterpolation,
37  SmoothInterpolation
38  };
39  Q_ENUM(InterpolationType)
40 
41 
42  enum Roles {
43  NameRole = Qt::UserRole + 1,
44  PropertyNameRole,
45  IsCurveRole,
46  MinimumValueRole,
47  MaximumValueRole,
48  LowestValueRole,
49  HighestValueRole,
50  FrameNumberRole,
51  KeyframeTypeRole,
52  NumericValueRole,
53  MinimumFrameRole,
54  MaximumFrameRole
55  };
56 
57  explicit KeyframesModel(QObject *parent = 0);
58  virtual ~KeyframesModel();
59 
60  int rowCount(const QModelIndex &parent) const;
61  int columnCount(const QModelIndex &parent) const;
62  QVariant data(const QModelIndex &index, int role) const;
63  QModelIndex index(int row, int column = 0,
64  const QModelIndex &parent = QModelIndex()) const;
65  QModelIndex parent(const QModelIndex &index) const;
66  QHash<int, QByteArray> roleNames() const;
67  void load(QmlFilter *, QmlMetadata *);
68  Q_INVOKABLE bool remove(int parameterIndex, int keyframeIndex);
69  int previousKeyframePosition(int parameterIndex, int currentPosition);
70  int nextKeyframePosition(int parameterIndex, int currentPosition);
71  Q_INVOKABLE int keyframeIndex(int parameterIndex, int currentPosition);
72  Q_INVOKABLE int parameterIndex(const QString &propertyName) const;
73  Q_INVOKABLE bool setInterpolation(int parameterIndex, int keyframeIndex, InterpolationType type);
74  Q_INVOKABLE void setKeyframePosition(int parameterIndex, int keyframeIndex, int position);
75  Q_INVOKABLE void addKeyframe(int parameterIndex, double value, int position,
76  InterpolationType type);
77  Q_INVOKABLE void addKeyframe(int parameterIndex, int position);
78  Q_INVOKABLE void setKeyframeValue(int parameterIndex, int keyframeIndex, double value);
79  Q_INVOKABLE void setKeyframeValuePosition(int parameterIndex, int keyframeIndex, double value,
80  int position);
81  Q_INVOKABLE bool isKeyframe(int parameterIndex, int position);
82  Q_INVOKABLE bool advancedKeyframesInUse();
83  Q_INVOKABLE void removeAdvancedKeyframes();
84  Q_INVOKABLE bool simpleKeyframesInUse();
85  Q_INVOKABLE void removeSimpleKeyframes();
86 
87 signals:
88  void loaded();
89  void keyframeAdded(QString parameter, int position);
90 
91 public slots:
92  void reload();
93  void onFilterChanged(const QString &property);
94  void onFilterInChanged(int delta);
95  void trimFilterIn(int in);
96  void trimFilterOut(int out);
97 
98 private:
99  QList<QString> m_propertyNames;
100  QmlMetadata *m_metadata;
101  QmlFilter *m_filter;
102  QList<int> m_keyframeCounts;
103  QList<int> m_metadataIndex;
104 
105  int keyframeCount(int index) const;
106  void updateNeighborsMinMax(int parameterIndex, int keyframeIndex);
107 };
108 
109 #endif // KEYFRAMESMODEL_H