7 #include <QAbstractTableModel>
14 int64_t pts_in = -1, pts_out = -1; // pts_in is inclusive, pts_out is exclusive.
15 std::string descriptions[NUM_CAMERAS];
16 unsigned stream_idx = 0; // For the playlist only.
17 double fade_time_seconds = 0.5; // For the playlist only.
20 class DataChangedReceiver {
22 virtual ~DataChangedReceiver() {}
23 virtual void emit_data_changed(size_t row) = 0;
26 // Like a smart pointer to a Clip, but emits dataChanged when it goes out of scope.
29 ClipProxy(Clip &clip, DataChangedReceiver *clip_list, size_t row)
30 : clip(clip), clip_list(clip_list), row(row) {}
33 if (clip_list != nullptr) {
34 clip_list->emit_data_changed(row);
37 Clip *operator->() { return &clip; }
38 Clip &operator*() { return clip; }
42 DataChangedReceiver *clip_list;
46 class ClipList : public QAbstractTableModel, public DataChangedReceiver {
50 explicit ClipList(const ClipListProto &serialized);
56 CAMERA_1, // Then CAMERA_2, CAMERA_3, etc. as needed.
57 NUM_NON_CAMERA_COLUMNS = CAMERA_1
60 int rowCount(const QModelIndex &parent) const override;
61 int columnCount(const QModelIndex &parent) const override;
62 QVariant data(const QModelIndex &parent, int role) const override;
63 QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
64 Qt::ItemFlags flags(const QModelIndex &index) const override;
65 bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
67 void add_clip(const Clip &clip);
68 size_t size() const { return clips.size(); }
69 bool empty() const { return clips.empty(); }
71 ClipProxy mutable_clip(size_t index) { return ClipProxy(clips[index], this, index); }
72 const Clip *clip(size_t index) const { return &clips[index]; }
74 ClipProxy mutable_back() { return mutable_clip(size() - 1); }
75 const Clip *back() const { return clip(size() - 1); }
77 ClipListProto serialize() const;
79 void emit_data_changed(size_t row) override;
81 static bool is_camera_column(int column)
83 return (column >= int(Column::CAMERA_1) && column < int(Column::CAMERA_1) + NUM_CAMERAS);
87 void any_content_changed();
90 std::vector<Clip> clips;
93 class PlayList : public QAbstractTableModel, public DataChangedReceiver {
97 explicit PlayList(const ClipListProto &serialized);
110 int rowCount(const QModelIndex &parent) const override;
111 int columnCount(const QModelIndex &parent) const override;
112 QVariant data(const QModelIndex &parent, int role) const override;
113 QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
114 Qt::ItemFlags flags(const QModelIndex &index) const override;
115 bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
117 void add_clip(const Clip &clip);
119 // <last> is inclusive in all of these.
120 void duplicate_clips(size_t first, size_t last);
121 void erase_clips(size_t first, size_t last);
122 // <delta> is -1 to move upwards, +1 to move downwards.
123 void move_clips(size_t first, size_t last, int delta);
125 size_t size() const { return clips.size(); }
126 bool empty() const { return clips.empty(); }
128 ClipProxy mutable_clip(size_t index) { return ClipProxy(clips[index], this, index); }
129 const Clip *clip(size_t index) const { return &clips[index]; }
131 ClipProxy mutable_back() { return mutable_clip(size() - 1); }
132 const Clip *back() const { return clip(size() - 1); }
134 // TODO: Move these out of PlayList.
135 void set_currently_playing(int index, double progress); // -1 = none.
136 int get_currently_playing() const { return currently_playing_index; }
138 void set_progress(const std::map<size_t, double> &progress);
140 ClipListProto serialize() const;
142 void emit_data_changed(size_t row) override;
145 void any_content_changed();
148 std::vector<Clip> clips;
149 int currently_playing_index = -1;
150 double play_progress = 0.0;
151 std::map<size_t, double> current_progress;
154 #endif // !defined (_CLIP_LIST_H)