From 9cc5ebcdd15736d648554c81e250cd6ce21f6e98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Mon, 14 Oct 2019 02:31:53 +0200 Subject: [PATCH] GH-2859 improve UI for twitch pack import with drag&drop --- application/CMakeLists.txt | 2 + application/pages/modplatform/TwitchPage.cpp | 5 +++ application/pages/modplatform/TwitchPage.ui | 43 ++++++++++++++------ application/widgets/DropLabel.cpp | 41 +++++++++++++++++++ application/widgets/DropLabel.h | 20 +++++++++ 5 files changed, 98 insertions(+), 13 deletions(-) create mode 100644 application/widgets/DropLabel.cpp create mode 100644 application/widgets/DropLabel.h diff --git a/application/CMakeLists.txt b/application/CMakeLists.txt index 4ce031f7..74139557 100644 --- a/application/CMakeLists.txt +++ b/application/CMakeLists.txt @@ -178,6 +178,8 @@ SET(MULTIMC_SOURCES widgets/Common.h widgets/CustomCommands.cpp widgets/CustomCommands.h + widgets/DropLabel.cpp + widgets/DropLabel.h widgets/FocusLineEdit.cpp widgets/FocusLineEdit.h widgets/IconLabel.cpp diff --git a/application/pages/modplatform/TwitchPage.cpp b/application/pages/modplatform/TwitchPage.cpp index ea0f9267..389e3194 100644 --- a/application/pages/modplatform/TwitchPage.cpp +++ b/application/pages/modplatform/TwitchPage.cpp @@ -10,6 +10,11 @@ TwitchPage::TwitchPage(NewInstanceDialog* dialog, QWidget *parent) { ui->setupUi(this); connect(ui->checkButton, &QPushButton::clicked, this, &TwitchPage::triggerCheck); + connect(ui->twitchLabel, &DropLabel::droppedURLs, [this](QList urls){ + if(urls.size()) { + setUrl(urls[0].toString()); + } + }); } TwitchPage::~TwitchPage() diff --git a/application/pages/modplatform/TwitchPage.ui b/application/pages/modplatform/TwitchPage.ui index 0db2484d..f87af421 100644 --- a/application/pages/modplatform/TwitchPage.ui +++ b/application/pages/modplatform/TwitchPage.ui @@ -6,23 +6,13 @@ 0 0 - 546 - 405 + 666 + 424 - - - - - - - Twitch URL: - - - - + 0 @@ -49,8 +39,35 @@ + + + + Twitch URL: + + + + + + + + + + Drag and drop an Install button from CurseForge into the are above. + + + Qt::AlignCenter + + + + + + DropLabel + QLabel +
widgets/DropLabel.h
+
+
lineEdit checkButton 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 +#include + +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 + +class DropLabel : public QLabel +{ + Q_OBJECT + +public: + explicit DropLabel(QWidget *parent = nullptr); + +signals: + void droppedURLs(QList urls); + +protected: + void dropEvent(QDropEvent *event) override; + void dragEnterEvent(QDragEnterEvent *event) override; + void dragMoveEvent(QDragMoveEvent *event) override; + void dragLeaveEvent(QDragLeaveEvent *event) override; +};