mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-08-20 13:23:34 -07:00
revert content and preview ui.
revert applyUITheme. add torrent state parameter
This commit is contained in:
parent
a1f561f2e5
commit
08510e0266
5 changed files with 23 additions and 8 deletions
|
@ -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<int>(progress), torrentState);
|
||||
m_progressBarPainter.paint(painter, option, text, static_cast<int>(progress));
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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<BitTorrent::TorrentState, QColor> m_stateThemeColors;
|
||||
|
||||
QColor m_chunkColor;
|
||||
// for painting progressbar with stylesheet option, a dummy progress bar is required
|
||||
QProgressBar m_dummyProgressBar;
|
||||
};
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -87,6 +87,8 @@ inline QHash<QString, UIThemeColor> defaultUIThemeColors()
|
|||
{u"PiecesBar.Piece"_s, {{}, {}}},
|
||||
{u"PiecesBar.PartialPiece"_s, {{}, {}}},
|
||||
{u"PiecesBar.MissingPiece"_s, {{}, {}}},
|
||||
|
||||
{u"ProgressBar"_s, {{}, {}}}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue