9efb56e2d43161d952efb444d1f13d87bfdd45b5 introduced rather complex logic for picture drag'n'drop events onto the profile. Among other things, the code had to check whether the picture actually belongs to the displayed dive. This can be simplified by transporting the dive-id in the drag'n'drop event structure. The flow goes like this: DivePictureModel--(1)-->DivePictureWidget--(2)-->ProfileWidget For (1), we can use the Qt::UserRole role. This was used to transport the picture-offset, but this is not needed anymore since ProfileWidget was decoupled from DivePictureModel. For (2), we simply replace the "position" value, which was never used. Why would the receiver care which pixel was pressed in the media-tab? This commit also contains a minor cleanup in DivePictureWidget: QListView::mousePressEvent(event) was called in both branches of an if and can therefore be removed from the if. This is so trivial, that it doesn't warrant its own commit. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
75 lines
2.4 KiB
C++
75 lines
2.4 KiB
C++
// 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)
|
|
{
|
|
}
|
|
|
|
void DivePictureWidget::mouseDoubleClickEvent(QMouseEvent *event)
|
|
{
|
|
if (event->button() == Qt::LeftButton) {
|
|
QString filePath = model()->data(indexAt(event->pos()), Qt::DisplayPropertyRole).toString();
|
|
emit photoDoubleClicked(localFilePath(filePath));
|
|
}
|
|
}
|
|
|
|
void DivePictureWidget::mousePressEvent(QMouseEvent *event)
|
|
{
|
|
if (event->button() == Qt::LeftButton && event->modifiers() == Qt::NoModifier) {
|
|
QModelIndex index = indexAt(event->pos());
|
|
QString filename = model()->data(index, Qt::DisplayPropertyRole).toString();
|
|
int diveId = model()->data(index, Qt::UserRole).toInt();
|
|
|
|
if (!filename.isEmpty()) {
|
|
int dim = lrint(defaultIconMetrics().sz_pic * 0.2);
|
|
|
|
QPixmap pixmap = model()->data(indexAt(event->pos()), Qt::DecorationRole).value<QPixmap>();
|
|
pixmap = pixmap.scaled(dim, dim, Qt::KeepAspectRatio);
|
|
|
|
QByteArray itemData;
|
|
QDataStream dataStream(&itemData, QIODevice::WriteOnly);
|
|
dataStream << filename << diveId;
|
|
|
|
QMimeData *mimeData = new QMimeData;
|
|
mimeData->setData("application/x-subsurfaceimagedrop", itemData);
|
|
|
|
QDrag *drag = new QDrag(this);
|
|
drag->setMimeData(mimeData);
|
|
drag->setPixmap(pixmap);
|
|
|
|
drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::CopyAction);
|
|
}
|
|
}
|
|
QListView::mousePressEvent(event);
|
|
}
|
|
|
|
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);
|
|
}
|