aboutsummaryrefslogtreecommitdiffstats
path: root/desktop-widgets/divepicturewidget.cpp
blob: fcdd010da5e1c0e6b053cd5af9c1b6fecd08bf20 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// SPDX-License-Identifier: GPL-2.0
#include "desktop-widgets/divepicturewidget.h"
#include "qt-models/divepicturemodel.h"
#include "core/metrics.h"
#include "core/dive.h"
#include "core/divelist.h"
#include <unistd.h>
#include <QtConcurrentMap>
#include <QtConcurrentRun>
#include <QFuture>
#include <QDir>
#include <QCryptographicHash>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include "desktop-widgets/mainwindow.h"
#include "core/qthelper.h"
#include <QStandardPaths>
#include <QtWidgets>

DivePictureWidget::DivePictureWidget(QWidget *parent) : QListView(parent)
{
	connect(this, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(doubleClicked(const QModelIndex &)));
}

void DivePictureWidget::doubleClicked(const QModelIndex &index)
{
	QString filePath = model()->data(index, Qt::DisplayPropertyRole).toString();
	emit photoDoubleClicked(localFilePath(filePath));
}


void DivePictureWidget::mousePressEvent(QMouseEvent *event)
{
	int doubleClickInterval = qApp->styleHints()->mouseDoubleClickInterval();
	static qint64 lasttime = 0L;
	qint64 timestamp = QDateTime::currentDateTime().toMSecsSinceEpoch();

	if (timestamp - lasttime <= doubleClickInterval) {
		doubleClicked(indexAt(event->pos()));
	} else {
		lasttime = timestamp;
		QPixmap pixmap = model()->data(indexAt(event->pos()), Qt::DecorationRole).value<QPixmap>();

		QString filename = model()->data(indexAt(event->pos()), Qt::DisplayPropertyRole).toString();

		QByteArray itemData;
		QDataStream dataStream(&itemData, QIODevice::WriteOnly);
		dataStream << filename << event->pos();

		QMimeData *mimeData = new QMimeData;
		mimeData->setData("application/x-subsurfaceimagedrop", itemData);

		QDrag *drag = new QDrag(this);
		drag->setMimeData(mimeData);
		drag->setPixmap(pixmap);
		drag->setHotSpot(event->pos() - rectForIndex(indexAt(event->pos())).topLeft());

		drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::CopyAction);
	}
}