painter->setFont( statusFont );
painter->drawText( statusArea, 0, statusStr );
myProgressBarStyle->rect = barArea;
- myProgressBarStyle->direction = option.direction;
- myProgressBarStyle->palette = option.palette;
- myProgressBarStyle->palette.setCurrentColorGroup( cg );
+ if ( tor.isDownloading() ) {
+ myProgressBarStyle->palette.setBrush( QPalette::Highlight, blueBrush );
+ myProgressBarStyle->palette.setColor( QPalette::Base, blueBack );
+ myProgressBarStyle->palette.setColor( QPalette::Background, blueBack );
+ }
+ else if ( tor.isSeeding() ) {
+ myProgressBarStyle->palette.setBrush( QPalette::Highlight, greenBrush );
+ myProgressBarStyle->palette.setColor( QPalette::Base, greenBack );
+ myProgressBarStyle->palette.setColor( QPalette::Background, greenBack );
+ }
myProgressBarStyle->state = progressBarState;
char buf[32];
tr_snprintf( buf, sizeof( buf ), "%d%%", (int)tr_truncd( 100.0 * tor.percentDone( ), 0 ) );
#include <iostream>
#include <QApplication>
-#include <QBrush>
#include <QFont>
#include <QFontMetrics>
#include <QIcon>
BAR_HEIGHT = 12
};
+QColor TorrentDelegate :: greenBrush;
+QColor TorrentDelegate :: blueBrush;
+QColor TorrentDelegate :: greenBack;
+QColor TorrentDelegate :: blueBack;
+
TorrentDelegate :: TorrentDelegate( QObject * parent ):
- QItemDelegate( parent ),
+ QStyledItemDelegate( parent ),
myProgressBarStyle( new QStyleOptionProgressBarV2 )
{
myProgressBarStyle->minimum = 0;
myProgressBarStyle->maximum = 1000;
+
+ greenBrush = QColor("forestgreen");
+ greenBack = QColor("darkseagreen");
+
+ blueBrush = QColor("steelblue");
+ blueBack = QColor("lightgrey");
}
TorrentDelegate :: ~TorrentDelegate( )
const Torrent * tor( index.data( TorrentModel::TorrentRole ).value<const Torrent*>() );
painter->save( );
painter->setClipRect( option.rect );
- drawBackground( painter, option, index );
drawTorrent( painter, option, *tor );
- drawFocus(painter, option, option.rect );
painter->restore( );
}
if (tor.isSeeding() && tor.getSeedRatio(seedRatioLimit))
{
const double seedRateRatio = tor.ratio() / seedRatioLimit;
- const double invertedRatio = 1. - seedRateRatio;
- const int scaledProgress = invertedRatio * (myProgressBarStyle->maximum - myProgressBarStyle->minimum);
+ const int scaledProgress = seedRateRatio * (myProgressBarStyle->maximum - myProgressBarStyle->minimum);
myProgressBarStyle->progress = myProgressBarStyle->minimum + scaledProgress;
}
else
painter->setFont( progressFont );
painter->drawText( progArea, 0, progressFM.elidedText( progressStr, Qt::ElideRight, progArea.width( ) ) );
myProgressBarStyle->rect = barArea;
- myProgressBarStyle->palette = option.palette;
- myProgressBarStyle->palette.setCurrentColorGroup( cg );
+ if ( tor.isDownloading() ) {
+ myProgressBarStyle->palette.setBrush( QPalette::Highlight, blueBrush );
+ myProgressBarStyle->palette.setColor( QPalette::Base, blueBack );
+ myProgressBarStyle->palette.setColor( QPalette::Background, blueBack );
+ }
+ else if ( tor.isSeeding() ) {
+ myProgressBarStyle->palette.setBrush( QPalette::Highlight, greenBrush );
+ myProgressBarStyle->palette.setColor( QPalette::Base, greenBack );
+ myProgressBarStyle->palette.setColor( QPalette::Background, greenBack );
+ }
myProgressBarStyle->state = progressBarState;
setProgressBarPercentDone( option, tor );
#ifndef QTR_TORRENT_DELEGATE_H
#define QTR_TORRENT_DELEGATE_H
-#include <QItemDelegate>
+#include <QStyledItemDelegate>
#include <QSize>
class QStyleOptionProgressBarV2;
class Session;
class Torrent;
-class TorrentDelegate: public QItemDelegate
+class TorrentDelegate: public QStyledItemDelegate
{
Q_OBJECT
+ public:
+ static QColor blueBrush, greenBrush;
+ static QColor blueBack, greenBack;
+
protected:
QStyleOptionProgressBarV2 * myProgressBarStyle;
QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const;
void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
+
};
#endif