]> git.sesse.net Git - nageru/blobdiff - futatabi/mainwindow.cpp
Only enable the queue button if we can actually queue something.
[nageru] / futatabi / mainwindow.cpp
index 77a3ba35e35bebfdf31c5df258052c75dcffb1e7..b39d8d4a3e55290501216a499e4fddec38571ce7 100644 (file)
@@ -203,6 +203,7 @@ MainWindow::MainWindow()
 
        connect(ui->clip_list->selectionModel(), &QItemSelectionModel::currentChanged,
                this, &MainWindow::clip_list_selection_changed);
+       enable_or_disable_queue_button();
 
        // Find out how many cameras we have in the existing frames;
        // if none, we start with two cameras.
@@ -285,6 +286,7 @@ void MainWindow::cue_in_clicked()
        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();
+       enable_or_disable_queue_button();
 }
 
 void MainWindow::cue_out_clicked()
@@ -300,10 +302,13 @@ void MainWindow::cue_out_clicked()
        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();
+       enable_or_disable_queue_button();
 }
 
 void MainWindow::queue_clicked()
 {
+       // See also enable_or_disable_queue_button().
+
        if (cliplist_clips->empty()) {
                return;
        }
@@ -342,6 +347,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();
@@ -575,6 +582,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) {
@@ -803,11 +814,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);
@@ -837,6 +851,7 @@ void MainWindow::clip_list_selection_changed(const QModelIndex &current, const Q
                camera_selected = current.column() - int(ClipList::Column::CAMERA_1);
        }
        highlight_camera_input(camera_selected);
+       enable_or_disable_queue_button();
 }
 
 void MainWindow::report_disk_space(off_t free_bytes, double estimated_seconds_left)
@@ -1030,6 +1045,48 @@ 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::enable_or_disable_queue_button()
+{
+       // Follows the logic in queue_clicked().
+       // TODO: Perhaps only enable this if something is actually selected.
+
+       bool enabled;
+
+       if (cliplist_clips->empty()) {
+               enabled = false;
+       } else {
+               QItemSelectionModel *selected = ui->clip_list->selectionModel();
+               if (!selected->hasSelection()) {
+                       Clip clip = *cliplist_clips->back();
+                       enabled = clip.pts_out != -1;
+               } else {
+                       QModelIndex index = selected->currentIndex();
+                       Clip clip = *cliplist_clips->clip(index.row());
+                       enabled = clip.pts_out != -1;
+               }
+       }
+
+       ui->queue_btn->setEnabled(enabled);
+}
+
 void MainWindow::set_output_status(const string &status)
 {
        ui->live_label->setText(QString::fromStdString("Current output (" + status + ")"));