]> git.sesse.net Git - nageru/blob - mainwindow.cpp
Support playing back arbitrary camera angles.
[nageru] / mainwindow.cpp
1 #include "mainwindow.h"
2
3 #include "clip_list.h"
4 #include "player.h"
5 #include "ui_mainwindow.h"
6
7 #include <string>
8 #include <vector>
9
10 #include <QShortcut>
11
12 using namespace std;
13
14 MainWindow *global_mainwindow = nullptr;
15 extern int64_t current_pts;
16 ClipList *clips;
17
18 MainWindow::MainWindow()
19         : ui(new Ui::MainWindow)
20 {
21         global_mainwindow = this;
22         ui->setupUi(this);
23
24         clips = new ClipList;
25         ui->clip_list->setModel(clips);
26
27         // TODO: Make these into buttons.
28         // TODO: These are too big for lambdas.
29         QShortcut *cue_in = new QShortcut(QKeySequence(Qt::Key_A), this);
30         connect(cue_in, &QShortcut::activated, []{
31                 if (!clips->empty() && clips->back()->pts_out < 0) {
32                         clips->back()->pts_in = current_pts;
33                         return;
34                 }
35                 Clip clip;
36                 clip.pts_in = current_pts;
37                 clips->add_clip(clip);
38         });
39
40         QShortcut *cue_out = new QShortcut(QKeySequence(Qt::Key_S), this);
41         connect(cue_out, &QShortcut::activated, []{
42                 if (!clips->empty()) {
43                         clips->back()->pts_out = current_pts;
44                         // TODO: select the row in the clip list?
45                 }
46         });
47
48         QShortcut *preview_shortcut = new QShortcut(QKeySequence(Qt::Key_W), this);
49         connect(preview_shortcut, &QShortcut::activated, this, &MainWindow::preview_clicked);
50 }
51
52 void MainWindow::preview_clicked()
53 {
54         QItemSelectionModel *selected = ui->clip_list->selectionModel();
55         if (!selected->hasSelection()) {
56                 play_clip(*clips->back(), 0);
57                 return;
58         }
59
60         QModelIndex index = selected->currentIndex();
61         if (index.column() >= ClipList::Column::CAMERA_1 &&
62             index.column() <= ClipList::Column::CAMERA_4) {
63                 unsigned stream_idx = index.column() - ClipList::Column::CAMERA_1;
64                 play_clip(*clips->clip(index.row()), stream_idx);
65         }
66 }