From be2cdca1e99f1b9d7ebe038aabae78089b784a3e Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Thu, 18 Mar 2021 12:04:46 +0800 Subject: [PATCH] Draw progress bar in disabled style --- src/gui/transferlistdelegate.cpp | 23 ++++++++++++++++++++++- src/gui/transferlistmodel.cpp | 2 +- src/gui/transferlistmodel.h | 2 +- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/gui/transferlistdelegate.cpp b/src/gui/transferlistdelegate.cpp index f80b485df..b649ecff1 100644 --- a/src/gui/transferlistdelegate.cpp +++ b/src/gui/transferlistdelegate.cpp @@ -68,9 +68,30 @@ void TransferListDelegate::paint(QPainter *painter, const QStyleOptionViewItem & { case TransferListModel::TR_PROGRESS: { + using namespace BitTorrent; + + const auto isEnableState = [](const TorrentState state) -> bool + { + switch (state) + { + case TorrentState::Error: + case TorrentState::PausedDownloading: + case TorrentState::Unknown: + return false; + default: + return true; + } + }; + const int progress = static_cast(index.data(TransferListModel::UnderlyingDataRole).toReal()); - m_progressBarPainter.paint(painter, option, index.data().toString(), progress); + 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, isEnableState(torrentState)); + + m_progressBarPainter.paint(painter, customOption, index.data().toString(), progress); } break; default: diff --git a/src/gui/transferlistmodel.cpp b/src/gui/transferlistmodel.cpp index 99d1429b9..b2f40690f 100644 --- a/src/gui/transferlistmodel.cpp +++ b/src/gui/transferlistmodel.cpp @@ -498,7 +498,7 @@ QVariant TransferListModel::data(const QModelIndex &index, const int role) const case Qt::DisplayRole: return displayValue(torrent, index.column()); case UnderlyingDataRole: - return internalValue(torrent, index.column()); + return internalValue(torrent, index.column(), false); case AdditionalUnderlyingDataRole: return internalValue(torrent, index.column(), true); case Qt::DecorationRole: diff --git a/src/gui/transferlistmodel.h b/src/gui/transferlistmodel.h index 91734bc8e..b67a33bf7 100644 --- a/src/gui/transferlistmodel.h +++ b/src/gui/transferlistmodel.h @@ -110,7 +110,7 @@ private slots: private: void configure(); QString displayValue(const BitTorrent::Torrent *torrent, int column) const; - QVariant internalValue(const BitTorrent::Torrent *torrent, int column, bool alt = false) const; + QVariant internalValue(const BitTorrent::Torrent *torrent, int column, bool alt) const; QList m_torrentList; // maps row number to torrent handle QHash m_torrentMap; // maps torrent handle to row number