File indexing completed on 2024-12-22 04:40:10
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 LINESMODEL_H 0009 #define LINESMODEL_H 0010 0011 #include <QAbstractListModel> 0012 #include <QExplicitlySharedDataPointer> 0013 #include <QList> 0014 #include <QTimer> 0015 0016 namespace SubtitleComposer { 0017 class Subtitle; 0018 class SubtitleLine; 0019 0020 class LinesModel : public QAbstractListModel 0021 { 0022 Q_OBJECT 0023 0024 public: 0025 enum { Number = 0, PauseTime, ShowTime, HideTime, Duration, Text, Translation, ColumnCount }; 0026 enum { PlayingLineRole = Qt::UserRole, MarkedRole, ErrorRole, AnchoredRole }; 0027 0028 explicit LinesModel(QObject *parent = nullptr); 0029 0030 inline Subtitle * subtitle() const { return m_subtitle.data(); } 0031 void setSubtitle(Subtitle *subtitle); 0032 0033 inline SubtitleLine * playingLine() const { return m_playingLine; } 0034 void setPlayingLine(SubtitleLine *line); 0035 0036 int rowCount(const QModelIndex &parent = QModelIndex()) const override; 0037 int columnCount(const QModelIndex &parent = QModelIndex()) const override; 0038 0039 Qt::ItemFlags flags(const QModelIndex &index) const override; 0040 0041 QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; 0042 0043 QVariant data(const QModelIndex &index, int role) const override; 0044 bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override; 0045 0046 inline void processSelectionUpdate() { 0047 if(!m_resetModelTimer->isActive()) 0048 return; 0049 m_resetModelTimer->stop(); 0050 onModelReset(); 0051 } 0052 0053 private slots: 0054 void onLinesInserted(int firstIndex, int lastIndex); 0055 void onLinesAboutToRemove(int firstIndex, int lastIndex); 0056 void onLinesRemoved(int firstIndex, int lastIndex); 0057 void onModelReset(); 0058 0059 void onLineChanged(const SubtitleLine *line); 0060 void onLinesChanged(); 0061 void emitDataChanged(); 0062 0063 private: 0064 static QString buildToolTip(SubtitleLine *line, bool primary); 0065 0066 private: 0067 QExplicitlySharedDataPointer<Subtitle> m_subtitle; 0068 SubtitleLine *m_playingLine; 0069 QTimer *m_dataChangedTimer; 0070 int m_minChangedLineIndex; 0071 int m_maxChangedLineIndex; 0072 QTimer *m_resetModelTimer; 0073 std::pair<const SubtitleLine *, const SubtitleLine *> m_resetModelSelection; 0074 bool m_resetModelResumeEditing; 0075 0076 friend class LinesWidget; 0077 }; 0078 } 0079 0080 #endif // LINESMODEL_H