diff --git a/qt/torrent-delegate-min.cc b/qt/torrent-delegate-min.cc index 7cd2c8a2a..a6e21e844 100644 --- a/qt/torrent-delegate-min.cc +++ b/qt/torrent-delegate-min.cc @@ -154,9 +154,16 @@ TorrentDelegateMin :: drawTorrent( QPainter * painter, const QStyleOptionViewIte 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 ) ); diff --git a/qt/torrent-delegate.cc b/qt/torrent-delegate.cc index 4d11ffcd0..f7b7d7630 100644 --- a/qt/torrent-delegate.cc +++ b/qt/torrent-delegate.cc @@ -13,7 +13,6 @@ #include #include -#include #include #include #include @@ -34,12 +33,23 @@ enum 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( ) @@ -314,9 +324,7 @@ TorrentDelegate :: paint( QPainter * painter, const Torrent * tor( index.data( TorrentModel::TorrentRole ).value() ); painter->save( ); painter->setClipRect( option.rect ); - drawBackground( painter, option, index ); drawTorrent( painter, option, *tor ); - drawFocus(painter, option, option.rect ); painter->restore( ); } @@ -327,8 +335,7 @@ TorrentDelegate :: setProgressBarPercentDone( const QStyleOptionViewItem& option 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 @@ -419,8 +426,16 @@ TorrentDelegate :: drawTorrent( QPainter * painter, const QStyleOptionViewItem& 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 ); diff --git a/qt/torrent-delegate.h b/qt/torrent-delegate.h index 77a42038e..d428951f5 100644 --- a/qt/torrent-delegate.h +++ b/qt/torrent-delegate.h @@ -13,7 +13,7 @@ #ifndef QTR_TORRENT_DELEGATE_H #define QTR_TORRENT_DELEGATE_H -#include +#include #include class QStyleOptionProgressBarV2; @@ -22,10 +22,14 @@ class QStyle; 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; @@ -47,6 +51,7 @@ class TorrentDelegate: public QItemDelegate QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const; void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const; + }; #endif