]> git.sesse.net Git - nageru/blob - clip_list.cpp
Allow playing from the playlist.
[nageru] / clip_list.cpp
1 #include "mainwindow.h"
2
3 #include "clip_list.h"
4 #include "ui_mainwindow.h"
5
6 #include <string>
7 #include <vector>
8
9 using namespace std;
10
11 int ClipList::rowCount(const QModelIndex &parent) const {
12         if (parent.isValid()) return 0;
13         return clips.size();
14 }
15
16 int ClipList::columnCount(const QModelIndex &parent) const {
17         if (parent.isValid()) return 0;
18         if (display_type == ListDisplay::CLIP_LIST) {
19                 return int(ClipListColumn::NUM_COLUMNS);
20         } else {
21                 return int(PlayListColumn::NUM_COLUMNS);
22         }
23 }
24
25 QVariant ClipList::data(const QModelIndex &parent, int role) const {
26         if (!parent.isValid())
27                 return QVariant();
28         if (role != Qt::DisplayRole)
29                 return QVariant();
30
31         const int row = parent.row(), column = parent.column();
32         if (size_t(row) >= clips.size())
33                 return QVariant();
34
35         if (display_type == ListDisplay::CLIP_LIST) {
36                 switch (ClipListColumn(column)) {
37                 case ClipListColumn::IN:
38                         return qlonglong(clips[row].pts_in);
39                 case ClipListColumn::OUT:
40                         if (clips[row].pts_out >= 0) {
41                                 return qlonglong(clips[row].pts_out);
42                         } else {
43                                 return QVariant();
44                         }
45                 case ClipListColumn::DURATION:
46                         if (clips[row].pts_out >= 0) {
47                                 return qlonglong(clips[row].pts_out - clips[row].pts_in);
48                         } else {
49                                 return QVariant();
50                         }
51                 default:
52                         return "";
53                 }
54         } else {
55                 switch (PlayListColumn(column)) {
56                 case PlayListColumn::PLAYING:
57                         return (row == currently_playing_index) ? "→" : "";
58                 case PlayListColumn::IN:
59                         return qlonglong(clips[row].pts_in);
60                 case PlayListColumn::OUT:
61                         if (clips[row].pts_out >= 0) {
62                                 return qlonglong(clips[row].pts_out);
63                         } else {
64                                 return QVariant();
65                         }
66                 case PlayListColumn::DURATION:
67                         if (clips[row].pts_out >= 0) {
68                                 return qlonglong(clips[row].pts_out - clips[row].pts_in);
69                         } else {
70                                 return QVariant();
71                         }
72                 case PlayListColumn::CAMERA:
73                         return qlonglong(clips[row].stream_idx + 1);
74                 default:
75                         return "";
76                 }
77         }
78 }
79
80 QVariant ClipList::headerData(int section, Qt::Orientation orientation, int role) const {
81         if (role != Qt::DisplayRole)
82                 return QVariant();
83         if (orientation != Qt::Horizontal)
84                 return QVariant();
85
86         if (display_type == ListDisplay::CLIP_LIST) {
87                 switch (ClipListColumn(section)) {
88                 case ClipListColumn::IN:
89                         return "In";
90                 case ClipListColumn::OUT:
91                         return "Out";
92                 case ClipListColumn::DURATION:
93                         return "Duration";
94                 case ClipListColumn::CAMERA_1:
95                         return "Camera 1";
96                 case ClipListColumn::CAMERA_2:
97                         return "Camera 2";
98                 case ClipListColumn::CAMERA_3:
99                         return "Camera 3";
100                 case ClipListColumn::CAMERA_4:
101                         return "Camera 4";
102                 default:
103                         return "";
104                 }
105         } else {
106                 switch (PlayListColumn(section)) {
107                 case PlayListColumn::PLAYING:
108                         return "";
109                 case PlayListColumn::IN:
110                         return "In";
111                 case PlayListColumn::OUT:
112                         return "Out";
113                 case PlayListColumn::DURATION:
114                         return "Duration";
115                 case PlayListColumn::CAMERA:
116                         return "Camera";
117                 case PlayListColumn::DESCRIPTION:
118                         return "Description";
119                 default:
120                         return "";
121                 }
122         }
123 }
124
125 void ClipList::add_clip(const Clip &clip)
126 {
127         beginInsertRows(QModelIndex(), clips.size(), clips.size());
128         clips.push_back(clip);
129         endInsertRows();
130 }
131
132 void ClipList::emit_data_changed(size_t row)
133 {
134         if (display_type == ListDisplay::CLIP_LIST) {
135                 emit dataChanged(index(row, 0), index(row, int(ClipListColumn::NUM_COLUMNS)));
136         } else {
137                 emit dataChanged(index(row, 0), index(row, int(PlayListColumn::NUM_COLUMNS)));
138         }
139 }
140
141 void ClipList::set_currently_playing(int index)
142 {
143         int old_index = currently_playing_index;
144         if (index != old_index) {
145                 currently_playing_index = index;
146                 if (old_index != -1) {
147                         emit_data_changed(old_index);
148                 }
149                 if (index != -1) {
150                         emit_data_changed(index);
151                 }
152         }
153 }