diff --git a/src/gui/previewlistdelegate.cpp b/src/gui/previewlistdelegate.cpp index f5cbf89e8..d89815756 100644 --- a/src/gui/previewlistdelegate.cpp +++ b/src/gui/previewlistdelegate.cpp @@ -53,9 +53,7 @@ void PreviewListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &o ? u"100%"_s : (Utils::String::fromDouble(progress, 1) + u'%'); - BitTorrent::TorrentState torrentState = progress >= 100 ? BitTorrent::TorrentState::StalledUploading : BitTorrent::TorrentState::Downloading; - - m_progressBarPainter.paint(painter, option, text, static_cast(progress), torrentState); + m_progressBarPainter.paint(painter, option, text, static_cast(progress)); } break; diff --git a/src/gui/progressbarpainter.cpp b/src/gui/progressbarpainter.cpp index 8233ac255..d814e83dc 100644 --- a/src/gui/progressbarpainter.cpp +++ b/src/gui/progressbarpainter.cpp @@ -95,6 +95,8 @@ ProgressBarPainter::ProgressBarPainter(QObject *parent) #endif loadUIThemeResources(); + applyUITheme(); + connect(UIThemeManager::instance(), &UIThemeManager::themeChanged, this, &ProgressBarPainter::applyUITheme); } void ProgressBarPainter::paint(QPainter *painter, const QStyleOptionViewItem &option, const QString &text, const int progress, const BitTorrent::TorrentState torrentState) const @@ -115,7 +117,14 @@ void ProgressBarPainter::paint(QPainter *painter, const QStyleOptionViewItem &op const bool isEnabled = option.state.testFlag(QStyle::State_Enabled); styleOption.palette.setCurrentColorGroup(isEnabled ? QPalette::Active : QPalette::Disabled); - styleOption.palette.setColor(QPalette::Highlight, m_stateThemeColors.value(torrentState)); + if (torrentState != BitTorrent::TorrentState::Unknown) + { + styleOption.palette.setColor(QPalette::Highlight, m_stateThemeColors.value(torrentState)); + } + else if (m_chunkColor.isValid()) + { + styleOption.palette.setColor(QPalette::Highlight, m_chunkColor); + } painter->save(); const QStyle *style = m_dummyProgressBar.style(); @@ -124,7 +133,13 @@ void ProgressBarPainter::paint(QPainter *painter, const QStyleOptionViewItem &op painter->restore(); } +void ProgressBarPainter::applyUITheme() +{ + m_chunkColor = UIThemeManager::instance()->getColor(u"ProgressBar"_s); +} + void ProgressBarPainter::loadUIThemeResources() { m_stateThemeColors = torrentStateColorsFromUITheme(); } + diff --git a/src/gui/progressbarpainter.h b/src/gui/progressbarpainter.h index 2f3a87327..9bc75888f 100644 --- a/src/gui/progressbarpainter.h +++ b/src/gui/progressbarpainter.h @@ -45,12 +45,14 @@ class ProgressBarPainter : public QObject public: explicit ProgressBarPainter(QObject *parent = nullptr); - void paint(QPainter *painter, const QStyleOptionViewItem &option, const QString &text, int progress, BitTorrent::TorrentState torrentState) const; + void paint(QPainter *painter, const QStyleOptionViewItem &option, const QString &text, int progress, BitTorrent::TorrentState state = BitTorrent::TorrentState::Unknown) const; private: + void applyUITheme(); void loadUIThemeResources(); QHash m_stateThemeColors; + QColor m_chunkColor; // for painting progressbar with stylesheet option, a dummy progress bar is required QProgressBar m_dummyProgressBar; }; diff --git a/src/gui/torrentcontentitemdelegate.cpp b/src/gui/torrentcontentitemdelegate.cpp index 679fdaaeb..4bc015301 100644 --- a/src/gui/torrentcontentitemdelegate.cpp +++ b/src/gui/torrentcontentitemdelegate.cpp @@ -143,9 +143,7 @@ void TorrentContentItemDelegate::paint(QPainter *painter, const QStyleOptionView QStyleOptionViewItem customOption {option}; customOption.state.setFlag(QStyle::State_Enabled, isEnabled); - BitTorrent::TorrentState torrentState = progress >= 100 ? BitTorrent::TorrentState::StalledUploading : BitTorrent::TorrentState::Downloading; - - m_progressBarPainter.paint(painter, customOption, index.data().toString(), progress, torrentState); + m_progressBarPainter.paint(painter, customOption, index.data().toString(), progress); } break; default: diff --git a/src/gui/uithemecommon.h b/src/gui/uithemecommon.h index 1b2afd777..16ad7d5e5 100644 --- a/src/gui/uithemecommon.h +++ b/src/gui/uithemecommon.h @@ -87,6 +87,8 @@ inline QHash defaultUIThemeColors() {u"PiecesBar.Piece"_s, {{}, {}}}, {u"PiecesBar.PartialPiece"_s, {{}, {}}}, {u"PiecesBar.MissingPiece"_s, {{}, {}}}, + + {u"ProgressBar"_s, {{}, {}}} }; }