]> granicus.if.org Git - transmission/commitdiff
(trunk qt) #4389 "share ratio progressbar indication counter-intuitive" -- apply...
authorJordan Lee <jordan@transmissionbt.com>
Sun, 4 Mar 2012 13:15:43 +0000 (13:15 +0000)
committerJordan Lee <jordan@transmissionbt.com>
Sun, 4 Mar 2012 13:15:43 +0000 (13:15 +0000)
qt/torrent-delegate-min.cc
qt/torrent-delegate.cc
qt/torrent-delegate.h

index 7cd2c8a2a9d4777ea76b26c86ee41cac2e396ae1..a6e21e844ac9b405d6b111ff15e7e6ef428c39ef 100644 (file)
@@ -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 ) );
index 4d11ffcd08a1d2332f46c4b8198ba0a401aa03fb..f7b7d7630c093ea1572c466d220010147e87be10 100644 (file)
@@ -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 );
 
index 77a42038e5e3f7f3f7f1faf099502601d3010583..d428951f51221671bd6dd51d09db118914f3e6b9 100644 (file)
@@ -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