GH-2859 improve UI for twitch pack import with drag&drop
This commit is contained in:
		| @@ -178,6 +178,8 @@ SET(MULTIMC_SOURCES | |||||||
|     widgets/Common.h |     widgets/Common.h | ||||||
|     widgets/CustomCommands.cpp |     widgets/CustomCommands.cpp | ||||||
|     widgets/CustomCommands.h |     widgets/CustomCommands.h | ||||||
|  |     widgets/DropLabel.cpp | ||||||
|  |     widgets/DropLabel.h | ||||||
|     widgets/FocusLineEdit.cpp |     widgets/FocusLineEdit.cpp | ||||||
|     widgets/FocusLineEdit.h |     widgets/FocusLineEdit.h | ||||||
|     widgets/IconLabel.cpp |     widgets/IconLabel.cpp | ||||||
|   | |||||||
| @@ -10,6 +10,11 @@ TwitchPage::TwitchPage(NewInstanceDialog* dialog, QWidget *parent) | |||||||
| { | { | ||||||
|     ui->setupUi(this); |     ui->setupUi(this); | ||||||
|     connect(ui->checkButton, &QPushButton::clicked, this, &TwitchPage::triggerCheck); |     connect(ui->checkButton, &QPushButton::clicked, this, &TwitchPage::triggerCheck); | ||||||
|  |     connect(ui->twitchLabel, &DropLabel::droppedURLs, [this](QList<QUrl> urls){ | ||||||
|  |         if(urls.size()) { | ||||||
|  |             setUrl(urls[0].toString()); | ||||||
|  |         } | ||||||
|  |     }); | ||||||
| } | } | ||||||
|  |  | ||||||
| TwitchPage::~TwitchPage() | TwitchPage::~TwitchPage() | ||||||
|   | |||||||
| @@ -6,23 +6,13 @@ | |||||||
|    <rect> |    <rect> | ||||||
|     <x>0</x> |     <x>0</x> | ||||||
|     <y>0</y> |     <y>0</y> | ||||||
|     <width>546</width> |     <width>666</width> | ||||||
|     <height>405</height> |     <height>424</height> | ||||||
|    </rect> |    </rect> | ||||||
|   </property> |   </property> | ||||||
|   <layout class="QGridLayout" name="gridLayout"> |   <layout class="QGridLayout" name="gridLayout"> | ||||||
|    <item row="0" column="1"> |  | ||||||
|     <widget class="QLineEdit" name="lineEdit"/> |  | ||||||
|    </item> |  | ||||||
|    <item row="0" column="0"> |  | ||||||
|     <widget class="QLabel" name="label"> |  | ||||||
|      <property name="text"> |  | ||||||
|       <string>Twitch URL:</string> |  | ||||||
|      </property> |  | ||||||
|     </widget> |  | ||||||
|    </item> |  | ||||||
|    <item row="1" column="0" colspan="3"> |    <item row="1" column="0" colspan="3"> | ||||||
|     <widget class="QLabel" name="twitchLabel"> |     <widget class="DropLabel" name="twitchLabel"> | ||||||
|      <property name="sizePolicy"> |      <property name="sizePolicy"> | ||||||
|       <sizepolicy hsizetype="Preferred" vsizetype="Expanding"> |       <sizepolicy hsizetype="Preferred" vsizetype="Expanding"> | ||||||
|        <horstretch>0</horstretch> |        <horstretch>0</horstretch> | ||||||
| @@ -49,8 +39,35 @@ | |||||||
|      </property> |      </property> | ||||||
|     </widget> |     </widget> | ||||||
|    </item> |    </item> | ||||||
|  |    <item row="0" column="0"> | ||||||
|  |     <widget class="QLabel" name="label"> | ||||||
|  |      <property name="text"> | ||||||
|  |       <string>Twitch URL:</string> | ||||||
|  |      </property> | ||||||
|  |     </widget> | ||||||
|  |    </item> | ||||||
|  |    <item row="0" column="1"> | ||||||
|  |     <widget class="QLineEdit" name="lineEdit"/> | ||||||
|  |    </item> | ||||||
|  |    <item row="2" column="0" colspan="3"> | ||||||
|  |     <widget class="QLabel" name="label_2"> | ||||||
|  |      <property name="text"> | ||||||
|  |       <string>Drag and drop an Install button from CurseForge into the are above.</string> | ||||||
|  |      </property> | ||||||
|  |      <property name="alignment"> | ||||||
|  |       <set>Qt::AlignCenter</set> | ||||||
|  |      </property> | ||||||
|  |     </widget> | ||||||
|  |    </item> | ||||||
|   </layout> |   </layout> | ||||||
|  </widget> |  </widget> | ||||||
|  |  <customwidgets> | ||||||
|  |   <customwidget> | ||||||
|  |    <class>DropLabel</class> | ||||||
|  |    <extends>QLabel</extends> | ||||||
|  |    <header>widgets/DropLabel.h</header> | ||||||
|  |   </customwidget> | ||||||
|  |  </customwidgets> | ||||||
|  <tabstops> |  <tabstops> | ||||||
|   <tabstop>lineEdit</tabstop> |   <tabstop>lineEdit</tabstop> | ||||||
|   <tabstop>checkButton</tabstop> |   <tabstop>checkButton</tabstop> | ||||||
|   | |||||||
							
								
								
									
										41
									
								
								application/widgets/DropLabel.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								application/widgets/DropLabel.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -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(); | ||||||
|  | } | ||||||
							
								
								
									
										20
									
								
								application/widgets/DropLabel.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								application/widgets/DropLabel.h
									
									
									
									
									
										Normal file
									
								
							| @@ -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; | ||||||
|  | }; | ||||||
		Reference in New Issue
	
	Block a user
	 Petr Mrázek
					Petr Mrázek