2017-04-27 18:26:05 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2016-04-05 05:02:03 +00:00
|
|
|
#include "desktop-widgets/divepicturewidget.h"
|
|
|
|
#include "qt-models/divepicturemodel.h"
|
|
|
|
#include "core/metrics.h"
|
|
|
|
#include "core/dive.h"
|
|
|
|
#include "core/divelist.h"
|
2015-03-02 15:18:16 +00:00
|
|
|
#include <unistd.h>
|
2014-06-26 17:01:31 +00:00
|
|
|
#include <QtConcurrentMap>
|
2015-02-26 13:39:42 +00:00
|
|
|
#include <QtConcurrentRun>
|
2015-03-10 17:22:34 +00:00
|
|
|
#include <QFuture>
|
2014-06-26 17:01:31 +00:00
|
|
|
#include <QDir>
|
2015-02-26 13:39:42 +00:00
|
|
|
#include <QCryptographicHash>
|
2015-03-02 15:18:16 +00:00
|
|
|
#include <QNetworkAccessManager>
|
|
|
|
#include <QNetworkReply>
|
2016-04-05 05:02:03 +00:00
|
|
|
#include "desktop-widgets/mainwindow.h"
|
|
|
|
#include "core/qthelper.h"
|
2015-03-02 15:18:16 +00:00
|
|
|
#include <QStandardPaths>
|
2015-11-03 20:17:50 +00:00
|
|
|
#include <QtWidgets>
|
2015-03-02 15:18:16 +00:00
|
|
|
|
2014-06-03 23:48:59 +00:00
|
|
|
DivePictureWidget::DivePictureWidget(QWidget *parent) : QListView(parent)
|
2014-05-30 17:38:27 +00:00
|
|
|
{
|
2014-06-27 12:16:55 +00:00
|
|
|
}
|
|
|
|
|
2017-11-29 11:40:06 +00:00
|
|
|
void DivePictureWidget::mouseDoubleClickEvent(QMouseEvent *event)
|
2014-06-27 12:16:55 +00:00
|
|
|
{
|
2017-11-29 11:40:06 +00:00
|
|
|
if (event->button() == Qt::LeftButton) {
|
|
|
|
QString filePath = model()->data(indexAt(event->pos()), Qt::DisplayPropertyRole).toString();
|
|
|
|
emit photoDoubleClicked(localFilePath(filePath));
|
|
|
|
}
|
2014-05-30 17:38:27 +00:00
|
|
|
}
|
2015-11-03 20:17:50 +00:00
|
|
|
|
|
|
|
void DivePictureWidget::mousePressEvent(QMouseEvent *event)
|
|
|
|
{
|
2017-11-29 11:40:06 +00:00
|
|
|
if (event->button() == Qt::LeftButton && event->modifiers() == Qt::NoModifier) {
|
2018-07-14 15:40:24 +00:00
|
|
|
QModelIndex index = indexAt(event->pos());
|
|
|
|
QString filename = model()->data(index, Qt::DisplayPropertyRole).toString();
|
|
|
|
int diveId = model()->data(index, Qt::UserRole).toInt();
|
2015-11-03 20:17:50 +00:00
|
|
|
|
2017-11-29 11:40:06 +00:00
|
|
|
if (!filename.isEmpty()) {
|
2017-11-29 17:24:13 +00:00
|
|
|
int dim = lrint(defaultIconMetrics().sz_pic * 0.2);
|
|
|
|
|
2017-11-29 11:40:06 +00:00
|
|
|
QPixmap pixmap = model()->data(indexAt(event->pos()), Qt::DecorationRole).value<QPixmap>();
|
2017-11-29 17:24:13 +00:00
|
|
|
pixmap = pixmap.scaled(dim, dim, Qt::KeepAspectRatio);
|
|
|
|
|
2017-11-29 11:40:06 +00:00
|
|
|
QByteArray itemData;
|
|
|
|
QDataStream dataStream(&itemData, QIODevice::WriteOnly);
|
2018-07-14 15:40:24 +00:00
|
|
|
dataStream << filename << diveId;
|
2017-11-29 11:40:06 +00:00
|
|
|
|
|
|
|
QMimeData *mimeData = new QMimeData;
|
|
|
|
mimeData->setData("application/x-subsurfaceimagedrop", itemData);
|
2015-11-03 20:17:50 +00:00
|
|
|
|
2017-11-29 11:40:06 +00:00
|
|
|
QDrag *drag = new QDrag(this);
|
|
|
|
drag->setMimeData(mimeData);
|
|
|
|
drag->setPixmap(pixmap);
|
2015-11-03 20:17:50 +00:00
|
|
|
|
2017-11-29 11:40:06 +00:00
|
|
|
drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::CopyAction);
|
|
|
|
}
|
2015-11-29 15:13:57 +00:00
|
|
|
}
|
2018-07-14 15:40:24 +00:00
|
|
|
QListView::mousePressEvent(event);
|
2015-11-03 20:17:50 +00:00
|
|
|
}
|
2017-12-17 15:17:38 +00:00
|
|
|
|
|
|
|
void DivePictureWidget::wheelEvent(QWheelEvent *event)
|
|
|
|
{
|
|
|
|
if (event->modifiers() == Qt::ControlModifier) {
|
|
|
|
// Angle delta is given in eighth parts of a degree. A classical mouse
|
|
|
|
// wheel click is 15 degrees. Each click should correspond to one zoom step.
|
|
|
|
// Therefore, divide by 15*8=120. To also support touch pads and finer-grained
|
|
|
|
// mouse wheels, take care to always round away from zero.
|
|
|
|
int delta = event->angleDelta().y();
|
|
|
|
int carry = delta > 0 ? 119 : -119;
|
|
|
|
emit zoomLevelChanged((delta + carry) / 120);
|
|
|
|
} else
|
|
|
|
QListView::wheelEvent(event);
|
|
|
|
}
|