2009-04-09 18:55:47 +00:00
|
|
|
/*
|
2010-08-01 20:36:13 +00:00
|
|
|
* This file Copyright (C) Mnemosyne LLC
|
2009-04-09 18:55:47 +00:00
|
|
|
*
|
2010-08-01 20:36:13 +00:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
2009-04-09 18:55:47 +00:00
|
|
|
*
|
2009-05-31 19:33:48 +00:00
|
|
|
* $Id$
|
2009-04-09 18:55:47 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
#include <QApplication>
|
|
|
|
#include <QFont>
|
|
|
|
#include <QFontMetrics>
|
|
|
|
#include <QIcon>
|
|
|
|
#include <QModelIndex>
|
|
|
|
#include <QPainter>
|
|
|
|
#include <QPixmap>
|
|
|
|
#include <QPixmapCache>
|
|
|
|
#include <QStyleOptionProgressBarV2>
|
|
|
|
|
2010-07-03 01:10:36 +00:00
|
|
|
#include "formatter.h"
|
2009-04-09 18:55:47 +00:00
|
|
|
#include "torrent.h"
|
|
|
|
#include "torrent-delegate.h"
|
|
|
|
#include "torrent-model.h"
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
GUI_PAD = 6,
|
|
|
|
BAR_HEIGHT = 12
|
|
|
|
};
|
|
|
|
|
2012-03-04 13:15:43 +00:00
|
|
|
QColor TorrentDelegate :: greenBrush;
|
|
|
|
QColor TorrentDelegate :: blueBrush;
|
|
|
|
QColor TorrentDelegate :: greenBack;
|
|
|
|
QColor TorrentDelegate :: blueBack;
|
|
|
|
|
2009-04-09 18:55:47 +00:00
|
|
|
TorrentDelegate :: TorrentDelegate( QObject * parent ):
|
2012-03-04 13:15:43 +00:00
|
|
|
QStyledItemDelegate( parent ),
|
2009-04-09 18:55:47 +00:00
|
|
|
myProgressBarStyle( new QStyleOptionProgressBarV2 )
|
|
|
|
{
|
|
|
|
myProgressBarStyle->minimum = 0;
|
|
|
|
myProgressBarStyle->maximum = 1000;
|
2012-03-04 13:15:43 +00:00
|
|
|
|
|
|
|
greenBrush = QColor("forestgreen");
|
|
|
|
greenBack = QColor("darkseagreen");
|
|
|
|
|
|
|
|
blueBrush = QColor("steelblue");
|
|
|
|
blueBack = QColor("lightgrey");
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TorrentDelegate :: ~TorrentDelegate( )
|
|
|
|
{
|
|
|
|
delete myProgressBarStyle;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
|
|
|
QSize
|
|
|
|
TorrentDelegate :: margin( const QStyle& style ) const
|
|
|
|
{
|
|
|
|
Q_UNUSED( style );
|
|
|
|
|
|
|
|
return QSize( 4, 4 );
|
|
|
|
}
|
|
|
|
|
|
|
|
QString
|
|
|
|
TorrentDelegate :: progressString( const Torrent& tor ) const
|
|
|
|
{
|
2010-06-16 03:02:17 +00:00
|
|
|
const bool isMagnet( !tor.hasMetadata( ) );
|
2009-04-09 18:55:47 +00:00
|
|
|
const bool isDone( tor.isDone( ) );
|
|
|
|
const bool isSeed( tor.isSeed( ) );
|
|
|
|
const uint64_t haveTotal( tor.haveTotal( ) );
|
|
|
|
QString str;
|
2010-01-05 23:47:50 +00:00
|
|
|
double seedRatio;
|
2010-04-01 06:08:20 +00:00
|
|
|
const bool hasSeedRatio( tor.getSeedRatio( seedRatio ) );
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2010-06-16 03:02:17 +00:00
|
|
|
if( isMagnet ) // magnet link with no metadata
|
|
|
|
{
|
|
|
|
/* %1 is the percentage of torrent metadata downloaded */
|
2010-06-16 06:34:45 +00:00
|
|
|
str = tr( "Magnetized transfer - retrieving metadata (%1%)" )
|
2010-07-03 01:10:36 +00:00
|
|
|
.arg( Formatter::percentToString( tor.metadataPercentDone() * 100.0 ) );
|
2010-06-16 03:02:17 +00:00
|
|
|
}
|
|
|
|
else if( !isDone ) // downloading
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
|
|
|
/* %1 is how much we've got,
|
|
|
|
%2 is how much we'll have when done,
|
|
|
|
%3 is a percentage of the two */
|
2010-07-03 01:10:36 +00:00
|
|
|
str = tr( "%1 of %2 (%3%)" ).arg( Formatter::sizeToString( haveTotal ) )
|
|
|
|
.arg( Formatter::sizeToString( tor.sizeWhenDone( ) ) )
|
|
|
|
.arg( Formatter::percentToString( tor.percentDone( ) * 100.0 ) );
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
2010-04-01 06:08:20 +00:00
|
|
|
else if( !isSeed ) // partial seed
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2010-04-01 06:08:20 +00:00
|
|
|
if( hasSeedRatio )
|
|
|
|
{
|
|
|
|
/* %1 is how much we've got,
|
|
|
|
%2 is the torrent's total size,
|
|
|
|
%3 is a percentage of the two,
|
|
|
|
%4 is how much we've uploaded,
|
|
|
|
%5 is our upload-to-download ratio
|
|
|
|
%6 is the ratio we want to reach before we stop uploading */
|
|
|
|
str = tr( "%1 of %2 (%3%), uploaded %4 (Ratio: %5 Goal: %6)" )
|
2010-07-03 01:10:36 +00:00
|
|
|
.arg( Formatter::sizeToString( haveTotal ) )
|
|
|
|
.arg( Formatter::sizeToString( tor.totalSize( ) ) )
|
|
|
|
.arg( Formatter::percentToString( tor.percentComplete( ) * 100.0 ) )
|
|
|
|
.arg( Formatter::sizeToString( tor.uploadedEver( ) ) )
|
|
|
|
.arg( Formatter::ratioToString( tor.ratio( ) ) )
|
|
|
|
.arg( Formatter::ratioToString( seedRatio ) );
|
2010-04-01 06:08:20 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* %1 is how much we've got,
|
|
|
|
%2 is the torrent's total size,
|
|
|
|
%3 is a percentage of the two,
|
|
|
|
%4 is how much we've uploaded,
|
|
|
|
%5 is our upload-to-download ratio */
|
|
|
|
str = tr( "%1 of %2 (%3%), uploaded %4 (Ratio: %5)" )
|
2010-07-03 01:10:36 +00:00
|
|
|
.arg( Formatter::sizeToString( haveTotal ) )
|
|
|
|
.arg( Formatter::sizeToString( tor.totalSize( ) ) )
|
|
|
|
.arg( Formatter::percentToString( tor.percentComplete( ) * 100.0 ) )
|
|
|
|
.arg( Formatter::sizeToString( tor.uploadedEver( ) ) )
|
|
|
|
.arg( Formatter::ratioToString( tor.ratio( ) ) );
|
2010-04-01 06:08:20 +00:00
|
|
|
}
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
2010-04-01 06:08:20 +00:00
|
|
|
else // seeding
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2010-04-01 06:08:20 +00:00
|
|
|
if( hasSeedRatio )
|
|
|
|
{
|
|
|
|
/* %1 is the torrent's total size,
|
|
|
|
%2 is how much we've uploaded,
|
|
|
|
%3 is our upload-to-download ratio,
|
|
|
|
%4 is the ratio we want to reach before we stop uploading */
|
2010-09-08 01:09:52 +00:00
|
|
|
str = tr( "%1, uploaded %2 (Ratio: %3 Goal: %4)" )
|
2010-07-03 01:10:36 +00:00
|
|
|
.arg( Formatter::sizeToString( haveTotal ) )
|
|
|
|
.arg( Formatter::sizeToString( tor.uploadedEver( ) ) )
|
|
|
|
.arg( Formatter::ratioToString( tor.ratio( ) ) )
|
|
|
|
.arg( Formatter::ratioToString( seedRatio ) );
|
2010-04-01 06:08:20 +00:00
|
|
|
}
|
|
|
|
else /* seeding w/o a ratio */
|
|
|
|
{
|
|
|
|
/* %1 is the torrent's total size,
|
|
|
|
%2 is how much we've uploaded,
|
|
|
|
%3 is our upload-to-download ratio */
|
|
|
|
str = tr( "%1, uploaded %2 (Ratio: %3)" )
|
2010-07-03 01:10:36 +00:00
|
|
|
.arg( Formatter::sizeToString( haveTotal ) )
|
|
|
|
.arg( Formatter::sizeToString( tor.uploadedEver( ) ) )
|
|
|
|
.arg( Formatter::ratioToString( tor.ratio( ) ) );
|
2010-04-01 06:08:20 +00:00
|
|
|
}
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* add time when downloading */
|
2010-03-31 19:42:30 +00:00
|
|
|
if( ( hasSeedRatio && tor.isSeeding( ) ) || tor.isDownloading( ) )
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
|
|
|
str += tr( " - " );
|
|
|
|
if( tor.hasETA( ) )
|
2010-07-03 01:10:36 +00:00
|
|
|
str += tr( "%1 left" ).arg( Formatter::timeToString( tor.getETA( ) ) );
|
2009-04-09 18:55:47 +00:00
|
|
|
else
|
|
|
|
str += tr( "Remaining time unknown" );
|
|
|
|
}
|
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString
|
2013-01-30 00:22:52 +00:00
|
|
|
TorrentDelegate :: shortTransferString (const Torrent& tor) const
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2013-01-30 00:22:52 +00:00
|
|
|
QString str;
|
|
|
|
const bool haveMeta (tor.hasMetadata());
|
|
|
|
const bool haveDown (haveMeta && ((tor.webseedsWeAreDownloadingFrom()>0) || (tor.peersWeAreDownloadingFrom()>0)));
|
|
|
|
const bool haveUp (haveMeta && tor.peersWeAreUploadingTo()>0);
|
|
|
|
|
|
|
|
if (haveDown)
|
2013-02-05 23:05:26 +00:00
|
|
|
str = tr( "%1 %2" ).arg(Formatter::downloadSpeedToString(tor.downloadSpeed()))
|
|
|
|
.arg(Formatter::uploadSpeedToString(tor.uploadSpeed()));
|
2013-01-30 00:22:52 +00:00
|
|
|
|
|
|
|
else if (haveUp)
|
2013-02-05 23:05:26 +00:00
|
|
|
str = Formatter::uploadSpeedToString(tor.uploadSpeed());
|
2013-01-30 00:22:52 +00:00
|
|
|
|
|
|
|
return str;
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QString
|
|
|
|
TorrentDelegate :: shortStatusString( const Torrent& tor ) const
|
|
|
|
{
|
|
|
|
QString str;
|
2013-01-30 00:22:52 +00:00
|
|
|
static const QChar ratioSymbol (0x262F);
|
2009-04-09 18:55:47 +00:00
|
|
|
|
|
|
|
switch( tor.getActivity( ) )
|
|
|
|
{
|
|
|
|
case TR_STATUS_CHECK:
|
2010-07-03 01:10:36 +00:00
|
|
|
str = tr( "Verifying local data (%1% tested)" ).arg( Formatter::percentToString( tor.getVerifyProgress()*100.0 ) );
|
2009-04-09 18:55:47 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TR_STATUS_DOWNLOAD:
|
|
|
|
case TR_STATUS_SEED:
|
2013-01-30 00:22:52 +00:00
|
|
|
str = tr("%1 %2 %3").arg(shortTransferString(tor))
|
|
|
|
.arg(tr("Ratio:"))
|
|
|
|
.arg(Formatter::ratioToString(tor.ratio()));
|
2009-04-09 18:55:47 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2010-04-06 02:34:45 +00:00
|
|
|
str = tor.activityString( );
|
2009-04-09 18:55:47 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString
|
|
|
|
TorrentDelegate :: statusString( const Torrent& tor ) const
|
|
|
|
{
|
|
|
|
QString str;
|
|
|
|
|
|
|
|
if( tor.hasError( ) )
|
|
|
|
{
|
|
|
|
str = tor.getError( );
|
|
|
|
}
|
|
|
|
else switch( tor.getActivity( ) )
|
|
|
|
{
|
|
|
|
case TR_STATUS_STOPPED:
|
|
|
|
case TR_STATUS_CHECK_WAIT:
|
|
|
|
case TR_STATUS_CHECK:
|
2011-08-08 16:38:22 +00:00
|
|
|
case TR_STATUS_DOWNLOAD_WAIT:
|
|
|
|
case TR_STATUS_SEED_WAIT:
|
2009-04-09 18:55:47 +00:00
|
|
|
str = shortStatusString( tor );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TR_STATUS_DOWNLOAD:
|
2012-10-07 17:51:56 +00:00
|
|
|
if( !tor.hasMetadata() ) {
|
2009-12-04 05:05:19 +00:00
|
|
|
str = tr( "Downloading metadata from %n peer(s) (%1% done)", 0, tor.peersWeAreDownloadingFrom( ) )
|
2010-07-03 01:10:36 +00:00
|
|
|
.arg( Formatter::percentToString( 100.0 * tor.metadataPercentDone( ) ) );
|
2012-10-07 17:51:56 +00:00
|
|
|
} else {
|
|
|
|
/* it would be nicer for translation if this was all one string, but I don't see how to do multiple %n's in tr() */
|
|
|
|
str = tr( "Downloading from %1 of %n connected peer(s)", 0, tor.connectedPeersAndWebseeds( ) )
|
|
|
|
.arg( tor.peersWeAreDownloadingFrom( ) );
|
|
|
|
if (tor.webseedsWeAreDownloadingFrom())
|
|
|
|
str += tr(" and %n web seed(s)", "", tor.webseedsWeAreDownloadingFrom());
|
|
|
|
}
|
2009-04-09 18:55:47 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TR_STATUS_SEED:
|
|
|
|
str = tr( "Seeding to %1 of %n connected peer(s)", 0, tor.connectedPeers( ) )
|
|
|
|
.arg( tor.peersWeAreUploadingTo( ) );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2011-08-20 05:19:27 +00:00
|
|
|
str = tr( "Error" );
|
2009-04-09 18:55:47 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-12-04 05:05:19 +00:00
|
|
|
if( tor.isReadyToTransfer( ) ) {
|
|
|
|
QString s = shortTransferString( tor );
|
|
|
|
if( !s.isEmpty( ) )
|
|
|
|
str += tr( " - " ) + s;
|
|
|
|
}
|
2009-04-09 18:55:47 +00:00
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
int MAX3( int a, int b, int c )
|
|
|
|
{
|
|
|
|
const int ab( a > b ? a : b );
|
|
|
|
return ab > c ? ab : c;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QSize
|
|
|
|
TorrentDelegate :: sizeHint( const QStyleOptionViewItem& option, const Torrent& tor ) const
|
|
|
|
{
|
|
|
|
const QStyle* style( QApplication::style( ) );
|
|
|
|
static const int iconSize( style->pixelMetric( QStyle::PM_MessageBoxIconSize ) );
|
|
|
|
|
|
|
|
QFont nameFont( option.font );
|
|
|
|
nameFont.setWeight( QFont::Bold );
|
|
|
|
const QFontMetrics nameFM( nameFont );
|
|
|
|
const QString nameStr( tor.name( ) );
|
2010-08-02 18:31:27 +00:00
|
|
|
const int nameWidth = nameFM.width( nameStr );
|
2009-04-09 18:55:47 +00:00
|
|
|
QFont statusFont( option.font );
|
|
|
|
statusFont.setPointSize( int( option.font.pointSize( ) * 0.9 ) );
|
|
|
|
const QFontMetrics statusFM( statusFont );
|
|
|
|
const QString statusStr( statusString( tor ) );
|
2010-08-02 18:31:27 +00:00
|
|
|
const int statusWidth = statusFM.width( statusStr );
|
2009-04-09 18:55:47 +00:00
|
|
|
QFont progressFont( statusFont );
|
|
|
|
const QFontMetrics progressFM( progressFont );
|
|
|
|
const QString progressStr( progressString( tor ) );
|
2010-08-02 18:31:27 +00:00
|
|
|
const int progressWidth = progressFM.width( progressStr );
|
2009-04-09 18:55:47 +00:00
|
|
|
const QSize m( margin( *style ) );
|
2010-08-02 18:31:27 +00:00
|
|
|
return QSize( m.width()*2 + iconSize + GUI_PAD + MAX3( nameWidth, statusWidth, progressWidth ),
|
2009-04-09 18:55:47 +00:00
|
|
|
//m.height()*3 + nameFM.lineSpacing() + statusFM.lineSpacing()*2 + progressFM.lineSpacing() );
|
|
|
|
m.height()*3 + nameFM.lineSpacing() + statusFM.lineSpacing() + BAR_HEIGHT + progressFM.lineSpacing() );
|
|
|
|
}
|
|
|
|
|
|
|
|
QSize
|
|
|
|
TorrentDelegate :: sizeHint( const QStyleOptionViewItem & option,
|
|
|
|
const QModelIndex & index ) const
|
|
|
|
{
|
2010-07-30 22:24:48 +00:00
|
|
|
const Torrent * tor( index.data( TorrentModel::TorrentRole ).value<const Torrent*>() );
|
2009-04-09 18:55:47 +00:00
|
|
|
return sizeHint( option, *tor );
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TorrentDelegate :: paint( QPainter * painter,
|
|
|
|
const QStyleOptionViewItem & option,
|
|
|
|
const QModelIndex & index) const
|
|
|
|
{
|
2010-07-30 22:24:48 +00:00
|
|
|
const Torrent * tor( index.data( TorrentModel::TorrentRole ).value<const Torrent*>() );
|
2009-04-09 18:55:47 +00:00
|
|
|
painter->save( );
|
|
|
|
painter->setClipRect( option.rect );
|
|
|
|
drawTorrent( painter, option, *tor );
|
|
|
|
painter->restore( );
|
|
|
|
}
|
|
|
|
|
2011-05-28 00:09:15 +00:00
|
|
|
void
|
|
|
|
TorrentDelegate :: setProgressBarPercentDone( const QStyleOptionViewItem& option, const Torrent& tor ) const
|
|
|
|
{
|
|
|
|
double seedRatioLimit;
|
|
|
|
if (tor.isSeeding() && tor.getSeedRatio(seedRatioLimit))
|
|
|
|
{
|
|
|
|
const double seedRateRatio = tor.ratio() / seedRatioLimit;
|
2012-03-04 13:15:43 +00:00
|
|
|
const int scaledProgress = seedRateRatio * (myProgressBarStyle->maximum - myProgressBarStyle->minimum);
|
2011-05-28 00:09:15 +00:00
|
|
|
myProgressBarStyle->progress = myProgressBarStyle->minimum + scaledProgress;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const bool isMagnet( !tor.hasMetadata( ) );
|
|
|
|
myProgressBarStyle->direction = option.direction;
|
|
|
|
myProgressBarStyle->progress = int(myProgressBarStyle->minimum + (((isMagnet ? tor.metadataPercentDone() : tor.percentDone()) * (myProgressBarStyle->maximum - myProgressBarStyle->minimum))));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-09 18:55:47 +00:00
|
|
|
void
|
|
|
|
TorrentDelegate :: drawTorrent( QPainter * painter, const QStyleOptionViewItem& option, const Torrent& tor ) const
|
|
|
|
{
|
|
|
|
const QStyle * style( QApplication::style( ) );
|
|
|
|
static const int iconSize( style->pixelMetric( QStyle::PM_LargeIconSize ) );
|
|
|
|
QFont nameFont( option.font );
|
|
|
|
nameFont.setWeight( QFont::Bold );
|
|
|
|
const QFontMetrics nameFM( nameFont );
|
|
|
|
const QString nameStr( tor.name( ) );
|
|
|
|
const QSize nameSize( nameFM.size( 0, nameStr ) );
|
|
|
|
QFont statusFont( option.font );
|
|
|
|
statusFont.setPointSize( int( option.font.pointSize( ) * 0.9 ) );
|
|
|
|
const QFontMetrics statusFM( statusFont );
|
|
|
|
const QString statusStr( progressString( tor ) );
|
|
|
|
QFont progressFont( statusFont );
|
|
|
|
const QFontMetrics progressFM( progressFont );
|
|
|
|
const QString progressStr( statusString( tor ) );
|
|
|
|
const bool isPaused( tor.isPaused( ) );
|
|
|
|
|
|
|
|
painter->save( );
|
|
|
|
|
|
|
|
if (option.state & QStyle::State_Selected) {
|
|
|
|
QPalette::ColorGroup cg = option.state & QStyle::State_Enabled
|
|
|
|
? QPalette::Normal : QPalette::Disabled;
|
|
|
|
if (cg == QPalette::Normal && !(option.state & QStyle::State_Active))
|
|
|
|
cg = QPalette::Inactive;
|
|
|
|
|
|
|
|
painter->fillRect(option.rect, option.palette.brush(cg, QPalette::Highlight));
|
|
|
|
}
|
|
|
|
|
|
|
|
QIcon::Mode im;
|
|
|
|
if( isPaused || !(option.state & QStyle::State_Enabled ) ) im = QIcon::Disabled;
|
|
|
|
else if( option.state & QStyle::State_Selected ) im = QIcon::Selected;
|
|
|
|
else im = QIcon::Normal;
|
|
|
|
|
|
|
|
QIcon::State qs;
|
|
|
|
if( isPaused ) qs = QIcon::Off;
|
|
|
|
else qs = QIcon::On;
|
|
|
|
|
|
|
|
QPalette::ColorGroup cg = QPalette::Normal;
|
|
|
|
if( isPaused || !(option.state & QStyle::State_Enabled ) ) cg = QPalette::Disabled;
|
|
|
|
if( cg == QPalette::Normal && !(option.state & QStyle::State_Active ) ) cg = QPalette::Inactive;
|
|
|
|
|
|
|
|
QPalette::ColorRole cr;
|
|
|
|
if( option.state & QStyle::State_Selected ) cr = QPalette::HighlightedText;
|
|
|
|
else cr = QPalette::Text;
|
|
|
|
|
2009-05-04 16:38:07 +00:00
|
|
|
QStyle::State progressBarState( option.state );
|
|
|
|
if( isPaused ) progressBarState = QStyle::State_None;
|
|
|
|
progressBarState |= QStyle::State_Small;
|
|
|
|
|
2009-04-09 18:55:47 +00:00
|
|
|
// layout
|
|
|
|
const QSize m( margin( *style ) );
|
|
|
|
QRect fillArea( option.rect );
|
|
|
|
fillArea.adjust( m.width(), m.height(), -m.width(), -m.height() );
|
|
|
|
QRect iconArea( fillArea.x( ), fillArea.y( ) + ( fillArea.height( ) - iconSize ) / 2, iconSize, iconSize );
|
|
|
|
QRect nameArea( iconArea.x( ) + iconArea.width( ) + GUI_PAD, fillArea.y( ),
|
|
|
|
fillArea.width( ) - GUI_PAD - iconArea.width( ), nameSize.height( ) );
|
|
|
|
QRect statusArea( nameArea );
|
|
|
|
statusArea.moveTop( nameArea.y( ) + nameFM.lineSpacing( ) );
|
|
|
|
statusArea.setHeight( nameSize.height( ) );
|
|
|
|
QRect barArea( statusArea );
|
|
|
|
barArea.setHeight( BAR_HEIGHT );
|
|
|
|
barArea.moveTop( statusArea.y( ) + statusFM.lineSpacing( ) );
|
|
|
|
QRect progArea( statusArea );
|
|
|
|
progArea.moveTop( barArea.y( ) + barArea.height( ) );
|
|
|
|
|
|
|
|
// render
|
|
|
|
if( tor.hasError( ) )
|
|
|
|
painter->setPen( QColor( "red" ) );
|
|
|
|
else
|
|
|
|
painter->setPen( option.palette.color( cg, cr ) );
|
|
|
|
tor.getMimeTypeIcon().paint( painter, iconArea, Qt::AlignCenter, im, qs );
|
|
|
|
painter->setFont( nameFont );
|
|
|
|
painter->drawText( nameArea, 0, nameFM.elidedText( nameStr, Qt::ElideRight, nameArea.width( ) ) );
|
|
|
|
painter->setFont( statusFont );
|
|
|
|
painter->drawText( statusArea, 0, statusFM.elidedText( statusStr, Qt::ElideRight, statusArea.width( ) ) );
|
|
|
|
painter->setFont( progressFont );
|
|
|
|
painter->drawText( progArea, 0, progressFM.elidedText( progressStr, Qt::ElideRight, progArea.width( ) ) );
|
|
|
|
myProgressBarStyle->rect = barArea;
|
2012-03-04 13:15:43 +00:00
|
|
|
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 );
|
|
|
|
}
|
2009-05-04 16:38:07 +00:00
|
|
|
myProgressBarStyle->state = progressBarState;
|
2011-05-28 00:09:15 +00:00
|
|
|
setProgressBarPercentDone( option, tor );
|
|
|
|
|
2009-04-09 18:55:47 +00:00
|
|
|
style->drawControl( QStyle::CE_ProgressBar, myProgressBarStyle, painter );
|
|
|
|
|
|
|
|
painter->restore( );
|
|
|
|
}
|