File indexing completed on 2024-06-09 04:53:08

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 SCRIPTING_SUBTITLE_H
0009 #define SCRIPTING_SUBTITLE_H
0010 
0011 #include "scripting_subtitleline.h"
0012 #include "core/subtitle.h"
0013 #include "core/rangelist.h"
0014 
0015 #include <QExplicitlySharedDataPointer>
0016 #include <QObject>
0017 
0018 namespace SubtitleComposer {
0019 class Subtitle;
0020 
0021 namespace Scripting {
0022 class Subtitle : public QObject
0023 {
0024     Q_OBJECT
0025 
0026 public slots:
0027 /// NOTE: target defaults to an invalid value, which means using and operation
0028 /// defined default value, generally dependent on translationMode value.
0029     double framesPerSecond() const;
0030     void setFramesPerSecond(double framesPerSecond);
0031 
0032     bool isEmpty() const;
0033     int linesCount() const;
0034     int lastIndex() const;
0035 
0036     QObject * firstLine();
0037     QObject * lastLine();
0038     QObject * line(int index);
0039 
0040     void changeFramesPerSecond(double toFramesPerSecond, double fromFramesPerSecond = -1.0);
0041 
0042     SubtitleLine * insertNewLine(int index, bool timeAfter, int target = -1);
0043     void removeLine(int index, int target = -1);
0044     void removeLines(QObject *ranges, int target = -1);
0045 
0046     void swapTexts(QObject *ranges);
0047 
0048     void splitLines(QObject *ranges);
0049     void joinLines(QObject *ranges);
0050 
0051     void shiftLines(QObject *ranges, int msecs);
0052     void adjustLines(QObject *range, int firstTime, int lastTime);
0053     void sortLines(QObject *range);
0054 
0055     void applyDurationLimits(QObject *ranges, int minDuration, int maxDuration, bool canOverlap);
0056     void setMaximumDurations(QObject *ranges);
0057     void setAutoDurations(QObject *ranges, int msecsPerChar, int msecsPerWord, int msecsPerLine, bool canOverlap, int calculationTarget = -1);
0058 
0059     void fixOverlappingLines(QObject *ranges, int minInterval = 100);
0060 
0061     void fixPunctuation(QObject *ranges, bool spaces, bool quotes, bool englishI, bool ellipsis, int target = -1);
0062 
0063     void lowerCase(QObject *ranges, int target = -1);
0064     void upperCase(QObject *ranges, int target = -1);
0065     void titleCase(QObject *ranges, bool lowerFirst, int target = -1);
0066     void sentenceCase(QObject *ranges, bool lowerFirst, int target = -1);
0067 
0068     void breakLines(QObject *ranges, int minLengthForLineBreak, int target = -1);
0069     void unbreakTexts(QObject *ranges, int target = -1);
0070     void simplifyTextWhiteSpace(QObject *ranges, int target = -1);
0071 
0072     void setMarked(QObject *ranges, bool value);
0073 
0074     void clearErrors(QObject *ranges, int errorFlags);
0075 
0076     void checkErrors(QObject *ranges, int errorFlags);
0077 
0078     void recheckErrors(QObject *ranges);
0079 
0080 private:
0081     static SubtitleComposer::RangeList toRangesList(const QObject *object);
0082 
0083     friend class SubtitleModule;
0084 
0085     Subtitle(SubtitleComposer::Subtitle *backend, QObject *parent);
0086 
0087     QExplicitlySharedDataPointer<SubtitleComposer::Subtitle> m_backend;
0088 };
0089 }
0090 }
0091 #endif