File indexing completed on 2024-06-16 04:38:25

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_SUBTITLELINE_H
0009 #define SCRIPTING_SUBTITLELINE_H
0010 
0011 #include "core/subtitleline.h"
0012 
0013 #include <QObject>
0014 #include <QString>
0015 
0016 namespace SubtitleComposer {
0017 namespace Scripting {
0018 class Subtitle;
0019 
0020 class SubtitleLine : public QObject
0021 {
0022     Q_OBJECT
0023 
0024 public slots:
0025 /// NOTE: target defaults to an invalid value, which means using and operation
0026 /// defined default value, generally dependent on translationMode value.
0027 /// Also, setSecondaryText is a noop is ! translationMode
0028     int number() const;
0029     int index() const;
0030 
0031     QObject * prevLine() const;
0032     QObject * nextLine() const;
0033 
0034     int primaryCharacters() const;
0035     int primaryWords() const;
0036     int primaryLines() const;
0037 
0038     QObject * primaryText() const;
0039     void setPrimaryText(QObject *text);
0040     QString plainPrimaryText() const;
0041     void setPlainPrimaryText(const QString &plainText);
0042     QString richPrimaryText() const;
0043     void setRichPrimaryText(const QString &richText);
0044 
0045     int secondaryCharacters() const;
0046     int secondaryWords() const;
0047     int secondaryLines() const;
0048 
0049     QObject * secondaryText() const;
0050     void setSecondaryText(QObject *text);
0051     QString plainSecondaryText() const;
0052     void setPlainSecondaryText(const QString &plainText);
0053     QString richSecondaryText() const;
0054     void setRichSecondaryText(const QString &richText);
0055 
0056     void breakText(int minLengthForBreak, int target = -1);
0057     void unbreakText(int target = -1);
0058     void simplifyTextWhiteSpace(int target = -1);
0059 
0060 /// all times or durations are specified in milliseconds
0061 
0062     int showTime() const;
0063     void setShowTime(int showTime);
0064 
0065     int hideTime() const;
0066     void setHideTime(int hideTime);
0067 
0068     int durationTime() const;
0069     void setDurationTime(int durationTime);
0070 
0071     int autoDuration(int msecsPerChar, int msecsPerWord, int msecsPerLine, int calculationTarget = -1);
0072 
0073     void shiftTimes(int mseconds);
0074     void adjustTimes(int shiftMseconds, double scaleFactor);
0075 
0076     int errorCount() const;
0077     int errorFlags() const;
0078     void setErrorFlags(int errorFlags);
0079     void setErrorFlags(int errorFlags, bool value);
0080 
0081     bool checkEmptyPrimaryText(bool update = true);
0082     bool checkEmptySecondaryText(bool update = true);
0083     bool checkUntranslatedText(bool update = true);
0084     bool checkOverlapsWithNext(bool update = true);
0085 
0086     bool checkMinDuration(int minMsecs, bool update = true);
0087     bool checkMaxDuration(int maxMsecs, bool update = true);
0088 
0089     bool checkMinDurationPerPrimaryChar(int minMsecsPerChar, bool update = true);
0090     bool checkMinDurationPerSecondaryChar(int minMsecsPerChar, bool update = true);
0091     bool checkMaxDurationPerPrimaryChar(int maxMsecsPerChar, bool update = true);
0092     bool checkMaxDurationPerSecondaryChar(int maxMsecsPerChar, bool update = true);
0093 
0094     bool checkMaxPrimaryChars(int maxCharacters, bool update = true);
0095     bool checkMaxSecondaryChars(int maxCharacters, bool update = true);
0096     bool checkMaxPrimaryLines(int maxLines, bool update = true);
0097     bool checkMaxSecondaryLines(int maxLines, bool update = true);
0098 
0099     bool checkPrimaryUnneededSpaces(bool update = true);
0100     bool checkSecondaryUnneededSpaces(bool update = true);
0101     bool checkPrimaryCapitalAfterEllipsis(bool update = true);
0102     bool checkSecondaryCapitalAfterEllipsis(bool update = true);
0103     bool checkPrimaryUnneededDash(bool update = true);
0104     bool checkSecondaryUnneededDash(bool update = true);
0105 
0106     int check(int errorFlagsToCheck, bool update = true);
0107 
0108     bool isRightToLeft() const;
0109 
0110 private:
0111     friend class Subtitle;
0112 
0113     SubtitleLine(SubtitleComposer::SubtitleLine *backend, QObject *parent = 0);
0114 
0115     SubtitleComposer::SubtitleLine *m_backend;
0116 };
0117 }
0118 }
0119 #endif