Changeset 12464
- Timestamp:
- May 28, 2011, 12:09:15 AM (10 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gtk/torrent-cell-renderer.c
r12412 r12464 539 539 } 540 540 541 static double 542 get_percent_done( const tr_torrent * tor, const tr_stat * st, bool * seed ) 543 { 544 double d; 545 546 if( ( st->activity == TR_STATUS_SEED ) && tr_torrentGetSeedRatio( tor, &d ) ) 547 { 548 *seed = true; 549 d = MAX( 0.0, st->seedRatioPercentDone ); 550 } 551 else 552 { 553 *seed = false; 554 d = MAX( 0.0, st->percentDone ); 555 } 556 557 return d; 558 } 559 541 560 static void 542 561 render_compact( TorrentCellRenderer * cell, … … 557 576 GdkPixbuf * icon; 558 577 GdkColor text_color; 578 bool seed; 559 579 560 580 struct TorrentCellRendererPrivate * p = cell->priv; … … 562 582 const tr_stat * st = tr_torrentStatCached( (tr_torrent*)tor ); 563 583 const gboolean active = st->activity != TR_STATUS_STOPPED; 564 const double percentDone = MAX( 0.0, st->percentDone);584 const double percentDone = get_percent_done( tor, st, &seed ); 565 585 const gboolean sensitive = active || st->error; 566 586 GString * gstr_stat = p->gstr1; … … 601 621 g_object_set( p->icon_renderer, "pixbuf", icon, "sensitive", sensitive, NULL ); 602 622 gtk_cell_renderer_render( p->icon_renderer, window, widget, &icon_area, &icon_area, &icon_area, flags ); 603 g_object_set( p->progress_renderer, "value", (int)(percentDone*100.0), "text", NULL, "sensitive", sensitive, NULL ); 623 g_object_set( p->progress_renderer, "value", (int)(percentDone*100.0), "text", NULL, "sensitive", sensitive, 624 #if GTK_CHECK_VERSION( 3,0,0 ) 625 "inverted", seed, 626 #elif GTK_CHECK_VERSION( 2,6,0 ) 627 "orientation", (seed ? GTK_PROGRESS_RIGHT_TO_LEFT : GTK_PROGRESS_LEFT_TO_RIGHT), 628 #endif 629 NULL ); 604 630 gtk_cell_renderer_render( p->progress_renderer, window, widget, &prog_area, &prog_area, &prog_area, flags ); 605 631 g_object_set( p->text_renderer, "text", gstr_stat->str, "scale", SMALL_SCALE, "ellipsize", PANGO_ELLIPSIZE_END, "foreground-gdk", &text_color, NULL ); … … 632 658 GdkPixbuf * icon; 633 659 GdkColor text_color; 660 bool seed; 634 661 635 662 struct TorrentCellRendererPrivate * p = cell->priv; … … 638 665 const tr_info * inf = tr_torrentInfo( tor ); 639 666 const gboolean active = st->activity != TR_STATUS_STOPPED; 640 const double percentDone = MAX( 0.0, st->percentDone);667 const double percentDone = get_percent_done( tor, st, &seed ); 641 668 const gboolean sensitive = active || st->error; 642 669 GString * gstr_prog = p->gstr1; … … 715 742 g_object_set( p->text_renderer, "text", gstr_prog->str, "scale", SMALL_SCALE, "weight", PANGO_WEIGHT_NORMAL, NULL ); 716 743 gtk_cell_renderer_render( p->text_renderer, window, widget, &prog_area, &prog_area, &prog_area, flags ); 717 g_object_set( p->progress_renderer, "value", (int)(percentDone*100.0), "text", "", "sensitive", sensitive, NULL ); 744 g_object_set( p->progress_renderer, "value", (int)(percentDone*100.0), "text", "", "sensitive", sensitive, 745 #if GTK_CHECK_VERSION( 3,0,0 ) 746 "inverted", seed, 747 #elif GTK_CHECK_VERSION( 2,6,0 ) 748 "orientation", (seed ? GTK_PROGRESS_RIGHT_TO_LEFT : GTK_PROGRESS_LEFT_TO_RIGHT), 749 #endif 750 NULL ); 718 751 gtk_cell_renderer_render( p->progress_renderer, window, widget, &prct_area, &prct_area, &prct_area, flags ); 719 752 g_object_set( p->text_renderer, "text", gstr_stat->str, NULL ); -
trunk/qt/torrent-delegate-min.cc
r11097 r12464 163 163 myProgressBarStyle->text = buf; 164 164 myProgressBarStyle->textVisible = true; 165 myProgressBarStyle->progress = int(myProgressBarStyle->minimum + (((isMagnet ? tor.metadataPercentDone() : tor.percentDone()) * (myProgressBarStyle->maximum - myProgressBarStyle->minimum))));165 setProgressBarPercentDone( option, tor ); 166 166 style->drawControl( QStyle::CE_ProgressBar, myProgressBarStyle, painter ); 167 167 -
trunk/qt/torrent-delegate.cc
r11198 r12464 318 318 319 319 void 320 TorrentDelegate :: setProgressBarPercentDone( const QStyleOptionViewItem& option, const Torrent& tor ) const 321 { 322 double seedRatioLimit; 323 if (tor.isSeeding() && tor.getSeedRatio(seedRatioLimit)) 324 { 325 const double seedRateRatio = tor.ratio() / seedRatioLimit; 326 const double invertedRatio = 1. - seedRateRatio; 327 const int scaledProgress = invertedRatio * (myProgressBarStyle->maximum - myProgressBarStyle->minimum); 328 myProgressBarStyle->progress = myProgressBarStyle->minimum + scaledProgress; 329 myProgressBarStyle->direction = (option.direction == Qt::RightToLeft ? Qt::LeftToRight : Qt::RightToLeft); 330 } 331 else 332 { 333 const bool isMagnet( !tor.hasMetadata( ) ); 334 myProgressBarStyle->direction = option.direction; 335 myProgressBarStyle->progress = int(myProgressBarStyle->minimum + (((isMagnet ? tor.metadataPercentDone() : tor.percentDone()) * (myProgressBarStyle->maximum - myProgressBarStyle->minimum)))); 336 } 337 } 338 339 void 320 340 TorrentDelegate :: drawTorrent( QPainter * painter, const QStyleOptionViewItem& option, const Torrent& tor ) const 321 341 { … … 396 416 painter->setFont( progressFont ); 397 417 painter->drawText( progArea, 0, progressFM.elidedText( progressStr, Qt::ElideRight, progArea.width( ) ) ); 398 const bool isMagnet( !tor.hasMetadata( ) );399 418 myProgressBarStyle->rect = barArea; 400 myProgressBarStyle->direction = option.direction;401 419 myProgressBarStyle->palette = option.palette; 402 420 myProgressBarStyle->palette.setCurrentColorGroup( cg ); 403 421 myProgressBarStyle->state = progressBarState; 404 myProgressBarStyle->progress = int(myProgressBarStyle->minimum + (((isMagnet ? tor.metadataPercentDone() : tor.percentDone()) * (myProgressBarStyle->maximum - myProgressBarStyle->minimum)))); 422 setProgressBarPercentDone( option, tor ); 423 405 424 style->drawControl( QStyle::CE_ProgressBar, myProgressBarStyle, painter ); 406 425 -
trunk/qt/torrent-delegate.h
r11092 r12464 39 39 QSize margin( const QStyle& style ) const; 40 40 virtual QSize sizeHint( const QStyleOptionViewItem&, const Torrent& ) const; 41 virtual void setProgressBarPercentDone( const QStyleOptionViewItem& option, const Torrent& ) const; 41 42 virtual void drawTorrent( QPainter* painter, const QStyleOptionViewItem& option, const Torrent& ) const; 42 43
Note: See TracChangeset
for help on using the changeset viewer.