diff --git a/dialogs/replaceclipmediadialog.cpp b/dialogs/replaceclipmediadialog.cpp index e8732164f..c1f042f22 100644 --- a/dialogs/replaceclipmediadialog.cpp +++ b/dialogs/replaceclipmediadialog.cpp @@ -19,9 +19,8 @@ #include #include -ReplaceClipMediaDialog::ReplaceClipMediaDialog(QWidget *parent, SourceTable *table, Media *old_media) : +ReplaceClipMediaDialog::ReplaceClipMediaDialog(QWidget *parent, Media *old_media) : QDialog(parent), - source_table(table), media(old_media) { resize(300, 400); @@ -30,11 +29,11 @@ ReplaceClipMediaDialog::ReplaceClipMediaDialog(QWidget *parent, SourceTable *tab layout->addWidget(new QLabel("Select which media you want to replace this media's clips with:")); - tree = new QTreeView(); + tree = new QTreeView(); layout->addWidget(tree); - use_same_media_in_points = new QCheckBox("Keep the same media in-points"); + use_same_media_in_points = new QCheckBox("Keep the same media in-points"); use_same_media_in_points->setChecked(true); layout->addWidget(use_same_media_in_points); @@ -56,34 +55,34 @@ ReplaceClipMediaDialog::ReplaceClipMediaDialog(QWidget *parent, SourceTable *tab setLayout(layout); - tree->setModel(&project_model); + tree->setModel(&project_model); - //copy_tree(NULL, NULL); + //copy_tree(NULL, NULL); } void ReplaceClipMediaDialog::replace() { - QModelIndexList selected_items = tree->selectionModel()->selectedRows(); - if (selected_items.size() != 1) { + QModelIndexList selected_items = panel_project->get_current_selected(); + if (selected_items.size() != 1) { QMessageBox::critical(this, "No media selected", "Please select a media to replace with or click 'Cancel'.", QMessageBox::Ok); } else { - Media* new_item = static_cast(selected_items.at(0).internalPointer()); + Media* new_item = static_cast(selected_items.at(0).internalPointer()); if (media == new_item) { QMessageBox::critical(this, "Same media selected", "You selected the same media that you're replacing. Please select a different one or click 'Cancel'.", QMessageBox::Ok); - } else if (new_item->get_type() == MEDIA_TYPE_FOLDER) { + } else if (new_item->get_type() == MEDIA_TYPE_FOLDER) { QMessageBox::critical(this, "Folder selected", "You cannot replace footage with a folder.", QMessageBox::Ok); } else { - if (new_item->get_type() == MEDIA_TYPE_SEQUENCE && sequence == new_item->to_sequence()) { + if (new_item->get_type() == MEDIA_TYPE_SEQUENCE && sequence == new_item->to_sequence()) { QMessageBox::critical(this, "Active sequence selected", "You cannot insert a sequence into itself.", QMessageBox::Ok); - } else { + } else { ReplaceClipMediaCommand* rcmc = new ReplaceClipMediaCommand( - media, - new_item, + media, + new_item, use_same_media_in_points->isChecked() ); - for (int i=0;iclips.size();i++) { - Clip* c = sequence->clips.at(i); - if (c != NULL && c->media == media) { + for (int i=0;iclips.size();i++) { + Clip* c = sequence->clips.at(i); + if (c != NULL && c->media == media) { rcmc->clips.append(c); } } diff --git a/dialogs/replaceclipmediadialog.h b/dialogs/replaceclipmediadialog.h index 15498336b..114d6fb9d 100644 --- a/dialogs/replaceclipmediadialog.h +++ b/dialogs/replaceclipmediadialog.h @@ -11,14 +11,13 @@ class QCheckBox; class ReplaceClipMediaDialog : public QDialog { Q_OBJECT public: - ReplaceClipMediaDialog(QWidget* parent, SourceTable* table, Media *old_media); + ReplaceClipMediaDialog(QWidget* parent, Media *old_media); private slots: void replace(); private: - SourceTable* source_table; - QTreeView* tree; - Media* media; - QCheckBox* use_same_media_in_points; + Media* media; + QTreeView* tree; + QCheckBox* use_same_media_in_points; }; #endif // REPLACECLIPMEDIADIALOG_H diff --git a/mainwindow.cpp b/mainwindow.cpp index 738e7c9b6..b7ac8d3f9 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -12,6 +12,7 @@ #include "ui/sourcetable.h" #include "ui/viewerwidget.h" +#include "ui/sourceiconview.h" #include "panels/panels.h" #include "panels/project.h" @@ -41,6 +42,7 @@ #include #include #include +#include MainWindow* mainWindow; @@ -52,44 +54,43 @@ QString appName = "Olive (December 2018 | Alpha)"; bool demoNoticeShown = false; void MainWindow::setup_layout(bool reset) { - panel_project->show(); - panel_effect_controls->show(); - panel_footage_viewer->show(); - panel_sequence_viewer->show(); - panel_timeline->show(); + panel_project->show(); + panel_effect_controls->show(); + panel_footage_viewer->show(); + panel_sequence_viewer->show(); + panel_timeline->show(); - bool load_default = true; + bool load_default = true; - /*if (!reset) { - QFile panel_config(get_data_path() + "/layout"); - if (panel_config.exists() && panel_config.open(QFile::ReadOnly)) { - if (restoreState(panel_config.readAll(), 0)) { - load_default = false; - } - panel_config.close(); - } - }*/ + /*if (!reset) { + QFile panel_config(get_data_path() + "/layout"); + if (panel_config.exists() && panel_config.open(QFile::ReadOnly)) { + if (restoreState(panel_config.readAll(), 0)) { + load_default = false; + } + panel_config.close(); + } + }*/ - if (load_default) { - addDockWidget(Qt::TopDockWidgetArea, panel_project); - addDockWidget(Qt::TopDockWidgetArea, panel_footage_viewer); - tabifyDockWidget(panel_footage_viewer, panel_effect_controls); - panel_footage_viewer->raise(); - addDockWidget(Qt::TopDockWidgetArea, panel_sequence_viewer); - addDockWidget(Qt::BottomDockWidgetArea, panel_timeline); + if (load_default) { + addDockWidget(Qt::TopDockWidgetArea, panel_project); + addDockWidget(Qt::TopDockWidgetArea, panel_footage_viewer); + tabifyDockWidget(panel_footage_viewer, panel_effect_controls); + panel_footage_viewer->raise(); + addDockWidget(Qt::TopDockWidgetArea, panel_sequence_viewer); + addDockWidget(Qt::BottomDockWidgetArea, panel_timeline); // workaround for strange Qt dock bug (see https://bugreports.qt.io/browse/QTBUG-65592) #if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0) - resizeDocks({panel_project}, {40}, Qt::Horizontal); + resizeDocks({panel_project}, {40}, Qt::Horizontal); #endif - } + } - layout()->update(); + layout()->update(); } MainWindow::MainWindow(QWidget *parent) : - QMainWindow(parent), - ui(new Ui::MainWindow) + QMainWindow(parent) { setup_debug(); @@ -98,14 +99,14 @@ MainWindow::MainWindow(QWidget *parent) : // set up style? qApp->setStyle(QStyleFactory::create("Fusion")); - setStyleSheet("QPushButton::checked { background: rgb(25, 25, 25); }"); + setStyleSheet("QPushButton::checked { background: rgb(25, 25, 25); }"); QPalette darkPalette; - darkPalette.setColor(QPalette::Window, QColor(53,53,53)); + darkPalette.setColor(QPalette::Window, QColor(53,53,53)); darkPalette.setColor(QPalette::WindowText, Qt::white); darkPalette.setColor(QPalette::Base, QColor(25,25,25)); darkPalette.setColor(QPalette::AlternateBase, QColor(53,53,53)); - darkPalette.setColor(QPalette::ToolTipBase, QColor(25,25,25)); + darkPalette.setColor(QPalette::ToolTipBase, QColor(25,25,25)); darkPalette.setColor(QPalette::ToolTipText, Qt::white); darkPalette.setColor(QPalette::Text, Qt::white); darkPalette.setColor(QPalette::Button, QColor(53,53,53)); @@ -113,38 +114,34 @@ MainWindow::MainWindow(QWidget *parent) : darkPalette.setColor(QPalette::Disabled, QPalette::ButtonText, QColor(128, 128, 128)); darkPalette.setColor(QPalette::Link, QColor(42, 130, 218)); darkPalette.setColor(QPalette::Highlight, QColor(42, 130, 218)); - darkPalette.setColor(QPalette::HighlightedText, Qt::black); + darkPalette.setColor(QPalette::HighlightedText, Qt::black); qApp->setPalette(darkPalette); // end style - ui->setupUi(this); + QWidget* centralWidget = new QWidget(this); + centralWidget->setMaximumSize(QSize(0, 0)); + setCentralWidget(centralWidget); - setTabPosition(Qt::AllDockWidgetAreas, QTabWidget::North); + setTabPosition(Qt::AllDockWidgetAreas, QTabWidget::North); updateTitle(""); statusBar()->showMessage("Welcome to " + appName); - setDockNestingEnabled(true); + setDockNestingEnabled(true); layout()->invalidate(); - connect(ui->menuWindow, SIGNAL(aboutToShow()), this, SLOT(windowMenu_About_To_Be_Shown())); - connect(ui->menu_View, SIGNAL(aboutToShow()), this, SLOT(viewMenu_About_To_Be_Shown())); - connect(ui->menu_Tools, SIGNAL(aboutToShow()), this, SLOT(toolMenu_About_To_Be_Shown())); - connect(ui->menuEdit, SIGNAL(aboutToShow()), this, SLOT(editMenu_About_To_Be_Shown())); - connect(ui->menu_File, SIGNAL(aboutToShow()), this, SLOT(fileMenu_About_To_Be_Shown())); - - QString data_dir = get_data_path(); - if (!data_dir.isEmpty()) { - QDir dir(data_dir); - dir.mkpath("."); - if (dir.exists()) { + QString data_dir = get_data_path(); + if (!data_dir.isEmpty()) { + QDir dir(data_dir); + dir.mkpath("."); + if (dir.exists()) { qint64 a_month_ago = QDateTime::currentMSecsSinceEpoch() - 2592000000; qint64 a_week_ago = QDateTime::currentMSecsSinceEpoch() - 604800000; - // TODO put delete functions in another thread? + // TODO put delete functions in another thread? // delete auto-recoveries older than 7 days QStringList old_autorecoveries = dir.entryList(QStringList("autorecovery.ove.*"), QDir::Files); @@ -171,61 +168,60 @@ MainWindow::MainWindow(QWidget *parent) : } } if (deleted_ars > 0) dout << "[INFO] Deleted" << deleted_ars << "preview" << ((deleted_ars == 1) ? "file that was" : "files that were") << "last read over 30 days ago"; - } + } - // search for open recents list - recent_proj_file = data_dir + "/recents"; - QFile f(recent_proj_file); - if (f.exists() && f.open(QFile::ReadOnly | QFile::Text)) { - QTextStream text_stream(&f); - while (true) { - QString line = text_stream.readLine(); - if (line.isNull()) { - break; - } else { - recent_projects.append(line); - } - } - f.close(); - } + // search for open recents list + recent_proj_file = data_dir + "/recents"; + QFile f(recent_proj_file); + if (f.exists() && f.open(QFile::ReadOnly | QFile::Text)) { + QTextStream text_stream(&f); + while (true) { + QString line = text_stream.readLine(); + if (line.isNull()) { + break; + } else { + recent_projects.append(line); + } + } + f.close(); + } - config_dir = data_dir + "/config.xml"; - config.load(config_dir); - } - } + config_dir = data_dir + "/config.xml"; + config.load(config_dir); + } + } - // TODO maybe replace these with non-pointers later on? - panel_sequence_viewer = new Viewer(this); - panel_footage_viewer = new Viewer(this); - panel_project = new Project(this); - panel_effect_controls = new EffectControls(this); - panel_timeline = new Timeline(this); + // TODO maybe replace these with non-pointers later on? + panel_sequence_viewer = new Viewer(this); + panel_footage_viewer = new Viewer(this); + panel_project = new Project(this); + panel_effect_controls = new EffectControls(this); + panel_timeline = new Timeline(this); - if (!data_dir.isEmpty()) { - // detect auto-recovery file - autorecovery_filename = data_dir + "/autorecovery.ove"; - if (QFile::exists(autorecovery_filename)) { - if (QMessageBox::question(NULL, "Auto-recovery", "Olive didn't close properly and an autorecovery file was detected. Would you like to open it?", QMessageBox::Yes, QMessageBox::No) == QMessageBox::Yes) { - updateTitle(autorecovery_filename); - panel_project->load_project(true); - } - } - autorecovery_timer.setInterval(60000); - QObject::connect(&autorecovery_timer, SIGNAL(timeout()), this, SLOT(autorecover_interval())); - autorecovery_timer.start(); - } + QStatusBar* statusBar = new QStatusBar(this); + setStatusBar(statusBar); - setup_layout(false); + setup_menus(); + + if (!data_dir.isEmpty()) { + // detect auto-recovery file + autorecovery_filename = data_dir + "/autorecovery.ove"; + if (QFile::exists(autorecovery_filename)) { + if (QMessageBox::question(NULL, "Auto-recovery", "Olive didn't close properly and an autorecovery file was detected. Would you like to open it?", QMessageBox::Yes, QMessageBox::No) == QMessageBox::Yes) { + updateTitle(autorecovery_filename); + panel_project->load_project(true); + } + } + autorecovery_timer.setInterval(60000); + QObject::connect(&autorecovery_timer, SIGNAL(timeout()), this, SLOT(autorecover_interval())); + autorecovery_timer.start(); + } + + setup_layout(false); + + init_audio(); - init_audio(); - connect(ui->action_Undo, SIGNAL(triggered(bool)), this, SLOT(undo())); - connect(ui->action_Redo, SIGNAL(triggered(bool)), this, SLOT(redo())); - connect(ui->actionCu_t, SIGNAL(triggered(bool)), this, SLOT(cut())); - connect(ui->actionCop_y, SIGNAL(triggered(bool)), this, SLOT(copy())); - connect(ui->action_Paste, SIGNAL(triggered(bool)), this, SLOT(paste())); - connect(ui->actionProject, SIGNAL(triggered(bool)), this, SLOT(new_project())); - connect(ui->actionFull_Screen, SIGNAL(triggered(bool)), this, SLOT(toggle_full_screen())); } MainWindow::~MainWindow() { @@ -235,148 +231,116 @@ MainWindow::~MainWindow() { set_sequence(NULL); - QString data_dir = get_data_path(); - if (!data_dir.isEmpty() && !autorecovery_filename.isEmpty()) { - if (QFile::exists(autorecovery_filename)) { - QFile::rename(autorecovery_filename, autorecovery_filename + "." + QDateTime::currentDateTimeUtc().toString("yyyyMMddHHmmss")); - } - } - if (!config_dir.isEmpty()) { - // save settings - config.save(config_dir); + QString data_dir = get_data_path(); + if (!data_dir.isEmpty() && !autorecovery_filename.isEmpty()) { + if (QFile::exists(autorecovery_filename)) { + QFile::rename(autorecovery_filename, autorecovery_filename + "." + QDateTime::currentDateTimeUtc().toString("yyyyMMddHHmmss")); + } + } + if (!config_dir.isEmpty()) { + // save settings + config.save(config_dir); - // save panel layout - QFile panel_config(data_dir + "/layout"); - if (panel_config.open(QFile::WriteOnly)) { - panel_config.write(saveState(0)); - panel_config.close(); - } else { - dout << "[ERROR] Failed to save layout"; - } - } + // save panel layout + QFile panel_config(data_dir + "/layout"); + if (panel_config.open(QFile::WriteOnly)) { + panel_config.write(saveState(0)); + panel_config.close(); + } else { + dout << "[ERROR] Failed to save layout"; + } + } stop_audio(); - delete ui; - - delete panel_sequence_viewer; - panel_sequence_viewer = NULL; - delete panel_footage_viewer; - panel_footage_viewer = NULL; - delete panel_project; - panel_project = NULL; - delete panel_effect_controls; - panel_effect_controls = NULL; + delete panel_sequence_viewer; + panel_sequence_viewer = NULL; + delete panel_footage_viewer; + panel_footage_viewer = NULL; + delete panel_project; + panel_project = NULL; + delete panel_effect_controls; + panel_effect_controls = NULL; delete panel_timeline; - panel_timeline = NULL; + panel_timeline = NULL; close_debug(); } -void MainWindow::on_action_Import_triggered() -{ - panel_project->import_dialog(); -} - -void MainWindow::on_actionExit_triggered() -{ - close(); -} - -void MainWindow::on_actionAbout_triggered() -{ +void MainWindow::show_about() { AboutDialog a(this); a.exec(); } -void MainWindow::on_actionDelete_triggered() +void MainWindow::delete_slot() { if (panel_timeline->ui->headers->hasFocus()) { panel_timeline->ui->headers->delete_markers(); } else if (panel_timeline->focused()) { panel_timeline->delete_selection(sequence->selections, false); - } else if (panel_effect_controls->is_focused()) { - panel_effect_controls->delete_effects(); - } else if (panel_project->is_focused()) { - panel_project->delete_selected_media(); + } else if (panel_effect_controls->is_focused()) { + panel_effect_controls->delete_effects(); + } else if (panel_project->is_focused()) { + panel_project->delete_selected_media(); } else if (panel_effect_controls->keyframe_focus()) { panel_effect_controls->delete_selected_keyframes(); } } -void MainWindow::on_actionSelect_All_triggered() -{ +void MainWindow::select_all() { if (panel_timeline->focused()) { panel_timeline->select_all(); } } -void MainWindow::on_actionSequence_triggered() -{ - NewSequenceDialog nsd(this); +void MainWindow::new_sequence() { + NewSequenceDialog nsd(this); nsd.set_sequence_name(panel_project->get_next_sequence_name()); nsd.exec(); } -void MainWindow::on_actionZoom_In_triggered() { - QDockWidget* focused_panel = get_focused_panel(); - if (focused_panel == panel_timeline) { - panel_timeline->set_zoom(true); - } else if (focused_panel == panel_effect_controls) { +void MainWindow::zoom_in() { + QDockWidget* focused_panel = get_focused_panel(); + if (focused_panel == panel_timeline) { + panel_timeline->set_zoom(true); + } else if (focused_panel == panel_effect_controls) { panel_effect_controls->set_zoom(true); - } else if (focused_panel == panel_footage_viewer) { - panel_footage_viewer->set_zoom(true); - } else if (focused_panel == panel_sequence_viewer) { - panel_sequence_viewer->set_zoom(true); - } + } else if (focused_panel == panel_footage_viewer) { + panel_footage_viewer->set_zoom(true); + } else if (focused_panel == panel_sequence_viewer) { + panel_sequence_viewer->set_zoom(true); + } } -void MainWindow::on_actionZoom_out_triggered() { - QDockWidget* focused_panel = get_focused_panel(); - if (focused_panel == panel_timeline) { - panel_timeline->set_zoom(false); - } else if (focused_panel == panel_effect_controls) { +void MainWindow::zoom_out() { + QDockWidget* focused_panel = get_focused_panel(); + if (focused_panel == panel_timeline) { + panel_timeline->set_zoom(false); + } else if (focused_panel == panel_effect_controls) { panel_effect_controls->set_zoom(false); - } else if (focused_panel == panel_footage_viewer) { - panel_footage_viewer->set_zoom(false); - } else if (focused_panel == panel_sequence_viewer) { - panel_sequence_viewer->set_zoom(false); - } + } else if (focused_panel == panel_footage_viewer) { + panel_footage_viewer->set_zoom(false); + } else if (focused_panel == panel_sequence_viewer) { + panel_sequence_viewer->set_zoom(false); + } } -void MainWindow::on_actionExport_triggered() { - if (sequence == NULL) { - QMessageBox::information(this, "No active sequence", "Please open the sequence you wish to export.", QMessageBox::Ok); - } else { - ExportDialog e(this); - e.exec(); - } +void MainWindow::export_dialog() { + if (sequence == NULL) { + QMessageBox::information(this, "No active sequence", "Please open the sequence you wish to export.", QMessageBox::Ok); + } else { + ExportDialog e(this); + e.exec(); + } } -void MainWindow::on_actionProject_2_triggered() { - panel_project->setVisible(!panel_project->isVisible()); -} - -void MainWindow::on_actionEffect_Controls_triggered() { - panel_effect_controls->setVisible(!panel_effect_controls->isVisible()); -} - -void MainWindow::on_actionViewer_triggered() { - panel_sequence_viewer->setVisible(!panel_sequence_viewer->isVisible()); -} - -void MainWindow::on_actionTimeline_triggered() { - panel_timeline->setVisible(!panel_timeline->isVisible()); -} - -void MainWindow::on_actionRipple_Delete_triggered() -{ +void MainWindow::ripple_delete() { panel_timeline->delete_selection(sequence->selections, true); } void MainWindow::editMenu_About_To_Be_Shown() { - ui->action_Undo->setEnabled(undo_stack.canUndo()); - ui->action_Redo->setEnabled(undo_stack.canRedo()); + undo_action->setEnabled(undo_stack.canUndo()); + redo_action->setEnabled(undo_stack.canRedo()); } void MainWindow::undo() { @@ -396,7 +360,7 @@ void MainWindow::openSpeedDialog() { SpeedDialog s(this); for (int i=0;iclips.size();i++) { Clip* c = sequence->clips.at(i); - if (c != NULL && panel_timeline->is_clip_selected(c, true)) { + if (c != NULL && panel_timeline->is_clip_selected(c, true)) { s.clips.append(c); } } @@ -405,111 +369,425 @@ void MainWindow::openSpeedDialog() { } void MainWindow::cut() { - if (sequence != NULL) { - QDockWidget* focused_panel = get_focused_panel(); - if (panel_timeline == focused_panel) { - panel_timeline->copy(true); - } else if (panel_effect_controls == focused_panel) { - panel_effect_controls->copy(true); - } - } + if (sequence != NULL) { + QDockWidget* focused_panel = get_focused_panel(); + if (panel_timeline == focused_panel) { + panel_timeline->copy(true); + } else if (panel_effect_controls == focused_panel) { + panel_effect_controls->copy(true); + } + } } void MainWindow::copy() { - if (sequence != NULL) { - QDockWidget* focused_panel = get_focused_panel(); - if (panel_timeline == focused_panel) { - panel_timeline->copy(false); - } else if (panel_effect_controls == focused_panel) { - panel_effect_controls->copy(false); - } - } + if (sequence != NULL) { + QDockWidget* focused_panel = get_focused_panel(); + if (panel_timeline == focused_panel) { + panel_timeline->copy(false); + } else if (panel_effect_controls == focused_panel) { + panel_effect_controls->copy(false); + } + } } void MainWindow::paste() { - QDockWidget* focused_panel = get_focused_panel(); - if ((panel_timeline == focused_panel || panel_effect_controls == focused_panel) && sequence != NULL) { - panel_timeline->paste(false); - } + QDockWidget* focused_panel = get_focused_panel(); + if ((panel_timeline == focused_panel || panel_effect_controls == focused_panel) && sequence != NULL) { + panel_timeline->paste(false); + } } void MainWindow::new_project() { - if (can_close_project()) { - panel_effect_controls->clear_effects(true); - undo_stack.clear(); - project_url.clear(); - panel_project->new_project(); - updateTitle(""); - update_ui(false); - panel_project->tree_view->update(); - } -} - -void MainWindow::on_actionSplit_at_Playhead_triggered() { - if (panel_timeline->focused()) { - panel_timeline->split_at_playhead(); - } + if (can_close_project()) { + panel_effect_controls->clear_effects(true); + undo_stack.clear(); + project_url.clear(); + panel_project->new_project(); + updateTitle(""); + update_ui(false); + panel_project->tree_view->update(); + } } void MainWindow::autorecover_interval() { - if (!rendering && isWindowModified()) { - panel_project->save_project(true); + if (!rendering && isWindowModified()) { + panel_project->save_project(true); dout << "[INFO] Auto-recovery project saved"; - } + } } bool MainWindow::save_project_as() { - QString fn = QFileDialog::getSaveFileName(this, "Save Project As...", "", OLIVE_FILE_FILTER); - if (!fn.isEmpty()) { - if (!fn.endsWith(".ove", Qt::CaseInsensitive)) { - fn += ".ove"; - } + QString fn = QFileDialog::getSaveFileName(this, "Save Project As...", "", OLIVE_FILE_FILTER); + if (!fn.isEmpty()) { + if (!fn.endsWith(".ove", Qt::CaseInsensitive)) { + fn += ".ove"; + } updateTitle(fn); - panel_project->save_project(false); - return true; - } - return false; + panel_project->save_project(false); + return true; + } + return false; } bool MainWindow::save_project() { - if (project_url.isEmpty()) { - return save_project_as(); - } else { - panel_project->save_project(false); - return true; - } + if (project_url.isEmpty()) { + return save_project_as(); + } else { + panel_project->save_project(false); + return true; + } } bool MainWindow::can_close_project() { if (isWindowModified()) { - QMessageBox* m = new QMessageBox( - QMessageBox::Question, - "Unsaved Project", - "This project has changed since it was last saved. Would you like to save it before closing?", - QMessageBox::Yes|QMessageBox::No|QMessageBox::Cancel, - this - ); - m->setWindowModality(Qt::WindowModal); - int r = m->exec(); - if (r == QMessageBox::Yes) { - return save_project(); - } else if (r == QMessageBox::Cancel) { - return false; - } - } + QMessageBox* m = new QMessageBox( + QMessageBox::Question, + "Unsaved Project", + "This project has changed since it was last saved. Would you like to save it before closing?", + QMessageBox::Yes|QMessageBox::No|QMessageBox::Cancel, + this + ); + m->setWindowModality(Qt::WindowModal); + int r = m->exec(); + if (r == QMessageBox::Yes) { + return save_project(); + } else if (r == QMessageBox::Cancel) { + return false; + } + } return true; } +void MainWindow::setup_menus() { + QMenuBar* menuBar = new QMenuBar(this); + setMenuBar(menuBar); + + // INITIALIZE FILE MENU + + QMenu* file_menu = menuBar->addMenu("&File"); + connect(file_menu, SIGNAL(aboutToShow()), this, SLOT(fileMenu_About_To_Be_Shown())); + + QMenu* new_menu = file_menu->addMenu("&New"); + new_menu->addAction("&Project", this, SLOT(new_project()), QKeySequence("Ctrl+N")); + new_menu->addSeparator(); + new_menu->addAction("&Sequence", this, SLOT(new_sequence()), QKeySequence("Ctrl+Shift+N")); + new_menu->addAction("&Folder", this, SLOT(new_folder())); + + file_menu->addAction("&Open Project", this, SLOT(open_project()), QKeySequence("Ctrl+O")); + + open_recent = file_menu->addMenu("Open Recent"); + + file_menu->addAction("&Save Project", this, SLOT(save_project()), QKeySequence("Ctrl+S")); + file_menu->addAction("Save Project &As", this, SLOT(save_project_as()), QKeySequence("Ctrl+Shift+S")); + + file_menu->addSeparator(); + + file_menu->addAction("&Import...", panel_project, SLOT(import_dialog()), QKeySequence("Ctrl+I")); + + file_menu->addSeparator(); + + file_menu->addAction("&Export...", this, SLOT(export_dialog()), QKeySequence("Ctrl+M")); + + file_menu->addSeparator(); + + file_menu->addAction("E&xit", this, SLOT(close())); + + // INITIALIZE EDIT MENU + + QMenu* edit_menu = menuBar->addMenu("&Edit"); + connect(edit_menu, SIGNAL(aboutToShow()), this, SLOT(editMenu_About_To_Be_Shown())); + + undo_action = edit_menu->addAction("&Undo", this, SLOT(undo()), QKeySequence("Ctrl+Z")); + redo_action = edit_menu->addAction("Redo", this, SLOT(redo()), QKeySequence("Ctrl+Shift+Z")); + + edit_menu->addSeparator(); + + edit_menu->addAction("Cu&t", this, SLOT(cut()), QKeySequence("Ctrl+X")); + edit_menu->addAction("Cop&y", this, SLOT(copy()), QKeySequence("Ctrl+C")); + edit_menu->addAction("&Paste", this, SLOT(paste()), QKeySequence("Ctrl+V")); + edit_menu->addAction("Paste Insert", this, SLOT(paste_insert()), QKeySequence("Ctrl+Shift+V")); + edit_menu->addAction("Duplicate", this, SLOT(duplicate()), QKeySequence("Ctrl+D")); + edit_menu->addAction("Delete", this, SLOT(delete_slot()), QKeySequence("Del")); + edit_menu->addAction("Ripple Delete", this, SLOT(ripple_delete()), QKeySequence("Shift+Del")); + edit_menu->addAction("Split", panel_timeline, SLOT(split_at_playhead()), QKeySequence("Ctrl+K")); + + edit_menu->addSeparator(); + + edit_menu->addAction("Select &All", this, SLOT(select_all()), QKeySequence("Ctrl+A")); + + edit_menu->addAction("Deselect All", panel_timeline, SLOT(deselect()), QKeySequence("Ctrl+Shift+A")); + + edit_menu->addSeparator(); + + edit_menu->addAction("Add Default Transition", this, SLOT(add_default_transition()), QKeySequence("Ctrl+Shift+D")); + edit_menu->addAction("Link/Unlink", panel_timeline, SLOT(toggle_links()), QKeySequence("Ctrl+L")); + edit_menu->addAction("Enable/Disable", this, SLOT(toggle_enable_clips()), QKeySequence("Shift+E")); + edit_menu->addAction("Nest", this, SLOT(nest())); + + edit_menu->addSeparator(); + + edit_menu->addAction("Ripple to In Point", this, SLOT(ripple_to_in_point()), QKeySequence("Q")); + edit_menu->addAction("Ripple to Out Point", this, SLOT(ripple_to_out_point()), QKeySequence("W")); + edit_menu->addAction("Edit to In Point", this, SLOT(edit_to_in_point()), QKeySequence("Ctrl+Alt+Q")); + edit_menu->addAction("Edit to Out Point", this, SLOT(edit_to_out_point()), QKeySequence("Ctrl+Alt+W")); + + edit_menu->addSeparator(); + + edit_menu->addAction("Set In Point", this, SLOT(set_in_point()), QKeySequence("I")); + edit_menu->addAction("Set Out Point", this, SLOT(set_out_point()), QKeySequence("O")); + edit_menu->addAction("Clear In/Out Point", this, SLOT(clear_inout()), QKeySequence("G")); + edit_menu->addAction("Delete In/Out Point", this, SLOT(delete_inout()), QKeySequence(";")); + edit_menu->addAction("Ripple Delete In/Out Point", this, SLOT(ripple_delete_inout()), QKeySequence("'")); + + edit_menu->addSeparator(); + + edit_menu->addAction("Set/Edit Marker", this, SLOT(set_marker()), QKeySequence("M")); + + // INITIALIZE VIEW MENU + + QMenu* view_menu = menuBar->addMenu("&View"); + connect(view_menu, SIGNAL(aboutToShow()), this, SLOT(viewMenu_About_To_Be_Shown())); + + view_menu->addAction("Zoom In", this, SLOT(zoom_in()), QKeySequence("=")); + view_menu->addAction("Zoom Out", this, SLOT(zoom_out()), QKeySequence("-")); + view_menu->addAction("Increase Track Height", this, SLOT(zoom_in_tracks()), QKeySequence("Ctrl+=")); + view_menu->addAction("Decrease Track Height", this, SLOT(zoom_out_tracks()), QKeySequence("Ctrl+-")); + + show_all = view_menu->addAction("Toggle Show All", panel_timeline, SLOT(toggle_show_all()), QKeySequence("\\")); + show_all->setCheckable(true); + + view_menu->addSeparator(); + + track_lines = view_menu->addAction("Track Lines", this, SLOT(toggle_bool_action())); + track_lines->setCheckable(true); + track_lines->setData(reinterpret_cast(&config.show_track_lines)); + + view_menu->addSeparator(); + + frames_action = view_menu->addAction("Frames", this, SLOT(set_timecode_view())); + frames_action->setData(TIMECODE_FRAMES); + frames_action->setCheckable(true); + drop_frame_action = view_menu->addAction("Drop Frame", this, SLOT(set_timecode_view())); + drop_frame_action->setData(TIMECODE_DROP); + drop_frame_action->setCheckable(true); + nondrop_frame_action = view_menu->addAction("Non-Drop Frame", this, SLOT(set_timecode_view())); + nondrop_frame_action->setData(TIMECODE_NONDROP); + nondrop_frame_action->setCheckable(true); + milliseconds_action = view_menu->addAction("Milliseconds", this, SLOT(set_timecode_view())); + milliseconds_action->setData(TIMECODE_MILLISECONDS); + milliseconds_action->setCheckable(true); + + view_menu->addSeparator(); + + QMenu* title_safe_area_menu = view_menu->addMenu("Title/Action Safe Area"); + + title_safe_off = title_safe_area_menu->addAction("Off"); + title_safe_off->setCheckable(true); + + title_safe_default = title_safe_area_menu->addAction("Default"); + title_safe_default->setCheckable(true); + + title_safe_43 = title_safe_area_menu->addAction("4:3"); + title_safe_43->setCheckable(true); + + title_safe_169 = title_safe_area_menu->addAction("16:9"); + title_safe_169->setCheckable(true); + + title_safe_custom = title_safe_area_menu->addAction("Custom"); + title_safe_custom->setCheckable(true); + + view_menu->addSeparator(); + + full_screen = view_menu->addAction("Full Screen", this, SLOT(toggle_full_screen()), QKeySequence("F11")); + full_screen->setCheckable(true); + + // INITIALIZE PLAYBACK MENU + + QMenu* playback_menu = menuBar->addMenu("&Playback"); + + playback_menu->addAction("Go to Start", this, SLOT(go_to_start()), QKeySequence("Home")); + playback_menu->addAction("Previous Frame", this, SLOT(prev_frame()), QKeySequence("Left")); + playback_menu->addAction("Play/Pause", this, SLOT(playpause()), QKeySequence("Space")); + playback_menu->addAction("Next Frame", this, SLOT(next_frame()), QKeySequence("Right")); + playback_menu->addAction("Go to End", this, SLOT(go_to_end()), QKeySequence("End")); + playback_menu->addSeparator(); + playback_menu->addAction("Go to Previous Cut", this, SLOT(prev_cut()), QKeySequence("Up")); + playback_menu->addAction("Go to Next Cut", this, SLOT(next_cut()), QKeySequence("Down")); + + // INITIALIZE WINDOW MENU + + window_menu = menuBar->addMenu("&Window"); + connect(window_menu, SIGNAL(aboutToShow()), this, SLOT(windowMenu_About_To_Be_Shown())); + + QAction* window_project_action = window_menu->addAction("Project", this, SLOT(toggle_panel_visibility())); + window_project_action->setCheckable(true); + window_project_action->setData(reinterpret_cast(panel_project)); + + QAction* window_effectcontrols_action = window_menu->addAction("Effect Controls", this, SLOT(toggle_panel_visibility())); + window_effectcontrols_action->setCheckable(true); + window_effectcontrols_action->setData(reinterpret_cast(panel_effect_controls)); + + QAction* window_timeline_action = window_menu->addAction("Timeline", this, SLOT(toggle_panel_visibility())); + window_timeline_action->setCheckable(true); + window_timeline_action->setData(reinterpret_cast(panel_timeline)); + + QAction* window_footageviewer_action = window_menu->addAction("Footage Viewer", this, SLOT(toggle_panel_visibility())); + window_footageviewer_action->setCheckable(true); + window_footageviewer_action->setData(reinterpret_cast(panel_footage_viewer)); + + QAction* window_sequenceviewer_action = window_menu->addAction("Sequence Viewer", this, SLOT(toggle_panel_visibility())); + window_sequenceviewer_action->setCheckable(true); + window_sequenceviewer_action->setData(reinterpret_cast(panel_sequence_viewer)); + + window_menu->addSeparator(); + + window_menu->addAction("Reset to Default Layout", this, SLOT(reset_layout())); + + // INITIALIZE TOOLS MENU + + QMenu* tools_menu = menuBar->addMenu("&Tools"); + connect(tools_menu, SIGNAL(aboutToShow()), this, SLOT(toolMenu_About_To_Be_Shown())); + + pointer_tool_action = tools_menu->addAction("Pointer Tool", this, SLOT(menu_click_button()), QKeySequence("V")); + pointer_tool_action->setCheckable(true); + pointer_tool_action->setData(reinterpret_cast(panel_timeline->ui->toolArrowButton)); + + edit_tool_action = tools_menu->addAction("Edit Tool", this, SLOT(menu_click_button()), QKeySequence("X")); + edit_tool_action->setCheckable(true); + edit_tool_action->setData(reinterpret_cast(panel_timeline->ui->toolEditButton)); + + ripple_tool_action = tools_menu->addAction("Ripple Tool", this, SLOT(menu_click_button()), QKeySequence("B")); + ripple_tool_action->setCheckable(true); + ripple_tool_action->setData(reinterpret_cast(panel_timeline->ui->toolRippleButton)); + + razor_tool_action = tools_menu->addAction("Razor Tool", this, SLOT(menu_click_button()), QKeySequence("C")); + razor_tool_action->setCheckable(true); + razor_tool_action->setData(reinterpret_cast(panel_timeline->ui->toolRazorButton)); + + slip_tool_action = tools_menu->addAction("Slip Tool", this, SLOT(menu_click_button()), QKeySequence("Y")); + slip_tool_action->setCheckable(true); + slip_tool_action->setData(reinterpret_cast(panel_timeline->ui->toolSlipButton)); + + slide_tool_action = tools_menu->addAction("Slide Tool", this, SLOT(menu_click_button()), QKeySequence("U")); + slide_tool_action->setCheckable(true); + slide_tool_action->setData(reinterpret_cast(panel_timeline->ui->toolSlideButton)); + + hand_tool_action = tools_menu->addAction("Hand Tool", this, SLOT(menu_click_button()), QKeySequence("H")); + hand_tool_action->setCheckable(true); + hand_tool_action->setData(reinterpret_cast(panel_timeline->ui->toolHandButton)); + + transition_tool_action = tools_menu->addAction("Transition Tool", this, SLOT(menu_click_button()), QKeySequence("T")); + transition_tool_action->setCheckable(true); + transition_tool_action->setData(reinterpret_cast(panel_timeline->ui->toolTransitionButton)); + + tools_menu->addSeparator(); + + snap_toggle = tools_menu->addAction("Enable Snapping", this, SLOT(menu_click_button()), QKeySequence("S")); + snap_toggle->setCheckable(true); + snap_toggle->setData(reinterpret_cast(panel_timeline->ui->snappingButton)); + + tools_menu->addSeparator(); + + selecting_also_seeks = tools_menu->addAction("Selecting Also Seeks", this, SLOT(toggle_bool_action())); + selecting_also_seeks->setCheckable(true); + selecting_also_seeks->setData(reinterpret_cast(&config.select_also_seeks)); + + edit_tool_also_seeks = tools_menu->addAction("Edit Tool Also Seeks", this, SLOT(toggle_bool_action())); + edit_tool_also_seeks->setCheckable(true); + edit_tool_also_seeks->setData(reinterpret_cast(&config.edit_tool_also_seeks)); + + edit_tool_selects_links = tools_menu->addAction("Edit Tool Selects Links", this, SLOT(toggle_bool_action())); + edit_tool_selects_links->setCheckable(true); + edit_tool_selects_links->setData(reinterpret_cast(&config.edit_tool_selects_links)); + + seek_to_end_of_pastes = tools_menu->addAction("Seek to the End of Pastes", this, SLOT(toggle_bool_action())); + seek_to_end_of_pastes->setCheckable(true); + seek_to_end_of_pastes->setData(reinterpret_cast(&config.paste_seeks)); + + scroll_wheel_zooms = tools_menu->addAction("Scroll Wheel Zooms", this, SLOT(toggle_bool_action())); + scroll_wheel_zooms->setCheckable(true); + scroll_wheel_zooms->setData(reinterpret_cast(&config.scroll_zooms)); + + rectified_waveforms = tools_menu->addAction("Rectified Waveforms", this, SLOT(toggle_bool_action())); + rectified_waveforms->setCheckable(true); + rectified_waveforms->setData(reinterpret_cast(&config.rectified_waveforms)); + + enable_drag_files_to_timeline = tools_menu->addAction("Enable Drag Files to Timeline", this, SLOT(toggle_bool_action())); + enable_drag_files_to_timeline->setCheckable(true); + enable_drag_files_to_timeline->setData(reinterpret_cast(&config.enable_drag_files_to_timeline)); + + autoscale_by_default = tools_menu->addAction("Auto-Scale By Default", this, SLOT(toggle_bool_action())); + autoscale_by_default->setCheckable(true); + autoscale_by_default->setData(reinterpret_cast(&config.autoscale_by_default)); + + enable_seek_to_import = tools_menu->addAction("Enable Seek to Import", this, SLOT(toggle_bool_action())); + enable_seek_to_import->setCheckable(true); + enable_seek_to_import->setData(reinterpret_cast(&config.enable_seek_to_import)); + + enable_audio_scrubbing = tools_menu->addAction("Audio Scrubbing", this, SLOT(toggle_bool_action())); + enable_audio_scrubbing->setCheckable(true); + enable_audio_scrubbing->setData(reinterpret_cast(&config.enable_audio_scrubbing)); + + enable_drop_on_media_to_replace = tools_menu->addAction("Enable Drop on Media to Replace", this, SLOT(toggle_bool_action())); + enable_drop_on_media_to_replace->setCheckable(true); + enable_drop_on_media_to_replace->setData(reinterpret_cast(&config.drop_on_media_to_replace)); + + enable_hover_focus = tools_menu->addAction("Enable Hover Focus", this, SLOT(toggle_bool_action())); + enable_hover_focus->setCheckable(true); + enable_hover_focus->setData(reinterpret_cast(&config.hover_focus)); + + tools_menu->addSeparator(); + + no_autoscroll = tools_menu->addAction("No Auto-Scroll", this, SLOT(set_autoscroll())); + no_autoscroll->setData(AUTOSCROLL_NO_SCROLL); + no_autoscroll->setCheckable(true); + + page_autoscroll = tools_menu->addAction("Page Auto-Scroll", this, SLOT(set_autoscroll())); + page_autoscroll->setData(AUTOSCROLL_PAGE_SCROLL); + page_autoscroll->setCheckable(true); + + smooth_autoscroll = tools_menu->addAction("Smooth Auto-Scroll", this, SLOT(set_autoscroll())); + smooth_autoscroll->setData(AUTOSCROLL_SMOOTH_SCROLL); + smooth_autoscroll->setCheckable(true); + + tools_menu->addSeparator(); + + tools_menu->addAction("Preferences", this, SLOT(preferences()), QKeySequence("Ctrl+.")); + + // INITIALIZE HELP MENU + + QMenu* help_menu = menuBar->addMenu("&Help"); + + help_menu->addAction("&About...", this, SLOT(show_about())); +} + +void MainWindow::set_bool_action_checked(QAction *a) { + if (!a->data().isNull()) { + bool* variable = reinterpret_cast(a->data().value()); + a->setChecked(*variable); + } +} + +void MainWindow::set_int_action_checked(QAction *a, const int& i) { + if (!a->data().isNull()) { + a->setChecked(a->data() == i); + } +} + +void MainWindow::set_button_action_checked(QAction *a) { + a->setChecked(reinterpret_cast(a->data().value())->isChecked()); +} + void MainWindow::updateTitle(const QString& url) { project_url = url; setWindowTitle(appName + " - " + ((project_url.isEmpty()) ? "" : project_url) + "[*]"); } void MainWindow::closeEvent(QCloseEvent *e) { - if (can_close_project()) { - e->accept(); - } else { - e->ignore(); + if (can_close_project()) { + e->accept(); + } else { + e->ignore(); } } @@ -524,40 +802,20 @@ void MainWindow::paintEvent(QPaintEvent *event) { #endif } -void MainWindow::on_action_Save_Project_triggered() -{ - save_project(); -} - -void MainWindow::on_action_Open_Project_triggered() -{ - QString fn = QFileDialog::getOpenFileName(this, "Open Project...", "", OLIVE_FILE_FILTER); +void MainWindow::open_project() { + QString fn = QFileDialog::getOpenFileName(this, "Open Project...", "", OLIVE_FILE_FILTER); if (!fn.isEmpty() && can_close_project()) { updateTitle(fn); - panel_project->load_project(false); - undo_stack.clear(); - } + panel_project->load_project(false); + undo_stack.clear(); + } } -void MainWindow::on_actionSave_Project_As_triggered() -{ - save_project_as(); +void MainWindow::reset_layout() { + setup_layout(true); } -void MainWindow::on_actionDeselect_All_triggered() -{ - if (panel_timeline->focused()) { - panel_timeline->deselect(); - } -} - -void MainWindow::on_actionReset_to_default_layout_triggered() -{ - setup_layout(true); -} - -void MainWindow::on_actionGo_to_start_triggered() -{ +void MainWindow::go_to_start() { if (panel_timeline->focused() || panel_sequence_viewer->is_focused() || panel_effect_controls->keyframe_focus()) { panel_sequence_viewer->go_to_start(); } else if (panel_footage_viewer->is_focused()) { @@ -565,7 +823,7 @@ void MainWindow::on_actionGo_to_start_triggered() } } -void MainWindow::on_actionPrevious_Frame_triggered() { +void MainWindow::prev_frame() { if (panel_timeline->focused() || panel_sequence_viewer->is_focused() || panel_effect_controls->keyframe_focus()) { panel_sequence_viewer->previous_frame(); } else if (panel_footage_viewer->is_focused()) { @@ -573,7 +831,7 @@ void MainWindow::on_actionPrevious_Frame_triggered() { } } -void MainWindow::on_actionNext_Frame_triggered() { +void MainWindow::next_frame() { if (panel_timeline->focused() || panel_sequence_viewer->is_focused() || panel_effect_controls->keyframe_focus()) { panel_sequence_viewer->next_frame(); } else if (panel_footage_viewer->is_focused()) { @@ -581,7 +839,7 @@ void MainWindow::on_actionNext_Frame_triggered() { } } -void MainWindow::on_actionGo_to_End_triggered() { +void MainWindow::go_to_end() { if (panel_timeline->focused() || panel_sequence_viewer->is_focused() || panel_effect_controls->keyframe_focus()) { panel_sequence_viewer->go_to_end(); } else if (panel_footage_viewer->is_focused()) { @@ -589,7 +847,7 @@ void MainWindow::on_actionGo_to_End_triggered() { } } -void MainWindow::on_actionPlay_Pause_triggered() { +void MainWindow::playpause() { if (panel_timeline->focused() || panel_sequence_viewer->is_focused() || panel_effect_controls->keyframe_focus()) { panel_sequence_viewer->toggle_play(); } else if (panel_footage_viewer->is_focused()) { @@ -597,224 +855,156 @@ void MainWindow::on_actionPlay_Pause_triggered() { } } -void MainWindow::on_actionEdit_Tool_triggered() -{ - if (panel_timeline->focused()) panel_timeline->ui->toolEditButton->click(); -} - -void MainWindow::on_actionToggle_Snapping_triggered() -{ - if (panel_timeline->focused() || panel_effect_controls->keyframe_focus()) panel_timeline->ui->snappingButton->click(); -} - -void MainWindow::on_actionPointer_Tool_triggered() -{ - if (panel_timeline->focused() - || panel_effect_controls->keyframe_focus() - || panel_footage_viewer->is_focused() - || panel_sequence_viewer->is_focused()) - panel_timeline->ui->toolArrowButton->click(); -} - -void MainWindow::on_actionRazor_Tool_triggered() -{ - if (panel_timeline->focused()) panel_timeline->ui->toolRazorButton->click(); -} - -void MainWindow::on_actionRipple_Tool_triggered() -{ - if (panel_timeline->focused()) panel_timeline->ui->toolRippleButton->click(); -} - -void MainWindow::on_actionRolling_Tool_triggered() -{ - if (panel_timeline->focused()) panel_timeline->ui->toolRollingButton->click(); -} - -void MainWindow::on_actionSlip_Tool_triggered() -{ - if (panel_timeline->focused()) panel_timeline->ui->toolSlipButton->click(); -} - -void MainWindow::on_actionGo_to_Previous_Cut_triggered() -{ +void MainWindow::prev_cut() { if (sequence != NULL && (panel_timeline->focused() || panel_sequence_viewer->is_focused())) { - panel_timeline->previous_cut(); - } + panel_timeline->previous_cut(); + } } -void MainWindow::on_actionGo_to_Next_Cut_triggered() -{ +void MainWindow::next_cut() { if (sequence != NULL && (panel_timeline->focused() || panel_sequence_viewer->is_focused())) { - panel_timeline->next_cut(); - } + panel_timeline->next_cut(); + } } -void MainWindow::on_actionPreferences_triggered() +void MainWindow::preferences() { - PreferencesDialog pd(this); - pd.setup_kbd_shortcuts(menuBar()); - pd.exec(); + PreferencesDialog pd(this); + pd.setup_kbd_shortcuts(menuBar()); + pd.exec(); } -void MainWindow::on_actionIncrease_Track_Height_triggered() -{ - panel_timeline->increase_track_height(); +void MainWindow::zoom_in_tracks() { + panel_timeline->increase_track_height(); } -void MainWindow::on_actionDecrease_Track_Height_triggered() -{ - panel_timeline->decrease_track_height(); +void MainWindow::zoom_out_tracks() { + panel_timeline->decrease_track_height(); } void MainWindow::windowMenu_About_To_Be_Shown() { - ui->actionProject_2->setChecked(panel_project->isVisible()); - ui->actionEffect_Controls->setChecked(panel_effect_controls->isVisible()); - ui->actionTimeline->setChecked(panel_timeline->isVisible()); - ui->actionViewer->setChecked(panel_sequence_viewer->isVisible()); - ui->actionFootage_Viewer->setChecked(panel_footage_viewer->isVisible()); + QList window_actions = window_menu->actions(); + for (int i=0;idata().isNull()) { + a->setChecked(reinterpret_cast(a->data().value())->isVisible()); + } + } } void MainWindow::viewMenu_About_To_Be_Shown() { - ui->actionTimeline_Track_Lines->setChecked(config.show_track_lines); - ui->actionFrames->setChecked(config.timecode_view == TIMECODE_FRAMES); - ui->actionDrop_Frame->setChecked(config.timecode_view == TIMECODE_DROP); - ui->actionNon_Drop_Frame->setChecked(config.timecode_view == TIMECODE_NONDROP); - ui->actionMilliseconds->setChecked(config.timecode_view == TIMECODE_MILLISECONDS); + set_bool_action_checked(track_lines); - ui->actionOff->setChecked(!config.show_title_safe_area); - ui->actionDefault->setChecked(config.show_title_safe_area && !config.use_custom_title_safe_ratio); - ui->action4_3->setChecked(config.show_title_safe_area && config.use_custom_title_safe_ratio && config.custom_title_safe_ratio == 4.0/3.0); - ui->action16_9->setChecked(config.show_title_safe_area && config.use_custom_title_safe_ratio && config.custom_title_safe_ratio == 16.0/9.0); - ui->actionCustom->setChecked(config.show_title_safe_area && config.use_custom_title_safe_ratio && !ui->action4_3->isChecked() && !ui->action16_9->isChecked()); + set_int_action_checked(frames_action, config.timecode_view); + set_int_action_checked(drop_frame_action, config.timecode_view); + set_int_action_checked(nondrop_frame_action, config.timecode_view); + set_int_action_checked(milliseconds_action, config.timecode_view); - ui->actionFull_Screen->setChecked(windowState() == Qt::WindowFullScreen); -} + title_safe_off->setChecked(!config.show_title_safe_area); + title_safe_default->setChecked(config.show_title_safe_area && !config.use_custom_title_safe_ratio); + title_safe_43->setChecked(config.show_title_safe_area && config.use_custom_title_safe_ratio && config.custom_title_safe_ratio == 4.0/3.0); + title_safe_169->setChecked(config.show_title_safe_area && config.use_custom_title_safe_ratio && config.custom_title_safe_ratio == 16.0/9.0); + title_safe_custom->setChecked(config.show_title_safe_area && config.use_custom_title_safe_ratio && !title_safe_43->isChecked() && !title_safe_169->isChecked()); -void MainWindow::on_actionFrames_triggered() -{ - config.timecode_view = TIMECODE_FRAMES; - update_ui(false); -} + full_screen->setChecked(windowState() == Qt::WindowFullScreen); -void MainWindow::on_actionDrop_Frame_triggered() -{ - config.timecode_view = TIMECODE_DROP; - update_ui(false); -} - -void MainWindow::on_actionNon_Drop_Frame_triggered() -{ - config.timecode_view = TIMECODE_NONDROP; - update_ui(false); + show_all->setChecked(panel_timeline->showing_all); } void MainWindow::toolMenu_About_To_Be_Shown() { - ui->actionEdit_Tool_Also_Seeks->setChecked(config.edit_tool_also_seeks); - ui->actionEdit_Tool_Selects_Links->setChecked(config.edit_tool_selects_links); - ui->actionSelecting_Also_Seeks->setChecked(config.select_also_seeks); - ui->actionSeek_to_the_End_of_Pastes->setChecked(config.paste_seeks); - ui->actionToggle_Snapping->setChecked(panel_timeline->snapping); - ui->actionScroll_Wheel_Zooms->setChecked(config.scroll_zooms); - ui->actionRectified_Waveforms->setChecked(config.rectified_waveforms); - ui->actionEnable_Drag_Files_to_Timeline->setChecked(config.enable_drag_files_to_timeline); - ui->actionAuto_scale_by_Default->setChecked(config.autoscale_by_default); - ui->actionEnable_Seek_to_Import->setChecked(config.enable_seek_to_import); - ui->actionAudio_Scrubbing->setChecked(config.enable_audio_scrubbing); - ui->actionEnable_Drop_on_Media_to_Replace->setChecked(config.drop_on_media_to_replace); - ui->actionEnable_Hover_Focus->setChecked(config.hover_focus); + set_button_action_checked(pointer_tool_action); + set_button_action_checked(edit_tool_action); + set_button_action_checked(ripple_tool_action); + set_button_action_checked(razor_tool_action); + set_button_action_checked(slip_tool_action); + set_button_action_checked(slide_tool_action); + set_button_action_checked(hand_tool_action); + set_button_action_checked(transition_tool_action); + set_button_action_checked(snap_toggle); - ui->actionNo_autoscroll->setChecked(config.autoscroll == AUTOSCROLL_NO_SCROLL); - ui->actionPage_Autoscroll->setChecked(config.autoscroll == AUTOSCROLL_PAGE_SCROLL); - ui->actionSmooth_Auto_scroll->setChecked(config.autoscroll == AUTOSCROLL_SMOOTH_SCROLL); + set_bool_action_checked(selecting_also_seeks); + set_bool_action_checked(edit_tool_also_seeks); + set_bool_action_checked(edit_tool_selects_links); + set_bool_action_checked(seek_to_end_of_pastes); + set_bool_action_checked(scroll_wheel_zooms); + set_bool_action_checked(rectified_waveforms); + set_bool_action_checked(enable_drag_files_to_timeline); + set_bool_action_checked(autoscale_by_default); + set_bool_action_checked(enable_seek_to_import); + set_bool_action_checked(enable_audio_scrubbing); + set_bool_action_checked(enable_drop_on_media_to_replace); + set_bool_action_checked(enable_hover_focus); + + set_int_action_checked(no_autoscroll, config.autoscroll); + set_int_action_checked(page_autoscroll, config.autoscroll); + set_int_action_checked(smooth_autoscroll, config.autoscroll); } -void MainWindow::on_actionEdit_Tool_Selects_Links_triggered() { - config.edit_tool_selects_links = !config.edit_tool_selects_links; +void MainWindow::duplicate() { + if (panel_project->is_focused()) { + panel_project->duplicate_selected(); + } } -void MainWindow::on_actionEdit_Tool_Also_Seeks_triggered() { - config.edit_tool_also_seeks = !config.edit_tool_also_seeks; +void MainWindow::add_default_transition() { + if (panel_timeline->focused()) panel_timeline->add_transition(); } -void MainWindow::on_actionDuplicate_triggered() { - if (panel_project->is_focused()) { - panel_project->duplicate_selected(); - } -} +void MainWindow::new_folder() { + Media* m = panel_project->new_folder(0); + undo_stack.push(new AddMediaCommand(m, panel_project->get_selected_folder())); -void MainWindow::on_actionSelecting_Also_Seeks_triggered() { - config.select_also_seeks = !config.select_also_seeks; -} - -void MainWindow::on_actionSeek_to_the_End_of_Pastes_triggered() -{ - config.paste_seeks = !config.paste_seeks; -} - -void MainWindow::on_actionAdd_Default_Transition_triggered() { - if (panel_timeline->focused()) panel_timeline->add_transition(); -} - -void MainWindow::on_actionSlide_Tool_triggered() -{ - if (panel_timeline->focused()) panel_timeline->ui->toolSlideButton->click(); -} - -void MainWindow::on_actionFolder_triggered() { - undo_stack.push(new AddMediaCommand(panel_project->new_folder(0), panel_project->get_selected_folder())); + QModelIndex index = project_model.create_index(m->row(), 0, m); + switch (config.project_view_type) { + case PROJECT_VIEW_TREE: + panel_project->tree_view->edit(panel_project->sorter->mapFromSource(index)); + break; + case PROJECT_VIEW_ICON: + panel_project->icon_view->edit(panel_project->sorter->mapFromSource(index)); + break; + } } void MainWindow::fileMenu_About_To_Be_Shown() { - if (recent_projects.size() > 0) { - ui->menuOpen_Recent->clear(); - ui->menuOpen_Recent->setEnabled(true); - for (int i=0;imenuOpen_Recent->addAction(recent_projects.at(i)); - action->setData(i); - connect(action, SIGNAL(triggered()), this, SLOT(load_recent_project())); - } - ui->menuOpen_Recent->addSeparator(); - QAction* clear_action = ui->menuOpen_Recent->addAction("Clear Recent List"); - connect(clear_action, SIGNAL(triggered()), panel_project, SLOT(clear_recent_projects())); - } else { - ui->menuOpen_Recent->setEnabled(false); - } + if (recent_projects.size() > 0) { + open_recent->clear(); + open_recent->setEnabled(true); + for (int i=0;iaddAction(recent_projects.at(i)); + action->setData(i); + connect(action, SIGNAL(triggered()), this, SLOT(load_recent_project())); + } + open_recent->addSeparator(); + QAction* clear_action = open_recent->addAction("Clear Recent List"); + connect(clear_action, SIGNAL(triggered()), panel_project, SLOT(clear_recent_projects())); + } else { + open_recent->setEnabled(false); + } } void MainWindow::load_recent_project() { - int index = static_cast(sender())->data().toInt(); - QString recent_url = recent_projects.at(index); - if (!QFile::exists(recent_url)) { - if (QMessageBox::question(this, "Missing recent project", "The project '" + recent_url + "' no longer exists. Would you like to remove it from the recent projects list?", QMessageBox::Yes, QMessageBox::No) == QMessageBox::Yes) { - recent_projects.removeAt(index); - panel_project->save_recent_projects(); - } + int index = static_cast(sender())->data().toInt(); + QString recent_url = recent_projects.at(index); + if (!QFile::exists(recent_url)) { + if (QMessageBox::question(this, "Missing recent project", "The project '" + recent_url + "' no longer exists. Would you like to remove it from the recent projects list?", QMessageBox::Yes, QMessageBox::No) == QMessageBox::Yes) { + recent_projects.removeAt(index); + panel_project->save_recent_projects(); + } } else if (can_close_project()) { updateTitle(recent_url); - panel_project->load_project(false); - } + panel_project->load_project(false); + } } -void MainWindow::on_actionScroll_Wheel_Zooms_triggered() -{ - config.scroll_zooms = !config.scroll_zooms; -} - -void MainWindow::on_actionLink_Unlink_triggered() -{ - if (panel_timeline->focused()) panel_timeline->toggle_links(); -} - -void MainWindow::on_actionRipple_To_In_Point_triggered() { +void MainWindow::ripple_to_in_point() { if (panel_timeline->focused()) panel_timeline->ripple_to_in_point(true, true); } -void MainWindow::on_actionRipple_to_Out_Point_triggered() { +void MainWindow::ripple_to_out_point() { if (panel_timeline->focused()) panel_timeline->ripple_to_in_point(false, true); } -void MainWindow::on_actionSet_In_Point_triggered() { +void MainWindow::set_in_point() { if (panel_timeline->focused() || panel_sequence_viewer->is_focused()) { panel_sequence_viewer->set_in_point(); } else if (panel_footage_viewer->is_focused()) { @@ -822,7 +1012,7 @@ void MainWindow::on_actionSet_In_Point_triggered() { } } -void MainWindow::on_actionSet_Out_Point_triggered() { +void MainWindow::set_out_point() { if (panel_timeline->focused() || panel_sequence_viewer->is_focused()) { panel_sequence_viewer->set_out_point(); } else if (panel_footage_viewer->is_focused()) { @@ -830,111 +1020,90 @@ void MainWindow::on_actionSet_Out_Point_triggered() { } } -void MainWindow::on_actionClear_In_Out_triggered() { - if (panel_timeline->focused() || panel_sequence_viewer->is_focused()) { - panel_sequence_viewer->clear_inout_point(); - } else if (panel_footage_viewer->is_focused()) { - panel_footage_viewer->clear_inout_point(); - } +void MainWindow::clear_inout() { + if (panel_timeline->focused() || panel_sequence_viewer->is_focused()) { + panel_sequence_viewer->clear_inout_point(); + } else if (panel_footage_viewer->is_focused()) { + panel_footage_viewer->clear_inout_point(); + } } void MainWindow::toggle_full_screen() { - if (windowState() == Qt::WindowFullScreen) { - setWindowState(Qt::WindowNoState); // seems to be necessary for it to return to Maximized correctly on Linux - setWindowState(Qt::WindowMaximized); - } else { - setWindowState(Qt::WindowFullScreen); - } + if (windowState() == Qt::WindowFullScreen) { + setWindowState(Qt::WindowNoState); // seems to be necessary for it to return to Maximized correctly on Linux + setWindowState(Qt::WindowMaximized); + } else { + setWindowState(Qt::WindowFullScreen); + } } -void MainWindow::on_actionDelete_In_Out_triggered() -{ - if (panel_timeline->focused()) { - panel_timeline->delete_in_out(false); - } +void MainWindow::delete_inout() { + if (panel_timeline->focused()) { + panel_timeline->delete_in_out(false); + } } -void MainWindow::on_actionRipple_Delete_In_Out_triggered() +void MainWindow::ripple_delete_inout() { - if (panel_timeline->focused()) { - panel_timeline->delete_in_out(true); - } -} - -void MainWindow::on_actionTimeline_Track_Lines_triggered() -{ - config.show_track_lines = !config.show_track_lines; - panel_timeline->repaint_timeline(); -} - -void MainWindow::on_actionRectified_Waveforms_triggered() -{ - config.rectified_waveforms = !config.rectified_waveforms; - panel_timeline->repaint_timeline(); + if (panel_timeline->focused()) { + panel_timeline->delete_in_out(true); + } } void MainWindow::on_actionDefault_triggered() { - config.show_title_safe_area = true; - config.use_custom_title_safe_ratio = false; - panel_sequence_viewer->viewer_widget->update(); + config.show_title_safe_area = true; + config.use_custom_title_safe_ratio = false; + panel_sequence_viewer->viewer_widget->update(); } void MainWindow::on_actionOff_triggered() { - config.show_title_safe_area = false; - panel_sequence_viewer->viewer_widget->update(); + config.show_title_safe_area = false; + panel_sequence_viewer->viewer_widget->update(); } void MainWindow::on_action4_3_triggered() { - config.show_title_safe_area = true; - config.use_custom_title_safe_ratio = true; - config.custom_title_safe_ratio = 4.0/3.0; - panel_sequence_viewer->viewer_widget->update(); + config.show_title_safe_area = true; + config.use_custom_title_safe_ratio = true; + config.custom_title_safe_ratio = 4.0/3.0; + panel_sequence_viewer->viewer_widget->update(); } void MainWindow::on_action16_9_triggered() { - config.show_title_safe_area = true; - config.use_custom_title_safe_ratio = true; - config.custom_title_safe_ratio = 16.0/9.0; - panel_sequence_viewer->viewer_widget->update(); + config.show_title_safe_area = true; + config.use_custom_title_safe_ratio = true; + config.custom_title_safe_ratio = 16.0/9.0; + panel_sequence_viewer->viewer_widget->update(); } void MainWindow::on_actionCustom_triggered() { - QString input; - bool invalid = false; - QRegExp arTest("[0-9.]+:[0-9.]+"); + QString input; + bool invalid = false; + QRegExp arTest("[0-9.]+:[0-9.]+"); - do { - if (invalid) { - QMessageBox::critical(this, "Invalid aspect ratio", "The aspect ratio '" + input + "' is invalid. Please try again."); - } + do { + if (invalid) { + QMessageBox::critical(this, "Invalid aspect ratio", "The aspect ratio '" + input + "' is invalid. Please try again."); + } - input = QInputDialog::getText(this, "Enter custom aspect ratio", "Enter the aspect ratio to use for the title/action safe area (e.g. 16:9):"); - invalid = !arTest.exactMatch(input) && !input.isEmpty(); - } while (invalid); + input = QInputDialog::getText(this, "Enter custom aspect ratio", "Enter the aspect ratio to use for the title/action safe area (e.g. 16:9):"); + invalid = !arTest.exactMatch(input) && !input.isEmpty(); + } while (invalid); - if (!input.isEmpty()) { - QStringList inputList = input.split(':'); + if (!input.isEmpty()) { + QStringList inputList = input.split(':'); - config.show_title_safe_area = true; - config.use_custom_title_safe_ratio = true; - config.custom_title_safe_ratio = inputList.at(0).toDouble()/inputList.at(1).toDouble(); - panel_sequence_viewer->viewer_widget->update(); - } + config.show_title_safe_area = true; + config.use_custom_title_safe_ratio = true; + config.custom_title_safe_ratio = inputList.at(0).toDouble()/inputList.at(1).toDouble(); + panel_sequence_viewer->viewer_widget->update(); + } } -void MainWindow::on_actionEnable_Drag_Files_to_Timeline_triggered() { - config.enable_drag_files_to_timeline = !config.enable_drag_files_to_timeline; -} - -void MainWindow::on_actionAuto_scale_by_Default_triggered() { - config.autoscale_by_default = !config.autoscale_by_default; -} - -void MainWindow::on_actionSet_Edit_Marker_triggered() { +void MainWindow::set_marker() { if (sequence != NULL) panel_timeline->set_marker(); } -void MainWindow::on_actionEnable_Disable_Clip_triggered() { +void MainWindow::toggle_enable_clips() { if (sequence != NULL) { ComboAction* ca = new ComboAction(); bool push_undo = false; @@ -954,47 +1123,35 @@ void MainWindow::on_actionEnable_Disable_Clip_triggered() { } } -void MainWindow::on_actionEnable_Seek_to_Import_triggered() { - config.enable_seek_to_import = !config.enable_seek_to_import; -} - -void MainWindow::on_actionAudio_Scrubbing_triggered() { - config.enable_audio_scrubbing = !config.enable_audio_scrubbing; -} - -void MainWindow::on_actionTransition_Tool_triggered() { - if (panel_timeline->focused()) panel_timeline->ui->toolTransitionButton->click(); -} - -void MainWindow::on_actionEdit_to_In_Point_triggered() { +void MainWindow::edit_to_in_point() { if (panel_timeline->focused()) panel_timeline->ripple_to_in_point(true, false); } -void MainWindow::on_actionEdit_to_Out_Point_triggered() { +void MainWindow::edit_to_out_point() { if (panel_timeline->focused()) panel_timeline->ripple_to_in_point(false, false); } -void MainWindow::on_actionNest_triggered() { - if (sequence != NULL) { - QVector selected_clips; - long earliest_point = LONG_MAX; +void MainWindow::nest() { + if (sequence != NULL) { + QVector selected_clips; + long earliest_point = LONG_MAX; - // get selected clips + // get selected clips for (int i=0;iclips.size();i++) { Clip* c = sequence->clips.at(i); if (c != NULL && panel_timeline->is_clip_selected(c, true)) { - selected_clips.append(i); - earliest_point = qMin(c->timeline_in, earliest_point); + selected_clips.append(i); + earliest_point = qMin(c->timeline_in, earliest_point); } } - // nest them + // nest them if (!selected_clips.isEmpty()) { - ComboAction* ca = new ComboAction(); + ComboAction* ca = new ComboAction(); Sequence* s = new Sequence(); - // create "nest" sequence + // create "nest" sequence s->name = panel_project->get_next_sequence_name("Nested Sequence"); s->width = sequence->width; s->height = sequence->height; @@ -1002,76 +1159,67 @@ void MainWindow::on_actionNest_triggered() { s->audio_frequency = sequence->audio_frequency; s->audio_layout = sequence->audio_layout; - // copy all selected clips to the nest + // copy all selected clips to the nest for (int i=0;iappend(new DeleteClipAction(sequence, selected_clips.at(i))); + // delete clip from old sequence + ca->append(new DeleteClipAction(sequence, selected_clips.at(i))); - // copy to new - Clip* copy = sequence->clips.at(selected_clips.at(i))->copy(s); - copy->timeline_in -= earliest_point; - copy->timeline_out -= earliest_point; - s->clips.append(copy); + // copy to new + Clip* copy = sequence->clips.at(selected_clips.at(i))->copy(s); + copy->timeline_in -= earliest_point; + copy->timeline_out -= earliest_point; + s->clips.append(copy); } - // add sequence to project - Media* m = panel_project->new_sequence(ca, s, false, NULL); + // add sequence to project + Media* m = panel_project->new_sequence(ca, s, false, NULL); - // add nested sequence to active sequence - QVector media_list = {m}; - panel_timeline->create_ghosts_from_media(sequence, earliest_point, media_list); - panel_timeline->add_clips_from_ghosts(ca, sequence); + // add nested sequence to active sequence + QVector media_list = {m}; + panel_timeline->create_ghosts_from_media(sequence, earliest_point, media_list); + panel_timeline->add_clips_from_ghosts(ca, sequence); - undo_stack.push(ca); + undo_stack.push(ca); - update_ui(true); - } + update_ui(true); + } } } -void MainWindow::on_actionToggle_Show_All_triggered() { - if (sequence != NULL) panel_timeline->toggle_show_all(); +void MainWindow::paste_insert() { + if (panel_timeline->focused() && sequence != NULL) { + panel_timeline->paste(true); + } } -void MainWindow::on_actionEnable_Drop_on_Media_to_Replace_triggered() { - config.drop_on_media_to_replace = !config.drop_on_media_to_replace; +void MainWindow::toggle_bool_action() { + QAction* action = static_cast(sender()); + bool* variable = reinterpret_cast(action->data().value()); + *variable = !(*variable); + update_ui(false); } -void MainWindow::on_actionFootage_Viewer_triggered() { - panel_footage_viewer->setVisible(!panel_footage_viewer->isVisible()); +void MainWindow::set_autoscroll() { + QAction* action = static_cast(sender()); + config.autoscroll = action->data().toInt(); } -void MainWindow::on_actionPasteInsert_triggered() { - if (panel_timeline->focused() && sequence != NULL) { - panel_timeline->paste(true); - } +void MainWindow::menu_click_button() { + if (panel_timeline->focused() + || panel_effect_controls->keyframe_focus() + || panel_footage_viewer->is_focused() + || panel_sequence_viewer->is_focused()) + reinterpret_cast(static_cast(sender())->data().value())->click(); } -void MainWindow::on_actionNo_autoscroll_triggered() { - config.autoscroll = AUTOSCROLL_NO_SCROLL; +void MainWindow::toggle_panel_visibility() { + QAction* action = static_cast(sender()); + QDockWidget* w = reinterpret_cast(action->data().value()); + w->setVisible(!w->isVisible()); } -void MainWindow::on_actionPage_Autoscroll_triggered() { - config.autoscroll = AUTOSCROLL_PAGE_SCROLL; -} - -void MainWindow::on_actionSmooth_Auto_scroll_triggered() { - config.autoscroll = AUTOSCROLL_SMOOTH_SCROLL; -} - -void MainWindow::on_actionMilliseconds_triggered() { - config.timecode_view = TIMECODE_MILLISECONDS; - update_ui(false); -} - -void MainWindow::on_actionEnable_Hover_Focus_triggered() { - config.hover_focus = !config.hover_focus; -} - -void MainWindow::on_actionHand_Tool_triggered() { - if (panel_timeline->focused() - || panel_effect_controls->keyframe_focus() - || panel_footage_viewer->is_focused() - || panel_sequence_viewer->is_focused()) - panel_timeline->ui->toolHandButton->click(); +void MainWindow::set_timecode_view() { + QAction* action = static_cast(sender()); + config.timecode_view = action->data().toInt(); + update_ui(false); } diff --git a/mainwindow.h b/mainwindow.h index a1b380542..a14a1ea3f 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -8,18 +8,14 @@ class EffectControls; class Viewer; class Timeline; -namespace Ui { -class MainWindow; -} - class MainWindow : public QMainWindow { Q_OBJECT public: explicit MainWindow(QWidget *parent = 0); - void updateTitle(const QString &url); - ~MainWindow(); + void updateTitle(const QString &url); + ~MainWindow(); public slots: void undo(); @@ -28,199 +24,147 @@ public slots: void cut(); void copy(); void paste(); - void new_project(); - void autorecover_interval(); - void on_actionNest_triggered(); - void on_actionClear_In_Out_triggered(); - void toggle_full_screen(); + void new_project(); + void autorecover_interval(); + void nest(); + void toggle_full_screen(); protected: void closeEvent(QCloseEvent *); void paintEvent(QPaintEvent *event); private slots: - void on_action_Import_triggered(); + void show_about(); + void delete_slot(); + void select_all(); - void on_actionExit_triggered(); + void new_sequence(); - void on_actionAbout_triggered(); + void zoom_in(); + void zoom_out(); + void export_dialog(); + void ripple_delete(); - void on_actionDelete_triggered(); + void open_project(); + bool save_project_as(); + bool save_project(); - void on_actionSelect_All_triggered(); + void go_to_start(); + void prev_frame(); + void playpause(); + void next_frame(); + void go_to_end(); + void prev_cut(); + void next_cut(); - void on_actionSequence_triggered(); + void reset_layout(); - void on_actionZoom_In_triggered(); + void preferences(); - void on_actionZoom_out_triggered(); + void zoom_in_tracks(); - void on_actionExport_triggered(); + void zoom_out_tracks(); - void on_actionProject_2_triggered(); + void fileMenu_About_To_Be_Shown(); + void editMenu_About_To_Be_Shown(); + void windowMenu_About_To_Be_Shown(); + void viewMenu_About_To_Be_Shown(); + void toolMenu_About_To_Be_Shown(); - void on_actionEffect_Controls_triggered(); + void duplicate(); - void on_actionViewer_triggered(); + void add_default_transition(); - void on_actionTimeline_triggered(); + void new_folder(); - void on_actionRipple_Delete_triggered(); + void load_recent_project(); - void on_actionSplit_at_Playhead_triggered(); + void ripple_to_in_point(); + void ripple_to_out_point(); - void on_action_Save_Project_triggered(); + void set_in_point(); + void set_out_point(); - void on_action_Open_Project_triggered(); + void clear_inout(); + void delete_inout(); + void ripple_delete_inout(); - void on_actionSave_Project_As_triggered(); + void on_actionDefault_triggered(); + void on_actionOff_triggered(); + void on_action4_3_triggered(); + void on_action16_9_triggered(); + void on_actionCustom_triggered(); - void on_actionDeselect_All_triggered(); + void set_marker(); - void on_actionGo_to_start_triggered(); - - void on_actionReset_to_default_layout_triggered(); - - void on_actionPrevious_Frame_triggered(); - - void on_actionNext_Frame_triggered(); - - void on_actionGo_to_End_triggered(); - - void on_actionPlay_Pause_triggered(); - - void on_actionEdit_Tool_triggered(); - - void on_actionToggle_Snapping_triggered(); - - void on_actionPointer_Tool_triggered(); - - void on_actionRazor_Tool_triggered(); - - void on_actionRipple_Tool_triggered(); - - void on_actionRolling_Tool_triggered(); - - void on_actionSlip_Tool_triggered(); - - void on_actionGo_to_Previous_Cut_triggered(); - - void on_actionGo_to_Next_Cut_triggered(); - - void on_actionPreferences_triggered(); - - void on_actionIncrease_Track_Height_triggered(); - - void on_actionDecrease_Track_Height_triggered(); - - void windowMenu_About_To_Be_Shown(); - - void on_actionFrames_triggered(); - - void on_actionDrop_Frame_triggered(); - - void on_actionNon_Drop_Frame_triggered(); - - void viewMenu_About_To_Be_Shown(); - - void on_actionEdit_Tool_Selects_Links_triggered(); - - void on_actionEdit_Tool_Also_Seeks_triggered(); - - void toolMenu_About_To_Be_Shown(); - - void on_actionDuplicate_triggered(); - - void on_actionSelecting_Also_Seeks_triggered(); - - void on_actionSeek_to_the_End_of_Pastes_triggered(); - - void on_actionAdd_Default_Transition_triggered(); - - void on_actionSlide_Tool_triggered(); - - void on_actionFolder_triggered(); - - void editMenu_About_To_Be_Shown(); - - void fileMenu_About_To_Be_Shown(); - - void load_recent_project(); - - void on_actionScroll_Wheel_Zooms_triggered(); - - void on_actionLink_Unlink_triggered(); - - void on_actionRipple_To_In_Point_triggered(); - - void on_actionRipple_to_Out_Point_triggered(); - - void on_actionSet_In_Point_triggered(); - - void on_actionSet_Out_Point_triggered(); - - void on_actionDelete_In_Out_triggered(); - - void on_actionRipple_Delete_In_Out_triggered(); - - void on_actionTimeline_Track_Lines_triggered(); - - void on_actionRectified_Waveforms_triggered(); - - void on_actionDefault_triggered(); - - void on_actionOff_triggered(); - - void on_action4_3_triggered(); - - void on_action16_9_triggered(); - - void on_actionCustom_triggered(); - - void on_actionEnable_Drag_Files_to_Timeline_triggered(); - - void on_actionAuto_scale_by_Default_triggered(); - - void on_actionSet_Edit_Marker_triggered(); - - void on_actionEnable_Disable_Clip_triggered(); - - void on_actionEnable_Seek_to_Import_triggered(); - - void on_actionAudio_Scrubbing_triggered(); - - void on_actionTransition_Tool_triggered(); - - void on_actionEdit_to_In_Point_triggered(); - - void on_actionEdit_to_Out_Point_triggered(); - - void on_actionToggle_Show_All_triggered(); - - void on_actionEnable_Drop_on_Media_to_Replace_triggered(); - - void on_actionFootage_Viewer_triggered(); - - void on_actionPasteInsert_triggered(); - - void on_actionNo_autoscroll_triggered(); - - void on_actionPage_Autoscroll_triggered(); - - void on_actionSmooth_Auto_scroll_triggered(); - - void on_actionMilliseconds_triggered(); - - void on_actionEnable_Hover_Focus_triggered(); - - void on_actionHand_Tool_triggered(); + void toggle_enable_clips(); + void edit_to_in_point(); + void edit_to_out_point(); + void paste_insert(); + void toggle_bool_action(); + void set_autoscroll(); + void menu_click_button(); + void toggle_panel_visibility(); + void set_timecode_view(); private: - Ui::MainWindow *ui; - void setup_layout(bool reset); - bool save_project_as(); - bool save_project(); - bool can_close_project(); + void setup_layout(bool reset); + bool can_close_project(); + void setup_menus(); + + // menu bar menus + QMenu* window_menu; + + // file menu actions + QMenu* open_recent; + + // view menu actions + QAction* track_lines; + QAction* frames_action; + QAction* drop_frame_action; + QAction* nondrop_frame_action; + QAction* milliseconds_action; + QAction* no_autoscroll; + QAction* page_autoscroll; + QAction* smooth_autoscroll; + QAction* title_safe_off; + QAction* title_safe_default; + QAction* title_safe_43; + QAction* title_safe_169; + QAction* title_safe_custom; + QAction* full_screen; + QAction* show_all; + + // tool menu actions + QAction* pointer_tool_action; + QAction* edit_tool_action; + QAction* ripple_tool_action; + QAction* razor_tool_action; + QAction* slip_tool_action; + QAction* slide_tool_action; + QAction* hand_tool_action; + QAction* transition_tool_action; + QAction* snap_toggle; + QAction* selecting_also_seeks; + QAction* edit_tool_also_seeks; + QAction* edit_tool_selects_links; + QAction* seek_to_end_of_pastes; + QAction* scroll_wheel_zooms; + QAction* rectified_waveforms; + QAction* enable_drag_files_to_timeline; + QAction* autoscale_by_default; + QAction* enable_seek_to_import; + QAction* enable_audio_scrubbing; + QAction* enable_drop_on_media_to_replace; + QAction* enable_hover_focus; + + // edit menu actions + QAction* undo_action; + QAction* redo_action; + + void set_bool_action_checked(QAction* a); + void set_int_action_checked(QAction* a, const int& i); + void set_button_action_checked(QAction* a); }; extern MainWindow* mainWindow; diff --git a/mainwindow.ui b/mainwindow.ui deleted file mode 100644 index fe24d5e23..000000000 --- a/mainwindow.ui +++ /dev/null @@ -1,964 +0,0 @@ - - - MainWindow - - - - 0 - 0 - 653 - 394 - - - - MainWindow - - - - - 0 - 0 - - - - - 0 - 0 - - - - - - - 0 - 0 - 653 - 16 - - - - - &File - - - - &New - - - - - - - - - Open Recent - - - - - - - - - - - - - - - - - &Edit - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - &Window - - - - - - - - - - - - &Help - - - - - - &View - - - - Title/Action Safe Area - - - - - - - - - - - - - - - - - - - - - - - - - - - &Playback - - - - - - - - - - - - - &Tools - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - &Open Project - - - Ctrl+O - - - - - &Save Project - - - Ctrl+S - - - - - Save Project &As - - - Ctrl+Shift+S - - - - - &Import... - - - Ctrl+I - - - - - &Export... - - - Ctrl+M - - - - - E&xit - - - - - About... - - - - - &Undo - - - Ctrl+Z - - - - - &Redo - - - Ctrl+Shift+Z - - - - - Cu&t - - - Ctrl+X - - - - - Cop&y - - - Ctrl+C - - - - - &Paste - - - Ctrl+V - - - - - Paste Insert - - - Ctrl+Shift+V - - - - - Delete - - - Del - - - - - Select &All - - - Ctrl+A - - - - - true - - - Track Lines - - - - - Project... - - - Ctrl+N - - - - - Sequence... - - - Ctrl+Shift+N - - - - - Zoom In - - - = - - - - - Zoom Out - - - - - - - - - true - - - true - - - Project - - - - - true - - - true - - - Effect Controls - - - - - true - - - true - - - Sequence Viewer - - - - - true - - - true - - - Timeline - - - - - Ripple Delete - - - Shift+Del - - - - - Split at Playhead - - - Ctrl+K - - - - - Deselect All - - - - - Go to Start - - - Home - - - - - Reset to default layout - - - - - Previous Frame - - - Left - - - - - Play/Pause - - - Space - - - - - Next Frame - - - Right - - - - - Go to End - - - End - - - - - Crash - - - false - - - - - Pointer Tool - - - V - - - - - Edit Tool - - - X - - - - - Razor Tool - - - C - - - - - Ripple Tool - - - B - - - - - Rolling Tool - - - N - - - false - - - - - Preferences - - - Ctrl+. - - - - - true - - - Snapping - - - Snapping - - - S - - - - - Slip Tool - - - Y - - - - - Go to Previous Cut - - - Up - - - - - Go to Next Cut - - - Down - - - - - true - - - Edit Tool Also Seeks - - - - - Increase Track Height - - - Ctrl+= - - - - - Decrease Track Height - - - Ctrl+- - - - - - true - - - Frames - - - - - true - - - Drop-Frame - - - - - true - - - Non-Drop Frame - - - - - true - - - Edit Tool Selects Links - - - - - Duplicate - - - Ctrl+D - - - - - true - - - Selecting Also Seeks - - - - - true - - - Seek to the End of Pastes - - - - - Add Default Transition - - - Ctrl+Shift+D - - - - - Slide Tool - - - U - - - - - Folder - - - - - Clear Recent List - - - - - true - - - Scroll Wheel Zooms - - - - - Link/Unlink - - - Ctrl+L - - - - - Ripple to In Point - - - Q - - - - - Ripple to Out Point - - - W - - - - - Set In Point - - - I - - - - - Set Out Point - - - O - - - - - Clear In/Out - - - G - - - - - Delete In/Out - - - ; - - - - - Ripple Delete In/Out - - - ' - - - - - true - - - Rectified Waveforms - - - - - true - - - Default - - - - - true - - - Off - - - - - true - - - 4:3 - - - - - true - - - 16:9 - - - - - true - - - Custom - - - - - true - - - Enable Drag Files to Timeline - - - - - true - - - Auto-scale by Default - - - - - Set/Edit Marker - - - M - - - - - Enable/Disable Clip - - - Shift+E - - - - - true - - - Enable Seek to Import - - - - - true - - - Audio Scrubbing - - - - - Transition Tool - - - T - - - - - Edit to In Point - - - Ctrl+Alt+Q - - - - - Edit to Out Point - - - Ctrl+Alt+W - - - - - Nest - - - - - Toggle Show All - - - \ - - - - - true - - - Enable Drop File on Media to Replace - - - - - true - - - Footage Viewer - - - - - true - - - No Auto-scroll - - - - - true - - - Page Auto-scroll - - - - - true - - - Smooth Auto-scroll - - - - - true - - - Milliseconds - - - - - true - - - Enable Hover Focus for Zooming - - - - - true - - - Full Screen - - - F11 - - - - - Hand Tool - - - H - - - - - - - diff --git a/olive.pro b/olive.pro index 6dc271e34..84097088f 100644 --- a/olive.pro +++ b/olive.pro @@ -188,7 +188,6 @@ HEADERS += \ ui/keyframenavigator.h FORMS += \ - mainwindow.ui \ panels/effectcontrols.ui \ panels/viewer.ui \ panels/timeline.ui \ diff --git a/panels/project.cpp b/panels/project.cpp index ce3264a6c..afaa1a127 100644 --- a/panels/project.cpp +++ b/panels/project.cpp @@ -71,73 +71,69 @@ Project::Project(QWidget *parent) : QWidget* dockWidgetContents = new QWidget(); QVBoxLayout* verticalLayout = new QVBoxLayout(dockWidgetContents); verticalLayout->setContentsMargins(0, 0, 0, 0); - verticalLayout->setSpacing(0); + verticalLayout->setSpacing(0); setWidget(dockWidgetContents); - sources_common = new SourcesCommon(this); + sources_common = new SourcesCommon(this); - sorter = new QSortFilterProxyModel(this); - sorter->setSourceModel(&project_model); + sorter = new QSortFilterProxyModel(this); + sorter->setSourceModel(&project_model); - tree_view = new SourceTable(dockWidgetContents); - tree_view->project_parent = this; - tree_view->setAcceptDrops(true); - tree_view->setEditTriggers(QAbstractItemView::NoEditTriggers); - tree_view->setDragDropMode(QAbstractItemView::DragDrop); - tree_view->setSelectionMode(QAbstractItemView::ExtendedSelection); - tree_view->setModel(sorter); - verticalLayout->addWidget(tree_view); + tree_view = new SourceTable(dockWidgetContents); + tree_view->project_parent = this; + tree_view->setModel(sorter); + verticalLayout->addWidget(tree_view); - icon_view_container = new QWidget(); + icon_view_container = new QWidget(); - QVBoxLayout* icon_view_container_layout = new QVBoxLayout(); - icon_view_container_layout->setMargin(0); - icon_view_container_layout->setSpacing(0); - icon_view_container->setLayout(icon_view_container_layout); + QVBoxLayout* icon_view_container_layout = new QVBoxLayout(); + icon_view_container_layout->setMargin(0); + icon_view_container_layout->setSpacing(0); + icon_view_container->setLayout(icon_view_container_layout); - QHBoxLayout* icon_view_controls = new QHBoxLayout(); - icon_view_controls->setMargin(0); - icon_view_controls->setSpacing(0); + QHBoxLayout* icon_view_controls = new QHBoxLayout(); + icon_view_controls->setMargin(0); + icon_view_controls->setSpacing(0); - QIcon directory_up_button; - directory_up_button.addFile(":/icons/dirup.png", QSize(), QIcon::Normal); - directory_up_button.addFile(":/icons/dirup-disabled.png", QSize(), QIcon::Disabled); + QIcon directory_up_button; + directory_up_button.addFile(":/icons/dirup.png", QSize(), QIcon::Normal); + directory_up_button.addFile(":/icons/dirup-disabled.png", QSize(), QIcon::Disabled); - directory_up = new QPushButton(); - directory_up->setIcon(directory_up_button); - directory_up->setEnabled(false); - icon_view_controls->addWidget(directory_up); + directory_up = new QPushButton(); + directory_up->setIcon(directory_up_button); + directory_up->setEnabled(false); + icon_view_controls->addWidget(directory_up); - icon_view_controls->addStretch(); + icon_view_controls->addStretch(); - QSlider* icon_size_slider = new QSlider(Qt::Horizontal); - icon_size_slider->setMinimum(16); - icon_size_slider->setMaximum(120); - icon_view_controls->addWidget(icon_size_slider); - connect(icon_size_slider, SIGNAL(valueChanged(int)), this, SLOT(set_icon_view_size(int))); + QSlider* icon_size_slider = new QSlider(Qt::Horizontal); + icon_size_slider->setMinimum(16); + icon_size_slider->setMaximum(120); + icon_view_controls->addWidget(icon_size_slider); + connect(icon_size_slider, SIGNAL(valueChanged(int)), this, SLOT(set_icon_view_size(int))); - icon_view_container_layout->addLayout(icon_view_controls); + icon_view_container_layout->addLayout(icon_view_controls); - icon_view = new SourceIconView(dockWidgetContents); - icon_view->project_parent = this; - icon_view->setModel(sorter); - icon_view->setIconSize(QSize(100, 100)); - icon_view->setViewMode(QListView::IconMode); - icon_view->setUniformItemSizes(true); - icon_view_container_layout->addWidget(icon_view); + icon_view = new SourceIconView(dockWidgetContents); + icon_view->project_parent = this; + icon_view->setModel(sorter); + icon_view->setIconSize(QSize(100, 100)); + icon_view->setViewMode(QListView::IconMode); + icon_view->setUniformItemSizes(true); + icon_view_container_layout->addWidget(icon_view); - icon_size_slider->setValue(icon_view->iconSize().height()); + icon_size_slider->setValue(icon_view->iconSize().height()); - verticalLayout->addWidget(icon_view_container); + verticalLayout->addWidget(icon_view_container); - connect(directory_up, SIGNAL(clicked(bool)), this, SLOT(go_up_dir())); - connect(icon_view, SIGNAL(changed_root()), this, SLOT(set_up_dir_enabled())); + connect(directory_up, SIGNAL(clicked(bool)), this, SLOT(go_up_dir())); + connect(icon_view, SIGNAL(changed_root()), this, SLOT(set_up_dir_enabled())); //retranslateUi(Project); setWindowTitle(QApplication::translate("Project", "Project", nullptr)); - update_view_type(); + update_view_type(); } Project::~Project() { @@ -157,8 +153,8 @@ QString Project::get_next_sequence_name(QString start) { name += "0"; } name += QString::number(n); - for (int i=0;iget_name(), name, Qt::CaseInsensitive) == 0) { + for (int i=0;iget_name(), name, Qt::CaseInsensitive) == 0) { found = true; n++; break; @@ -183,11 +179,11 @@ Sequence* create_sequence_from_media(QVector& media_list) { bool got_video_values = false; bool got_audio_values = false; for (int i=0;iget_type()) { + Media* media = media_list.at(i); + switch (media->get_type()) { case MEDIA_TYPE_FOOTAGE: { - Footage* m = media->to_footage(); + Footage* m = media->to_footage(); if (m->ready) { if (!got_video_values) { for (int j=0;jvideo_tracks.size();j++) { @@ -218,7 +214,7 @@ Sequence* create_sequence_from_media(QVector& media_list) { break; case MEDIA_TYPE_SEQUENCE: { - Sequence* seq = media->to_sequence(); + Sequence* seq = media->to_sequence(); s->width = seq->width; s->height = seq->height; s->frame_rate = seq->frame_rate; @@ -237,28 +233,29 @@ Sequence* create_sequence_from_media(QVector& media_list) { } void Project::duplicate_selected() { - QModelIndexList items = tree_view->selectionModel()->selectedRows(); - bool duped = false; - ComboAction* ca = new ComboAction(); - for (int j=0;jget_type() == MEDIA_TYPE_SEQUENCE) { - new_sequence(ca, i->to_sequence()->copy(), false, item_to_media(items.at(j).parent())); - duped = true; - } - } - if (duped) { - undo_stack.push(ca); - } else { - delete ca; - } + QModelIndexList items = get_current_selected(); + bool duped = false; + ComboAction* ca = new ComboAction(); + for (int j=0;jget_type() == MEDIA_TYPE_SEQUENCE) { + new_sequence(ca, i->to_sequence()->copy(), false, item_to_media(items.at(j).parent())); + duped = true; + } + } + if (duped) { + undo_stack.push(ca); + } else { + delete ca; + } } void Project::replace_selected_file() { - QModelIndexList selected_items = tree_view->selectionModel()->selectedRows(); + QModelIndexList selected_items = get_current_selected(); if (selected_items.size() == 1) { - Media* item = item_to_media(selected_items.at(0)); - if (item->get_type() == MEDIA_TYPE_FOOTAGE) { + Media* item = item_to_media(selected_items.at(0)); + if (item->get_type() == MEDIA_TYPE_FOOTAGE) { replace_media(item, 0); } } @@ -266,7 +263,7 @@ void Project::replace_selected_file() { void Project::replace_media(Media* item, QString filename) { if (filename.isEmpty()) { - filename = QFileDialog::getOpenFileName(this, "Replace '" + item->get_name() + "'", "", "All Files (*)"); + filename = QFileDialog::getOpenFileName(this, "Replace '" + item->get_name() + "'", "", "All Files (*)"); } if (!filename.isEmpty()) { ReplaceMediaCommand* rmc = new ReplaceMediaCommand(item, filename); @@ -277,46 +274,46 @@ void Project::replace_media(Media* item, QString filename) { void Project::replace_clip_media() { if (sequence == NULL) { QMessageBox::critical(this, "No active sequence", "No sequence is active, please open the sequence you want to replace clips from.", QMessageBox::Ok); - } else { - QModelIndexList selected_items = tree_view->selectionModel()->selectedRows(); - if (selected_items.size() == 1) { - Media* item = item_to_media(selected_items.at(0)); - if (item->get_type() == MEDIA_TYPE_SEQUENCE && sequence == item->to_sequence()) { - QMessageBox::critical(this, "Active sequence selected", "You cannot insert a sequence into itself, so no clips of this media would be in this sequence.", QMessageBox::Ok); - } else { - ReplaceClipMediaDialog dialog(this, tree_view, item); - dialog.exec(); - } - } + } else { + QModelIndexList selected_items = get_current_selected(); + if (selected_items.size() == 1) { + Media* item = item_to_media(selected_items.at(0)); + if (item->get_type() == MEDIA_TYPE_SEQUENCE && sequence == item->to_sequence()) { + QMessageBox::critical(this, "Active sequence selected", "You cannot insert a sequence into itself, so no clips of this media would be in this sequence.", QMessageBox::Ok); + } else { + ReplaceClipMediaDialog dialog(this, item); + dialog.exec(); + } + } } } void Project::open_properties() { - QModelIndexList selected_items = tree_view->selectionModel()->selectedRows(); - if (selected_items.size() == 1) { - Media* item = item_to_media(selected_items.at(0)); - switch (item->get_type()) { + QModelIndexList selected_items = get_current_selected(); + if (selected_items.size() == 1) { + Media* item = item_to_media(selected_items.at(0)); + switch (item->get_type()) { case MEDIA_TYPE_FOOTAGE: { - MediaPropertiesDialog mpd(this, item); + MediaPropertiesDialog mpd(this, item); mpd.exec(); } break; case MEDIA_TYPE_SEQUENCE: { NewSequenceDialog nsd(this); - Sequence* s = item->to_sequence(); + Sequence* s = item->to_sequence(); nsd.existing_sequence = s; - nsd.existing_item = item; + nsd.existing_item = item; nsd.exec(); } break; default: { // fall back to renaming - QString new_name = QInputDialog::getText(this, "Rename '" + item->get_name() + "'", "Enter new name:", QLineEdit::Normal, item->get_name()); - if (!new_name.isEmpty()) { - MediaRename* mr = new MediaRename(item, new_name); + QString new_name = QInputDialog::getText(this, "Rename '" + item->get_name() + "'", "Enter new name:", QLineEdit::Normal, item->get_name()); + if (!new_name.isEmpty()) { + MediaRename* mr = new MediaRename(item, new_name); undo_stack.push(mr); } } @@ -325,18 +322,18 @@ void Project::open_properties() { } Media* Project::new_sequence(ComboAction *ca, Sequence *s, bool open, Media* parent) { - if (parent == NULL) parent = project_model.get_root(); - Media* item = new Media(parent); - item->set_sequence(s); + if (parent == NULL) parent = project_model.get_root(); + Media* item = new Media(parent); + item->set_sequence(s); - if (ca != NULL) { - ca->append(new NewSequenceCommand(item, parent)); - if (open) ca->append(new ChangeSequenceAction(s)); - } else { - project_model.appendChild(NULL, item); - if (open) set_sequence(s); + if (ca != NULL) { + ca->append(new NewSequenceCommand(item, parent)); + if (open) ca->append(new ChangeSequenceAction(s)); + } else { + project_model.appendChild(NULL, item); + if (open) set_sequence(s); } - return item; + return item; } QString Project::get_file_name_from_path(const QString& path) { @@ -344,233 +341,229 @@ QString Project::get_file_name_from_path(const QString& path) { } /*Media* Project::new_item() { - Media* item = new Media(0); - //item->setFlags(item->flags() | Qt::ItemIsEditable); - return item; + Media* item = new Media(0); + //item->setFlags(item->flags() | Qt::ItemIsEditable); + return item; }*/ bool Project::is_focused() { - return tree_view->hasFocus(); + return tree_view->hasFocus() || icon_view->hasFocus(); } Media* Project::new_folder(QString name) { - Media* item = new Media(0); - item->set_folder(); - return item; + Media* item = new Media(0); + item->set_folder(); + return item; } Media *Project::item_to_media(const QModelIndex &index) { - return static_cast(sorter->mapToSource(index).internalPointer()); + return static_cast(sorter->mapToSource(index).internalPointer()); // return static_cast(index.internalPointer()); } void Project::get_all_media_from_table(QList items, QList& list, int search_type) { - for (int i=0;iget_type() == MEDIA_TYPE_FOLDER) { - QList children; - for (int j=0;jchildCount();j++) { - children.append(item->child(j)); - } + for (int i=0;iget_type() == MEDIA_TYPE_FOLDER) { + QList children; + for (int j=0;jchildCount();j++) { + children.append(item->child(j)); + } get_all_media_from_table(children, list, search_type); - } else if (search_type == item->get_type() || search_type == -1) { - list.append(item); - } - } + } else if (search_type == item->get_type() || search_type == -1) { + list.append(item); + } + } } bool delete_clips_in_clipboard_with_media(ComboAction* ca, Media* m) { - int delete_count = 0; - if (clipboard_type == CLIPBOARD_TYPE_CLIP) { - for (int i=0;i(clipboard.at(i)); - if (c->media == m) { - ca->append(new RemoveClipsFromClipboard(i-delete_count)); - delete_count++; - } - } - } - return (delete_count > 0); + int delete_count = 0; + if (clipboard_type == CLIPBOARD_TYPE_CLIP) { + for (int i=0;i(clipboard.at(i)); + if (c->media == m) { + ca->append(new RemoveClipsFromClipboard(i-delete_count)); + delete_count++; + } + } + } + return (delete_count > 0); } void Project::delete_selected_media() { - ComboAction* ca = new ComboAction(); - QModelIndexList selected_items = tree_view->selectionModel()->selectedRows(); - QList items; - for (int i=0;i items; + for (int i=0;isetSortingEnabled(false); - tree_view->setSortingEnabled(true); - - // check if media is in use - QVector parents; - QList sequence_items; - QList all_top_level_items; - for (int i=0;i parents; + QList sequence_items; + QList all_top_level_items; + for (int i=0;i 0) { - QList media_items; + if (sequence_items.size() > 0) { + QList media_items; get_all_media_from_table(items, media_items, MEDIA_TYPE_FOOTAGE); - for (int i=0;ito_footage(); - bool confirm_delete = false; - for (int j=0;jto_sequence(); - for (int k=0;kclips.size();k++) { - Clip* c = s->clips.at(k); - if (c != NULL && c->media == item) { - if (!confirm_delete) { - // we found a reference, so we know we'll need to ask if the user wants to delete it - QMessageBox confirm(this); - confirm.setWindowTitle("Delete media in use?"); - confirm.setText("The media '" + media->name + "' is currently used in '" + s->name + "'. Deleting it will remove all instances in the sequence. Are you sure you want to do this?"); - QAbstractButton* yes_button = confirm.addButton(QMessageBox::Yes); - QAbstractButton* skip_button = NULL; - if (items.size() > 1) skip_button = confirm.addButton("Skip", QMessageBox::NoRole); - QAbstractButton* abort_button = confirm.addButton(QMessageBox::Cancel); - confirm.exec(); - if (confirm.clickedButton() == yes_button) { - // remove all clips referencing this media - confirm_delete = true; - redraw = true; - } else if (confirm.clickedButton() == skip_button) { - // remove media item and any folders containing it from the remove list - Media* parent = item; - while (parent != NULL) { - parents.append(parent); + for (int i=0;ito_footage(); + bool confirm_delete = false; + for (int j=0;jto_sequence(); + for (int k=0;kclips.size();k++) { + Clip* c = s->clips.at(k); + if (c != NULL && c->media == item) { + if (!confirm_delete) { + // we found a reference, so we know we'll need to ask if the user wants to delete it + QMessageBox confirm(this); + confirm.setWindowTitle("Delete media in use?"); + confirm.setText("The media '" + media->name + "' is currently used in '" + s->name + "'. Deleting it will remove all instances in the sequence. Are you sure you want to do this?"); + QAbstractButton* yes_button = confirm.addButton(QMessageBox::Yes); + QAbstractButton* skip_button = NULL; + if (items.size() > 1) skip_button = confirm.addButton("Skip", QMessageBox::NoRole); + QAbstractButton* abort_button = confirm.addButton(QMessageBox::Cancel); + confirm.exec(); + if (confirm.clickedButton() == yes_button) { + // remove all clips referencing this media + confirm_delete = true; + redraw = true; + } else if (confirm.clickedButton() == skip_button) { + // remove media item and any folders containing it from the remove list + Media* parent = item; + while (parent != NULL) { + parents.append(parent); - // re-add item's siblings - for (int m=0;mchildCount();m++) { - Media* child = parent->child(m); - bool found = false; - for (int n=0;nchildCount();m++) { + Media* child = parent->child(m); + bool found = false; + for (int n=0;nparentItem(); - } + parent = parent->parentItem(); + } - j = sequence_items.size(); - k = s->clips.size(); - } else if (confirm.clickedButton() == abort_button) { - // break out of loop - i = media_items.size(); - j = sequence_items.size(); - k = s->clips.size(); + j = sequence_items.size(); + k = s->clips.size(); + } else if (confirm.clickedButton() == abort_button) { + // break out of loop + i = media_items.size(); + j = sequence_items.size(); + k = s->clips.size(); - remove = false; - } - } - if (confirm_delete) { - ca->append(new DeleteClipAction(s, k)); - } - } - } + remove = false; + } + } + if (confirm_delete) { + ca->append(new DeleteClipAction(s, k)); + } + } + } } if (confirm_delete) { - delete_clips_in_clipboard_with_media(ca, item); + delete_clips_in_clipboard_with_media(ca, item); } - } - } + } + } - // remove - if (remove) { - // remove media and parents - for (int m=0;mappend(new DeleteMediaCommand(items.at(i))); + ca->append(new DeleteMediaCommand(items.at(i))); - if (items.at(i)->get_type() == MEDIA_TYPE_SEQUENCE) { - redraw = true; + if (items.at(i)->get_type() == MEDIA_TYPE_SEQUENCE) { + redraw = true; - Sequence* s = items.at(i)->to_sequence(); + Sequence* s = items.at(i)->to_sequence(); if (s == sequence) { - ca->append(new ChangeSequenceAction(NULL)); - } + ca->append(new ChangeSequenceAction(NULL)); + } if (s == panel_footage_viewer->seq) { - panel_footage_viewer->set_media(NULL); + panel_footage_viewer->set_media(NULL); } - } else if (items.at(i)->get_type() == MEDIA_TYPE_FOOTAGE) { + } else if (items.at(i)->get_type() == MEDIA_TYPE_FOOTAGE) { if (panel_footage_viewer->seq != NULL) { for (int j=0;jseq->clips.size();j++) { Clip* c = panel_footage_viewer->seq->clips.at(j); if (c != NULL) { - if (c->media == items.at(i)->to_object()) { - panel_footage_viewer->set_media(NULL); + if (c->media == items.at(i)->to_object()) { + panel_footage_viewer->set_media(NULL); } break; } } } } - } - undo_stack.push(ca); + } + undo_stack.push(ca); - // redraw clips - if (redraw) { + // redraw clips + if (redraw) { update_ui(true); } - } else { - delete ca; - } + } else { + delete ca; + } } void Project::start_preview_generator(Media* item, bool replacing) { - // set up throbber animation - MediaThrobber* throbber = new MediaThrobber(item); - throbber->moveToThread(QApplication::instance()->thread()); - item->throbber = throbber; - QMetaObject::invokeMethod(throbber, "start", Qt::QueuedConnection); + // set up throbber animation + MediaThrobber* throbber = new MediaThrobber(item); + throbber->moveToThread(QApplication::instance()->thread()); + item->throbber = throbber; + QMetaObject::invokeMethod(throbber, "start", Qt::QueuedConnection); - PreviewGenerator* pg = new PreviewGenerator(item, item->to_footage(), replacing); - item->to_footage()->preview_gen = pg; - connect(pg, SIGNAL(set_icon(int, bool)), throbber, SLOT(stop(int, bool))); - pg->start(QThread::LowPriority); + PreviewGenerator* pg = new PreviewGenerator(item, item->to_footage(), replacing); + item->to_footage()->preview_gen = pg; + connect(pg, SIGNAL(set_icon(int, bool)), throbber, SLOT(stop(int, bool))); + pg->start(QThread::LowPriority); } void Project::process_file_list(QStringList& files, bool recursive, Media* replace, Media* parent) { - bool imported = false; + bool imported = false; - QVector image_sequence_urls; - QVector image_sequence_importassequence; - QStringList image_sequence_formats = config.img_seq_formats.split("|"); + QVector image_sequence_urls; + QVector image_sequence_importassequence; + QStringList image_sequence_formats = config.img_seq_formats.split("|"); if (!recursive) last_imported_media.clear(); bool create_undo_action = (!recursive && replace == NULL); - ComboAction* ca; - if (create_undo_action) ca = new ComboAction(); + ComboAction* ca; + if (create_undo_action) ca = new ComboAction(); for (int i=0;iappend(new AddMediaCommand(folder, parent)); - } else { - project_model.appendChild(parent, folder); + if (create_undo_action) { + ca->append(new AddMediaCommand(folder, parent)); + } else { + project_model.appendChild(parent, folder); } imported = true; @@ -668,80 +661,86 @@ void Project::process_file_list(QStringList& files, bool recursive, Media* repla } if (!skip) { - Media* item; + Media* item; Footage* m; if (replace != NULL) { item = replace; - m = replace->to_footage(); + m = replace->to_footage(); m->reset(); } else { - item = new Media(parent); + item = new Media(parent); m = new Footage(); } - m->using_inout = false; - m->url = file; + m->using_inout = false; + m->url = file; m->name = get_file_name_from_path(files.at(i)); - item->set_footage(m); + item->set_footage(m); - // generate waveform/thumbnail in another thread - start_preview_generator(item, replace != NULL); + // generate waveform/thumbnail in another thread + start_preview_generator(item, replace != NULL); - last_imported_media.append(item); + last_imported_media.append(item); if (replace == NULL) { if (create_undo_action) { - ca->append(new AddMediaCommand(item, parent)); + ca->append(new AddMediaCommand(item, parent)); } else { - project_model.appendChild(parent, item); + project_model.appendChild(parent, item); } } imported = true; } } - } + } if (create_undo_action) { if (imported) { - undo_stack.push(ca); + undo_stack.push(ca); } else { - delete ca; + delete ca; } } } Media* Project::get_selected_folder() { // if one item is selected and it's a folder, return it - QModelIndexList selected_items = tree_view->selectionModel()->selectedRows(); - if (selected_items.size() == 1) { - Media* m = item_to_media(selected_items.at(0)); - if (m->get_type() == MEDIA_TYPE_FOLDER) return m; + QModelIndexList selected_items = get_current_selected(); + if (selected_items.size() == 1) { + Media* m = item_to_media(selected_items.at(0)); + if (m->get_type() == MEDIA_TYPE_FOLDER) return m; } - return NULL; + return NULL; } bool Project::reveal_media(Media *media, QModelIndex parent) { - for (int i=0;iget_type() == MEDIA_TYPE_FOLDER) { + if (m->get_type() == MEDIA_TYPE_FOLDER) { if (reveal_media(media, item)) return true; - } else if (m == media) { + } else if (m == media) { // expand all folders leading to this media - QModelIndex sorted_index = sorter->mapFromSource(item); + QModelIndex sorted_index = sorter->mapFromSource(item); - QModelIndex hierarchy = sorted_index.parent(); - while (hierarchy.isValid()) { - tree_view->setExpanded(hierarchy, true); - hierarchy = hierarchy.parent(); + QModelIndex hierarchy = sorted_index.parent(); + + if (config.project_view_type == PROJECT_VIEW_TREE) { + while (hierarchy.isValid()) { + tree_view->setExpanded(hierarchy, true); + hierarchy = hierarchy.parent(); + } + + // select item + tree_view->selectionModel()->select(sorted_index, QItemSelectionModel::Select); + } else if (config.project_view_type == PROJECT_VIEW_ICON) { + icon_view->setRootIndex(hierarchy); + set_up_dir_enabled(); } - // select item - tree_view->selectionModel()->select(sorted_index, QItemSelectionModel::Select); - return true; } } @@ -755,7 +754,7 @@ void Project::import_dialog() { if (fd.exec()) { QStringList files = fd.selectedFiles(); - process_file_list(files, false, NULL, get_selected_folder()); + process_file_list(files, false, NULL, get_selected_folder()); } } @@ -763,30 +762,30 @@ void Project::delete_clips_using_selected_media() { if (sequence == NULL) { QMessageBox::critical(this, "No active sequence", "No sequence is active, please open the sequence you want to delete clips from.", QMessageBox::Ok); } else { - ComboAction* ca = new ComboAction(); + ComboAction* ca = new ComboAction(); bool deleted = false; - QModelIndexList items = tree_view->selectionModel()->selectedRows(); - for (int i=0;iclips.size();i++) { - Clip* c = sequence->clips.at(i); + QModelIndexList items = get_current_selected(); + for (int i=0;iclips.size();i++) { + Clip* c = sequence->clips.at(i); if (c != NULL) { for (int j=0;jmedia == m) { - ca->append(new DeleteClipAction(sequence, i)); + ca->append(new DeleteClipAction(sequence, i)); deleted = true; } } } } for (int j=0;jclear_effects(true); - // delete sequences first because it's important to close all the clips before deleting the media - QVector sequences = list_all_project_sequences(); - for (int i=0;ito_sequence(); - sequences.at(i)->set_sequence(NULL); - } + // delete sequences first because it's important to close all the clips before deleting the media + QVector sequences = list_all_project_sequences(); + for (int i=0;ito_sequence(); + sequences.at(i)->set_sequence(NULL); + } - // delete everything else - project_model.clear(); + // delete everything else + project_model.clear(); } void Project::new_project() { // clear existing project - set_sequence(NULL); - panel_footage_viewer->set_media(NULL); - clear(); + set_sequence(NULL); + panel_footage_viewer->set_media(NULL); + clear(); mainWindow->setWindowModified(false); } void Project::load_project(bool autorecovery) { - new_project(); + new_project(); - LoadDialog ld(this, autorecovery); - ld.exec(); + LoadDialog ld(this, autorecovery); + ld.exec(); } void Project::save_folder(QXmlStreamWriter& stream, int type, bool set_ids_only, const QModelIndex& parent) { - bool root = (!parent.parent().isValid()); - for (int i=0;iget_type()) { - if (m->get_type() == MEDIA_TYPE_FOLDER) { - if (set_ids_only) { - m->temp_id = folder_id; // saves a temporary ID for matching in the project file - folder_id++; - } else { - // if we're saving folders, save the folder - stream.writeStartElement("folder"); - stream.writeAttribute("name", m->get_name()); - stream.writeAttribute("id", QString::number(m->temp_id)); - if (!item.parent().isValid()) { - stream.writeAttribute("parent", "0"); - } else { - stream.writeAttribute("parent", QString::number(project_model.getItem(item.parent())->temp_id)); - } - stream.writeEndElement(); - } + if (type == m->get_type()) { + if (m->get_type() == MEDIA_TYPE_FOLDER) { + if (set_ids_only) { + m->temp_id = folder_id; // saves a temporary ID for matching in the project file + folder_id++; + } else { + // if we're saving folders, save the folder + stream.writeStartElement("folder"); + stream.writeAttribute("name", m->get_name()); + stream.writeAttribute("id", QString::number(m->temp_id)); + if (!item.parent().isValid()) { + stream.writeAttribute("parent", "0"); + } else { + stream.writeAttribute("parent", QString::number(project_model.getItem(item.parent())->temp_id)); + } + stream.writeEndElement(); + } // save_folder(stream, item, type, set_ids_only); - } else { - int folder = root ? 0 : project_model.getItem(parent)->temp_id; - if (type == MEDIA_TYPE_FOOTAGE) { - Footage* f = m->to_footage(); - f->save_id = media_id; - stream.writeStartElement("footage"); - stream.writeAttribute("id", QString::number(media_id)); - stream.writeAttribute("folder", QString::number(folder)); - stream.writeAttribute("name", f->name); - stream.writeAttribute("url", proj_dir.relativeFilePath(f->url)); - stream.writeAttribute("duration", QString::number(f->length)); - stream.writeAttribute("using_inout", QString::number(f->using_inout)); - stream.writeAttribute("in", QString::number(f->in)); - stream.writeAttribute("out", QString::number(f->out)); - for (int j=0;jvideo_tracks.size();j++) { - FootageStream* ms = f->video_tracks.at(j); - stream.writeStartElement("video"); - stream.writeAttribute("id", QString::number(ms->file_index)); - stream.writeAttribute("width", QString::number(ms->video_width)); - stream.writeAttribute("height", QString::number(ms->video_height)); + } else { + int folder = root ? 0 : project_model.getItem(parent)->temp_id; + if (type == MEDIA_TYPE_FOOTAGE) { + Footage* f = m->to_footage(); + f->save_id = media_id; + stream.writeStartElement("footage"); + stream.writeAttribute("id", QString::number(media_id)); + stream.writeAttribute("folder", QString::number(folder)); + stream.writeAttribute("name", f->name); + stream.writeAttribute("url", proj_dir.relativeFilePath(f->url)); + stream.writeAttribute("duration", QString::number(f->length)); + stream.writeAttribute("using_inout", QString::number(f->using_inout)); + stream.writeAttribute("in", QString::number(f->in)); + stream.writeAttribute("out", QString::number(f->out)); + for (int j=0;jvideo_tracks.size();j++) { + FootageStream* ms = f->video_tracks.at(j); + stream.writeStartElement("video"); + stream.writeAttribute("id", QString::number(ms->file_index)); + stream.writeAttribute("width", QString::number(ms->video_width)); + stream.writeAttribute("height", QString::number(ms->video_height)); stream.writeAttribute("framerate", QString::number(ms->video_frame_rate, 'f', 10)); - stream.writeAttribute("infinite", QString::number(ms->infinite_length)); - stream.writeEndElement(); - } - for (int j=0;jaudio_tracks.size();j++) { - FootageStream* ms = f->audio_tracks.at(j); - stream.writeStartElement("audio"); - stream.writeAttribute("id", QString::number(ms->file_index)); - stream.writeAttribute("channels", QString::number(ms->audio_channels)); - stream.writeAttribute("layout", QString::number(ms->audio_layout)); - stream.writeAttribute("frequency", QString::number(ms->audio_frequency)); - stream.writeEndElement(); - } - stream.writeEndElement(); - media_id++; - } else if (type == MEDIA_TYPE_SEQUENCE) { - Sequence* s = m->to_sequence(); - if (set_ids_only) { - s->save_id = sequence_id; - sequence_id++; - } else { - stream.writeStartElement("sequence"); - stream.writeAttribute("id", QString::number(s->save_id)); - stream.writeAttribute("folder", QString::number(folder)); - stream.writeAttribute("name", s->name); - stream.writeAttribute("width", QString::number(s->width)); - stream.writeAttribute("height", QString::number(s->height)); + stream.writeAttribute("infinite", QString::number(ms->infinite_length)); + stream.writeEndElement(); + } + for (int j=0;jaudio_tracks.size();j++) { + FootageStream* ms = f->audio_tracks.at(j); + stream.writeStartElement("audio"); + stream.writeAttribute("id", QString::number(ms->file_index)); + stream.writeAttribute("channels", QString::number(ms->audio_channels)); + stream.writeAttribute("layout", QString::number(ms->audio_layout)); + stream.writeAttribute("frequency", QString::number(ms->audio_frequency)); + stream.writeEndElement(); + } + stream.writeEndElement(); + media_id++; + } else if (type == MEDIA_TYPE_SEQUENCE) { + Sequence* s = m->to_sequence(); + if (set_ids_only) { + s->save_id = sequence_id; + sequence_id++; + } else { + stream.writeStartElement("sequence"); + stream.writeAttribute("id", QString::number(s->save_id)); + stream.writeAttribute("folder", QString::number(folder)); + stream.writeAttribute("name", s->name); + stream.writeAttribute("width", QString::number(s->width)); + stream.writeAttribute("height", QString::number(s->height)); stream.writeAttribute("framerate", QString::number(s->frame_rate, 'f', 10)); - stream.writeAttribute("afreq", QString::number(s->audio_frequency)); - stream.writeAttribute("alayout", QString::number(s->audio_layout)); - if (s == sequence) { - stream.writeAttribute("open", "1"); + stream.writeAttribute("afreq", QString::number(s->audio_frequency)); + stream.writeAttribute("alayout", QString::number(s->audio_layout)); + if (s == sequence) { + stream.writeAttribute("open", "1"); } stream.writeAttribute("workarea", QString::number(s->using_workarea)); stream.writeAttribute("workareaIn", QString::number(s->workarea_in)); stream.writeAttribute("workareaOut", QString::number(s->workarea_out)); - for (int j=0;jtransitions.size();j++) { - Transition* t = s->transitions.at(j); - if (t != NULL) { - stream.writeStartElement("transition"); - stream.writeAttribute("id", QString::number(j)); - stream.writeAttribute("length", QString::number(t->get_true_length())); - t->save(stream); - stream.writeEndElement(); // transition - } - } + for (int j=0;jtransitions.size();j++) { + Transition* t = s->transitions.at(j); + if (t != NULL) { + stream.writeStartElement("transition"); + stream.writeAttribute("id", QString::number(j)); + stream.writeAttribute("length", QString::number(t->get_true_length())); + t->save(stream); + stream.writeEndElement(); // transition + } + } - for (int j=0;jclips.size();j++) { - Clip* c = s->clips.at(j); - if (c != NULL) { - stream.writeStartElement("clip"); // clip - stream.writeAttribute("id", QString::number(j)); + for (int j=0;jclips.size();j++) { + Clip* c = s->clips.at(j); + if (c != NULL) { + stream.writeStartElement("clip"); // clip + stream.writeAttribute("id", QString::number(j)); stream.writeAttribute("enabled", QString::number(c->enabled)); - stream.writeAttribute("name", c->name); - stream.writeAttribute("clipin", QString::number(c->clip_in)); - stream.writeAttribute("in", QString::number(c->timeline_in)); - stream.writeAttribute("out", QString::number(c->timeline_out)); - stream.writeAttribute("track", QString::number(c->track)); - stream.writeAttribute("opening", QString::number(c->opening_transition)); - stream.writeAttribute("closing", QString::number(c->closing_transition)); + stream.writeAttribute("name", c->name); + stream.writeAttribute("clipin", QString::number(c->clip_in)); + stream.writeAttribute("in", QString::number(c->timeline_in)); + stream.writeAttribute("out", QString::number(c->timeline_out)); + stream.writeAttribute("track", QString::number(c->track)); + stream.writeAttribute("opening", QString::number(c->opening_transition)); + stream.writeAttribute("closing", QString::number(c->closing_transition)); - stream.writeAttribute("r", QString::number(c->color_r)); - stream.writeAttribute("g", QString::number(c->color_g)); - stream.writeAttribute("b", QString::number(c->color_b)); + stream.writeAttribute("r", QString::number(c->color_r)); + stream.writeAttribute("g", QString::number(c->color_g)); + stream.writeAttribute("b", QString::number(c->color_b)); - stream.writeAttribute("autoscale", QString::number(c->autoscale)); + stream.writeAttribute("autoscale", QString::number(c->autoscale)); stream.writeAttribute("speed", QString::number(c->speed, 'f', 10)); - stream.writeAttribute("maintainpitch", QString::number(c->maintain_audio_pitch)); - stream.writeAttribute("reverse", QString::number(c->reverse)); + stream.writeAttribute("maintainpitch", QString::number(c->maintain_audio_pitch)); + stream.writeAttribute("reverse", QString::number(c->reverse)); if (c->media != NULL) { stream.writeAttribute("type", QString::number(c->media->get_type())); @@ -949,186 +948,193 @@ void Project::save_folder(QXmlStreamWriter& stream, int type, bool set_ids_only, } } - stream.writeStartElement("linked"); // linked - for (int k=0;klinked.size();k++) { - stream.writeStartElement("link"); // link - stream.writeAttribute("id", QString::number(c->linked.at(k))); - stream.writeEndElement(); // link - } - stream.writeEndElement(); // linked + stream.writeStartElement("linked"); // linked + for (int k=0;klinked.size();k++) { + stream.writeStartElement("link"); // link + stream.writeAttribute("id", QString::number(c->linked.at(k))); + stream.writeEndElement(); // link + } + stream.writeEndElement(); // linked - for (int k=0;keffects.size();k++) { + for (int k=0;keffects.size();k++) { stream.writeStartElement("effect"); // effect c->effects.at(k)->save(stream); stream.writeEndElement(); // effect - } + } - stream.writeEndElement(); // clip - } - } + stream.writeEndElement(); // clip + } + } for (int j=0;jmarkers.size();j++) { stream.writeStartElement("marker"); stream.writeAttribute("frame", QString::number(s->markers.at(j).frame)); stream.writeAttribute("name", s->markers.at(j).name); stream.writeEndElement(); } - stream.writeEndElement(); - } - } - } - } - - if (m->get_type() == MEDIA_TYPE_FOLDER) { - save_folder(stream, type, set_ids_only, item); + stream.writeEndElement(); + } + } + } } - } + + if (m->get_type() == MEDIA_TYPE_FOLDER) { + save_folder(stream, type, set_ids_only, item); + } + } } void Project::save_project(bool autorecovery) { - folder_id = 1; - media_id = 1; - sequence_id = 1; + folder_id = 1; + media_id = 1; + sequence_id = 1; - QFile file(autorecovery ? autorecovery_filename : project_url); - if (!file.open(QIODevice::WriteOnly/* | QIODevice::Text*/)) { + QFile file(autorecovery ? autorecovery_filename : project_url); + if (!file.open(QIODevice::WriteOnly/* | QIODevice::Text*/)) { dout << "[ERROR] Could not open file"; - return; - } + return; + } - QXmlStreamWriter stream(&file); - stream.setAutoFormatting(true); - stream.writeStartDocument(); // doc + QXmlStreamWriter stream(&file); + stream.setAutoFormatting(true); + stream.writeStartDocument(); // doc - stream.writeStartElement("project"); // project + stream.writeStartElement("project"); // project stream.writeTextElement("version", QString::number(SAVE_VERSION)); - stream.writeTextElement("url", project_url); - proj_dir = QFileInfo(project_url).absoluteDir(); + stream.writeTextElement("url", project_url); + proj_dir = QFileInfo(project_url).absoluteDir(); - save_folder(stream, MEDIA_TYPE_FOLDER, true); + save_folder(stream, MEDIA_TYPE_FOLDER, true); - stream.writeStartElement("folders"); // folders - save_folder(stream, MEDIA_TYPE_FOLDER, false); - stream.writeEndElement(); // folders + stream.writeStartElement("folders"); // folders + save_folder(stream, MEDIA_TYPE_FOLDER, false); + stream.writeEndElement(); // folders - stream.writeStartElement("media"); // media - save_folder(stream, MEDIA_TYPE_FOOTAGE, false); - stream.writeEndElement(); // media + stream.writeStartElement("media"); // media + save_folder(stream, MEDIA_TYPE_FOOTAGE, false); + stream.writeEndElement(); // media - save_folder(stream, MEDIA_TYPE_SEQUENCE, true); + save_folder(stream, MEDIA_TYPE_SEQUENCE, true); - stream.writeStartElement("sequences"); // sequences - save_folder(stream, MEDIA_TYPE_SEQUENCE, false); - stream.writeEndElement();// sequences + stream.writeStartElement("sequences"); // sequences + save_folder(stream, MEDIA_TYPE_SEQUENCE, false); + stream.writeEndElement();// sequences - stream.writeEndElement(); // project + stream.writeEndElement(); // project - stream.writeEndDocument(); // doc + stream.writeEndDocument(); // doc - file.close(); + file.close(); - if (!autorecovery) { - add_recent_project(project_url); + if (!autorecovery) { + add_recent_project(project_url); mainWindow->setWindowModified(false); - } + } } void Project::update_view_type() { - tree_view->setVisible(config.project_view_type == PROJECT_VIEW_TREE); - icon_view_container->setVisible(config.project_view_type == PROJECT_VIEW_ICON); + tree_view->setVisible(config.project_view_type == PROJECT_VIEW_TREE); + icon_view_container->setVisible(config.project_view_type == PROJECT_VIEW_ICON); - switch (config.project_view_type) { - case PROJECT_VIEW_TREE: - sources_common->view = tree_view; - break; - case PROJECT_VIEW_ICON: - sources_common->view = icon_view; - break; - } + switch (config.project_view_type) { + case PROJECT_VIEW_TREE: + sources_common->view = tree_view; + break; + case PROJECT_VIEW_ICON: + sources_common->view = icon_view; + break; + } } void Project::set_icon_view() { - config.project_view_type = PROJECT_VIEW_ICON; - update_view_type(); + config.project_view_type = PROJECT_VIEW_ICON; + update_view_type(); } void Project::set_tree_view() { - config.project_view_type = PROJECT_VIEW_TREE; - update_view_type(); + config.project_view_type = PROJECT_VIEW_TREE; + update_view_type(); } void Project::save_recent_projects() { - // save to file - QFile f(recent_proj_file); - if (f.open(QFile::WriteOnly | QFile::Truncate | QFile::Text)) { - QTextStream out(&f); - for (int i=0;i 0) { - out << "\n"; - } - out << recent_projects.at(i); - } - f.close(); - } else { + // save to file + QFile f(recent_proj_file); + if (f.open(QFile::WriteOnly | QFile::Truncate | QFile::Text)) { + QTextStream out(&f); + for (int i=0;i 0) { + out << "\n"; + } + out << recent_projects.at(i); + } + f.close(); + } else { dout << "[WARNING] Could not save recent projects"; - } + } } void Project::clear_recent_projects() { - recent_projects.clear(); - save_recent_projects(); + recent_projects.clear(); + save_recent_projects(); } void Project::set_icon_view_size(int s) { - icon_view->setIconSize(QSize(s, s)); + icon_view->setIconSize(QSize(s, s)); } void Project::set_up_dir_enabled() { - directory_up->setEnabled(icon_view->rootIndex().isValid()); + directory_up->setEnabled(icon_view->rootIndex().isValid()); } void Project::go_up_dir() { - icon_view->setRootIndex(icon_view->rootIndex().parent()); - set_up_dir_enabled(); + icon_view->setRootIndex(icon_view->rootIndex().parent()); + set_up_dir_enabled(); } void Project::add_recent_project(QString url) { - bool found = false; - for (int i=0;i MAXIMUM_RECENT_PROJECTS) { - recent_projects.removeLast(); - } - } - save_recent_projects(); + bool found = false; + for (int i=0;i MAXIMUM_RECENT_PROJECTS) { + recent_projects.removeLast(); + } + } + save_recent_projects(); } void Project::list_all_sequences_worker(QVector* list, Media* parent) { - for (int i=0;iget_type()) { - case MEDIA_TYPE_SEQUENCE: - list->append(item); - break; - case MEDIA_TYPE_FOLDER: - list_all_sequences_worker(list, item); - break; - } - } + for (int i=0;iget_type()) { + case MEDIA_TYPE_SEQUENCE: + list->append(item); + break; + case MEDIA_TYPE_FOLDER: + list_all_sequences_worker(list, item); + break; + } + } } QVector Project::list_all_project_sequences() { - QVector list; - list_all_sequences_worker(&list, NULL); - return list; + QVector list; + list_all_sequences_worker(&list, NULL); + return list; +} + +QModelIndexList Project::get_current_selected() { + if (config.project_view_type == PROJECT_VIEW_TREE) { + return panel_project->tree_view->selectionModel()->selectedRows(); + } + return panel_project->icon_view->selectionModel()->selectedIndexes(); } #define THROBBER_LIMIT 20 @@ -1137,51 +1143,51 @@ QVector Project::list_all_project_sequences() { MediaThrobber::MediaThrobber(Media *i) : pixmap(":/icons/throbber.png"), animation(0), item(i), animator(NULL) {} void MediaThrobber::start() { - // set up throbber - animation_update(); - animator = new QTimer(this); - animator->setInterval(20); - connect(animator, SIGNAL(timeout()), this, SLOT(animation_update())); - animator->start(); + // set up throbber + animation_update(); + animator = new QTimer(this); + animator->setInterval(20); + connect(animator, SIGNAL(timeout()), this, SLOT(animation_update())); + animator->start(); } void MediaThrobber::animation_update() { - if (animation == THROBBER_LIMIT) { - animation = 0; - } - project_model.set_icon(item, QIcon(pixmap.copy(THROBBER_SIZE*animation, 0, THROBBER_SIZE, THROBBER_SIZE))); + if (animation == THROBBER_LIMIT) { + animation = 0; + } + project_model.set_icon(item, QIcon(pixmap.copy(THROBBER_SIZE*animation, 0, THROBBER_SIZE, THROBBER_SIZE))); animation++; } void MediaThrobber::stop(int icon_type, bool replace) { - if (animator != NULL) { - animator->stop(); - delete animator; - } - - switch (icon_type) { - case ICON_TYPE_VIDEO: project_model.set_icon(item, QIcon(":/icons/videosource.png")); break; - case ICON_TYPE_AUDIO: project_model.set_icon(item, QIcon(":/icons/audiosource.png")); break; - case ICON_TYPE_IMAGE: project_model.set_icon(item, QIcon(":/icons/imagesource.png")); break; - case ICON_TYPE_ERROR: project_model.set_icon(item, QIcon(":/icons/error.png")); break; - } - - // refresh all clips - QVector sequences = panel_project->list_all_project_sequences(); - for (int i=0;ito_sequence(); - for (int j=0;jclips.size();j++) { - Clip* c = s->clips.at(j); - if (c != NULL) { - c->refresh(); - } - } + if (animator != NULL) { + animator->stop(); + delete animator; } - // redraw clips + switch (icon_type) { + case ICON_TYPE_VIDEO: project_model.set_icon(item, QIcon(":/icons/videosource.png")); break; + case ICON_TYPE_AUDIO: project_model.set_icon(item, QIcon(":/icons/audiosource.png")); break; + case ICON_TYPE_IMAGE: project_model.set_icon(item, QIcon(":/icons/imagesource.png")); break; + case ICON_TYPE_ERROR: project_model.set_icon(item, QIcon(":/icons/error.png")); break; + } + + // refresh all clips + QVector sequences = panel_project->list_all_project_sequences(); + for (int i=0;ito_sequence(); + for (int j=0;jclips.size();j++) { + Clip* c = s->clips.at(j); + if (c != NULL) { + c->refresh(); + } + } + } + + // redraw clips update_ui(replace); - panel_project->tree_view->viewport()->update(); - item->throbber = NULL; - deleteLater(); + panel_project->tree_view->viewport()->update(); + item->throbber = NULL; + deleteLater(); } diff --git a/panels/project.h b/panels/project.h index 71fdd0137..6516ff39e 100644 --- a/panels/project.h +++ b/panels/project.h @@ -48,81 +48,81 @@ class Project : public QDockWidget { public: explicit Project(QWidget *parent = 0); ~Project(); - bool is_focused(); + bool is_focused(); void clear(); - Media* new_sequence(ComboAction *ca, Sequence* s, bool open, Media* parent); - QString get_next_sequence_name(QString start = 0); - void process_file_list(QStringList& files, bool recursive = false, Media* replace = NULL, Media *parent = NULL); - void replace_media(Media* item, QString filename); - Media *get_selected_folder(); - bool reveal_media(Media *media, QModelIndex parent = QModelIndex()); - void add_recent_project(QString url); + Media* new_sequence(ComboAction *ca, Sequence* s, bool open, Media* parent); + QString get_next_sequence_name(QString start = 0); + void process_file_list(QStringList& files, bool recursive = false, Media* replace = NULL, Media *parent = NULL); + void replace_media(Media* item, QString filename); + Media *get_selected_folder(); + bool reveal_media(Media *media, QModelIndex parent = QModelIndex()); + void add_recent_project(QString url); - void new_project(); - void load_project(bool autorecovery); - void save_project(bool autorecovery); + void new_project(); + void load_project(bool autorecovery); + void save_project(bool autorecovery); - Media* new_folder(QString name); - Media* item_to_media(const QModelIndex& index); + Media* new_folder(QString name); + Media* item_to_media(const QModelIndex& index); - void save_recent_projects(); + void save_recent_projects(); - QVector list_all_project_sequences(); + QVector list_all_project_sequences(); - SourceTable* tree_view; - SourceIconView* icon_view; - SourcesCommon* sources_common; + SourceTable* tree_view; + SourceIconView* icon_view; + SourcesCommon* sources_common; - QSortFilterProxyModel* sorter; + QSortFilterProxyModel* sorter; - QVector last_imported_media; + QVector last_imported_media; - //Media *new_item(); + QModelIndexList get_current_selected(); void start_preview_generator(Media* item, bool replacing); public slots: void import_dialog(); - void delete_selected_media(); - void duplicate_selected(); + void delete_selected_media(); + void duplicate_selected(); void delete_clips_using_selected_media(); void replace_selected_file(); void replace_clip_media(); void open_properties(); private: - void save_folder(QXmlStreamWriter& stream, int type, bool set_ids_only, const QModelIndex &parent = QModelIndex()); - int folder_id; - int media_id; - int sequence_id; - void get_all_media_from_table(QList items, QList &list, int type); - void list_all_sequences_worker(QVector *list, Media* parent); + void save_folder(QXmlStreamWriter& stream, int type, bool set_ids_only, const QModelIndex &parent = QModelIndex()); + int folder_id; + int media_id; + int sequence_id; + void get_all_media_from_table(QList items, QList &list, int type); + void list_all_sequences_worker(QVector *list, Media* parent); QString get_file_name_from_path(const QString &path); - QDir proj_dir; - QWidget* icon_view_container; - QPushButton* directory_up; + QDir proj_dir; + QWidget* icon_view_container; + QPushButton* directory_up; private slots: - void update_view_type(); - void set_icon_view(); - void set_tree_view(); + void update_view_type(); + void set_icon_view(); + void set_tree_view(); void clear_recent_projects(); - void set_icon_view_size(int); - void set_up_dir_enabled(); - void go_up_dir(); + void set_icon_view_size(int); + void set_up_dir_enabled(); + void go_up_dir(); }; class MediaThrobber : public QObject { - Q_OBJECT + Q_OBJECT public: - MediaThrobber(Media*); + MediaThrobber(Media*); public slots: - void start(); + void start(); void stop(int, bool replace); private slots: - void animation_update(); + void animation_update(); private: - QPixmap pixmap; - int animation; - Media* item; - QTimer* animator; + QPixmap pixmap; + int animation; + Media* item; + QTimer* animator; }; #endif // PROJECT_H diff --git a/panels/timeline.h b/panels/timeline.h index d3ae3a7d1..0caf38d8b 100644 --- a/panels/timeline.h +++ b/panels/timeline.h @@ -38,7 +38,7 @@ bool selection_contains_transition(const Selection& s, Clip* c, int type); void move_clip(ComboAction *ca, Clip *c, long iin, long iout, long iclip_in, int itrack, bool verify_transitions = true); struct Ghost { - int clip; + int clip; long in; long out; int track; @@ -50,17 +50,17 @@ struct Ghost { long old_clip_in; // importing variables - Media* media; - int media_stream; + Media* media; + int media_stream; // other variables long ghost_length; long media_length; - bool trim_in; - bool trimming; + bool trim_in; + bool trimming; // transition trimming - Transition* transition; + Transition* transition; }; namespace Ui { @@ -74,35 +74,31 @@ public: explicit Timeline(QWidget *parent = 0); ~Timeline(); - bool focused(); - void set_zoom(bool in); - void copy(bool del); - void paste(bool insert); - void deselect(); - Clip* split_clip(ComboAction* ca, int p, long frame); - Clip* split_clip(ComboAction* ca, int p, long frame, long post_in); - bool split_selection(ComboAction* ca); - void split_at_playhead(); - bool split_all_clips_at_point(ComboAction *ca, long point); - bool split_clip_and_relink(ComboAction* ca, int clip, long frame, bool relink); - void clean_up_selections(QVector& areas); + bool focused(); + void set_zoom(bool in); + void copy(bool del); + void paste(bool insert); + Clip* split_clip(ComboAction* ca, int p, long frame); + Clip* split_clip(ComboAction* ca, int p, long frame, long post_in); + bool split_selection(ComboAction* ca); + bool split_all_clips_at_point(ComboAction *ca, long point); + bool split_clip_and_relink(ComboAction* ca, int clip, long frame, bool relink); + void clean_up_selections(QVector& areas); void deselect_area(long in, long out, int track); - void delete_areas_and_relink(ComboAction *ca, QVector& areas); - void relink_clips_using_ids(QVector& old_clips, QVector& new_clips); - void update_sequence(); - void increase_track_height(); - void decrease_track_height(); - void add_transition(); - QVector get_tracks_of_linked_clips(int i); - bool has_clip_been_split(int c); - void toggle_links(); + void delete_areas_and_relink(ComboAction *ca, QVector& areas); + void relink_clips_using_ids(QVector& old_clips, QVector& new_clips); + void update_sequence(); + void increase_track_height(); + void decrease_track_height(); + void add_transition(); + QVector get_tracks_of_linked_clips(int i); + bool has_clip_been_split(int c); void ripple_to_in_point(bool in, bool ripple); - void delete_in_out(bool ripple); + void delete_in_out(bool ripple); void previous_cut(); void next_cut(); - void toggle_show_all(); - void create_ghosts_from_media(Sequence *seq, long entry_point, QVector &media_list); + void create_ghosts_from_media(Sequence *seq, long entry_point, QVector &media_list); void add_clips_from_ghosts(ComboAction *ca, Sequence *s); int getTimelineScreenPointFromFrame(long frame); @@ -111,114 +107,118 @@ public: long getDisplayFrameFromScreenPoint(int x); int get_snap_range(); - bool snap_to_point(long point, long* l); + bool snap_to_point(long point, long* l); bool snap_to_timeline(long* l, bool use_playhead, bool use_markers, bool use_workarea); void set_marker(); - // shared information + // shared information int tool; - long cursor_frame; - int cursor_track; - double zoom; - bool zoom_just_changed; + long cursor_frame; + int cursor_track; + double zoom; + bool zoom_just_changed; long drag_frame_start; int drag_track_start; void update_effect_controls(); bool showing_all; double old_zoom; - QVector video_track_heights; - QVector audio_track_heights; - int get_track_height_size(bool video); - int calculate_track_height(int track, int height); + QVector video_track_heights; + QVector audio_track_heights; + int get_track_height_size(bool video); + int calculate_track_height(int track, int height); - // snapping - bool snapping; - bool snapped; - long snap_point; + // snapping + bool snapping; + bool snapped; + long snap_point; // selecting functions bool selecting; - int selection_offset; - bool is_clip_selected(Clip* clip, bool containing); + int selection_offset; + bool is_clip_selected(Clip* clip, bool containing); void delete_selection(QVector &selections, bool ripple); void select_all(); - bool rect_select_init; - bool rect_select_proc; - int rect_select_x; - int rect_select_y; - int rect_select_w; - int rect_select_h; + bool rect_select_init; + bool rect_select_proc; + int rect_select_x; + int rect_select_y; + int rect_select_w; + int rect_select_h; // moving bool moving_init; bool moving_proc; - QVector ghosts; - bool video_ghosts; - bool audio_ghosts; + QVector ghosts; + bool video_ghosts; + bool audio_ghosts; bool move_insert; // trimming int trim_target; - bool trim_in_point; + bool trim_in_point; int transition_select; // splitting bool splitting; - QVector split_tracks; - QVector split_cache; + QVector split_tracks; + QVector split_cache; // importing - bool importing; + bool importing; bool importing_files; // creating variables bool creating; int creating_object; - // transition variables - bool transition_tool_init; - bool transition_tool_proc; - int transition_tool_pre_clip; - int transition_tool_post_clip; - int transition_tool_type; + // transition variables + bool transition_tool_init; + bool transition_tool_proc; + int transition_tool_pre_clip; + int transition_tool_post_clip; + int transition_tool_type; const EffectMeta* transition_tool_meta; int transition_tool_side; - // hand tool variables - bool hand_moving; - int drag_x_start; - int drag_y_start; + // hand tool variables + bool hand_moving; + int drag_x_start; + int drag_y_start; - bool block_repaints; + bool block_repaints; - Ui::Timeline *ui; + Ui::Timeline *ui; - void resizeEvent(QResizeEvent *event); + void resizeEvent(QResizeEvent *event); public slots: void repaint_timeline(); + void toggle_show_all(); + void deselect(); + void toggle_links(); + void split_at_playhead(); private slots: void on_pushButton_4_clicked(); - void on_pushButton_5_clicked(); + void on_pushButton_5_clicked(); - void on_snappingButton_toggled(bool checked); + void on_snappingButton_toggled(bool checked); - void on_toolSlideButton_clicked(); + void on_toolSlideButton_clicked(); - void on_toolArrowButton_clicked(); + void on_toolArrowButton_clicked(); - void on_toolEditButton_clicked(); + void on_toolEditButton_clicked(); - void on_toolRippleButton_clicked(); + void on_toolRippleButton_clicked(); - void on_toolRollingButton_clicked(); + void on_toolRollingButton_clicked(); - void on_toolRazorButton_clicked(); + void on_toolRazorButton_clicked(); - void on_toolSlipButton_clicked(); + void on_toolSlipButton_clicked(); void on_addButton_clicked(); @@ -232,18 +232,18 @@ private slots: void transition_menu_select(QAction*); - void resize_move(double d); + void resize_move(double d); - void on_toolHandButton_clicked(); + void on_toolHandButton_clicked(); private: void set_zoom_value(double v); QVector tool_buttons; void decheck_tool_buttons(QObject* sender); - void set_tool(int tool); + void set_tool(int tool); long last_frame; - int scroll; - void set_sb_max(); + int scroll; + void set_sb_max(); int default_track_height; }; diff --git a/project/projectmodel.cpp b/project/projectmodel.cpp index 6452b623d..4105e5a54 100644 --- a/project/projectmodel.cpp +++ b/project/projectmodel.cpp @@ -7,172 +7,176 @@ #include "debug.h" ProjectModel::ProjectModel(QObject *parent) : QAbstractItemModel(parent), root_item(NULL) { - root_item = new Media(0); - root_item->root = true; + root_item = new Media(0); + root_item->root = true; } -ProjectModel::~ProjectModel() { - destroy_root(); +ProjectModel::~ProjectModel() { + destroy_root(); } void ProjectModel::destroy_root() { - if (panel_sequence_viewer != NULL) panel_sequence_viewer->viewer_widget->delete_function(); - if (panel_footage_viewer != NULL) panel_footage_viewer->viewer_widget->delete_function(); + if (panel_sequence_viewer != NULL) panel_sequence_viewer->viewer_widget->delete_function(); + if (panel_footage_viewer != NULL) panel_footage_viewer->viewer_widget->delete_function(); - if (root_item != NULL) { - delete root_item; - } + if (root_item != NULL) { + delete root_item; + } } void ProjectModel::clear() { - beginResetModel(); - destroy_root(); - root_item = new Media(0); - root_item->root = true; - endResetModel(); + beginResetModel(); + destroy_root(); + root_item = new Media(0); + root_item->root = true; + endResetModel(); } Media *ProjectModel::get_root() { - return root_item; + return root_item; } QVariant ProjectModel::data(const QModelIndex &index, int role) const { - if (!index.isValid()) - return QVariant(); + if (!index.isValid()) + return QVariant(); - return static_cast(index.internalPointer())->data(index.column(), role); + return static_cast(index.internalPointer())->data(index.column(), role); } Qt::ItemFlags ProjectModel::flags(const QModelIndex &index) const { - if (!index.isValid()) - return Qt::ItemIsDropEnabled; + if (!index.isValid()) + return Qt::ItemIsDropEnabled; - return QAbstractItemModel::flags(index) | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | Qt::ItemIsEditable; + return QAbstractItemModel::flags(index) | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | Qt::ItemIsEditable; } QVariant ProjectModel::headerData(int section, Qt::Orientation orientation, int role) const { - if (orientation == Qt::Horizontal && role == Qt::DisplayRole) - return root_item->data(section, role); + if (orientation == Qt::Horizontal && role == Qt::DisplayRole) + return root_item->data(section, role); - return QVariant(); + return QVariant(); } QModelIndex ProjectModel::index(int row, int column, const QModelIndex &parent) const { - if (!hasIndex(row, column, parent)) - return QModelIndex(); + if (!hasIndex(row, column, parent)) + return QModelIndex(); - Media *parentItem; + Media *parentItem; - if (!parent.isValid()) - parentItem = root_item; - else - parentItem = static_cast(parent.internalPointer()); + if (!parent.isValid()) + parentItem = root_item; + else + parentItem = static_cast(parent.internalPointer()); - Media *childItem = parentItem->child(row); - if (childItem) - return createIndex(row, column, childItem); - else - return QModelIndex(); + Media *childItem = parentItem->child(row); + if (childItem) + return createIndex(row, column, childItem); + else + return QModelIndex(); +} + +QModelIndex ProjectModel::create_index(int arow, int acolumn, void* aid) { + return createIndex(arow, acolumn, aid); } QModelIndex ProjectModel::parent(const QModelIndex &index) const { - if (!index.isValid()) - return QModelIndex(); + if (!index.isValid()) + return QModelIndex(); - Media *childItem = static_cast(index.internalPointer()); - Media *parentItem = childItem->parentItem(); + Media *childItem = static_cast(index.internalPointer()); + Media *parentItem = childItem->parentItem(); - if (parentItem == root_item) - return QModelIndex(); + if (parentItem == root_item) + return QModelIndex(); - return createIndex(parentItem->row(), 0, parentItem); + return createIndex(parentItem->row(), 0, parentItem); } bool ProjectModel::setData(const QModelIndex &index, const QVariant &value, int role) { - if (role != Qt::EditRole) - return false; + if (role != Qt::EditRole) + return false; - Media *item = static_cast(index.internalPointer()); - bool result = item->setData(index.column(), value); + Media *item = static_cast(index.internalPointer()); + bool result = item->setData(index.column(), value); - if (result) - emit dataChanged(index, index); + if (result) + emit dataChanged(index, index); - return result; + return result; } int ProjectModel::rowCount(const QModelIndex &parent) const { - Media *parentItem; - if (parent.column() > 0) - return 0; + Media *parentItem; + if (parent.column() > 0) + return 0; - if (!parent.isValid()) { - parentItem = root_item; - } else { - parentItem = static_cast(parent.internalPointer()); - } + if (!parent.isValid()) { + parentItem = root_item; + } else { + parentItem = static_cast(parent.internalPointer()); + } - return parentItem->childCount(); + return parentItem->childCount(); } int ProjectModel::columnCount(const QModelIndex &parent) const { - if (parent.isValid()) - return static_cast(parent.internalPointer())->columnCount(); - else - return root_item->columnCount(); + if (parent.isValid()) + return static_cast(parent.internalPointer())->columnCount(); + else + return root_item->columnCount(); } Media *ProjectModel::getItem(const QModelIndex &index) const { - if (index.isValid()) { - Media *item = static_cast(index.internalPointer()); - if (item) - return item; - } - return root_item; + if (index.isValid()) { + Media *item = static_cast(index.internalPointer()); + if (item) + return item; + } + return root_item; } void ProjectModel::set_icon(Media* m, const QIcon &ico) { - QModelIndex index = createIndex(m->row(), 0, m); - m->set_icon(ico); - emit dataChanged(index, index); + QModelIndex index = createIndex(m->row(), 0, m); + m->set_icon(ico); + emit dataChanged(index, index); } void ProjectModel::appendChild(Media *parent, Media *child) { - if (parent == NULL) parent = root_item; - beginInsertRows(parent == root_item ? QModelIndex() : createIndex(parent->row(), 0, parent), parent->childCount(), parent->childCount()); - parent->appendChild(child); - endInsertRows(); + if (parent == NULL) parent = root_item; + beginInsertRows(parent == root_item ? QModelIndex() : createIndex(parent->row(), 0, parent), parent->childCount(), parent->childCount()); + parent->appendChild(child); + endInsertRows(); } void ProjectModel::moveChild(Media *child, Media *to) { - if (to == NULL) to = root_item; - Media* from = child->parentItem(); - beginMoveRows( - from == root_item ? QModelIndex() : createIndex(from->row(), 0, from), - child->row(), - child->row(), - to == root_item ? QModelIndex() : createIndex(to->row(), 0, to), - to->childCount() - ); - from->removeChild(child->row()); - to->appendChild(child); - endMoveRows(); + if (to == NULL) to = root_item; + Media* from = child->parentItem(); + beginMoveRows( + from == root_item ? QModelIndex() : createIndex(from->row(), 0, from), + child->row(), + child->row(), + to == root_item ? QModelIndex() : createIndex(to->row(), 0, to), + to->childCount() + ); + from->removeChild(child->row()); + to->appendChild(child); + endMoveRows(); } void ProjectModel::removeChild(Media* parent, Media* m) { - if (parent == NULL) parent = root_item; - beginRemoveRows(parent == root_item ? QModelIndex() : createIndex(parent->row(), 0, parent), m->row(), m->row()); - parent->removeChild(m->row()); - endRemoveRows(); + if (parent == NULL) parent = root_item; + beginRemoveRows(parent == root_item ? QModelIndex() : createIndex(parent->row(), 0, parent), m->row(), m->row()); + parent->removeChild(m->row()); + endRemoveRows(); } Media* ProjectModel::child(int i, Media* parent) { - if (parent == NULL) parent = root_item; - return parent->child(i); + if (parent == NULL) parent = root_item; + return parent->child(i); } int ProjectModel::childCount(Media *parent) { - if (parent == NULL) parent = root_item; - return parent->childCount(); + if (parent == NULL) parent = root_item; + return parent->childCount(); } diff --git a/project/projectmodel.h b/project/projectmodel.h index 42709b848..b37836f6b 100644 --- a/project/projectmodel.h +++ b/project/projectmodel.h @@ -7,35 +7,36 @@ class Media; class ProjectModel : public QAbstractItemModel { - Q_OBJECT + Q_OBJECT public: - ProjectModel(QObject* parent = 0); - ~ProjectModel() override; + ProjectModel(QObject* parent = 0); + ~ProjectModel() override; - void destroy_root(); - void clear(); - Media* get_root(); - QVariant data(const QModelIndex &index, int role) const override; - Qt::ItemFlags flags(const QModelIndex &index) const override; - QVariant headerData(int section, Qt::Orientation orientation, - int role = Qt::DisplayRole) const override; - QModelIndex index(int row, int column, - const QModelIndex &parent = QModelIndex()) const override; - QModelIndex parent(const QModelIndex &index) const override; - bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override; - int rowCount(const QModelIndex &parent = QModelIndex()) const override; - int columnCount(const QModelIndex &parent = QModelIndex()) const override; - Media *getItem(const QModelIndex &index) const; + void destroy_root(); + void clear(); + Media* get_root(); + QVariant data(const QModelIndex &index, int role) const override; + Qt::ItemFlags flags(const QModelIndex &index) const override; + QVariant headerData(int section, Qt::Orientation orientation, + int role = Qt::DisplayRole) const override; + QModelIndex index(int row, int column, + const QModelIndex &parent = QModelIndex()) const override; + QModelIndex create_index(int arow, int acolumn, void *aid); + QModelIndex parent(const QModelIndex &index) const override; + bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override; + int rowCount(const QModelIndex &parent = QModelIndex()) const override; + int columnCount(const QModelIndex &parent = QModelIndex()) const override; + Media *getItem(const QModelIndex &index) const; - void appendChild(Media* parent, Media* child); - void moveChild(Media *child, Media *to); - void removeChild(Media *parent, Media* m); - Media *child(int i, Media* parent = NULL); - int childCount(Media* parent = NULL); - void set_icon(Media* m, const QIcon &ico); + void appendChild(Media* parent, Media* child); + void moveChild(Media *child, Media *to); + void removeChild(Media *parent, Media* m); + Media *child(int i, Media* parent = NULL); + int childCount(Media* parent = NULL); + void set_icon(Media* m, const QIcon &ico); private: - Media* root_item; + Media* root_item; }; #endif // PROJECTMODEL_H diff --git a/project/sourcescommon.cpp b/project/sourcescommon.cpp index dd1bd3da2..366406e60 100644 --- a/project/sourcescommon.cpp +++ b/project/sourcescommon.cpp @@ -18,263 +18,263 @@ #include SourcesCommon::SourcesCommon(Project* parent) : - project_parent(parent), - editing_item(NULL) + project_parent(parent), + editing_item(NULL) { - rename_timer.setInterval(1000); - connect(&rename_timer, SIGNAL(timeout()), this, SLOT(rename_interval())); + rename_timer.setInterval(1000); + connect(&rename_timer, SIGNAL(timeout()), this, SLOT(rename_interval())); } void SourcesCommon::create_seq_from_selected() { - if (!selected_items.isEmpty()) { - QVector media_list; - for (int i=0;iitem_to_media(selected_items.at(i))); - } + if (!selected_items.isEmpty()) { + QVector media_list; + for (int i=0;iitem_to_media(selected_items.at(i))); + } - ComboAction* ca = new ComboAction(); - Sequence* s = create_sequence_from_media(media_list); + ComboAction* ca = new ComboAction(); + Sequence* s = create_sequence_from_media(media_list); - // add clips to it - panel_timeline->create_ghosts_from_media(s, 0, media_list); - panel_timeline->add_clips_from_ghosts(ca, s); + // add clips to it + panel_timeline->create_ghosts_from_media(s, 0, media_list); + panel_timeline->add_clips_from_ghosts(ca, s); - project_parent->new_sequence(ca, s, true, NULL); - undo_stack.push(ca); - } + project_parent->new_sequence(ca, s, true, NULL); + undo_stack.push(ca); + } } void SourcesCommon::show_context_menu(QWidget* parent, const QModelIndexList& items) { - QMenu menu(parent); + QMenu menu(parent); - selected_items = items; + selected_items = items; - QAction* import_action = menu.addAction("Import..."); - QObject::connect(import_action, SIGNAL(triggered(bool)), project_parent, SLOT(import_dialog())); + QAction* import_action = menu.addAction("Import..."); + QObject::connect(import_action, SIGNAL(triggered(bool)), project_parent, SLOT(import_dialog())); - QAction* new_folder_action = menu.addAction("New Folder..."); - QObject::connect(new_folder_action, SIGNAL(triggered(bool)), mainWindow, SLOT(on_actionFolder_triggered())); + QAction* new_folder_action = menu.addAction("New Folder..."); + QObject::connect(new_folder_action, SIGNAL(triggered(bool)), mainWindow, SLOT(new_folder())); - if (items.size() > 0) { - Media* m = project_parent->item_to_media(items.at(0)); + if (items.size() > 0) { + Media* m = project_parent->item_to_media(items.at(0)); - if (items.size() == 1) { - // replace footage - int type = m->get_type(); - if (type == MEDIA_TYPE_FOOTAGE) { - QAction* replace_action = menu.addAction("Replace/Relink Media"); - QObject::connect(replace_action, SIGNAL(triggered(bool)), project_parent, SLOT(replace_selected_file())); + if (items.size() == 1) { + // replace footage + int type = m->get_type(); + if (type == MEDIA_TYPE_FOOTAGE) { + QAction* replace_action = menu.addAction("Replace/Relink Media"); + QObject::connect(replace_action, SIGNAL(triggered(bool)), project_parent, SLOT(replace_selected_file())); #if defined(Q_OS_WIN) - QAction* reveal_in_explorer = menu.addAction("Reveal in Explorer"); + QAction* reveal_in_explorer = menu.addAction("Reveal in Explorer"); #elif defined(Q_OS_MAC) - QAction* reveal_in_explorer = menu.addAction("Reveal in Finder"); + QAction* reveal_in_explorer = menu.addAction("Reveal in Finder"); #else - QAction* reveal_in_explorer = menu.addAction("Reveal in File Manager"); + QAction* reveal_in_explorer = menu.addAction("Reveal in File Manager"); #endif - QObject::connect(reveal_in_explorer, SIGNAL(triggered(bool)), this, SLOT(reveal_in_browser())); - } - if (type != MEDIA_TYPE_FOLDER) { - QAction* replace_clip_media = menu.addAction("Replace Clips Using This Media"); - QObject::connect(replace_clip_media, SIGNAL(triggered(bool)), project_parent, SLOT(replace_clip_media())); - } - } + QObject::connect(reveal_in_explorer, SIGNAL(triggered(bool)), this, SLOT(reveal_in_browser())); + } + if (type != MEDIA_TYPE_FOLDER) { + QAction* replace_clip_media = menu.addAction("Replace Clips Using This Media"); + QObject::connect(replace_clip_media, SIGNAL(triggered(bool)), project_parent, SLOT(replace_clip_media())); + } + } - // duplicate item - bool all_sequences = true; - bool all_footage = true; - for (int i=0;iget_type() != MEDIA_TYPE_SEQUENCE) { - all_sequences = false; - } - if (m->get_type() != MEDIA_TYPE_FOOTAGE) { - all_footage = false; - } - } + // duplicate item + bool all_sequences = true; + bool all_footage = true; + for (int i=0;iget_type() != MEDIA_TYPE_SEQUENCE) { + all_sequences = false; + } + if (m->get_type() != MEDIA_TYPE_FOOTAGE) { + all_footage = false; + } + } - // create sequence from - QAction* create_seq_from = menu.addAction("Create Sequence With This Media"); - QObject::connect(create_seq_from, SIGNAL(triggered(bool)), this, SLOT(create_seq_from_selected())); + // create sequence from + QAction* create_seq_from = menu.addAction("Create Sequence With This Media"); + QObject::connect(create_seq_from, SIGNAL(triggered(bool)), this, SLOT(create_seq_from_selected())); - // ONLY sequences are selected - if (all_sequences) { - // ONLY sequences are selected - QAction* duplicate_action = menu.addAction("Duplicate"); - QObject::connect(duplicate_action, SIGNAL(triggered(bool)), project_parent, SLOT(duplicate_selected())); - } + // ONLY sequences are selected + if (all_sequences) { + // ONLY sequences are selected + QAction* duplicate_action = menu.addAction("Duplicate"); + QObject::connect(duplicate_action, SIGNAL(triggered(bool)), project_parent, SLOT(duplicate_selected())); + } - // ONLY footage is selected - if (all_footage) { - QAction* delete_footage_from_sequences = menu.addAction("Delete All Clips Using This Media"); - QObject::connect(delete_footage_from_sequences, SIGNAL(triggered(bool)), project_parent, SLOT(delete_clips_using_selected_media())); - } + // ONLY footage is selected + if (all_footage) { + QAction* delete_footage_from_sequences = menu.addAction("Delete All Clips Using This Media"); + QObject::connect(delete_footage_from_sequences, SIGNAL(triggered(bool)), project_parent, SLOT(delete_clips_using_selected_media())); + } - // delete media - QAction* delete_action = menu.addAction("Delete"); - QObject::connect(delete_action, SIGNAL(triggered(bool)), project_parent, SLOT(delete_selected_media())); + // delete media + QAction* delete_action = menu.addAction("Delete"); + QObject::connect(delete_action, SIGNAL(triggered(bool)), project_parent, SLOT(delete_selected_media())); - if (items.size() == 1) { - QAction* properties_action = menu.addAction("Properties..."); - QObject::connect(properties_action, SIGNAL(triggered(bool)), project_parent, SLOT(open_properties())); - } - } + if (items.size() == 1) { + QAction* properties_action = menu.addAction("Properties..."); + QObject::connect(properties_action, SIGNAL(triggered(bool)), project_parent, SLOT(open_properties())); + } + } - menu.addSeparator(); + menu.addSeparator(); - QAction* tree_view_action = menu.addAction("Tree View"); - connect(tree_view_action, SIGNAL(triggered(bool)), project_parent, SLOT(set_tree_view())); + QAction* tree_view_action = menu.addAction("Tree View"); + connect(tree_view_action, SIGNAL(triggered(bool)), project_parent, SLOT(set_tree_view())); - QAction* icon_view_action = menu.addAction("Icon View"); - connect(icon_view_action, SIGNAL(triggered(bool)), project_parent, SLOT(set_icon_view())); + QAction* icon_view_action = menu.addAction("Icon View"); + connect(icon_view_action, SIGNAL(triggered(bool)), project_parent, SLOT(set_icon_view())); - menu.exec(QCursor::pos()); + menu.exec(QCursor::pos()); } void SourcesCommon::mousePressEvent(QMouseEvent *) { - stop_rename_timer(); + stop_rename_timer(); } void SourcesCommon::item_click(Media *m, const QModelIndex& index) { - if (editing_item == m) { - rename_timer.start(); - } else { - editing_item = m; - editing_index = index; - } + if (editing_item == m) { + rename_timer.start(); + } else { + editing_item = m; + editing_index = index; + } } void SourcesCommon::mouseDoubleClickEvent(QMouseEvent *e, const QModelIndexList& selected_items) { - stop_rename_timer(); - if (selected_items.size() == 0) { - project_parent->import_dialog(); - } else if (selected_items.size() == 1) { - Media* item = project_parent->item_to_media(selected_items.at(0)); - switch (item->get_type()) { - case MEDIA_TYPE_FOOTAGE: - panel_footage_viewer->set_media(item); - panel_footage_viewer->setFocus(); - break; - case MEDIA_TYPE_SEQUENCE: - undo_stack.push(new ChangeSequenceAction(item->to_sequence())); - break; - } - } + stop_rename_timer(); + if (selected_items.size() == 0) { + project_parent->import_dialog(); + } else if (selected_items.size() == 1) { + Media* item = project_parent->item_to_media(selected_items.at(0)); + switch (item->get_type()) { + case MEDIA_TYPE_FOOTAGE: + panel_footage_viewer->set_media(item); + panel_footage_viewer->setFocus(); + break; + case MEDIA_TYPE_SEQUENCE: + undo_stack.push(new ChangeSequenceAction(item->to_sequence())); + break; + } + } } void SourcesCommon::dropEvent(QWidget* parent, QDropEvent *event, const QModelIndex& drop_item, const QModelIndexList& items) { - const QMimeData* mimeData = event->mimeData(); - Media* m = project_parent->item_to_media(drop_item); - if (mimeData->hasUrls()) { - // drag files in from outside - QList urls = mimeData->urls(); - if (!urls.isEmpty()) { - QStringList paths; - for (int i=0;iget_type() == MEDIA_TYPE_FOOTAGE - && !QFileInfo(paths.at(0)).isDir() - && config.drop_on_media_to_replace - && QMessageBox::question(parent, "Replace Media", "You dropped a file onto '" + m->get_name() + "'. Would you like to replace it with the dropped file?", QMessageBox::Yes | QMessageBox::No, QMessageBox::No) == QMessageBox::Yes) { - replace = true; - project_parent->replace_media(m, paths.at(0)); - } - if (!replace) { - QModelIndex parent; - if (drop_item.isValid()) { - if (m->get_type() == MEDIA_TYPE_FOLDER) { - parent = drop_item; - } else { - parent = drop_item.parent(); - } - } - project_parent->process_file_list(paths, false, NULL, panel_project->item_to_media(parent)); - } - } - event->acceptProposedAction(); - } else { - event->ignore(); + const QMimeData* mimeData = event->mimeData(); + Media* m = project_parent->item_to_media(drop_item); + if (mimeData->hasUrls()) { + // drag files in from outside + QList urls = mimeData->urls(); + if (!urls.isEmpty()) { + QStringList paths; + for (int i=0;iget_type() == MEDIA_TYPE_FOOTAGE + && !QFileInfo(paths.at(0)).isDir() + && config.drop_on_media_to_replace + && QMessageBox::question(parent, "Replace Media", "You dropped a file onto '" + m->get_name() + "'. Would you like to replace it with the dropped file?", QMessageBox::Yes | QMessageBox::No, QMessageBox::No) == QMessageBox::Yes) { + replace = true; + project_parent->replace_media(m, paths.at(0)); + } + if (!replace) { + QModelIndex parent; + if (drop_item.isValid()) { + if (m->get_type() == MEDIA_TYPE_FOLDER) { + parent = drop_item; + } else { + parent = drop_item.parent(); + } + } + project_parent->process_file_list(paths, false, NULL, panel_project->item_to_media(parent)); + } + } + event->acceptProposedAction(); + } else { + event->ignore(); - // dragging files within project - // if we dragged to the root OR dragged to a folder - if (!drop_item.isValid() || (drop_item.isValid() && m->get_type() == MEDIA_TYPE_FOLDER)) { - QVector move_items; - for (int i=0;iitem_to_media(item); - if (parent != drop_item && item != drop_item) { - bool ignore = false; - if (parent.isValid()) { - // if child belongs to a selected parent, assume the user is just moving the parent and ignore the child - QModelIndex par = parent; - while (par.isValid() && !ignore) { - for (int j=0;j 0) { - MediaMove* mm = new MediaMove(); - mm->to = m; - mm->items = move_items; - undo_stack.push(mm); - } - } - } + // dragging files within project + // if we dragged to the root OR dragged to a folder + if (!drop_item.isValid() || (drop_item.isValid() && m->get_type() == MEDIA_TYPE_FOLDER)) { + QVector move_items; + for (int i=0;iitem_to_media(item); + if (parent != drop_item && item != drop_item) { + bool ignore = false; + if (parent.isValid()) { + // if child belongs to a selected parent, assume the user is just moving the parent and ignore the child + QModelIndex par = parent; + while (par.isValid() && !ignore) { + for (int j=0;j 0) { + MediaMove* mm = new MediaMove(); + mm->to = m; + mm->items = move_items; + undo_stack.push(mm); + } + } + } } void SourcesCommon::reveal_in_browser() { - Media* media = project_parent->item_to_media(selected_items.at(0)); - Footage* m = media->to_footage(); + Media* media = project_parent->item_to_media(selected_items.at(0)); + Footage* m = media->to_footage(); #if defined(Q_OS_WIN) - QStringList args; - args << "/select," << QDir::toNativeSeparators(m->url); - QProcess::startDetached("explorer", args); + QStringList args; + args << "/select," << QDir::toNativeSeparators(m->url); + QProcess::startDetached("explorer", args); #elif defined(Q_OS_MAC) - QStringList args; - args << "-e"; - args << "tell application \"Finder\""; - args << "-e"; - args << "activate"; - args << "-e"; - args << "select POSIX file \""+m->url+"\""; - args << "-e"; - args << "end tell"; - QProcess::startDetached("osascript", args); + QStringList args; + args << "-e"; + args << "tell application \"Finder\""; + args << "-e"; + args << "activate"; + args << "-e"; + args << "select POSIX file \""+m->url+"\""; + args << "-e"; + args << "end tell"; + QProcess::startDetached("osascript", args); #else - QDesktopServices::openUrl(QUrl::fromLocalFile(m->url.left(m->url.lastIndexOf('/')))); + QDesktopServices::openUrl(QUrl::fromLocalFile(m->url.left(m->url.lastIndexOf('/')))); #endif } void SourcesCommon::stop_rename_timer() { - rename_timer.stop(); + rename_timer.stop(); } void SourcesCommon::rename_interval() { - stop_rename_timer(); - if (view->hasFocus() && editing_item != NULL) { - view->edit(editing_index); - } + stop_rename_timer(); + if (view->hasFocus() && editing_item != NULL) { + view->edit(editing_index); + } } void SourcesCommon::item_renamed(Media* item) { - if (editing_item == item) { - MediaRename* mr = new MediaRename(item, "idk"); - undo_stack.push(mr); - editing_item = NULL; - } + if (editing_item == item) { + MediaRename* mr = new MediaRename(item, "idk"); + undo_stack.push(mr); + editing_item = NULL; + } } diff --git a/ui/sourceiconview.cpp b/ui/sourceiconview.cpp index 8f0af0af4..83aed6176 100644 --- a/ui/sourceiconview.cpp +++ b/ui/sourceiconview.cpp @@ -9,60 +9,61 @@ SourceIconView::SourceIconView(QWidget *parent) : QListView(parent) { setSelectionMode(QAbstractItemView::ExtendedSelection); - setContextMenuPolicy(Qt::CustomContextMenu); - connect(this, SIGNAL(clicked(const QModelIndex&)), this, SLOT(item_click(const QModelIndex&))); - connect(this, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(show_context_menu())); + setResizeMode(QListView::Adjust); + setContextMenuPolicy(Qt::CustomContextMenu); + connect(this, SIGNAL(clicked(const QModelIndex&)), this, SLOT(item_click(const QModelIndex&))); + connect(this, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(show_context_menu())); } void SourceIconView::show_context_menu() { - project_parent->sources_common->show_context_menu(this, selectedIndexes()); + project_parent->sources_common->show_context_menu(this, selectedIndexes()); } void SourceIconView::item_click(const QModelIndex& index) { - if (selectionModel()->selectedRows().size() == 1 && index.column() == 0) { - project_parent->sources_common->item_click(project_parent->item_to_media(index), index); - } + if (selectedIndexes().size() == 1 && index.column() == 0) { + project_parent->sources_common->item_click(project_parent->item_to_media(index), index); + } } void SourceIconView::mousePressEvent(QMouseEvent* event) { - project_parent->sources_common->mousePressEvent(event); - if (!indexAt(event->pos()).isValid()) selectionModel()->clear(); - QListView::mousePressEvent(event); + project_parent->sources_common->mousePressEvent(event); + if (!indexAt(event->pos()).isValid()) selectionModel()->clear(); + QListView::mousePressEvent(event); } void SourceIconView::dragEnterEvent(QDragEnterEvent *event) { - if (event->mimeData()->hasUrls()) { - event->acceptProposedAction(); - } else { - QListView::dragEnterEvent(event); - } + if (event->mimeData()->hasUrls()) { + event->acceptProposedAction(); + } else { + QListView::dragEnterEvent(event); + } } void SourceIconView::dragMoveEvent(QDragMoveEvent *event) { - if (event->mimeData()->hasUrls()) { - event->acceptProposedAction(); - } else { - QListView::dragMoveEvent(event); - } + if (event->mimeData()->hasUrls()) { + event->acceptProposedAction(); + } else { + QListView::dragMoveEvent(event); + } } void SourceIconView::dropEvent(QDropEvent* event) { - QModelIndex drop_item = indexAt(event->pos()); - if (!drop_item.isValid()) drop_item = rootIndex(); - project_parent->sources_common->dropEvent(this, event, drop_item, selectedIndexes()); + QModelIndex drop_item = indexAt(event->pos()); + if (!drop_item.isValid()) drop_item = rootIndex(); + project_parent->sources_common->dropEvent(this, event, drop_item, selectedIndexes()); } void SourceIconView::mouseDoubleClickEvent(QMouseEvent *event) { - bool default_behavior = true; - if (selectedIndexes().size() == 1) { - Media* m = project_parent->item_to_media(selectedIndexes().at(0)); - if (m->get_type() == MEDIA_TYPE_FOLDER) { - default_behavior = false; - setRootIndex(selectedIndexes().at(0)); - emit changed_root(); - } - } - if (default_behavior) { - project_parent->sources_common->mouseDoubleClickEvent(event, selectedIndexes()); - } + bool default_behavior = true; + if (selectedIndexes().size() == 1) { + Media* m = project_parent->item_to_media(selectedIndexes().at(0)); + if (m->get_type() == MEDIA_TYPE_FOLDER) { + default_behavior = false; + setRootIndex(selectedIndexes().at(0)); + emit changed_root(); + } + } + if (default_behavior) { + project_parent->sources_common->mouseDoubleClickEvent(event, selectedIndexes()); + } } diff --git a/ui/sourcetable.cpp b/ui/sourcetable.cpp index 75586e8b4..d439c0f04 100644 --- a/ui/sourcetable.cpp +++ b/ui/sourcetable.cpp @@ -27,47 +27,51 @@ SourceTable::SourceTable(QWidget* parent) : QTreeView(parent) { setSortingEnabled(true); - sortByColumn(0, Qt::AscendingOrder); - setContextMenuPolicy(Qt::CustomContextMenu); - connect(this, SIGNAL(clicked(const QModelIndex&)), this, SLOT(item_click(const QModelIndex&))); - connect(this, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(show_context_menu())); + setAcceptDrops(true); + sortByColumn(0, Qt::AscendingOrder); + setContextMenuPolicy(Qt::CustomContextMenu); + setEditTriggers(QAbstractItemView::NoEditTriggers); + setDragDropMode(QAbstractItemView::DragDrop); + setSelectionMode(QAbstractItemView::ExtendedSelection); + connect(this, SIGNAL(clicked(const QModelIndex&)), this, SLOT(item_click(const QModelIndex&))); + connect(this, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(show_context_menu())); } void SourceTable::show_context_menu() { - project_parent->sources_common->show_context_menu(this, selectionModel()->selectedRows()); + project_parent->sources_common->show_context_menu(this, selectionModel()->selectedRows()); } void SourceTable::item_click(const QModelIndex& index) { - if (selectionModel()->selectedRows().size() == 1 && index.column() == 0) { - project_parent->sources_common->item_click(project_parent->item_to_media(index), index); - } + if (selectionModel()->selectedRows().size() == 1 && index.column() == 0) { + project_parent->sources_common->item_click(project_parent->item_to_media(index), index); + } } void SourceTable::mousePressEvent(QMouseEvent* event) { - project_parent->sources_common->mousePressEvent(event); - QTreeView::mousePressEvent(event); + project_parent->sources_common->mousePressEvent(event); + QTreeView::mousePressEvent(event); } void SourceTable::mouseDoubleClickEvent(QMouseEvent* event) { - project_parent->sources_common->mouseDoubleClickEvent(event, selectionModel()->selectedRows()); + project_parent->sources_common->mouseDoubleClickEvent(event, selectionModel()->selectedRows()); } void SourceTable::dragEnterEvent(QDragEnterEvent *event) { if (event->mimeData()->hasUrls()) { - event->acceptProposedAction(); - } else { - QTreeView::dragEnterEvent(event); - } + event->acceptProposedAction(); + } else { + QTreeView::dragEnterEvent(event); + } } void SourceTable::dragMoveEvent(QDragMoveEvent *event) { - if (event->mimeData()->hasUrls()) { - event->acceptProposedAction(); - } else { - QTreeView::dragMoveEvent(event); - } + if (event->mimeData()->hasUrls()) { + event->acceptProposedAction(); + } else { + QTreeView::dragMoveEvent(event); + } } void SourceTable::dropEvent(QDropEvent* event) { - project_parent->sources_common->dropEvent(this, event, indexAt(event->pos()), selectionModel()->selectedRows()); + project_parent->sources_common->dropEvent(this, event, indexAt(event->pos()), selectionModel()->selectedRows()); } diff --git a/ui/timelinewidget.cpp b/ui/timelinewidget.cpp index 7a8ee4fbe..2d5cfbe9c 100644 --- a/ui/timelinewidget.cpp +++ b/ui/timelinewidget.cpp @@ -44,21 +44,21 @@ #define TRANSITION_BETWEEN_RANGE 40 TimelineWidget::TimelineWidget(QWidget *parent) : QWidget(parent) { - selection_command = NULL; + selection_command = NULL; self_created_sequence = NULL; scroll = 0; bottom_align = false; - track_resizing = false; - setMouseTracking(true); + track_resizing = false; + setMouseTracking(true); - setAcceptDrops(true); + setAcceptDrops(true); - setContextMenuPolicy(Qt::CustomContextMenu); - connect(this, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(show_context_menu(const QPoint&))); + setContextMenuPolicy(Qt::CustomContextMenu); + connect(this, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(show_context_menu(const QPoint&))); - tooltip_timer.setInterval(500); - connect(&tooltip_timer, SIGNAL(timeout()), this, SLOT(tooltip_timer_timeout())); + tooltip_timer.setInterval(500); + connect(&tooltip_timer, SIGNAL(timeout()), this, SLOT(tooltip_timer_timeout())); } void TimelineWidget::right_click_ripple() { @@ -75,143 +75,143 @@ void TimelineWidget::right_click_ripple() { } void TimelineWidget::show_context_menu(const QPoint& pos) { - if (sequence != NULL) { - // hack because sometimes right clicking doesn't trigger mouse release event - panel_timeline->rect_select_init = false; - panel_timeline->rect_select_proc = false; + if (sequence != NULL) { + // hack because sometimes right clicking doesn't trigger mouse release event + panel_timeline->rect_select_init = false; + panel_timeline->rect_select_proc = false; - QMenu menu(this); + QMenu menu(this); - QAction* undoAction = menu.addAction("&Undo"); - QAction* redoAction = menu.addAction("&Redo"); - connect(undoAction, SIGNAL(triggered(bool)), mainWindow, SLOT(undo())); - connect(redoAction, SIGNAL(triggered(bool)), mainWindow, SLOT(redo())); - undoAction->setEnabled(undo_stack.canUndo()); - redoAction->setEnabled(undo_stack.canRedo()); - menu.addSeparator(); + QAction* undoAction = menu.addAction("&Undo"); + QAction* redoAction = menu.addAction("&Redo"); + connect(undoAction, SIGNAL(triggered(bool)), mainWindow, SLOT(undo())); + connect(redoAction, SIGNAL(triggered(bool)), mainWindow, SLOT(redo())); + undoAction->setEnabled(undo_stack.canUndo()); + redoAction->setEnabled(undo_stack.canRedo()); + menu.addSeparator(); - // collect all the selected clips - QVector selected_clips; - for (int i=0;iclips.size();i++) { - Clip* c = sequence->clips.at(i); - if (c != NULL && panel_timeline->is_clip_selected(c, true)) { - selected_clips.append(c); - } - } + // collect all the selected clips + QVector selected_clips; + for (int i=0;iclips.size();i++) { + Clip* c = sequence->clips.at(i); + if (c != NULL && panel_timeline->is_clip_selected(c, true)) { + selected_clips.append(c); + } + } - if (selected_clips.isEmpty()) { - // no clips are selected - panel_timeline->cursor_frame = panel_timeline->getTimelineFrameFromScreenPoint(pos.x()); - panel_timeline->cursor_track = getTrackFromScreenPoint(pos.y()); + if (selected_clips.isEmpty()) { + // no clips are selected + panel_timeline->cursor_frame = panel_timeline->getTimelineFrameFromScreenPoint(pos.x()); + panel_timeline->cursor_track = getTrackFromScreenPoint(pos.y()); - bool can_ripple_delete = true; - bool at_end_of_sequence = true; - rc_ripple_min = 0; - rc_ripple_max = LONG_MAX; + bool can_ripple_delete = true; + bool at_end_of_sequence = true; + rc_ripple_min = 0; + rc_ripple_max = LONG_MAX; - for (int i=0;iclips.size();i++) { - Clip* c = sequence->clips.at(i); - if (c != NULL) { - if (c->timeline_in > panel_timeline->cursor_frame || c->timeline_out > panel_timeline->cursor_frame) { - at_end_of_sequence = false; - } - if (c->track == panel_timeline->cursor_track) { - if (c->timeline_in <= panel_timeline->cursor_frame && c->timeline_out >= panel_timeline->cursor_frame) { - can_ripple_delete = false; - break; - } else if (c->timeline_out < panel_timeline->cursor_frame) { - rc_ripple_min = qMax(rc_ripple_min, c->timeline_out); - } else if (c->timeline_in > panel_timeline->cursor_frame) { - rc_ripple_max = qMin(rc_ripple_max, c->timeline_in); - } - } - } - } + for (int i=0;iclips.size();i++) { + Clip* c = sequence->clips.at(i); + if (c != NULL) { + if (c->timeline_in > panel_timeline->cursor_frame || c->timeline_out > panel_timeline->cursor_frame) { + at_end_of_sequence = false; + } + if (c->track == panel_timeline->cursor_track) { + if (c->timeline_in <= panel_timeline->cursor_frame && c->timeline_out >= panel_timeline->cursor_frame) { + can_ripple_delete = false; + break; + } else if (c->timeline_out < panel_timeline->cursor_frame) { + rc_ripple_min = qMax(rc_ripple_min, c->timeline_out); + } else if (c->timeline_in > panel_timeline->cursor_frame) { + rc_ripple_max = qMin(rc_ripple_max, c->timeline_in); + } + } + } + } - if (can_ripple_delete && !at_end_of_sequence) { - QAction* ripple_delete_action = menu.addAction("R&ipple Delete"); - connect(ripple_delete_action, SIGNAL(triggered(bool)), this, SLOT(right_click_ripple())); - } + if (can_ripple_delete && !at_end_of_sequence) { + QAction* ripple_delete_action = menu.addAction("R&ipple Delete"); + connect(ripple_delete_action, SIGNAL(triggered(bool)), this, SLOT(right_click_ripple())); + } - menu.addAction("Sequence settings coming soon..."); - } else { - // clips are selected - QAction* cutAction = menu.addAction("C&ut"); - connect(cutAction, SIGNAL(triggered(bool)), mainWindow, SLOT(cut())); - QAction* copyAction = menu.addAction("Cop&y"); - connect(copyAction, SIGNAL(triggered(bool)), mainWindow, SLOT(copy())); - QAction* pasteAction = menu.addAction("&Paste"); - connect(pasteAction, SIGNAL(triggered(bool)), mainWindow, SLOT(paste())); - menu.addSeparator(); - QAction* speedAction = menu.addAction("&Speed/Duration"); - connect(speedAction, SIGNAL(triggered(bool)), mainWindow, SLOT(openSpeedDialog())); - QAction* autoscaleAction = menu.addAction("Auto-s&cale"); - autoscaleAction->setCheckable(true); - connect(autoscaleAction, SIGNAL(triggered(bool)), this, SLOT(toggle_autoscale())); + menu.addAction("Sequence settings coming soon..."); + } else { + // clips are selected + QAction* cutAction = menu.addAction("C&ut"); + connect(cutAction, SIGNAL(triggered(bool)), mainWindow, SLOT(cut())); + QAction* copyAction = menu.addAction("Cop&y"); + connect(copyAction, SIGNAL(triggered(bool)), mainWindow, SLOT(copy())); + QAction* pasteAction = menu.addAction("&Paste"); + connect(pasteAction, SIGNAL(triggered(bool)), mainWindow, SLOT(paste())); + menu.addSeparator(); + QAction* speedAction = menu.addAction("&Speed/Duration"); + connect(speedAction, SIGNAL(triggered(bool)), mainWindow, SLOT(openSpeedDialog())); + QAction* autoscaleAction = menu.addAction("Auto-s&cale"); + autoscaleAction->setCheckable(true); + connect(autoscaleAction, SIGNAL(triggered(bool)), this, SLOT(toggle_autoscale())); - QAction* nestAction = menu.addAction("&Nest"); - connect(nestAction, SIGNAL(triggered(bool)), mainWindow, SLOT(on_actionNest_triggered())); + QAction* nestAction = menu.addAction("&Nest"); + connect(nestAction, SIGNAL(triggered(bool)), mainWindow, SLOT(on_actionNest_triggered())); - // stabilizer option - int video_clip_count = 0; - bool all_video_is_footage = true; - for (int i=0;itrack < 0) { - video_clip_count++; - if (selected_clips.at(i)->media == NULL - || selected_clips.at(i)->media->get_type() != MEDIA_TYPE_FOOTAGE) { - all_video_is_footage = false; - } - } - } - if (video_clip_count == 1 && all_video_is_footage) { - QAction* stabilizerAction = menu.addAction("S&tabilizer"); - connect(stabilizerAction, SIGNAL(triggered(bool)), this, SLOT(show_stabilizer_diag())); - } + // stabilizer option + int video_clip_count = 0; + bool all_video_is_footage = true; + for (int i=0;itrack < 0) { + video_clip_count++; + if (selected_clips.at(i)->media == NULL + || selected_clips.at(i)->media->get_type() != MEDIA_TYPE_FOOTAGE) { + all_video_is_footage = false; + } + } + } + if (video_clip_count == 1 && all_video_is_footage) { + QAction* stabilizerAction = menu.addAction("S&tabilizer"); + connect(stabilizerAction, SIGNAL(triggered(bool)), this, SLOT(show_stabilizer_diag())); + } - // set autoscale arbitrarily to the first selected clip - autoscaleAction->setChecked(selected_clips.at(0)->autoscale); + // set autoscale arbitrarily to the first selected clip + autoscaleAction->setChecked(selected_clips.at(0)->autoscale); - // check if all selected clips have the same media for a "Reveal In Project" - bool same_media = true; - rc_reveal_media = selected_clips.at(0)->media; - for (int i=1;imedia != rc_reveal_media) { - same_media = false; - break; - } - } + // check if all selected clips have the same media for a "Reveal In Project" + bool same_media = true; + rc_reveal_media = selected_clips.at(0)->media; + for (int i=1;imedia != rc_reveal_media) { + same_media = false; + break; + } + } - if (same_media) { - QAction* revealInProjectAction = menu.addAction("&Reveal in Project"); - connect(revealInProjectAction, SIGNAL(triggered(bool)), this, SLOT(reveal_media())); - } + if (same_media) { + QAction* revealInProjectAction = menu.addAction("&Reveal in Project"); + connect(revealInProjectAction, SIGNAL(triggered(bool)), this, SLOT(reveal_media())); + } - QAction* rename = menu.addAction("R&ename"); - connect(rename, SIGNAL(triggered(bool)), this, SLOT(rename_clip())); - } + QAction* rename = menu.addAction("R&ename"); + connect(rename, SIGNAL(triggered(bool)), this, SLOT(rename_clip())); + } - menu.exec(mapToGlobal(pos)); - } + menu.exec(mapToGlobal(pos)); + } } void TimelineWidget::toggle_autoscale() { - SetAutoscaleAction* action = new SetAutoscaleAction(); - for (int i=0;iclips.size();i++) { - Clip* c = sequence->clips.at(i); - if (c != NULL && panel_timeline->is_clip_selected(c, true)) { - action->clips.append(c); - } - } - if (action->clips.size() > 0) { - undo_stack.push(action); - } else { - delete action; - } + SetAutoscaleAction* action = new SetAutoscaleAction(); + for (int i=0;iclips.size();i++) { + Clip* c = sequence->clips.at(i); + if (c != NULL && panel_timeline->is_clip_selected(c, true)) { + action->clips.append(c); + } + } + if (action->clips.size() > 0) { + undo_stack.push(action); + } else { + delete action; + } } void TimelineWidget::tooltip_timer_timeout() { - if (sequence != NULL) { + if (sequence != NULL) { if (tooltip_clip < sequence->clips.size()) { Clip* c = sequence->clips.at(tooltip_clip); if (c != NULL) { @@ -222,7 +222,7 @@ void TimelineWidget::tooltip_timer_timeout() { + "\nDuration: " + frame_to_timecode(c->getLength(), config.timecode_view, sequence->frame_rate)); } } - } + } tooltip_timer.stop(); } @@ -234,7 +234,7 @@ void TimelineWidget::rename_clip() { selected_clips.append(c); } } - if (selected_clips.size() > 0) { + if (selected_clips.size() > 0) { QString s = QInputDialog::getText(this, (selected_clips.size() == 1) ? "Rename '" + selected_clips.at(0)->name + "'" : "Rename multiple clips", "Enter a new name for this clip:", @@ -248,12 +248,12 @@ void TimelineWidget::rename_clip() { undo_stack.push(rcc); update_ui(true); } - } + } } void TimelineWidget::show_stabilizer_diag() { - StabilizerDialog sd; - sd.exec(); + StabilizerDialog sd; + sd.exec(); } bool same_sign(int a, int b) { @@ -263,16 +263,14 @@ bool same_sign(int a, int b) { void TimelineWidget::dragEnterEvent(QDragEnterEvent *event) { bool import_init = false; - QVector media_list; + QVector media_list; panel_timeline->importing_files = false; - if (event->source() == panel_project->tree_view || event->source() == panel_project->icon_view) { - QModelIndexList items = (event->source() == panel_project->tree_view) - ? panel_project->tree_view->selectionModel()->selectedRows() - : panel_project->icon_view->selectionModel()->selectedIndexes(); - media_list.resize(items.size()); - for (int i=0;iitem_to_media(items.at(i)); + if (event->source() == panel_project->tree_view || event->source() == panel_project->icon_view) { + QModelIndexList items = panel_project->get_current_selected(); + media_list.resize(items.size()); + for (int i=0;iitem_to_media(items.at(i)); } import_init = true; } @@ -280,7 +278,7 @@ void TimelineWidget::dragEnterEvent(QDragEnterEvent *event) { if (event->source() == panel_footage_viewer->viewer_widget) { Sequence* proposed_seq = panel_footage_viewer->seq; if (proposed_seq != sequence) { // don't allow nesting the same sequence - media_list.append(panel_footage_viewer->media); + media_list.append(panel_footage_viewer->media); import_init = true; } } @@ -294,17 +292,17 @@ void TimelineWidget::dragEnterEvent(QDragEnterEvent *event) { file_list.append(urls.at(i).toLocalFile()); } - panel_project->process_file_list(file_list); + panel_project->process_file_list(file_list); for (int i=0;ilast_imported_media.size();i++) { // waits for media to have a duration // TODO would be much nicer if this was multithreaded - Footage* f = panel_project->last_imported_media.at(i)->to_footage(); - f->ready_lock.lock(); - f->ready_lock.unlock(); + Footage* f = panel_project->last_imported_media.at(i)->to_footage(); + f->ready_lock.lock(); + f->ready_lock.unlock(); - if (f->ready) { - media_list.append(panel_project->last_imported_media.at(i)); + if (f->ready) { + media_list.append(panel_project->last_imported_media.at(i)); } } @@ -317,8 +315,8 @@ void TimelineWidget::dragEnterEvent(QDragEnterEvent *event) { } } - if (import_init) { - event->acceptProposedAction(); + if (import_init) { + event->acceptProposedAction(); long entry_point; Sequence* seq = sequence; @@ -327,7 +325,7 @@ void TimelineWidget::dragEnterEvent(QDragEnterEvent *event) { // if no sequence, we're going to create a new one using the clips as a reference entry_point = 0; - self_created_sequence = create_sequence_from_media(media_list); + self_created_sequence = create_sequence_from_media(media_list); seq = self_created_sequence; } else { entry_point = panel_timeline->getTimelineFrameFromScreenPoint(event->pos().x()); @@ -335,22 +333,22 @@ void TimelineWidget::dragEnterEvent(QDragEnterEvent *event) { panel_timeline->drag_track_start = (bottom_align) ? -1 : 0; } - panel_timeline->create_ghosts_from_media(seq, entry_point, media_list); + panel_timeline->create_ghosts_from_media(seq, entry_point, media_list); panel_timeline->importing = true; - } + } } void TimelineWidget::dragMoveEvent(QDragMoveEvent *event) { - if (panel_timeline->importing) { - event->acceptProposedAction(); + if (panel_timeline->importing) { + event->acceptProposedAction(); - if (sequence != NULL) { - QPoint pos = event->pos(); - update_ghosts(pos, event->keyboardModifiers() & Qt::ShiftModifier); - panel_timeline->move_insert = ((event->keyboardModifiers() & Qt::ControlModifier) && (panel_timeline->tool == TIMELINE_TOOL_POINTER || panel_timeline->importing)); - update_ui(false); - } + if (sequence != NULL) { + QPoint pos = event->pos(); + update_ghosts(pos, event->keyboardModifiers() & Qt::ShiftModifier); + panel_timeline->move_insert = ((event->keyboardModifiers() & Qt::ControlModifier) && (panel_timeline->tool == TIMELINE_TOOL_POINTER || panel_timeline->importing)); + update_ui(false); + } } } @@ -373,7 +371,7 @@ void TimelineWidget::wheelEvent(QWheelEvent *event) { } void TimelineWidget::dragLeaveEvent(QDragLeaveEvent* event) { - event->accept(); + event->accept(); if (panel_timeline->importing) { if (panel_timeline->importing_files) { undo_stack.undo(); @@ -385,7 +383,7 @@ void TimelineWidget::dragLeaveEvent(QDragLeaveEvent* event) { } if (self_created_sequence != NULL) { delete self_created_sequence; - self_created_sequence = NULL; + self_created_sequence = NULL; } } @@ -424,36 +422,36 @@ void insert_clips(ComboAction* ca) { if (g.clip >= 0) { ignore_clips.append(sequence->clips.at(g.clip)); } else { - // don't try to close old gap if importing + // don't try to close old gap if importing ripple_old_point = false; } } - panel_timeline->split_cache.clear(); + panel_timeline->split_cache.clear(); for (int i=0;iclips.size();i++) { Clip* c = sequence->clips.at(i); if (c != NULL) { - // don't split any clips that are moving - bool found = false; - for (int j=0;jghosts.size();j++) { - if (panel_timeline->ghosts.at(j).clip == i) { - found = true; - break; - } - } - if (!found) { - if (c->timeline_in < earliest_new_point && c->timeline_out > earliest_new_point) { - panel_timeline->split_clip_and_relink(ca, i, earliest_new_point, true); - } + // don't split any clips that are moving + bool found = false; + for (int j=0;jghosts.size();j++) { + if (panel_timeline->ghosts.at(j).clip == i) { + found = true; + break; + } + } + if (!found) { + if (c->timeline_in < earliest_new_point && c->timeline_out > earliest_new_point) { + panel_timeline->split_clip_and_relink(ca, i, earliest_new_point, true); + } - // determine if we should close the gap the old clips left behind - if (ripple_old_point - && !((c->timeline_in < earliest_old_point && c->timeline_out <= earliest_old_point) || (c->timeline_in >= latest_old_point && c->timeline_out > latest_old_point)) - && !ignore_clips.contains(c)) { - ripple_old_point = false; - } - } + // determine if we should close the gap the old clips left behind + if (ripple_old_point + && !((c->timeline_in < earliest_old_point && c->timeline_out <= earliest_old_point) || (c->timeline_in >= latest_old_point && c->timeline_out > latest_old_point)) + && !ignore_clips.contains(c)) { + ripple_old_point = false; + } + } } } @@ -487,15 +485,15 @@ void insert_clips(ComboAction* ca) { } void TimelineWidget::dropEvent(QDropEvent* event) { - if (panel_timeline->importing && panel_timeline->ghosts.size() > 0) { - event->acceptProposedAction(); + if (panel_timeline->importing && panel_timeline->ghosts.size() > 0) { + event->acceptProposedAction(); - ComboAction* ca = new ComboAction(); + ComboAction* ca = new ComboAction(); - Sequence* s = sequence; + Sequence* s = sequence; - // if we're dropping into nothing, create a new sequences based on the clip being dragged - if (s == NULL) { + // if we're dropping into nothing, create a new sequences based on the clip being dragged + if (s == NULL) { s = self_created_sequence; panel_project->new_sequence(ca, self_created_sequence, true, NULL); self_created_sequence = NULL; @@ -507,28 +505,28 @@ void TimelineWidget::dropEvent(QDropEvent* event) { panel_timeline->add_clips_from_ghosts(ca, s); - undo_stack.push(ca); + undo_stack.push(ca); - setFocus(); + setFocus(); update_ui(true); } } void TimelineWidget::mouseDoubleClickEvent(QMouseEvent *event) { - if (panel_timeline->tool == TIMELINE_TOOL_EDIT) { - int clip_index = getClipIndexFromCoords(panel_timeline->cursor_frame, panel_timeline->cursor_track); - if (clip_index >= 0) { - Clip* clip = sequence->clips.at(clip_index); + if (panel_timeline->tool == TIMELINE_TOOL_EDIT) { + int clip_index = getClipIndexFromCoords(panel_timeline->cursor_frame, panel_timeline->cursor_track); + if (clip_index >= 0) { + Clip* clip = sequence->clips.at(clip_index); if (!(event->modifiers() & Qt::ShiftModifier)) sequence->selections.clear(); - Selection s; - s.in = clip->timeline_in; - s.out = clip->timeline_out; - s.track = clip->track; + Selection s; + s.in = clip->timeline_in; + s.out = clip->timeline_out; + s.track = clip->track; sequence->selections.append(s); update_ui(false); - } - } + } + } } bool isLiveEditing() { @@ -536,7 +534,7 @@ bool isLiveEditing() { } void TimelineWidget::mousePressEvent(QMouseEvent *event) { - if (sequence != NULL) { + if (sequence != NULL) { int tool = panel_timeline->tool; if (event->button() == Qt::RightButton) { tool = TIMELINE_TOOL_MENU; @@ -618,28 +616,28 @@ void TimelineWidget::mousePressEvent(QMouseEvent *event) { panel_timeline->deselect_area(link->timeline_in, link->timeline_out, link->track); } } - } else if (panel_timeline->tool == TIMELINE_TOOL_POINTER && panel_timeline->transition_select != TA_NO_TRANSITION) { - panel_timeline->deselect_area(clip->timeline_in, clip->timeline_out, clip->track); + } else if (panel_timeline->tool == TIMELINE_TOOL_POINTER && panel_timeline->transition_select != TA_NO_TRANSITION) { + panel_timeline->deselect_area(clip->timeline_in, clip->timeline_out, clip->track); - for (int i=0;ilinked.size();i++) { - Clip* link = sequence->clips.at(clip->linked.at(i)); - panel_timeline->deselect_area(link->timeline_in, link->timeline_out, link->track); - } + for (int i=0;ilinked.size();i++) { + Clip* link = sequence->clips.at(clip->linked.at(i)); + panel_timeline->deselect_area(link->timeline_in, link->timeline_out, link->track); + } - Selection s; - s.track = clip->track; + Selection s; + s.track = clip->track; - if (panel_timeline->transition_select == TA_OPENING_TRANSITION && clip->get_opening_transition() != NULL) { - s.in = clip->timeline_in; - if (clip->get_opening_transition()->secondary_clip != NULL) s.in -= clip->get_opening_transition()->get_true_length(); - s.out = clip->timeline_in + clip->get_opening_transition()->get_true_length(); - } else if (panel_timeline->transition_select == TA_CLOSING_TRANSITION && clip->get_closing_transition() != NULL) { - s.in = clip->timeline_out - clip->get_closing_transition()->get_true_length(); - s.out = clip->timeline_out; - if (clip->get_closing_transition()->secondary_clip != NULL) s.out += clip->get_closing_transition()->get_true_length(); - } - sequence->selections.append(s); - } + if (panel_timeline->transition_select == TA_OPENING_TRANSITION && clip->get_opening_transition() != NULL) { + s.in = clip->timeline_in; + if (clip->get_opening_transition()->secondary_clip != NULL) s.in -= clip->get_opening_transition()->get_true_length(); + s.out = clip->timeline_in + clip->get_opening_transition()->get_true_length(); + } else if (panel_timeline->transition_select == TA_CLOSING_TRANSITION && clip->get_closing_transition() != NULL) { + s.in = clip->timeline_out - clip->get_closing_transition()->get_true_length(); + s.out = clip->timeline_out; + if (clip->get_closing_transition()->secondary_clip != NULL) s.out += clip->get_closing_transition()->get_true_length(); + } + sequence->selections.append(s); + } } else { // if "shift" is not down if (!shift) { @@ -651,17 +649,17 @@ void TimelineWidget::mousePressEvent(QMouseEvent *event) { s.in = clip->timeline_in; s.out = clip->timeline_out; - if (panel_timeline->tool == TIMELINE_TOOL_POINTER) { - if (panel_timeline->transition_select == TA_OPENING_TRANSITION) { - s.out = clip->timeline_in + clip->get_opening_transition()->get_true_length(); - if (clip->get_opening_transition()->secondary_clip != NULL) s.in -= clip->get_opening_transition()->get_true_length(); - } + if (panel_timeline->tool == TIMELINE_TOOL_POINTER) { + if (panel_timeline->transition_select == TA_OPENING_TRANSITION) { + s.out = clip->timeline_in + clip->get_opening_transition()->get_true_length(); + if (clip->get_opening_transition()->secondary_clip != NULL) s.in -= clip->get_opening_transition()->get_true_length(); + } - if (panel_timeline->transition_select == TA_CLOSING_TRANSITION) { - s.in = clip->timeline_out - clip->get_closing_transition()->get_true_length(); - if (clip->get_closing_transition()->secondary_clip != NULL) s.out += clip->get_closing_transition()->get_true_length(); - } - } + if (panel_timeline->transition_select == TA_CLOSING_TRANSITION) { + s.in = clip->timeline_out - clip->get_closing_transition()->get_true_length(); + if (clip->get_closing_transition()->secondary_clip != NULL) s.out += clip->get_closing_transition()->get_true_length(); + } + } s.track = clip->track; sequence->selections.append(s); @@ -698,12 +696,12 @@ void TimelineWidget::mousePressEvent(QMouseEvent *event) { update_ui(false); } } - break; - case TIMELINE_TOOL_HAND: - panel_timeline->hand_moving = true; - panel_timeline->drag_x_start = pos.x(); - panel_timeline->drag_y_start = pos.y(); - break; + break; + case TIMELINE_TOOL_HAND: + panel_timeline->hand_moving = true; + panel_timeline->drag_x_start = pos.x(); + panel_timeline->drag_y_start = pos.y(); + break; case TIMELINE_TOOL_EDIT: if (config.edit_tool_also_seeks) panel_sequence_viewer->seek(panel_timeline->drag_frame_start); panel_timeline->selecting = true; @@ -715,55 +713,55 @@ void TimelineWidget::mousePressEvent(QMouseEvent *event) { update_ui(false); } break; - case TIMELINE_TOOL_TRANSITION: - { - if (panel_timeline->transition_tool_pre_clip > -1) { - panel_timeline->transition_tool_init = true; - } - } - break; + case TIMELINE_TOOL_TRANSITION: + { + if (panel_timeline->transition_tool_pre_clip > -1) { + panel_timeline->transition_tool_init = true; + } + } + break; } } - } + } } void make_room_for_transition(ComboAction* ca, Clip* c, int type, long transition_start, long transition_end, bool delete_old_transitions) { - // make room for transition - if (type == TA_OPENING_TRANSITION) { - if (delete_old_transitions && c->get_opening_transition() != NULL) { - ca->append(new DeleteTransitionCommand(c->sequence, c->opening_transition)); - } - if (c->get_closing_transition() != NULL) { - if (transition_end >= c->timeline_out) { - ca->append(new DeleteTransitionCommand(c->sequence, c->closing_transition)); - } else if (transition_end > c->timeline_out - c->get_closing_transition()->get_true_length()) { - ca->append(new ModifyTransitionCommand(c, TA_CLOSING_TRANSITION, c->timeline_out - transition_end)); - } - } - } else { - if (delete_old_transitions && c->get_closing_transition() != NULL) { - ca->append(new DeleteTransitionCommand(c->sequence, c->closing_transition)); - } - if (c->get_opening_transition() != NULL) { - if (transition_start <= c->timeline_in) { - ca->append(new DeleteTransitionCommand(c->sequence, c->opening_transition)); - } else if (transition_start < c->timeline_in + c->get_opening_transition()->get_true_length()) { - ca->append(new ModifyTransitionCommand(c, TA_OPENING_TRANSITION, transition_start - c->timeline_in)); - } - } - } + // make room for transition + if (type == TA_OPENING_TRANSITION) { + if (delete_old_transitions && c->get_opening_transition() != NULL) { + ca->append(new DeleteTransitionCommand(c->sequence, c->opening_transition)); + } + if (c->get_closing_transition() != NULL) { + if (transition_end >= c->timeline_out) { + ca->append(new DeleteTransitionCommand(c->sequence, c->closing_transition)); + } else if (transition_end > c->timeline_out - c->get_closing_transition()->get_true_length()) { + ca->append(new ModifyTransitionCommand(c, TA_CLOSING_TRANSITION, c->timeline_out - transition_end)); + } + } + } else { + if (delete_old_transitions && c->get_closing_transition() != NULL) { + ca->append(new DeleteTransitionCommand(c->sequence, c->closing_transition)); + } + if (c->get_opening_transition() != NULL) { + if (transition_start <= c->timeline_in) { + ca->append(new DeleteTransitionCommand(c->sequence, c->opening_transition)); + } else if (transition_start < c->timeline_in + c->get_opening_transition()->get_true_length()) { + ca->append(new ModifyTransitionCommand(c, TA_OPENING_TRANSITION, transition_start - c->timeline_in)); + } + } + } } void TimelineWidget::mouseReleaseEvent(QMouseEvent *event) { QToolTip::hideText(); - if (sequence != NULL) { - bool alt = (event->modifiers() & Qt::AltModifier); + if (sequence != NULL) { + bool alt = (event->modifiers() & Qt::AltModifier); bool shift = (event->modifiers() & Qt::ShiftModifier); bool ctrl = (event->modifiers() & Qt::ControlModifier); if (event->button() == Qt::LeftButton) { - ComboAction* ca = new ComboAction(); - bool push_undo = false; + ComboAction* ca = new ComboAction(); + bool push_undo = false; if (panel_timeline->creating) { if (panel_timeline->ghosts.size() > 0) { @@ -797,46 +795,46 @@ void TimelineWidget::mouseReleaseEvent(QMouseEvent *event) { QVector add; add.append(c); - ca->append(new AddClipCommand(sequence, add)); + ca->append(new AddClipCommand(sequence, add)); if (c->track < 0) { // default video effects (before custom effects) - c->effects.append(create_effect(c, get_internal_meta(EFFECT_INTERNAL_TRANSFORM, EFFECT_TYPE_EFFECT))); - //c->media_type = MEDIA_TYPE_SOLID; + c->effects.append(create_effect(c, get_internal_meta(EFFECT_INTERNAL_TRANSFORM, EFFECT_TYPE_EFFECT))); + //c->media_type = MEDIA_TYPE_SOLID; } switch (panel_timeline->creating_object) { case ADD_OBJ_TITLE: c->name = "Title"; - c->effects.append(create_effect(c, get_internal_meta(EFFECT_INTERNAL_TEXT, EFFECT_TYPE_EFFECT))); + c->effects.append(create_effect(c, get_internal_meta(EFFECT_INTERNAL_TEXT, EFFECT_TYPE_EFFECT))); break; case ADD_OBJ_SOLID: c->name = "Solid Color"; - c->effects.append(create_effect(c, get_internal_meta(EFFECT_INTERNAL_SOLID, EFFECT_TYPE_EFFECT))); + c->effects.append(create_effect(c, get_internal_meta(EFFECT_INTERNAL_SOLID, EFFECT_TYPE_EFFECT))); break; case ADD_OBJ_BARS: - { + { c->name = "Bars"; - Effect* e = create_effect(c, get_internal_meta(EFFECT_INTERNAL_SOLID, EFFECT_TYPE_EFFECT)); - e->row(0)->field(0)->set_combo_index(1); + Effect* e = create_effect(c, get_internal_meta(EFFECT_INTERNAL_SOLID, EFFECT_TYPE_EFFECT)); + e->row(0)->field(0)->set_combo_index(1); c->effects.append(e); - } + } break; case ADD_OBJ_TONE: c->name = "Tone"; - c->effects.append(create_effect(c, get_internal_meta(EFFECT_INTERNAL_TONE, EFFECT_TYPE_EFFECT))); + c->effects.append(create_effect(c, get_internal_meta(EFFECT_INTERNAL_TONE, EFFECT_TYPE_EFFECT))); break; case ADD_OBJ_NOISE: c->name = "Noise"; - c->effects.append(create_effect(c, get_internal_meta(EFFECT_INTERNAL_NOISE, EFFECT_TYPE_EFFECT))); + c->effects.append(create_effect(c, get_internal_meta(EFFECT_INTERNAL_NOISE, EFFECT_TYPE_EFFECT))); break; } if (c->track >= 0) { // default audio effects (after custom effects) - c->effects.append(create_effect(c, get_internal_meta(EFFECT_INTERNAL_VOLUME, EFFECT_TYPE_EFFECT))); - c->effects.append(create_effect(c, get_internal_meta(EFFECT_INTERNAL_PAN, EFFECT_TYPE_EFFECT))); - //c->media_type = MEDIA_TYPE_TONE; + c->effects.append(create_effect(c, get_internal_meta(EFFECT_INTERNAL_VOLUME, EFFECT_TYPE_EFFECT))); + c->effects.append(create_effect(c, get_internal_meta(EFFECT_INTERNAL_PAN, EFFECT_TYPE_EFFECT))); + //c->media_type = MEDIA_TYPE_TONE; } push_undo = true; @@ -848,7 +846,7 @@ void TimelineWidget::mouseReleaseEvent(QMouseEvent *event) { } } else if (panel_timeline->moving_proc) { if (panel_timeline->ghosts.size() > 0) { - const Ghost& first_ghost = panel_timeline->ghosts.at(0); + const Ghost& first_ghost = panel_timeline->ghosts.at(0); // if we were RIPPLING, move all the clips if (panel_timeline->tool == TIMELINE_TOOL_RIPPLE) { @@ -869,13 +867,13 @@ void TimelineWidget::mouseReleaseEvent(QMouseEvent *event) { ripple_length = first_ghost.old_out - panel_timeline->ghosts.at(0).out; ripple_point = first_ghost.old_out; } - QVector ignore_clips; + QVector ignore_clips; for (int i=0;ighosts.size();i++) { const Ghost& g = panel_timeline->ghosts.at(i); // push rippled clips forward if necessary if (panel_timeline->trim_in_point) { - ignore_clips.append(sequence->clips.at(g.clip)); + ignore_clips.append(sequence->clips.at(g.clip)); panel_timeline->ghosts[i].in += ripple_length; panel_timeline->ghosts[i].out += ripple_length; } @@ -884,9 +882,9 @@ void TimelineWidget::mouseReleaseEvent(QMouseEvent *event) { ripple_point = qMin(ripple_point, comp_point); } if (!panel_timeline->trim_in_point) ripple_length = -ripple_length; - RippleCommand* rc = new RippleCommand(sequence, ripple_point, ripple_length); - rc->ignore = ignore_clips; - ca->append(rc); + RippleCommand* rc = new RippleCommand(sequence, ripple_point, ripple_length); + rc->ignore = ignore_clips; + ca->append(rc); } if (panel_timeline->tool == TIMELINE_TOOL_POINTER @@ -900,7 +898,7 @@ void TimelineWidget::mouseReleaseEvent(QMouseEvent *event) { const Ghost& g = panel_timeline->ghosts.at(i); if (g.old_in != g.in || g.old_out != g.out || g.track != g.old_track || g.clip_in != g.old_clip_in) { // create copy of clip - Clip* c = sequence->clips.at(g.clip)->copy(sequence); + Clip* c = sequence->clips.at(g.clip)->copy(sequence); c->timeline_in = g.in; c->timeline_out = g.out; @@ -917,12 +915,12 @@ void TimelineWidget::mouseReleaseEvent(QMouseEvent *event) { } } if (new_clips.size() > 0) { - panel_timeline->delete_areas_and_relink(ca, delete_areas); + panel_timeline->delete_areas_and_relink(ca, delete_areas); // relink duplicated clips panel_timeline->relink_clips_using_ids(old_clips, new_clips); - ca->append(new AddClipCommand(sequence, new_clips)); + ca->append(new AddClipCommand(sequence, new_clips)); } } else { // INSERT if holding ctrl @@ -935,11 +933,11 @@ void TimelineWidget::mouseReleaseEvent(QMouseEvent *event) { // step 1 - set clips that are moving to "undeletable" (to avoid step 2 deleting any part of them) const Ghost& g = panel_timeline->ghosts.at(i); - sequence->clips.at(g.clip)->undeletable = true; - if (g.transition != NULL) { - g.transition->parent_clip->undeletable = true; - if (g.transition->secondary_clip != NULL) g.transition->secondary_clip->undeletable = true; - } + sequence->clips.at(g.clip)->undeletable = true; + if (g.transition != NULL) { + g.transition->parent_clip->undeletable = true; + if (g.transition->secondary_clip != NULL) g.transition->secondary_clip->undeletable = true; + } Selection s; s.in = g.in; @@ -947,238 +945,238 @@ void TimelineWidget::mouseReleaseEvent(QMouseEvent *event) { s.track = g.track; delete_areas.append(s); } - panel_timeline->delete_areas_and_relink(ca, delete_areas); + panel_timeline->delete_areas_and_relink(ca, delete_areas); for (int i=0;ighosts.size();i++) { - const Ghost& g = panel_timeline->ghosts.at(i); - sequence->clips.at(g.clip)->undeletable = false; - if (g.transition != NULL) { - g.transition->parent_clip->undeletable = false; - if (g.transition->secondary_clip != NULL) g.transition->secondary_clip->undeletable = false; - } + const Ghost& g = panel_timeline->ghosts.at(i); + sequence->clips.at(g.clip)->undeletable = false; + if (g.transition != NULL) { + g.transition->parent_clip->undeletable = false; + if (g.transition->secondary_clip != NULL) g.transition->secondary_clip->undeletable = false; + } } } for (int i=0;ighosts.size();i++) { Ghost& g = panel_timeline->ghosts[i]; // step 3 - move clips - Clip* c = sequence->clips.at(g.clip); + Clip* c = sequence->clips.at(g.clip); if (g.transition == NULL) { - move_clip(ca, c, c->timeline_in + (g.in - g.old_in), c->timeline_out + (g.out - g.old_out), c->clip_in + (g.clip_in - g.old_clip_in), c->track + (g.track - g.old_track)); + move_clip(ca, c, c->timeline_in + (g.in - g.old_in), c->timeline_out + (g.out - g.old_out), c->clip_in + (g.clip_in - g.old_clip_in), c->track + (g.track - g.old_track)); // adjust transitions if we need to long new_clip_length = (g.out - g.in); - if (c->get_opening_transition() != NULL) { + if (c->get_opening_transition() != NULL) { long max_open_length = new_clip_length; - if (c->get_closing_transition() != NULL && !panel_timeline->trim_in_point) { - max_open_length -= c->get_closing_transition()->get_true_length(); + if (c->get_closing_transition() != NULL && !panel_timeline->trim_in_point) { + max_open_length -= c->get_closing_transition()->get_true_length(); } if (max_open_length <= 0) { - ca->append(new DeleteTransitionCommand(c->sequence, c->opening_transition)); - } else if (c->get_opening_transition()->get_true_length() > max_open_length) { - ca->append(new ModifyTransitionCommand(c, TA_OPENING_TRANSITION, max_open_length)); + ca->append(new DeleteTransitionCommand(c->sequence, c->opening_transition)); + } else if (c->get_opening_transition()->get_true_length() > max_open_length) { + ca->append(new ModifyTransitionCommand(c, TA_OPENING_TRANSITION, max_open_length)); } } - if (c->get_closing_transition() != NULL) { + if (c->get_closing_transition() != NULL) { long max_open_length = new_clip_length; - if (c->get_opening_transition() != NULL && panel_timeline->trim_in_point) { - max_open_length -= c->get_opening_transition()->get_true_length(); + if (c->get_opening_transition() != NULL && panel_timeline->trim_in_point) { + max_open_length -= c->get_opening_transition()->get_true_length(); } if (max_open_length <= 0) { - ca->append(new DeleteTransitionCommand(c->sequence, c->closing_transition)); - } else if (c->get_closing_transition()->get_true_length() > max_open_length) { - ca->append(new ModifyTransitionCommand(c, TA_CLOSING_TRANSITION, max_open_length)); + ca->append(new DeleteTransitionCommand(c->sequence, c->closing_transition)); + } else if (c->get_closing_transition()->get_true_length() > max_open_length) { + ca->append(new ModifyTransitionCommand(c, TA_CLOSING_TRANSITION, max_open_length)); } } } else { - bool is_opening_transition = (g.transition == c->get_opening_transition()); + bool is_opening_transition = (g.transition == c->get_opening_transition()); long new_transition_length = g.out - g.in; - if (g.transition->secondary_clip != NULL) new_transition_length >>= 1; - ca->append(new ModifyTransitionCommand(c, is_opening_transition ? TA_OPENING_TRANSITION : TA_CLOSING_TRANSITION, new_transition_length)); + if (g.transition->secondary_clip != NULL) new_transition_length >>= 1; + ca->append(new ModifyTransitionCommand(c, is_opening_transition ? TA_OPENING_TRANSITION : TA_CLOSING_TRANSITION, new_transition_length)); - long clip_length = c->getLength(); + long clip_length = c->getLength(); - if (g.transition->secondary_clip != NULL) { - if (g.in != g.old_in && !g.trimming) { - long movement = g.in - g.old_in; - move_clip(ca, g.transition->parent_clip, g.transition->parent_clip->timeline_in + movement, g.transition->parent_clip->timeline_out, g.transition->parent_clip->clip_in + movement, g.transition->parent_clip->track, false); - move_clip(ca, g.transition->secondary_clip, g.transition->secondary_clip->timeline_in, g.transition->secondary_clip->timeline_out + movement, g.transition->secondary_clip->clip_in, g.transition->secondary_clip->track, false); - } - } else if (is_opening_transition) { - if (g.in != g.old_in) { - // if transition is going to make the clip bigger, make the clip bigger - move_clip(ca, c, c->timeline_in + (g.in - g.old_in), c->timeline_out, c->clip_in + (g.clip_in - g.old_clip_in), c->track); - clip_length -= (g.in - g.old_in); - } + if (g.transition->secondary_clip != NULL) { + if (g.in != g.old_in && !g.trimming) { + long movement = g.in - g.old_in; + move_clip(ca, g.transition->parent_clip, g.transition->parent_clip->timeline_in + movement, g.transition->parent_clip->timeline_out, g.transition->parent_clip->clip_in + movement, g.transition->parent_clip->track, false); + move_clip(ca, g.transition->secondary_clip, g.transition->secondary_clip->timeline_in, g.transition->secondary_clip->timeline_out + movement, g.transition->secondary_clip->clip_in, g.transition->secondary_clip->track, false); + } + } else if (is_opening_transition) { + if (g.in != g.old_in) { + // if transition is going to make the clip bigger, make the clip bigger + move_clip(ca, c, c->timeline_in + (g.in - g.old_in), c->timeline_out, c->clip_in + (g.clip_in - g.old_clip_in), c->track); + clip_length -= (g.in - g.old_in); + } - make_room_for_transition(ca, c, TA_OPENING_TRANSITION, g.in, g.out, false); - } else { - if (g.out != g.old_out) { - // if transition is going to make the clip bigger, make the clip bigger - move_clip(ca, c, c->timeline_in, c->timeline_out + (g.out - g.old_out), c->clip_in, c->track); - clip_length += (g.out - g.old_out); - } + make_room_for_transition(ca, c, TA_OPENING_TRANSITION, g.in, g.out, false); + } else { + if (g.out != g.old_out) { + // if transition is going to make the clip bigger, make the clip bigger + move_clip(ca, c, c->timeline_in, c->timeline_out + (g.out - g.old_out), c->clip_in, c->track); + clip_length += (g.out - g.old_out); + } - make_room_for_transition(ca, c, TA_CLOSING_TRANSITION, g.in, g.out, false); - } + make_room_for_transition(ca, c, TA_CLOSING_TRANSITION, g.in, g.out, false); + } } } - } + } push_undo = true; } } else if (panel_timeline->selecting || panel_timeline->rect_select_proc) { - } else if (panel_timeline->transition_tool_proc) { - const Ghost& g = panel_timeline->ghosts.at(0); + } else if (panel_timeline->transition_tool_proc) { + const Ghost& g = panel_timeline->ghosts.at(0); - if (g.in != g.out) { - long transition_start = qMin(g.in, g.out); - long transition_end = qMax(g.in, g.out); + if (g.in != g.out) { + long transition_start = qMin(g.in, g.out); + long transition_end = qMax(g.in, g.out); - Clip* pre = sequence->clips.at(g.clip); - Clip* post = pre; + Clip* pre = sequence->clips.at(g.clip); + Clip* post = pre; - make_room_for_transition(ca, pre, panel_timeline->transition_tool_type, transition_start, transition_end, true); + make_room_for_transition(ca, pre, panel_timeline->transition_tool_type, transition_start, transition_end, true); - if (panel_timeline->transition_tool_post_clip > -1) { - post = sequence->clips.at(panel_timeline->transition_tool_post_clip); - int opposite_type = (panel_timeline->transition_tool_type == TA_OPENING_TRANSITION) ? TA_CLOSING_TRANSITION : TA_OPENING_TRANSITION; - make_room_for_transition( - ca, - post, - opposite_type, - transition_start, - transition_end, - true - ); + if (panel_timeline->transition_tool_post_clip > -1) { + post = sequence->clips.at(panel_timeline->transition_tool_post_clip); + int opposite_type = (panel_timeline->transition_tool_type == TA_OPENING_TRANSITION) ? TA_CLOSING_TRANSITION : TA_OPENING_TRANSITION; + make_room_for_transition( + ca, + post, + opposite_type, + transition_start, + transition_end, + true + ); - if (panel_timeline->transition_tool_type == TA_CLOSING_TRANSITION) { - // swap - Clip* temp = pre; - pre = post; - post = temp; - } - } + if (panel_timeline->transition_tool_type == TA_CLOSING_TRANSITION) { + // swap + Clip* temp = pre; + pre = post; + post = temp; + } + } - if (transition_start < post->timeline_in || transition_end > pre->timeline_out) { - // delete shit over there and extend timeline in - QVector areas; - Selection s; - s.track = post->track; + if (transition_start < post->timeline_in || transition_end > pre->timeline_out) { + // delete shit over there and extend timeline in + QVector areas; + Selection s; + s.track = post->track; - bool move_post = false; - bool move_pre = false; + bool move_post = false; + bool move_pre = false; - if (transition_start < post->timeline_in) { - s.in = transition_start; - s.out = post->timeline_in; - areas.append(s); - move_post = true; - } - if (transition_end > pre->timeline_out) { - s.in = pre->timeline_out; - s.out = transition_end; - areas.append(s); - move_pre = true; - } + if (transition_start < post->timeline_in) { + s.in = transition_start; + s.out = post->timeline_in; + areas.append(s); + move_post = true; + } + if (transition_end > pre->timeline_out) { + s.in = pre->timeline_out; + s.out = transition_end; + areas.append(s); + move_pre = true; + } - panel_timeline->delete_areas_and_relink(ca, areas); + panel_timeline->delete_areas_and_relink(ca, areas); - if (move_post) move_clip(ca, post, qMin(transition_start, post->timeline_in), post->timeline_out, post->clip_in - (post->timeline_in - transition_start), post->track); - if (move_pre) move_clip(ca, pre, pre->timeline_in, qMax(transition_end, pre->timeline_out), pre->clip_in, pre->track); - } + if (move_post) move_clip(ca, post, qMin(transition_start, post->timeline_in), post->timeline_out, post->clip_in - (post->timeline_in - transition_start), post->track); + if (move_pre) move_clip(ca, pre, pre->timeline_in, qMax(transition_end, pre->timeline_out), pre->clip_in, pre->track); + } - if (panel_timeline->transition_tool_post_clip > -1) { - ca->append(new AddTransitionCommand(pre, post, NULL, panel_timeline->transition_tool_meta, TA_OPENING_TRANSITION, transition_end - pre->timeline_in)); - } else { - ca->append(new AddTransitionCommand(pre, NULL, NULL, panel_timeline->transition_tool_meta, panel_timeline->transition_tool_type, transition_end - transition_start)); - } + if (panel_timeline->transition_tool_post_clip > -1) { + ca->append(new AddTransitionCommand(pre, post, NULL, panel_timeline->transition_tool_meta, TA_OPENING_TRANSITION, transition_end - pre->timeline_in)); + } else { + ca->append(new AddTransitionCommand(pre, NULL, NULL, panel_timeline->transition_tool_meta, panel_timeline->transition_tool_type, transition_end - transition_start)); + } - push_undo = true; - } - } else if (panel_timeline->splitting) { - bool split = false; - for (int i=0;isplit_tracks.size();i++) { - int split_index = getClipIndexFromCoords(panel_timeline->drag_frame_start, panel_timeline->split_tracks.at(i)); - if (split_index > -1 && panel_timeline->split_clip_and_relink(ca, split_index, panel_timeline->drag_frame_start, !alt)) { - split = true; - } - } - if (split) { push_undo = true; - } - panel_timeline->split_cache.clear(); - } + } + } else if (panel_timeline->splitting) { + bool split = false; + for (int i=0;isplit_tracks.size();i++) { + int split_index = getClipIndexFromCoords(panel_timeline->drag_frame_start, panel_timeline->split_tracks.at(i)); + if (split_index > -1 && panel_timeline->split_clip_and_relink(ca, split_index, panel_timeline->drag_frame_start, !alt)) { + split = true; + } + } + if (split) { + push_undo = true; + } + panel_timeline->split_cache.clear(); + } - // remove duplicate selections + // remove duplicate selections panel_timeline->clean_up_selections(sequence->selections); - if (selection_command != NULL) { - selection_command->new_data = sequence->selections; - ca->append(selection_command); - selection_command = NULL; - push_undo = true; - } + if (selection_command != NULL) { + selection_command->new_data = sequence->selections; + ca->append(selection_command); + selection_command = NULL; + push_undo = true; + } - if (push_undo) { - undo_stack.push(ca); - } else { - delete ca; - } + if (push_undo) { + undo_stack.push(ca); + } else { + delete ca; + } - // destroy all ghosts - panel_timeline->ghosts.clear(); + // destroy all ghosts + panel_timeline->ghosts.clear(); - // clear split tracks - panel_timeline->split_tracks.clear(); + // clear split tracks + panel_timeline->split_tracks.clear(); - panel_timeline->selecting = false; - panel_timeline->moving_proc = false; - panel_timeline->moving_init = false; - panel_timeline->splitting = false; - panel_timeline->snapped = false; - panel_timeline->rect_select_init = false; - panel_timeline->rect_select_proc = false; - panel_timeline->transition_tool_init = false; - panel_timeline->transition_tool_proc = false; - panel_timeline->hand_moving = false; - pre_clips.clear(); - post_clips.clear(); + panel_timeline->selecting = false; + panel_timeline->moving_proc = false; + panel_timeline->moving_init = false; + panel_timeline->splitting = false; + panel_timeline->snapped = false; + panel_timeline->rect_select_init = false; + panel_timeline->rect_select_proc = false; + panel_timeline->transition_tool_init = false; + panel_timeline->transition_tool_proc = false; + panel_timeline->hand_moving = false; + pre_clips.clear(); + post_clips.clear(); update_ui(true); - } - } + } + } } void TimelineWidget::init_ghosts() { for (int i=0;ighosts.size();i++) { Ghost& g = panel_timeline->ghosts[i]; - Clip* c = sequence->clips.at(g.clip); + Clip* c = sequence->clips.at(g.clip); g.track = g.old_track = c->track; - g.clip_in = g.old_clip_in = c->clip_in; + g.clip_in = g.old_clip_in = c->clip_in; - if (panel_timeline->tool == TIMELINE_TOOL_SLIP) { - g.clip_in = g.old_clip_in = c->get_clip_in_with_transition(); - g.in = g.old_in = c->get_timeline_in_with_transition(); - g.out = g.old_out = c->get_timeline_out_with_transition(); - g.ghost_length = g.old_out - g.old_in; - } else if (g.transition == NULL) { - // this ghost is for a clip - g.in = g.old_in = c->timeline_in; - g.out = g.old_out = c->timeline_out; + if (panel_timeline->tool == TIMELINE_TOOL_SLIP) { + g.clip_in = g.old_clip_in = c->get_clip_in_with_transition(); + g.in = g.old_in = c->get_timeline_in_with_transition(); + g.out = g.old_out = c->get_timeline_out_with_transition(); g.ghost_length = g.old_out - g.old_in; - } else if (g.transition == c->get_opening_transition()) { - g.in = g.old_in = c->get_timeline_in_with_transition(); - g.ghost_length = c->get_opening_transition()->get_length(); - g.out = g.old_out = g.in + g.ghost_length; - } else if (g.transition == c->get_closing_transition()) { - g.out = g.old_out = c->get_timeline_out_with_transition(); - g.ghost_length = c->get_closing_transition()->get_length(); - g.in = g.old_in = g.out - g.ghost_length; - g.clip_in = g.old_clip_in = c->clip_in + c->getLength() - c->get_closing_transition()->get_true_length(); + } else if (g.transition == NULL) { + // this ghost is for a clip + g.in = g.old_in = c->timeline_in; + g.out = g.old_out = c->timeline_out; + g.ghost_length = g.old_out - g.old_in; + } else if (g.transition == c->get_opening_transition()) { + g.in = g.old_in = c->get_timeline_in_with_transition(); + g.ghost_length = c->get_opening_transition()->get_length(); + g.out = g.old_out = g.in + g.ghost_length; + } else if (g.transition == c->get_closing_transition()) { + g.out = g.old_out = c->get_timeline_out_with_transition(); + g.ghost_length = c->get_closing_transition()->get_length(); + g.in = g.old_in = g.out - g.ghost_length; + g.clip_in = g.old_clip_in = c->clip_in + c->getLength() - c->get_closing_transition()->get_true_length(); } // used for trim ops - g.media_length = c->getMaximumLength(); + g.media_length = c->getMaximumLength(); } for (int i=0;iselections.size();i++) { Selection& s = sequence->selections[i]; @@ -1189,48 +1187,48 @@ void TimelineWidget::init_ghosts() { } void validate_transitions(Clip* c, int transition_type, long& frame_diff) { - long validator; + long validator; - if (transition_type == TA_OPENING_TRANSITION) { - // prevent from going below 0 on the timeline - validator = c->timeline_in + frame_diff; - if (validator < 0) frame_diff -= validator; + if (transition_type == TA_OPENING_TRANSITION) { + // prevent from going below 0 on the timeline + validator = c->timeline_in + frame_diff; + if (validator < 0) frame_diff -= validator; - // prevent from going below 0 for the media - validator = c->clip_in + frame_diff; - if (validator < 0) frame_diff -= validator; + // prevent from going below 0 for the media + validator = c->clip_in + frame_diff; + if (validator < 0) frame_diff -= validator; - // prevent transition from exceeding media length - validator -= c->getMaximumLength(); - if (validator > 0) frame_diff -= validator; - } else { - // prevent from going below 0 on the timeline - validator = c->timeline_out + frame_diff; - if (validator < 0) frame_diff -= validator; + // prevent transition from exceeding media length + validator -= c->getMaximumLength(); + if (validator > 0) frame_diff -= validator; + } else { + // prevent from going below 0 on the timeline + validator = c->timeline_out + frame_diff; + if (validator < 0) frame_diff -= validator; - // prevent from going below 0 for the media - validator = c->clip_in + c->getLength() + frame_diff; - if (validator < 0) frame_diff -= validator; + // prevent from going below 0 for the media + validator = c->clip_in + c->getLength() + frame_diff; + if (validator < 0) frame_diff -= validator; - // prevent transition from exceeding media length - validator -= c->getMaximumLength(); - if (validator > 0) frame_diff -= validator; - } + // prevent transition from exceeding media length + validator -= c->getMaximumLength(); + if (validator > 0) frame_diff -= validator; + } } void TimelineWidget::update_ghosts(const QPoint& mouse_pos, bool lock_frame) { - int mouse_track = getTrackFromScreenPoint(mouse_pos.y()); - long frame_diff = (lock_frame) ? 0 : panel_timeline->getTimelineFrameFromScreenPoint(mouse_pos.x()) - panel_timeline->drag_frame_start; + int mouse_track = getTrackFromScreenPoint(mouse_pos.y()); + long frame_diff = (lock_frame) ? 0 : panel_timeline->getTimelineFrameFromScreenPoint(mouse_pos.x()) - panel_timeline->drag_frame_start; int track_diff = ((panel_timeline->tool == TIMELINE_TOOL_SLIDE || panel_timeline->transition_select != TA_NO_TRANSITION) && !panel_timeline->importing) ? 0 : mouse_track - panel_timeline->drag_track_start; - long validator; + long validator; long earliest_in_point = LONG_MAX; // first try to snap long fm; - if (panel_timeline->tool != TIMELINE_TOOL_SLIP) { - // slipping doesn't move the clips so we don't bother snapping for it - for (int i=0;ighosts.size();i++) { - const Ghost& g = panel_timeline->ghosts.at(i); + if (panel_timeline->tool != TIMELINE_TOOL_SLIP) { + // slipping doesn't move the clips so we don't bother snapping for it + for (int i=0;ighosts.size();i++) { + const Ghost& g = panel_timeline->ghosts.at(i); if (panel_timeline->trim_target == -1 || g.trim_in) { fm = g.old_in + frame_diff; if (panel_timeline->snap_to_timeline(&fm, true, true, true)) { @@ -1245,37 +1243,37 @@ void TimelineWidget::update_ghosts(const QPoint& mouse_pos, bool lock_frame) { break; } } - } - } + } + } - bool clips_are_movable = (panel_timeline->tool == TIMELINE_TOOL_POINTER || panel_timeline->tool == TIMELINE_TOOL_SLIDE || panel_timeline->importing); + bool clips_are_movable = (panel_timeline->tool == TIMELINE_TOOL_POINTER || panel_timeline->tool == TIMELINE_TOOL_SLIDE || panel_timeline->importing); - // validate ghosts - long temp_frame_diff = frame_diff; // cache to see if we change it (thus cancelling any snap) + // validate ghosts + long temp_frame_diff = frame_diff; // cache to see if we change it (thus cancelling any snap) for (int i=0;ighosts.size();i++) { - const Ghost& g = panel_timeline->ghosts.at(i); - Clip* c = NULL; - if (g.clip != -1) c = sequence->clips.at(g.clip); + const Ghost& g = panel_timeline->ghosts.at(i); + Clip* c = NULL; + if (g.clip != -1) c = sequence->clips.at(g.clip); FootageStream* ms = NULL; if (g.clip != -1 && c->media != NULL && c->media->get_type() == MEDIA_TYPE_FOOTAGE) { - ms = c->media->to_footage()->get_stream_from_file_index(c->track < 0, c->media_stream); + ms = c->media->to_footage()->get_stream_from_file_index(c->track < 0, c->media_stream); } - // validate ghosts for trimming + // validate ghosts for trimming if (panel_timeline->creating) { // i feel like we might need something here but we haven't so far? } else if (panel_timeline->tool == TIMELINE_TOOL_SLIP) { - if (c->media->get_type() == MEDIA_TYPE_SEQUENCE - || (ms != NULL && !ms->infinite_length)) { - // prevent slip moving a clip below 0 clip_in - validator = g.old_clip_in - frame_diff; - if (validator < 0) frame_diff += validator; + if (c->media->get_type() == MEDIA_TYPE_SEQUENCE + || (ms != NULL && !ms->infinite_length)) { + // prevent slip moving a clip below 0 clip_in + validator = g.old_clip_in - frame_diff; + if (validator < 0) frame_diff += validator; - // prevent slip moving clip beyond media length - validator += g.ghost_length; - if (validator > g.media_length) frame_diff += validator - g.media_length; - } + // prevent slip moving clip beyond media length + validator += g.ghost_length; + if (validator > g.media_length) frame_diff += validator - g.media_length; + } } else if (g.trimming) { if (g.trim_in) { // prevent clip/transition length from being less than 1 frame long @@ -1289,12 +1287,12 @@ void TimelineWidget::update_ghosts(const QPoint& mouse_pos, bool lock_frame) { } // prevent clip_in from going below 0 - if (c->media->get_type() == MEDIA_TYPE_SEQUENCE + if (c->media->get_type() == MEDIA_TYPE_SEQUENCE || (ms != NULL && !ms->infinite_length)) { validator = g.old_clip_in + frame_diff; if (validator < 0) frame_diff -= validator; - } - } else { + } + } else { // prevent clip length from being less than 1 frame long validator = g.ghost_length + frame_diff; if (validator < 1) frame_diff += (1 - validator); @@ -1305,95 +1303,95 @@ void TimelineWidget::update_ghosts(const QPoint& mouse_pos, bool lock_frame) { validator = g.old_clip_in + g.ghost_length + frame_diff; if (validator > g.media_length) frame_diff -= validator - g.media_length; } - } + } - // prevent dual transition from going below 0 on the primary or media length on the secondary - if (g.transition != NULL && g.transition->secondary_clip != NULL) { - Clip* otc = g.transition->parent_clip; - Clip* ctc = g.transition->secondary_clip; + // prevent dual transition from going below 0 on the primary or media length on the secondary + if (g.transition != NULL && g.transition->secondary_clip != NULL) { + Clip* otc = g.transition->parent_clip; + Clip* ctc = g.transition->secondary_clip; - if (g.trim_in) { - frame_diff -= g.transition->get_true_length(); - } else { - frame_diff += g.transition->get_true_length(); - } + if (g.trim_in) { + frame_diff -= g.transition->get_true_length(); + } else { + frame_diff += g.transition->get_true_length(); + } - validate_transitions(otc, TA_OPENING_TRANSITION, frame_diff); - validate_transitions(ctc, TA_CLOSING_TRANSITION, frame_diff); + validate_transitions(otc, TA_OPENING_TRANSITION, frame_diff); + validate_transitions(ctc, TA_CLOSING_TRANSITION, frame_diff); - frame_diff = -frame_diff; - validate_transitions(otc, TA_OPENING_TRANSITION, frame_diff); - validate_transitions(ctc, TA_CLOSING_TRANSITION, frame_diff); - frame_diff = -frame_diff; + frame_diff = -frame_diff; + validate_transitions(otc, TA_OPENING_TRANSITION, frame_diff); + validate_transitions(ctc, TA_CLOSING_TRANSITION, frame_diff); + frame_diff = -frame_diff; - if (g.trim_in) { - frame_diff += g.transition->get_true_length(); - } else { - frame_diff -= g.transition->get_true_length(); - } - } + if (g.trim_in) { + frame_diff += g.transition->get_true_length(); + } else { + frame_diff -= g.transition->get_true_length(); + } + } - // ripple ops - if (panel_timeline->tool == TIMELINE_TOOL_RIPPLE) { - for (int j=0;jtool == TIMELINE_TOOL_RIPPLE) { + for (int j=0;jtrim_in_point) { - validator = post->timeline_in - frame_diff; - if (validator < 0) frame_diff += validator; - } + // prevent any rippled clip from going below 0 + if (panel_timeline->trim_in_point) { + validator = post->timeline_in - frame_diff; + if (validator < 0) frame_diff += validator; + } - // prevent any post-clips colliding with pre-clips - for (int k=0;ktrack == post->track) { - if (panel_timeline->trim_in_point) { - validator = post->timeline_in - frame_diff - pre->timeline_out; - if (validator < 0) frame_diff += validator; - } else { - validator = post->timeline_in + frame_diff - pre->timeline_out; - if (validator < 0) frame_diff -= validator; - } - } - } - } - } - } else if (clips_are_movable) { // validate ghosts for moving - // prevent clips from moving below 0 on the timeline - validator = g.old_in + frame_diff; - if (validator < 0) frame_diff -= validator; + // prevent any post-clips colliding with pre-clips + for (int k=0;ktrack == post->track) { + if (panel_timeline->trim_in_point) { + validator = post->timeline_in - frame_diff - pre->timeline_out; + if (validator < 0) frame_diff += validator; + } else { + validator = post->timeline_in + frame_diff - pre->timeline_out; + if (validator < 0) frame_diff -= validator; + } + } + } + } + } + } else if (clips_are_movable) { // validate ghosts for moving + // prevent clips from moving below 0 on the timeline + validator = g.old_in + frame_diff; + if (validator < 0) frame_diff -= validator; if (g.transition != NULL) { - if (g.transition->secondary_clip != NULL) { - // prevent dual transitions from going below 0 on the primary or above media length on the secondary + if (g.transition->secondary_clip != NULL) { + // prevent dual transitions from going below 0 on the primary or above media length on the secondary - validator = g.transition->parent_clip->get_clip_in_with_transition() + frame_diff; - if (validator < 0) frame_diff -= validator; + validator = g.transition->parent_clip->get_clip_in_with_transition() + frame_diff; + if (validator < 0) frame_diff -= validator; - validator = g.transition->secondary_clip->get_timeline_out_with_transition() - g.transition->secondary_clip->get_timeline_in_with_transition() - g.transition->get_length() + g.transition->secondary_clip->get_clip_in_with_transition() + frame_diff; - if (validator < 0) frame_diff -= validator; + validator = g.transition->secondary_clip->get_timeline_out_with_transition() - g.transition->secondary_clip->get_timeline_in_with_transition() - g.transition->get_length() + g.transition->secondary_clip->get_clip_in_with_transition() + frame_diff; + if (validator < 0) frame_diff -= validator; - validator = g.transition->parent_clip->clip_in + frame_diff - g.transition->parent_clip->getMaximumLength() + g.transition->get_true_length(); - if (validator > 0) frame_diff -= validator; + validator = g.transition->parent_clip->clip_in + frame_diff - g.transition->parent_clip->getMaximumLength() + g.transition->get_true_length(); + if (validator > 0) frame_diff -= validator; - validator = g.transition->secondary_clip->get_timeline_out_with_transition() - g.transition->secondary_clip->get_timeline_in_with_transition() + g.transition->secondary_clip->get_clip_in_with_transition() + frame_diff - g.transition->secondary_clip->getMaximumLength(); - if (validator > 0) frame_diff -= validator; - } else { - // prevent clip_in from going below 0 - if (c->media->get_type() == MEDIA_TYPE_SEQUENCE - || (ms != NULL && !ms->infinite_length)) { - validator = g.old_clip_in + frame_diff; - if (validator < 0) frame_diff -= validator; - } + validator = g.transition->secondary_clip->get_timeline_out_with_transition() - g.transition->secondary_clip->get_timeline_in_with_transition() + g.transition->secondary_clip->get_clip_in_with_transition() + frame_diff - g.transition->secondary_clip->getMaximumLength(); + if (validator > 0) frame_diff -= validator; + } else { + // prevent clip_in from going below 0 + if (c->media->get_type() == MEDIA_TYPE_SEQUENCE + || (ms != NULL && !ms->infinite_length)) { + validator = g.old_clip_in + frame_diff; + if (validator < 0) frame_diff -= validator; + } - // prevent clip length exceeding media length - if (c->media->get_type() == MEDIA_TYPE_SEQUENCE - || (ms != NULL && !ms->infinite_length)) { - validator = g.old_clip_in + g.ghost_length + frame_diff; - if (validator > g.media_length) frame_diff -= validator - g.media_length; - } - } + // prevent clip length exceeding media length + if (c->media->get_type() == MEDIA_TYPE_SEQUENCE + || (ms != NULL && !ms->infinite_length)) { + validator = g.old_clip_in + g.ghost_length + frame_diff; + if (validator > g.media_length) frame_diff -= validator - g.media_length; + } + } } // prevent clips from crossing tracks @@ -1406,121 +1404,121 @@ void TimelineWidget::update_ghosts(const QPoint& mouse_pos, bool lock_frame) { } } } - } else if (panel_timeline->tool == TIMELINE_TOOL_TRANSITION) { - if (panel_timeline->transition_tool_post_clip == -1) { - validate_transitions(c, panel_timeline->transition_tool_type, frame_diff); - } else { - Clip* otc = c; // open transition clip - Clip* ctc = sequence->clips.at(panel_timeline->transition_tool_post_clip); // close transition clip + } else if (panel_timeline->tool == TIMELINE_TOOL_TRANSITION) { + if (panel_timeline->transition_tool_post_clip == -1) { + validate_transitions(c, panel_timeline->transition_tool_type, frame_diff); + } else { + Clip* otc = c; // open transition clip + Clip* ctc = sequence->clips.at(panel_timeline->transition_tool_post_clip); // close transition clip - if (panel_timeline->transition_tool_type == TA_CLOSING_TRANSITION) { - // swap - Clip* temp = otc; - otc = ctc; - ctc = temp; - } + if (panel_timeline->transition_tool_type == TA_CLOSING_TRANSITION) { + // swap + Clip* temp = otc; + otc = ctc; + ctc = temp; + } - // always gets a positive frame_diff - validate_transitions(otc, TA_OPENING_TRANSITION, frame_diff); - validate_transitions(ctc, TA_CLOSING_TRANSITION, frame_diff); + // always gets a positive frame_diff + validate_transitions(otc, TA_OPENING_TRANSITION, frame_diff); + validate_transitions(ctc, TA_CLOSING_TRANSITION, frame_diff); - // always gets a negative frame_diff - frame_diff = -frame_diff; - validate_transitions(otc, TA_OPENING_TRANSITION, frame_diff); - validate_transitions(ctc, TA_CLOSING_TRANSITION, frame_diff); - frame_diff = -frame_diff; - } - } - } - if (temp_frame_diff != frame_diff) panel_timeline->snapped = false; + // always gets a negative frame_diff + frame_diff = -frame_diff; + validate_transitions(otc, TA_OPENING_TRANSITION, frame_diff); + validate_transitions(ctc, TA_CLOSING_TRANSITION, frame_diff); + frame_diff = -frame_diff; + } + } + } + if (temp_frame_diff != frame_diff) panel_timeline->snapped = false; - // apply changes to ghosts - for (int i=0;ighosts.size();i++) { - Ghost& g = panel_timeline->ghosts[i]; + // apply changes to ghosts + for (int i=0;ighosts.size();i++) { + Ghost& g = panel_timeline->ghosts[i]; - if (panel_timeline->tool == TIMELINE_TOOL_SLIP) { - g.clip_in = g.old_clip_in - frame_diff; - } else if (g.trimming) { - long ghost_diff = frame_diff; + if (panel_timeline->tool == TIMELINE_TOOL_SLIP) { + g.clip_in = g.old_clip_in - frame_diff; + } else if (g.trimming) { + long ghost_diff = frame_diff; - // prevent trimming clips from overlapping each other - for (int j=0;jghosts.size();j++) { - const Ghost& comp = panel_timeline->ghosts.at(j); - if (i != j && g.track == comp.track) { - long validator; - if (g.trim_in && comp.out < g.out) { - validator = (g.old_in + ghost_diff) - comp.out; - if (validator < 0) ghost_diff -= validator; - } else if (comp.in > g.in) { - validator = (g.old_out + ghost_diff) - comp.in; - if (validator > 0) ghost_diff -= validator; - } - } - } + // prevent trimming clips from overlapping each other + for (int j=0;jghosts.size();j++) { + const Ghost& comp = panel_timeline->ghosts.at(j); + if (i != j && g.track == comp.track) { + long validator; + if (g.trim_in && comp.out < g.out) { + validator = (g.old_in + ghost_diff) - comp.out; + if (validator < 0) ghost_diff -= validator; + } else if (comp.in > g.in) { + validator = (g.old_out + ghost_diff) - comp.in; + if (validator > 0) ghost_diff -= validator; + } + } + } - // apply changes - if (g.transition != NULL && g.transition->secondary_clip != NULL) { - if (g.trim_in) ghost_diff = -ghost_diff; - g.in = g.old_in - ghost_diff; - g.out = g.old_out + ghost_diff; - } else if (g.trim_in) { - g.in = g.old_in + ghost_diff; - g.clip_in = g.old_clip_in + ghost_diff; - } else { - g.out = g.old_out + ghost_diff; - } - } else if (clips_are_movable) { - g.track = g.old_track; - g.in = g.old_in + frame_diff; - g.out = g.old_out + frame_diff; + // apply changes + if (g.transition != NULL && g.transition->secondary_clip != NULL) { + if (g.trim_in) ghost_diff = -ghost_diff; + g.in = g.old_in - ghost_diff; + g.out = g.old_out + ghost_diff; + } else if (g.trim_in) { + g.in = g.old_in + ghost_diff; + g.clip_in = g.old_clip_in + ghost_diff; + } else { + g.out = g.old_out + ghost_diff; + } + } else if (clips_are_movable) { + g.track = g.old_track; + g.in = g.old_in + frame_diff; + g.out = g.old_out + frame_diff; - if (g.transition != NULL && g.transition == sequence->clips.at(g.clip)->get_opening_transition()) { + if (g.transition != NULL && g.transition == sequence->clips.at(g.clip)->get_opening_transition()) { g.clip_in = g.old_clip_in + frame_diff; } - if (panel_timeline->importing) { - if ((panel_timeline->video_ghosts && mouse_track < 0) - || (panel_timeline->audio_ghosts && mouse_track >= 0)) { - int abs_track_diff = abs(track_diff); - if (g.old_track < 0) { // clip is video - g.track -= abs_track_diff; - } else { // clip is audio - g.track += abs_track_diff; - } - } + if (panel_timeline->importing) { + if ((panel_timeline->video_ghosts && mouse_track < 0) + || (panel_timeline->audio_ghosts && mouse_track >= 0)) { + int abs_track_diff = abs(track_diff); + if (g.old_track < 0) { // clip is video + g.track -= abs_track_diff; + } else { // clip is audio + g.track += abs_track_diff; + } + } } else if (same_sign(g.old_track, panel_timeline->drag_track_start)) { - g.track += track_diff; - } - } else if (panel_timeline->tool == TIMELINE_TOOL_TRANSITION) { - if (panel_timeline->transition_tool_post_clip > -1) { - g.in = g.old_in - frame_diff; - g.out = g.old_out + frame_diff; - } else if (panel_timeline->transition_tool_type == TA_OPENING_TRANSITION) { - g.out = g.old_out + frame_diff; - } else { - g.in = g.old_in + frame_diff; - } - } + g.track += track_diff; + } + } else if (panel_timeline->tool == TIMELINE_TOOL_TRANSITION) { + if (panel_timeline->transition_tool_post_clip > -1) { + g.in = g.old_in - frame_diff; + g.out = g.old_out + frame_diff; + } else if (panel_timeline->transition_tool_type == TA_OPENING_TRANSITION) { + g.out = g.old_out + frame_diff; + } else { + g.in = g.old_in + frame_diff; + } + } earliest_in_point = qMin(earliest_in_point, g.in); - } + } - // apply changes to selections - if (panel_timeline->tool != TIMELINE_TOOL_SLIP && !panel_timeline->importing && !panel_timeline->creating) { + // apply changes to selections + if (panel_timeline->tool != TIMELINE_TOOL_SLIP && !panel_timeline->importing && !panel_timeline->creating) { for (int i=0;iselections.size();i++) { Selection& s = sequence->selections[i]; - if (panel_timeline->trim_target > -1) { - if (panel_timeline->trim_in_point) { - s.in = s.old_in + frame_diff; - } else { - s.out = s.old_out + frame_diff; - } + if (panel_timeline->trim_target > -1) { + if (panel_timeline->trim_in_point) { + s.in = s.old_in + frame_diff; + } else { + s.out = s.old_out + frame_diff; + } } else if (clips_are_movable) { for (int i=0;iselections.size();i++) { Selection& s = sequence->selections[i]; - s.in = s.old_in + frame_diff; - s.out = s.old_out + frame_diff; - s.track = s.old_track; + s.in = s.old_in + frame_diff; + s.out = s.old_out + frame_diff; + s.track = s.old_track; if (panel_timeline->importing) { int abs_track_diff = abs(track_diff); @@ -1532,14 +1530,14 @@ void TimelineWidget::update_ghosts(const QPoint& mouse_pos, bool lock_frame) { } else { if (same_sign(s.track, panel_timeline->drag_track_start)) s.track += track_diff; } - } - } - } - } + } + } + } + } if (panel_timeline->importing) { QToolTip::showText(mapToGlobal(mouse_pos), frame_to_timecode(earliest_in_point, config.timecode_view, sequence->frame_rate)); - } else { + } else { QString tip = ((frame_diff < 0) ? "-" : "+") + frame_to_timecode(qAbs(frame_diff), config.timecode_view, sequence->frame_rate); if (panel_timeline->trim_target > -1) { // find which clip is being moved @@ -1567,408 +1565,408 @@ void TimelineWidget::update_ghosts(const QPoint& mouse_pos, bool lock_frame) { } void TimelineWidget::mouseMoveEvent(QMouseEvent *event) { - tooltip_timer.stop(); - if (sequence != NULL) { - bool alt = (event->modifiers() & Qt::AltModifier); + tooltip_timer.stop(); + if (sequence != NULL) { + bool alt = (event->modifiers() & Qt::AltModifier); - panel_timeline->cursor_frame = panel_timeline->getTimelineFrameFromScreenPoint(event->pos().x()); - panel_timeline->cursor_track = getTrackFromScreenPoint(event->pos().y()); + panel_timeline->cursor_frame = panel_timeline->getTimelineFrameFromScreenPoint(event->pos().x()); + panel_timeline->cursor_track = getTrackFromScreenPoint(event->pos().y()); panel_timeline->move_insert = ((event->modifiers() & Qt::ControlModifier) && (panel_timeline->tool == TIMELINE_TOOL_POINTER || panel_timeline->importing || panel_timeline->creating)); - if (!panel_timeline->moving_init) track_resizing = false; + if (!panel_timeline->moving_init) track_resizing = false; if (isLiveEditing()) { panel_timeline->snap_to_timeline(&panel_timeline->cursor_frame, !config.edit_tool_also_seeks || !panel_timeline->selecting, true, true); - } - if (panel_timeline->selecting) { - int selection_count = 1 + qMax(panel_timeline->cursor_track, panel_timeline->drag_track_start) - qMin(panel_timeline->cursor_track, panel_timeline->drag_track_start) + panel_timeline->selection_offset; + } + if (panel_timeline->selecting) { + int selection_count = 1 + qMax(panel_timeline->cursor_track, panel_timeline->drag_track_start) - qMin(panel_timeline->cursor_track, panel_timeline->drag_track_start) + panel_timeline->selection_offset; if (sequence->selections.size() != selection_count) { sequence->selections.resize(selection_count); - } - int minimum_selection_track = qMin(panel_timeline->cursor_track, panel_timeline->drag_track_start); - for (int i=panel_timeline->selection_offset;icursor_track, panel_timeline->drag_track_start); + for (int i=panel_timeline->selection_offset;iselections[i]; - s.track = minimum_selection_track + i - panel_timeline->selection_offset; - long in = panel_timeline->drag_frame_start; - long out = panel_timeline->cursor_frame; - s.in = qMin(in, out); - s.out = qMax(in, out); - } + s.track = minimum_selection_track + i - panel_timeline->selection_offset; + long in = panel_timeline->drag_frame_start; + long out = panel_timeline->cursor_frame; + s.in = qMin(in, out); + s.out = qMax(in, out); + } - // select linked clips too - if (config.edit_tool_selects_links) { - for (int j=0;jclips.size();j++) { - Clip* c = sequence->clips.at(j); + // select linked clips too + if (config.edit_tool_selects_links) { + for (int j=0;jclips.size();j++) { + Clip* c = sequence->clips.at(j); for (int k=0;kselections.size();k++) { const Selection& s = sequence->selections.at(k); - if (!(c->timeline_in < s.in && c->timeline_out < s.in) && - !(c->timeline_in > s.out && c->timeline_out > s.out) && - c->track == s.track) { + if (!(c->timeline_in < s.in && c->timeline_out < s.in) && + !(c->timeline_in > s.out && c->timeline_out > s.out) && + c->track == s.track) { - QVector linked_tracks = panel_timeline->get_tracks_of_linked_clips(j); - for (int k=0;k linked_tracks = panel_timeline->get_tracks_of_linked_clips(j); + for (int k=0;kselections.size();l++) { const Selection& test_sel = sequence->selections.at(l); - if (test_sel.track == linked_tracks.at(k) && - test_sel.in == s.in && - test_sel.out == s.out) { - found = true; - break; - } - } - if (!found) { - Selection link_sel; - link_sel.in = s.in; - link_sel.out = s.out; - link_sel.track = linked_tracks.at(k); + if (test_sel.track == linked_tracks.at(k) && + test_sel.in == s.in && + test_sel.out == s.out) { + found = true; + break; + } + } + if (!found) { + Selection link_sel; + link_sel.in = s.in; + link_sel.out = s.out; + link_sel.track = linked_tracks.at(k); sequence->selections.append(link_sel); - } - } + } + } - break; - } - } - } - } + break; + } + } + } + } - if (config.edit_tool_also_seeks) { + if (config.edit_tool_also_seeks) { panel_sequence_viewer->seek(qMin(panel_timeline->drag_frame_start, panel_timeline->cursor_frame)); } else { panel_timeline->repaint_timeline(); - } - } else if (panel_timeline->hand_moving) { - panel_timeline->block_repaints = true; - panel_timeline->ui->horizontalScrollBar->setValue(panel_timeline->ui->horizontalScrollBar->value() + panel_timeline->drag_x_start - event->pos().x()); - scrollBar->setValue(scrollBar->value() + panel_timeline->drag_y_start - event->pos().y()); - panel_timeline->block_repaints = false; + } + } else if (panel_timeline->hand_moving) { + panel_timeline->block_repaints = true; + panel_timeline->ui->horizontalScrollBar->setValue(panel_timeline->ui->horizontalScrollBar->value() + panel_timeline->drag_x_start - event->pos().x()); + scrollBar->setValue(scrollBar->value() + panel_timeline->drag_y_start - event->pos().y()); + panel_timeline->block_repaints = false; - panel_timeline->repaint_timeline(); + panel_timeline->repaint_timeline(); - panel_timeline->drag_x_start = event->pos().x(); - panel_timeline->drag_y_start = event->pos().y(); - } else if (panel_timeline->moving_init) { - if (track_resizing) { - int diff = track_resize_mouse_cache - event->pos().y(); - int new_height = track_resize_old_value; - if (bottom_align) { - new_height += diff; - } else { - new_height -= diff; - } - if (new_height < TRACK_MIN_HEIGHT) new_height = TRACK_MIN_HEIGHT; - panel_timeline->calculate_track_height(track_target, new_height); + panel_timeline->drag_x_start = event->pos().x(); + panel_timeline->drag_y_start = event->pos().y(); + } else if (panel_timeline->moving_init) { + if (track_resizing) { + int diff = track_resize_mouse_cache - event->pos().y(); + int new_height = track_resize_old_value; + if (bottom_align) { + new_height += diff; + } else { + new_height -= diff; + } + if (new_height < TRACK_MIN_HEIGHT) new_height = TRACK_MIN_HEIGHT; + panel_timeline->calculate_track_height(track_target, new_height); update(); - } else if (panel_timeline->moving_proc) { - update_ghosts(event->pos(), event->modifiers() & Qt::ShiftModifier); - } else { - // set up movement - // create ghosts - for (int i=0;iclips.size();i++) { - Clip* c = sequence->clips.at(i); + } else if (panel_timeline->moving_proc) { + update_ghosts(event->pos(), event->modifiers() & Qt::ShiftModifier); + } else { + // set up movement + // create ghosts + for (int i=0;iclips.size();i++) { + Clip* c = sequence->clips.at(i); if (c != NULL) { - Ghost g; + Ghost g; g.transition = NULL; bool add = panel_timeline->is_clip_selected(c, true); // if a whole clip is not selected, maybe just a transition is - if (panel_timeline->tool == TIMELINE_TOOL_POINTER && (c->get_opening_transition() != NULL || c->get_closing_transition() != NULL)) { + if (panel_timeline->tool == TIMELINE_TOOL_POINTER && (c->get_opening_transition() != NULL || c->get_closing_transition() != NULL)) { // check if any selections contain the whole clip or transition for (int j=0;jselections.size();j++) { const Selection& s = sequence->selections.at(j); if (s.track == c->track) { - if (selection_contains_transition(s, c, TA_OPENING_TRANSITION)) { - g.transition = c->get_opening_transition(); + if (selection_contains_transition(s, c, TA_OPENING_TRANSITION)) { + g.transition = c->get_opening_transition(); add = true; break; - } else if (selection_contains_transition(s, c, TA_CLOSING_TRANSITION)) { - g.transition = c->get_closing_transition(); + } else if (selection_contains_transition(s, c, TA_CLOSING_TRANSITION)) { + g.transition = c->get_closing_transition(); add = true; break; } } } - } + } - if (add && g.transition != NULL) { - // check for duplicate transitions - for (int j=0;jghosts.size();j++) { - if (panel_timeline->ghosts.at(j).transition == g.transition) { - add = false; - break; - } - } - } + if (add && g.transition != NULL) { + // check for duplicate transitions + for (int j=0;jghosts.size();j++) { + if (panel_timeline->ghosts.at(j).transition == g.transition) { + add = false; + break; + } + } + } - if (add) { + if (add) { g.clip = i; g.trimming = (panel_timeline->trim_target > -1); g.trim_in = panel_timeline->trim_in_point; panel_timeline->ghosts.append(g); } - } - } + } + } - int size = panel_timeline->ghosts.size(); - if (panel_timeline->tool == TIMELINE_TOOL_ROLLING) { - for (int i=0;iclips.at(panel_timeline->ghosts.at(i).clip); + int size = panel_timeline->ghosts.size(); + if (panel_timeline->tool == TIMELINE_TOOL_ROLLING) { + for (int i=0;iclips.at(panel_timeline->ghosts.at(i).clip); - // see if any ghosts are touching, in which case flip them - for (int k=0;kclips.at(panel_timeline->ghosts.at(k).clip); - if ((panel_timeline->trim_in_point && comp_clip->timeline_out == ghost_clip->timeline_in) || - (!panel_timeline->trim_in_point && comp_clip->timeline_in == ghost_clip->timeline_out)) { - panel_timeline->ghosts[k].trim_in = !panel_timeline->trim_in_point; - } - } - } + // see if any ghosts are touching, in which case flip them + for (int k=0;kclips.at(panel_timeline->ghosts.at(k).clip); + if ((panel_timeline->trim_in_point && comp_clip->timeline_out == ghost_clip->timeline_in) || + (!panel_timeline->trim_in_point && comp_clip->timeline_in == ghost_clip->timeline_out)) { + panel_timeline->ghosts[k].trim_in = !panel_timeline->trim_in_point; + } + } + } - // then look for other clips we're touching - for (int i=0;ighosts.at(i); - Clip* ghost_clip = sequence->clips.at(g.clip); - for (int j=0;jclips.size();j++) { - Clip* comp_clip = sequence->clips.at(j); - if (comp_clip->track == ghost_clip->track) { - if ((panel_timeline->trim_in_point && comp_clip->timeline_out == ghost_clip->timeline_in) || - (!panel_timeline->trim_in_point && comp_clip->timeline_in == ghost_clip->timeline_out)) { - // see if this clip is already selected, and if so just switch the trim_in - bool found = false; - int duplicate_ghost_index; - for (duplicate_ghost_index=0;duplicate_ghost_indexghosts.at(duplicate_ghost_index).clip == j) { - found = true; - break; - } - } - if (g.trim_in == panel_timeline->trim_in_point) { - if (!found) { - // add ghost for this clip with opposite trim_in - Ghost gh; + // then look for other clips we're touching + for (int i=0;ighosts.at(i); + Clip* ghost_clip = sequence->clips.at(g.clip); + for (int j=0;jclips.size();j++) { + Clip* comp_clip = sequence->clips.at(j); + if (comp_clip->track == ghost_clip->track) { + if ((panel_timeline->trim_in_point && comp_clip->timeline_out == ghost_clip->timeline_in) || + (!panel_timeline->trim_in_point && comp_clip->timeline_in == ghost_clip->timeline_out)) { + // see if this clip is already selected, and if so just switch the trim_in + bool found = false; + int duplicate_ghost_index; + for (duplicate_ghost_index=0;duplicate_ghost_indexghosts.at(duplicate_ghost_index).clip == j) { + found = true; + break; + } + } + if (g.trim_in == panel_timeline->trim_in_point) { + if (!found) { + // add ghost for this clip with opposite trim_in + Ghost gh; gh.transition = NULL; - gh.clip = j; - gh.trimming = (panel_timeline->trim_target > -1); - gh.trim_in = !panel_timeline->trim_in_point; - panel_timeline->ghosts.append(gh); - } - } else { - if (found) { - panel_timeline->ghosts.removeAt(duplicate_ghost_index); - size--; - if (duplicate_ghost_index < i) i--; - } - } - } - } - } - } - } else if (panel_timeline->tool == TIMELINE_TOOL_SLIDE) { - for (int i=0;ighosts.at(i); - Clip* ghost_clip = sequence->clips.at(g.clip); - panel_timeline->ghosts[i].trimming = false; - for (int j=0;jclips.size();j++) { - Clip* c = sequence->clips.at(j); + gh.clip = j; + gh.trimming = (panel_timeline->trim_target > -1); + gh.trim_in = !panel_timeline->trim_in_point; + panel_timeline->ghosts.append(gh); + } + } else { + if (found) { + panel_timeline->ghosts.removeAt(duplicate_ghost_index); + size--; + if (duplicate_ghost_index < i) i--; + } + } + } + } + } + } + } else if (panel_timeline->tool == TIMELINE_TOOL_SLIDE) { + for (int i=0;ighosts.at(i); + Clip* ghost_clip = sequence->clips.at(g.clip); + panel_timeline->ghosts[i].trimming = false; + for (int j=0;jclips.size();j++) { + Clip* c = sequence->clips.at(j); if (c != NULL && c->track == ghost_clip->track) { - bool found = false; - for (int k=0;kghosts.at(k).clip == j) { - found = true; - break; - } - } - if (!found) { - bool is_in = (c->timeline_in == ghost_clip->timeline_out); - if (is_in || c->timeline_out == ghost_clip->timeline_in) { - Ghost gh; + bool found = false; + for (int k=0;kghosts.at(k).clip == j) { + found = true; + break; + } + } + if (!found) { + bool is_in = (c->timeline_in == ghost_clip->timeline_out); + if (is_in || c->timeline_out == ghost_clip->timeline_in) { + Ghost gh; gh.transition = NULL; - gh.clip = j; - gh.trimming = true; - gh.trim_in = is_in; - panel_timeline->ghosts.append(gh); - } - } - } - } - } - } + gh.clip = j; + gh.trimming = true; + gh.trim_in = is_in; + panel_timeline->ghosts.append(gh); + } + } + } + } + } + } - init_ghosts(); + init_ghosts(); - // ripple edit prep - if (panel_timeline->tool == TIMELINE_TOOL_RIPPLE) { - QVector axis_ghosts; - for (int i=0;ighosts.size();i++) { - Clip* c = sequence->clips.at(panel_timeline->ghosts.at(i).clip); - bool found = false; - for (int j=0;jtrack == cc->track && - ((panel_timeline->trim_in_point && c->timeline_in < cc->timeline_in) || - (!panel_timeline->trim_in_point && c->timeline_out > cc->timeline_out))) { - axis_ghosts[j] = c; - found = true; - break; - } - } - if (!found) { - axis_ghosts.append(c); - } - } + // ripple edit prep + if (panel_timeline->tool == TIMELINE_TOOL_RIPPLE) { + QVector axis_ghosts; + for (int i=0;ighosts.size();i++) { + Clip* c = sequence->clips.at(panel_timeline->ghosts.at(i).clip); + bool found = false; + for (int j=0;jtrack == cc->track && + ((panel_timeline->trim_in_point && c->timeline_in < cc->timeline_in) || + (!panel_timeline->trim_in_point && c->timeline_out > cc->timeline_out))) { + axis_ghosts[j] = c; + found = true; + break; + } + } + if (!found) { + axis_ghosts.append(c); + } + } - for (int i=0;iclips.size();i++) { - Clip* c = sequence->clips.at(i); - if (c != NULL && !panel_timeline->is_clip_selected(c, true)) { - for (int j=0;jtrim_in_point) ? axis->timeline_in : axis->timeline_out; - bool clip_is_pre = (c->timeline_in < comp_point); - QVector& clip_list = clip_is_pre ? pre_clips : post_clips; - bool found = false; - for (int k=0;ktrack == c->track) { - if (clip_is_pre == (c->timeline_in > cached->timeline_in)) { - clip_list[k] = c; - } - found = true; - break; - } - } - if (!found) { - clip_list.append(c); - } - } - } - } - } + for (int i=0;iclips.size();i++) { + Clip* c = sequence->clips.at(i); + if (c != NULL && !panel_timeline->is_clip_selected(c, true)) { + for (int j=0;jtrim_in_point) ? axis->timeline_in : axis->timeline_out; + bool clip_is_pre = (c->timeline_in < comp_point); + QVector& clip_list = clip_is_pre ? pre_clips : post_clips; + bool found = false; + for (int k=0;ktrack == c->track) { + if (clip_is_pre == (c->timeline_in > cached->timeline_in)) { + clip_list[k] = c; + } + found = true; + break; + } + } + if (!found) { + clip_list.append(c); + } + } + } + } + } - // store selections - selection_command = new SetSelectionsCommand(sequence); - selection_command->old_data = sequence->selections; + // store selections + selection_command = new SetSelectionsCommand(sequence); + selection_command->old_data = sequence->selections; - panel_timeline->moving_proc = true; - } - update_ui(false); - } else if (panel_timeline->splitting) { - int track_start = qMin(panel_timeline->cursor_track, panel_timeline->drag_track_start); - int track_end = qMax(panel_timeline->cursor_track, panel_timeline->drag_track_start); - int track_size = 1 + track_end - track_start; - panel_timeline->split_tracks.resize(track_size); - for (int i=0;isplit_tracks[i] = track_start + i; - } + panel_timeline->moving_proc = true; + } + update_ui(false); + } else if (panel_timeline->splitting) { + int track_start = qMin(panel_timeline->cursor_track, panel_timeline->drag_track_start); + int track_end = qMax(panel_timeline->cursor_track, panel_timeline->drag_track_start); + int track_size = 1 + track_end - track_start; + panel_timeline->split_tracks.resize(track_size); + for (int i=0;isplit_tracks[i] = track_start + i; + } - if (!alt) { - for (int i=0;idrag_frame_start, panel_timeline->split_tracks[i]); - if (clip_index > -1) { - QVector tracks = panel_timeline->get_tracks_of_linked_clips(clip_index); - for (int j=0;j track_end) { - panel_timeline->split_tracks.append(tracks.at(j)); - } - } - } - } - } - update_ui(false); - } else if (panel_timeline->rect_select_init) { - if (panel_timeline->rect_select_proc) { - panel_timeline->rect_select_w = event->pos().x() - panel_timeline->rect_select_x; - panel_timeline->rect_select_h = event->pos().y() - panel_timeline->rect_select_y; - if (bottom_align) panel_timeline->rect_select_h -= height(); + if (!alt) { + for (int i=0;idrag_frame_start, panel_timeline->split_tracks[i]); + if (clip_index > -1) { + QVector tracks = panel_timeline->get_tracks_of_linked_clips(clip_index); + for (int j=0;j track_end) { + panel_timeline->split_tracks.append(tracks.at(j)); + } + } + } + } + } + update_ui(false); + } else if (panel_timeline->rect_select_init) { + if (panel_timeline->rect_select_proc) { + panel_timeline->rect_select_w = event->pos().x() - panel_timeline->rect_select_x; + panel_timeline->rect_select_h = event->pos().y() - panel_timeline->rect_select_y; + if (bottom_align) panel_timeline->rect_select_h -= height(); long frame_start = panel_timeline->getTimelineFrameFromScreenPoint(panel_timeline->rect_select_x); long frame_end = panel_timeline->getTimelineFrameFromScreenPoint(event->pos().x()); - long frame_min = qMin(frame_start, frame_end); - long frame_max = qMax(frame_start, frame_end); + long frame_min = qMin(frame_start, frame_end); + long frame_max = qMax(frame_start, frame_end); - int rsy = panel_timeline->rect_select_y; - if (bottom_align) rsy += height(); - int track_start = getTrackFromScreenPoint(rsy); - int track_end = getTrackFromScreenPoint(event->pos().y()); - int track_min = qMin(track_start, track_end); - int track_max = qMax(track_start, track_end); + int rsy = panel_timeline->rect_select_y; + if (bottom_align) rsy += height(); + int track_start = getTrackFromScreenPoint(rsy); + int track_end = getTrackFromScreenPoint(event->pos().y()); + int track_min = qMin(track_start, track_end); + int track_max = qMax(track_start, track_end); - QVector selected_clips; - for (int i=0;iclips.size();i++) { - Clip* clip = sequence->clips.at(i); - if (clip != NULL && - clip->track >= track_min && - clip->track <= track_max && - !(clip->timeline_in < frame_min && clip->timeline_out < frame_min) && - !(clip->timeline_in > frame_max && clip->timeline_out > frame_max)) { - QVector session_clips; - session_clips.append(clip); + QVector selected_clips; + for (int i=0;iclips.size();i++) { + Clip* clip = sequence->clips.at(i); + if (clip != NULL && + clip->track >= track_min && + clip->track <= track_max && + !(clip->timeline_in < frame_min && clip->timeline_out < frame_min) && + !(clip->timeline_in > frame_max && clip->timeline_out > frame_max)) { + QVector session_clips; + session_clips.append(clip); - if (!alt) { - for (int j=0;jlinked.size();j++) { - session_clips.append(sequence->clips.at(clip->linked.at(j))); - } - } + if (!alt) { + for (int j=0;jlinked.size();j++) { + session_clips.append(sequence->clips.at(clip->linked.at(j))); + } + } - for (int j=0;jselections.resize(selected_clips.size() + panel_timeline->selection_offset); - for (int i=0;iselections[i+panel_timeline->selection_offset]; - Clip* clip = selected_clips.at(i); - s.old_in = s.in = clip->timeline_in; - s.old_out = s.out = clip->timeline_out; - s.old_track = s.track = clip->track; - } + Clip* clip = selected_clips.at(i); + s.old_in = s.in = clip->timeline_in; + s.old_out = s.out = clip->timeline_out; + s.old_track = s.track = clip->track; + } panel_timeline->repaint_timeline(); - } else { - panel_timeline->rect_select_x = event->pos().x(); - panel_timeline->rect_select_y = event->pos().y(); - if (bottom_align) panel_timeline->rect_select_y -= height(); - panel_timeline->rect_select_w = 0; - panel_timeline->rect_select_h = 0; - panel_timeline->rect_select_proc = true; - } + } else { + panel_timeline->rect_select_x = event->pos().x(); + panel_timeline->rect_select_y = event->pos().y(); + if (bottom_align) panel_timeline->rect_select_y -= height(); + panel_timeline->rect_select_w = 0; + panel_timeline->rect_select_h = 0; + panel_timeline->rect_select_proc = true; + } } else if (isLiveEditing()) { // redraw because we have a cursor panel_timeline->repaint_timeline(); - } else if (panel_timeline->tool == TIMELINE_TOOL_POINTER || - panel_timeline->tool == TIMELINE_TOOL_RIPPLE || - panel_timeline->tool == TIMELINE_TOOL_ROLLING) { + } else if (panel_timeline->tool == TIMELINE_TOOL_POINTER || + panel_timeline->tool == TIMELINE_TOOL_RIPPLE || + panel_timeline->tool == TIMELINE_TOOL_ROLLING) { QToolTip::hideText(); - QPoint pos = event->pos(); + QPoint pos = event->pos(); - int lim = 5; - int mouse_track = getTrackFromScreenPoint(pos.y()); + int lim = 5; + int mouse_track = getTrackFromScreenPoint(pos.y()); long mouse_frame_lower = panel_timeline->getTimelineFrameFromScreenPoint(pos.x()-lim)-1; long mouse_frame_upper = panel_timeline->getTimelineFrameFromScreenPoint(pos.x()+lim)+1; - bool found = false; - bool cursor_contains_clip = false; - int closeness = INT_MAX; + bool found = false; + bool cursor_contains_clip = false; + int closeness = INT_MAX; int min_track = INT_MAX; int max_track = INT_MIN; panel_timeline->transition_select = TA_NO_TRANSITION; - for (int i=0;iclips.size();i++) { - Clip* c = sequence->clips.at(i); + for (int i=0;iclips.size();i++) { + Clip* c = sequence->clips.at(i); if (c != NULL) { min_track = qMin(min_track, c->track); max_track = qMax(max_track, c->track); @@ -1980,9 +1978,9 @@ void TimelineWidget::mouseMoveEvent(QMouseEvent *event) { tooltip_timer.start(); tooltip_clip = i; - if (c->get_opening_transition() != NULL && panel_timeline->cursor_frame <= c->timeline_in + c->get_opening_transition()->get_true_length()) { + if (c->get_opening_transition() != NULL && panel_timeline->cursor_frame <= c->timeline_in + c->get_opening_transition()->get_true_length()) { panel_timeline->transition_select = TA_OPENING_TRANSITION; - } else if (c->get_closing_transition() != NULL && panel_timeline->cursor_frame >= c->timeline_out - c->get_closing_transition()->get_true_length()) { + } else if (c->get_closing_transition() != NULL && panel_timeline->cursor_frame >= c->timeline_out - c->get_closing_transition()->get_true_length()) { panel_timeline->transition_select = TA_CLOSING_TRANSITION; } } @@ -2005,8 +2003,8 @@ void TimelineWidget::mouseMoveEvent(QMouseEvent *event) { } } if (panel_timeline->tool == TIMELINE_TOOL_POINTER) { - if (c->get_opening_transition() != NULL) { - long transition_point = c->timeline_in + c->get_opening_transition()->get_true_length(); + if (c->get_opening_transition() != NULL) { + long transition_point = c->timeline_in + c->get_opening_transition()->get_true_length(); if (transition_point > mouse_frame_lower && transition_point < mouse_frame_upper) { int nc = qAbs(transition_point - 1 - panel_timeline->cursor_frame); @@ -2019,8 +2017,8 @@ void TimelineWidget::mouseMoveEvent(QMouseEvent *event) { } } } - if (c->get_closing_transition() != NULL) { - long transition_point = c->timeline_out - c->get_closing_transition()->get_true_length(); + if (c->get_closing_transition() != NULL) { + long transition_point = c->timeline_out - c->get_closing_transition()->get_true_length(); if (transition_point > mouse_frame_lower && transition_point < mouse_frame_upper) { int nc = qAbs(transition_point + 1 - panel_timeline->cursor_frame); if (nc < closeness) { @@ -2035,19 +2033,19 @@ void TimelineWidget::mouseMoveEvent(QMouseEvent *event) { } } } - } - /*if (cursor_contains_clip) { + } + /*if (cursor_contains_clip) { QToolTip::showText(mapToGlobal(event->pos()), "HOVER OVER CLIP"); - }*/ - if (found) { - setCursor(Qt::SizeHorCursor); - } else { - panel_timeline->trim_target = -1; + }*/ + if (found) { + setCursor(Qt::SizeHorCursor); + } else { + panel_timeline->trim_target = -1; - // look for track heights - int track_y = 0; - for (int i=0;iget_track_height_size(bottom_align);i++) { - int track = (bottom_align) ? -1-i : i; + // look for track heights + int track_y = 0; + for (int i=0;iget_track_height_size(bottom_align);i++) { + int track = (bottom_align) ? -1-i : i; if (track >= min_track && track <= max_track) { int track_height = panel_timeline->calculate_track_height(track, -1); track_y += track_height; @@ -2065,74 +2063,74 @@ void TimelineWidget::mouseMoveEvent(QMouseEvent *event) { break; } } - } + } - if (found) { - setCursor(Qt::SizeVerCursor); - } else { - unsetCursor(); - } + if (found) { + setCursor(Qt::SizeVerCursor); + } else { + unsetCursor(); + } } - } else if (panel_timeline->tool == TIMELINE_TOOL_SLIP) { - if (getClipIndexFromCoords(panel_timeline->cursor_frame, panel_timeline->cursor_track) > -1) { - setCursor(Qt::SizeHorCursor); - } else { - unsetCursor(); - } - } else if (panel_timeline->tool == TIMELINE_TOOL_TRANSITION) { - if (panel_timeline->transition_tool_init) { - if (panel_timeline->transition_tool_proc) { - update_ghosts(event->pos(), event->modifiers() & Qt::ShiftModifier); - } else { - Clip* c = sequence->clips.at(panel_timeline->transition_tool_pre_clip); + } else if (panel_timeline->tool == TIMELINE_TOOL_SLIP) { + if (getClipIndexFromCoords(panel_timeline->cursor_frame, panel_timeline->cursor_track) > -1) { + setCursor(Qt::SizeHorCursor); + } else { + unsetCursor(); + } + } else if (panel_timeline->tool == TIMELINE_TOOL_TRANSITION) { + if (panel_timeline->transition_tool_init) { + if (panel_timeline->transition_tool_proc) { + update_ghosts(event->pos(), event->modifiers() & Qt::ShiftModifier); + } else { + Clip* c = sequence->clips.at(panel_timeline->transition_tool_pre_clip); - Ghost g; + Ghost g; - g.in = g.old_in = g.out = g.old_out = (panel_timeline->transition_tool_type == TA_OPENING_TRANSITION) ? c->timeline_in : c->timeline_out; - g.track = c->track; - g.clip = panel_timeline->transition_tool_pre_clip; - g.media_stream = panel_timeline->transition_tool_type; - g.trimming = false; + g.in = g.old_in = g.out = g.old_out = (panel_timeline->transition_tool_type == TA_OPENING_TRANSITION) ? c->timeline_in : c->timeline_out; + g.track = c->track; + g.clip = panel_timeline->transition_tool_pre_clip; + g.media_stream = panel_timeline->transition_tool_type; + g.trimming = false; - panel_timeline->ghosts.append(g); + panel_timeline->ghosts.append(g); - panel_timeline->transition_tool_proc = true; - } - } else { + panel_timeline->transition_tool_proc = true; + } + } else { int mouse_clip = getClipIndexFromCoords(panel_timeline->cursor_frame, panel_timeline->cursor_track); if (mouse_clip > -1) { Clip* c = sequence->clips.at(mouse_clip); if (same_sign(c->track, panel_timeline->transition_tool_side)) { - panel_timeline->transition_tool_pre_clip = mouse_clip; + panel_timeline->transition_tool_pre_clip = mouse_clip; long halfway = c->timeline_in + (c->getLength()/2); - long between_range = getFrameFromScreenPoint(panel_timeline->zoom, TRANSITION_BETWEEN_RANGE) + 1; + long between_range = getFrameFromScreenPoint(panel_timeline->zoom, TRANSITION_BETWEEN_RANGE) + 1; - if (panel_timeline->cursor_frame > halfway) { - panel_timeline->transition_tool_type = TA_CLOSING_TRANSITION; - } else { - panel_timeline->transition_tool_type = TA_OPENING_TRANSITION; - } + if (panel_timeline->cursor_frame > halfway) { + panel_timeline->transition_tool_type = TA_CLOSING_TRANSITION; + } else { + panel_timeline->transition_tool_type = TA_OPENING_TRANSITION; + } - panel_timeline->transition_tool_post_clip = -1; - if (panel_timeline->cursor_frame < c->timeline_in + between_range) { - panel_timeline->transition_tool_post_clip = getClipIndexFromCoords(c->timeline_in-1, c->track); - } else if (panel_timeline->cursor_frame > c->timeline_out - between_range) { - panel_timeline->transition_tool_post_clip = getClipIndexFromCoords(c->timeline_out+1, c->track); - } + panel_timeline->transition_tool_post_clip = -1; + if (panel_timeline->cursor_frame < c->timeline_in + between_range) { + panel_timeline->transition_tool_post_clip = getClipIndexFromCoords(c->timeline_in-1, c->track); + } else if (panel_timeline->cursor_frame > c->timeline_out - between_range) { + panel_timeline->transition_tool_post_clip = getClipIndexFromCoords(c->timeline_out+1, c->track); + } } - } else { - panel_timeline->transition_tool_pre_clip = -1; - panel_timeline->transition_tool_post_clip = -1; - } - } + } else { + panel_timeline->transition_tool_pre_clip = -1; + panel_timeline->transition_tool_post_clip = -1; + } + } - panel_timeline->repaint_timeline(); - } - } + panel_timeline->repaint_timeline(); + } + } } void TimelineWidget::leaveEvent(QEvent*) { - tooltip_timer.stop(); + tooltip_timer.stop(); } int color_brightness(int r, int g, int b) { @@ -2171,52 +2169,52 @@ void draw_waveform(Clip* clip, FootageStream* ms, long media_length, QPainter *p } void draw_transition(QPainter& p, Clip* c, const QRect& clip_rect, QRect& text_rect, int transition_type) { - Transition* t = (transition_type == TA_OPENING_TRANSITION) ? c->get_opening_transition() : c->get_closing_transition(); - if (t != NULL) { - QColor transition_color(255, 0, 0, 16); - int transition_width = getScreenPointFromFrame(panel_timeline->zoom, t->get_true_length()); - int transition_height = clip_rect.height(); - int tr_y = clip_rect.y(); - int tr_x = 0; - if (transition_type == TA_OPENING_TRANSITION) { - tr_x = clip_rect.x(); - text_rect.setX(text_rect.x()+transition_width); - } else { - tr_x = clip_rect.right()-transition_width; - text_rect.setWidth(text_rect.width()-transition_width); - } - QRect transition_rect = QRect(tr_x, tr_y, transition_width, transition_height); - p.fillRect(transition_rect, transition_color); - QRect transition_text_rect(transition_rect.x() + CLIP_TEXT_PADDING, transition_rect.y() + CLIP_TEXT_PADDING, transition_rect.width() - CLIP_TEXT_PADDING, transition_rect.height() - CLIP_TEXT_PADDING); - if (transition_text_rect.width() > MAX_TEXT_WIDTH) { - bool draw_text = true; + Transition* t = (transition_type == TA_OPENING_TRANSITION) ? c->get_opening_transition() : c->get_closing_transition(); + if (t != NULL) { + QColor transition_color(255, 0, 0, 16); + int transition_width = getScreenPointFromFrame(panel_timeline->zoom, t->get_true_length()); + int transition_height = clip_rect.height(); + int tr_y = clip_rect.y(); + int tr_x = 0; + if (transition_type == TA_OPENING_TRANSITION) { + tr_x = clip_rect.x(); + text_rect.setX(text_rect.x()+transition_width); + } else { + tr_x = clip_rect.right()-transition_width; + text_rect.setWidth(text_rect.width()-transition_width); + } + QRect transition_rect = QRect(tr_x, tr_y, transition_width, transition_height); + p.fillRect(transition_rect, transition_color); + QRect transition_text_rect(transition_rect.x() + CLIP_TEXT_PADDING, transition_rect.y() + CLIP_TEXT_PADDING, transition_rect.width() - CLIP_TEXT_PADDING, transition_rect.height() - CLIP_TEXT_PADDING); + if (transition_text_rect.width() > MAX_TEXT_WIDTH) { + bool draw_text = true; - p.setPen(QColor(0, 0, 0, 96)); - if (t->secondary_clip == NULL) { - if (transition_type == TA_OPENING_TRANSITION) { - p.drawLine(transition_rect.bottomLeft(), transition_rect.topRight()); - } else { - p.drawLine(transition_rect.topLeft(), transition_rect.bottomRight()); - } - } else { - if (transition_type == TA_OPENING_TRANSITION) { - p.drawLine(QPoint(transition_rect.left(), transition_rect.center().y()), transition_rect.topRight()); - p.drawLine(QPoint(transition_rect.left(), transition_rect.center().y()), transition_rect.bottomRight()); - draw_text = false; - } else { - p.drawLine(QPoint(transition_rect.right(), transition_rect.center().y()), transition_rect.topLeft()); - p.drawLine(QPoint(transition_rect.right(), transition_rect.center().y()), transition_rect.bottomLeft()); - } - } + p.setPen(QColor(0, 0, 0, 96)); + if (t->secondary_clip == NULL) { + if (transition_type == TA_OPENING_TRANSITION) { + p.drawLine(transition_rect.bottomLeft(), transition_rect.topRight()); + } else { + p.drawLine(transition_rect.topLeft(), transition_rect.bottomRight()); + } + } else { + if (transition_type == TA_OPENING_TRANSITION) { + p.drawLine(QPoint(transition_rect.left(), transition_rect.center().y()), transition_rect.topRight()); + p.drawLine(QPoint(transition_rect.left(), transition_rect.center().y()), transition_rect.bottomRight()); + draw_text = false; + } else { + p.drawLine(QPoint(transition_rect.right(), transition_rect.center().y()), transition_rect.topLeft()); + p.drawLine(QPoint(transition_rect.right(), transition_rect.center().y()), transition_rect.bottomLeft()); + } + } - if (draw_text) { - p.setPen(Qt::white); - p.drawText(transition_text_rect, 0, t->meta->name, &transition_text_rect); - } - } - p.setPen(Qt::black); - p.drawRect(transition_rect); - } + if (draw_text) { + p.setPen(Qt::white); + p.drawText(transition_text_rect, 0, t->meta->name, &transition_text_rect); + } + } + p.setPen(Qt::black); + p.drawRect(transition_rect); + } } @@ -2258,7 +2256,7 @@ void TimelineWidget::paintEvent(QPaintEvent*) { QRect clip_rect(panel_timeline->getTimelineScreenPointFromFrame(clip->timeline_in), getScreenPointFromTrack(clip->track), getScreenPointFromFrame(panel_timeline->zoom, clip->getLength()), panel_timeline->calculate_track_height(clip->track, -1)); QRect text_rect(clip_rect.left() + CLIP_TEXT_PADDING, clip_rect.top() + CLIP_TEXT_PADDING, clip_rect.width() - CLIP_TEXT_PADDING - 1, clip_rect.height() - CLIP_TEXT_PADDING - 1); if (clip_rect.left() < width() && clip_rect.right() >= 0 && clip_rect.top() < height() && clip_rect.bottom() >= 0) { - QRect actual_clip_rect = clip_rect; + QRect actual_clip_rect = clip_rect; if (actual_clip_rect.x() < 0) actual_clip_rect.setX(0); if (actual_clip_rect.right() > width()) actual_clip_rect.setRight(width()); if (actual_clip_rect.y() < 0) actual_clip_rect.setY(0); @@ -2267,46 +2265,46 @@ void TimelineWidget::paintEvent(QPaintEvent*) { int thumb_x = clip_rect.x() + 1; - if (clip->media != NULL && clip->media->get_type() == MEDIA_TYPE_FOOTAGE) { + if (clip->media != NULL && clip->media->get_type() == MEDIA_TYPE_FOOTAGE) { bool draw_checkerboard = false; QRect checkerboard_rect(clip_rect); - Footage* m = clip->media->to_footage(); + Footage* m = clip->media->to_footage(); FootageStream* ms = m->get_stream_from_file_index(clip->track < 0, clip->media_stream); if (ms == NULL) { draw_checkerboard = true; } else if (ms->preview_done) { // draw top and tail triangles - int triangle_size = TRACK_MIN_HEIGHT >> 2; - if (!ms->infinite_length && clip_rect.width() > triangle_size) { - p.setPen(Qt::NoPen); - p.setBrush(QColor(80, 80, 80)); - if (clip->clip_in == 0 - && clip_rect.x() + triangle_size > 0 - && clip_rect.y() + triangle_size > 0 - && clip_rect.x() < width() - && clip_rect.y() < height()) { - const QPoint points[3] = { - QPoint(clip_rect.x(), clip_rect.y()), - QPoint(clip_rect.x() + triangle_size, clip_rect.y()), - QPoint(clip_rect.x(), clip_rect.y() + triangle_size) - }; - p.drawPolygon(points, 3); - text_rect.setLeft(text_rect.left() + (triangle_size >> 2)); - } - if (clip->timeline_out - clip->timeline_in + clip->clip_in == clip->getMaximumLength() - && clip_rect.right() - triangle_size < width() - && clip_rect.y() + triangle_size > 0 - && clip_rect.right() > 0 - && clip_rect.y() < height()) { - const QPoint points[3] = { - QPoint(clip_rect.right(), clip_rect.y()), - QPoint(clip_rect.right() - triangle_size, clip_rect.y()), - QPoint(clip_rect.right(), clip_rect.y() + triangle_size) - }; - p.drawPolygon(points, 3); - text_rect.setRight(text_rect.right() - (triangle_size >> 2)); - } - } + int triangle_size = TRACK_MIN_HEIGHT >> 2; + if (!ms->infinite_length && clip_rect.width() > triangle_size) { + p.setPen(Qt::NoPen); + p.setBrush(QColor(80, 80, 80)); + if (clip->clip_in == 0 + && clip_rect.x() + triangle_size > 0 + && clip_rect.y() + triangle_size > 0 + && clip_rect.x() < width() + && clip_rect.y() < height()) { + const QPoint points[3] = { + QPoint(clip_rect.x(), clip_rect.y()), + QPoint(clip_rect.x() + triangle_size, clip_rect.y()), + QPoint(clip_rect.x(), clip_rect.y() + triangle_size) + }; + p.drawPolygon(points, 3); + text_rect.setLeft(text_rect.left() + (triangle_size >> 2)); + } + if (clip->timeline_out - clip->timeline_in + clip->clip_in == clip->getMaximumLength() + && clip_rect.right() - triangle_size < width() + && clip_rect.y() + triangle_size > 0 + && clip_rect.right() > 0 + && clip_rect.y() < height()) { + const QPoint points[3] = { + QPoint(clip_rect.right(), clip_rect.y()), + QPoint(clip_rect.right() - triangle_size, clip_rect.y()), + QPoint(clip_rect.right(), clip_rect.y() + triangle_size) + }; + p.drawPolygon(points, 3); + text_rect.setRight(text_rect.right() - (triangle_size >> 2)); + } + } p.setBrush(Qt::NoBrush); @@ -2317,23 +2315,23 @@ void TimelineWidget::paintEvent(QPaintEvent*) { // draw thumbnail int thumb_y = p.fontMetrics().height()+CLIP_TEXT_PADDING+CLIP_TEXT_PADDING; if (thumb_x < width() && thumb_y < height()) { - int space_for_thumb = clip_rect.width()-1; - if (clip->get_opening_transition() != NULL) { - int ot_width = getScreenPointFromFrame(panel_timeline->zoom, clip->get_opening_transition()->get_true_length()); + int space_for_thumb = clip_rect.width()-1; + if (clip->get_opening_transition() != NULL) { + int ot_width = getScreenPointFromFrame(panel_timeline->zoom, clip->get_opening_transition()->get_true_length()); thumb_x += ot_width; space_for_thumb -= ot_width; } - if (clip->get_closing_transition() != NULL) { - space_for_thumb -= getScreenPointFromFrame(panel_timeline->zoom, clip->get_closing_transition()->get_true_length()); - } + if (clip->get_closing_transition() != NULL) { + space_for_thumb -= getScreenPointFromFrame(panel_timeline->zoom, clip->get_closing_transition()->get_true_length()); + } int thumb_height = clip_rect.height()-thumb_y; int thumb_width = (thumb_height*((double)ms->video_preview.width()/(double)ms->video_preview.height())); if (thumb_x + thumb_width >= 0 && thumb_height > thumb_y - && thumb_y + thumb_height >= 0 - && space_for_thumb > MAX_TEXT_WIDTH) { - int thumb_clip_width = qMin(thumb_width, space_for_thumb); - p.drawImage(QRect(thumb_x, clip_rect.y()+thumb_y, thumb_clip_width, thumb_height), ms->video_preview, QRect(0, 0, thumb_clip_width*((double)ms->video_preview.width()/(double)thumb_width), ms->video_preview.height())); + && thumb_y + thumb_height >= 0 + && space_for_thumb > MAX_TEXT_WIDTH) { + int thumb_clip_width = qMin(thumb_width, space_for_thumb); + p.drawImage(QRect(thumb_x, clip_rect.y()+thumb_y, thumb_clip_width, thumb_height), ms->video_preview, QRect(0, 0, thumb_clip_width*((double)ms->video_preview.width()/(double)thumb_width), ms->video_preview.height())); } } } else if (clip_rect.height() > TRACK_MIN_HEIGHT) { @@ -2387,8 +2385,8 @@ void TimelineWidget::paintEvent(QPaintEvent*) { } // draw clip transitions - draw_transition(p, clip, clip_rect, text_rect, TA_OPENING_TRANSITION); - draw_transition(p, clip, clip_rect, text_rect, TA_CLOSING_TRANSITION); + draw_transition(p, clip, clip_rect, text_rect, TA_OPENING_TRANSITION); + draw_transition(p, clip, clip_rect, text_rect, TA_CLOSING_TRANSITION); // top left bevel p.setPen(Qt::white); @@ -2418,41 +2416,41 @@ void TimelineWidget::paintEvent(QPaintEvent*) { } // bottom right gray - p.setPen(QColor(0, 0, 0, 128)); - if (clip_rect.right() >= 0 && clip_rect.right() < width()) p.drawLine(clip_rect.bottomRight(), clip_rect.topRight()); + p.setPen(QColor(0, 0, 0, 128)); + if (clip_rect.right() >= 0 && clip_rect.right() < width()) p.drawLine(clip_rect.bottomRight(), clip_rect.topRight()); if (clip_rect.bottom() >= 0 && clip_rect.bottom() < height()) p.drawLine(QPoint(qMax(0, clip_rect.left()), clip_rect.bottom()), QPoint(qMin(width(), clip_rect.right()), clip_rect.bottom())); - // draw transition tool - if (panel_timeline->tool == TIMELINE_TOOL_TRANSITION && (panel_timeline->transition_tool_pre_clip == i || panel_timeline->transition_tool_post_clip == i)) { - int type = panel_timeline->transition_tool_type; - if (panel_timeline->transition_tool_post_clip == i) { - // invert transition type - type = (type == TA_CLOSING_TRANSITION) ? TA_OPENING_TRANSITION : TA_CLOSING_TRANSITION; - } - QRect transition_tool_rect = clip_rect; - if (type == TA_CLOSING_TRANSITION) { - if (panel_timeline->transition_tool_post_clip > -1) { - transition_tool_rect.setLeft(transition_tool_rect.right() - TRANSITION_BETWEEN_RANGE); - } else { - transition_tool_rect.setLeft(transition_tool_rect.left() + (3*(transition_tool_rect.width()>>2))); - } - } else { - if (panel_timeline->transition_tool_post_clip > -1) { - transition_tool_rect.setWidth(TRANSITION_BETWEEN_RANGE); - } else { - transition_tool_rect.setWidth(transition_tool_rect.width()>>2); - } - } - if (transition_tool_rect.left() < width() && transition_tool_rect.right() > 0) { - if (transition_tool_rect.left() < 0) { - transition_tool_rect.setLeft(0); - } - if (transition_tool_rect.right() > width()) { - transition_tool_rect.setRight(width()); - } - p.fillRect(transition_tool_rect, QColor(0, 0, 0, 128)); - } - } + // draw transition tool + if (panel_timeline->tool == TIMELINE_TOOL_TRANSITION && (panel_timeline->transition_tool_pre_clip == i || panel_timeline->transition_tool_post_clip == i)) { + int type = panel_timeline->transition_tool_type; + if (panel_timeline->transition_tool_post_clip == i) { + // invert transition type + type = (type == TA_CLOSING_TRANSITION) ? TA_OPENING_TRANSITION : TA_CLOSING_TRANSITION; + } + QRect transition_tool_rect = clip_rect; + if (type == TA_CLOSING_TRANSITION) { + if (panel_timeline->transition_tool_post_clip > -1) { + transition_tool_rect.setLeft(transition_tool_rect.right() - TRANSITION_BETWEEN_RANGE); + } else { + transition_tool_rect.setLeft(transition_tool_rect.left() + (3*(transition_tool_rect.width()>>2))); + } + } else { + if (panel_timeline->transition_tool_post_clip > -1) { + transition_tool_rect.setWidth(TRANSITION_BETWEEN_RANGE); + } else { + transition_tool_rect.setWidth(transition_tool_rect.width()>>2); + } + } + if (transition_tool_rect.left() < width() && transition_tool_rect.right() > 0) { + if (transition_tool_rect.left() < 0) { + transition_tool_rect.setLeft(0); + } + if (transition_tool_rect.right() > width()) { + transition_tool_rect.setRight(width()); + } + p.fillRect(transition_tool_rect, QColor(0, 0, 0, 128)); + } + } } } } @@ -2531,16 +2529,16 @@ void TimelineWidget::paintEvent(QPaintEvent*) { } } - // draw rectangle select - if (panel_timeline->rect_select_proc) { - int rsy = panel_timeline->rect_select_y; - int rsh = panel_timeline->rect_select_h; - if (bottom_align) { - rsy += height(); - } + // draw rectangle select + if (panel_timeline->rect_select_proc) { + int rsy = panel_timeline->rect_select_y; + int rsh = panel_timeline->rect_select_h; + if (bottom_align) { + rsy += height(); + } QRect rect_select(panel_timeline->rect_select_x, rsy, panel_timeline->rect_select_w, rsh); draw_selection_rectangle(p, rect_select); - } + } // Draw ghosts if (!panel_timeline->ghosts.isEmpty()) { @@ -2564,7 +2562,7 @@ void TimelineWidget::paintEvent(QPaintEvent*) { } } - // draw insert indicator + // draw insert indicator if (panel_timeline->move_insert && !insert_points.isEmpty()) { p.setBrush(Qt::white); p.setPen(Qt::NoPen); @@ -2583,35 +2581,35 @@ void TimelineWidget::paintEvent(QPaintEvent*) { } - // Draw splitting cursor - if (panel_timeline->splitting) { - for (int i=0;isplit_tracks.size();i++) { - if (is_track_visible(panel_timeline->split_tracks.at(i))) { + // Draw splitting cursor + if (panel_timeline->splitting) { + for (int i=0;isplit_tracks.size();i++) { + if (is_track_visible(panel_timeline->split_tracks.at(i))) { int cursor_x = panel_timeline->getTimelineScreenPointFromFrame(panel_timeline->drag_frame_start); - int cursor_y = getScreenPointFromTrack(panel_timeline->split_tracks.at(i)); + int cursor_y = getScreenPointFromTrack(panel_timeline->split_tracks.at(i)); p.setPen(QColor(64, 64, 64)); p.drawLine(cursor_x, cursor_y, cursor_x, cursor_y + panel_timeline->calculate_track_height(panel_timeline->split_tracks.at(i), -1)); - } - } - } + } + } + } - // Draw playhead - p.setPen(Qt::red); + // Draw playhead + p.setPen(Qt::red); int playhead_x = panel_timeline->getTimelineScreenPointFromFrame(sequence->playhead); - p.drawLine(playhead_x, rect().top(), playhead_x, rect().bottom()); + p.drawLine(playhead_x, rect().top(), playhead_x, rect().bottom()); - // draw border - p.setPen(QColor(0, 0, 0, 64)); - int edge_y = (bottom_align) ? rect().height()-1 : 0; - p.drawLine(0, edge_y, rect().width(), edge_y); + // draw border + p.setPen(QColor(0, 0, 0, 64)); + int edge_y = (bottom_align) ? rect().height()-1 : 0; + p.drawLine(0, edge_y, rect().width(), edge_y); - // draw snap point - if (panel_timeline->snapped) { - p.setPen(Qt::white); + // draw snap point + if (panel_timeline->snapped) { + p.setPen(Qt::white); int snap_x = panel_timeline->getTimelineScreenPointFromFrame(panel_timeline->snap_point); - p.drawLine(snap_x, 0, snap_x, height()); - } + p.drawLine(snap_x, 0, snap_x, height()); + } // Draw edit cursor if (isLiveEditing() && is_track_visible(panel_timeline->cursor_track)) { @@ -2621,15 +2619,15 @@ void TimelineWidget::paintEvent(QPaintEvent*) { p.setPen(Qt::gray); p.drawLine(cursor_x, cursor_y, cursor_x, cursor_y + panel_timeline->calculate_track_height(panel_timeline->cursor_track, -1)); } - } + } } void TimelineWidget::resizeEvent(QResizeEvent *event) { - scrollBar->setPageStep(height()); + scrollBar->setPageStep(height()); } bool TimelineWidget::is_track_visible(int track) { - return (bottom_align == (track < 0)); + return (bottom_align == (track < 0)); } // ************************************** @@ -2638,44 +2636,44 @@ bool TimelineWidget::is_track_visible(int track) { int TimelineWidget::getTrackFromScreenPoint(int y) { y += scroll; - if (bottom_align) { + if (bottom_align) { y = -(y - height()); - } - y--; - int height_measure = 0; - int counter = ((!bottom_align && y > 0) || (bottom_align && y < 0)) ? 0 : -1; - int track_height = panel_timeline->calculate_track_height(counter, -1); - while (qAbs(y) > height_measure+track_height) { - if (config.show_track_lines && counter != -1) y--; - height_measure += track_height; - if ((!bottom_align && y > 0) || (bottom_align && y < 0)) { - counter++; - } else { - counter--; - } - track_height = panel_timeline->calculate_track_height(counter, -1); - } - return counter; + } + y--; + int height_measure = 0; + int counter = ((!bottom_align && y > 0) || (bottom_align && y < 0)) ? 0 : -1; + int track_height = panel_timeline->calculate_track_height(counter, -1); + while (qAbs(y) > height_measure+track_height) { + if (config.show_track_lines && counter != -1) y--; + height_measure += track_height; + if ((!bottom_align && y > 0) || (bottom_align && y < 0)) { + counter++; + } else { + counter--; + } + track_height = panel_timeline->calculate_track_height(counter, -1); + } + return counter; } int TimelineWidget::getScreenPointFromTrack(int track) { int y = 0; - int counter = 0; - while (counter != track) { - if (bottom_align) counter--; - y += panel_timeline->calculate_track_height(counter, -1); - if (!bottom_align) counter++; - if (config.show_track_lines && counter != -1) y++; - } - y++; + int counter = 0; + while (counter != track) { + if (bottom_align) counter--; + y += panel_timeline->calculate_track_height(counter, -1); + if (!bottom_align) counter++; + if (config.show_track_lines && counter != -1) y++; + } + y++; return (bottom_align) ? height() - y - scroll : y - scroll; } int TimelineWidget::getClipIndexFromCoords(long frame, int track) { - for (int i=0;iclips.size();i++) { - Clip* c = sequence->clips.at(i); - if (c != NULL && c->track == track && frame >= c->timeline_in && frame < c->timeline_out) { - return i; + for (int i=0;iclips.size();i++) { + Clip* c = sequence->clips.at(i); + if (c != NULL && c->track == track && frame >= c->timeline_in && frame < c->timeline_out) { + return i; } } return -1; @@ -2687,5 +2685,5 @@ void TimelineWidget::setScroll(int s) { } void TimelineWidget::reveal_media() { - panel_project->reveal_media(rc_reveal_media); + panel_project->reveal_media(rc_reveal_media); }