CuteLogger
Fast and simple logging solution for Qt based applications
filtercommands.h
1 /*
2  * Copyright (c) 2021-2024 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 FILTERCOMMANDS_H
19 #define FILTERCOMMANDS_H
20 
21 #include "models/attachedfiltersmodel.h"
22 #include <MltService.h>
23 #include <MltProducer.h>
24 #include <QUndoCommand>
25 #include <QString>
26 #include <QUuid>
27 
28 class QmlMetadata;
29 class FilterController;
30 
31 namespace Filter {
32 
33 enum {
34  UndoIdAdd = 300,
35  UndoIdMove,
36  UndoIdDisable,
37  UndoIdChangeParameter,
38  UndoIdChangeAddKeyframe,
39  UndoIdChangeRemoveKeyframe,
40  UndoIdChangeKeyframe,
41 };
42 
43 class AddCommand : public QUndoCommand
44 {
45 public:
46  typedef enum {
47  AddSingle,
48  AddSet,
49  AddSetLast,
50  } AddType;
51  AddCommand(AttachedFiltersModel &model, const QString &name, Mlt::Service &service, int row,
52  AddCommand::AddType type = AddCommand::AddSingle, QUndoCommand *parent = 0);
53  void redo();
54  void undo();
55 protected:
56  int id() const
57  {
58  return UndoIdAdd;
59  }
60  bool mergeWith(const QUndoCommand *other);
61 private:
62  AttachedFiltersModel &m_model;
63  std::vector<int> m_rows;
64  std::vector<Mlt::Service> m_services;
65  Mlt::Producer m_producer;
66  QUuid m_producerUuid;
67  AddType m_type;
68 };
69 
70 class RemoveCommand : public QUndoCommand
71 {
72 public:
73  RemoveCommand(AttachedFiltersModel &model, const QString &name, Mlt::Service &service, int row,
74  QUndoCommand *parent = 0);
75  void redo();
76  void undo();
77 private:
78  AttachedFiltersModel &m_model;
79  int m_index;
80  int m_row;
81  Mlt::Producer m_producer;
82  QUuid m_producerUuid;
83  Mlt::Service m_service;
84 };
85 
86 class MoveCommand : public QUndoCommand
87 {
88 public:
89  MoveCommand(AttachedFiltersModel &model, const QString &name, int fromRow, int toRow,
90  QUndoCommand *parent = 0);
91  void redo();
92  void undo();
93 protected:
94  int id() const
95  {
96  return UndoIdMove;
97  }
98 private:
99  AttachedFiltersModel &m_model;
100  int m_fromRow;
101  int m_toRow;
102  Mlt::Producer m_producer;
103  QUuid m_producerUuid;
104 };
105 
106 class DisableCommand : public QUndoCommand
107 {
108 public:
109  DisableCommand(AttachedFiltersModel &model, const QString &name, int row, bool disabled,
110  QUndoCommand *parent = 0);
111  void redo();
112  void undo();
113 protected:
114  int id() const
115  {
116  return UndoIdDisable;
117  }
118  bool mergeWith(const QUndoCommand *other);
119 private:
120  AttachedFiltersModel &m_model;
121  int m_row;
122  Mlt::Producer m_producer;
123  QUuid m_producerUuid;
124  bool m_disabled;
125 };
126 
127 class UndoParameterCommand : public QUndoCommand
128 {
129 public:
130  UndoParameterCommand(const QString &name, FilterController *controller, int row,
131  Mlt::Properties &before, const QString &desc = QString(), QUndoCommand *parent = 0);
132  void update(const QString &propertyName);
133  void redo();
134  void undo();
135 protected:
136  int id() const
137  {
138  return UndoIdChangeParameter;
139  }
140  bool mergeWith(const QUndoCommand *other);
141 private:
142  int m_row;
143  QUuid m_producerUuid;
144  Mlt::Properties m_before;
145  Mlt::Properties m_after;
146  FilterController *m_filterController;
147  bool m_firstRedo;
148 };
149 
150 class UndoAddKeyframeCommand : public UndoParameterCommand
151 {
152 public:
153  UndoAddKeyframeCommand(const QString &name, FilterController *controller, int row,
154  Mlt::Properties &before)
155  : UndoParameterCommand(name, controller, row, before, QObject::tr("add keyframe"))
156  {}
157 protected:
158  int id() const
159  {
160  return UndoIdChangeAddKeyframe;
161  }
162  bool mergeWith(const QUndoCommand *other)
163  {
164  return false;
165  }
166 };
167 
168 class UndoRemoveKeyframeCommand : public UndoParameterCommand
169 {
170 public:
171  UndoRemoveKeyframeCommand(const QString &name, FilterController *controller, int row,
172  Mlt::Properties &before)
173  : UndoParameterCommand(name, controller, row, before, QObject::tr("remove keyframe"))
174  {}
175 protected:
176  int id() const
177  {
178  return UndoIdChangeRemoveKeyframe;
179  }
180  bool mergeWith(const QUndoCommand *other)
181  {
182  return false;
183  }
184 };
185 
186 class UndoModifyKeyframeCommand : public UndoParameterCommand
187 {
188 public:
189  UndoModifyKeyframeCommand(const QString &name, FilterController *controller, int row,
190  Mlt::Properties &before, int paramIndex, int keyframeIndex)
191  : UndoParameterCommand(name, controller, row, before, QObject::tr("modify keyframe"))
192  , m_paramIndex(paramIndex)
193  , m_keyframeIndex(keyframeIndex)
194  {}
195 protected:
196  int id() const
197  {
198  return UndoIdChangeRemoveKeyframe;
199  }
200  bool mergeWith(const QUndoCommand *other)
201  {
202  auto *that = dynamic_cast<const UndoModifyKeyframeCommand *>(other);
203  if (!that || m_paramIndex != that->m_paramIndex || m_keyframeIndex != that->m_keyframeIndex)
204  return false;
205  else
206  return UndoParameterCommand::mergeWith(other);
207  }
208 
209 private:
210  int m_paramIndex;
211  int m_keyframeIndex;
212 };
213 
214 } // namespace Filter
215 
216 #endif // FILTERCOMMANDS_H