41 const QColor green {Qt::green};
42 return QColor::fromHsl(green.hslHue(), pieceColor.hslSaturation(), pieceColor.lightness());
54 QVector<float> result(reqSize, 0.0);
55 if (vecin.isEmpty())
return result;
57 const float ratio = vecin.size() /
static_cast<float>(reqSize);
64 for (
int x = 0; x < reqSize; ++x)
67 const float fromR = x * ratio;
68 const float toR = (x + 1) * ratio;
72 int toC = std::ceil(toR);
73 if (toC > vecin.size())
80 const int toCMinusOne = toC - 1;
86 if (x2 == toCMinusOne)
99 value += 1.0 - (fromR - fromC);
104 for (; x2 < toCMinusOne; ++x2)
109 if (x2 == toCMinusOne)
112 value += 1.0 - (toC - toR);
132 QImage image2(width() - 2 *
borderWidth, 1, QImage::Format_RGB888);
135 qDebug() <<
"QImage image2() allocation failed, width():" << width();
150 for (
int x = 0; x < scaledPieces.size(); ++x)
152 float piecesToValue = scaledPieces.at(x);
153 float piecesToValueDl = scaledPiecesDl.at(x);
154 if (piecesToValueDl != 0)
156 float fillRatio = piecesToValue + piecesToValueDl;
157 float ratio = piecesToValueDl / fillRatio;
162 image2.setPixel(x, 0, mixedColor);
166 image2.setPixel(x, 0,
pieceColors()[piecesToValue * 255]);
191 const QString rowHTML = QString::fromLatin1(
"<tr><td width=20 bgcolor='%1' style='border: 1px solid \"%2\";'></td><td>%3</td></tr>");
192 return QLatin1String(
"<table cellspacing=4>")
196 + QLatin1String(
"</table>");
DownloadedPiecesBar(QWidget *parent)
QVector< float > bitfieldToFloatVector(const QBitArray &vecin, int reqSize)
QBitArray m_downloadedPieces
QString simpleToolTipText() const override
const QColor m_dlPieceColor
virtual bool updateImage(QImage &image) override
void setProgress(const QBitArray &pieces, const QBitArray &downloadedPieces)
static QRgb mixTwoColors(QRgb rgb1, QRgb rgb2, float ratio)
QColor colorBoxBorderColor() const
QColor pieceColor() const
QColor backgroundColor() const
void requestImageUpdate()
static constexpr int borderWidth
const QVector< QRgb > & pieceColors() const
QColor borderColor() const
QColor dlPieceColor(const QColor &pieceColor)
T value(const QString &key, const T &defaultValue={})