1 #include "mainwindow.h"
8 #include "ui_mainwindow.h"
12 string pts_to_string(int64_t pts)
14 // FIXME: This depends on a fixed timebase.
15 int64_t t = lrint((pts / 12800.0) * 1e3); // In milliseconds.
25 snprintf(buf, sizeof(buf), "%d:%02d:%02d.%03d", hour, min, sec, ms);
29 string duration_to_string(int64_t pts_diff)
31 // FIXME: This depends on a fixed timebase.
32 int64_t t = lrint((pts_diff / 12800.0) * 1e3); // In milliseconds.
40 snprintf(buf, sizeof(buf), "%d:%02d.%03d", min, sec, ms);
44 int ClipList::rowCount(const QModelIndex &parent) const {
45 if (parent.isValid()) return 0;
49 int ClipList::columnCount(const QModelIndex &parent) const {
50 if (parent.isValid()) return 0;
51 if (display_type == ListDisplay::CLIP_LIST) {
52 return int(ClipListColumn::NUM_COLUMNS);
54 return int(PlayListColumn::NUM_COLUMNS);
58 QVariant ClipList::data(const QModelIndex &parent, int role) const {
59 if (!parent.isValid())
61 const int row = parent.row(), column = parent.column();
62 if (size_t(row) >= clips.size())
65 if (role == Qt::TextAlignmentRole) {
66 if (display_type == ListDisplay::CLIP_LIST) {
67 switch (ClipListColumn(column)) {
68 case ClipListColumn::IN:
69 case ClipListColumn::OUT:
70 case ClipListColumn::DURATION:
71 return Qt::AlignRight + Qt::AlignVCenter;
73 return Qt::AlignLeft + Qt::AlignVCenter;
76 switch (PlayListColumn(column)) {
77 case PlayListColumn::PLAYING:
78 return Qt::AlignCenter;
79 case PlayListColumn::IN:
80 case PlayListColumn::OUT:
81 case PlayListColumn::DURATION:
82 return Qt::AlignRight + Qt::AlignVCenter;
83 case PlayListColumn::CAMERA:
84 return Qt::AlignCenter;
86 return Qt::AlignLeft + Qt::AlignVCenter;
91 if (role != Qt::DisplayRole)
94 if (display_type == ListDisplay::CLIP_LIST) {
95 switch (ClipListColumn(column)) {
96 case ClipListColumn::IN:
97 return QString::fromStdString(pts_to_string(clips[row].pts_in));
98 case ClipListColumn::OUT:
99 if (clips[row].pts_out >= 0) {
100 return QString::fromStdString(pts_to_string(clips[row].pts_out));
104 case ClipListColumn::DURATION:
105 if (clips[row].pts_out >= 0) {
106 return QString::fromStdString(duration_to_string(clips[row].pts_out - clips[row].pts_in));
114 switch (PlayListColumn(column)) {
115 case PlayListColumn::PLAYING:
116 return (row == currently_playing_index) ? "→" : "";
117 case PlayListColumn::IN:
118 return QString::fromStdString(pts_to_string(clips[row].pts_in));
119 case PlayListColumn::OUT:
120 if (clips[row].pts_out >= 0) {
121 return QString::fromStdString(pts_to_string(clips[row].pts_out));
125 case PlayListColumn::DURATION:
126 if (clips[row].pts_out >= 0) {
127 return QString::fromStdString(duration_to_string(clips[row].pts_out - clips[row].pts_in));
131 case PlayListColumn::CAMERA:
132 return qlonglong(clips[row].stream_idx + 1);
139 QVariant ClipList::headerData(int section, Qt::Orientation orientation, int role) const {
140 if (role != Qt::DisplayRole)
142 if (orientation != Qt::Horizontal)
145 if (display_type == ListDisplay::CLIP_LIST) {
146 switch (ClipListColumn(section)) {
147 case ClipListColumn::IN:
149 case ClipListColumn::OUT:
151 case ClipListColumn::DURATION:
153 case ClipListColumn::CAMERA_1:
155 case ClipListColumn::CAMERA_2:
157 case ClipListColumn::CAMERA_3:
159 case ClipListColumn::CAMERA_4:
165 switch (PlayListColumn(section)) {
166 case PlayListColumn::PLAYING:
168 case PlayListColumn::IN:
170 case PlayListColumn::OUT:
172 case PlayListColumn::DURATION:
174 case PlayListColumn::CAMERA:
176 case PlayListColumn::DESCRIPTION:
177 return "Description";
184 void ClipList::add_clip(const Clip &clip)
186 beginInsertRows(QModelIndex(), clips.size(), clips.size());
187 clips.push_back(clip);
191 void ClipList::emit_data_changed(size_t row)
193 if (display_type == ListDisplay::CLIP_LIST) {
194 emit dataChanged(index(row, 0), index(row, int(ClipListColumn::NUM_COLUMNS)));
196 emit dataChanged(index(row, 0), index(row, int(PlayListColumn::NUM_COLUMNS)));
200 void ClipList::set_currently_playing(int index)
202 int old_index = currently_playing_index;
203 if (index != old_index) {
204 currently_playing_index = index;
205 if (old_index != -1) {
206 emit_data_changed(old_index);
209 emit_data_changed(index);