From 325ba4860127b0c9b06f04855f938ce7c44e4959 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Sun, 24 Jan 2016 16:01:33 +0800 Subject: [PATCH 1/6] 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; } From a56b745429a861280637d3eb2d31cce163cbd99a Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Sun, 24 Jan 2016 17:15:39 +0800 Subject: [PATCH 2/6] Follow project coding style. Issue #2192. --- src/gui/transferlistdelegate.cpp | 397 ++++++++++++++++--------------- src/gui/transferlistdelegate.h | 26 +- 2 files changed, 215 insertions(+), 208 deletions(-) diff --git a/src/gui/transferlistdelegate.cpp b/src/gui/transferlistdelegate.cpp index 766ef0391..058ed466a 100644 --- a/src/gui/transferlistdelegate.cpp +++ b/src/gui/transferlistdelegate.cpp @@ -51,232 +51,239 @@ #endif #endif -TransferListDelegate::TransferListDelegate(QObject *parent) : QItemDelegate(parent) {} +TransferListDelegate::TransferListDelegate(QObject *parent) + : QItemDelegate(parent) +{ +} -TransferListDelegate::~TransferListDelegate() {} +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()) { - case TorrentModel::TR_AMOUNT_DOWNLOADED: - case TorrentModel::TR_AMOUNT_UPLOADED: - case TorrentModel::TR_AMOUNT_DOWNLOADED_SESSION: - case TorrentModel::TR_AMOUNT_UPLOADED_SESSION: - case TorrentModel::TR_AMOUNT_LEFT: - case TorrentModel::TR_COMPLETED: - case TorrentModel::TR_SIZE: - case TorrentModel::TR_TOTAL_SIZE: { - QItemDelegate::drawBackground(painter, opt, index); - qlonglong size = index.data().toLongLong(); - if (hideValues && !size) +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()) { + case TorrentModel::TR_AMOUNT_DOWNLOADED: + case TorrentModel::TR_AMOUNT_UPLOADED: + case TorrentModel::TR_AMOUNT_DOWNLOADED_SESSION: + case TorrentModel::TR_AMOUNT_UPLOADED_SESSION: + case TorrentModel::TR_AMOUNT_LEFT: + case TorrentModel::TR_COMPLETED: + 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(size)); break; - opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; - 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; - QItemDelegate::drawDisplay(painter, opt, option.rect, Utils::Misc::userFriendlyDuration(index.data().toLongLong())); - break; } - case TorrentModel::TR_SEEDS: - case TorrentModel::TR_PEERS: { - QString display = QString::number(index.data().toLongLong()); - qlonglong total = index.data(Qt::UserRole).toLongLong(); - if (total > 0) { - // Scrape was successful, we have total values - display += " ("+QString::number(total)+")"; - } - QItemDelegate::drawBackground(painter, opt, index); - opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; - QItemDelegate::drawDisplay(painter, opt, opt.rect, display); - break; - } - case TorrentModel::TR_STATUS: { - const int state = index.data().toInt(); - QString display; - switch(state) { - case BitTorrent::TorrentState::Downloading: - display = tr("Downloading"); - break; - case BitTorrent::TorrentState::StalledDownloading: - display = tr("Stalled", "Torrent is waiting for download to begin"); - break; - case BitTorrent::TorrentState::DownloadingMetadata: - display = tr("Downloading metadata", "used when loading a magnet link"); - break; - case BitTorrent::TorrentState::ForcedDownloading: - display = tr("[F] Downloading", "used when the torrent is forced started. You probably shouldn't translate the F."); - break; - case BitTorrent::TorrentState::Allocating: - display = tr("Allocating", "qBittorrent is allocating the files on disk"); - break; - case BitTorrent::TorrentState::Uploading: - case BitTorrent::TorrentState::StalledUploading: - display = tr("Seeding", "Torrent is complete and in upload-only mode"); - break; - case BitTorrent::TorrentState::ForcedUploading: - display = tr("[F] Seeding", "used when the torrent is forced started. You probably shouldn't translate the F."); - break; - case BitTorrent::TorrentState::QueuedDownloading: - case BitTorrent::TorrentState::QueuedUploading: - display = tr("Queued", "i.e. torrent is queued"); - break; - case BitTorrent::TorrentState::CheckingDownloading: - case BitTorrent::TorrentState::CheckingUploading: - display = tr("Checking", "Torrent local data is being checked"); - break; - case BitTorrent::TorrentState::QueuedForChecking: - display = tr("Queued for checking", "i.e. torrent is queued for hash checking"); - break; - case BitTorrent::TorrentState::CheckingResumeData: - display = tr("Checking resume data", "used when loading the torrents from disk after qbt is launched. It checks the correctness of the .fastresume file. Normally it is completed in a fraction of a second, unless loading many many torrents."); + case TorrentModel::TR_ETA: { + QItemDelegate::drawBackground(painter, opt, index); + opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; + QItemDelegate::drawDisplay(painter, opt, option.rect, Utils::Misc::userFriendlyDuration(index.data().toLongLong())); break; - case BitTorrent::TorrentState::PausedDownloading: - display = tr("Paused"); + } + case TorrentModel::TR_SEEDS: + case TorrentModel::TR_PEERS: { + QString display = QString::number(index.data().toLongLong()); + qlonglong total = index.data(Qt::UserRole).toLongLong(); + if (total > 0) + // Scrape was successful, we have total values + display += " (" + QString::number(total) + ")"; + QItemDelegate::drawBackground(painter, opt, index); + opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; + QItemDelegate::drawDisplay(painter, opt, opt.rect, display); break; - case BitTorrent::TorrentState::PausedUploading: - display = tr("Completed"); + } + case TorrentModel::TR_STATUS: { + const int state = index.data().toInt(); + QString display; + switch (state) { + case BitTorrent::TorrentState::Downloading: + display = tr("Downloading"); + break; + case BitTorrent::TorrentState::StalledDownloading: + display = tr("Stalled", "Torrent is waiting for download to begin"); + break; + case BitTorrent::TorrentState::DownloadingMetadata: + display = tr("Downloading metadata", "used when loading a magnet link"); + break; + case BitTorrent::TorrentState::ForcedDownloading: + display = tr("[F] Downloading", "used when the torrent is forced started. You probably shouldn't translate the F."); + break; + case BitTorrent::TorrentState::Allocating: + display = tr("Allocating", "qBittorrent is allocating the files on disk"); + break; + case BitTorrent::TorrentState::Uploading: + case BitTorrent::TorrentState::StalledUploading: + display = tr("Seeding", "Torrent is complete and in upload-only mode"); + break; + case BitTorrent::TorrentState::ForcedUploading: + display = tr("[F] Seeding", "used when the torrent is forced started. You probably shouldn't translate the F."); + break; + case BitTorrent::TorrentState::QueuedDownloading: + case BitTorrent::TorrentState::QueuedUploading: + display = tr("Queued", "i.e. torrent is queued"); + break; + case BitTorrent::TorrentState::CheckingDownloading: + case BitTorrent::TorrentState::CheckingUploading: + display = tr("Checking", "Torrent local data is being checked"); + break; + case BitTorrent::TorrentState::QueuedForChecking: + display = tr("Queued for checking", "i.e. torrent is queued for hash checking"); + break; + case BitTorrent::TorrentState::CheckingResumeData: + display = tr("Checking resume data", "used when loading the torrents from disk after qbt is launched. It checks the correctness of the .fastresume file. Normally it is completed in a fraction of a second, unless loading many many torrents."); + break; + case BitTorrent::TorrentState::PausedDownloading: + display = tr("Paused"); + break; + case BitTorrent::TorrentState::PausedUploading: + display = tr("Completed"); + break; + case BitTorrent::TorrentState::MissingFiles: + display = tr("Missing Files"); + break; + case BitTorrent::TorrentState::Error: + display = tr("Errored", "torrent status, the torrent has an error"); + break; + default: + display = ""; + } + QItemDelegate::drawBackground(painter, opt, index); + QItemDelegate::drawDisplay(painter, opt, opt.rect, display); break; - case BitTorrent::TorrentState::MissingFiles: - display = tr("Missing Files"); - break; - case BitTorrent::TorrentState::Error: - display = tr("Errored", "torrent status, the torrent has an error"); + } + case TorrentModel::TR_UPSPEED: + 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; - default: - display = ""; - } - QItemDelegate::drawBackground(painter, opt, index); - QItemDelegate::drawDisplay(painter, opt, opt.rect, display); - break; } - case TorrentModel::TR_UPSPEED: - case TorrentModel::TR_DLSPEED: { - QItemDelegate::drawBackground(painter, opt, index); - const qulonglong speed = index.data().toULongLong(); - if (hideValues && !speed) + case TorrentModel::TR_UPLIMIT: + 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; - opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; - QItemDelegate::drawDisplay(painter, opt, opt.rect, Utils::Misc::friendlyUnit(speed, true)); - break; } - case TorrentModel::TR_UPLIMIT: - 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; - } - case TorrentModel::TR_TIME_ELAPSED: { - QItemDelegate::drawBackground(painter, opt, index); - qlonglong seeding_time = index.data(Qt::UserRole).toLongLong(); - QString txt; - if (seeding_time > 0) - txt += tr("%1 (seeded for %2)", "e.g. 4m39s (seeded for 3m10s)") - .arg(Utils::Misc::userFriendlyDuration(index.data().toLongLong())) - .arg(Utils::Misc::userFriendlyDuration(seeding_time)); - QItemDelegate::drawDisplay(painter, opt, opt.rect, txt); - break; - } - case TorrentModel::TR_ADD_DATE: - case TorrentModel::TR_SEED_DATE: - QItemDelegate::drawBackground(painter, opt, index); - QItemDelegate::drawDisplay(painter, opt, opt.rect, index.data().toDateTime().toLocalTime().toString(Qt::DefaultLocaleShortDate)); - break; - case TorrentModel::TR_RATIO_LIMIT: - case TorrentModel::TR_RATIO: { - QItemDelegate::drawBackground(painter, opt, index); - opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; - const qreal ratio = index.data().toDouble(); - if (hideValues && (ratio <= 0)) + case TorrentModel::TR_TIME_ELAPSED: { + QItemDelegate::drawBackground(painter, opt, index); + qlonglong seeding_time = index.data(Qt::UserRole).toLongLong(); + QString txt; + if (seeding_time > 0) + txt += tr("%1 (seeded for %2)", "e.g. 4m39s (seeded for 3m10s)") + .arg(Utils::Misc::userFriendlyDuration(index.data().toLongLong())) + .arg(Utils::Misc::userFriendlyDuration(seeding_time)); + QItemDelegate::drawDisplay(painter, opt, opt.rect, txt); break; - QItemDelegate::drawDisplay(painter, opt, opt.rect, - ((ratio == -1) || (ratio > BitTorrent::TorrentHandle::MAX_RATIO)) ? QString::fromUtf8(C_INFINITY) : Utils::String::fromDouble(ratio, 2)); - break; } - case TorrentModel::TR_PRIORITY: { - const int priority = index.data().toInt(); - opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; - if (priority > 0) - QItemDelegate::paint(painter, opt, index); - else { + case TorrentModel::TR_ADD_DATE: + case TorrentModel::TR_SEED_DATE: + QItemDelegate::drawBackground(painter, opt, index); + QItemDelegate::drawDisplay(painter, opt, opt.rect, index.data().toDateTime().toLocalTime().toString(Qt::DefaultLocaleShortDate)); + break; + case TorrentModel::TR_RATIO_LIMIT: + case TorrentModel::TR_RATIO: { QItemDelegate::drawBackground(painter, opt, index); - QItemDelegate::drawDisplay(painter, opt, opt.rect, "*"); - } - break; + 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; + } + case TorrentModel::TR_PRIORITY: { + const int priority = index.data().toInt(); + opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; + if (priority > 0) { + QItemDelegate::paint(painter, opt, index); + } + else { + QItemDelegate::drawBackground(painter, opt, index); + QItemDelegate::drawDisplay(painter, opt, opt.rect, "*"); + } + break; } - case TorrentModel::TR_PROGRESS: { - QStyleOptionProgressBarV2 newopt; - qreal progress = index.data().toDouble()*100.; - newopt.rect = opt.rect; - newopt.text = ((progress == 100.0) ? QString("100%") : Utils::String::fromDouble(progress, 1) + "%"); - newopt.progress = (int)progress; - newopt.maximum = 100; - newopt.minimum = 0; - newopt.state |= QStyle::State_Enabled; - newopt.textVisible = true; + case TorrentModel::TR_PROGRESS: { + QStyleOptionProgressBarV2 newopt; + qreal progress = index.data().toDouble() * 100.; + newopt.rect = opt.rect; + newopt.text = ((progress == 100.0) ? QString("100%") : Utils::String::fromDouble(progress, 1) + "%"); + newopt.progress = (int)progress; + newopt.maximum = 100; + newopt.minimum = 0; + newopt.state |= QStyle::State_Enabled; + newopt.textVisible = true; #ifndef Q_OS_WIN - QApplication::style()->drawControl(QStyle::CE_ProgressBar, &newopt, painter); + QApplication::style()->drawControl(QStyle::CE_ProgressBar, &newopt, painter); #else - // XXX: To avoid having the progress text on the right of the bar + // XXX: To avoid having the progress text on the right of the bar #ifndef QBT_USES_QT5 QPlastiqueStyle st; #else QProxyStyle st("fusion"); #endif - st.drawControl(QStyle::CE_ProgressBar, &newopt, painter, 0); + st.drawControl(QStyle::CE_ProgressBar, &newopt, painter, 0); #endif - break; - } - case TorrentModel::TR_LAST_ACTIVITY: { - QItemDelegate::drawBackground(painter, opt, index); - qlonglong elapsed = index.data().toLongLong(); - if (hideValues && ((elapsed < 0) || (elapsed >= MAX_ETA))) break; + } + case TorrentModel::TR_LAST_ACTIVITY: { + QItemDelegate::drawBackground(painter, opt, index); + 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; - 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; + QString elapsedString; + if (elapsed == 0) + // Show '< 1m ago' when elapsed time is 0 + elapsed = 1; + 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; } - default: - QItemDelegate::paint(painter, option, index); - } - painter->restore(); + default: + QItemDelegate::paint(painter, option, index); + } + painter->restore(); } -QWidget* TransferListDelegate::createEditor(QWidget*, const QStyleOptionViewItem &, const QModelIndex &) const { - // No editor here - return 0; +QWidget* TransferListDelegate::createEditor(QWidget*, const QStyleOptionViewItem &, const QModelIndex &) const +{ + // No editor here + return 0; } -QSize TransferListDelegate::sizeHint(const QStyleOptionViewItem & option, const QModelIndex & index) const { - QSize size = QItemDelegate::sizeHint(option, index); +QSize TransferListDelegate::sizeHint(const QStyleOptionViewItem & option, const QModelIndex & index) const +{ + QSize size = QItemDelegate::sizeHint(option, index); - static int icon_height = -1; - if (icon_height == -1) { - QIcon icon(":/icons/skin/downloading.png"); - QList ic_sizes(icon.availableSizes()); - icon_height = ic_sizes[0].height(); - } + static int iconHeight = -1; + if (iconHeight == -1) { + QIcon icon(":/icons/skin/downloading.png"); + QList icSizes(icon.availableSizes()); + iconHeight = icSizes[0].height(); + } - if (size.height() < icon_height) - size.setHeight(icon_height); + if (size.height() < iconHeight) + size.setHeight(iconHeight); - return size; + return size; } diff --git a/src/gui/transferlistdelegate.h b/src/gui/transferlistdelegate.h index ce8593241..7e9856c4c 100644 --- a/src/gui/transferlistdelegate.h +++ b/src/gui/transferlistdelegate.h @@ -41,21 +41,21 @@ QT_END_NAMESPACE // Defines for download list list columns -class TransferListDelegate: public QItemDelegate { - Q_OBJECT +class TransferListDelegate: public QItemDelegate +{ + Q_OBJECT public: - TransferListDelegate(QObject *parent); - ~TransferListDelegate(); - void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const; - QWidget* createEditor(QWidget*, const QStyleOptionViewItem &, const QModelIndex &) const; - - // Reimplementing sizeHint() because the 'name' column contains text+icon. - // When that WHOLE column goes out of view(eg user scrolls horizontally) - // the rows shrink if the text's height is smaller than the icon's height. - // This happens because icon from the 'name' column is no longer drawn. - QSize sizeHint(const QStyleOptionViewItem & option, const QModelIndex & index) const; - + TransferListDelegate(QObject *parent); + ~TransferListDelegate(); + void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const; + QWidget* createEditor(QWidget*, const QStyleOptionViewItem &, const QModelIndex &) const; + + // Reimplementing sizeHint() because the 'name' column contains text+icon. + // When that WHOLE column goes out of view(eg user scrolls horizontally) + // the rows shrink if the text's height is smaller than the icon's height. + // This happens because icon from the 'name' column is no longer drawn. + QSize sizeHint(const QStyleOptionViewItem & option, const QModelIndex & index) const; }; #endif // TRANSFERLISTDELEGATE_H From 5c4470ec074d0a8661a2ede307236c122ca65928 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Mon, 25 Jan 2016 13:54:13 +0800 Subject: [PATCH 3/6] Remove unused destructor move get state text to its own function --- src/gui/transferlistdelegate.cpp | 118 ++++++++++++++++--------------- src/gui/transferlistdelegate.h | 4 +- 2 files changed, 64 insertions(+), 58 deletions(-) diff --git a/src/gui/transferlistdelegate.cpp b/src/gui/transferlistdelegate.cpp index 058ed466a..389d1f5e3 100644 --- a/src/gui/transferlistdelegate.cpp +++ b/src/gui/transferlistdelegate.cpp @@ -56,10 +56,6 @@ TransferListDelegate::TransferListDelegate(QObject *parent) { } -TransferListDelegate::~TransferListDelegate() -{ -} - void TransferListDelegate::paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const { const bool hideValues = Preferences::instance()->getHideZeroValues(); @@ -102,59 +98,7 @@ void TransferListDelegate::paint(QPainter * painter, const QStyleOptionViewItem } case TorrentModel::TR_STATUS: { const int state = index.data().toInt(); - QString display; - switch (state) { - case BitTorrent::TorrentState::Downloading: - display = tr("Downloading"); - break; - case BitTorrent::TorrentState::StalledDownloading: - display = tr("Stalled", "Torrent is waiting for download to begin"); - break; - case BitTorrent::TorrentState::DownloadingMetadata: - display = tr("Downloading metadata", "used when loading a magnet link"); - break; - case BitTorrent::TorrentState::ForcedDownloading: - display = tr("[F] Downloading", "used when the torrent is forced started. You probably shouldn't translate the F."); - break; - case BitTorrent::TorrentState::Allocating: - display = tr("Allocating", "qBittorrent is allocating the files on disk"); - break; - case BitTorrent::TorrentState::Uploading: - case BitTorrent::TorrentState::StalledUploading: - display = tr("Seeding", "Torrent is complete and in upload-only mode"); - break; - case BitTorrent::TorrentState::ForcedUploading: - display = tr("[F] Seeding", "used when the torrent is forced started. You probably shouldn't translate the F."); - break; - case BitTorrent::TorrentState::QueuedDownloading: - case BitTorrent::TorrentState::QueuedUploading: - display = tr("Queued", "i.e. torrent is queued"); - break; - case BitTorrent::TorrentState::CheckingDownloading: - case BitTorrent::TorrentState::CheckingUploading: - display = tr("Checking", "Torrent local data is being checked"); - break; - case BitTorrent::TorrentState::QueuedForChecking: - display = tr("Queued for checking", "i.e. torrent is queued for hash checking"); - break; - case BitTorrent::TorrentState::CheckingResumeData: - display = tr("Checking resume data", "used when loading the torrents from disk after qbt is launched. It checks the correctness of the .fastresume file. Normally it is completed in a fraction of a second, unless loading many many torrents."); - break; - case BitTorrent::TorrentState::PausedDownloading: - display = tr("Paused"); - break; - case BitTorrent::TorrentState::PausedUploading: - display = tr("Completed"); - break; - case BitTorrent::TorrentState::MissingFiles: - display = tr("Missing Files"); - break; - case BitTorrent::TorrentState::Error: - display = tr("Errored", "torrent status, the torrent has an error"); - break; - default: - display = ""; - } + QString display = getStatusString(state); QItemDelegate::drawBackground(painter, opt, index); QItemDelegate::drawDisplay(painter, opt, opt.rect, display); break; @@ -287,3 +231,63 @@ QSize TransferListDelegate::sizeHint(const QStyleOptionViewItem & option, const return size; } + +QString TransferListDelegate::getStatusString(const int state) const +{ + QString str; + + switch (state) { + case BitTorrent::TorrentState::Downloading: + str = tr("Downloading"); + break; + case BitTorrent::TorrentState::StalledDownloading: + str = tr("Stalled", "Torrent is waiting for download to begin"); + break; + case BitTorrent::TorrentState::DownloadingMetadata: + str = tr("Downloading metadata", "used when loading a magnet link"); + break; + case BitTorrent::TorrentState::ForcedDownloading: + str = tr("[F] Downloading", "used when the torrent is forced started. You probably shouldn't translate the F."); + break; + case BitTorrent::TorrentState::Allocating: + str = tr("Allocating", "qBittorrent is allocating the files on disk"); + break; + case BitTorrent::TorrentState::Uploading: + case BitTorrent::TorrentState::StalledUploading: + str = tr("Seeding", "Torrent is complete and in upload-only mode"); + break; + case BitTorrent::TorrentState::ForcedUploading: + str = tr("[F] Seeding", "used when the torrent is forced started. You probably shouldn't translate the F."); + break; + case BitTorrent::TorrentState::QueuedDownloading: + case BitTorrent::TorrentState::QueuedUploading: + str = tr("Queued", "i.e. torrent is queued"); + break; + case BitTorrent::TorrentState::CheckingDownloading: + case BitTorrent::TorrentState::CheckingUploading: + str = tr("Checking", "Torrent local data is being checked"); + break; + case BitTorrent::TorrentState::QueuedForChecking: + str = tr("Queued for checking", "i.e. torrent is queued for hash checking"); + break; + case BitTorrent::TorrentState::CheckingResumeData: + str = tr("Checking resume data", "used when loading the torrents from disk after qbt is launched. It checks the correctness of the .fastresume file. Normally it is completed in a fraction of a second, unless loading many many torrents."); + break; + case BitTorrent::TorrentState::PausedDownloading: + str = tr("Paused"); + break; + case BitTorrent::TorrentState::PausedUploading: + str = tr("Completed"); + break; + case BitTorrent::TorrentState::MissingFiles: + str = tr("Missing Files"); + break; + case BitTorrent::TorrentState::Error: + str = tr("Errored", "torrent status, the torrent has an error"); + break; + default: + str = ""; + } + + return str; +} diff --git a/src/gui/transferlistdelegate.h b/src/gui/transferlistdelegate.h index 7e9856c4c..3b1b55758 100644 --- a/src/gui/transferlistdelegate.h +++ b/src/gui/transferlistdelegate.h @@ -47,7 +47,6 @@ class TransferListDelegate: public QItemDelegate public: TransferListDelegate(QObject *parent); - ~TransferListDelegate(); void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const; QWidget* createEditor(QWidget*, const QStyleOptionViewItem &, const QModelIndex &) const; @@ -56,6 +55,9 @@ public: // the rows shrink if the text's height is smaller than the icon's height. // This happens because icon from the 'name' column is no longer drawn. QSize sizeHint(const QStyleOptionViewItem & option, const QModelIndex & index) const; + +private: + QString getStatusString(const int state) const; }; #endif // TRANSFERLISTDELEGATE_H From b0a5c973a5b1232fe89d4b6e3e0c9b1bb3cb2bf5 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Mon, 25 Jan 2016 14:09:17 +0800 Subject: [PATCH 4/6] Simplify common paint actions --- src/gui/transferlistdelegate.cpp | 37 ++++++++++++-------------------- 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/src/gui/transferlistdelegate.cpp b/src/gui/transferlistdelegate.cpp index 389d1f5e3..c2c1a6aa5 100644 --- a/src/gui/transferlistdelegate.cpp +++ b/src/gui/transferlistdelegate.cpp @@ -58,9 +58,11 @@ TransferListDelegate::TransferListDelegate(QObject *parent) void TransferListDelegate::paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const { + painter->save(); const bool hideValues = Preferences::instance()->getHideZeroValues(); + QStyleOptionViewItemV2 opt = QItemDelegate::setOptions(index, option); - painter->save(); + QItemDelegate::drawBackground(painter, opt, index); switch (index.column()) { case TorrentModel::TR_AMOUNT_DOWNLOADED: case TorrentModel::TR_AMOUNT_UPLOADED: @@ -70,7 +72,6 @@ void TransferListDelegate::paint(QPainter * painter, const QStyleOptionViewItem case TorrentModel::TR_COMPLETED: case TorrentModel::TR_SIZE: case TorrentModel::TR_TOTAL_SIZE: { - QItemDelegate::drawBackground(painter, opt, index); qlonglong size = index.data().toLongLong(); if (hideValues && !size) break; @@ -79,19 +80,17 @@ void TransferListDelegate::paint(QPainter * painter, const QStyleOptionViewItem break; } case TorrentModel::TR_ETA: { - QItemDelegate::drawBackground(painter, opt, index); opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; QItemDelegate::drawDisplay(painter, opt, option.rect, Utils::Misc::userFriendlyDuration(index.data().toLongLong())); break; } case TorrentModel::TR_SEEDS: case TorrentModel::TR_PEERS: { - QString display = QString::number(index.data().toLongLong()); + QString display = index.data().toString(); qlonglong total = index.data(Qt::UserRole).toLongLong(); + // Scrape was successful, we have total values if (total > 0) - // Scrape was successful, we have total values display += " (" + QString::number(total) + ")"; - QItemDelegate::drawBackground(painter, opt, index); opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; QItemDelegate::drawDisplay(painter, opt, opt.rect, display); break; @@ -99,13 +98,11 @@ void TransferListDelegate::paint(QPainter * painter, const QStyleOptionViewItem case TorrentModel::TR_STATUS: { const int state = index.data().toInt(); QString display = getStatusString(state); - QItemDelegate::drawBackground(painter, opt, index); QItemDelegate::drawDisplay(painter, opt, opt.rect, display); break; } case TorrentModel::TR_UPSPEED: case TorrentModel::TR_DLSPEED: { - QItemDelegate::drawBackground(painter, opt, index); const qulonglong speed = index.data().toULongLong(); if (hideValues && !speed) break; @@ -115,7 +112,6 @@ void TransferListDelegate::paint(QPainter * painter, const QStyleOptionViewItem } case TorrentModel::TR_UPLIMIT: case TorrentModel::TR_DLLIMIT: { - QItemDelegate::drawBackground(painter, opt, index); const qlonglong limit = index.data().toLongLong(); if (hideValues && !limit) break; @@ -124,30 +120,28 @@ void TransferListDelegate::paint(QPainter * painter, const QStyleOptionViewItem break; } case TorrentModel::TR_TIME_ELAPSED: { - QItemDelegate::drawBackground(painter, opt, index); - qlonglong seeding_time = index.data(Qt::UserRole).toLongLong(); + qlonglong elapsedTime = index.data().toLongLong(); + qlonglong seedingTime = index.data(Qt::UserRole).toLongLong(); QString txt; - if (seeding_time > 0) + if (seedingTime > 0) txt += tr("%1 (seeded for %2)", "e.g. 4m39s (seeded for 3m10s)") - .arg(Utils::Misc::userFriendlyDuration(index.data().toLongLong())) - .arg(Utils::Misc::userFriendlyDuration(seeding_time)); + .arg(Utils::Misc::userFriendlyDuration(elapsedTime)) + .arg(Utils::Misc::userFriendlyDuration(seedingTime)); QItemDelegate::drawDisplay(painter, opt, opt.rect, txt); break; } case TorrentModel::TR_ADD_DATE: case TorrentModel::TR_SEED_DATE: - QItemDelegate::drawBackground(painter, opt, index); QItemDelegate::drawDisplay(painter, opt, opt.rect, index.data().toDateTime().toLocalTime().toString(Qt::DefaultLocaleShortDate)); break; case TorrentModel::TR_RATIO_LIMIT: case TorrentModel::TR_RATIO: { - 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)); + QString str = ((ratio == -1) || (ratio > BitTorrent::TorrentHandle::MAX_RATIO)) ? QString::fromUtf8(C_INFINITY) : Utils::String::fromDouble(ratio, 2); + opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; + QItemDelegate::drawDisplay(painter, opt, opt.rect, str); break; } case TorrentModel::TR_PRIORITY: { @@ -157,7 +151,6 @@ void TransferListDelegate::paint(QPainter * painter, const QStyleOptionViewItem QItemDelegate::paint(painter, opt, index); } else { - QItemDelegate::drawBackground(painter, opt, index); QItemDelegate::drawDisplay(painter, opt, opt.rect, "*"); } break; @@ -186,7 +179,6 @@ void TransferListDelegate::paint(QPainter * painter, const QStyleOptionViewItem break; } case TorrentModel::TR_LAST_ACTIVITY: { - QItemDelegate::drawBackground(painter, opt, index); qlonglong elapsed = index.data().toLongLong(); if (hideValues && ((elapsed < 0) || (elapsed >= MAX_ETA))) break; @@ -217,8 +209,6 @@ QWidget* TransferListDelegate::createEditor(QWidget*, const QStyleOptionViewItem QSize TransferListDelegate::sizeHint(const QStyleOptionViewItem & option, const QModelIndex & index) const { - QSize size = QItemDelegate::sizeHint(option, index); - static int iconHeight = -1; if (iconHeight == -1) { QIcon icon(":/icons/skin/downloading.png"); @@ -226,6 +216,7 @@ QSize TransferListDelegate::sizeHint(const QStyleOptionViewItem & option, const iconHeight = icSizes[0].height(); } + QSize size = QItemDelegate::sizeHint(option, index); if (size.height() < iconHeight) size.setHeight(iconHeight); From 1a010cbfc61c7823aaa35731d200362c6967b54b Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Mon, 1 Feb 2016 20:07:18 +0800 Subject: [PATCH 5/6] Fix total values for "Seeds" & "Peers" --- src/gui/torrentmodel.cpp | 4 ++-- src/gui/transferlistdelegate.cpp | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/gui/torrentmodel.cpp b/src/gui/torrentmodel.cpp index 67f0bad0d..451a5a02d 100644 --- a/src/gui/torrentmodel.cpp +++ b/src/gui/torrentmodel.cpp @@ -185,9 +185,9 @@ QVariant TorrentModel::data(const QModelIndex &index, int role) const case TR_STATUS: return static_cast(torrent->state()); case TR_SEEDS: - return (role == Qt::DisplayRole) ? torrent->seedsCount() : torrent->completeCount(); + return (role == Qt::DisplayRole) ? torrent->seedsCount() : torrent->totalSeedsCount(); case TR_PEERS: - return (role == Qt::DisplayRole) ? (torrent->peersCount() - torrent->seedsCount()) : torrent->incompleteCount(); + return (role == Qt::DisplayRole) ? torrent->leechsCount() : torrent->totalLeechersCount(); case TR_DLSPEED: return torrent->downloadPayloadRate(); case TR_UPSPEED: diff --git a/src/gui/transferlistdelegate.cpp b/src/gui/transferlistdelegate.cpp index c2c1a6aa5..9ab172418 100644 --- a/src/gui/transferlistdelegate.cpp +++ b/src/gui/transferlistdelegate.cpp @@ -86,11 +86,11 @@ void TransferListDelegate::paint(QPainter * painter, const QStyleOptionViewItem } case TorrentModel::TR_SEEDS: case TorrentModel::TR_PEERS: { - QString display = index.data().toString(); + qlonglong value = index.data().toLongLong(); qlonglong total = index.data(Qt::UserRole).toLongLong(); - // Scrape was successful, we have total values - if (total > 0) - display += " (" + QString::number(total) + ")"; + if (hideValues && (!value && !total)) + break; + QString display = QString::number(value) + " (" + QString::number(total) + ")"; opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; QItemDelegate::drawDisplay(painter, opt, opt.rect, display); break; From ee277bf126d1debf9ef4c6d27abf5074293ff72d Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Mon, 1 Feb 2016 20:19:28 +0800 Subject: [PATCH 6/6] Add "Paused torrents only" option for "Hide zero and infinity values" --- src/base/preferences.cpp | 10 ++++++++ src/base/preferences.h | 2 ++ src/gui/options.ui | 43 +++++++++++++++++++++++++++----- src/gui/options_imp.cpp | 3 +++ src/gui/transferlistdelegate.cpp | 8 +++++- 5 files changed, 59 insertions(+), 7 deletions(-) diff --git a/src/base/preferences.cpp b/src/base/preferences.cpp index 79e6125e4..7081a659d 100644 --- a/src/base/preferences.cpp +++ b/src/base/preferences.cpp @@ -283,6 +283,16 @@ void Preferences::setHideZeroValues(bool b) setValue("Preferences/General/HideZeroValues", b); } +int Preferences::getHideZeroComboValues() const +{ + return value("Preferences/General/HideZeroComboValues", 0).toInt(); +} + +void Preferences::setHideZeroComboValues(int n) +{ + setValue("Preferences/General/HideZeroComboValues", n); +} + bool Preferences::useRandomPort() const { return value("Preferences/General/UseRandomPort", false).toBool(); diff --git a/src/base/preferences.h b/src/base/preferences.h index acf0a254c..ca29ab46b 100644 --- a/src/base/preferences.h +++ b/src/base/preferences.h @@ -134,6 +134,8 @@ public: void setAlternatingRowColors(bool b); bool getHideZeroValues() const; void setHideZeroValues(bool b); + int getHideZeroComboValues() const; + void setHideZeroComboValues(int n); bool useRandomPort() const; void setRandomPort(bool b); bool systrayIntegration() const; diff --git a/src/gui/options.ui b/src/gui/options.ui index 7733b2fdb..1144033b0 100644 --- a/src/gui/options.ui +++ b/src/gui/options.ui @@ -163,7 +163,7 @@ 0 0 480 - 698 + 702 @@ -258,11 +258,42 @@ - - - Hide zero and infinity values - - + + + + + Hide zero and infinity values + + + + + + + + Always + + + + + Paused torrents only + + + + + + + + Qt::Horizontal + + + + 0 + 0 + + + + + diff --git a/src/gui/options_imp.cpp b/src/gui/options_imp.cpp index 37de68ca0..7f200cd4e 100644 --- a/src/gui/options_imp.cpp +++ b/src/gui/options_imp.cpp @@ -142,6 +142,7 @@ options_imp::options_imp(QWidget *parent) 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(comboHideZero, SIGNAL(currentIndexChanged(int)), 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())); @@ -394,6 +395,7 @@ void options_imp::saveOptions() pref->setConfirmTorrentDeletion(confirmDeletion->isChecked()); pref->setAlternatingRowColors(checkAltRowColors->isChecked()); pref->setHideZeroValues(checkHideZero->isChecked()); + pref->setHideZeroComboValues(comboHideZero->currentIndex()); pref->setSystrayIntegration(systrayIntegration()); pref->setTrayIconStyle(TrayIcon::Style(comboTrayIcon->currentIndex())); pref->setCloseToTray(closeToTray()); @@ -576,6 +578,7 @@ void options_imp::loadOptions() confirmDeletion->setChecked(pref->confirmTorrentDeletion()); checkAltRowColors->setChecked(pref->useAlternatingRowColors()); checkHideZero->setChecked(pref->getHideZeroValues()); + comboHideZero->setCurrentIndex(pref->getHideZeroComboValues()); checkShowSplash->setChecked(!pref->isSplashScreenDisabled()); checkStartMinimized->setChecked(pref->startMinimized()); diff --git a/src/gui/transferlistdelegate.cpp b/src/gui/transferlistdelegate.cpp index 9ab172418..72dc0cb70 100644 --- a/src/gui/transferlistdelegate.cpp +++ b/src/gui/transferlistdelegate.cpp @@ -59,7 +59,13 @@ TransferListDelegate::TransferListDelegate(QObject *parent) void TransferListDelegate::paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const { painter->save(); - const bool hideValues = Preferences::instance()->getHideZeroValues(); + bool isHideState = true; + if (Preferences::instance()->getHideZeroComboValues() == 1) { // paused torrents only + QModelIndex stateIndex = index.sibling(index.row(), TorrentModel::TR_STATUS); + if (stateIndex.data().toInt() != BitTorrent::TorrentState::PausedDownloading) + isHideState = false; + } + const bool hideValues = Preferences::instance()->getHideZeroValues() & isHideState; QStyleOptionViewItemV2 opt = QItemDelegate::setOptions(index, option); QItemDelegate::drawBackground(painter, opt, index);