mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-22 20:44:15 +00:00
Cosmetic changes to the piece availability and downloaded pieces bars
This commit is contained in:
parent
6ae7db4afb
commit
35c1389794
@ -86,39 +86,9 @@ public:
|
|||||||
}
|
}
|
||||||
++scaled_index;
|
++scaled_index;
|
||||||
}
|
}
|
||||||
QPixmap pix = QPixmap(scaled_pieces.size(), 1);
|
updatePixmap(scaled_pieces, scaled_downloading);
|
||||||
//pix.fill();
|
|
||||||
QPainter painter(&pix);
|
|
||||||
for(uint i=0; i<scaled_pieces.size(); ++i) {
|
|
||||||
if(scaled_pieces[i]) {
|
|
||||||
painter.setPen(Qt::blue);
|
|
||||||
} else {
|
|
||||||
if(scaled_downloading[i]) {
|
|
||||||
painter.setPen(Qt::yellow);
|
|
||||||
} else {
|
|
||||||
painter.setPen(Qt::white);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
painter.drawPoint(i,0);
|
|
||||||
}
|
|
||||||
pixmap = pix;
|
|
||||||
} else {
|
} else {
|
||||||
QPixmap pix = QPixmap(pieces.size(), 1);
|
updatePixmap(pieces, downloading_pieces);
|
||||||
//pix.fill();
|
|
||||||
QPainter painter(&pix);
|
|
||||||
for(uint i=0; i<pieces.size(); ++i) {
|
|
||||||
if(pieces[i]) {
|
|
||||||
painter.setPen(Qt::blue);
|
|
||||||
} else {
|
|
||||||
if(downloading_pieces[i]) {
|
|
||||||
painter.setPen(Qt::yellow);
|
|
||||||
} else {
|
|
||||||
painter.setPen(Qt::white);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
painter.drawPoint(i,0);
|
|
||||||
}
|
|
||||||
pixmap = pix;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
update();
|
update();
|
||||||
@ -136,6 +106,26 @@ protected:
|
|||||||
painter.drawPixmap(rect(), pixmap);
|
painter.drawPixmap(rect(), pixmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
void updatePixmap(const libtorrent::bitfield &pieces, const libtorrent::bitfield &downloading_pieces) {
|
||||||
|
QPixmap pix = QPixmap(pieces.size(), 1);
|
||||||
|
//pix.fill();
|
||||||
|
QPainter painter(&pix);
|
||||||
|
for(uint i=0; i<pieces.size(); ++i) {
|
||||||
|
if(pieces[i]) {
|
||||||
|
painter.setPen(Qt::blue);
|
||||||
|
} else {
|
||||||
|
if(downloading_pieces[i]) {
|
||||||
|
painter.setPen(Qt::green);
|
||||||
|
} else {
|
||||||
|
painter.setPen(Qt::white);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
painter.drawPoint(i,0);
|
||||||
|
}
|
||||||
|
pixmap = pix;
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DOWNLOADEDPIECESBAR_H
|
#endif // DOWNLOADEDPIECESBAR_H
|
||||||
|
@ -36,7 +36,8 @@
|
|||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
#include <QColor>
|
#include <QColor>
|
||||||
#include <numeric>
|
#include <numeric>
|
||||||
#include <math.h>
|
#include <cmath>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
#define BAR_HEIGHT 18
|
#define BAR_HEIGHT 18
|
||||||
|
|
||||||
@ -53,52 +54,30 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void setAvailability(const std::vector<int>& avail) {
|
void setAvailability(const std::vector<int>& avail) {
|
||||||
qreal average = 0;
|
|
||||||
if(avail.empty()) {
|
if(avail.empty()) {
|
||||||
// Empty bar
|
// Empty bar
|
||||||
QPixmap pix = QPixmap(1, 1);
|
QPixmap pix = QPixmap(1, 1);
|
||||||
pix.fill();
|
pix.fill();
|
||||||
pixmap = pix;
|
pixmap = pix;
|
||||||
} else {
|
} 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
|
// Reduce the number of pieces before creating the pixmap
|
||||||
// otherwise it can crash when there are too many pieces
|
// otherwise it can crash when there are too many pieces
|
||||||
|
const qulonglong nb_pieces = avail.size();
|
||||||
const uint w = width();
|
const uint w = width();
|
||||||
if(nb_pieces > w) {
|
if(nb_pieces > w) {
|
||||||
const qulonglong ratio = floor(nb_pieces/(double)w);
|
const qulonglong ratio = floor(nb_pieces/(double)w);
|
||||||
std::vector<int> scaled_avail;
|
std::vector<int> scaled_avail;
|
||||||
scaled_avail.reserve(ceil(nb_pieces/(double)ratio));
|
scaled_avail.reserve(ceil(nb_pieces/(double)ratio));
|
||||||
for(qulonglong i=0; i<nb_pieces; i+= ratio) {
|
for(qulonglong i=0; i<nb_pieces; i+= ratio) {
|
||||||
/*qulonglong j = i;
|
|
||||||
qulonglong sum = avail[i];
|
|
||||||
for(j=i+1; j<qMin(i+ratio, nb_pieces); ++j) {
|
|
||||||
sum += avail[j];
|
|
||||||
}
|
|
||||||
scaled_avail.push_back(sum/(qMin(ratio, nb_pieces-i)));*/
|
|
||||||
// XXX: Do not compute the average to save cpu
|
// XXX: Do not compute the average to save cpu
|
||||||
scaled_avail.push_back(avail[i]);
|
scaled_avail.push_back(avail[i]);
|
||||||
}
|
}
|
||||||
QPixmap pix = QPixmap(scaled_avail.size(), 1);
|
updatePixmap(scaled_avail);
|
||||||
//pix.fill();
|
|
||||||
QPainter painter(&pix);
|
|
||||||
for(qulonglong i=0; i < scaled_avail.size(); ++i) {
|
|
||||||
painter.setPen(getPieceColor(scaled_avail[i], average));
|
|
||||||
painter.drawPoint(i,0);
|
|
||||||
}
|
|
||||||
pixmap = pix;
|
|
||||||
} else {
|
} else {
|
||||||
QPixmap pix = QPixmap(nb_pieces, 1);
|
updatePixmap(avail);
|
||||||
//pix.fill();
|
|
||||||
QPainter painter(&pix);
|
|
||||||
for(qulonglong i=0; i < nb_pieces; ++i) {
|
|
||||||
painter.setPen(getPieceColor(avail[i], average));
|
|
||||||
painter.drawPoint(i,0);
|
|
||||||
}
|
|
||||||
pixmap = pix;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,15 +93,24 @@ protected:
|
|||||||
painter.drawPixmap(rect(), pixmap);
|
painter.drawPixmap(rect(), pixmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
QColor getPieceColor(int avail, qreal average) {
|
private:
|
||||||
if(!avail) return Qt::white;
|
void updatePixmap(const std::vector<int> avail) {
|
||||||
//qDebug("avail: %d/%d", avail, max_avail);
|
const int max = *std::max_element(avail.begin(), avail.end());
|
||||||
qreal fraction = 100.*average/avail;
|
if(max == 0) {
|
||||||
if(fraction < 100)
|
QPixmap pix = QPixmap(1, 1);
|
||||||
fraction *= 0.8;
|
pix.fill();
|
||||||
else
|
pixmap = pix;
|
||||||
fraction *= 1.2;
|
return;
|
||||||
return QColor(Qt::blue).lighter(fraction);
|
}
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user