1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2025-01-31 09:05:14 +01:00

Added support for multiple images

This commit is contained in:
Martin Tůma 2019-11-15 22:10:55 +01:00
parent 475eb6185a
commit e4d8ab1feb
6 changed files with 32 additions and 24 deletions

View File

@ -1,8 +1,21 @@
#include "popup.h" #include "popup.h"
#include "tooltip.h" #include "tooltip.h"
static QSize thumbnailSize(const ImageInfo &img, int limit)
{
int width, height;
if (img.size().width() > img.size().height()) {
width = qMin(img.size().width(), limit);
qreal ratio = img.size().width() / (qreal)img.size().height();
height = (int)(width / ratio);
} else {
height = qMin(img.size().height(), limit);
qreal ratio = img.size().height() / (qreal)img.size().width();
width = (int)(height / ratio);
}
#define THUMBNAIL_MAX_SIZE 240 return QSize(width, height);
}
void ToolTip::insert(const QString &key, const QString &value) void ToolTip::insert(const QString &key, const QString &value)
{ {
@ -13,22 +26,17 @@ QString ToolTip::toString() const
{ {
QString html; QString html;
if (_img.isValid()) { if (_images.size()) {
int width, height; html = "<div align=\"center\">";
if (_img.size().width() > _img.size().height()) { for (int i = 0; i < _images.size(); i++) {
width = qMin(_img.size().width(), THUMBNAIL_MAX_SIZE); const ImageInfo &img = _images.at(i);
qreal ratio = _img.size().width() / (qreal)_img.size().height(); QSize size(thumbnailSize(img, qMin(960/_images.size(), 240)));
height = (int)(width / ratio);
} else {
height = qMin(_img.size().height(), THUMBNAIL_MAX_SIZE);
qreal ratio = _img.size().height() / (qreal)_img.size().width();
width = (int)(height / ratio);
}
html += "<div align=\"center\">"; html += QString("<a href=\"file:%0\">"
html += QString("<a href=\"file:%0\">" "<img src=\"%0\" width=\"%1\" height=\"%2\"/></a>")
"<img src=\"%0\" width=\"%1\" height=\"%2\"/></a>") .arg(img.path(), QString::number(size.width()),
.arg(_img.path(), QString::number(width), QString::number(height)); QString::number(size.height()));
}
html += "</div>"; html += "</div>";
} }

View File

@ -10,12 +10,12 @@ class ToolTip
{ {
public: public:
void insert(const QString &key, const QString &value); void insert(const QString &key, const QString &value);
void setImage(const ImageInfo &image) {_img = image;} void setImages(const QVector<ImageInfo> &images) {_images = images;}
QString toString() const; QString toString() const;
private: private:
QList<KV<QString, QString> > _list; QList<KV<QString, QString> > _list;
ImageInfo _img; QVector<ImageInfo> _images;
}; };
#endif // TOOLTIP_H #endif // TOOLTIP_H

View File

@ -54,7 +54,7 @@ QString WaypointItem::info() const
} }
tt.insert(qApp->translate("WaypointItem", "Links"), links); tt.insert(qApp->translate("WaypointItem", "Links"), links);
} }
tt.setImage(_waypoint.image()); tt.setImages(_waypoint.images());
return tt.toString(); return tt.toString();
} }

View File

@ -209,7 +209,7 @@ bool EXIFParser::parseTIFF(QFile *file, QVector<Waypoint> &waypoints)
Waypoint wp(c); Waypoint wp(c);
wp.setName(QFileInfo(file->fileName()).baseName()); wp.setName(QFileInfo(file->fileName()).baseName());
wp.setImage(img); wp.addImage(img);
wp.setElevation(altitude(tiff, GPSIFD.value(GPSAltitude), wp.setElevation(altitude(tiff, GPSIFD.value(GPSAltitude),
GPSIFD.value(GPSAltitudeRef))); GPSIFD.value(GPSAltitudeRef)));
wp.setTimestamp(QDateTime(QDate::fromString(text(tiff, wp.setTimestamp(QDateTime(QDate::fromString(text(tiff,

View File

@ -413,7 +413,7 @@ static quint32 readImageInfo(QDataStream &stream, Waypoint &waypoint,
imgFile.write(ba); imgFile.write(ba);
imgFile.close(); imgFile.close();
waypoint.setImage(ImageInfo(imgFile.fileName(), ir.size())); waypoint.addImage(ImageInfo(imgFile.fileName(), ir.size()));
if (size + 5 != rh.size) if (size + 5 != rh.size)
stream.setStatus(QDataStream::ReadCorruptData); stream.setStatus(QDataStream::ReadCorruptData);

View File

@ -21,7 +21,7 @@ public:
const QString &name() const {return _name;} const QString &name() const {return _name;}
const QString &description() const {return _description;} const QString &description() const {return _description;}
const Address &address() const {return _address;} const Address &address() const {return _address;}
const ImageInfo &image() const {return _image;} const QVector<ImageInfo> &images() const {return _images;}
const QVector<Link> &links() const {return _links;} const QVector<Link> &links() const {return _links;}
const QDateTime &timestamp() const {return _timestamp;} const QDateTime &timestamp() const {return _timestamp;}
qreal elevation() const {return _elevation;} qreal elevation() const {return _elevation;}
@ -34,7 +34,7 @@ public:
void setAddress(const Address &address) {_address = address;} void setAddress(const Address &address) {_address = address;}
void setTimestamp(const QDateTime &timestamp) {_timestamp = timestamp;} void setTimestamp(const QDateTime &timestamp) {_timestamp = timestamp;}
void setElevation(qreal elevation) {_elevation = elevation;} void setElevation(qreal elevation) {_elevation = elevation;}
void setImage(const ImageInfo &image) {_image = image;} void addImage(const ImageInfo &image) {_images.append(image);}
void addLink(const Link &link) {_links.append(link);} void addLink(const Link &link) {_links.append(link);}
bool hasElevation() const {return !std::isnan(_elevation);} bool hasElevation() const {return !std::isnan(_elevation);}
@ -48,7 +48,7 @@ private:
QString _name; QString _name;
QString _description; QString _description;
Address _address; Address _address;
ImageInfo _image; QVector<ImageInfo> _images;
QVector<Link> _links; QVector<Link> _links;
QDateTime _timestamp; QDateTime _timestamp;
qreal _elevation; qreal _elevation;