(trunk, GTK+/Qt) #4281 "Visualize seed progress like the web client does" -- done, with a modified patch & suggestion from mag
This commit is contained in:
parent
d6e39e4d2f
commit
c1d5b4a7e6
|
@ -538,6 +538,25 @@ get_text_color( GtkWidget * w, const tr_stat * st, GdkColor * setme )
|
|||
*setme = gtk_widget_get_style(w)->text[GTK_STATE_NORMAL];
|
||||
}
|
||||
|
||||
static double
|
||||
get_percent_done( const tr_torrent * tor, const tr_stat * st, bool * seed )
|
||||
{
|
||||
double d;
|
||||
|
||||
if( ( st->activity == TR_STATUS_SEED ) && tr_torrentGetSeedRatio( tor, &d ) )
|
||||
{
|
||||
*seed = true;
|
||||
d = MAX( 0.0, st->seedRatioPercentDone );
|
||||
}
|
||||
else
|
||||
{
|
||||
*seed = false;
|
||||
d = MAX( 0.0, st->percentDone );
|
||||
}
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
static void
|
||||
render_compact( TorrentCellRenderer * cell,
|
||||
GdkDrawable * window,
|
||||
|
@ -556,12 +575,13 @@ render_compact( TorrentCellRenderer * cell,
|
|||
const char * name;
|
||||
GdkPixbuf * icon;
|
||||
GdkColor text_color;
|
||||
bool seed;
|
||||
|
||||
struct TorrentCellRendererPrivate * p = cell->priv;
|
||||
const tr_torrent * tor = p->tor;
|
||||
const tr_stat * st = tr_torrentStatCached( (tr_torrent*)tor );
|
||||
const gboolean active = st->activity != TR_STATUS_STOPPED;
|
||||
const double percentDone = MAX( 0.0, st->percentDone );
|
||||
const double percentDone = get_percent_done( tor, st, &seed );
|
||||
const gboolean sensitive = active || st->error;
|
||||
GString * gstr_stat = p->gstr1;
|
||||
|
||||
|
@ -600,7 +620,13 @@ render_compact( TorrentCellRenderer * cell,
|
|||
|
||||
g_object_set( p->icon_renderer, "pixbuf", icon, "sensitive", sensitive, NULL );
|
||||
gtk_cell_renderer_render( p->icon_renderer, window, widget, &icon_area, &icon_area, &icon_area, flags );
|
||||
g_object_set( p->progress_renderer, "value", (int)(percentDone*100.0), "text", NULL, "sensitive", sensitive, NULL );
|
||||
g_object_set( p->progress_renderer, "value", (int)(percentDone*100.0), "text", NULL, "sensitive", sensitive,
|
||||
#if GTK_CHECK_VERSION( 3,0,0 )
|
||||
"inverted", seed,
|
||||
#elif GTK_CHECK_VERSION( 2,6,0 )
|
||||
"orientation", (seed ? GTK_PROGRESS_RIGHT_TO_LEFT : GTK_PROGRESS_LEFT_TO_RIGHT),
|
||||
#endif
|
||||
NULL );
|
||||
gtk_cell_renderer_render( p->progress_renderer, window, widget, &prog_area, &prog_area, &prog_area, flags );
|
||||
g_object_set( p->text_renderer, "text", gstr_stat->str, "scale", SMALL_SCALE, "ellipsize", PANGO_ELLIPSIZE_END, "foreground-gdk", &text_color, NULL );
|
||||
gtk_cell_renderer_render( p->text_renderer, window, widget, &stat_area, &stat_area, &stat_area, flags );
|
||||
|
@ -631,13 +657,14 @@ render_full( TorrentCellRenderer * cell,
|
|||
const char * name;
|
||||
GdkPixbuf * icon;
|
||||
GdkColor text_color;
|
||||
bool seed;
|
||||
|
||||
struct TorrentCellRendererPrivate * p = cell->priv;
|
||||
const tr_torrent * tor = p->tor;
|
||||
const tr_stat * st = tr_torrentStatCached( (tr_torrent*)tor );
|
||||
const tr_info * inf = tr_torrentInfo( tor );
|
||||
const gboolean active = st->activity != TR_STATUS_STOPPED;
|
||||
const double percentDone = MAX( 0.0, st->percentDone );
|
||||
const double percentDone = get_percent_done( tor, st, &seed );
|
||||
const gboolean sensitive = active || st->error;
|
||||
GString * gstr_prog = p->gstr1;
|
||||
GString * gstr_stat = p->gstr2;
|
||||
|
@ -714,7 +741,13 @@ render_full( TorrentCellRenderer * cell,
|
|||
gtk_cell_renderer_render( p->text_renderer, window, widget, &name_area, &name_area, &name_area, flags );
|
||||
g_object_set( p->text_renderer, "text", gstr_prog->str, "scale", SMALL_SCALE, "weight", PANGO_WEIGHT_NORMAL, NULL );
|
||||
gtk_cell_renderer_render( p->text_renderer, window, widget, &prog_area, &prog_area, &prog_area, flags );
|
||||
g_object_set( p->progress_renderer, "value", (int)(percentDone*100.0), "text", "", "sensitive", sensitive, NULL );
|
||||
g_object_set( p->progress_renderer, "value", (int)(percentDone*100.0), "text", "", "sensitive", sensitive,
|
||||
#if GTK_CHECK_VERSION( 3,0,0 )
|
||||
"inverted", seed,
|
||||
#elif GTK_CHECK_VERSION( 2,6,0 )
|
||||
"orientation", (seed ? GTK_PROGRESS_RIGHT_TO_LEFT : GTK_PROGRESS_LEFT_TO_RIGHT),
|
||||
#endif
|
||||
NULL );
|
||||
gtk_cell_renderer_render( p->progress_renderer, window, widget, &prct_area, &prct_area, &prct_area, flags );
|
||||
g_object_set( p->text_renderer, "text", gstr_stat->str, NULL );
|
||||
gtk_cell_renderer_render( p->text_renderer, window, widget, &stat_area, &stat_area, &stat_area, flags );
|
||||
|
|
|
@ -162,7 +162,7 @@ TorrentDelegateMin :: drawTorrent( QPainter * painter, const QStyleOptionViewIte
|
|||
tr_snprintf( buf, sizeof( buf ), "%d%%", (int)tr_truncd( 100.0 * tor.percentDone( ), 0 ) );
|
||||
myProgressBarStyle->text = buf;
|
||||
myProgressBarStyle->textVisible = true;
|
||||
myProgressBarStyle->progress = int(myProgressBarStyle->minimum + (((isMagnet ? tor.metadataPercentDone() : tor.percentDone()) * (myProgressBarStyle->maximum - myProgressBarStyle->minimum))));
|
||||
setProgressBarPercentDone( option, tor );
|
||||
style->drawControl( QStyle::CE_ProgressBar, myProgressBarStyle, painter );
|
||||
|
||||
painter->restore( );
|
||||
|
|
|
@ -316,6 +316,26 @@ TorrentDelegate :: paint( QPainter * painter,
|
|||
painter->restore( );
|
||||
}
|
||||
|
||||
void
|
||||
TorrentDelegate :: setProgressBarPercentDone( const QStyleOptionViewItem& option, const Torrent& tor ) const
|
||||
{
|
||||
double seedRatioLimit;
|
||||
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);
|
||||
myProgressBarStyle->progress = myProgressBarStyle->minimum + scaledProgress;
|
||||
myProgressBarStyle->direction = (option.direction == Qt::RightToLeft ? Qt::LeftToRight : Qt::RightToLeft);
|
||||
}
|
||||
else
|
||||
{
|
||||
const bool isMagnet( !tor.hasMetadata( ) );
|
||||
myProgressBarStyle->direction = option.direction;
|
||||
myProgressBarStyle->progress = int(myProgressBarStyle->minimum + (((isMagnet ? tor.metadataPercentDone() : tor.percentDone()) * (myProgressBarStyle->maximum - myProgressBarStyle->minimum))));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
TorrentDelegate :: drawTorrent( QPainter * painter, const QStyleOptionViewItem& option, const Torrent& tor ) const
|
||||
{
|
||||
|
@ -395,13 +415,12 @@ TorrentDelegate :: drawTorrent( QPainter * painter, const QStyleOptionViewItem&
|
|||
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( ) ) );
|
||||
const bool isMagnet( !tor.hasMetadata( ) );
|
||||
myProgressBarStyle->rect = barArea;
|
||||
myProgressBarStyle->direction = option.direction;
|
||||
myProgressBarStyle->palette = option.palette;
|
||||
myProgressBarStyle->palette.setCurrentColorGroup( cg );
|
||||
myProgressBarStyle->state = progressBarState;
|
||||
myProgressBarStyle->progress = int(myProgressBarStyle->minimum + (((isMagnet ? tor.metadataPercentDone() : tor.percentDone()) * (myProgressBarStyle->maximum - myProgressBarStyle->minimum))));
|
||||
setProgressBarPercentDone( option, tor );
|
||||
|
||||
style->drawControl( QStyle::CE_ProgressBar, myProgressBarStyle, painter );
|
||||
|
||||
painter->restore( );
|
||||
|
|
|
@ -38,6 +38,7 @@ class TorrentDelegate: public QItemDelegate
|
|||
protected:
|
||||
QSize margin( const QStyle& style ) const;
|
||||
virtual QSize sizeHint( const QStyleOptionViewItem&, const Torrent& ) const;
|
||||
virtual void setProgressBarPercentDone( const QStyleOptionViewItem& option, const Torrent& ) const;
|
||||
virtual void drawTorrent( QPainter* painter, const QStyleOptionViewItem& option, const Torrent& ) const;
|
||||
|
||||
public:
|
||||
|
|
Loading…
Reference in New Issue