CuteLogger
Fast and simple logging solution for Qt based applications
keyframesmodel.h
1 /*
2  * Copyright (c) 2018-2019 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  FrameNumberRole,
49  KeyframeTypeRole,
50  NumericValueRole,
51  MinimumFrameRole,
52  MaximumFrameRole
53  };
54 
55  explicit KeyframesModel(QObject* parent = 0);
56  virtual ~KeyframesModel();
57 
58  int rowCount(const QModelIndex& parent) const;
59  int columnCount(const QModelIndex& parent) const;
60  QVariant data(const QModelIndex& index, int role) const;
61  QModelIndex index(int row, int column = 0,
62  const QModelIndex& parent = QModelIndex()) const;
63  QModelIndex parent(const QModelIndex& index) const;
64  QHash<int, QByteArray> roleNames() const;
65  void load(QmlFilter*, QmlMetadata*);
66  Q_INVOKABLE bool remove(int parameterIndex, int keyframeIndex);
67  int previousKeyframePosition(int parameterIndex, int currentPosition);
68  int nextKeyframePosition(int parameterIndex, int currentPosition);
69  Q_INVOKABLE int keyframeIndex(int parameterIndex, int currentPosition);
70  Q_INVOKABLE int parameterIndex(const QString& propertyName) const;
71  Q_INVOKABLE bool setInterpolation(int parameterIndex, int keyframeIndex, InterpolationType type);
72  Q_INVOKABLE bool setPosition(int parameterIndex, int keyframeIndex, int position);
73  Q_INVOKABLE void addKeyframe(int parameterIndex, double value, int position, InterpolationType type);
74  Q_INVOKABLE void addKeyframe(int parameterIndex, int position);
75  Q_INVOKABLE void setKeyframe(int parameterIndex, double value, int position, InterpolationType type);
76  Q_INVOKABLE bool isKeyframe(int parameterIndex, int position);
77 
78 signals:
79  void loaded();
80 
81 public slots:
82  void reload();
83  void onFilterChanged(const QString& property);
84  void onFilterInChanged(int delta);
85  void onFilterOutChanged(int delta);
86 
87 private:
88  QList<QString> m_propertyNames;
89  QmlMetadata* m_metadata;
90  QmlFilter* m_filter;
91  QList<int> m_keyframeCounts;
92  QList<int> m_metadataIndex;
93 
94  int keyframeCount(int index) const;
95  void updateNeighborsMinMax(int parameterIndex, int keyframeIndex);
96 };
97 
98 #endif // KEYFRAMESMODEL_H