aboutsummaryrefslogtreecommitdiff
path: root/lib/downloads/widgets
diff options
context:
space:
mode:
Diffstat (limited to 'lib/downloads/widgets')
-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);
}