1 /***
2
3 Olive - Non-Linear Video Editor
4 Copyright (C) 2019 Olive Team
5
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18
19 ***/
20
21 #include "sourcetable.h"
22 #include "panels/project.h"
23
24 #include "project/footage.h"
25 #include "panels/timeline.h"
26 #include "panels/viewer.h"
27 #include "panels/panels.h"
28 #include "rendering/renderfunctions.h"
29 #include "undo/undo.h"
30 #include "timeline/sequence.h"
31 #include "mainwindow.h"
32 #include "global/config.h"
33 #include "project/media.h"
34 #include "project/sourcescommon.h"
35 #include "global/debug.h"
36
37 #include <QDragEnterEvent>
38 #include <QMimeData>
39 #include <QHeaderView>
40 #include <QMenu>
41 #include <QMessageBox>
42 #include <QFileInfo>
43 #include <QDebug>
44 #include <QDesktopServices>
45 #include <QDir>
46 #include <QProcess>
47
SourceTable(SourcesCommon & commons)48 SourceTable::SourceTable(SourcesCommon& commons) : commons_(commons) {
49 setSortingEnabled(true);
50 setAcceptDrops(true);
51 sortByColumn(0, Qt::AscendingOrder);
52 setContextMenuPolicy(Qt::CustomContextMenu);
53 setEditTriggers(QAbstractItemView::NoEditTriggers);
54 setDragDropMode(QAbstractItemView::DragDrop);
55 setSelectionMode(QAbstractItemView::ExtendedSelection);
56 connect(this, SIGNAL(clicked(const QModelIndex&)), this, SLOT(item_click(const QModelIndex&)));
57 connect(this, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(show_context_menu()));
58 }
59
show_context_menu()60 void SourceTable::show_context_menu() {
61 commons_.show_context_menu(this, selectionModel()->selectedRows());
62 }
63
item_click(const QModelIndex & index)64 void SourceTable::item_click(const QModelIndex& index) {
65 if (selectionModel()->selectedRows().size() == 1 && index.column() == 0) {
66 commons_.item_click(project_parent->item_to_media(index), index);
67 }
68 }
69
mousePressEvent(QMouseEvent * event)70 void SourceTable::mousePressEvent(QMouseEvent* event) {
71 commons_.mousePressEvent(event);
72 QTreeView::mousePressEvent(event);
73 }
74
mouseDoubleClickEvent(QMouseEvent *)75 void SourceTable::mouseDoubleClickEvent(QMouseEvent* ) {
76 commons_.mouseDoubleClickEvent(selectionModel()->selectedRows());
77 }
78
dragEnterEvent(QDragEnterEvent * event)79 void SourceTable::dragEnterEvent(QDragEnterEvent *event) {
80 if (event->mimeData()->hasUrls()) {
81 event->acceptProposedAction();
82 } else {
83 QTreeView::dragEnterEvent(event);
84 }
85 }
86
dragMoveEvent(QDragMoveEvent * event)87 void SourceTable::dragMoveEvent(QDragMoveEvent *event) {
88 if (event->mimeData()->hasUrls()) {
89 event->acceptProposedAction();
90 } else {
91 QTreeView::dragMoveEvent(event);
92 }
93 }
94
dropEvent(QDropEvent * event)95 void SourceTable::dropEvent(QDropEvent* event) {
96 commons_.dropEvent(this, event, indexAt(event->pos()), selectionModel()->selectedRows());
97 }
98