From 883b2f4ba313cd65c6c543ffbcea0bb6b084a6ad Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Fri, 5 Oct 2018 12:25:43 +0200 Subject: downloads: only show preview on images --- lib/downloads/widgets/downloaditemwidget.cpp | 46 ++++++++++++++++------------ 1 file 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 #include #include +#include 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 = "" - "" - "" - "" - "" - "" - "" - "" - "" - "
PreviewInformation
%1" - "

URL: %2

" - "

Path: %3

" - "

MIME Type: %4

" - "

Size: %5

" - "
"; - if(item->mimeType().startsWith("image")) - tooltip = tooltip.arg("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 = "

URL: %1

" + "

Path: %2

" + "

MIME Type: %3

" + "

Size: %4

"; 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("" + "" + "" + "
PreviewInformation
%1%2
").arg(QString("preview"), + tooltip); + + } + setToolTip(tooltip); } -- cgit v1.2.1