diff --git a/src/gui/previewlistdelegate.cpp b/src/gui/previewlistdelegate.cpp index d89815756..955db4a89 100644 --- a/src/gui/previewlistdelegate.cpp +++ b/src/gui/previewlistdelegate.cpp @@ -34,6 +34,7 @@ #include "base/utils/string.h" #include "previewselectdialog.h" +#include "transferlistmodel.h" PreviewListDelegate::PreviewListDelegate(QObject *parent) : QStyledItemDelegate(parent) @@ -53,7 +54,10 @@ void PreviewListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &o ? u"100%"_s : (Utils::String::fromDouble(progress, 1) + u'%'); - m_progressBarPainter.paint(painter, option, text, static_cast(progress)); + const QModelIndex statusIndex = index.siblingAtColumn(TransferListModel::TR_STATUS); + const auto torrentState = statusIndex.data(TransferListModel::UnderlyingDataRole).value(); + + m_progressBarPainter.paint(painter, option, text, static_cast(progress), torrentState); } break; diff --git a/src/gui/progressbarpainter.cpp b/src/gui/progressbarpainter.cpp index 1f0d40c7c..e24f22ba4 100644 --- a/src/gui/progressbarpainter.cpp +++ b/src/gui/progressbarpainter.cpp @@ -39,8 +39,51 @@ #endif #include "base/global.h" +#include "base/bittorrent/torrent.h" #include "gui/uithememanager.h" +namespace +{ + QHash torrentStateColorsFromUITheme() + { + struct TorrentStateColorDescriptor + { + const BitTorrent::TorrentState state; + const QString id; + }; + + const TorrentStateColorDescriptor colorDescriptors[] = + { + {BitTorrent::TorrentState::Downloading, u"TransferList.Downloading"_s}, + {BitTorrent::TorrentState::StalledDownloading, u"TransferList.StalledDownloading"_s}, + {BitTorrent::TorrentState::DownloadingMetadata, u"TransferList.DownloadingMetadata"_s}, + {BitTorrent::TorrentState::ForcedDownloadingMetadata, u"TransferList.ForcedDownloadingMetadata"_s}, + {BitTorrent::TorrentState::ForcedDownloading, u"TransferList.ForcedDownloading"_s}, + {BitTorrent::TorrentState::Uploading, u"TransferList.Uploading"_s}, + {BitTorrent::TorrentState::StalledUploading, u"TransferList.StalledUploading"_s}, + {BitTorrent::TorrentState::ForcedUploading, u"TransferList.ForcedUploading"_s}, + {BitTorrent::TorrentState::QueuedDownloading, u"TransferList.QueuedDownloading"_s}, + {BitTorrent::TorrentState::QueuedUploading, u"TransferList.QueuedUploading"_s}, + {BitTorrent::TorrentState::CheckingDownloading, u"TransferList.CheckingDownloading"_s}, + {BitTorrent::TorrentState::CheckingUploading, u"TransferList.CheckingUploading"_s}, + {BitTorrent::TorrentState::CheckingResumeData, u"TransferList.CheckingResumeData"_s}, + {BitTorrent::TorrentState::StoppedDownloading, u"TransferList.StoppedDownloading"_s}, + {BitTorrent::TorrentState::StoppedUploading, u"TransferList.StoppedUploading"_s}, + {BitTorrent::TorrentState::Moving, u"TransferList.Moving"_s}, + {BitTorrent::TorrentState::MissingFiles, u"TransferList.MissingFiles"_s}, + {BitTorrent::TorrentState::Error, u"TransferList.Error"_s} + }; + + QHash colors; + for (const TorrentStateColorDescriptor &colorDescriptor : colorDescriptors) + { + const QColor themeColor = UIThemeManager::instance()->getColor(colorDescriptor.id); + colors.insert(colorDescriptor.state, themeColor); + } + return colors; + } +} + ProgressBarPainter::ProgressBarPainter(QObject *parent) : QObject(parent) { @@ -50,11 +93,10 @@ ProgressBarPainter::ProgressBarPainter(QObject *parent) m_dummyProgressBar.setStyle(fusionStyle); #endif - applyUITheme(); - connect(UIThemeManager::instance(), &UIThemeManager::themeChanged, this, &ProgressBarPainter::applyUITheme); + loadUIThemeResources(); } -void ProgressBarPainter::paint(QPainter *painter, const QStyleOptionViewItem &option, const QString &text, const int progress) const +void ProgressBarPainter::paint(QPainter *painter, const QStyleOptionViewItem &option, const QString &text, const int progress, const BitTorrent::TorrentState torrentState) const { QStyleOptionProgressBar styleOption; styleOption.initFrom(&m_dummyProgressBar); @@ -72,8 +114,7 @@ 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 (m_chunkColor.isValid()) - styleOption.palette.setColor(QPalette::Highlight, m_chunkColor); + styleOption.palette.setColor(QPalette::Highlight, m_stateThemeColors.value(torrentState)); painter->save(); const QStyle *style = m_dummyProgressBar.style(); @@ -82,7 +123,7 @@ void ProgressBarPainter::paint(QPainter *painter, const QStyleOptionViewItem &op painter->restore(); } -void ProgressBarPainter::applyUITheme() +void ProgressBarPainter::loadUIThemeResources() { - m_chunkColor = UIThemeManager::instance()->getColor(u"ProgressBar"_s); + m_stateThemeColors = torrentStateColorsFromUITheme(); } diff --git a/src/gui/progressbarpainter.h b/src/gui/progressbarpainter.h index cf0ea1932..2f3a87327 100644 --- a/src/gui/progressbarpainter.h +++ b/src/gui/progressbarpainter.h @@ -33,6 +33,8 @@ #include #include +#include "base/bittorrent/torrent.h" + class QStyleOptionViewItem; class ProgressBarPainter : public QObject @@ -43,12 +45,12 @@ class ProgressBarPainter : public QObject public: explicit ProgressBarPainter(QObject *parent = nullptr); - void paint(QPainter *painter, const QStyleOptionViewItem &option, const QString &text, int progress) const; + void paint(QPainter *painter, const QStyleOptionViewItem &option, const QString &text, int progress, BitTorrent::TorrentState torrentState) 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 4bc015301..4341bc18a 100644 --- a/src/gui/torrentcontentitemdelegate.cpp +++ b/src/gui/torrentcontentitemdelegate.cpp @@ -34,6 +34,7 @@ #include #include +#include "transferlistmodel.h" #include "base/bittorrent/downloadpriority.h" #include "base/bittorrent/torrent.h" #include "gui/torrentcontentmodel.h" @@ -140,10 +141,13 @@ void TorrentContentItemDelegate::paint(QPainter *painter, const QStyleOptionView const int priority = index.sibling(index.row(), TorrentContentModelItem::COL_PRIO).data(TorrentContentModel::UnderlyingDataRole).toInt(); const bool isEnabled = static_cast(priority) != BitTorrent::DownloadPriority::Ignored; + const QModelIndex statusIndex = index.siblingAtColumn(TransferListModel::TR_STATUS); + const auto torrentState = statusIndex.data(TransferListModel::UnderlyingDataRole).value(); + QStyleOptionViewItem customOption {option}; customOption.state.setFlag(QStyle::State_Enabled, isEnabled); - m_progressBarPainter.paint(painter, customOption, index.data().toString(), progress); + m_progressBarPainter.paint(painter, customOption, index.data().toString(), progress, torrentState); } break; default: diff --git a/src/gui/transferlistdelegate.cpp b/src/gui/transferlistdelegate.cpp index e08cb7ef8..37c326674 100644 --- a/src/gui/transferlistdelegate.cpp +++ b/src/gui/transferlistdelegate.cpp @@ -90,7 +90,7 @@ void TransferListDelegate::paint(QPainter *painter, const QStyleOptionViewItem & QStyleOptionViewItem customOption {option}; customOption.state.setFlag(QStyle::State_Enabled, isEnableState(torrentState)); - m_progressBarPainter.paint(painter, customOption, index.data().toString(), progress); + m_progressBarPainter.paint(painter, customOption, index.data().toString(), progress, torrentState); } break; default: