mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2026-01-01 05:08:05 -06:00
Refresh pieces bar colors once color scheme is changed
PR #21183. Closes #21155.
This commit is contained in:
committed by
Vladimir Golovnev (Glassez)
parent
a8cffbb205
commit
a67bd271c6
@@ -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
|
||||
@@ -46,9 +47,9 @@ namespace
|
||||
}
|
||||
|
||||
DownloadedPiecesBar::DownloadedPiecesBar(QWidget *parent)
|
||||
: base {parent}
|
||||
, m_dlPieceColor {dlPieceColor(pieceColor())}
|
||||
: base(parent)
|
||||
{
|
||||
updateColorsImpl();
|
||||
}
|
||||
|
||||
QVector<float> DownloadedPiecesBar::bitfieldToFloatVector(const QBitArray &vecin, int reqSize)
|
||||
@@ -128,25 +129,24 @@ QVector<float> DownloadedPiecesBar::bitfieldToFloatVector(const QBitArray &vecin
|
||||
return result;
|
||||
}
|
||||
|
||||
bool DownloadedPiecesBar::updateImage(QImage &image)
|
||||
QImage DownloadedPiecesBar::renderImage()
|
||||
{
|
||||
// qDebug() << "updateImage";
|
||||
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.isEmpty())
|
||||
{
|
||||
image2.fill(backgroundColor());
|
||||
image = image2;
|
||||
return true;
|
||||
image.fill(backgroundColor());
|
||||
return image;
|
||||
}
|
||||
|
||||
QVector<float> scaledPieces = bitfieldToFloatVector(m_pieces, image2.width());
|
||||
QVector<float> scaledPiecesDl = bitfieldToFloatVector(m_downloadedPieces, image2.width());
|
||||
QVector<float> scaledPieces = bitfieldToFloatVector(m_pieces, image.width());
|
||||
QVector<float> scaledPiecesDl = bitfieldToFloatVector(m_downloadedPieces, image.width());
|
||||
|
||||
// filling image
|
||||
for (int x = 0; x < scaledPieces.size(); ++x)
|
||||
@@ -161,15 +161,15 @@ bool DownloadedPiecesBar::updateImage(QImage &image)
|
||||
QRgb mixedColor = mixTwoColors(pieceColor().rgb(), m_dlPieceColor.rgb(), ratio);
|
||||
mixedColor = mixTwoColors(backgroundColor().rgb(), mixedColor, fillRatio);
|
||||
|
||||
image2.setPixel(x, 0, mixedColor);
|
||||
image.setPixel(x, 0, mixedColor);
|
||||
}
|
||||
else
|
||||
{
|
||||
image2.setPixel(x, 0, pieceColors()[piecesToValue * 255]);
|
||||
image.setPixel(x, 0, pieceColors()[piecesToValue * 255]);
|
||||
}
|
||||
}
|
||||
image = image2;
|
||||
return true;
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
void DownloadedPiecesBar::setProgress(const QBitArray &pieces, const QBitArray &downloadedPieces)
|
||||
@@ -177,7 +177,7 @@ void DownloadedPiecesBar::setProgress(const QBitArray &pieces, const QBitArray &
|
||||
m_pieces = pieces;
|
||||
m_downloadedPieces = downloadedPieces;
|
||||
|
||||
requestImageUpdate();
|
||||
redraw();
|
||||
}
|
||||
|
||||
void DownloadedPiecesBar::clear()
|
||||
@@ -198,3 +198,14 @@ QString DownloadedPiecesBar::simpleToolTipText() const
|
||||
+ u"</table>";
|
||||
|
||||
}
|
||||
|
||||
void DownloadedPiecesBar::updateColors()
|
||||
{
|
||||
PiecesBar::updateColors();
|
||||
updateColorsImpl();
|
||||
}
|
||||
|
||||
void DownloadedPiecesBar::updateColorsImpl()
|
||||
{
|
||||
m_dlPieceColor = dlPieceColor(pieceColor());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user