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, InterpolationType type);
76  Q_INVOKABLE void addKeyframe(int parameterIndex, int position);
77  Q_INVOKABLE void setKeyframeValue(int parameterIndex, int keyframeIndex, double value);
78  Q_INVOKABLE void setKeyframeValuePosition(int parameterIndex, int keyframeIndex, double value, int position);
79  Q_INVOKABLE bool isKeyframe(int parameterIndex, int position);
80  Q_INVOKABLE bool advancedKeyframesInUse();
81  Q_INVOKABLE void removeAdvancedKeyframes();
82  Q_INVOKABLE bool simpleKeyframesInUse();
83  Q_INVOKABLE void removeSimpleKeyframes();
84 
85 signals:
86  void loaded();
87  void keyframeAdded(QString parameter, int position);
88 
89 public slots:
90  void reload();
91  void onFilterChanged(const QString& property);
92  void onFilterInChanged(int delta);
93  void trimFilterIn(int in);
94  void trimFilterOut(int out);
95 
96 private:
97  QList<QString> m_propertyNames;
98  QmlMetadata* m_metadata;
99  QmlFilter* m_filter;
100  QList<int> m_keyframeCounts;
101  QList<int> m_metadataIndex;
102 
103  int keyframeCount(int index) const;
104  void updateNeighborsMinMax(int parameterIndex, int keyframeIndex);
105 };
106 
107 #endif // KEYFRAMESMODEL_H