-
Notifications
You must be signed in to change notification settings - Fork 0
/
videowidget.cpp
52 lines (47 loc) · 1.22 KB
/
videowidget.cpp
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
#include "videowidget.h"
#include <QEvent>
#include <QDropEvent>
#include <QMimeData>
VideoWidget::VideoWidget(QWidget *parent) : QVideoWidget(parent)
{
QObject *child = findChild<QWidget*>();
child->installEventFilter(this);
}
// Qt 6 bug: https://bugreports.qt.io/browse/QTBUG-107668
bool VideoWidget::eventFilter(QObject *object, QEvent *event)
{
QObject *child = findChild<QWidget*>();
if(object == child){
if(event->type() == QEvent::DragEnter)
{
event->accept();
return true;
}
else if(event->type() == QEvent::DragMove)
{
event->accept();
return true;
}
else if(event->type() == QEvent::Drop)
{
handleDragDidDrop(static_cast<QDropEvent *>(event));
event->accept();
return true;
}
}
return QVideoWidget::eventFilter(object, event);
}
void VideoWidget::handleDragDidDrop(QDropEvent *event) {
auto mimeData = event->mimeData();
if (!mimeData) {
return;
}
if (!mimeData->hasUrls()) {
return;
}
if (mimeData->urls().count() < 1) {
return;
}
auto url = mimeData->urls().at(0);
emit dragDidDropUrl(url);
}