Refresh pieces bar colors once color scheme is changed

PR #21183.
Closes #21155.
This commit is contained in:
Vladimir Golovnev
2024-08-13 09:11:21 +03:00
committed by Vladimir Golovnev (Glassez)
parent a8cffbb205
commit a67bd271c6
6 changed files with 86 additions and 55 deletions

View File

@@ -1,5 +1,6 @@
/*
* Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2024 Vladimir Golovnev <glassez@yandex.ru>
* Copyright (C) 2006 Christophe Dumez <chris@qbittorrent.org>
*
* This program is free software; you can redistribute it and/or
@@ -126,39 +127,38 @@ QVector<float> PieceAvailabilityBar::intToFloatVector(const QVector<int> &vecin,
return result;
}
bool PieceAvailabilityBar::updateImage(QImage &image)
QImage PieceAvailabilityBar::renderImage()
{
QImage image2(width() - 2 * borderWidth, 1, QImage::Format_RGB888);
if (image2.isNull())
QImage image {width() - 2 * borderWidth, 1, QImage::Format_RGB888};
if (image.isNull())
{
qDebug() << "QImage image2() allocation failed, width():" << width();
return false;
qDebug() << "QImage allocation failed, width():" << width();
return image;
}
if (m_pieces.empty())
{
image2.fill(backgroundColor());
image = image2;
return true;
image.fill(backgroundColor());
return image;
}
QVector<float> scaledPieces = intToFloatVector(m_pieces, image2.width());
QVector<float> scaledPieces = intToFloatVector(m_pieces, image.width());
// filling image
for (int x = 0; x < scaledPieces.size(); ++x)
{
float piecesToValue = scaledPieces.at(x);
image2.setPixel(x, 0, pieceColors()[piecesToValue * 255]);
image.setPixel(x, 0, pieceColors()[piecesToValue * 255]);
}
image = image2;
return true;
return image;
}
void PieceAvailabilityBar::setAvailability(const QVector<int> &avail)
{
m_pieces = avail;
requestImageUpdate();
redraw();
}
void PieceAvailabilityBar::clear()