File indexing completed on 2024-04-21 04:52:34

0001 /*
0002     SPDX-FileCopyrightText: 2007 Jean-Baptiste Mardelle <jb@kdenlive.org>
0003 
0004 SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005 */
0006 
0007 #include "definitions.h"
0008 #include <KLocalizedString>
0009 
0010 #include <QColor>
0011 #include <utility>
0012 
0013 #ifdef CRASH_AUTO_TEST
0014 #pragma GCC diagnostic push
0015 #pragma GCC diagnostic ignored "-Wunused-parameter"
0016 #pragma GCC diagnostic ignored "-Wsign-conversion"
0017 #pragma GCC diagnostic ignored "-Wfloat-equal"
0018 #pragma GCC diagnostic ignored "-Wshadow"
0019 #pragma GCC diagnostic ignored "-Wpedantic"
0020 #include <rttr/registration>
0021 #pragma GCC diagnostic pop
0022 
0023 RTTR_REGISTRATION
0024 {
0025     using namespace rttr;
0026     // clang-format off
0027     registration::enumeration<GroupType>("GroupType")(
0028         value("Normal", GroupType::Normal),
0029         value("Selection", GroupType::Selection),
0030         value("AVSplit", GroupType::AVSplit),
0031         value("Leaf", GroupType::Leaf)
0032         );
0033     registration::enumeration<PlaylistState::ClipState>("PlaylistState")(
0034         value("VideoOnly", PlaylistState::VideoOnly),
0035         value("AudioOnly", PlaylistState::AudioOnly),
0036         value("Disabled", PlaylistState::Disabled)
0037         );
0038     // clang-format on
0039 }
0040 #endif
0041 
0042 QDebug operator<<(QDebug qd, const ItemInfo &info)
0043 {
0044     qd << "ItemInfo " << &info;
0045     qd << "\tTrack" << info.track;
0046     qd << "\tStart pos: " << info.startPos.toString();
0047     qd << "\tEnd pos: " << info.endPos.toString();
0048     qd << "\tCrop start: " << info.cropStart.toString();
0049     qd << "\tCrop duration: " << info.cropDuration.toString();
0050     return qd.maybeSpace();
0051 }
0052 
0053 CommentedTime::CommentedTime()
0054     : m_time(GenTime(0))
0055 
0056 {
0057 }
0058 
0059 CommentedTime::CommentedTime(const GenTime &time, QString comment, int markerType)
0060     : m_time(time)
0061     , m_comment(std::move(comment))
0062     , m_type(markerType)
0063 {
0064 }
0065 
0066 CommentedTime::CommentedTime(const QString &hash, const GenTime &time)
0067     : m_time(time)
0068     , m_comment(hash.section(QLatin1Char(':'), 1))
0069     , m_type(hash.section(QLatin1Char(':'), 0, 0).toInt())
0070 {
0071 }
0072 
0073 QString CommentedTime::comment() const
0074 {
0075     return (m_comment.isEmpty() ? i18n("Marker") : m_comment);
0076 }
0077 
0078 GenTime CommentedTime::time() const
0079 {
0080     return m_time;
0081 }
0082 
0083 void CommentedTime::setComment(const QString &comm)
0084 {
0085     m_comment = comm;
0086 }
0087 
0088 void CommentedTime::setTime(const GenTime &t)
0089 {
0090     m_time = t;
0091 }
0092 
0093 void CommentedTime::setMarkerType(int newtype)
0094 {
0095     m_type = newtype;
0096 }
0097 
0098 QString CommentedTime::hash() const
0099 {
0100     return QString::number(m_type) + QLatin1Char(':') + (m_comment.isEmpty() ? i18n("Marker") : m_comment);
0101 }
0102 
0103 int CommentedTime::markerType() const
0104 {
0105     return m_type;
0106 }
0107 
0108 bool CommentedTime::operator>(const CommentedTime &op) const
0109 {
0110     return m_time > op.time();
0111 }
0112 
0113 bool CommentedTime::operator<(const CommentedTime &op) const
0114 {
0115     return m_time < op.time();
0116 }
0117 
0118 bool CommentedTime::operator>=(const CommentedTime &op) const
0119 {
0120     return m_time >= op.time();
0121 }
0122 
0123 bool CommentedTime::operator<=(const CommentedTime &op) const
0124 {
0125     return m_time <= op.time();
0126 }
0127 
0128 bool CommentedTime::operator==(const CommentedTime &op) const
0129 {
0130     return m_time == op.time();
0131 }
0132 
0133 bool CommentedTime::operator!=(const CommentedTime &op) const
0134 {
0135     return m_time != op.time();
0136 }
0137 
0138 const QString groupTypeToStr(GroupType t)
0139 {
0140     switch (t) {
0141     case GroupType::Normal:
0142         return QStringLiteral("Normal");
0143     case GroupType::Selection:
0144         return QStringLiteral("Selection");
0145     case GroupType::AVSplit:
0146         return QStringLiteral("AVSplit");
0147     case GroupType::Leaf:
0148         return QStringLiteral("Leaf");
0149     }
0150     Q_ASSERT(false);
0151     return QString();
0152 }
0153 GroupType groupTypeFromStr(const QString &s)
0154 {
0155     std::vector<GroupType> types{GroupType::Selection, GroupType::Normal, GroupType::AVSplit, GroupType::Leaf};
0156     for (const auto &t : types) {
0157         if (s == groupTypeToStr(t)) {
0158             return t;
0159         }
0160     }
0161     Q_ASSERT(false);
0162     return GroupType::Normal;
0163 }
0164 
0165 std::pair<bool, bool> stateToBool(PlaylistState::ClipState state)
0166 {
0167     return {state == PlaylistState::VideoOnly, state == PlaylistState::AudioOnly};
0168 }
0169 PlaylistState::ClipState stateFromBool(std::pair<bool, bool> av)
0170 {
0171     Q_ASSERT(!av.first || !av.second);
0172     if (av.first) {
0173         return PlaylistState::VideoOnly;
0174     } else if (av.second) {
0175         return PlaylistState::AudioOnly;
0176     } else {
0177         return PlaylistState::Disabled;
0178     }
0179 }
0180 
0181 SubtitledTime::SubtitledTime()
0182     : m_starttime(0)
0183     , m_endtime(0)
0184 {
0185 }
0186 
0187 SubtitledTime::SubtitledTime(const GenTime &start, QString sub, const GenTime &end)
0188     : m_starttime(start)
0189     , m_subtitle(std::move(sub))
0190     , m_endtime(end)
0191 {
0192 }
0193 
0194 QString SubtitledTime::subtitle() const
0195 {
0196     return m_subtitle;
0197 }
0198 
0199 GenTime SubtitledTime::start() const
0200 {
0201     return m_starttime;
0202 }
0203 
0204 GenTime SubtitledTime::end() const
0205 {
0206     return m_endtime;
0207 }
0208 
0209 void SubtitledTime::setSubtitle(const QString &sub)
0210 {
0211     m_subtitle = sub;
0212 }
0213 
0214 void SubtitledTime::setEndTime(const GenTime &end)
0215 {
0216     m_endtime = end;
0217 }
0218 
0219 bool SubtitledTime::operator>(const SubtitledTime &op) const
0220 {
0221     return (m_starttime > op.m_starttime && m_endtime > op.m_endtime && m_starttime > op.m_endtime);
0222 }
0223 
0224 bool SubtitledTime::operator<(const SubtitledTime &op) const
0225 {
0226     return (m_starttime < op.m_starttime && m_endtime < op.m_endtime && m_endtime < op.m_starttime);
0227 }
0228 
0229 bool SubtitledTime::operator==(const SubtitledTime &op) const
0230 {
0231     return (m_starttime == op.m_starttime && m_endtime == op.m_endtime);
0232 }
0233 
0234 bool SubtitledTime::operator!=(const SubtitledTime &op) const
0235 {
0236     return (m_starttime != op.m_starttime && m_endtime != op.m_endtime);
0237 }