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