File indexing completed on 2024-06-16 04:38:14
0001 /* 0002 SPDX-FileCopyrightText: 2007-2009 Sergio Pistone <sergio_pistone@yahoo.com.ar> 0003 SPDX-FileCopyrightText: 2010-2022 Mladen Milinkovic <max@smoothware.net> 0004 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #ifndef SUBTITLEACTIONS_H 0009 #define SUBTITLEACTIONS_H 0010 0011 #include "core/range.h" 0012 #include "core/rangelist.h" 0013 #include "core/undo/undoaction.h" 0014 #include "core/richtext/richdocument.h" 0015 #include "core/subtitle.h" 0016 0017 #include <QString> 0018 #include <QList> 0019 0020 QT_FORWARD_DECLARE_CLASS(QTextEdit) 0021 0022 namespace SubtitleComposer { 0023 0024 class SubtitleAction : public UndoAction 0025 { 0026 public: 0027 SubtitleAction(Subtitle *subtitle, UndoStack::DirtyMode dirtyMode, const QString &description = QString()); 0028 virtual ~SubtitleAction(); 0029 0030 inline void setLineSubtitle(SubtitleLine *line) 0031 { 0032 line->m_primaryDoc->setStylesheet(m_subtitle->stylesheet()); 0033 line->m_secondaryDoc->setStylesheet(m_subtitle->stylesheet()); 0034 line->m_subtitle = m_subtitle; 0035 } 0036 0037 inline void clearLineSubtitle(SubtitleLine *line) 0038 { 0039 line->m_subtitle = nullptr; 0040 line->m_primaryDoc->setStylesheet(nullptr); 0041 line->m_secondaryDoc->setStylesheet(nullptr); 0042 } 0043 }; 0044 0045 class SetFramesPerSecondAction : public SubtitleAction 0046 { 0047 public: 0048 SetFramesPerSecondAction(Subtitle *subtitle, double framesPerSecond); 0049 virtual ~SetFramesPerSecondAction(); 0050 0051 inline int id() const override { return UndoAction::SetFramesPerSecond; } 0052 0053 protected: 0054 void redo() override; 0055 0056 private: 0057 double m_framesPerSecond; 0058 }; 0059 0060 class InsertLinesAction : public SubtitleAction 0061 { 0062 public: 0063 InsertLinesAction(Subtitle *subtitle, const QList<SubtitleLine *> &lines, int insertIndex = -1); 0064 virtual ~InsertLinesAction(); 0065 0066 inline int id() const override { return UndoAction::InsertLines; } 0067 bool mergeWith(const QUndoCommand *command) override; 0068 0069 protected: 0070 void redo() override; 0071 void undo() override; 0072 0073 private: 0074 int m_insertIndex; 0075 int m_lastIndex; 0076 QList<SubtitleLine *> m_lines; 0077 }; 0078 0079 class RemoveLinesAction : public SubtitleAction 0080 { 0081 public: 0082 RemoveLinesAction(Subtitle *subtitle, int firstIndex, int lastIndex = -1); 0083 virtual ~RemoveLinesAction(); 0084 0085 inline int id() const override { return UndoAction::RemoveLines; } 0086 bool mergeWith(const QUndoCommand *command) override; 0087 0088 protected: 0089 void redo() override; 0090 void undo() override; 0091 0092 private: 0093 int m_firstIndex; 0094 int m_lastIndex; 0095 QList<SubtitleLine *> m_lines; 0096 }; 0097 0098 class MoveLineAction : public SubtitleAction 0099 { 0100 public: 0101 MoveLineAction(Subtitle *subtitle, int fromIndex, int toIndex = -1); 0102 virtual ~MoveLineAction(); 0103 0104 inline int id() const override { return UndoAction::MoveLine; } 0105 bool mergeWith(const QUndoCommand *command) override; 0106 0107 protected: 0108 void redo() override; 0109 void undo() override; 0110 0111 private: 0112 int m_fromIndex; 0113 int m_toIndex; 0114 }; 0115 0116 class SwapLinesTextsAction : public SubtitleAction 0117 { 0118 public: 0119 SwapLinesTextsAction(Subtitle *subtitle, const RangeList &ranges); 0120 virtual ~SwapLinesTextsAction(); 0121 0122 inline int id() const override { return UndoAction::SwapLinesTexts; } 0123 0124 protected: 0125 void redo() override; 0126 0127 private: 0128 const RangeList m_ranges; 0129 }; 0130 0131 class EditStylesheetAction : public SubtitleAction 0132 { 0133 public: 0134 EditStylesheetAction(Subtitle *subtitle, QTextEdit *textEdit); 0135 virtual ~EditStylesheetAction(); 0136 0137 inline int id() const override { return UndoAction::ChangeStylesheet; } 0138 bool mergeWith(const QUndoCommand *command) override; 0139 0140 protected: 0141 void redo() override; 0142 void undo() override; 0143 0144 private: 0145 void update(const QString &stylesheet); 0146 0147 private: 0148 QTextEdit *m_stylesheetEdit; 0149 int m_stylesheetDocState = -1; 0150 }; 0151 0152 } 0153 #endif