From 6d6444c126c59c4307873755b08fc5773b3d3955 Mon Sep 17 00:00:00 2001 From: Al12rs Date: Sun, 20 May 2018 23:53:57 +0200 Subject: Made downlods file sizes human readable instead of just being KB --- src/downloadlistwidget.cpp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'src/downloadlistwidget.cpp') diff --git a/src/downloadlistwidget.cpp b/src/downloadlistwidget.cpp index 2af74cc2..94394778 100644 --- a/src/downloadlistwidget.cpp +++ b/src/downloadlistwidget.cpp @@ -87,6 +87,25 @@ void DownloadListWidgetDelegate::drawCache(QPainter *painter, const QStyleOption } +QString DownloadListWidgetDelegate::sizeFormat(quint64 size) const +{ + qreal calc = size; + QStringList list; + list << "KB" << "MB" << "GB" << "TB"; + + QStringListIterator i(list); + QString unit("byte(s)"); + + while (calc >= 1024.0 && i.hasNext()) + { + unit = i.next(); + calc /= 1024.0; + } + + return QString().setNum(calc, 'f', 2) + " " + unit; +} + + void DownloadListWidgetDelegate::paintPendingDownload(int downloadIndex) const { std::tuple nexusids = m_Manager->getPendingDownload(downloadIndex); @@ -106,7 +125,7 @@ void DownloadListWidgetDelegate::paintRegularDownload(int downloadIndex) const name.append("..."); } m_NameLabel->setText(name); - m_SizeLabel->setText(QString::number(m_Manager->getFileSize(downloadIndex) / 1024)); + m_SizeLabel->setText(sizeFormat(m_Manager->getFileSize(downloadIndex) )); DownloadManager::DownloadState state = m_Manager->getState(downloadIndex); if ((state == DownloadManager::STATE_PAUSED) || (state == DownloadManager::STATE_ERROR)) { QPalette labelPalette; -- cgit v1.3.1