diff --git a/olive.pro b/olive.pro index ef37b525d..ad08b1454 100644 --- a/olive.pro +++ b/olive.pro @@ -97,7 +97,8 @@ SOURCES += \ io/clipboard.cpp \ dialogs/stabilizerdialog.cpp \ io/avtogl.cpp \ - ui/sourceiconview.cpp + ui/sourceiconview.cpp \ + project/sourcescommon.cpp HEADERS += \ mainwindow.h \ @@ -174,7 +175,8 @@ HEADERS += \ io/clipboard.h \ dialogs/stabilizerdialog.h \ io/avtogl.h \ - ui/sourceiconview.h + ui/sourceiconview.h \ + project/sourcescommon.h FORMS += \ mainwindow.ui \ diff --git a/panels/project.cpp b/panels/project.cpp index 39f595d63..cad3eaefe 100644 --- a/panels/project.cpp +++ b/panels/project.cpp @@ -24,6 +24,7 @@ #include "project/media.h" #include "ui/sourcetable.h" #include "ui/sourceiconview.h" +#include "project/sourcescommon.h" #include "debug.h" #include @@ -74,6 +75,8 @@ Project::Project(QWidget *parent) : setWidget(dockWidgetContents); + sources_common = new SourcesCommon(this); + sorter = new QSortFilterProxyModel(this); sorter->setSourceModel(&project_model); @@ -128,13 +131,6 @@ Project::Project(QWidget *parent) : verticalLayout->addWidget(icon_view_container); - QPushButton* tree_view_button = new QPushButton("Tree View"); - verticalLayout->addWidget(tree_view_button); - connect(tree_view_button, SIGNAL(clicked(bool)), this, SLOT(set_tree_view())); - QPushButton* icon_view_button = new QPushButton("Icon View"); - verticalLayout->addWidget(icon_view_button); - connect(icon_view_button, SIGNAL(clicked(bool)), this, SLOT(set_icon_view())); - connect(directory_up, SIGNAL(clicked(bool)), this, SLOT(go_up_dir())); connect(icon_view, SIGNAL(changed_root()), this, SLOT(set_up_dir_enabled())); @@ -1041,6 +1037,15 @@ void Project::save_project(bool autorecovery) { 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); + + 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() { diff --git a/panels/project.h b/panels/project.h index df36e5284..71fdd0137 100644 --- a/panels/project.h +++ b/panels/project.h @@ -22,6 +22,7 @@ class QSortFilterProxyModel; class ComboAction; class SourceIconView; class QPushButton; +class SourcesCommon; #define LOAD_TYPE_VERSION 69 #define LOAD_TYPE_URL 70 @@ -70,6 +71,7 @@ public: SourceTable* tree_view; SourceIconView* icon_view; + SourcesCommon* sources_common; QSortFilterProxyModel* sorter; diff --git a/project/clip.cpp b/project/clip.cpp index df0927544..65fbdb50a 100644 --- a/project/clip.cpp +++ b/project/clip.cpp @@ -109,7 +109,12 @@ void Clip::refresh() { // validates media if it was replaced if (replaced && media != NULL && media->get_type() == MEDIA_TYPE_FOOTAGE) { Footage* m = media->to_footage(); - media_stream = (track < 0) ? m->video_tracks.at(0)->file_index : m->audio_tracks.at(0)->file_index; + + if (track < 0 && m->video_tracks.size() > 0) { + media_stream = m->video_tracks.at(0)->file_index; + } else if (track >= 0 && m->audio_tracks.size() > 0) { + media_stream = m->audio_tracks.at(0)->file_index; + } } replaced = false; diff --git a/project/sourcescommon.cpp b/project/sourcescommon.cpp new file mode 100644 index 000000000..510ff8a32 --- /dev/null +++ b/project/sourcescommon.cpp @@ -0,0 +1,279 @@ +#include "sourcescommon.h" + +#include "panels/panels.h" +#include "project/media.h" +#include "project/undo.h" +#include "panels/timeline.h" +#include "panels/project.h" +#include "project/footage.h" +#include "panels/viewer.h" +#include "io/config.h" +#include "mainwindow.h" + +#include +#include +#include +#include +#include + +SourcesCommon::SourcesCommon(Project* parent) : + project_parent(parent), + editing_item(NULL) +{ + 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))); + } + + 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); + + 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); + + selected_items = items; + + 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())); + + 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 defined(Q_OS_WIN) + QAction* reveal_in_explorer = menu.addAction("Reveal in Explorer"); +#elif defined(Q_OS_MAC) + QAction* reveal_in_explorer = menu.addAction("Reveal in Finder"); +#else + 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())); + } + } + + // 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())); + + // 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())); + } + + // 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())); + } + } + + menu.addSeparator(); + + 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())); + + menu.exec(QCursor::pos()); +} + +void SourcesCommon::mousePressEvent(QMouseEvent *) { + 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; + } +} + +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; + } + } +} + +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(); + + // 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(); + +#if defined(Q_OS_WIN) + 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); +#else + QDesktopServices::openUrl(QUrl::fromLocalFile(m->url.left(m->url.lastIndexOf('/')))); +#endif +} + +void SourcesCommon::stop_rename_timer() { + rename_timer.stop(); +} + +void SourcesCommon::rename_interval() { + 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; + } +} diff --git a/project/sourcescommon.h b/project/sourcescommon.h new file mode 100644 index 000000000..4522efdfa --- /dev/null +++ b/project/sourcescommon.h @@ -0,0 +1,39 @@ +#ifndef SOURCESCOMMON_H +#define SOURCESCOMMON_H + +#include +#include + +class Project; +class QMouseEvent; +class Media; +class QAbstractItemView; +class QDropEvent; + +class SourcesCommon : public QObject { + Q_OBJECT +public: + SourcesCommon(Project *parent); + QAbstractItemView* view; + void show_context_menu(QWidget* parent, const QModelIndexList &items); + + void mousePressEvent(QMouseEvent* e); + void mouseDoubleClickEvent(QMouseEvent* e, const QModelIndexList& selected_items); + void dropEvent(QWidget *parent, QDropEvent* e, const QModelIndex& drop_item, const QModelIndexList &items); + + void item_click(Media* m, const QModelIndex &index); +private slots: + void create_seq_from_selected(); + void reveal_in_browser(); + void rename_interval(); + void item_renamed(Media *item); +private: + Media* editing_item; + QModelIndex editing_index; + QModelIndexList selected_items; + Project* project_parent; + void stop_rename_timer(); + QTimer rename_timer; +}; + +#endif // SOURCESCOMMON_H diff --git a/project/undo.cpp b/project/undo.cpp index 17fe258d7..8e9132d82 100644 --- a/project/undo.cpp +++ b/project/undo.cpp @@ -592,6 +592,7 @@ void ReplaceMediaCommand::replace(QString& filename) { // replace media QStringList files; files.append(filename); + item->to_footage()->ready_lock.lock(); panel_project->process_file_list(files, false, item, NULL); } @@ -694,7 +695,7 @@ void EffectDeleteCommand::redo() { mainWindow->setWindowModified(true); } -MediaMove::MediaMove(SourceTable *s) : table(s), old_project_changed(mainWindow->isWindowModified()) {} +MediaMove::MediaMove() : old_project_changed(mainWindow->isWindowModified()) {} void MediaMove::undo() { for (int i=0;i items; Media* to; void undo(); void redo(); private: QVector froms; - SourceTable* table; bool old_project_changed; }; diff --git a/ui/sourceiconview.cpp b/ui/sourceiconview.cpp index d1de9e4c2..9617adc24 100644 --- a/ui/sourceiconview.cpp +++ b/ui/sourceiconview.cpp @@ -1,17 +1,67 @@ #include "sourceiconview.h" +#include + #include "panels/project.h" #include "project/media.h" +#include "project/sourcescommon.h" #include "debug.h" -SourceIconView::SourceIconView(QWidget *parent) : QListView(parent) {} +SourceIconView::SourceIconView(QWidget *parent) : QListView(parent) { + 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()); +} + +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); + } +} + +void SourceIconView::mousePressEvent(QMouseEvent* 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); + } +} + +void SourceIconView::dragMoveEvent(QDragMoveEvent *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()); +} 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()); + } } diff --git a/ui/sourceiconview.h b/ui/sourceiconview.h index ea255d10d..9320a1628 100644 --- a/ui/sourceiconview.h +++ b/ui/sourceiconview.h @@ -10,9 +10,17 @@ class SourceIconView : public QListView { public: SourceIconView(QWidget* parent = 0); Project* project_parent; + + void mousePressEvent(QMouseEvent* event); void mouseDoubleClickEvent(QMouseEvent *event); + void dragEnterEvent(QDragEnterEvent *event); + void dragMoveEvent(QDragMoveEvent *event); + void dropEvent(QDropEvent* event); signals: void changed_root(); +private slots: + void show_context_menu(); + void item_click(const QModelIndex& index); }; #endif // SOURCEICONVIEW_H diff --git a/ui/sourcetable.cpp b/ui/sourcetable.cpp index aa835f55d..75586e8b4 100644 --- a/ui/sourcetable.cpp +++ b/ui/sourcetable.cpp @@ -11,6 +11,7 @@ #include "mainwindow.h" #include "io/config.h" #include "project/media.h" +#include "project/sourcescommon.h" #include "debug.h" #include @@ -25,193 +26,30 @@ #include SourceTable::SourceTable(QWidget* parent) : QTreeView(parent) { - editing_item = NULL; setSortingEnabled(true); sortByColumn(0, Qt::AscendingOrder); - rename_timer.setInterval(1000); setContextMenuPolicy(Qt::CustomContextMenu); - connect(&rename_timer, SIGNAL(timeout()), this, SLOT(rename_interval())); 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() { - QMenu menu(this); - - QAction* import_action = menu.addAction("Import..."); - connect(import_action, SIGNAL(triggered(bool)), project_parent, SLOT(import_dialog())); - - QAction* new_folder_action = menu.addAction("New Folder..."); - connect(new_folder_action, SIGNAL(triggered(bool)), mainWindow, SLOT(on_actionFolder_triggered())); - - QModelIndexList selected_items = selectionModel()->selectedRows(); - - if (selected_items.size() > 0) { - Media* m = project_parent->item_to_media(selected_items.at(0)); - - if (selected_items.size() == 1) { - // replace footage - int type = m->get_type(); - if (type == MEDIA_TYPE_FOOTAGE) { - QAction* replace_action = menu.addAction("Replace/Relink Media"); - 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"); -#elif defined(Q_OS_MAC) - QAction* reveal_in_explorer = menu.addAction("Reveal in Finder"); -#else - QAction* reveal_in_explorer = menu.addAction("Reveal in File Manager"); -#endif - 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"); - 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; - } - } - - // create sequence from - QAction* create_seq_from = menu.addAction("Create Sequence With This Media"); - 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"); - 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"); - connect(delete_footage_from_sequences, SIGNAL(triggered(bool)), project_parent, SLOT(delete_clips_using_selected_media())); - } - - // delete media - QAction* delete_action = menu.addAction("Delete"); - connect(delete_action, SIGNAL(triggered(bool)), project_parent, SLOT(delete_selected_media())); - - if (selected_items.size() == 1) { - QAction* properties_action = menu.addAction("Properties..."); - connect(properties_action, SIGNAL(triggered(bool)), project_parent, SLOT(open_properties())); - } - } - - menu.exec(QCursor::pos()); + project_parent->sources_common->show_context_menu(this, selectionModel()->selectedRows()); } -void SourceTable::create_seq_from_selected() { - QModelIndexList selected_items = selectionModel()->selectedRows(); - - 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); - - // 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); - } -} - -void SourceTable::reveal_in_browser() { - QModelIndexList selected_items = selectionModel()->selectedRows(); - 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); -#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); -#else - QDesktopServices::openUrl(QUrl::fromLocalFile(m->url.left(m->url.lastIndexOf('/')))); -#endif -} - -void SourceTable::item_renamed(Media* item) { - if (editing_item == item) { - MediaRename* mr = new MediaRename(item, "idk"); - undo_stack.push(mr); - editing_item = NULL; - } -} - -void SourceTable::stop_rename_timer() { - rename_timer.stop(); -} - -void SourceTable::rename_interval() { - stop_rename_timer(); - if (hasFocus() && editing_item != NULL) { - edit(editing_index); - //editItem(editing_item, 0); - } -} void SourceTable::item_click(const QModelIndex& index) { if (selectionModel()->selectedRows().size() == 1 && index.column() == 0) { - Media* m = project_parent->item_to_media(index); - if (editing_item == m) { - rename_timer.start(); - } else { - editing_item = m; - editing_index = index; - } + project_parent->sources_common->item_click(project_parent->item_to_media(index), index); } } void SourceTable::mousePressEvent(QMouseEvent* event) { - stop_rename_timer(); + project_parent->sources_common->mousePressEvent(event); QTreeView::mousePressEvent(event); } -void SourceTable::mouseDoubleClickEvent(QMouseEvent* e) { - stop_rename_timer(); - QModelIndexList selected_items = selectionModel()->selectedRows(); - 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 SourceTable::mouseDoubleClickEvent(QMouseEvent* event) { + project_parent->sources_common->mouseDoubleClickEvent(event, selectionModel()->selectedRows()); } void SourceTable::dragEnterEvent(QDragEnterEvent *event) { @@ -231,79 +69,5 @@ void SourceTable::dragMoveEvent(QDragMoveEvent *event) { } void SourceTable::dropEvent(QDropEvent* event) { - const QMimeData* mimeData = event->mimeData(); - const QModelIndex& drop_item = indexAt(event->pos()); - 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(this, "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(); - } - } - if (parent.isValid()) setExpanded(parent, true); - 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; - QModelIndexList selected_items = selectionModel()->selectedRows(); - 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(this); - mm->to = m; - mm->items = move_items; - undo_stack.push(mm); - } - } - } + project_parent->sources_common->dropEvent(this, event, indexAt(event->pos()), selectionModel()->selectedRows()); } diff --git a/ui/sourcetable.h b/ui/sourcetable.h index 0e3428152..aa19a5449 100644 --- a/ui/sourcetable.h +++ b/ui/sourcetable.h @@ -16,22 +16,13 @@ public: Project* project_parent; protected: void mousePressEvent(QMouseEvent*); - void mouseDoubleClickEvent(QMouseEvent *event); + void mouseDoubleClickEvent(QMouseEvent *); void dragEnterEvent(QDragEnterEvent *event); void dragMoveEvent(QDragMoveEvent *event); void dropEvent(QDropEvent *event); -private: - QTimer rename_timer; - Media* editing_item; - QModelIndex editing_index; private slots: - void rename_interval(); void item_click(const QModelIndex& index); - void stop_rename_timer(); - void item_renamed(Media *item); - void show_context_menu(); - void create_seq_from_selected(); - void reveal_in_browser(); + void show_context_menu(); }; #endif // SOURCETABLE_H