diff --git a/src/properties/downloadedpiecesbar.h b/src/properties/downloadedpiecesbar.h index ff3b54fea..8bb2bbf8d 100644 --- a/src/properties/downloadedpiecesbar.h +++ b/src/properties/downloadedpiecesbar.h @@ -86,39 +86,9 @@ public: } ++scaled_index; } - QPixmap pix = QPixmap(scaled_pieces.size(), 1); - //pix.fill(); - QPainter painter(&pix); - for(uint i=0; i #include #include -#include +#include +#include #define BAR_HEIGHT 18 @@ -53,52 +54,30 @@ public: } void setAvailability(const std::vector& avail) { - qreal average = 0; if(avail.empty()) { // Empty bar QPixmap pix = QPixmap(1, 1); pix.fill(); pixmap = pix; } else { - // Look for maximum value - const qulonglong nb_pieces = avail.size(); - average = std::accumulate(avail.begin(), avail.end(), 0)/(double)nb_pieces; // Reduce the number of pieces before creating the pixmap // otherwise it can crash when there are too many pieces + const qulonglong nb_pieces = avail.size(); const uint w = width(); if(nb_pieces > w) { const qulonglong ratio = floor(nb_pieces/(double)w); std::vector scaled_avail; scaled_avail.reserve(ceil(nb_pieces/(double)ratio)); for(qulonglong i=0; i avail) { + const int max = *std::max_element(avail.begin(), avail.end()); + if(max == 0) { + QPixmap pix = QPixmap(1, 1); + pix.fill(); + pixmap = pix; + return; + } + QPixmap pix = QPixmap(avail.size(), 1); + //pix.fill(); + QPainter painter(&pix); + for(uint i=0; i < avail.size(); ++i) { + const uint rg = 0xff - (0xff * avail[i]/max); + painter.setPen(QColor(rg, rg, 0xff)); + painter.drawPoint(i,0); + } + pixmap = pix; } };