1 /* 2 SPDX-FileCopyrightText: 2007-2009 Sergio Pistone <sergio_pistone@yahoo.com.ar> 3 SPDX-FileCopyrightText: 2010-2018 Mladen Milinkovic <max@smoothware.net> 4 5 SPDX-License-Identifier: GPL-2.0-or-later 6 */ 7 8 #ifndef SUBTITLEITERATOR_H 9 #define SUBTITLEITERATOR_H 10 11 #include "core/range.h" 12 #include "core/rangelist.h" 13 #include "core/subtitle.h" 14 15 #include <QExplicitlySharedDataPointer> 16 #include <QObject> 17 #include <QList> 18 19 namespace SubtitleComposer { 20 class SubtitleLine; 21 class Subtitle; 22 class SubtitleIterator : public QObject 23 { 24 Q_OBJECT 25 Q_PROPERTY(int index READ index WRITE toIndex) 26 27 public: 28 enum { 29 AfterLast = -1, 30 BehindFirst = -2, 31 Invalid = -3 32 }; 33 34 explicit SubtitleIterator(const Subtitle &subtitle, const RangeList &ranges = Range::full(), bool toLast = false); 35 SubtitleIterator(const SubtitleIterator &it); 36 SubtitleIterator & operator=(const SubtitleIterator &it); 37 virtual ~SubtitleIterator(); 38 39 RangeList ranges() const; 40 41 void toFirst(); 42 void toLast(); 43 bool toIndex(int index); 44 index()45 inline int index() { return m_index; } firstIndex()46 inline int firstIndex() { return m_index == Invalid ? -1 : m_ranges.firstIndex(); } lastIndex()47 inline int lastIndex() { return m_index == Invalid ? -1 : m_ranges.lastIndex(); } 48 current()49 inline SubtitleLine * current() const { return const_cast<SubtitleLine *>(m_subtitle->line(m_index)); } 50 inline operator SubtitleLine *() const { return const_cast<SubtitleLine *>(m_subtitle->line(m_index)); } 51 52 SubtitleIterator & operator++(); 53 SubtitleIterator & operator+=(int steps); 54 SubtitleIterator & operator--(); 55 SubtitleIterator & operator-=(int steps); 56 57 private: 58 QExplicitlySharedDataPointer<const Subtitle> m_subtitle; 59 RangeList m_ranges; 60 int m_index; 61 RangeList::ConstIterator m_rangesIterator; 62 }; 63 } 64 65 #endif 66