extern int64_t current_pts;
+template <class Model>
+void replace_model(QTableView *view, Model **model, Model *new_model, MainWindow *main_window)
+{
+ QItemSelectionModel *old_selection_model = view->selectionModel();
+ view->setModel(new_model);
+ delete *model;
+ delete old_selection_model;
+ *model = new_model;
+ main_window->connect(new_model, &Model::any_content_changed, main_window, &MainWindow::content_changed);
+}
+
MainWindow::MainWindow()
: ui(new Ui::MainWindow),
db(global_flags.working_directory + "/futatabi.db")
global_mainwindow = this;
ui->setupUi(this);
+ // Load settings from database if needed.
+ if (!global_flags.interpolation_quality_set) {
+ SettingsProto settings = db.get_settings();
+ if (settings.interpolation_quality() != 0) {
+ global_flags.interpolation_quality = settings.interpolation_quality() - 1;
+ }
+ }
+ if (global_flags.interpolation_quality == 0) {
+ // Allocate something just for simplicity; we won't be using it
+ // unless the user changes runtime, in which case 1 is fine.
+ flow_initialized_interpolation_quality = 1;
+ } else {
+ flow_initialized_interpolation_quality = global_flags.interpolation_quality;
+ }
+ save_settings();
+
// The menus.
connect(ui->exit_action, &QAction::triggered, this, &MainWindow::exit_triggered);
connect(ui->export_cliplist_clip_multitrack_action, &QAction::triggered, this, &MainWindow::export_cliplist_clip_multitrack_triggered);
connect(ui->export_playlist_clip_interpolated_action, &QAction::triggered, this, &MainWindow::export_playlist_clip_interpolated_triggered);
connect(ui->manual_action, &QAction::triggered, this, &MainWindow::manual_triggered);
connect(ui->about_action, &QAction::triggered, this, &MainWindow::about_triggered);
+ connect(ui->undo_action, &QAction::triggered, this, &MainWindow::undo_triggered);
+ connect(ui->redo_action, &QAction::triggered, this, &MainWindow::redo_triggered);
+ ui->undo_action->setEnabled(false);
+ ui->redo_action->setEnabled(false);
+
+ // The quality group.
+ QActionGroup *quality_group = new QActionGroup(ui->interpolation_menu);
+ quality_group->addAction(ui->quality_0_action);
+ quality_group->addAction(ui->quality_1_action);
+ quality_group->addAction(ui->quality_2_action);
+ quality_group->addAction(ui->quality_3_action);
+ quality_group->addAction(ui->quality_4_action);
+ if (global_flags.interpolation_quality == 0) {
+ ui->quality_0_action->setChecked(true);
+ } else if (global_flags.interpolation_quality == 1) {
+ ui->quality_1_action->setChecked(true);
+ } else if (global_flags.interpolation_quality == 2) {
+ ui->quality_2_action->setChecked(true);
+ } else if (global_flags.interpolation_quality == 3) {
+ ui->quality_3_action->setChecked(true);
+ } else if (global_flags.interpolation_quality == 4) {
+ ui->quality_4_action->setChecked(true);
+ } else {
+ assert(false);
+ }
+ connect(ui->quality_0_action, &QAction::toggled, bind(&MainWindow::quality_toggled, this, 0, _1));
+ connect(ui->quality_1_action, &QAction::toggled, bind(&MainWindow::quality_toggled, this, 1, _1));
+ connect(ui->quality_2_action, &QAction::toggled, bind(&MainWindow::quality_toggled, this, 2, _1));
+ connect(ui->quality_3_action, &QAction::toggled, bind(&MainWindow::quality_toggled, this, 3, _1));
+ connect(ui->quality_4_action, &QAction::toggled, bind(&MainWindow::quality_toggled, this, 4, _1));
global_disk_space_estimator = new DiskSpaceEstimator(bind(&MainWindow::report_disk_space, this, _1, _2));
disk_free_label = new QLabel(this);
ui->menuBar->setCornerWidget(disk_free_label);
StateProto state = db.get_state();
+ undo_stack.push_back(state); // The undo stack always has the current state on top.
cliplist_clips = new ClipList(state.clip_list());
ui->clip_list->setModel(cliplist_clips);
defer_timeout = new QTimer(this);
defer_timeout->setSingleShot(true);
connect(defer_timeout, &QTimer::timeout, this, &MainWindow::defer_timer_expired);
+ ui->undo_action->setEnabled(true);
connect(ui->clip_list->selectionModel(), &QItemSelectionModel::currentChanged,
this, &MainWindow::clip_list_selection_changed);
void MainWindow::state_changed(const StateProto &state)
{
db.store_state(state);
+
+ redo_stack.clear();
+ ui->redo_action->setEnabled(false);
+
+ undo_stack.push_back(state);
+ ui->undo_action->setEnabled(undo_stack.size() > 1);
+
+ // Make sure it doesn't grow without bounds.
+ while (undo_stack.size() >= 100) {
+ undo_stack.pop_front();
+ }
+}
+
+void MainWindow::save_settings()
+{
+ SettingsProto settings;
+ settings.set_interpolation_quality(global_flags.interpolation_quality + 1);
+ db.store_settings(settings);
}
void MainWindow::play_clicked()
AboutDialog("Futatabi", "Multicamera slow motion video server").exec();
}
+void MainWindow::undo_triggered()
+{
+ // Finish any deferred action.
+ if (defer_timeout->isActive()) {
+ defer_timeout->stop();
+ state_changed(deferred_state);
+ }
+
+ StateProto redo_state;
+ *redo_state.mutable_clip_list() = cliplist_clips->serialize();
+ *redo_state.mutable_play_list() = playlist_clips->serialize();
+ redo_stack.push_back(std::move(redo_state));
+ ui->redo_action->setEnabled(true);
+
+ assert(undo_stack.size() > 1);
+
+ // Pop off the current state, which is always at the top of the stack.
+ undo_stack.pop_back();
+
+ StateProto state = undo_stack.back();
+ ui->undo_action->setEnabled(undo_stack.size() > 1);
+
+ replace_model(ui->clip_list, &cliplist_clips, new ClipList(state.clip_list()), this);
+ replace_model(ui->playlist, &playlist_clips, new PlayList(state.play_list()), this);
+
+ db.store_state(state);
+}
+
+void MainWindow::redo_triggered()
+{
+ assert(!redo_stack.empty());
+
+ ui->undo_action->setEnabled(true);
+ ui->redo_action->setEnabled(true);
+
+ undo_stack.push_back(std::move(redo_stack.back()));
+ redo_stack.pop_back();
+ ui->undo_action->setEnabled(true);
+ ui->redo_action->setEnabled(!redo_stack.empty());
+
+ const StateProto &state = undo_stack.back();
+ replace_model(ui->clip_list, &cliplist_clips, new ClipList(state.clip_list()), this);
+ replace_model(ui->playlist, &playlist_clips, new PlayList(state.play_list()), this);
+
+ db.store_state(state);
+}
+
+void MainWindow::quality_toggled(int quality, bool checked)
+{
+ if (!checked) {
+ return;
+ }
+ global_flags.interpolation_quality = quality;
+ if (quality != 0 && // Turning interpolation off is always possible.
+ quality != flow_initialized_interpolation_quality) {
+ QMessageBox msgbox;
+ msgbox.setText(QString::fromStdString(
+ "The interpolation quality for the main output cannot be changed at runtime, "
+ "except being turned completely off; it will take effect for exported files "
+ "only until next restart. The live output quality thus remains at " + to_string(flow_initialized_interpolation_quality) + "."));
+ msgbox.exec();
+ }
+
+ save_settings();
+}
+
void MainWindow::highlight_camera_input(int stream_idx)
{
if (stream_idx == 0) {