From 5be2319b12feb703e5966c874f969a51bbc80fa5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sch=C3=BCrmann?= Date: Sun, 5 May 2024 14:51:39 +0200 Subject: [PATCH 1/3] Unify event name to pEvent in drag and drop code --- src/util/dnd.cpp | 22 +++++++++++----------- src/util/dnd.h | 4 ++-- src/widget/trackdroptarget.h | 4 ++-- src/widget/wspinnybase.cpp | 12 ++++++------ src/widget/wspinnybase.h | 2 +- src/widget/wwaveformviewer.cpp | 12 ++++++------ src/widget/wwaveformviewer.h | 2 +- 7 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/util/dnd.cpp b/src/util/dnd.cpp index 08ce11491f1..2f98506670e 100644 --- a/src/util/dnd.cpp +++ b/src/util/dnd.cpp @@ -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 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(); } diff --git a/src/util/dnd.h b/src/util/dnd.h index 6a83457c4d7..5361b0fcefb 100644 --- a/src/util/dnd.h +++ b/src/util/dnd.h @@ -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); diff --git a/src/widget/trackdroptarget.h b/src/widget/trackdroptarget.h index 56dc3af3d19..202b1cc99af 100644 --- a/src/widget/trackdroptarget.h +++ b/src/widget/trackdroptarget.h @@ -22,8 +22,8 @@ class TrackDropTarget { emit trackDropped(filename, group); // clazy:exclude=incorrect-emit } - virtual bool handleDragAndDropEventFromWindow(QEvent* event) { - Q_UNUSED(event); + virtual bool handleDragAndDropEventFromWindow(QEvent* pEvent) { + Q_UNUSED(pEvent); return false; } diff --git a/src/widget/wspinnybase.cpp b/src/widget/wspinnybase.cpp index 62f780bec09..083f6f55d5d 100644 --- a/src/widget/wspinnybase.cpp +++ b/src/widget/wspinnybase.cpp @@ -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); } diff --git a/src/widget/wspinnybase.h b/src/widget/wspinnybase.h index a43e08ac235..bc7703c6cae 100644 --- a/src/widget/wspinnybase.h +++ b/src/widget/wspinnybase.h @@ -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); diff --git a/src/widget/wwaveformviewer.cpp b/src/widget/wwaveformviewer.cpp index 8cd120760f8..da585c8e937 100644 --- a/src/widget/wwaveformviewer.cpp +++ b/src/widget/wwaveformviewer.cpp @@ -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*) { diff --git a/src/widget/wwaveformviewer.h b/src/widget/wwaveformviewer.h index fde5d9cd10d..eead266f540 100644 --- a/src/widget/wwaveformviewer.h +++ b/src/widget/wwaveformviewer.h @@ -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; From b75d63bee69e323422a5dd7098e079b5d270f488 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sch=C3=BCrmann?= Date: Sun, 5 May 2024 14:54:53 +0200 Subject: [PATCH 2/3] ignore drag and drop event in handleDragAndDropEventFromWindow() dafault implementation --- src/widget/trackdroptarget.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/widget/trackdroptarget.h b/src/widget/trackdroptarget.h index 202b1cc99af..ba04689ac29 100644 --- a/src/widget/trackdroptarget.h +++ b/src/widget/trackdroptarget.h @@ -1,9 +1,8 @@ #pragma once +#include #include -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 @@ -23,7 +22,7 @@ class TrackDropTarget { } virtual bool handleDragAndDropEventFromWindow(QEvent* pEvent) { - Q_UNUSED(pEvent); + pEvent->ignore(); return false; } From a2b1867683b477b55ecb86299a3cb5be88b21efd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sch=C3=BCrmann?= Date: Sun, 5 May 2024 17:21:02 +0200 Subject: [PATCH 3/3] Handle ignored drag events in OpenGLWindow like Qt does it in QWidgetWindow --- src/widget/openglwindow.cpp | 42 ++++++++++++++++++++++++++++++------- src/widget/openglwindow.h | 2 ++ 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/src/widget/openglwindow.cpp b/src/widget/openglwindow.cpp index 0bcda0ddd05..b84e8d41af5 100644 --- a/src/widget/openglwindow.cpp +++ b/src/widget/openglwindow.cpp @@ -10,7 +10,8 @@ #include "widget/wglwidget.h" OpenGLWindow::OpenGLWindow(WGLWidget* pWidget) - : m_pWidget(pWidget) { + : m_pWidget(pWidget), + m_pTrackDropTarget(nullptr) { setFormat(WaveformWidgetFactory::getSurfaceFormat()); } @@ -66,19 +67,46 @@ bool OpenGLWindow::event(QEvent* pEv) { if (t == QEvent::MouseMove) { ToolTipQOpenGL::singleton().start( m_pWidget, dynamic_cast(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 } diff --git a/src/widget/openglwindow.h b/src/widget/openglwindow.h index a3a4f3ebdc6..74e8f954db6 100644 --- a/src/widget/openglwindow.h +++ b/src/widget/openglwindow.h @@ -3,6 +3,7 @@ #include class WGLWidget; +class TrackDropTarget; /// Helper class used by wglwidgetqopengl @@ -22,4 +23,5 @@ class OpenGLWindow : public QOpenGLWindow { bool event(QEvent* pEv) override; WGLWidget* m_pWidget; + TrackDropTarget* m_pTrackDropTarget; };