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 SUBTITLELINEACTIONS_H
0009 #define SUBTITLELINEACTIONS_H
0010 
0011 #include "core/undo/undoaction.h"
0012 #include "core/time.h"
0013 #include "core/richstring.h"
0014 #include "core/subtitleline.h"
0015 
0016 #include <QString>
0017 
0018 namespace SubtitleComposer {
0019 class SubtitleLineAction : public UndoAction
0020 {
0021 public:
0022     SubtitleLineAction(SubtitleLine *line, UndoStack::DirtyMode dirtyMode, const QString &desc = QString());
0023     virtual ~SubtitleLineAction();
0024 
0025 protected:
0026     SubtitleLine *m_line;
0027 
0028     template<class T>
0029     const T * tryCastToThisLineAction(const QUndoCommand *prevAction)
0030     {
0031         const T *castedPrevAction = dynamic_cast<const T *>(prevAction);
0032         return castedPrevAction ? (&castedPrevAction->m_line == &m_line ? castedPrevAction : 0) : 0;
0033     }
0034 };
0035 
0036 class SetLinePrimaryTextAction : public SubtitleLineAction
0037 {
0038     friend class SetLineTextsAction;
0039 
0040 public:
0041     SetLinePrimaryTextAction(SubtitleLine *line, RichDocument *primaryDoc);
0042     virtual ~SetLinePrimaryTextAction();
0043 
0044     inline int id() const override { return UndoAction::SetLinePrimaryText; }
0045     bool mergeWith(const QUndoCommand *command) override;
0046 
0047 protected:
0048     void undo() override;
0049     void redo() override;
0050 
0051 private:
0052     RichDocument *m_primaryDoc;
0053     int m_primaryDocState = -1;
0054 };
0055 
0056 class SetLineSecondaryTextAction : public SubtitleLineAction
0057 {
0058     friend class SetLineTextsAction;
0059 
0060 public:
0061     SetLineSecondaryTextAction(SubtitleLine *line, RichDocument *secondaryDoc);
0062     virtual ~SetLineSecondaryTextAction();
0063 
0064     inline int id() const override { return UndoAction::SetLineSecondaryText; }
0065     bool mergeWith(const QUndoCommand *command) override;
0066 
0067 protected:
0068     void undo() override;
0069     void redo() override;
0070 
0071 private:
0072     RichDocument *m_secondaryDoc;
0073     int m_secondaryDocState = -1;
0074 };
0075 
0076 class SetLineShowTimeAction : public SubtitleLineAction
0077 {
0078     friend class SetLineTimesAction;
0079 
0080 public:
0081     SetLineShowTimeAction(SubtitleLine *line, const Time &showTime);
0082     virtual ~SetLineShowTimeAction();
0083 
0084     inline int id() const override { return UndoAction::SetLineShowTime; }
0085     bool mergeWith(const QUndoCommand *command) override;
0086 
0087 protected:
0088     void redo() override;
0089 
0090 private:
0091     Time m_showTime;
0092 };
0093 
0094 class SetLineHideTimeAction : public SubtitleLineAction
0095 {
0096     friend class SetLineTimesAction;
0097 
0098 public:
0099     SetLineHideTimeAction(SubtitleLine *line, const Time &hideTime);
0100     virtual ~SetLineHideTimeAction();
0101 
0102     inline int id() const override { return UndoAction::SetLineHideTime; }
0103     bool mergeWith(const QUndoCommand *command) override;
0104 
0105 protected:
0106     void redo() override;
0107 
0108 private:
0109     Time m_hideTime;
0110 };
0111 
0112 class SetLineTimesAction : public SubtitleLineAction
0113 {
0114 public:
0115     SetLineTimesAction(SubtitleLine *line, const Time &showTime, const Time &hideTime, QString description = QString());
0116     virtual ~SetLineTimesAction();
0117 
0118     inline int id() const override { return UndoAction::SetLineTimes; }
0119     bool mergeWith(const QUndoCommand *command) override;
0120 
0121 protected:
0122     void redo() override;
0123 
0124 private:
0125     typedef enum { ShowTime = 0x1, HideTime = 0x2 } SignalFlags;
0126 
0127     Time m_showTime;
0128     Time m_hideTime;
0129 };
0130 
0131 class SetLineErrorsAction : public SubtitleLineAction
0132 {
0133 public:
0134     SetLineErrorsAction(SubtitleLine *line, int errorFlags);
0135     virtual ~SetLineErrorsAction();
0136 
0137     inline int id() const override { return UndoAction::SetLineErrors; }
0138     bool mergeWith(const QUndoCommand *command) override;
0139 
0140 protected:
0141     void redo() override;
0142 
0143 private:
0144     int m_errorFlags;
0145 };
0146 }
0147 
0148 #endif