mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-14 00:37:58 +00:00
Use ProgressBarDelegate for drawing progressbar in TransferListView
This commit is contained in:
parent
816bc45707
commit
49d5591f48
@ -28,52 +28,15 @@
|
||||
|
||||
#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}
|
||||
: ProgressBarDelegate {TransferListModel::TR_PROGRESS, TransferListModel::UnderlyingDataRole, parent}
|
||||
{
|
||||
}
|
||||
|
||||
void TransferListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||
{
|
||||
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
|
||||
{
|
||||
// No editor here
|
||||
|
@ -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
|
||||
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…
Reference in New Issue
Block a user