Browse Source

Follow project coding style. Issue #2192.

adaptive-webui-19844
Chocobo1 9 years ago
parent
commit
a56b745429
  1. 45
      src/gui/transferlistdelegate.cpp
  2. 4
      src/gui/transferlistdelegate.h

45
src/gui/transferlistdelegate.cpp

@ -51,15 +51,21 @@
#endif #endif
#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 { void TransferListDelegate::paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const
{
const bool hideValues = Preferences::instance()->getHideZeroValues(); 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()) {
case TorrentModel::TR_AMOUNT_DOWNLOADED: case TorrentModel::TR_AMOUNT_DOWNLOADED:
case TorrentModel::TR_AMOUNT_UPLOADED: case TorrentModel::TR_AMOUNT_UPLOADED:
case TorrentModel::TR_AMOUNT_DOWNLOADED_SESSION: case TorrentModel::TR_AMOUNT_DOWNLOADED_SESSION:
@ -76,7 +82,6 @@ void TransferListDelegate::paint(QPainter * painter, const QStyleOptionViewItem
QItemDelegate::drawDisplay(painter, opt, option.rect, Utils::Misc::friendlyUnit(size)); 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;
@ -87,10 +92,9 @@ void TransferListDelegate::paint(QPainter * painter, const QStyleOptionViewItem
case TorrentModel::TR_PEERS: { case TorrentModel::TR_PEERS: {
QString display = QString::number(index.data().toLongLong()); QString display = QString::number(index.data().toLongLong());
qlonglong total = index.data(Qt::UserRole).toLongLong(); qlonglong total = index.data(Qt::UserRole).toLongLong();
if (total > 0) { if (total > 0)
// Scrape was successful, we have total values // Scrape was successful, we have total values
display += " ("+QString::number(total)+")"; display += " (" + QString::number(total) + ")";
}
QItemDelegate::drawBackground(painter, opt, index); QItemDelegate::drawBackground(painter, opt, index);
opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter;
QItemDelegate::drawDisplay(painter, opt, opt.rect, display); QItemDelegate::drawDisplay(painter, opt, opt.rect, display);
@ -99,7 +103,7 @@ void TransferListDelegate::paint(QPainter * painter, const QStyleOptionViewItem
case TorrentModel::TR_STATUS: { case TorrentModel::TR_STATUS: {
const int state = index.data().toInt(); const int state = index.data().toInt();
QString display; QString display;
switch(state) { switch (state) {
case BitTorrent::TorrentState::Downloading: case BitTorrent::TorrentState::Downloading:
display = tr("Downloading"); display = tr("Downloading");
break; break;
@ -205,8 +209,9 @@ void TransferListDelegate::paint(QPainter * painter, const QStyleOptionViewItem
case TorrentModel::TR_PRIORITY: { case TorrentModel::TR_PRIORITY: {
const int priority = index.data().toInt(); const int priority = index.data().toInt();
opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter;
if (priority > 0) if (priority > 0) {
QItemDelegate::paint(painter, opt, index); QItemDelegate::paint(painter, opt, index);
}
else { else {
QItemDelegate::drawBackground(painter, opt, index); QItemDelegate::drawBackground(painter, opt, index);
QItemDelegate::drawDisplay(painter, opt, opt.rect, "*"); QItemDelegate::drawDisplay(painter, opt, opt.rect, "*");
@ -215,7 +220,7 @@ void TransferListDelegate::paint(QPainter * painter, const QStyleOptionViewItem
} }
case TorrentModel::TR_PROGRESS: { case TorrentModel::TR_PROGRESS: {
QStyleOptionProgressBarV2 newopt; QStyleOptionProgressBarV2 newopt;
qreal progress = index.data().toDouble()*100.; qreal progress = index.data().toDouble() * 100.;
newopt.rect = opt.rect; newopt.rect = opt.rect;
newopt.text = ((progress == 100.0) ? QString("100%") : Utils::String::fromDouble(progress, 1) + "%"); newopt.text = ((progress == 100.0) ? QString("100%") : Utils::String::fromDouble(progress, 1) + "%");
newopt.progress = (int)progress; newopt.progress = (int)progress;
@ -260,23 +265,25 @@ void TransferListDelegate::paint(QPainter * painter, const QStyleOptionViewItem
painter->restore(); painter->restore();
} }
QWidget* TransferListDelegate::createEditor(QWidget*, const QStyleOptionViewItem &, const QModelIndex &) const { QWidget* TransferListDelegate::createEditor(QWidget*, const QStyleOptionViewItem &, const QModelIndex &) const
{
// No editor here // No editor here
return 0; return 0;
} }
QSize TransferListDelegate::sizeHint(const QStyleOptionViewItem & option, const QModelIndex & index) const { QSize TransferListDelegate::sizeHint(const QStyleOptionViewItem & option, const QModelIndex & index) const
{
QSize size = QItemDelegate::sizeHint(option, index); QSize size = QItemDelegate::sizeHint(option, index);
static int icon_height = -1; static int iconHeight = -1;
if (icon_height == -1) { if (iconHeight == -1) {
QIcon icon(":/icons/skin/downloading.png"); QIcon icon(":/icons/skin/downloading.png");
QList<QSize> ic_sizes(icon.availableSizes()); QList<QSize> icSizes(icon.availableSizes());
icon_height = ic_sizes[0].height(); iconHeight = icSizes[0].height();
} }
if (size.height() < icon_height) if (size.height() < iconHeight)
size.setHeight(icon_height); size.setHeight(iconHeight);
return size; return size;
} }

4
src/gui/transferlistdelegate.h

@ -41,7 +41,8 @@ QT_END_NAMESPACE
// Defines for download list list columns // Defines for download list list columns
class TransferListDelegate: public QItemDelegate { class TransferListDelegate: public QItemDelegate
{
Q_OBJECT Q_OBJECT
public: public:
@ -55,7 +56,6 @@ public:
// the rows shrink if the text's height is smaller than the icon's height. // 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. // This happens because icon from the 'name' column is no longer drawn.
QSize sizeHint(const QStyleOptionViewItem & option, const QModelIndex & index) const; QSize sizeHint(const QStyleOptionViewItem & option, const QModelIndex & index) const;
}; };
#endif // TRANSFERLISTDELEGATE_H #endif // TRANSFERLISTDELEGATE_H

Loading…
Cancel
Save