add ability to drop images

This commit is contained in:
Syping 2018-06-29 08:52:43 +02:00
parent a8db3985a2
commit 81ea0490cf
3 changed files with 31 additions and 10 deletions

View file

@ -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<QImage>(mimeData->imageData()));
importImage(snapmaticImage, QDateTime::currentDateTime());
}
else if (mimeData->hasUrls())
{
importUrls(mimeData);
}
}
void ProfileInterface::retranslateUi()

View file

@ -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<QUrl> urlList = dragEnterEvent->mimeData()->urls();
const QList<QUrl> urlList = dragEnterEvent->mimeData()->urls();
foreach(const QUrl &currentUrl, urlList)
for (const QUrl &currentUrl : 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)

View file

@ -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);