Browse Source

Add "Hide zero values" option. Closes #3543.

adaptive-webui-19844
Chocobo1 9 years ago
parent
commit
325ba48601
  1. 12
      src/base/preferences.cpp
  2. 2
      src/base/preferences.h
  3. 9
      src/gui/options.ui
  4. 3
      src/gui/options_imp.cpp
  5. 26
      src/gui/transferlistdelegate.cpp

12
src/base/preferences.cpp

@ -273,6 +273,16 @@ void Preferences::setAlternatingRowColors(bool b)
setValue("Preferences/General/AlternatingRowColors", 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 bool Preferences::useRandomPort() const
{ {
return value("Preferences/General/UseRandomPort", false).toBool(); return value("Preferences/General/UseRandomPort", false).toBool();
@ -1900,7 +1910,7 @@ bool Preferences::isTorrentFileAssocSet()
CFStringRef myBundleId = CFBundleGetIdentifier(CFBundleGetMainBundle()); CFStringRef myBundleId = CFBundleGetIdentifier(CFBundleGetMainBundle());
isSet = CFStringCompare(myBundleId, defaultHandlerId, 0) == kCFCompareEqualTo; isSet = CFStringCompare(myBundleId, defaultHandlerId, 0) == kCFCompareEqualTo;
CFRelease(defaultHandlerId); CFRelease(defaultHandlerId);
} }
CFRelease(torrentId); CFRelease(torrentId);
} }
return isSet; return isSet;

2
src/base/preferences.h

@ -132,6 +132,8 @@ public:
void showSpeedInTitleBar(bool show); void showSpeedInTitleBar(bool show);
bool useAlternatingRowColors() const; bool useAlternatingRowColors() const;
void setAlternatingRowColors(bool b); void setAlternatingRowColors(bool b);
bool getHideZeroValues() const;
void setHideZeroValues(bool b);
bool useRandomPort() const; bool useRandomPort() const;
void setRandomPort(bool b); void setRandomPort(bool b);
bool systrayIntegration() const; bool systrayIntegration() const;

9
src/gui/options.ui

@ -163,7 +163,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>480</width> <width>480</width>
<height>672</height> <height>698</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_9"> <layout class="QVBoxLayout" name="verticalLayout_9">
@ -257,6 +257,13 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QCheckBox" name="checkHideZero">
<property name="text">
<string>Hide zero and infinity values</string>
</property>
</widget>
</item>
<item> <item>
<widget class="QGroupBox" name="groupBox_7"> <widget class="QGroupBox" name="groupBox_7">
<property name="font"> <property name="font">

3
src/gui/options_imp.cpp

