Browse Source

Draw progress bar in disabled style

adaptive-webui-19844
Chocobo1 4 years ago
parent
commit
be2cdca1e9
No known key found for this signature in database
GPG Key ID: 210D9C873253A68C
  1. 23
      src/gui/transferlistdelegate.cpp
  2. 2
      src/gui/transferlistmodel.cpp
  3. 2
      src/gui/transferlistmodel.h

23
src/gui/transferlistdelegate.cpp

@ -68,9 +68,30 @@ void TransferListDelegate::paint(QPainter *painter, const QStyleOptionViewItem & @@ -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<int>(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<TorrentState>();
QStyleOptionViewItem customOption {option};
customOption.state.setFlag(QStyle::State_Enabled, isEnableState(torrentState));
m_progressBarPainter.paint(painter, customOption, index.data().toString(), progress);
}
break;
default:

2
src/gui/transferlistmodel.cpp

@ -498,7 +498,7 @@ QVariant TransferListModel::data(const QModelIndex &index, const int role) const @@ -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:

2
src/gui/transferlistmodel.h

@ -110,7 +110,7 @@ private slots: @@ -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<BitTorrent::Torrent *> m_torrentList; // maps row number to torrent handle
QHash<BitTorrent::Torrent *, int> m_torrentMap; // maps torrent handle to row number

Loading…
Cancel
Save