mirror of
https://github.com/transmission/transmission
synced 2024-12-23 00:04:06 +00:00
(trunk qt) #4389 "share ratio progressbar indication counter-intuitive" -- apply rb07's 'color-progress-bar.patch' to to add color to the progress bar, similar to the Mac and Web client. It also restores seed bar to normal filling, not reverse or emptying.
This commit is contained in:
parent
4c8c5f578d
commit
018fe4c4a9
3 changed files with 40 additions and 13 deletions
|
@ -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 ) );
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
#include <iostream>
|
||||
|
||||
#include <QApplication>
|
||||
#include <QBrush>
|
||||
#include <QFont>
|
||||
#include <QFontMetrics>
|
||||
#include <QIcon>
|
||||
|
@ -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<const Torrent*>() );
|
||||
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 );
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
#ifndef QTR_TORRENT_DELEGATE_H
|
||||
#define QTR_TORRENT_DELEGATE_H
|
||||
|
||||
#include <QItemDelegate>
|
||||
#include <QStyledItemDelegate>
|
||||
#include <QSize>
|
||||
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue