summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAl12rs <gabriel.cortesi@outlook.com>2018-05-20 23:53:57 +0200
committerAl12rs <gabriel.cortesi@outlook.com>2018-05-20 23:53:57 +0200
commit6d6444c126c59c4307873755b08fc5773b3d3955 (patch)
tree7da3a02da5b15d79118772fee2a901773f13c3a6 /src
parent4b66c6c1ef52a68cbca752be69fc57b47a25104c (diff)
Made downlods file sizes human readable instead of just being KB
Diffstat (limited to 'src')
-rw-r--r--src/downloadlistwidget.cpp21
-rw-r--r--src/downloadlistwidget.h2
-rw-r--r--src/downloadlistwidget.ui3
3 files changed, 25 insertions, 1 deletions
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<QString, int, int> 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;
diff --git a/src/downloadlistwidget.h b/src/downloadlistwidget.h
index c1dfe4cd..62f21837 100644
--- a/src/downloadlistwidget.h
+++ b/src/downloadlistwidget.h
@@ -74,11 +74,13 @@ signals:
protected:
+ QString sizeFormat(quint64 size) const;
bool editorEvent(QEvent *event, QAbstractItemModel *model,
const QStyleOptionViewItem &option, const QModelIndex &index);
private:
+
void drawCache(QPainter *painter, const QStyleOptionViewItem &option, const QPixmap &cache) const;
private slots:
diff --git a/src/downloadlistwidget.ui b/src/downloadlistwidget.ui
index 7a6ce8ba..9e238509 100644
--- a/src/downloadlistwidget.ui
+++ b/src/downloadlistwidget.ui
@@ -87,6 +87,9 @@
<property name="text">
<string notr="true">KB</string>
</property>
+ <property name="visible">
+ <bool>false</bool>
+ </property>
</widget>
</item>
</layout>