1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-10-06 23:03:22 +02:00
GPXSee/src/GUI/tooltip.cpp

53 lines
1.3 KiB
C++
Raw Normal View History

#include "popup.h"
2016-08-02 00:28:56 +02:00
#include "tooltip.h"
2019-11-15 22:10:55 +01:00
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);
}
2019-11-15 22:10:55 +01:00
return QSize(width, height);
}
2016-08-02 00:28:56 +02:00
void ToolTip::insert(const QString &key, const QString &value)
{
_list.append(KV<QString, QString>(key, value));
2016-08-02 00:28:56 +02:00
}
2019-03-15 19:39:52 +01:00
QString ToolTip::toString() const
2016-08-02 00:28:56 +02:00
{
QString html;
2019-11-15 22:10:55 +01:00
if (_images.size()) {
html = "<div align=\"center\">";
for (int i = 0; i < _images.size(); i++) {
const ImageInfo &img = _images.at(i);
QSize size(thumbnailSize(img, qMin(960/_images.size(), 240)));
2019-03-15 19:39:52 +01:00
2019-11-15 22:10:55 +01:00
html += QString("<a href=\"file:%0\">"
"<img src=\"%0\" width=\"%1\" height=\"%2\"/></a>")
.arg(img.path(), QString::number(size.width()),
QString::number(size.height()));
}
2019-03-15 19:39:52 +01:00
html += "</div>";
}
if (!_list.isEmpty()) {
html += "<table>";
for (int i = 0; i < _list.count(); i++)
html += "<tr><td align=\"right\"><b>" + _list.at(i).key()
+ ":&nbsp;</b></td><td>" + _list.at(i).value() + "</td></tr>";
html += "</table>";
}
2016-08-02 00:28:56 +02:00
return html;
2016-08-02 00:28:56 +02:00
}