#include "clip_list.h"
#include "player.h"
+#include "post_to_main_thread.h"
#include "ui_mainwindow.h"
#include <string>
MainWindow *global_mainwindow = nullptr;
extern int64_t current_pts;
-ClipList *cliplist_clips, *playlist_clips;
+ClipList *cliplist_clips;
+PlayList *playlist_clips;
MainWindow::MainWindow()
: ui(new Ui::MainWindow)
global_mainwindow = this;
ui->setupUi(this);
- cliplist_clips = new ClipList(ClipList::ListDisplay::CLIP_LIST);
+ cliplist_clips = new ClipList();
ui->clip_list->setModel(cliplist_clips);
- playlist_clips = new ClipList(ClipList::ListDisplay::PLAY_LIST);
+ playlist_clips = new PlayList();
ui->playlist->setModel(playlist_clips);
// TODO: These are too big for lambdas.
preview_player = new Player(ui->preview_display);
live_player = new Player(ui->live_display);
+ live_player->set_done_callback([this]{
+ post_to_main_thread([this]{
+ live_player_clip_done();
+ });
+ });
}
void MainWindow::queue_clicked()
}
QModelIndex index = selected->currentIndex();
- if (index.column() >= int(ClipList::ClipListColumn::CAMERA_1) &&
- index.column() <= int(ClipList::ClipListColumn::CAMERA_4)) {
+ if (index.column() >= int(ClipList::Column::CAMERA_1) &&
+ index.column() <= int(ClipList::Column::CAMERA_4)) {
Clip clip = *cliplist_clips->clip(index.row());
- clip.stream_idx = index.column() - int(ClipList::ClipListColumn::CAMERA_1);
+ clip.stream_idx = index.column() - int(ClipList::Column::CAMERA_1);
playlist_clips->add_clip(clip);
}
}
void MainWindow::preview_clicked()
{
+ if (cliplist_clips->empty()) return;
+
QItemSelectionModel *selected = ui->clip_list->selectionModel();
if (!selected->hasSelection()) {
preview_player->play_clip(*cliplist_clips->back(), 0);
}
QModelIndex index = selected->currentIndex();
- if (index.column() >= int(ClipList::ClipListColumn::CAMERA_1) &&
- index.column() <= int(ClipList::ClipListColumn::CAMERA_4)) {
- unsigned stream_idx = index.column() - int(ClipList::ClipListColumn::CAMERA_1);
+ if (index.column() >= int(ClipList::Column::CAMERA_1) &&
+ index.column() <= int(ClipList::Column::CAMERA_4)) {
+ unsigned stream_idx = index.column() - int(ClipList::Column::CAMERA_1);
preview_player->play_clip(*cliplist_clips->clip(index.row()), stream_idx);
}
}
void MainWindow::play_clicked()
{
+ if (playlist_clips->empty()) return;
+
QItemSelectionModel *selected = ui->playlist->selectionModel();
int row;
if (!selected->hasSelection()) {
row = selected->selectedRows(0)[0].row();
}
- const Clip &clip = *cliplist_clips->clip(row);
+ const Clip &clip = *playlist_clips->clip(row);
live_player->play_clip(clip, clip.stream_idx);
playlist_clips->set_currently_playing(row);
}
+
+void MainWindow::live_player_clip_done()
+{
+ int row = playlist_clips->get_currently_playing();
+ if (row != -1 && row < int(playlist_clips->size()) - 1) {
+ ++row;
+ const Clip &clip = *playlist_clips->clip(row);
+ live_player->play_clip(clip, clip.stream_idx);
+ playlist_clips->set_currently_playing(row);
+ } else {
+ playlist_clips->set_currently_playing(-1);
+ }
+}
+
+void MainWindow::resizeEvent(QResizeEvent *event)
+{
+ QMainWindow::resizeEvent(event);
+
+ // Ask for a relayout, but only after the event loop is done doing relayout
+ // on everything else.
+ QMetaObject::invokeMethod(this, "relayout", Qt::QueuedConnection);
+}
+
+void MainWindow::relayout()
+{
+ ui->live_display->setMinimumHeight(ui->live_display->width() * 9 / 16);
+}