revert content and preview ui.

revert applyUITheme.

add torrent state parameter
This commit is contained in:
Mark 2025-07-06 17:44:04 +04:00
commit 08510e0266
5 changed files with 23 additions and 8 deletions

View file

@ -53,9 +53,7 @@ void PreviewListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &o
? u"100%"_s ? u"100%"_s
: (Utils::String::fromDouble(progress, 1) + u'%'); : (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<int>(progress));
m_progressBarPainter.paint(painter, option, text, static_cast<int>(progress), torrentState);
} }
break; break;

View file

@ -95,6 +95,8 @@ ProgressBarPainter::ProgressBarPainter(QObject *parent)
#endif #endif
loadUIThemeResources(); 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 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); const bool isEnabled = option.state.testFlag(QStyle::State_Enabled);
styleOption.palette.setCurrentColorGroup(isEnabled ? QPalette::Active : QPalette::Disabled); 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(); painter->save();
const QStyle *style = m_dummyProgressBar.style(); const QStyle *style = m_dummyProgressBar.style();
@ -124,7 +133,13 @@ void ProgressBarPainter::paint(QPainter *painter, const QStyleOptionViewItem &op
painter->restore(); painter->restore();
} }
void ProgressBarPainter::applyUITheme()
{
m_chunkColor = UIThemeManager::instance()->getColor(u"ProgressBar"_s);
}
void ProgressBarPainter::loadUIThemeResources() void ProgressBarPainter::loadUIThemeResources()
{ {
m_stateThemeColors = torrentStateColorsFromUITheme(); m_stateThemeColors = torrentStateColorsFromUITheme();
} }

View file

@ -45,12 +45,14 @@ class ProgressBarPainter : public QObject
public: public:
explicit ProgressBarPainter(QObject *parent = nullptr); 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: private:
void applyUITheme();
void loadUIThemeResources(); void loadUIThemeResources();
QHash<BitTorrent::TorrentState, QColor> m_stateThemeColors; QHash<BitTorrent::TorrentState, QColor> m_stateThemeColors;
QColor m_chunkColor;
// for painting progressbar with stylesheet option, a dummy progress bar is required // for painting progressbar with stylesheet option, a dummy progress bar is required
QProgressBar m_dummyProgressBar; QProgressBar m_dummyProgressBar;
}; };

View file

@ -143,9 +143,7 @@ void TorrentContentItemDelegate::paint(QPainter *painter, const QStyleOptionView
QStyleOptionViewItem customOption {option}; QStyleOptionViewItem customOption {option};
customOption.state.setFlag(QStyle::State_Enabled, isEnabled); 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);
m_progressBarPainter.paint(painter, customOption, index.data().toString(), progress, torrentState);
} }
break; break;
default: default:

View file

@ -87,6 +87,8 @@ inline QHash<QString, UIThemeColor> defaultUIThemeColors()
{u"PiecesBar.Piece"_s, {{}, {}}}, {u"PiecesBar.Piece"_s, {{}, {}}},
{u"PiecesBar.PartialPiece"_s, {{}, {}}}, {u"PiecesBar.PartialPiece"_s, {{}, {}}},
{u"PiecesBar.MissingPiece"_s, {{}, {}}}, {u"PiecesBar.MissingPiece"_s, {{}, {}}},
{u"ProgressBar"_s, {{}, {}}}
}; };
} }