diff --git a/src/gui/properties/proplistdelegate.cpp b/src/gui/properties/proplistdelegate.cpp index d75fb97e0..b6dda5cab 100644 --- a/src/gui/properties/proplistdelegate.cpp +++ b/src/gui/properties/proplistdelegate.cpp @@ -67,6 +67,15 @@ void PropListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &opti QItemDelegate::drawBackground(painter, opt, index); QItemDelegate::drawDisplay(painter, opt, option.rect, Utils::Misc::friendlyUnit(index.data().toLongLong())); break; + case REMAINING: + QItemDelegate::drawBackground(painter, opt, index); + if (index.sibling(index.row(), PRIORITY).data().toInt() == prio::IGNORED) { + QItemDelegate::drawDisplay(painter, opt, option.rect, tr("N/A")); + } + else { + QItemDelegate::drawDisplay(painter, opt, option.rect, Utils::Misc::friendlyUnit(index.data().toLongLong())); + } + break; case PROGRESS: if (index.data().toDouble() >= 0) { QStyleOptionProgressBarV2 newopt; diff --git a/src/gui/properties/proplistdelegate.h b/src/gui/properties/proplistdelegate.h index 10cab6f71..7f1ecc251 100644 --- a/src/gui/properties/proplistdelegate.h +++ b/src/gui/properties/proplistdelegate.h @@ -45,7 +45,8 @@ enum PropColumn NAME, PCSIZE, PROGRESS, - PRIORITY + PRIORITY, + REMAINING }; class PropListDelegate : public QItemDelegate diff --git a/src/gui/torrentcontentmodel.cpp b/src/gui/torrentcontentmodel.cpp index 8faf800bd..6eb69f57a 100644 --- a/src/gui/torrentcontentmodel.cpp +++ b/src/gui/torrentcontentmodel.cpp @@ -56,7 +56,7 @@ namespace TorrentContentModel::TorrentContentModel(QObject *parent) : QAbstractItemModel(parent) - , m_rootItem(new TorrentContentModelFolder(QList({ tr("Name"), tr("Size"), tr("Progress"), tr("Download Priority") }))) + , m_rootItem(new TorrentContentModelFolder(QList({ tr("Name"), tr("Size"), tr("Progress"), tr("Download Priority"), tr("Remaining") }))) { } diff --git a/src/gui/torrentcontentmodelfile.cpp b/src/gui/torrentcontentmodelfile.cpp index 1d8d1dd0a..cabd8ed5c 100644 --- a/src/gui/torrentcontentmodelfile.cpp +++ b/src/gui/torrentcontentmodelfile.cpp @@ -69,5 +69,6 @@ void TorrentContentModelFile::setPriority(int new_prio, bool update_parent) void TorrentContentModelFile::setProgress(qreal progress) { m_progress = progress; + m_remaining = (qulonglong)(m_size * (1.0 - m_progress)); Q_ASSERT(m_progress <= 1.); } diff --git a/src/gui/torrentcontentmodelfolder.cpp b/src/gui/torrentcontentmodelfolder.cpp index 8dd6fa114..6695dbab9 100644 --- a/src/gui/torrentcontentmodelfolder.cpp +++ b/src/gui/torrentcontentmodelfolder.cpp @@ -138,17 +138,20 @@ void TorrentContentModelFolder::recalculateProgress() { qreal tProgress = 0; qulonglong tSize = 0; + qulonglong tRemaining = 0; foreach (TorrentContentModelItem* child, m_childItems) { if (child->priority() != prio::IGNORED) { if (child->itemType() == FolderType) static_cast(child)->recalculateProgress(); tProgress += child->progress() * child->size(); tSize += child->size(); + tRemaining += child->remaining(); } } if (!isRootItem() && tSize > 0) { m_progress = tProgress / tSize; + m_remaining = tRemaining; Q_ASSERT(m_progress <= 1.); } } diff --git a/src/gui/torrentcontentmodelitem.cpp b/src/gui/torrentcontentmodelitem.cpp index 65522b5d2..478feac89 100644 --- a/src/gui/torrentcontentmodelitem.cpp +++ b/src/gui/torrentcontentmodelitem.cpp @@ -37,6 +37,7 @@ TorrentContentModelItem::TorrentContentModelItem(TorrentContentModelFolder* parent) : m_parentItem(parent) , m_size(0) + , m_remaining(0) , m_priority(prio::NORMAL) , m_progress(0) { @@ -75,6 +76,14 @@ qreal TorrentContentModelItem::progress() const return 1; } +qulonglong TorrentContentModelItem::remaining() const +{ + Q_ASSERT(!isRootItem()); + if (m_priority == prio::IGNORED) return 0; + + return m_remaining; +} + int TorrentContentModelItem::priority() const { Q_ASSERT(!isRootItem()); @@ -100,6 +109,8 @@ QVariant TorrentContentModelItem::data(int column) const return progress(); case COL_SIZE: return m_size; + case COL_REMAINING: + return remaining(); default: Q_ASSERT(false); return QVariant(); diff --git a/src/gui/torrentcontentmodelitem.h b/src/gui/torrentcontentmodelitem.h index fd1979dde..a21398f80 100644 --- a/src/gui/torrentcontentmodelitem.h +++ b/src/gui/torrentcontentmodelitem.h @@ -42,7 +42,7 @@ class TorrentContentModelFolder; class TorrentContentModelItem { public: - enum TreeItemColumns {COL_NAME, COL_SIZE, COL_PROGRESS, COL_PRIO, NB_COL}; + enum TreeItemColumns {COL_NAME, COL_SIZE, COL_PROGRESS, COL_PRIO, COL_REMAINING, NB_COL}; enum ItemType { FileType, FolderType }; TorrentContentModelItem(TorrentContentModelFolder* parent); @@ -57,6 +57,7 @@ public: qulonglong size() const; qreal progress() const; + qulonglong remaining() const; int priority() const; virtual void setPriority(int new_prio, bool update_parent = true) = 0; @@ -72,6 +73,7 @@ protected: // Non-root item members QString m_name; qulonglong m_size; + qulonglong m_remaining; int m_priority; qreal m_progress; };