diff --git a/src/gui/properties/downloadedpiecesbar.cpp b/src/gui/properties/downloadedpiecesbar.cpp
index 896ce5f57..55e05a13d 100644
--- a/src/gui/properties/downloadedpiecesbar.cpp
+++ b/src/gui/properties/downloadedpiecesbar.cpp
@@ -120,7 +120,7 @@ bool DownloadedPiecesBar::updateImage(QImage &image)
}
if (m_pieces.isEmpty()) {
- image2.fill(Qt::white);
+ image2.fill(backgroundColor());
image = image2;
return true;
}
@@ -157,12 +157,6 @@ void DownloadedPiecesBar::setProgress(const QBitArray &pieces, const QBitArray &
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()
{
m_pieces.clear();
@@ -172,7 +166,11 @@ void DownloadedPiecesBar::clear()
QString DownloadedPiecesBar::simpleToolTipText() const
{
- return tr("White: Missing pieces") + '\n'
- + tr("Green: Partial pieces") + '\n'
- + tr("Blue: Completed pieces") + '\n';
+ const QString borderColor = colorBoxBorderColor().name();
+ const QString rowHTML = QString::fromLatin1("
| %3 |
");
+ return QLatin1String("")
+ + 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("
");
}
diff --git a/src/gui/properties/downloadedpiecesbar.h b/src/gui/properties/downloadedpiecesbar.h
index 102913ce8..e0621fe0b 100644
--- a/src/gui/properties/downloadedpiecesbar.h
+++ b/src/gui/properties/downloadedpiecesbar.h
@@ -47,8 +47,6 @@ public:
void setProgress(const QBitArray &pieces, const QBitArray &downloadedPieces);
- void setColors(const QColor &background, const QColor &border, const QColor &complete, const QColor &incomplete);
-
// PiecesBar interface
void clear() override;
diff --git a/src/gui/properties/pieceavailabilitybar.cpp b/src/gui/properties/pieceavailabilitybar.cpp
index 922220661..f03b6b855 100644
--- a/src/gui/properties/pieceavailabilitybar.cpp
+++ b/src/gui/properties/pieceavailabilitybar.cpp
@@ -127,7 +127,7 @@ bool PieceAvailabilityBar::updateImage(QImage &image)
}
if (m_pieces.empty()) {
- image2.fill(Qt::white);
+ image2.fill(backgroundColor());
image = image2;
return true;
}
@@ -158,6 +158,10 @@ void PieceAvailabilityBar::clear()
QString PieceAvailabilityBar::simpleToolTipText() const
{
- return tr("White: Unavailable pieces") + '\n'
- + tr("Blue: Available pieces") + '\n';
+ const QString borderColor = colorBoxBorderColor().name();
+ const QString rowHTML = QString::fromLatin1(" | %3 |
");
+ return QLatin1String("")
+ + rowHTML.arg(backgroundColor().name(), borderColor, tr("Unavailable pieces"))
+ + rowHTML.arg(pieceColor().name(), borderColor, tr("Available pieces"))
+ + QLatin1String("
");
}
diff --git a/src/gui/properties/piecesbar.cpp b/src/gui/properties/piecesbar.cpp
index 37d455618..458edcf3e 100644
--- a/src/gui/properties/piecesbar.cpp
+++ b/src/gui/properties/piecesbar.cpp
@@ -112,9 +112,6 @@ namespace
PiecesBar::PiecesBar(QWidget *parent)
: QWidget {parent}
, m_torrent {nullptr}
- , m_borderColor {palette().color(QPalette::Dark)}
- , m_bgColor {Qt::white}
- , m_pieceColor {Qt::blue}
, m_hovered {false}
{
updatePieceColors();
@@ -134,16 +131,6 @@ void PiecesBar::clear()
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)
{
if (e->type() == QEvent::ToolTip) {
@@ -181,7 +168,7 @@ void PiecesBar::paintEvent(QPaintEvent *)
QPainter painter(this);
QRect imageRect(borderWidth, borderWidth, width() - 2 * borderWidth, height() - 2 * borderWidth);
if (m_image.isNull()) {
- painter.setBrush(Qt::white);
+ painter.setBrush(backgroundColor());
painter.drawRect(imageRect);
}
else {
@@ -199,7 +186,7 @@ void PiecesBar::paintEvent(QPaintEvent *)
QPainterPath border;
border.addRect(0, 0, width(), height());
- painter.setPen(m_borderColor);
+ painter.setPen(borderColor());
painter.drawPath(border);
}
@@ -211,17 +198,22 @@ void PiecesBar::requestImageUpdate()
QColor PiecesBar::backgroundColor() const
{
- return m_bgColor;
+ return palette().color(QPalette::Base);
}
QColor PiecesBar::borderColor() const
{
- return m_borderColor;
+ return palette().color(QPalette::Dark);
}
QColor PiecesBar::pieceColor() const
{
- return m_pieceColor;
+ return palette().color(QPalette::Highlight);
+}
+
+QColor PiecesBar::colorBoxBorderColor() const
+{
+ return palette().color(QPalette::ToolTipText);
}
const QVector &PiecesBar::pieceColors() const
@@ -326,6 +318,6 @@ void PiecesBar::updatePieceColors()
m_pieceColors = QVector(256);
for (int i = 0; i < 256; ++i) {
float ratio = (i / 255.0);
- m_pieceColors[i] = mixTwoColors(backgroundColor().rgb(), m_pieceColor.rgb(), ratio);
+ m_pieceColors[i] = mixTwoColors(backgroundColor().rgb(), pieceColor().rgb(), ratio);
}
}
diff --git a/src/gui/properties/piecesbar.h b/src/gui/properties/piecesbar.h
index 7d555aeff..335b0c23a 100644
--- a/src/gui/properties/piecesbar.h
+++ b/src/gui/properties/piecesbar.h
@@ -51,7 +51,6 @@ public:
explicit PiecesBar(QWidget *parent = nullptr);
void setTorrent(const BitTorrent::TorrentHandle *torrent);
- void setColors(const QColor &background, const QColor &border, const QColor &complete);
virtual void clear();
@@ -70,6 +69,7 @@ protected:
QColor backgroundColor() const;
QColor borderColor() const;
QColor pieceColor() const;
+ QColor colorBoxBorderColor() const;
const QVector &pieceColors() const;
// mix two colors by light model, ratio <0, 1>
@@ -90,13 +90,6 @@ private:
const BitTorrent::TorrentHandle *m_torrent;
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
QVector m_pieceColors;
bool m_hovered;