diff options
| author | Al12rs <gabriel.cortesi@outlook.com> | 2018-07-17 00:10:03 +0200 |
|---|---|---|
| committer | Al12rs <gabriel.cortesi@outlook.com> | 2018-07-17 00:10:03 +0200 |
| commit | 1867c20f02d44f98154955a89686fe9edf09d7f5 (patch) | |
| tree | 9dfbe151145b5713a29ab35f3b24585cae066a7f | |
| parent | 2524d65441e99cbb14037144b8af60e1d25e1179 (diff) | |
Added sortable "Size" column to the downlaods tab.
| -rw-r--r-- | src/downloadlist.cpp | 3 | ||||
| -rw-r--r-- | src/downloadlist.h | 3 | ||||
| -rw-r--r-- | src/downloadlistsortproxy.cpp | 2 | ||||
| -rw-r--r-- | src/downloadlistwidget.cpp | 4 | ||||
| -rw-r--r-- | src/downloadlistwidgetcompact.cpp | 25 |
5 files changed, 29 insertions, 8 deletions
diff --git a/src/downloadlist.cpp b/src/downloadlist.cpp index f13cdef1..1e31973d 100644 --- a/src/downloadlist.cpp +++ b/src/downloadlist.cpp @@ -40,7 +40,7 @@ int DownloadList::rowCount(const QModelIndex&) const int DownloadList::columnCount(const QModelIndex&) const
{
- return 3;
+ return 4;
}
@@ -63,6 +63,7 @@ QVariant DownloadList::headerData(int section, Qt::Orientation orientation, int switch (section) {
case COL_NAME: return tr("Name");
case COL_FILETIME: return tr("Filetime");
+ case COL_SIZE: return tr("Size");
default: return tr("Done");
}
} else {
diff --git a/src/downloadlist.h b/src/downloadlist.h index 2316dddc..e8833f0f 100644 --- a/src/downloadlist.h +++ b/src/downloadlist.h @@ -39,7 +39,8 @@ public: enum EColumn {
COL_NAME = 0,
COL_FILETIME,
- COL_STATUS
+ COL_STATUS,
+ COL_SIZE
};
public:
diff --git a/src/downloadlistsortproxy.cpp b/src/downloadlistsortproxy.cpp index 2780f973..f791617a 100644 --- a/src/downloadlistsortproxy.cpp +++ b/src/downloadlistsortproxy.cpp @@ -47,6 +47,8 @@ bool DownloadListSortProxy::lessThan(const QModelIndex &left, return m_Manager->getFileTime(leftIndex) < m_Manager->getFileTime(rightIndex);
} else if (left.column() == DownloadList::COL_STATUS) {
return m_Manager->getState(leftIndex) < m_Manager->getState(rightIndex);
+ } else if(left.column() == DownloadList::COL_SIZE){
+ return m_Manager->getFileSize(leftIndex) < m_Manager->getFileSize(rightIndex);
} else {
return leftIndex < rightIndex;
}
diff --git a/src/downloadlistwidget.cpp b/src/downloadlistwidget.cpp index 0ef408fb..1a401d10 100644 --- a/src/downloadlistwidget.cpp +++ b/src/downloadlistwidget.cpp @@ -82,7 +82,7 @@ void DownloadListWidgetDelegate::drawCache(QPainter *painter, const QStyleOption {
QRect rect = option.rect;
rect.setLeft(0);
- rect.setWidth(m_View->columnWidth(0) + m_View->columnWidth(1) + m_View->columnWidth(2));
+ rect.setWidth(m_View->columnWidth(0) + m_View->columnWidth(1) + m_View->columnWidth(2) + m_View->columnWidth(3));
painter->drawPixmap(rect, cache);
}
@@ -193,7 +193,7 @@ void DownloadListWidgetDelegate::paint(QPainter *painter, const QStyleOptionView return;
}
- m_ItemWidget->resize(QSize(m_View->columnWidth(0) + m_View->columnWidth(1) + m_View->columnWidth(2), option.rect.height()));
+ m_ItemWidget->resize(QSize(m_View->columnWidth(0) + m_View->columnWidth(1) + m_View->columnWidth(2) + m_View->columnWidth(3), option.rect.height()));
int downloadIndex = index.data().toInt();
diff --git a/src/downloadlistwidgetcompact.cpp b/src/downloadlistwidgetcompact.cpp index 1d1805ef..ad9e0994 100644 --- a/src/downloadlistwidgetcompact.cpp +++ b/src/downloadlistwidgetcompact.cpp @@ -81,10 +81,27 @@ void DownloadListWidgetCompactDelegate::drawCache(QPainter *painter, const QStyl {
QRect rect = option.rect;
rect.setLeft(0);
- rect.setWidth(m_View->columnWidth(0) + m_View->columnWidth(1) + m_View->columnWidth(2));
+ rect.setWidth(m_View->columnWidth(0) + m_View->columnWidth(1) + m_View->columnWidth(2) + m_View->columnWidth(3));
painter->drawPixmap(rect, cache);
}
+QString DownloadListWidgetCompactDelegate::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 DownloadListWidgetCompactDelegate::paintPendingDownload(int downloadIndex) const
{
@@ -110,8 +127,8 @@ void DownloadListWidgetCompactDelegate::paintRegularDownload(int downloadIndex) DownloadManager::DownloadState state = m_Manager->getState(downloadIndex);
- if ((m_SizeLabel != nullptr) && (state >= DownloadManager::STATE_READY)) {
- m_SizeLabel->setText(QString::number(m_Manager->getFileSize(downloadIndex) / 1048576));
+ if ((m_SizeLabel != nullptr)) {
+ m_SizeLabel->setText(sizeFormat(m_Manager->getFileSize(downloadIndex)));
}
if ((state == DownloadManager::STATE_PAUSED) || (state == DownloadManager::STATE_ERROR) || (state == DownloadManager::STATE_PAUSING)) {
@@ -153,7 +170,7 @@ void DownloadListWidgetCompactDelegate::paint(QPainter *painter, const QStyleOpt return;
}
- m_ItemWidget->resize(QSize(m_View->columnWidth(0) + m_View->columnWidth(1) + m_View->columnWidth(2), option.rect.height()));
+ m_ItemWidget->resize(QSize(m_View->columnWidth(0) + m_View->columnWidth(1) + m_View->columnWidth(2) + m_View->columnWidth(3), option.rect.height()));
if (index.row() % 2 == 1) {
m_ItemWidget->setBackgroundRole(QPalette::AlternateBase);
} else {
|
