1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-28 05:34:47 +01:00
GPXSee/src/GUI/thumbnail.cpp

53 lines
1.3 KiB
C++
Raw Normal View History

#include <QImageReader>
#include <QDesktopServices>
#include <QFileInfo>
#include <QMouseEvent>
#include "thumbnail.h"
static QSize thumbnailSize(const QSize &size, int limit)
{
int width, height;
if (size.width() > size.height()) {
width = qMin(size.width(), limit);
qreal ratio = size.width() / (qreal)size.height();
height = (int)(width / ratio);
} else {
height = qMin(size.height(), limit);
qreal ratio = size.height() / (qreal)size.width();
width = (int)(height / ratio);
}
return QSize(width, height);
}
Thumbnail::Thumbnail(const QString &path, int limit, QWidget *parent)
: QLabel(parent)
{
QImageReader reader(path);
reader.setAutoTransform(true);
reader.setScaledSize(thumbnailSize(reader.size(), limit));
setPixmap(QPixmap::fromImage(reader.read()));
setCursor(Qt::PointingHandCursor);
setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
2022-05-28 14:05:14 +02:00
#ifdef Q_OS_ANDROID
_path = path;
#else //Q_OS_ANDROID
_path = QFileInfo(path).absoluteFilePath();
2022-05-28 14:05:14 +02:00
#endif // Q_OS_ANDROID
}
void Thumbnail::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton)
2022-05-28 14:05:14 +02:00
#ifdef Q_OS_ANDROID
QDesktopServices::openUrl(_path);
#else // Q_OS_ANDROID
QDesktopServices::openUrl(QUrl::fromLocalFile(_path));
2022-05-28 14:05:14 +02:00
#endif // Q_OS_ANDROID
QLabel::mousePressEvent(event);
}