From 81ea0490cf345ad25d6278529adddb7bd05fd40f Mon Sep 17 00:00:00 2001 From: Syping Date: Fri, 29 Jun 2018 08:52:43 +0200 Subject: [PATCH] add ability to drop images --- ProfileInterface.cpp | 13 +++++++++++-- uimod/UiModWidget.cpp | 22 ++++++++++++++++------ uimod/UiModWidget.h | 6 ++++-- 3 files changed, 31 insertions(+), 10 deletions(-) diff --git a/ProfileInterface.cpp b/ProfileInterface.cpp index f303772..6de5a01 100644 --- a/ProfileInterface.cpp +++ b/ProfileInterface.cpp @@ -88,7 +88,8 @@ ProfileInterface::ProfileInterface(ProfileDatabase *profileDB, CrewDatabase *cre updatePalette(); ui->labVersion->setText(QString("%1 %2").arg(GTA5SYNC_APPSTR, GTA5SYNC_APPVER)); - ui->saProfileContent->setFilesMode(true); + ui->saProfileContent->setFilesDropEnabled(true); + ui->saProfileContent->setImageDropEnabled(true); // Set Icon for Close Button if (QIcon::hasThemeIcon("dialog-close")) @@ -1411,7 +1412,15 @@ void ProfileInterface::contextMenuTriggeredSGD(QContextMenuEvent *ev) void ProfileInterface::on_saProfileContent_dropped(const QMimeData *mimeData) { if (!mimeData) return; - importUrls(mimeData); + if (mimeData->hasImage()) + { + QImage *snapmaticImage = new QImage(qvariant_cast(mimeData->imageData())); + importImage(snapmaticImage, QDateTime::currentDateTime()); + } + else if (mimeData->hasUrls()) + { + importUrls(mimeData); + } } void ProfileInterface::retranslateUi() diff --git a/uimod/UiModWidget.cpp b/uimod/UiModWidget.cpp index 75cddf7..ff8946c 100644 --- a/uimod/UiModWidget.cpp +++ b/uimod/UiModWidget.cpp @@ -26,26 +26,32 @@ UiModWidget::UiModWidget(QWidget *parent) : QWidget(parent) { - filesMode = false; + filesDropEnabled = false; + imageDropEnabled = false; } UiModWidget::~UiModWidget() { } -void UiModWidget::setFilesMode(bool filesModeEnabled) +void UiModWidget::setFilesDropEnabled(bool enabled) { - filesMode = filesModeEnabled; + filesDropEnabled = enabled; +} + +void UiModWidget::setImageDropEnabled(bool enabled) +{ + imageDropEnabled = enabled; } void UiModWidget::dragEnterEvent(QDragEnterEvent *dragEnterEvent) { - if (filesMode && dragEnterEvent->mimeData()->hasUrls()) + if (filesDropEnabled && dragEnterEvent->mimeData()->hasUrls()) { QStringList pathList; - QList urlList = dragEnterEvent->mimeData()->urls(); + const QList urlList = dragEnterEvent->mimeData()->urls(); - foreach(const QUrl ¤tUrl, urlList) + for (const QUrl ¤tUrl : urlList) { if (currentUrl.isLocalFile()) { @@ -58,6 +64,10 @@ void UiModWidget::dragEnterEvent(QDragEnterEvent *dragEnterEvent) dragEnterEvent->acceptProposedAction(); } } + else if (imageDropEnabled && dragEnterEvent->mimeData()->hasImage()) + { + dragEnterEvent->acceptProposedAction(); + } } void UiModWidget::dropEvent(QDropEvent *dropEvent) diff --git a/uimod/UiModWidget.h b/uimod/UiModWidget.h index db3ae04..469c000 100644 --- a/uimod/UiModWidget.h +++ b/uimod/UiModWidget.h @@ -29,7 +29,8 @@ class UiModWidget : public QWidget Q_OBJECT public: UiModWidget(QWidget *parent = 0); - void setFilesMode(bool enabled); + void setFilesDropEnabled(bool enabled); + void setImageDropEnabled(bool enabled); ~UiModWidget(); protected: @@ -38,7 +39,8 @@ protected: void paintEvent(QPaintEvent *paintEvent); private: - bool filesMode; + bool filesDropEnabled; + bool imageDropEnabled; signals: void dropped(const QMimeData *mimeData);