From ced2e0772e21dd5cc23926a650c76270c0bdf2b2 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Mon, 11 Jun 2018 00:18:25 +0200 Subject: [PATCH] Hook up some more clip modifications. --- clip_list.cpp | 16 ++++++++++++---- clip_list.h | 29 ++++++++++++++++++++++++++++- main.cpp | 4 ++++ mainwindow.cpp | 31 ++++++++++++++++++++++++++++--- mainwindow.h | 3 +++ 5 files changed, 75 insertions(+), 8 deletions(-) diff --git a/clip_list.cpp b/clip_list.cpp index 48d8e7b..d8eada8 100644 --- a/clip_list.cpp +++ b/clip_list.cpp @@ -37,6 +37,12 @@ QVariant ClipList::data(const QModelIndex &parent, int role) const { } else { return QVariant(); } + case 2: + if (clips[row].pts_out >= 0) { + return qlonglong(clips[row].pts_out - clips[row].pts_in); + } else { + return QVariant(); + } default: return QVariant(); } @@ -68,12 +74,14 @@ QVariant ClipList::headerData(int section, Qt::Orientation orientation, int role } } -void ClipList::add_clip(int64_t pts_in) +void ClipList::add_clip(const Clip &clip) { - Clip clip; - clip.pts_in = pts_in; - beginInsertRows(QModelIndex(), clips.size(), clips.size()); clips.push_back(clip); endInsertRows(); } + +void ClipList::emit_data_changed(size_t row) +{ + emit dataChanged(index(row, 0), index(row, 6)); +} diff --git a/clip_list.h b/clip_list.h index adf3748..cb58564 100644 --- a/clip_list.h +++ b/clip_list.h @@ -22,8 +22,35 @@ public: QVariant data(const QModelIndex &parent, int role) const override; QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; - void add_clip(int64_t pts_in); + void add_clip(const Clip &clip); size_t size() const { return clips.size(); } + bool empty() const { return clips.empty(); } + + // Like a smart pointer to a Clip, but emits dataChanged when it goes out of scope. + struct ClipProxy { + public: + ClipProxy(Clip &clip, ClipList *clip_list, size_t row) + : clip(clip), clip_list(clip_list), row(row) {} + ~ClipProxy() { + if (clip_list != nullptr) { + clip_list->emit_data_changed(row); + } + } + Clip *operator->() { return &clip; } + + private: + Clip &clip; + ClipList *clip_list; + size_t row; + }; + + ClipProxy clip(size_t index) { return ClipProxy(clips[index], this, index); } + const Clip *clip(size_t index) const { return &clips[index]; } + + ClipProxy back() { return clip(size() - 1); } + const Clip *back() const { return clip(size() - 1); } + + void emit_data_changed(size_t row); private: std::vector clips; diff --git a/main.cpp b/main.cpp index 526ed57..865b98b 100644 --- a/main.cpp +++ b/main.cpp @@ -25,6 +25,9 @@ extern "C" { using namespace std; using namespace std::chrono; +// TODO: Replace by some sort of GUI control, I guess. +int64_t current_pts = 0; + string filename_for_frame(unsigned stream_idx, int64_t pts) { char filename[256]; @@ -100,6 +103,7 @@ int thread_func() this_thread::sleep_for(microseconds((pkt.pts - last_pts) * 1000000 / 12800)); } last_pts = pkt.pts; + current_pts = pkt.pts; } return 0; diff --git a/mainwindow.cpp b/mainwindow.cpp index e148345..9db4a9b 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -11,6 +11,7 @@ using namespace std; MainWindow *global_mainwindow = nullptr; +extern int64_t current_pts; MainWindow::MainWindow() : ui(new Ui::MainWindow) @@ -21,8 +22,32 @@ MainWindow::MainWindow() ClipList *clips = new ClipList; ui->clip_list->setModel(clips); - QShortcut *shortcut = new QShortcut(QKeySequence(Qt::Key_Q), this); - connect(shortcut, &QShortcut::activated, [clips]{ - clips->add_clip(12345); + // TODO: Make these into buttons. + // TODO: These are too big for lambdas. + QShortcut *cue_in = new QShortcut(QKeySequence(Qt::Key_A), this); + connect(cue_in, &QShortcut::activated, [clips]{ + if (!clips->empty() && clips->back()->pts_out < 0) { + clips->back()->pts_in = current_pts; + return; + } + Clip clip; + clip.pts_in = current_pts; + clips->add_clip(clip); }); + + QShortcut *cue_out = new QShortcut(QKeySequence(Qt::Key_S), this); + connect(cue_out, &QShortcut::activated, [clips]{ + if (!clips->empty()) { + clips->back()->pts_out = current_pts; + // TODO: select the row in the clip list? + } + }); + + QShortcut *preview_shortcut = new QShortcut(QKeySequence(Qt::Key_W), this); + connect(preview_shortcut, &QShortcut::activated, this, &MainWindow::preview_clicked); +} + +void MainWindow::preview_clicked() +{ + printf("preview\n"); } diff --git a/mainwindow.h b/mainwindow.h index f17757f..a1254b1 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -18,6 +18,9 @@ public: //private: Ui::MainWindow *ui; + +private: + void preview_clicked(); }; extern MainWindow *global_mainwindow; -- 2.39.2