subsurface/desktop-widgets/divepicturewidget.cpp
Berthold Stoeger 05a1626c7e Implement different zoom levels for dive photos tab
This implements different zoom levels for the dive photos tab as
suggested by Stefan Fuchs <sfuchs@gmx.de> in #898.
The zoom level can be changed using a slider or CTRL+mousewheel.
Zoom levels range from a third of the standard thumbnail size to
thrice the standard thumbnail size.

Thumbnails are cached in maximum resolution and scaled down on
the fly. Because the profile widget took its pictures from the
photo list model, an extra picture copy with a fixed size had
to be introduced.

The UI is still a bit crude.

Reported-by: Stefan Fuchs <sfuchs@gmx.de>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-12-18 12:07:10 -08:00

75 lines
2.3 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) {
QString filename = model()->data(indexAt(event->pos()), Qt::DisplayPropertyRole).toString();
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 << event->pos();
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);
} else {
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);
}