forked from IENT/YUView
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplaylisttreewidget.cpp
More file actions
138 lines (122 loc) · 4.09 KB
/
Copy pathplaylisttreewidget.cpp
File metadata and controls
138 lines (122 loc) · 4.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/* YUView - YUV player with advanced analytics toolset
* Copyright (C) 2015 Institut für Nachrichtentechnik
* RWTH Aachen University, GERMANY
*
* YUView is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* YUView is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with YUView. If not, see <http://www.gnu.org/licenses/>.
*/
#include "playlisttreewidget.h"
#include <QDragEnterEvent>
#include <QUrl>
#include <QMimeData>
#include "playlistitem.h"
#include "mainwindow.h"
PlaylistTreeWidget::PlaylistTreeWidget(QWidget *parent) : QTreeWidget(parent)
{
setDragEnabled(true);
setDropIndicatorShown(true);
setDragDropMode(QAbstractItemView::InternalMove);
setSortingEnabled(true);
}
PlaylistItem* PlaylistTreeWidget::getDropTarget(QPoint pos)
{
PlaylistItem *pItem = dynamic_cast<PlaylistItem*>(this->itemAt(pos));
if (pItem != NULL)
{
// check if dropped on or below/above pItem
QRect rc = this->visualItemRect(pItem);
QRect rcNew = QRect(rc.left(), rc.top() + 2, rc.width(), rc.height() - 4);
if (!rcNew.contains(pos, true))
{
// dropped next to pItem
pItem = NULL;
}
}
return pItem;
}
void PlaylistTreeWidget::dragMoveEvent(QDragMoveEvent* event)
{
PlaylistItem* dropTarget = getDropTarget(event->pos());
if (dropTarget)
{
QList<QTreeWidgetItem*> draggedItems = selectedItems();
PlaylistItem* draggedItem = dynamic_cast<PlaylistItem*>(draggedItems[0]);
// handle video items as target
if( dropTarget->itemType() == VideoItemType && (dropTarget->childCount() != 0 || draggedItems.count() != 1 || draggedItem->itemType() != StatisticsItemType ))
{
// no valid drop
event->ignore();
return;
}
// handle diff items as target
if( dropTarget->itemType() == DifferenceItemType && (dropTarget->childCount() >= 2 || draggedItems.count() > 2 ))
{
// no valid drop
event->ignore();
return;
}
}
QTreeWidget::dragMoveEvent(event);
}
void PlaylistTreeWidget::dragEnterEvent(QDragEnterEvent *event)
{
if (event->mimeData()->hasUrls())
{
event->acceptProposedAction();
}
else // default behavior
{
QTreeWidget::dragEnterEvent(event);
}
}
void PlaylistTreeWidget::dropEvent(QDropEvent *event)
{
if (event->mimeData()->hasUrls())
{
QStringList fileList;
QList<QUrl> urls = event->mimeData()->urls();
if (!urls.isEmpty())
{
QUrl url;
foreach (url, urls)
{
QString fileName = url.toLocalFile();
fileList.append(fileName);
}
}
event->acceptProposedAction();
// use our main window to open this file
MainWindow* mainWindow = (MainWindow*)this->window();
mainWindow->loadFiles(fileList);
}
else
{
QTreeWidget::dropEvent(event);
}
// {
// QModelIndex droppedIndex = indexAt( event->pos() );
// if( !droppedIndex.isValid() )
// return;
// QTreeWidget::dropEvent(event);
// DropIndicatorPosition dp = dropIndicatorPosition();
// if (dp == QAbstractItemView::BelowItem) {
// droppedIndex = droppedIndex.sibling(droppedIndex.row() + 1, // adjust the row number
// droppedIndex.column());
// }
// selectionModel()->select(droppedIndex, QItemSelectionModel::Select);
// }
}
Qt::DropActions PlaylistTreeWidget::supportedDropActions () const
{
return Qt::CopyAction | Qt::MoveAction;
}