From f22a41cb05c5cc1bbe8ce391fa918707138afad3 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Wed, 9 Jan 2019 22:34:09 +0100 Subject: [PATCH] Only enable the preview button if we can actually preview something. --- futatabi/mainwindow.cpp | 26 ++++++++++++++++++++++++++ futatabi/mainwindow.h | 1 + 2 files changed, 27 insertions(+) diff --git a/futatabi/mainwindow.cpp b/futatabi/mainwindow.cpp index a7f6f82..4a4c0d6 100644 --- a/futatabi/mainwindow.cpp +++ b/futatabi/mainwindow.cpp @@ -342,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(); @@ -575,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) { @@ -809,6 +815,8 @@ void MainWindow::preview_single_frame(int64_t pts, unsigned stream_idx, MainWind 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); @@ -1031,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 + ")")); diff --git a/futatabi/mainwindow.h b/futatabi/mainwindow.h index 8d28611..d7e037c 100644 --- a/futatabi/mainwindow.h +++ b/futatabi/mainwindow.h @@ -138,6 +138,7 @@ private: void padding_toggled(double seconds, bool checked); void highlight_camera_input(int stream_idx); + void enable_or_disable_preview_button(); template void replace_model(QTableView *view, Model **model, Model *new_model); -- 2.39.2