Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle not supported files when dragging to waveforms and spinnies #13208

Merged
merged 3 commits into from
May 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions src/util/dnd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,38 +256,38 @@ QDrag* DragAndDropHelper::dragTrackLocations(

//static
void DragAndDropHelper::handleTrackDragEnterEvent(
QDragEnterEvent* event,
QDragEnterEvent* pEvent,
const QString& group,
UserSettingsPointer pConfig) {
if (allowLoadToPlayer(group, pConfig) &&
dragEnterAccept(*event->mimeData(), group, true, false)) {
event->acceptProposedAction();
dragEnterAccept(*pEvent->mimeData(), group, true, false)) {
pEvent->acceptProposedAction();
} else {
qDebug() << "Ignoring drag enter event, loading not allowed";
event->ignore();
pEvent->ignore();
}
}

//static
void DragAndDropHelper::handleTrackDropEvent(
QDropEvent* event,
QDropEvent* pEvent,
TrackDropTarget& target,
const QString& group,
UserSettingsPointer pConfig) {
if (allowLoadToPlayer(group, pConfig)) {
if (allowDeckCloneAttempt(*event, group)) {
event->accept();
target.emitCloneDeck(event->mimeData()->text(), group);
if (allowDeckCloneAttempt(*pEvent, group)) {
pEvent->accept();
target.emitCloneDeck(pEvent->mimeData()->text(), group);
return;
} else {
const QList<mixxx::FileInfo> files = dropEventFiles(
*event->mimeData(), group, true, false);
*pEvent->mimeData(), group, true, false);
if (!files.isEmpty()) {
event->accept();
pEvent->accept();
target.emitTrackDropped(files.at(0).location(), group);
return;
}
}
}
event->ignore();
pEvent->ignore();
}
4 changes: 2 additions & 2 deletions src/util/dnd.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ class DragAndDropHelper final {
const QString& sourceIdentifier);

static void handleTrackDragEnterEvent(
QDragEnterEvent* event,
QDragEnterEvent* pEvent,
const QString& group,
UserSettingsPointer pConfig);

static void handleTrackDropEvent(
QDropEvent* event,
QDropEvent* pEvent,
TrackDropTarget& target,
const QString& group,
UserSettingsPointer pConfig);
Expand Down
42 changes: 35 additions & 7 deletions src/widget/openglwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
#include "widget/wglwidget.h"

OpenGLWindow::OpenGLWindow(WGLWidget* pWidget)
: m_pWidget(pWidget) {
: m_pWidget(pWidget),
m_pTrackDropTarget(nullptr) {
setFormat(WaveformWidgetFactory::getSurfaceFormat());
}

Expand Down Expand Up @@ -66,19 +67,46 @@ bool OpenGLWindow::event(QEvent* pEv) {
if (t == QEvent::MouseMove) {
ToolTipQOpenGL::singleton().start(
m_pWidget, dynamic_cast<QMouseEvent*>(pEv)->globalPos());
return result;
}

if (t == QEvent::Leave) {
ToolTipQOpenGL::singleton().stop();
return result;
}

// Drag & Drop events are not delivered correctly when using QApplication::sendEvent
// and even result in a recursive call to this method, so we use our own mechanism.

if (t == QEvent::DragEnter) {
DEBUG_ASSERT(!m_pTrackDropTarget);
TrackDropTarget* pTrackDropTarget = m_pWidget->trackDropTarget();
if (pTrackDropTarget) {
bool ret = pTrackDropTarget->handleDragAndDropEventFromWindow(pEv);
if (pEv->isAccepted()) {
m_pTrackDropTarget = pTrackDropTarget;
}
return ret;
}
pEv->ignore();
return false; // clazy:exclude=base-class-event
}

if (t == QEvent::DragEnter || t == QEvent::DragMove ||
t == QEvent::DragLeave || t == QEvent::Drop) {
// Drag & Drop events are not delivered correctly when using QApplication::sendEvent
// and even result in a recursive call to this method, so we use our own mechanism.
if (m_pWidget->trackDropTarget()) {
return m_pWidget->trackDropTarget()->handleDragAndDropEventFromWindow(pEv);
if (t == QEvent::DragMove) {
if (m_pTrackDropTarget) {
bool ret = m_pTrackDropTarget->handleDragAndDropEventFromWindow(pEv);
return ret;
}
pEv->ignore();
return false; // clazy:exclude=base-class-event
}

if (t == QEvent::DragLeave || t == QEvent::Drop) {
if (m_pTrackDropTarget) {
bool ret = m_pTrackDropTarget->handleDragAndDropEventFromWindow(pEv);
m_pTrackDropTarget = nullptr;
return ret;
}
pEv->ignore();
return false; // clazy:exclude=base-class-event
}
Expand Down
2 changes: 2 additions & 0 deletions src/widget/openglwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <QOpenGLWindow>

class WGLWidget;
class TrackDropTarget;

/// Helper class used by wglwidgetqopengl

Expand All @@ -22,4 +23,5 @@ class OpenGLWindow : public QOpenGLWindow {
bool event(QEvent* pEv) override;

WGLWidget* m_pWidget;
TrackDropTarget* m_pTrackDropTarget;
};
7 changes: 3 additions & 4 deletions src/widget/trackdroptarget.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#pragma once

#include <QEvent>
#include <QString>

class QEvent;

/// Mixin to mark a widget as a drop target for tracks.
///
/// This class is *not* derived from QObject (inheriting from 2 QObject classes
Expand All @@ -22,8 +21,8 @@ class TrackDropTarget {
emit trackDropped(filename, group); // clazy:exclude=incorrect-emit
}

virtual bool handleDragAndDropEventFromWindow(QEvent* event) {
Q_UNUSED(event);
virtual bool handleDragAndDropEventFromWindow(QEvent* pEvent) {
pEvent->ignore();
return false;
}

Expand Down
12 changes: 6 additions & 6 deletions src/widget/wspinnybase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -647,14 +647,14 @@ bool WSpinnyBase::event(QEvent* pEvent) {
return WGLWidget::event(pEvent);
}

bool WSpinnyBase::handleDragAndDropEventFromWindow(QEvent* ev) {
return event(ev);
bool WSpinnyBase::handleDragAndDropEventFromWindow(QEvent* pEvent) {
return event(pEvent);
}

void WSpinnyBase::dragEnterEvent(QDragEnterEvent* event) {
DragAndDropHelper::handleTrackDragEnterEvent(event, m_group, m_pConfig);
void WSpinnyBase::dragEnterEvent(QDragEnterEvent* pEvent) {
DragAndDropHelper::handleTrackDragEnterEvent(pEvent, m_group, m_pConfig);
}

void WSpinnyBase::dropEvent(QDropEvent* event) {
DragAndDropHelper::handleTrackDropEvent(event, *this, m_group, m_pConfig);
void WSpinnyBase::dropEvent(QDropEvent* pEvent) {
DragAndDropHelper::handleTrackDropEvent(pEvent, *this, m_group, m_pConfig);
}
2 changes: 1 addition & 1 deletion src/widget/wspinnybase.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class WSpinnyBase : public WGLWidget,
bool event(QEvent* pEvent) override;

// TrackDropTarget:
bool handleDragAndDropEventFromWindow(QEvent* ev) override;
bool handleDragAndDropEventFromWindow(QEvent* pEvent) override;

double calculateAngle(double playpos);
int calculateFullRotations(double playpos);
Expand Down
12 changes: 6 additions & 6 deletions src/widget/wwaveformviewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,16 +202,16 @@ void WWaveformViewer::wheelEvent(QWheelEvent* event) {
}
}

void WWaveformViewer::dragEnterEvent(QDragEnterEvent* event) {
DragAndDropHelper::handleTrackDragEnterEvent(event, m_group, m_pConfig);
void WWaveformViewer::dragEnterEvent(QDragEnterEvent* pEvent) {
DragAndDropHelper::handleTrackDragEnterEvent(pEvent, m_group, m_pConfig);
}

void WWaveformViewer::dropEvent(QDropEvent* event) {
DragAndDropHelper::handleTrackDropEvent(event, *this, m_group, m_pConfig);
void WWaveformViewer::dropEvent(QDropEvent* pEvent) {
DragAndDropHelper::handleTrackDropEvent(pEvent, *this, m_group, m_pConfig);
}

bool WWaveformViewer::handleDragAndDropEventFromWindow(QEvent* ev) {
return event(ev);
bool WWaveformViewer::handleDragAndDropEventFromWindow(QEvent* pEvent) {
return event(pEvent);
}

void WWaveformViewer::leaveEvent(QEvent*) {
Expand Down
2 changes: 1 addition & 1 deletion src/widget/wwaveformviewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class WWaveformViewer : public WWidget, public TrackDropTarget {
}
void setup(const QDomNode& node, const SkinContext& context);

bool handleDragAndDropEventFromWindow(QEvent* ev) override;
bool handleDragAndDropEventFromWindow(QEvent* pEvent) override;

void dragEnterEvent(QDragEnterEvent *event) override;
void dropEvent(QDropEvent *event) override;
Expand Down
Loading