From 325ba4860127b0c9b06f04855f938ce7c44e4959 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Sun, 24 Jan 2016 16:01:33 +0800 Subject: [PATCH] Add "Hide zero values" option. Closes #3543. --- src/base/preferences.cpp | 12 +++++++++++- src/base/preferences.h | 2 ++ src/gui/options.ui | 9 ++++++++- src/gui/options_imp.cpp | 3 +++ src/gui/transferlistdelegate.cpp | 26 +++++++++++++++++++++----- 5 files changed, 45 insertions(+), 7 deletions(-) diff --git a/src/base/preferences.cpp b/src/base/preferences.cpp index 2eb08eead..79e6125e4 100644 --- a/src/base/preferences.cpp +++ b/src/base/preferences.cpp @@ -273,6 +273,16 @@ void Preferences::setAlternatingRowColors(bool b) setValue("Preferences/General/AlternatingRowColors", b); } +bool Preferences::getHideZeroValues() const +{ + return value("Preferences/General/HideZeroValues", false).toBool(); +} + +void Preferences::setHideZeroValues(bool b) +{ + setValue("Preferences/General/HideZeroValues", b); +} + bool Preferences::useRandomPort() const { return value("Preferences/General/UseRandomPort", false).toBool(); @@ -1900,7 +1910,7 @@ bool Preferences::isTorrentFileAssocSet() CFStringRef myBundleId = CFBundleGetIdentifier(CFBundleGetMainBundle()); isSet = CFStringCompare(myBundleId, defaultHandlerId, 0) == kCFCompareEqualTo; CFRelease(defaultHandlerId); - } + } CFRelease(torrentId); } return isSet; diff --git a/src/base/preferences.h b/src/base/preferences.h index 84d1d67ef..acf0a254c 100644 --- a/src/base/preferences.h +++ b/src/base/preferences.h @@ -132,6 +132,8 @@ public: void showSpeedInTitleBar(bool show); bool useAlternatingRowColors() const; void setAlternatingRowColors(bool b); + bool getHideZeroValues() const; + void setHideZeroValues(bool b); bool useRandomPort() const; void setRandomPort(bool b); bool systrayIntegration() const; diff --git a/src/gui/options.ui b/src/gui/options.ui index b65051f72..7733b2fdb 100644 --- a/src/gui/options.ui +++ b/src/gui/options.ui @@ -163,7 +163,7 @@ 0 0 480 - 672 + 698 @@ -257,6 +257,13 @@ + + + + Hide zero and infinity values + + + diff --git a/src/gui/options_imp.cpp b/src/gui/options_imp.cpp index 515e4bf39..37de68ca0 100644 --- a/src/gui/options_imp.cpp +++ b/src/gui/options_imp.cpp @@ -141,6 +141,7 @@ options_imp::options_imp(QWidget *parent) connect(comboI18n, SIGNAL(currentIndexChanged(int)), this, SLOT(enableApplyButton())); connect(confirmDeletion, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton())); connect(checkAltRowColors, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton())); + connect(checkHideZero, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton())); connect(checkShowSystray, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton())); connect(checkCloseToSystray, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton())); connect(checkMinimizeToSysTray, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton())); @@ -392,6 +393,7 @@ void options_imp::saveOptions() pref->setLocale(locale); pref->setConfirmTorrentDeletion(confirmDeletion->isChecked()); pref->setAlternatingRowColors(checkAltRowColors->isChecked()); + pref->setHideZeroValues(checkHideZero->isChecked()); pref->setSystrayIntegration(systrayIntegration()); pref->setTrayIconStyle(TrayIcon::Style(comboTrayIcon->currentIndex())); pref->setCloseToTray(closeToTray()); @@ -573,6 +575,7 @@ void options_imp::loadOptions() setLocale(pref->getLocale()); confirmDeletion->setChecked(pref->confirmTorrentDeletion()); checkAltRowColors->setChecked(pref->useAlternatingRowColors()); + checkHideZero->setChecked(pref->getHideZeroValues()); checkShowSplash->setChecked(!pref->isSplashScreenDisabled()); checkStartMinimized->setChecked(pref->startMinimized()); diff --git a/src/gui/transferlistdelegate.cpp b/src/gui/transferlistdelegate.cpp index 6aeadda44..766ef0391 100644 --- a/src/gui/transferlistdelegate.cpp +++ b/src/gui/transferlistdelegate.cpp @@ -39,6 +39,8 @@ #include "torrentmodel.h" #include "base/bittorrent/session.h" #include "base/bittorrent/torrenthandle.h" +#include "base/types.h" +#include "base/preferences.h" #include "base/unicodestrings.h" #ifdef Q_OS_WIN @@ -54,6 +56,7 @@ TransferListDelegate::TransferListDelegate(QObject *parent) : QItemDelegate(pare TransferListDelegate::~TransferListDelegate() {} void TransferListDelegate::paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const { + const bool hideValues = Preferences::instance()->getHideZeroValues(); QStyleOptionViewItemV2 opt = QItemDelegate::setOptions(index, option); painter->save(); switch(index.column()) { @@ -66,10 +69,14 @@ void TransferListDelegate::paint(QPainter * painter, const QStyleOptionViewItem case TorrentModel::TR_SIZE: case TorrentModel::TR_TOTAL_SIZE: { QItemDelegate::drawBackground(painter, opt, index); + qlonglong size = index.data().toLongLong(); + if (hideValues && !size) + break; opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; - QItemDelegate::drawDisplay(painter, opt, option.rect, Utils::Misc::friendlyUnit(index.data().toLongLong())); + QItemDelegate::drawDisplay(painter, opt, option.rect, Utils::Misc::friendlyUnit(size)); break; } + case TorrentModel::TR_ETA: { QItemDelegate::drawBackground(painter, opt, index); opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; @@ -152,6 +159,8 @@ void TransferListDelegate::paint(QPainter * painter, const QStyleOptionViewItem case TorrentModel::TR_DLSPEED: { QItemDelegate::drawBackground(painter, opt, index); const qulonglong speed = index.data().toULongLong(); + if (hideValues && !speed) + break; opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; QItemDelegate::drawDisplay(painter, opt, opt.rect, Utils::Misc::friendlyUnit(speed, true)); break; @@ -160,6 +169,8 @@ void TransferListDelegate::paint(QPainter * painter, const QStyleOptionViewItem case TorrentModel::TR_DLLIMIT: { QItemDelegate::drawBackground(painter, opt, index); const qlonglong limit = index.data().toLongLong(); + if (hideValues && !limit) + break; opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; QItemDelegate::drawDisplay(painter, opt, opt.rect, limit > 0 ? Utils::Misc::friendlyUnit(limit, true) : QString::fromUtf8(C_INFINITY)); break; @@ -185,6 +196,8 @@ void TransferListDelegate::paint(QPainter * painter, const QStyleOptionViewItem QItemDelegate::drawBackground(painter, opt, index); opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; const qreal ratio = index.data().toDouble(); + if (hideValues && (ratio <= 0)) + break; QItemDelegate::drawDisplay(painter, opt, opt.rect, ((ratio == -1) || (ratio > BitTorrent::TorrentHandle::MAX_RATIO)) ? QString::fromUtf8(C_INFINITY) : Utils::String::fromDouble(ratio, 2)); break; @@ -224,17 +237,20 @@ void TransferListDelegate::paint(QPainter * painter, const QStyleOptionViewItem break; } case TorrentModel::TR_LAST_ACTIVITY: { - QString elapsedString; - long long elapsed = index.data().toLongLong(); QItemDelegate::drawBackground(painter, opt, index); - opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; + qlonglong elapsed = index.data().toLongLong(); + if (hideValues && ((elapsed < 0) || (elapsed >= MAX_ETA))) + break; + + QString elapsedString; if (elapsed == 0) // Show '< 1m ago' when elapsed time is 0 elapsed = 1; - if (elapsed < 0) + else if (elapsed < 0) elapsedString = Utils::Misc::userFriendlyDuration(elapsed); else elapsedString = tr("%1 ago", "e.g.: 1h 20m ago").arg(Utils::Misc::userFriendlyDuration(elapsed)); + opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; QItemDelegate::drawDisplay(painter, opt, option.rect, elapsedString); break; }