]> git.sesse.net Git - nageru/blobdiff - futatabi/mainwindow.cpp
Only enable the preview button if we can actually preview something.
[nageru] / futatabi / mainwindow.cpp
index d73f579a9e6faee5880c6ac2447004a1df6cc99c..4a4c0d658f2a54f478d84847295020ec37888163 100644 (file)
@@ -273,21 +273,33 @@ void MainWindow::cue_in_clicked()
 {
        if (!cliplist_clips->empty() && cliplist_clips->back()->pts_out < 0) {
                cliplist_clips->mutable_back()->pts_in = current_pts;
-               return;
+       } else {
+               Clip clip;
+               clip.pts_in = max<int64_t>(current_pts - lrint(global_flags.cue_point_padding_seconds * TIMEBASE), 0);
+               cliplist_clips->add_clip(clip);
+               playlist_selection_changed();
        }
-       Clip clip;
-       clip.pts_in = max<int64_t>(current_pts - lrint(global_flags.cue_point_padding_seconds * TIMEBASE), 0);
-       cliplist_clips->add_clip(clip);
-       playlist_selection_changed();
+
+       // Select the item so that we can jog it.
+       ui->clip_list->setFocus();
+       QModelIndex index = cliplist_clips->index(cliplist_clips->size() - 1, int(ClipList::Column::IN));
+       ui->clip_list->selectionModel()->setCurrentIndex(index, QItemSelectionModel::ClearAndSelect);
        ui->clip_list->scrollToBottom();
 }
 
 void MainWindow::cue_out_clicked()
 {
-       if (!cliplist_clips->empty()) {
-               cliplist_clips->mutable_back()->pts_out = current_pts + lrint(global_flags.cue_point_padding_seconds * TIMEBASE);
-               // TODO: select the row in the clip list?
+       if (cliplist_clips->empty()) {
+               return;
        }
+
+       cliplist_clips->mutable_back()->pts_out = current_pts + lrint(global_flags.cue_point_padding_seconds * TIMEBASE);
+
+       // Select the item so that we can jog it.
+       ui->clip_list->setFocus();
+       QModelIndex index = cliplist_clips->index(cliplist_clips->size() - 1, int(ClipList::Column::OUT));
+       ui->clip_list->selectionModel()->setCurrentIndex(index, QItemSelectionModel::ClearAndSelect);
+       ui->clip_list->scrollToBottom();
 }
 
 void MainWindow::queue_clicked()
@@ -330,6 +342,8 @@ void MainWindow::queue_clicked()
 
 void MainWindow::preview_clicked()
 {
+       // See also enable_or_disable_preview_button().
+
        if (ui->playlist->hasFocus()) {
                // Allow the playlist as preview iff it has focus and something is selected.
                QItemSelectionModel *selected = ui->playlist->selectionModel();
@@ -524,21 +538,6 @@ void MainWindow::live_player_done()
        ui->stop_btn->setEnabled(false);
 }
 
-static string format_duration(double t)
-{
-       int t_ms = lrint(t * 1e3);
-
-       int ms = t_ms % 1000;
-       t_ms /= 1000;
-       int s = t_ms % 60;
-       t_ms /= 60;
-       int m = t_ms;
-
-       char buf[256];
-       snprintf(buf, sizeof(buf), "%d:%02d.%03d", m, s, ms);
-       return buf;
-}
-
 void MainWindow::live_player_clip_progress(const map<uint64_t, double> &progress, double time_remaining)
 {
        playlist_clips->set_progress(progress);
@@ -578,6 +577,10 @@ bool MainWindow::eventFilter(QObject *watched, QEvent *event)
        int scrub_sensitivity = 100;  // pts units per pixel.
        int wheel_sensitivity = 100;  // pts units per degree.
 
+       if (event->type() == QEvent::FocusIn || event->type() == QEvent::FocusOut) {
+               enable_or_disable_preview_button();
+       }
+
        unsigned stream_idx = ui->preview_display->get_stream_idx();
 
        if (watched == ui->clip_list) {
@@ -806,11 +809,14 @@ void MainWindow::preview_single_frame(int64_t pts, unsigned stream_idx, MainWind
        Clip fake_clip;
        fake_clip.pts_in = pts;
        fake_clip.pts_out = pts + 1;
+       fake_clip.stream_idx = stream_idx;
        preview_player->play(fake_clip);
 }
 
 void MainWindow::playlist_selection_changed()
 {
+       enable_or_disable_preview_button();
+
        QItemSelectionModel *selected = ui->playlist->selectionModel();
        bool any_selected = selected->hasSelection();
        ui->playlist_duplicate_btn->setEnabled(any_selected);
@@ -1033,9 +1039,30 @@ void MainWindow::highlight_camera_input(int stream_idx)
        }
 }
 
+void MainWindow::enable_or_disable_preview_button()
+{
+       // Follows the logic in preview_clicked().
+
+       if (ui->playlist->hasFocus()) {
+               // Allow the playlist as preview iff it has focus and something is selected.
+               // TODO: Is this part really relevant?
+               QItemSelectionModel *selected = ui->playlist->selectionModel();
+               if (selected->hasSelection()) {
+                       ui->preview_btn->setEnabled(true);
+                       return;
+               }
+       }
+
+       // TODO: Perhaps only enable this if something is actually selected.
+       ui->preview_btn->setEnabled(!cliplist_clips->empty());
+}
+
 void MainWindow::set_output_status(const string &status)
 {
        ui->live_label->setText(QString::fromStdString("Current output (" + status + ")"));
+       if (live_player != nullptr) {
+               live_player->set_pause_status(status);
+       }
 
        lock_guard<mutex> lock(queue_status_mu);
        queue_status = status;