mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-16 02:03:07 -07:00
commit
ae0a9d74c4
8 changed files with 129 additions and 139 deletions
|
@ -70,7 +70,10 @@ const QString KEY_SAVEPATHHISTORY = SETTINGS_KEY("SavePathHistory");
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
// just a shortcut
|
// just a shortcut
|
||||||
inline SettingsStorage *settings() { return SettingsStorage::instance(); }
|
inline SettingsStorage *settings()
|
||||||
|
{
|
||||||
|
return SettingsStorage::instance();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AddNewTorrentDialog::AddNewTorrentDialog(QWidget *parent)
|
AddNewTorrentDialog::AddNewTorrentDialog(QWidget *parent)
|
||||||
|
@ -311,7 +314,6 @@ void AddNewTorrentDialog::showEvent(QShowEvent *event)
|
||||||
raise();
|
raise();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void AddNewTorrentDialog::showAdvancedSettings(bool show)
|
void AddNewTorrentDialog::showAdvancedSettings(bool show)
|
||||||
{
|
{
|
||||||
const int minimumW = minimumWidth();
|
const int minimumW = minimumWidth();
|
||||||
|
@ -720,7 +722,7 @@ void AddNewTorrentDialog::setupTreeview()
|
||||||
m_contentModel = new TorrentContentFilterModel(this);
|
m_contentModel = new TorrentContentFilterModel(this);
|
||||||
connect(m_contentModel->model(), SIGNAL(filteredFilesChanged()), SLOT(updateDiskSpaceLabel()));
|
connect(m_contentModel->model(), SIGNAL(filteredFilesChanged()), SLOT(updateDiskSpaceLabel()));
|
||||||
ui->contentTreeView->setModel(m_contentModel);
|
ui->contentTreeView->setModel(m_contentModel);
|
||||||
m_contentDelegate = new PropListDelegate();
|
m_contentDelegate = new PropListDelegate(nullptr);
|
||||||
ui->contentTreeView->setItemDelegate(m_contentDelegate);
|
ui->contentTreeView->setItemDelegate(m_contentDelegate);
|
||||||
connect(ui->contentTreeView, SIGNAL(clicked(const QModelIndex&)), ui->contentTreeView, SLOT(edit(const QModelIndex&)));
|
connect(ui->contentTreeView, SIGNAL(clicked(const QModelIndex&)), ui->contentTreeView, SLOT(edit(const QModelIndex&)));
|
||||||
connect(ui->contentTreeView, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayContentTreeMenu(const QPoint&)));
|
connect(ui->contentTreeView, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayContentTreeMenu(const QPoint&)));
|
||||||
|
|
|
@ -38,7 +38,8 @@
|
||||||
#include "base/utils/misc.h"
|
#include "base/utils/misc.h"
|
||||||
#include "base/utils/string.h"
|
#include "base/utils/string.h"
|
||||||
|
|
||||||
class PeerListDelegate: public QItemDelegate {
|
class PeerListDelegate: public QItemDelegate
|
||||||
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -67,14 +68,16 @@ public:
|
||||||
|
|
||||||
~PeerListDelegate() {}
|
~PeerListDelegate() {}
|
||||||
|
|
||||||
void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const
|
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override
|
||||||
{
|
{
|
||||||
painter->save();
|
painter->save();
|
||||||
|
|
||||||
const bool hideValues = Preferences::instance()->getHideZeroValues();
|
const bool hideValues = Preferences::instance()->getHideZeroValues();
|
||||||
QStyleOptionViewItem opt = QItemDelegate::setOptions(index, option);
|
QStyleOptionViewItem opt = QItemDelegate::setOptions(index, option);
|
||||||
|
QItemDelegate::drawBackground(painter, opt, index);
|
||||||
|
|
||||||
switch (index.column()) {
|
switch (index.column()) {
|
||||||
case PORT: {
|
case PORT: {
|
||||||
QItemDelegate::drawBackground(painter, opt, index);
|
|
||||||
opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter;
|
opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter;
|
||||||
QItemDelegate::drawDisplay(painter, opt, option.rect, index.data().toString());
|
QItemDelegate::drawDisplay(painter, opt, option.rect, index.data().toString());
|
||||||
}
|
}
|
||||||
|
@ -84,23 +87,21 @@ public:
|
||||||
qlonglong size = index.data().toLongLong();
|
qlonglong size = index.data().toLongLong();
|
||||||
if (hideValues && (size <= 0))
|
if (hideValues && (size <= 0))
|
||||||
break;
|
break;
|
||||||
QItemDelegate::drawBackground(painter, opt, index);
|
|
||||||
opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter;
|
opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter;
|
||||||
QItemDelegate::drawDisplay(painter, opt, option.rect, Utils::Misc::friendlyUnit(size));
|
QItemDelegate::drawDisplay(painter, opt, option.rect, Utils::Misc::friendlyUnit(size));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case DOWN_SPEED:
|
case DOWN_SPEED:
|
||||||
case UP_SPEED: {
|
case UP_SPEED: {
|
||||||
QItemDelegate::drawBackground(painter, opt, index);
|
|
||||||
qreal speed = index.data().toDouble();
|
qreal speed = index.data().toDouble();
|
||||||
|
if (speed <= 0.0)
|
||||||
|
break;
|
||||||
opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter;
|
opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter;
|
||||||
if (speed > 0.0)
|
|
||||||
QItemDelegate::drawDisplay(painter, opt, opt.rect, Utils::Misc::friendlyUnit(speed, true));
|
QItemDelegate::drawDisplay(painter, opt, opt.rect, Utils::Misc::friendlyUnit(speed, true));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case PROGRESS:
|
case PROGRESS:
|
||||||
case RELEVANCE: {
|
case RELEVANCE: {
|
||||||
QItemDelegate::drawBackground(painter, opt, index);
|
|
||||||
qreal progress = index.data().toDouble();
|
qreal progress = index.data().toDouble();
|
||||||
opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter;
|
opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter;
|
||||||
QItemDelegate::drawDisplay(painter, opt, opt.rect, Utils::String::fromDouble(progress * 100.0, 1) + "%");
|
QItemDelegate::drawDisplay(painter, opt, opt.rect, Utils::String::fromDouble(progress * 100.0, 1) + "%");
|
||||||
|
@ -109,15 +110,15 @@ public:
|
||||||
default:
|
default:
|
||||||
QItemDelegate::paint(painter, option, index);
|
QItemDelegate::paint(painter, option, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
painter->restore();
|
painter->restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
QWidget* createEditor(QWidget*, const QStyleOptionViewItem &, const QModelIndex &) const
|
QWidget *createEditor(QWidget *, const QStyleOptionViewItem &, const QModelIndex &) const override
|
||||||
{
|
{
|
||||||
// No editor here
|
// No editor here
|
||||||
return 0;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // PEERLISTDELEGATE_H
|
#endif // PEERLISTDELEGATE_H
|
||||||
|
|
|
@ -69,7 +69,7 @@ PeerListWidget::PeerListWidget(PropertiesWidget *parent)
|
||||||
setSelectionMode(QAbstractItemView::ExtendedSelection);
|
setSelectionMode(QAbstractItemView::ExtendedSelection);
|
||||||
header()->setStretchLastSection(false);
|
header()->setStretchLastSection(false);
|
||||||
// List Model
|
// List Model
|
||||||
m_listModel = new QStandardItemModel(0, PeerListDelegate::COL_COUNT);
|
m_listModel = new QStandardItemModel(0, PeerListDelegate::COL_COUNT, this);
|
||||||
m_listModel->setHeaderData(PeerListDelegate::COUNTRY, Qt::Horizontal, tr("Country")); // Country flag column
|
m_listModel->setHeaderData(PeerListDelegate::COUNTRY, Qt::Horizontal, tr("Country")); // Country flag column
|
||||||
m_listModel->setHeaderData(PeerListDelegate::IP, Qt::Horizontal, tr("IP"));
|
m_listModel->setHeaderData(PeerListDelegate::IP, Qt::Horizontal, tr("IP"));
|
||||||
m_listModel->setHeaderData(PeerListDelegate::PORT, Qt::Horizontal, tr("Port"));
|
m_listModel->setHeaderData(PeerListDelegate::PORT, Qt::Horizontal, tr("Port"));
|
||||||
|
@ -92,7 +92,7 @@ PeerListWidget::PeerListWidget(PropertiesWidget *parent)
|
||||||
m_listModel->setHeaderData(PeerListDelegate::TOT_UP, Qt::Horizontal, QVariant(Qt::AlignRight | Qt::AlignVCenter), Qt::TextAlignmentRole);
|
m_listModel->setHeaderData(PeerListDelegate::TOT_UP, Qt::Horizontal, QVariant(Qt::AlignRight | Qt::AlignVCenter), Qt::TextAlignmentRole);
|
||||||
m_listModel->setHeaderData(PeerListDelegate::RELEVANCE, Qt::Horizontal, QVariant(Qt::AlignRight | Qt::AlignVCenter), Qt::TextAlignmentRole);
|
m_listModel->setHeaderData(PeerListDelegate::RELEVANCE, Qt::Horizontal, QVariant(Qt::AlignRight | Qt::AlignVCenter), Qt::TextAlignmentRole);
|
||||||
// Proxy model to support sorting without actually altering the underlying model
|
// Proxy model to support sorting without actually altering the underlying model
|
||||||
m_proxyModel = new PeerListSortModel();
|
m_proxyModel = new PeerListSortModel(this);
|
||||||
m_proxyModel->setDynamicSortFilter(true);
|
m_proxyModel->setDynamicSortFilter(true);
|
||||||
m_proxyModel->setSourceModel(m_listModel);
|
m_proxyModel->setSourceModel(m_listModel);
|
||||||
m_proxyModel->setSortCaseSensitivity(Qt::CaseInsensitive);
|
m_proxyModel->setSortCaseSensitivity(Qt::CaseInsensitive);
|
||||||
|
@ -146,12 +146,8 @@ PeerListWidget::PeerListWidget(PropertiesWidget *parent)
|
||||||
PeerListWidget::~PeerListWidget()
|
PeerListWidget::~PeerListWidget()
|
||||||
{
|
{
|
||||||
saveSettings();
|
saveSettings();
|
||||||
delete m_proxyModel;
|
|
||||||
delete m_listModel;
|
|
||||||
delete m_listDelegate;
|
|
||||||
if (m_resolver)
|
if (m_resolver)
|
||||||
delete m_resolver;
|
delete m_resolver;
|
||||||
delete m_copyHotkey;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PeerListWidget::displayToggleColumnsMenu(const QPoint &)
|
void PeerListWidget::displayToggleColumnsMenu(const QPoint &)
|
||||||
|
|
|
@ -47,12 +47,12 @@
|
||||||
#include "propertieswidget.h"
|
#include "propertieswidget.h"
|
||||||
#include "torrentcontentmodelitem.h"
|
#include "torrentcontentmodelitem.h"
|
||||||
|
|
||||||
namespace {
|
namespace
|
||||||
|
{
|
||||||
|
|
||||||
QPalette progressBarDisabledPalette()
|
QPalette progressBarDisabledPalette()
|
||||||
{
|
{
|
||||||
auto getPalette = []()
|
auto getPalette = []() {
|
||||||
{
|
|
||||||
QProgressBar bar;
|
QProgressBar bar;
|
||||||
bar.setEnabled(false);
|
bar.setEnabled(false);
|
||||||
QStyleOptionProgressBar opt;
|
QStyleOptionProgressBar opt;
|
||||||
|
@ -64,8 +64,8 @@ namespace {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PropListDelegate::PropListDelegate(PropertiesWidget *properties, QObject *parent)
|
PropListDelegate::PropListDelegate(PropertiesWidget *properties)
|
||||||
: QItemDelegate(parent)
|
: QItemDelegate(properties)
|
||||||
, m_properties(properties)
|
, m_properties(properties)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -74,23 +74,22 @@ void PropListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &opti
|
||||||
{
|
{
|
||||||
painter->save();
|
painter->save();
|
||||||
QStyleOptionViewItem opt = QItemDelegate::setOptions(index, option);
|
QStyleOptionViewItem opt = QItemDelegate::setOptions(index, option);
|
||||||
|
QItemDelegate::drawBackground(painter, opt, index);
|
||||||
|
|
||||||
switch (index.column()) {
|
switch (index.column()) {
|
||||||
case PCSIZE:
|
case PCSIZE:
|
||||||
QItemDelegate::drawBackground(painter, opt, index);
|
|
||||||
QItemDelegate::drawDisplay(painter, opt, option.rect, Utils::Misc::friendlyUnit(index.data().toLongLong()));
|
|
||||||
break;
|
|
||||||
case REMAINING:
|
case REMAINING:
|
||||||
QItemDelegate::drawBackground(painter, opt, index);
|
|
||||||
QItemDelegate::drawDisplay(painter, opt, option.rect, Utils::Misc::friendlyUnit(index.data().toLongLong()));
|
QItemDelegate::drawDisplay(painter, opt, option.rect, Utils::Misc::friendlyUnit(index.data().toLongLong()));
|
||||||
break;
|
break;
|
||||||
case PROGRESS:
|
case PROGRESS: {
|
||||||
if (index.data().toDouble() >= 0) {
|
if (index.data().toDouble() < 0)
|
||||||
|
break;
|
||||||
|
|
||||||
QStyleOptionProgressBar newopt;
|
QStyleOptionProgressBar newopt;
|
||||||
qreal progress = index.data().toDouble() * 100.;
|
qreal progress = index.data().toDouble() * 100.;
|
||||||
newopt.rect = opt.rect;
|
newopt.rect = opt.rect;
|
||||||
newopt.text = ((progress == 100.0) ? QString("100%") : Utils::String::fromDouble(progress, 1) + "%");
|
newopt.text = ((progress == 100.0) ? QString("100%") : Utils::String::fromDouble(progress, 1) + "%");
|
||||||
newopt.progress = (int)progress;
|
newopt.progress = int(progress);
|
||||||
newopt.maximum = 100;
|
newopt.maximum = 100;
|
||||||
newopt.minimum = 0;
|
newopt.minimum = 0;
|
||||||
newopt.textVisible = true;
|
newopt.textVisible = true;
|
||||||
|
@ -98,23 +97,19 @@ void PropListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &opti
|
||||||
newopt.state &= ~QStyle::State_Enabled;
|
newopt.state &= ~QStyle::State_Enabled;
|
||||||
newopt.palette = progressBarDisabledPalette();
|
newopt.palette = progressBarDisabledPalette();
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
newopt.state |= QStyle::State_Enabled;
|
newopt.state |= QStyle::State_Enabled;
|
||||||
|
}
|
||||||
|
|
||||||
#ifndef Q_OS_WIN
|
#ifndef Q_OS_WIN
|
||||||
QApplication::style()->drawControl(QStyle::CE_ProgressBar, &newopt, painter);
|
QApplication::style()->drawControl(QStyle::CE_ProgressBar, &newopt, painter);
|
||||||
#else
|
#else
|
||||||
// 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("fusion").drawControl(QStyle::CE_ProgressBar, &newopt, painter, 0);
|
||||||
st.drawControl(QStyle::CE_ProgressBar, &newopt, painter, 0);
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
// Do not display anything if the file is disabled (progress == 0)
|
|
||||||
QItemDelegate::drawBackground(painter, opt, index);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case PRIORITY: {
|
case PRIORITY: {
|
||||||
QItemDelegate::drawBackground(painter, opt, index);
|
|
||||||
QString text = "";
|
QString text = "";
|
||||||
switch (index.data().toInt()) {
|
switch (index.data().toInt()) {
|
||||||
case prio::MIXED:
|
case prio::MIXED:
|
||||||
|
|
|
@ -54,15 +54,15 @@ class PropListDelegate : public QItemDelegate
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PropListDelegate(PropertiesWidget *properties = 0, QObject *parent = 0);
|
PropListDelegate(PropertiesWidget *properties);
|
||||||
|
|
||||||
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
|
||||||
void setEditorData(QWidget *editor, const QModelIndex &index) const;
|
void setEditorData(QWidget *editor, const QModelIndex &index) const override;
|
||||||
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &/* option */, const QModelIndex &index) const;
|
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem & /* option */, const QModelIndex &index) const override;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const;
|
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override;
|
||||||
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &/* index */) const;
|
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex & /* index */) const override;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void filteredFilesChanged() const;
|
void filteredFilesChanged() const;
|
||||||
|
|
|
@ -47,19 +47,15 @@ void SearchListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &op
|
||||||
painter->save();
|
painter->save();
|
||||||
|
|
||||||
QStyleOptionViewItem opt = QItemDelegate::setOptions(index, option);
|
QStyleOptionViewItem opt = QItemDelegate::setOptions(index, option);
|
||||||
|
QItemDelegate::drawBackground(painter, opt, index);
|
||||||
|
|
||||||
switch (index.column()) {
|
switch (index.column()) {
|
||||||
case SearchSortModel::SIZE:
|
case SearchSortModel::SIZE:
|
||||||
QItemDelegate::drawBackground(painter, opt, index);
|
|
||||||
opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter;
|
opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter;
|
||||||
QItemDelegate::drawDisplay(painter, opt, option.rect, Utils::Misc::friendlyUnit(index.data().toLongLong()));
|
QItemDelegate::drawDisplay(painter, opt, option.rect, Utils::Misc::friendlyUnit(index.data().toLongLong()));
|
||||||
break;
|
break;
|
||||||
case SearchSortModel::SEEDS:
|
case SearchSortModel::SEEDS:
|
||||||
QItemDelegate::drawBackground(painter, opt, index);
|
|
||||||
opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter;
|
|
||||||
QItemDelegate::drawDisplay(painter, opt, option.rect, (index.data().toLongLong() >= 0) ? index.data().toString() : tr("Unknown"));
|
|
||||||
break;
|
|
||||||
case SearchSortModel::LEECHES:
|
case SearchSortModel::LEECHES:
|
||||||
QItemDelegate::drawBackground(painter, opt, index);
|
|
||||||
opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter;
|
opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter;
|
||||||
QItemDelegate::drawDisplay(painter, opt, option.rect, (index.data().toLongLong() >= 0) ? index.data().toString() : tr("Unknown"));
|
QItemDelegate::drawDisplay(painter, opt, option.rect, (index.data().toLongLong() >= 0) ? index.data().toString() : tr("Unknown"));
|
||||||
break;
|
break;
|
||||||
|
@ -73,5 +69,5 @@ void SearchListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &op
|
||||||
QWidget *SearchListDelegate::createEditor(QWidget *, const QStyleOptionViewItem &, const QModelIndex &) const
|
QWidget *SearchListDelegate::createEditor(QWidget *, const QStyleOptionViewItem &, const QModelIndex &) const
|
||||||
{
|
{
|
||||||
// No editor here
|
// No editor here
|
||||||
return 0;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,10 +36,10 @@
|
||||||
class SearchListDelegate: public QItemDelegate
|
class SearchListDelegate: public QItemDelegate
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit SearchListDelegate(QObject *parent = 0);
|
explicit SearchListDelegate(QObject *parent);
|
||||||
|
|
||||||
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
|
||||||
QWidget* createEditor(QWidget*, const QStyleOptionViewItem &, const QModelIndex &) const;
|
QWidget *createEditor(QWidget *, const QStyleOptionViewItem &, const QModelIndex &) const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue