From 1c771a46b8ed697ee02b8a24c41ad64b1da44b5b Mon Sep 17 00:00:00 2001 From: Om Prakash Mohapatra <158698144+OfficialMunu@users.noreply.github.com> Date: Fri, 8 Nov 2024 23:28:19 +0530 Subject: [PATCH] Update ic_library_drag_and_drop.svg MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit setAcceptDrops(true): This enables the widget to accept drag and drop events. dragEnterEvent: This event is triggered when a drag operation enters the widget. If the dragged data (like a file URL) is valid, we accept the drop and set the cursor to Qt::CopyCursor, which indicates that the object can be copied (or dropped). dragMoveEvent: This event happens as the dragged object moves inside the widget area. It’s important to update the cursor here as well. dragLeaveEvent: When the dragged object leaves the widget area without dropping, you should revert the cursor back to its original state. dropEvent: Handles the final drop operation, where you process the dragged data (e.g., load the file onto the deck). --- .../library/ic_library_drag_and_drop.svg | 281 +++--------------- 1 file changed, 44 insertions(+), 237 deletions(-) diff --git a/res/images/library/ic_library_drag_and_drop.svg b/res/images/library/ic_library_drag_and_drop.svg index 2b8d6b58fa1..5636609a74b 100644 --- a/res/images/library/ic_library_drag_and_drop.svg +++ b/res/images/library/ic_library_drag_and_drop.svg @@ -1,238 +1,45 @@ - - - - - - - Mixxx 1.12+ iconset - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - image/svg+xml - en - - - image/svg+xml - - Mixxx 1.12+ iconset - - - Mixxx - GUI - Interface - Icons - - - - - s.brandt@mixxx.org - - - - 2014-04-18 - www.mixxx.org - Iconset for use in Mixxx 1.12s+. Optimized for 48px (16px) icon size. Contains icons for preference menu and library widget +#include +#include +#include +#include +#include +#include +#include -Grid based on suggestions from http://techbase.kde.org/Projects/Oxygen/Style - - en - - - - - - - - - - - - - - - - - - +class DeckWidget : public QWidget { + Q_OBJECT + +public: + DeckWidget(QWidget *parent = nullptr) : QWidget(parent) { + setAcceptDrops(true); // Enable drag and drop + } + +protected: + void dragEnterEvent(QDragEnterEvent *event) override { + // Only accept the event if the source is valid (e.g., file manager) + if (event->mimeData()->hasUrls()) { + event->acceptProposedAction(); + setCursor(Qt::CopyCursor); // Set the drag cursor here + } + } + + void dragMoveEvent(QDragMoveEvent *event) override { + if (event->mimeData()->hasUrls()) { + event->accept(); // Continue the drag operation + setCursor(Qt::CopyCursor); // Ensure the drag cursor remains + } + } + + void dragLeaveEvent(QDragLeaveEvent *event) override { + event->accept(); // Finish the drag operation + unsetCursor(); // Restore the original cursor + } + + void dropEvent(QDropEvent *event) override { + // Handle the drop logic here (e.g., adding a track to the deck) + if (event->mimeData()->hasUrls()) { + event->acceptProposedAction(); + // Perform your drop handling here (like loading the file to the deck) + } + } +};