qBittorrent
TransferListDelegate Class Referencefinal

#include <transferlistdelegate.h>

Inheritance diagram for TransferListDelegate:
Collaboration diagram for TransferListDelegate:

Public Member Functions

 TransferListDelegate (QObject *parent)
 
QWidget * createEditor (QWidget *, const QStyleOptionViewItem &, const QModelIndex &) const override
 
QSize sizeHint (const QStyleOptionViewItem &option, const QModelIndex &index) const override
 
void paint (QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override
 

Private Attributes

ProgressBarPainter m_progressBarPainter
 

Detailed Description

Definition at line 35 of file transferlistdelegate.h.

Constructor & Destructor Documentation

◆ TransferListDelegate()

TransferListDelegate::TransferListDelegate ( QObject *  parent)
explicit

Definition at line 35 of file transferlistdelegate.cpp.

36  : QStyledItemDelegate {parent}
37 {
38 }

Member Function Documentation

◆ createEditor()

QWidget * TransferListDelegate::createEditor ( QWidget *  ,
const QStyleOptionViewItem &  ,
const QModelIndex &   
) const
override

Definition at line 40 of file transferlistdelegate.cpp.

41 {
42  // No editor here
43  return nullptr;
44 }

◆ paint()

void TransferListDelegate::paint ( QPainter *  painter,
const QStyleOptionViewItem &  option,
const QModelIndex &  index 
) const
override

Definition at line 65 of file transferlistdelegate.cpp.

66 {
67  switch (index.column())
68  {
70  {
71  using namespace BitTorrent;
72 
73  const auto isEnableState = [](const TorrentState state) -> bool
74  {
75  switch (state)
76  {
77  case TorrentState::Error:
78  case TorrentState::PausedDownloading:
79  case TorrentState::Unknown:
80  return false;
81  default:
82  return true;
83  }
84  };
85 
86  const int progress = static_cast<int>(index.data(TransferListModel::UnderlyingDataRole).toReal());
87 
88  const QModelIndex statusIndex = index.siblingAtColumn(TransferListModel::TR_STATUS);
89  const auto torrentState = statusIndex.data(TransferListModel::UnderlyingDataRole).value<TorrentState>();
90 
91  QStyleOptionViewItem customOption {option};
92  customOption.state.setFlag(QStyle::State_Enabled, isEnableState(torrentState));
93 
94  m_progressBarPainter.paint(painter, customOption, index.data().toString(), progress);
95  }
96  break;
97  default:
98  QStyledItemDelegate::paint(painter, option, index);
99  break;
100  }
101 }
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QString &text, int progress) const
ProgressBarPainter m_progressBarPainter
TorrentState
Definition: torrent.h:70

References m_progressBarPainter, ProgressBarPainter::paint(), TransferListModel::TR_PROGRESS, TransferListModel::TR_STATUS, and TransferListModel::UnderlyingDataRole.

Here is the call graph for this function:

◆ sizeHint()

QSize TransferListDelegate::sizeHint ( const QStyleOptionViewItem &  option,
const QModelIndex &  index 
) const
override

Definition at line 46 of file transferlistdelegate.cpp.

47 {
48  // Reimplementing sizeHint() because the 'name' column contains text+icon.
49  // When that WHOLE column goes out of view(eg user scrolls horizontally)
50  // the rows shrink if the text's height is smaller than the icon's height.
51  // This happens because icon from the 'name' column is no longer drawn.
52 
53  static int nameColHeight = -1;
54  if (nameColHeight == -1)
55  {
56  const QModelIndex nameColumn = index.sibling(index.row(), TransferListModel::TR_NAME);
57  nameColHeight = QStyledItemDelegate::sizeHint(option, nameColumn).height();
58  }
59 
60  QSize size = QStyledItemDelegate::sizeHint(option, index);
61  size.setHeight(std::max(nameColHeight, size.height()));
62  return size;
63 }

References TransferListModel::TR_NAME.

Member Data Documentation

◆ m_progressBarPainter

ProgressBarPainter TransferListDelegate::m_progressBarPainter
private

Definition at line 48 of file transferlistdelegate.h.

Referenced by paint().


The documentation for this class was generated from the following files: