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