|
|
|
@ -33,31 +33,50 @@
@@ -33,31 +33,50 @@
|
|
|
|
|
|
|
|
|
|
#include <QItemDelegate> |
|
|
|
|
#include <QPainter> |
|
|
|
|
|
|
|
|
|
#include "base/preferences.h" |
|
|
|
|
#include "base/utils/misc.h" |
|
|
|
|
#include "base/utils/string.h" |
|
|
|
|
#include "base/preferences.h" |
|
|
|
|
|
|
|
|
|
class PeerListDelegate: public QItemDelegate { |
|
|
|
|
Q_OBJECT |
|
|
|
|
|
|
|
|
|
public: |
|
|
|
|
enum PeerListColumns {COUNTRY, IP, PORT, CONNECTION, FLAGS, CLIENT, PROGRESS, DOWN_SPEED, UP_SPEED, |
|
|
|
|
TOT_DOWN, TOT_UP, RELEVANCE, DOWNLOADING_PIECE, IP_HIDDEN, COL_COUNT}; |
|
|
|
|
enum PeerListColumns |
|
|
|
|
{ |
|
|
|
|
COUNTRY, |
|
|
|
|
IP, |
|
|
|
|
PORT, |
|
|
|
|
CONNECTION, |
|
|
|
|
FLAGS, |
|
|
|
|
CLIENT, |
|
|
|
|
PROGRESS, |
|
|
|
|
DOWN_SPEED, |
|
|
|
|
UP_SPEED, |
|
|
|
|
TOT_DOWN, |
|
|
|
|
TOT_UP, RELEVANCE, |
|
|
|
|
DOWNLOADING_PIECE, |
|
|
|
|
IP_HIDDEN, |
|
|
|
|
|
|
|
|
|
COL_COUNT |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
public: |
|
|
|
|
PeerListDelegate(QObject *parent) : QItemDelegate(parent) {} |
|
|
|
|
|
|
|
|
|
~PeerListDelegate() {} |
|
|
|
|
|
|
|
|
|
void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const { |
|
|
|
|
void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const |
|
|
|
|
{ |
|
|
|
|
painter->save(); |
|
|
|
|
const bool hideValues = Preferences::instance()->getHideZeroValues(); |
|
|
|
|
QStyleOptionViewItem opt = QItemDelegate::setOptions(index, option); |
|
|
|
|
switch(index.column()) { |
|
|
|
|
case PORT: |
|
|
|
|
case PORT: { |
|
|
|
|
QItemDelegate::drawBackground(painter, opt, index); |
|
|
|
|
opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; |
|
|
|
|
QItemDelegate::drawDisplay(painter, opt, option.rect, index.data().toString()); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
case TOT_DOWN: |
|
|
|
|
case TOT_UP: { |
|
|
|
@ -76,23 +95,24 @@ public:
@@ -76,23 +95,24 @@ public:
|
|
|
|
|
opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; |
|
|
|
|
if (speed > 0.0) |
|
|
|
|
QItemDelegate::drawDisplay(painter, opt, opt.rect, Utils::Misc::friendlyUnit(speed, true)); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
case PROGRESS: |
|
|
|
|
case RELEVANCE: { |
|
|
|
|
QItemDelegate::drawBackground(painter, opt, index); |
|
|
|
|
qreal progress = index.data().toDouble(); |
|
|
|
|
opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; |
|
|
|
|
QItemDelegate::drawDisplay(painter, opt, opt.rect, Utils::String::fromDouble(progress*100.0, 1)+"%"); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
default: |
|
|
|
|
QItemDelegate::paint(painter, option, index); |
|
|
|
|
} |
|
|
|
|
painter->restore(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
QWidget* createEditor(QWidget*, const QStyleOptionViewItem &, const QModelIndex &) const { |
|
|
|
|
QWidget* createEditor(QWidget*, const QStyleOptionViewItem &, const QModelIndex &) const |
|
|
|
|
{ |
|
|
|
|
// No editor here
|
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|