mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-08-21 13:53:37 -07:00
Use QStyledItemDelegate instead of QItemDelegate
This commit is contained in:
parent
766cfb67df
commit
15f2a3b564
2 changed files with 18 additions and 21 deletions
|
@ -41,38 +41,36 @@
|
||||||
#include "transferlistmodel.h"
|
#include "transferlistmodel.h"
|
||||||
|
|
||||||
TransferListDelegate::TransferListDelegate(QObject *parent)
|
TransferListDelegate::TransferListDelegate(QObject *parent)
|
||||||
: QItemDelegate(parent)
|
: QStyledItemDelegate {parent}
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransferListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
void TransferListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
if (index.column() != TransferListModel::TR_PROGRESS) {
|
if (index.column() != TransferListModel::TR_PROGRESS) {
|
||||||
QItemDelegate::paint(painter, option, index);
|
QStyledItemDelegate::paint(painter, option, index);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
painter->save();
|
|
||||||
|
|
||||||
QStyleOptionViewItem opt = QItemDelegate::setOptions(index, option);
|
|
||||||
QItemDelegate::drawBackground(painter, opt, index);
|
|
||||||
|
|
||||||
QStyleOptionProgressBar newopt;
|
QStyleOptionProgressBar newopt;
|
||||||
newopt.rect = opt.rect;
|
newopt.rect = option.rect;
|
||||||
newopt.text = index.data().toString();
|
newopt.text = index.data().toString();
|
||||||
newopt.progress = static_cast<int>(index.data(TransferListModel::UnderlyingDataRole).toReal());
|
newopt.progress = static_cast<int>(index.data(TransferListModel::UnderlyingDataRole).toReal());
|
||||||
newopt.maximum = 100;
|
newopt.maximum = 100;
|
||||||
newopt.minimum = 0;
|
newopt.minimum = 0;
|
||||||
newopt.state |= QStyle::State_Enabled;
|
newopt.state = option.state;
|
||||||
newopt.textVisible = true;
|
newopt.textVisible = true;
|
||||||
|
|
||||||
#if defined(Q_OS_WIN) || defined(Q_OS_MACOS)
|
#if defined(Q_OS_WIN) || defined(Q_OS_MACOS)
|
||||||
// XXX: To avoid having the progress text on the right of the bar
|
// XXX: To avoid having the progress text on the right of the bar
|
||||||
QProxyStyle st("fusion");
|
QProxyStyle fusionStyle {"fusion"};
|
||||||
st.drawControl(QStyle::CE_ProgressBar, &newopt, painter);
|
QStyle *style = &fusionStyle;
|
||||||
#else
|
#else
|
||||||
QApplication::style()->drawControl(QStyle::CE_ProgressBar, &newopt, painter);
|
QStyle *style = option.widget ? option.widget->style() : QApplication::style();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
painter->save();
|
||||||
|
style->drawControl(QStyle::CE_ProgressBar, &newopt, painter, option.widget);
|
||||||
painter->restore();
|
painter->restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,10 +90,10 @@ QSize TransferListDelegate::sizeHint(const QStyleOptionViewItem &option, const Q
|
||||||
static int nameColHeight = -1;
|
static int nameColHeight = -1;
|
||||||
if (nameColHeight == -1) {
|
if (nameColHeight == -1) {
|
||||||
const QModelIndex nameColumn = index.sibling(index.row(), TransferListModel::TR_NAME);
|
const QModelIndex nameColumn = index.sibling(index.row(), TransferListModel::TR_NAME);
|
||||||
nameColHeight = QItemDelegate::sizeHint(option, nameColumn).height();
|
nameColHeight = QStyledItemDelegate::sizeHint(option, nameColumn).height();
|
||||||
}
|
}
|
||||||
|
|
||||||
QSize size = QItemDelegate::sizeHint(option, index);
|
QSize size = QStyledItemDelegate::sizeHint(option, index);
|
||||||
size.setHeight(std::max(nameColHeight, size.height()));
|
size.setHeight(std::max(nameColHeight, size.height()));
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,24 +26,23 @@
|
||||||
* exception statement from your version.
|
* exception statement from your version.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef TRANSFERLISTDELEGATE_H
|
#pragma once
|
||||||
#define TRANSFERLISTDELEGATE_H
|
|
||||||
|
|
||||||
#include <QItemDelegate>
|
#include <QStyledItemDelegate>
|
||||||
|
|
||||||
class QModelIndex;
|
class QModelIndex;
|
||||||
class QPainter;
|
class QPainter;
|
||||||
class QStyleOptionViewItem;
|
class QStyleOptionViewItem;
|
||||||
|
|
||||||
class TransferListDelegate : public QItemDelegate
|
class TransferListDelegate : public QStyledItemDelegate
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
Q_DISABLE_COPY(TransferListDelegate)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TransferListDelegate(QObject *parent);
|
explicit TransferListDelegate(QObject *parent);
|
||||||
|
|
||||||
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
|
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
|
||||||
QWidget *createEditor(QWidget *, const QStyleOptionViewItem &, const QModelIndex &) const override;
|
QWidget *createEditor(QWidget *, const QStyleOptionViewItem &, const QModelIndex &) const override;
|
||||||
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override;
|
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // TRANSFERLISTDELEGATE_H
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue