]> git.sesse.net Git - nageru/blob - clip_list.cpp
Some refactoring of the player code, and begin working on 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         switch (column) {
36         case 0:
37                 return qlonglong(clips[row].pts_in);
38         case 1:
39                 if (clips[row].pts_out >= 0) {
40                         return qlonglong(clips[row].pts_out);
41                 } else {
42                         return QVariant();
43                 }
44         case 2:
45                 if (clips[row].pts_out >= 0) {
46                         return qlonglong(clips[row].pts_out - clips[row].pts_in);
47                 } else {
48                         return QVariant();
49                 }
50         default:
51                 return QVariant();
52         }
53 }
54
55 QVariant ClipList::headerData(int section, Qt::Orientation orientation, int role) const {
56         if (role != Qt::DisplayRole)
57                 return QVariant();
58         if (orientation != Qt::Horizontal)
59                 return QVariant();
60
61         if (display_type == ListDisplay::CLIP_LIST) {
62                 switch (ClipListColumn(section)) {
63                 case ClipListColumn::IN:
64                         return "In";
65                 case ClipListColumn::OUT:
66                         return "Out";
67                 case ClipListColumn::DURATION:
68                         return "Duration";
69                 case ClipListColumn::CAMERA_1:
70                         return "Camera 1";
71                 case ClipListColumn::CAMERA_2:
72                         return "Camera 2";
73                 case ClipListColumn::CAMERA_3:
74                         return "Camera 3";
75                 case ClipListColumn::CAMERA_4:
76                         return "Camera 4";
77                 default:
78                         return "";
79                 }
80         } else {
81                 switch (PlayListColumn(section)) {
82                 case PlayListColumn::IN:
83                         return "In";
84                 case PlayListColumn::OUT:
85                         return "Out";
86                 case PlayListColumn::DURATION:
87                         return "Duration";
88                 case PlayListColumn::CAMERA:
89                         return "Camera";
90                 case PlayListColumn::DESCRIPTION:
91                         return "Description";
92                 default:
93                         return "";
94                 }
95         }
96 }
97
98 void ClipList::add_clip(const Clip &clip)
99 {
100         beginInsertRows(QModelIndex(), clips.size(), clips.size());
101         clips.push_back(clip);
102         endInsertRows();
103 }
104
105 void ClipList::emit_data_changed(size_t row)
106 {
107         if (display_type == ListDisplay::CLIP_LIST) {
108                 emit dataChanged(index(row, 0), index(row, int(ClipListColumn::NUM_COLUMNS)));
109         } else {
110                 emit dataChanged(index(row, 0), index(row, int(PlayListColumn::NUM_COLUMNS)));
111         }
112 }