aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2018-10-05 12:25:43 +0200
committerAqua-sama <aqua@iserlohn-fortress.net>2018-10-05 12:25:43 +0200
commit883b2f4ba313cd65c6c543ffbcea0bb6b084a6ad (patch)
treeb2c780c3e56a01bb38d0d0d968f6d932e2663de3
parentclazy: fix warnings (diff)
downloadsmolbote-883b2f4ba313cd65c6c543ffbcea0bb6b084a6ad.tar.xz
downloads: only show preview on images
-rw-r--r--lib/downloads/widgets/downloaditemwidget.cpp46
1 files changed, 27 insertions, 19 deletions
diff --git a/lib/downloads/widgets/downloaditemwidget.cpp b/lib/downloads/widgets/downloaditemwidget.cpp
index e32db22..4096751 100644
--- a/lib/downloads/widgets/downloaditemwidget.cpp
+++ b/lib/downloads/widgets/downloaditemwidget.cpp
@@ -11,6 +11,7 @@
#include <QStyle>
#include <QUrl>
#include <QDesktopServices>
+#include <QBuffer>
inline QString sizeString(int size)
{
@@ -120,25 +121,32 @@ void DownloadItemWidget::updateProgress(qint64 value, qint64 total)
void DownloadItemWidget::updateFinished()
{
ui->progressBar->setValue(ui->progressBar->maximum());
- QString tooltip = "<table>"
- "<tr>"
- "<th>Preview</th>"
- "<th>Information</th>"
- "</tr>"
- "<tr>"
- "<td>%1</td>"
- "<td>"
- "<p><b>URL</b>: %2</p>"
- "<p><b>Path</b>: %3</p>"
- "<p><b>MIME Type</b>: %4</p>"
- "<p><b>Size</b>: %5</p>"
- "</td>"
- "</tr>"
- "</table>";
- if(item->mimeType().startsWith("image"))
- tooltip = tooltip.arg("<img src='file://" + item->path() + "' width='400' alt='not available'>");
- else
- tooltip = tooltip.arg("not available");
+ ui->pause_toolButton->hide();
+ ui->abort_toolButton->hide();
+ ui->open_toolButton->show();
+
+ // generate a useful tooltip
+ QString tooltip = "<p><b>URL</b>: %1</p>"
+ "<p><b>Path</b>: %2</p>"
+ "<p><b>MIME Type</b>: %3</p>"
+ "<p><b>Size</b>: %4</p>";
tooltip = tooltip.arg(item->url().toString(), item->path(), item->mimeType(), sizeString(item->totalBytes()));
+
+ if(item->mimeType().startsWith("image")) {
+ const QPixmap pixmap(item->path());
+ const QPixmap thumbnail = pixmap.scaledToWidth(qMax(400, pixmap.width()), Qt::SmoothTransformation);
+
+ QByteArray imageData;
+ QBuffer buffer(&imageData);
+ thumbnail.save(&buffer, "PNG");
+
+ tooltip = QString("<table>"
+ "<tr><th>Preview</th><th>Information</th></tr>"
+ "<tr><td>%1</td><td>%2</td></tr>"
+ "</table>").arg(QString("<img src='data:image/png;base64," + imageData.toBase64() + "' width='400' alt='preview'>"),
+ tooltip);
+
+ }
+
setToolTip(tooltip);
}