mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-25 22:14:32 +00:00
Use palette colors in pieces bars
This commit is contained in:
parent
eb32bdab34
commit
d73757bf6e
@ -120,7 +120,7 @@ bool DownloadedPiecesBar::updateImage(QImage &image)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (m_pieces.isEmpty()) {
|
if (m_pieces.isEmpty()) {
|
||||||
image2.fill(Qt::white);
|
image2.fill(backgroundColor());
|
||||||
image = image2;
|
image = image2;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -157,12 +157,6 @@ void DownloadedPiecesBar::setProgress(const QBitArray &pieces, const QBitArray &
|
|||||||
requestImageUpdate();
|
requestImageUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DownloadedPiecesBar::setColors(const QColor &background, const QColor &border, const QColor &complete, const QColor &incomplete)
|
|
||||||
{
|
|
||||||
m_dlPieceColor = incomplete;
|
|
||||||
base::setColors(background, border, complete);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DownloadedPiecesBar::clear()
|
void DownloadedPiecesBar::clear()
|
||||||
{
|
{
|
||||||
m_pieces.clear();
|
m_pieces.clear();
|
||||||
@ -172,7 +166,11 @@ void DownloadedPiecesBar::clear()
|
|||||||
|
|
||||||
QString DownloadedPiecesBar::simpleToolTipText() const
|
QString DownloadedPiecesBar::simpleToolTipText() const
|
||||||
{
|
{
|
||||||
return tr("White: Missing pieces") + '\n'
|
const QString borderColor = colorBoxBorderColor().name();
|
||||||
+ tr("Green: Partial pieces") + '\n'
|
const QString rowHTML = QString::fromLatin1("<tr><td width=20 bgcolor='%1' style='border: 1px solid \"%2\";'></td><td>%3</td></tr>");
|
||||||
+ tr("Blue: Completed pieces") + '\n';
|
return QLatin1String("<table cellspacing=4>")
|
||||||
|
+ rowHTML.arg(backgroundColor().name(), borderColor, tr("Missing pieces"))
|
||||||
|
+ rowHTML.arg(m_dlPieceColor.name(), borderColor, tr("Partial pieces"))
|
||||||
|
+ rowHTML.arg(pieceColor().name(), borderColor, tr("Completed pieces"))
|
||||||
|
+ QLatin1String("</table>");
|
||||||
}
|
}
|
||||||
|
@ -47,8 +47,6 @@ public:
|
|||||||
|
|
||||||
void setProgress(const QBitArray &pieces, const QBitArray &downloadedPieces);
|
void setProgress(const QBitArray &pieces, const QBitArray &downloadedPieces);
|
||||||
|
|
||||||
void setColors(const QColor &background, const QColor &border, const QColor &complete, const QColor &incomplete);
|
|
||||||
|
|
||||||
// PiecesBar interface
|
// PiecesBar interface
|
||||||
void clear() override;
|
void clear() override;
|
||||||
|
|
||||||
|
@ -127,7 +127,7 @@ bool PieceAvailabilityBar::updateImage(QImage &image)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (m_pieces.empty()) {
|
if (m_pieces.empty()) {
|
||||||
image2.fill(Qt::white);
|
image2.fill(backgroundColor());
|
||||||
image = image2;
|
image = image2;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -158,6 +158,10 @@ void PieceAvailabilityBar::clear()
|
|||||||
|
|
||||||
QString PieceAvailabilityBar::simpleToolTipText() const
|
QString PieceAvailabilityBar::simpleToolTipText() const
|
||||||
{
|
{
|
||||||
return tr("White: Unavailable pieces") + '\n'
|
const QString borderColor = colorBoxBorderColor().name();
|
||||||
+ tr("Blue: Available pieces") + '\n';
|
const QString rowHTML = QString::fromLatin1("<tr><td width=20 bgcolor='%1' style='border: 1px solid \"%2\";'></td><td>%3</td></tr>");
|
||||||
|
return QLatin1String("<table cellspacing=4>")
|
||||||
|
+ rowHTML.arg(backgroundColor().name(), borderColor, tr("Unavailable pieces"))
|
||||||
|
+ rowHTML.arg(pieceColor().name(), borderColor, tr("Available pieces"))
|
||||||
|
+ QLatin1String("</table>");
|
||||||
}
|
}
|
||||||
|
@ -112,9 +112,6 @@ namespace
|
|||||||
PiecesBar::PiecesBar(QWidget *parent)
|
PiecesBar::PiecesBar(QWidget *parent)
|
||||||
: QWidget {parent}
|
: QWidget {parent}
|
||||||
, m_torrent {nullptr}
|
, m_torrent {nullptr}
|
||||||
, m_borderColor {palette().color(QPalette::Dark)}
|
|
||||||
, m_bgColor {Qt::white}
|
|
||||||
, m_pieceColor {Qt::blue}
|
|
||||||
, m_hovered {false}
|
, m_hovered {false}
|
||||||
{
|
{
|
||||||
updatePieceColors();
|
updatePieceColors();
|
||||||
@ -134,16 +131,6 @@ void PiecesBar::clear()
|
|||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PiecesBar::setColors(const QColor &background, const QColor &border, const QColor &complete)
|
|
||||||
{
|
|
||||||
m_bgColor = background;
|
|
||||||
m_borderColor = border;
|
|
||||||
m_pieceColor = complete;
|
|
||||||
|
|
||||||
updatePieceColors();
|
|
||||||
requestImageUpdate();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool PiecesBar::event(QEvent *e)
|
bool PiecesBar::event(QEvent *e)
|
||||||
{
|
{
|
||||||
if (e->type() == QEvent::ToolTip) {
|
if (e->type() == QEvent::ToolTip) {
|
||||||
@ -181,7 +168,7 @@ void PiecesBar::paintEvent(QPaintEvent *)
|
|||||||
QPainter painter(this);
|
QPainter painter(this);
|
||||||
QRect imageRect(borderWidth, borderWidth, width() - 2 * borderWidth, height() - 2 * borderWidth);
|
QRect imageRect(borderWidth, borderWidth, width() - 2 * borderWidth, height() - 2 * borderWidth);
|
||||||
if (m_image.isNull()) {
|
if (m_image.isNull()) {
|
||||||
painter.setBrush(Qt::white);
|
painter.setBrush(backgroundColor());
|
||||||
painter.drawRect(imageRect);
|
painter.drawRect(imageRect);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -199,7 +186,7 @@ void PiecesBar::paintEvent(QPaintEvent *)
|
|||||||
|
|
||||||
QPainterPath border;
|
QPainterPath border;
|
||||||
border.addRect(0, 0, width(), height());
|
border.addRect(0, 0, width(), height());
|
||||||
painter.setPen(m_borderColor);
|
painter.setPen(borderColor());
|
||||||
painter.drawPath(border);
|
painter.drawPath(border);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -211,17 +198,22 @@ void PiecesBar::requestImageUpdate()
|
|||||||
|
|
||||||
QColor PiecesBar::backgroundColor() const
|
QColor PiecesBar::backgroundColor() const
|
||||||
{
|
{
|
||||||
return m_bgColor;
|
return palette().color(QPalette::Base);
|
||||||
}
|
}
|
||||||
|
|
||||||
QColor PiecesBar::borderColor() const
|
QColor PiecesBar::borderColor() const
|
||||||
{
|
{
|
||||||
return m_borderColor;
|
return palette().color(QPalette::Dark);
|
||||||
}
|
}
|
||||||
|
|
||||||
QColor PiecesBar::pieceColor() const
|
QColor PiecesBar::pieceColor() const
|
||||||
{
|
{
|
||||||
return m_pieceColor;
|
return palette().color(QPalette::Highlight);
|
||||||
|
}
|
||||||
|
|
||||||
|
QColor PiecesBar::colorBoxBorderColor() const
|
||||||
|
{
|
||||||
|
return palette().color(QPalette::ToolTipText);
|
||||||
}
|
}
|
||||||
|
|
||||||
const QVector<QRgb> &PiecesBar::pieceColors() const
|
const QVector<QRgb> &PiecesBar::pieceColors() const
|
||||||
@ -326,6 +318,6 @@ void PiecesBar::updatePieceColors()
|
|||||||
m_pieceColors = QVector<QRgb>(256);
|
m_pieceColors = QVector<QRgb>(256);
|
||||||
for (int i = 0; i < 256; ++i) {
|
for (int i = 0; i < 256; ++i) {
|
||||||
float ratio = (i / 255.0);
|
float ratio = (i / 255.0);
|
||||||
m_pieceColors[i] = mixTwoColors(backgroundColor().rgb(), m_pieceColor.rgb(), ratio);
|
m_pieceColors[i] = mixTwoColors(backgroundColor().rgb(), pieceColor().rgb(), ratio);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,6 @@ public:
|
|||||||
explicit PiecesBar(QWidget *parent = nullptr);
|
explicit PiecesBar(QWidget *parent = nullptr);
|
||||||
|
|
||||||
void setTorrent(const BitTorrent::TorrentHandle *torrent);
|
void setTorrent(const BitTorrent::TorrentHandle *torrent);
|
||||||
void setColors(const QColor &background, const QColor &border, const QColor &complete);
|
|
||||||
|
|
||||||
virtual void clear();
|
virtual void clear();
|
||||||
|
|
||||||
@ -70,6 +69,7 @@ protected:
|
|||||||
QColor backgroundColor() const;
|
QColor backgroundColor() const;
|
||||||
QColor borderColor() const;
|
QColor borderColor() const;
|
||||||
QColor pieceColor() const;
|
QColor pieceColor() const;
|
||||||
|
QColor colorBoxBorderColor() const;
|
||||||
const QVector<QRgb> &pieceColors() const;
|
const QVector<QRgb> &pieceColors() const;
|
||||||
|
|
||||||
// mix two colors by light model, ratio <0, 1>
|
// mix two colors by light model, ratio <0, 1>
|
||||||
@ -90,13 +90,6 @@ private:
|
|||||||
|
|
||||||
const BitTorrent::TorrentHandle *m_torrent;
|
const BitTorrent::TorrentHandle *m_torrent;
|
||||||
QImage m_image;
|
QImage m_image;
|
||||||
// I used values, because it should be possible to change colors at run time
|
|
||||||
// border color
|
|
||||||
QColor m_borderColor;
|
|
||||||
// background color
|
|
||||||
QColor m_bgColor;
|
|
||||||
// complete piece color
|
|
||||||
QColor m_pieceColor;
|
|
||||||
// buffered 256 levels gradient from bg_color to piece_color
|
// buffered 256 levels gradient from bg_color to piece_color
|
||||||
QVector<QRgb> m_pieceColors;
|
QVector<QRgb> m_pieceColors;
|
||||||
bool m_hovered;
|
bool m_hovered;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user