]> 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 154537c7c4c05791c8532d8f35eb29536d3a46a2..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();
@@ -563,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) {
@@ -791,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);
@@ -1018,6 +1039,24 @@ 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 + ")"));