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 PlayList::rowCount(const QModelIndex &parent) const {
50 if (parent.isValid()) return 0;
54 int ClipList::columnCount(const QModelIndex &parent) const {
55 if (parent.isValid()) return 0;
56 return int(Column::NUM_COLUMNS);
59 int PlayList::columnCount(const QModelIndex &parent) const {
60 if (parent.isValid()) return 0;
61 return int(Column::NUM_COLUMNS);
64 QVariant ClipList::data(const QModelIndex &parent, int role) const {
65 if (!parent.isValid())
67 const int row = parent.row(), column = parent.column();
68 if (size_t(row) >= clips.size())
71 if (role == Qt::TextAlignmentRole) {
72 switch (Column(column)) {
75 case Column::DURATION:
76 return Qt::AlignRight + Qt::AlignVCenter;
78 return Qt::AlignLeft + Qt::AlignVCenter;
82 if (role != Qt::DisplayRole)
85 switch (Column(column)) {
87 return QString::fromStdString(pts_to_string(clips[row].pts_in));
89 if (clips[row].pts_out >= 0) {
90 return QString::fromStdString(pts_to_string(clips[row].pts_out));
94 case Column::DURATION:
95 if (clips[row].pts_out >= 0) {
96 return QString::fromStdString(duration_to_string(clips[row].pts_out - clips[row].pts_in));
105 QVariant PlayList::data(const QModelIndex &parent, int role) const {
106 if (!parent.isValid())
108 const int row = parent.row(), column = parent.column();
109 if (size_t(row) >= clips.size())
112 if (role == Qt::TextAlignmentRole) {
113 switch (Column(column)) {
114 case Column::PLAYING:
115 return Qt::AlignCenter;
118 case Column::DURATION:
119 return Qt::AlignRight + Qt::AlignVCenter;
121 return Qt::AlignCenter;
123 return Qt::AlignLeft + Qt::AlignVCenter;
127 if (role != Qt::DisplayRole)
130 switch (Column(column)) {
131 case Column::PLAYING:
132 return (row == currently_playing_index) ? "→" : "";
134 return QString::fromStdString(pts_to_string(clips[row].pts_in));
136 if (clips[row].pts_out >= 0) {
137 return QString::fromStdString(pts_to_string(clips[row].pts_out));
141 case Column::DURATION:
142 if (clips[row].pts_out >= 0) {
143 return QString::fromStdString(duration_to_string(clips[row].pts_out - clips[row].pts_in));
148 return qlonglong(clips[row].stream_idx + 1);
154 QVariant ClipList::headerData(int section, Qt::Orientation orientation, int role) const {
155 if (role != Qt::DisplayRole)
157 if (orientation != Qt::Horizontal)
160 switch (Column(section)) {
165 case Column::DURATION:
167 case Column::CAMERA_1:
169 case Column::CAMERA_2:
171 case Column::CAMERA_3:
173 case Column::CAMERA_4:
180 QVariant PlayList::headerData(int section, Qt::Orientation orientation, int role) const {
181 if (role != Qt::DisplayRole)
183 if (orientation != Qt::Horizontal)
186 switch (Column(section)) {
187 case Column::PLAYING:
193 case Column::DURATION:
197 case Column::DESCRIPTION:
198 return "Description";
204 void ClipList::add_clip(const Clip &clip)
206 beginInsertRows(QModelIndex(), clips.size(), clips.size());
207 clips.push_back(clip);
211 void PlayList::add_clip(const Clip &clip)
213 beginInsertRows(QModelIndex(), clips.size(), clips.size());
214 clips.push_back(clip);
218 void ClipList::emit_data_changed(size_t row)
220 emit dataChanged(index(row, 0), index(row, int(Column::NUM_COLUMNS)));
223 void PlayList::emit_data_changed(size_t row)
225 emit dataChanged(index(row, 0), index(row, int(Column::NUM_COLUMNS)));
228 void PlayList::set_currently_playing(int index)
230 int old_index = currently_playing_index;
231 if (index != old_index) {
232 currently_playing_index = index;
233 if (old_index != -1) {
234 emit_data_changed(old_index);
237 emit_data_changed(index);