@ -141,6 +141,7 @@ options_imp::options_imp(QWidget *parent)
connect(comboI18n, SIGNAL(currentIndexChanged(int)), this, SLOT(enableApplyButton())); connect(comboI18n, SIGNAL(currentIndexChanged(int)), this, SLOT(enableApplyButton()));
connect(confirmDeletion, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton())); connect(confirmDeletion, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton()));
connect(checkAltRowColors, 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(checkShowSystray, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton()));
connect(checkCloseToSystray, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton())); connect(checkCloseToSystray, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton()));
connect(checkMinimizeToSysTray, 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->setLocale(locale);
pref->setConfirmTorrentDeletion(confirmDeletion->isChecked()); pref->setConfirmTorrentDeletion(confirmDeletion->isChecked());
pref->setAlternatingRowColors(checkAltRowColors->isChecked()); pref->setAlternatingRowColors(checkAltRowColors->isChecked());
pref->setHideZeroValues(checkHideZero->isChecked());
pref->setSystrayIntegration(systrayIntegration()); pref->setSystrayIntegration(systrayIntegration());
pref->setTrayIconStyle(TrayIcon::Style(comboTrayIcon->currentIndex())); pref->setTrayIconStyle(TrayIcon::Style(comboTrayIcon->currentIndex()));
pref->setCloseToTray(closeToTray()); pref->setCloseToTray(closeToTray());
@ -573,6 +575,7 @@ void options_imp::loadOptions()
setLocale(pref->getLocale()); setLocale(pref->getLocale());
confirmDeletion->setChecked(pref->confirmTorrentDeletion()); confirmDeletion->setChecked(pref->confirmTorrentDeletion());
checkAltRowColors->setChecked(pref->useAlternatingRowColors()); checkAltRowColors->setChecked(pref->useAlternatingRowColors());
checkHideZero->setChecked(pref->getHideZeroValues());
checkShowSplash->setChecked(!pref->isSplashScreenDisabled()); checkShowSplash->setChecked(!pref->isSplashScreenDisabled());
checkStartMinimized->setChecked(pref->startMinimized()); checkStartMinimized->setChecked(pref->startMinimized());

26
src/gui/transferlistdelegate.cpp

@ -39,6 +39,8 @@
#include "torrentmodel.h" #include "torrentmodel.h"
#include "base/bittorrent/session.h" #include "base/bittorrent/session.h"
#include "base/bittorrent/torrenthandle.h" #include "base/bittorrent/torrenthandle.h"
#include "base/types.h"
#include "base/preferences.h"
#include "base/unicodestrings.h" #include "base/unicodestrings.h"
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
@ -54,6 +56,7 @@ TransferListDelegate::TransferListDelegate(QObject *parent) : QItemDelegate(pare
TransferListDelegate::~TransferListDelegate() {} TransferListDelegate::~TransferListDelegate() {}
void TransferListDelegate::paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const { void TransferListDelegate::paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const {
const bool hideValues = Preferences::instance()->getHideZeroValues();
QStyleOptionViewItemV2 opt = QItemDelegate::setOptions(index, option); QStyleOptionViewItemV2 opt = QItemDelegate::setOptions(index, option);
painter->save(); painter->save();
switch(index.column()) { switch(index.column()) {
@ -66,10 +69,14 @@ void TransferListDelegate::paint(QPainter * painter, const QStyleOptionViewItem
case TorrentModel::TR_SIZE: case TorrentModel::TR_SIZE:
case TorrentModel::TR_TOTAL_SIZE: { case TorrentModel::TR_TOTAL_SIZE: {
QItemDelegate::drawBackground(painter, opt, index); QItemDelegate::drawBackground(painter, opt, index);
qlonglong size = index.data().toLongLong();
if (hideValues && !size)
break;
opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; 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; break;
} }
case TorrentModel::TR_ETA: { case TorrentModel::TR_ETA: {
QItemDelegate::drawBackground(painter, opt, index); QItemDelegate::drawBackground(painter, opt, index);
opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter;
@ -152,6 +159,8 @@ void TransferListDelegate::paint(QPainter * painter, const QStyleOptionViewItem
case TorrentModel::TR_DLSPEED: { case TorrentModel::TR_DLSPEED: {
QItemDelegate::drawBackground(painter, opt, index); QItemDelegate::drawBackground(painter, opt, index);
const qulonglong speed = index.data().toULongLong(); const qulonglong speed = index.data().toULongLong();
if (hideValues && !speed)
break;
opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter;
QItemDelegate::drawDisplay(painter, opt, opt.rect, Utils::Misc::friendlyUnit(speed, true)); QItemDelegate::drawDisplay(painter, opt, opt.rect, Utils::Misc::friendlyUnit(speed, true));
break; break;
@ -160,6 +169,8 @@ void TransferListDelegate::paint(QPainter * painter, const QStyleOptionViewItem
case TorrentModel::TR_DLLIMIT: { case TorrentModel::TR_DLLIMIT: {
QItemDelegate::drawBackground(painter, opt, index); QItemDelegate::drawBackground(painter, opt, index);
const qlonglong limit = index.data().toLongLong(); const qlonglong limit = index.data().toLongLong();
if (hideValues && !limit)
break;
opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter;
QItemDelegate::drawDisplay(painter, opt, opt.rect, limit > 0 ? Utils::Misc::friendlyUnit(limit, true) : QString::fromUtf8(C_INFINITY)); QItemDelegate::drawDisplay(painter, opt, opt.rect, limit > 0 ? Utils::Misc::friendlyUnit(limit, true) : QString::fromUtf8(C_INFINITY));
break; break;
@ -185,6 +196,8 @@ void TransferListDelegate::paint(QPainter * painter, const QStyleOptionViewItem
QItemDelegate::drawBackground(painter, opt, index); QItemDelegate::drawBackground(painter, opt, index);
opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter;
const qreal ratio = index.data().toDouble(); const qreal ratio = index.data().toDouble();
if (hideValues && (ratio <= 0))
break;
QItemDelegate::drawDisplay(painter, opt, opt.rect, QItemDelegate::drawDisplay(painter, opt, opt.rect,
((ratio == -1) || (ratio > BitTorrent::TorrentHandle::MAX_RATIO)) ? QString::fromUtf8(C_INFINITY) : Utils::String::fromDouble(ratio, 2)); ((ratio == -1) || (ratio > BitTorrent::TorrentHandle::MAX_RATIO)) ? QString::fromUtf8(C_INFINITY) : Utils::String::fromDouble(ratio, 2));
break; break;
@ -224,17 +237,20 @@ void TransferListDelegate::paint(QPainter * painter, const QStyleOptionViewItem
break; break;
} }
case TorrentModel::TR_LAST_ACTIVITY: { case TorrentModel::TR_LAST_ACTIVITY: {
QString elapsedString;
long long elapsed = index.data().toLongLong();
QItemDelegate::drawBackground(painter, opt, index); 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) if (elapsed == 0)
// Show '< 1m ago' when elapsed time is 0 // Show '< 1m ago' when elapsed time is 0
elapsed = 1; elapsed = 1;
if (elapsed < 0) else if (elapsed < 0)
elapsedString = Utils::Misc::userFriendlyDuration(elapsed); elapsedString = Utils::Misc::userFriendlyDuration(elapsed);
else else
elapsedString = tr("%1 ago", "e.g.: 1h 20m ago").arg(Utils::Misc::userFriendlyDuration(elapsed)); 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); QItemDelegate::drawDisplay(painter, opt, option.rect, elapsedString);
break; break;
} }

Loading…
Cancel
Save