diff --git a/src/gui/transferlistdelegate.cpp b/src/gui/transferlistdelegate.cpp index d8ecfb1a4..eddbef7b8 100644 --- a/src/gui/transferlistdelegate.cpp +++ b/src/gui/transferlistdelegate.cpp @@ -28,50 +28,13 @@ #include "transferlistdelegate.h" -#include #include -#include -#include -#if defined(Q_OS_WIN) || defined(Q_OS_MACOS) -#include -#endif - -#include "base/utils/string.h" #include "transferlistmodel.h" TransferListDelegate::TransferListDelegate(QObject *parent) - : QStyledItemDelegate {parent} -{ -} - -void TransferListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const + : ProgressBarDelegate {TransferListModel::TR_PROGRESS, TransferListModel::UnderlyingDataRole, parent} { - if (index.column() != TransferListModel::TR_PROGRESS) { - QStyledItemDelegate::paint(painter, option, index); - return; - } - - QStyleOptionProgressBar newopt; - newopt.rect = option.rect; - newopt.text = index.data().toString(); - newopt.progress = static_cast(index.data(TransferListModel::UnderlyingDataRole).toReal()); - newopt.maximum = 100; - newopt.minimum = 0; - newopt.state = option.state; - newopt.textVisible = true; - -#if defined(Q_OS_WIN) || defined(Q_OS_MACOS) - // XXX: To avoid having the progress text on the right of the bar - QProxyStyle fusionStyle {"fusion"}; - QStyle *style = &fusionStyle; -#else - QStyle *style = option.widget ? option.widget->style() : QApplication::style(); -#endif - - painter->save(); - style->drawControl(QStyle::CE_ProgressBar, &newopt, painter); - painter->restore(); } QWidget *TransferListDelegate::createEditor(QWidget *, const QStyleOptionViewItem &, const QModelIndex &) const diff --git a/src/gui/transferlistdelegate.h b/src/gui/transferlistdelegate.h index 2d5302cca..7be78cc39 100644 --- a/src/gui/transferlistdelegate.h +++ b/src/gui/transferlistdelegate.h @@ -28,13 +28,9 @@ #pragma once -#include +#include "progressbardelegate.h" -class QModelIndex; -class QPainter; -class QStyleOptionViewItem; - -class TransferListDelegate final : public QStyledItemDelegate +class TransferListDelegate final : public ProgressBarDelegate { Q_OBJECT Q_DISABLE_COPY(TransferListDelegate) @@ -42,7 +38,6 @@ class TransferListDelegate final : public QStyledItemDelegate public: explicit TransferListDelegate(QObject *parent); - void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override; QWidget *createEditor(QWidget *, const QStyleOptionViewItem &, const QModelIndex &) const override; QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override; };