2019-10-13 20:20:32 +02:00
|
|
|
#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-03-13 20:48:25 +01:00
|
|
|
|
2019-11-15 22:10:55 +01:00
|
|
|
return QSize(width, height);
|
|
|
|
}
|
2019-03-13 20:48:25 +01:00
|
|
|
|
2016-08-02 00:28:56 +02:00
|
|
|
void ToolTip::insert(const QString &key, const QString &value)
|
|
|
|
{
|
2019-08-01 08:36:58 +02:00
|
|
|
_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
|
|
|
{
|
2019-03-13 20:48:25 +01: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>";
|
2019-03-13 20:48:25 +01:00
|
|
|
}
|
2016-08-02 20:46:22 +02:00
|
|
|
|
2019-03-13 20:48:25 +01:00
|
|
|
if (!_list.isEmpty()) {
|
|
|
|
html += "<table>";
|
|
|
|
for (int i = 0; i < _list.count(); i++)
|
|
|
|
html += "<tr><td align=\"right\"><b>" + _list.at(i).key()
|
|
|
|
+ ": </b></td><td>" + _list.at(i).value() + "</td></tr>";
|
|
|
|
html += "</table>";
|
|
|
|
}
|
2016-08-02 00:28:56 +02:00
|
|
|
|
2019-03-13 20:48:25 +01:00
|
|
|
return html;
|
2016-08-02 00:28:56 +02:00
|
|
|
}
|