Browse Source

Use ProgressBarDelegate for drawing progressbar in TransferListView

adaptive-webui-19844
jagannatharjun 4 years ago
parent
commit
49d5591f48
  1. 39
      src/gui/transferlistdelegate.cpp
  2. 9
      src/gui/transferlistdelegate.h

39
src/gui/transferlistdelegate.cpp

@ -28,50 +28,13 @@ @@ -28,50 +28,13 @@
#include "transferlistdelegate.h"
#include <QApplication>
#include <QModelIndex>
#include <QPainter>
#include <QStyleOptionViewItem>
#if defined(Q_OS_WIN) || defined(Q_OS_MACOS)
#include <QProxyStyle>
#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<int>(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

9
src/gui/transferlistdelegate.h

@ -28,13 +28,9 @@ @@ -28,13 +28,9 @@
#pragma once
#include <QStyledItemDelegate>
#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 @@ -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;
};

Loading…
Cancel
Save