CuteLogger
Fast and simple logging solution for Qt based applications
subtitlecommands.h
1 /*
2  * Copyright (c) 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 SUBTITLECOMMANDS_H
19 #define SUBTITLECOMMANDS_H
20 
21 #include "models/subtitlesmodel.h"
22 #include <QUndoCommand>
23 
24 namespace Subtitles {
25 
26 enum {
27  UndoIdSubText = 400,
28  UndoIdSubStart,
29  UndoIdSubEnd,
30  UndoIdSubMove,
31 };
32 
33 class InsertTrackCommand : public QUndoCommand
34 {
35 public:
36  InsertTrackCommand(SubtitlesModel &model, const SubtitlesModel::SubtitleTrack &track, int index);
37  void redo();
38  void undo();
39 private:
40  SubtitlesModel &m_model;
41  SubtitlesModel::SubtitleTrack m_track;
42  int m_index;
43 };
44 
45 class RemoveTrackCommand : public QUndoCommand
46 {
47 public:
48  RemoveTrackCommand(SubtitlesModel &model, int trackIndex);
49  void redo();
50  void undo();
51 private:
52  SubtitlesModel &m_model;
53  int m_trackIndex;
54  SubtitlesModel::SubtitleTrack m_saveTrack;
55  QList<Subtitles::SubtitleItem> m_saveSubtitles;
56 };
57 
58 class EditTrackCommand : public QUndoCommand
59 {
60 public:
61  EditTrackCommand(SubtitlesModel &model, const SubtitlesModel::SubtitleTrack &track, int index);
62  void redo();
63  void undo();
64 private:
65  SubtitlesModel &m_model;
66  SubtitlesModel::SubtitleTrack m_oldTrack;
67  SubtitlesModel::SubtitleTrack m_newTrack;
68  int m_index;
69 };
70 
71 class OverwriteSubtitlesCommand : public QUndoCommand
72 {
73 public:
74  OverwriteSubtitlesCommand(SubtitlesModel &model, int trackIndex,
75  const QList<Subtitles::SubtitleItem> &items);
76  void redo();
77  void undo();
78 protected:
79  QList<Subtitles::SubtitleItem> m_newSubtitles;
80 private:
81  SubtitlesModel &m_model;
82  int m_trackIndex;
83  QList<Subtitles::SubtitleItem> m_saveSubtitles;
84 };
85 
86 class RemoveSubtitlesCommand : public QUndoCommand
87 {
88 public:
89  RemoveSubtitlesCommand(SubtitlesModel &model, int trackIndex,
90  const QList<Subtitles::SubtitleItem> &items);
91  void redo();
92  void undo();
93 private:
94  SubtitlesModel &m_model;
95  int m_trackIndex;
96  QList<Subtitles::SubtitleItem> m_items;
97 };
98 
99 class SetTextCommand : public QUndoCommand
100 {
101 public:
102  SetTextCommand(SubtitlesModel &model, int trackIndex, int itemIndex, const QString &text);
103  void redo();
104  void undo();
105 protected:
106  int id() const
107  {
108  return UndoIdSubText;
109  }
110  bool mergeWith(const QUndoCommand *other);
111 private:
112  SubtitlesModel &m_model;
113  int m_trackIndex;
114  int m_itemIndex;
115  QString m_newText;
116  QString m_oldText;
117 };
118 
119 class SetStartCommand : public QUndoCommand
120 {
121 public:
122  SetStartCommand(SubtitlesModel &model, int trackIndex, int itemIndex, int64_t msTime);
123  void redo();
124  void undo();
125 protected:
126  int id() const
127  {
128  return UndoIdSubStart;
129  }
130  bool mergeWith(const QUndoCommand *other);
131 private:
132  SubtitlesModel &m_model;
133  int m_trackIndex;
134  int m_itemIndex;
135  int64_t m_newStart;
136  int64_t m_oldStart;
137 };
138 
139 class SetEndCommand : public QUndoCommand
140 {
141 public:
142  SetEndCommand(SubtitlesModel &model, int trackIndex, int itemIndex, int64_t msTime);
143  void redo();
144  void undo();
145 protected:
146  int id() const
147  {
148  return UndoIdSubEnd;
149  }
150  bool mergeWith(const QUndoCommand *other);
151 private:
152  SubtitlesModel &m_model;
153  int m_trackIndex;
154  int m_itemIndex;
155  int64_t m_newEnd;
156  int64_t m_oldEnd;
157 };
158 
159 class MoveSubtitlesCommand : public QUndoCommand
160 {
161 public:
162  MoveSubtitlesCommand(SubtitlesModel &model, int trackIndex,
163  const QList<Subtitles::SubtitleItem> &items, int64_t msTime);
164  void redo();
165  void undo();
166 protected:
167  int id() const
168  {
169  return UndoIdSubMove;
170  }
171  bool mergeWith(const QUndoCommand *other);
172 private:
173  SubtitlesModel &m_model;
174  int m_trackIndex;
175  QList<Subtitles::SubtitleItem> m_oldSubtitles;
176  QList<Subtitles::SubtitleItem> m_newSubtitles;
177 };
178 
179 }
180 
181 #endif // SUBTITLECOMMANDS_H