diff options
author | Petr Mrázek <peterix@gmail.com> | 2019-10-14 02:31:53 +0200 |
---|---|---|
committer | Petr Mrázek <peterix@gmail.com> | 2019-10-14 02:31:53 +0200 |
commit | 9cc5ebcdd15736d648554c81e250cd6ce21f6e98 (patch) | |
tree | 8a3ee8329208e1324d278e1f21c826e33b00ba53 /application/widgets | |
parent | c60647523e0a19adff994ff165410e5f0438d718 (diff) | |
download | MultiMC-9cc5ebcdd15736d648554c81e250cd6ce21f6e98.tar MultiMC-9cc5ebcdd15736d648554c81e250cd6ce21f6e98.tar.gz MultiMC-9cc5ebcdd15736d648554c81e250cd6ce21f6e98.tar.lz MultiMC-9cc5ebcdd15736d648554c81e250cd6ce21f6e98.tar.xz MultiMC-9cc5ebcdd15736d648554c81e250cd6ce21f6e98.zip |
GH-2859 improve UI for twitch pack import with drag&drop
Diffstat (limited to 'application/widgets')
-rw-r--r-- | application/widgets/DropLabel.cpp | 41 | ||||
-rw-r--r-- | application/widgets/DropLabel.h | 20 |
2 files changed, 61 insertions, 0 deletions
diff --git a/application/widgets/DropLabel.cpp b/application/widgets/DropLabel.cpp new file mode 100644 index 00000000..a900e57c --- /dev/null +++ b/application/widgets/DropLabel.cpp @@ -0,0 +1,41 @@ +#include "DropLabel.h" + +#include <QMimeData> +#include <QDropEvent> + +DropLabel::DropLabel(QWidget *parent) : QLabel(parent) +{ + setAcceptDrops(true); +} + +void DropLabel::dragEnterEvent(QDragEnterEvent *event) +{ + event->acceptProposedAction(); +} + +void DropLabel::dragMoveEvent(QDragMoveEvent *event) +{ + event->acceptProposedAction(); +} + +void DropLabel::dragLeaveEvent(QDragLeaveEvent *event) +{ + event->accept(); +} + +void DropLabel::dropEvent(QDropEvent *event) +{ + const QMimeData *mimeData = event->mimeData(); + + if (!mimeData) + { + return; + } + + if (mimeData->hasUrls()) { + auto urls = mimeData->urls(); + emit droppedURLs(urls); + } + + event->acceptProposedAction(); +} diff --git a/application/widgets/DropLabel.h b/application/widgets/DropLabel.h new file mode 100644 index 00000000..c5ca0bcc --- /dev/null +++ b/application/widgets/DropLabel.h @@ -0,0 +1,20 @@ +#pragma once + +#include <QLabel> + +class DropLabel : public QLabel +{ + Q_OBJECT + +public: + explicit DropLabel(QWidget *parent = nullptr); + +signals: + void droppedURLs(QList<QUrl> urls); + +protected: + void dropEvent(QDropEvent *event) override; + void dragEnterEvent(QDragEnterEvent *event) override; + void dragMoveEvent(QDragMoveEvent *event) override; + void dragLeaveEvent(QDragLeaveEvent *event) override; +}; |