Browse Source

Merge pull request #6487 from Chocobo1/ui

GUI polish
adaptive-webui-19844
sledgehammer999 8 years ago committed by GitHub
parent
commit
ae0a9d74c4
  1. 40
      src/gui/addnewtorrentdialog.cpp
  2. 29
      src/gui/properties/peerlistdelegate.h
  3. 32
      src/gui/properties/peerlistwidget.cpp
  4. 6
      src/gui/properties/peerlistwidget.h
  5. 129
      src/gui/properties/proplistdelegate.cpp
  6. 14
      src/gui/properties/proplistdelegate.h
  7. 12
      src/gui/search/searchlistdelegate.cpp
  8. 6
      src/gui/search/searchlistdelegate.h

40
src/gui/addnewtorrentdialog.cpp

@ -69,8 +69,11 @@ 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)
@ -89,7 +92,7 @@ AddNewTorrentDialog::AddNewTorrentDialog(QWidget *parent)
auto session = BitTorrent::Session::instance(); auto session = BitTorrent::Session::instance();
ui->startTorrentCheckBox->setChecked(!session->isAddTorrentPaused()); ui->startTorrentCheckBox->setChecked(!session->isAddTorrentPaused());
ui->comboTTM->blockSignals(true); //the TreeView size isn't correct if the slot does it job at this point ui->comboTTM->blockSignals(true); // the TreeView size isn't correct if the slot does it job at this point
ui->comboTTM->setCurrentIndex(!session->isAutoTMMDisabledByDefault()); ui->comboTTM->setCurrentIndex(!session->isAutoTMMDisabledByDefault());
ui->comboTTM->blockSignals(false); ui->comboTTM->blockSignals(false);
populateSavePathComboBox(); populateSavePathComboBox();
@ -183,9 +186,9 @@ void AddNewTorrentDialog::show(QString source, QWidget *parent)
if (Utils::Misc::isUrl(source)) { if (Utils::Misc::isUrl(source)) {
// Launch downloader // Launch downloader
Net::DownloadHandler *handler = Net::DownloadManager::instance()->downloadUrl(source, true, 10485760 /* 10MB */, true); Net::DownloadHandler *handler = Net::DownloadManager::instance()->downloadUrl(source, true, 10485760 /* 10MB */, true);
connect(handler, SIGNAL(downloadFinished(QString, QString)), dlg, SLOT(handleDownloadFinished(QString, QString))); connect(handler, SIGNAL(downloadFinished(QString,QString)), dlg, SLOT(handleDownloadFinished(QString,QString)));
connect(handler, SIGNAL(downloadFailed(QString, QString)), dlg, SLOT(handleDownloadFailed(QString, QString))); connect(handler, SIGNAL(downloadFailed(QString,QString)), dlg, SLOT(handleDownloadFailed(QString,QString)));
connect(handler, SIGNAL(redirectedToMagnet(QString, QString)), dlg, SLOT(handleRedirectedToMagnet(QString, QString))); connect(handler, SIGNAL(redirectedToMagnet(QString,QString)), dlg, SLOT(handleRedirectedToMagnet(QString,QString)));
} }
else { else {
bool ok = false; bool ok = false;
@ -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();
@ -321,7 +323,7 @@ void AddNewTorrentDialog::showAdvancedSettings(bool show)
ui->settings_group->setVisible(true); ui->settings_group->setVisible(true);
ui->infoGroup->setVisible(true); ui->infoGroup->setVisible(true);
ui->contentTreeView->setVisible(m_hasMetadata); ui->contentTreeView->setVisible(m_hasMetadata);
static_cast<QVBoxLayout*>(layout())->insertWidget(layout()->indexOf(ui->never_show_cb) + 1, ui->adv_button); static_cast<QVBoxLayout *>(layout())->insertWidget(layout()->indexOf(ui->never_show_cb) + 1, ui->adv_button);
} }
else { else {
ui->adv_button->setText(QString::fromUtf8(C_DOWN)); ui->adv_button->setText(QString::fromUtf8(C_DOWN));
@ -339,7 +341,7 @@ void AddNewTorrentDialog::saveSavePathHistory() const
// Get current history // Get current history
QStringList history = settings()->loadValue(KEY_SAVEPATHHISTORY).toStringList(); QStringList history = settings()->loadValue(KEY_SAVEPATHHISTORY).toStringList();
QList<QDir> historyDirs; QList<QDir> historyDirs;
foreach(const QString dir, history) foreach (const QString dir, history)
historyDirs << QDir(dir); historyDirs << QDir(dir);
if (!historyDirs.contains(selectedSavePath)) { if (!historyDirs.contains(selectedSavePath)) {
// Add save path to history // Add save path to history
@ -383,8 +385,8 @@ void AddNewTorrentDialog::updateDiskSpaceLabel()
QString size_string = torrent_size ? Utils::Misc::friendlyUnit(torrent_size) : QString(tr("Not Available", "This size is unavailable.")); QString size_string = torrent_size ? Utils::Misc::friendlyUnit(torrent_size) : QString(tr("Not Available", "This size is unavailable."));
size_string += " ("; size_string += " (";
size_string += tr("Free space on disk: %1").arg(Utils::Misc::friendlyUnit(Utils::Fs::freeDiskSpaceOnPath( size_string += tr("Free space on disk: %1").arg(Utils::Misc::friendlyUnit(Utils::Fs::freeDiskSpaceOnPath(
ui->savePathComboBox->itemData( ui->savePathComboBox->itemData(
ui->savePathComboBox->currentIndex()).toString()))); ui->savePathComboBox->currentIndex()).toString())));
size_string += ")"; size_string += ")";
ui->size_lbl->setText(size_string); ui->size_lbl->setText(size_string);
} }
@ -394,8 +396,8 @@ void AddNewTorrentDialog::onSavePathChanged(int index)
// Toggle default save path setting checkbox visibility // Toggle default save path setting checkbox visibility
ui->defaultSavePathCheckBox->setChecked(false); ui->defaultSavePathCheckBox->setChecked(false);
ui->defaultSavePathCheckBox->setVisible( ui->defaultSavePathCheckBox->setVisible(
QDir(ui->savePathComboBox->itemData(ui->savePathComboBox->currentIndex()).toString()) QDir(ui->savePathComboBox->itemData(ui->savePathComboBox->currentIndex()).toString())
!= QDir(BitTorrent::Session::instance()->defaultSavePath())); != QDir(BitTorrent::Session::instance()->defaultSavePath()));
// Remember index // Remember index
m_oldIndex = index; m_oldIndex = index;
@ -504,7 +506,7 @@ void AddNewTorrentDialog::renameSelectedFile()
QStringList path_items; QStringList path_items;
path_items << index.data().toString(); path_items << index.data().toString();
QModelIndex parent = m_contentModel->parent(index); QModelIndex parent = m_contentModel->parent(index);
while(parent.isValid()) { while (parent.isValid()) {
path_items.prepend(parent.data().toString()); path_items.prepend(parent.data().toString());
parent = m_contentModel->parent(parent); parent = m_contentModel->parent(parent);
} }
@ -579,7 +581,7 @@ void AddNewTorrentDialog::populateSavePathComboBox()
ui->savePathComboBox->addItem(Utils::Fs::toNativePath(savePath), savePath); ui->savePathComboBox->addItem(Utils::Fs::toNativePath(savePath), savePath);
} }
void AddNewTorrentDialog::displayContentTreeMenu(const QPoint&) void AddNewTorrentDialog::displayContentTreeMenu(const QPoint &)
{ {
QMenu myFilesLlistMenu; QMenu myFilesLlistMenu;
const QModelIndexList selectedRows = ui->contentTreeView->selectionModel()->selectedRows(0); const QModelIndexList selectedRows = ui->contentTreeView->selectionModel()->selectedRows(0);
@ -622,7 +624,7 @@ void AddNewTorrentDialog::displayContentTreeMenu(const QPoint&)
void AddNewTorrentDialog::accept() void AddNewTorrentDialog::accept()
{ {
if (!m_hasMetadata) if (!m_hasMetadata)
disconnect(this, SLOT(updateMetadata(const BitTorrent::TorrentInfo &))); disconnect(this, SLOT(updateMetadata(const BitTorrent::TorrentInfo&)));
BitTorrent::AddTorrentParams params; BitTorrent::AddTorrentParams params;
@ -720,10 +722,10 @@ 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&)));
// List files in torrent // List files in torrent
m_contentModel->model()->setupModelData(m_torrentInfo); m_contentModel->model()->setupModelData(m_torrentInfo);

29
src/gui/properties/peerlistdelegate.h

@ -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);
switch(index.column()) { QItemDelegate::drawBackground(painter, opt, index);
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,40 +87,38 @@ 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) + "%");
} }
break; break;
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

32
src/gui/properties/peerlistwidget.cpp

@ -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);
@ -102,7 +102,7 @@ PeerListWidget::PeerListWidget(PropertiesWidget *parent)
m_resolveCountries = Preferences::instance()->resolvePeerCountries(); m_resolveCountries = Preferences::instance()->resolvePeerCountries();
if (!m_resolveCountries) if (!m_resolveCountries)
hideColumn(PeerListDelegate::COUNTRY); hideColumn(PeerListDelegate::COUNTRY);
//Ensure that at least one column is visible at all times // Ensure that at least one column is visible at all times
bool atLeastOne = false; bool atLeastOne = false;
for (unsigned int i = 0; i < PeerListDelegate::IP_HIDDEN; i++) { for (unsigned int i = 0; i < PeerListDelegate::IP_HIDDEN; i++) {
if (!isColumnHidden(i)) { if (!isColumnHidden(i)) {
@ -112,9 +112,9 @@ PeerListWidget::PeerListWidget(PropertiesWidget *parent)
} }
if (!atLeastOne) if (!atLeastOne)
setColumnHidden(PeerListDelegate::IP, false); setColumnHidden(PeerListDelegate::IP, false);
//To also mitigate the above issue, we have to resize each column when // To also mitigate the above issue, we have to resize each column when
//its size is 0, because explicitly 'showing' the column isn't enough // its size is 0, because explicitly 'showing' the column isn't enough
//in the above scenario. // in the above scenario.
for (unsigned int i = 0; i < PeerListDelegate::IP_HIDDEN; i++) for (unsigned int i = 0; i < PeerListDelegate::IP_HIDDEN; i++)
if ((columnWidth(i) <= 0) && !isColumnHidden(i)) if ((columnWidth(i) <= 0) && !isColumnHidden(i))
resizeColumnToContents(i); resizeColumnToContents(i);
@ -130,7 +130,7 @@ PeerListWidget::PeerListWidget(PropertiesWidget *parent)
updatePeerHostNameResolutionState(); updatePeerHostNameResolutionState();
// SIGNAL/SLOT // SIGNAL/SLOT
header()->setContextMenuPolicy(Qt::CustomContextMenu); header()->setContextMenuPolicy(Qt::CustomContextMenu);
connect(header(), SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(displayToggleColumnsMenu(const QPoint &))); connect(header(), SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayToggleColumnsMenu(const QPoint&)));
connect(header(), SIGNAL(sectionClicked(int)), SLOT(handleSortColumnChanged(int))); connect(header(), SIGNAL(sectionClicked(int)), SLOT(handleSortColumnChanged(int)));
handleSortColumnChanged(header()->sortIndicatorSection()); handleSortColumnChanged(header()->sortIndicatorSection());
m_copyHotkey = new QShortcut(QKeySequence::Copy, this, SLOT(copySelectedPeers()), 0, Qt::WidgetShortcut); m_copyHotkey = new QShortcut(QKeySequence::Copy, this, SLOT(copySelectedPeers()), 0, Qt::WidgetShortcut);
@ -146,19 +146,15 @@ 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 &)
{ {
QMenu hideshowColumn(this); QMenu hideshowColumn(this);
hideshowColumn.setTitle(tr("Column visibility")); hideshowColumn.setTitle(tr("Column visibility"));
QList<QAction*> actions; QList<QAction *> actions;
for (int i = 0; i < PeerListDelegate::IP_HIDDEN; ++i) { for (int i = 0; i < PeerListDelegate::IP_HIDDEN; ++i) {
if ((i == PeerListDelegate::COUNTRY) && !Preferences::instance()->resolvePeerCountries()) { if ((i == PeerListDelegate::COUNTRY) && !Preferences::instance()->resolvePeerCountries()) {
actions.append(nullptr); // keep the index in sync actions.append(nullptr); // keep the index in sync
@ -199,7 +195,7 @@ void PeerListWidget::updatePeerHostNameResolutionState()
if (Preferences::instance()->resolvePeerHostNames()) { if (Preferences::instance()->resolvePeerHostNames()) {
if (!m_resolver) { if (!m_resolver) {
m_resolver = new Net::ReverseResolution(this); m_resolver = new Net::ReverseResolution(this);
connect(m_resolver, SIGNAL(ipResolved(QString, QString)), SLOT(handleResolved(QString, QString))); connect(m_resolver, SIGNAL(ipResolved(QString,QString)), SLOT(handleResolved(QString,QString)));
loadPeers(m_properties->getCurrentTorrent(), true); loadPeers(m_properties->getCurrentTorrent(), true);
} }
} }
@ -224,7 +220,7 @@ void PeerListWidget::updatePeerCountryResolutionState()
} }
} }
void PeerListWidget::showPeerListMenu(const QPoint&) void PeerListWidget::showPeerListMenu(const QPoint &)
{ {
QMenu menu; QMenu menu;
bool emptyMenu = true; bool emptyMenu = true;
@ -368,7 +364,7 @@ void PeerListWidget::loadPeers(BitTorrent::TorrentHandle *const torrent, bool fo
// Delete peers that are gone // Delete peers that are gone
QSetIterator<QString> it(oldeersSet); QSetIterator<QString> it(oldeersSet);
while (it.hasNext()) { while (it.hasNext()) {
const QString& ip = it.next(); const QString &ip = it.next();
m_missingFlags.remove(ip); m_missingFlags.remove(ip);
m_peerAddresses.remove(ip); m_peerAddresses.remove(ip);
QStandardItem *item = m_peerItems.take(ip); QStandardItem *item = m_peerItems.take(ip);
@ -376,7 +372,7 @@ void PeerListWidget::loadPeers(BitTorrent::TorrentHandle *const torrent, bool fo
} }
} }
QStandardItem* PeerListWidget::addPeer(const QString& ip, BitTorrent::TorrentHandle *const torrent, const BitTorrent::PeerInfo &peer) QStandardItem *PeerListWidget::addPeer(const QString &ip, BitTorrent::TorrentHandle *const torrent, const BitTorrent::PeerInfo &peer)
{ {
int row = m_listModel->rowCount(); int row = m_listModel->rowCount();
// Adding Peer to peer list // Adding Peer to peer list
@ -466,7 +462,7 @@ void PeerListWidget::wheelEvent(QWheelEvent *event)
{ {
event->accept(); event->accept();
if(event->modifiers() & Qt::ShiftModifier) { if (event->modifiers() & Qt::ShiftModifier) {
// Shift + scroll = horizontal scroll // Shift + scroll = horizontal scroll
QWheelEvent scrollHEvent(event->pos(), event->globalPos(), event->delta(), event->buttons(), event->modifiers(), Qt::Horizontal); QWheelEvent scrollHEvent(event->pos(), event->globalPos(), event->delta(), event->buttons(), event->modifiers(), Qt::Horizontal);
QTreeView::wheelEvent(&scrollHEvent); QTreeView::wheelEvent(&scrollHEvent);

6
src/gui/properties/peerlistwidget.h

@ -77,8 +77,8 @@ public:
private slots: private slots:
void loadSettings(); void loadSettings();
void saveSettings() const; void saveSettings() const;
void displayToggleColumnsMenu(const QPoint&); void displayToggleColumnsMenu(const QPoint &);
void showPeerListMenu(const QPoint&); void showPeerListMenu(const QPoint &);
void banSelectedPeers(); void banSelectedPeers();
void copySelectedPeers(); void copySelectedPeers();
void handleSortColumnChanged(int col); void handleSortColumnChanged(int col);
@ -90,7 +90,7 @@ private:
QStandardItemModel *m_listModel; QStandardItemModel *m_listModel;
PeerListDelegate *m_listDelegate; PeerListDelegate *m_listDelegate;
PeerListSortModel *m_proxyModel; PeerListSortModel *m_proxyModel;
QHash<QString, QStandardItem*> m_peerItems; QHash<QString, QStandardItem *> m_peerItems;
QHash<QString, BitTorrent::PeerAddress> m_peerAddresses; QHash<QString, BitTorrent::PeerAddress> m_peerAddresses;
QSet<QString> m_missingFlags; QSet<QString> m_missingFlags;
QPointer<Net::ReverseResolution> m_resolver; QPointer<Net::ReverseResolution> m_resolver;

129
src/gui/properties/proplistdelegate.cpp

@ -47,25 +47,25 @@
#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; opt.initFrom(&bar);
opt.initFrom(&bar); return opt.palette;
return opt.palette; };
};
static QPalette palette = getPalette(); static QPalette palette = getPalette();
return palette; return palette;
} }
} }
PropListDelegate::PropListDelegate(PropertiesWidget *properties, QObject *parent) PropListDelegate::PropListDelegate(PropertiesWidget *properties)
: QItemDelegate(parent) : QItemDelegate(properties)
, m_properties(properties) , m_properties(properties)
{ {
} }
@ -74,66 +74,61 @@ 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)
QStyleOptionProgressBar newopt; break;
qreal progress = index.data().toDouble() * 100.;
newopt.rect = opt.rect; QStyleOptionProgressBar newopt;
newopt.text = ((progress == 100.0) ? QString("100%") : Utils::String::fromDouble(progress, 1) + "%"); qreal progress = index.data().toDouble() * 100.;
newopt.progress = (int)progress; newopt.rect = opt.rect;
newopt.maximum = 100; newopt.text = ((progress == 100.0) ? QString("100%") : Utils::String::fromDouble(progress, 1) + "%");
newopt.minimum = 0; newopt.progress = int(progress);
newopt.textVisible = true; newopt.maximum = 100;
if (index.sibling(index.row(), PRIORITY).data().toInt() == prio::IGNORED) { newopt.minimum = 0;
newopt.state &= ~QStyle::State_Enabled; newopt.textVisible = true;
newopt.palette = progressBarDisabledPalette(); if (index.sibling(index.row(), PRIORITY).data().toInt() == prio::IGNORED) {
} newopt.state &= ~QStyle::State_Enabled;
else newopt.palette = progressBarDisabledPalette();
newopt.state |= QStyle::State_Enabled;
#ifndef Q_OS_WIN
QApplication::style()->drawControl(QStyle::CE_ProgressBar, &newopt, painter);
#else
// XXX: To avoid having the progress text on the right of the bar
QProxyStyle st("fusion");
st.drawControl(QStyle::CE_ProgressBar, &newopt, painter, 0);
#endif
} }
else { else {
// Do not display anything if the file is disabled (progress == 0) newopt.state |= QStyle::State_Enabled;
QItemDelegate::drawBackground(painter, opt, index);
} }
break;
#ifndef Q_OS_WIN
QApplication::style()->drawControl(QStyle::CE_ProgressBar, &newopt, painter);
#else
// XXX: To avoid having the progress text on the right of the bar
QProxyStyle("fusion").drawControl(QStyle::CE_ProgressBar, &newopt, painter, 0);
#endif
}
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: text = tr("Mixed", "Mixed (priorities");
text = tr("Mixed", "Mixed (priorities"); break;
break; case prio::IGNORED:
case prio::IGNORED: text = tr("Not downloaded");
text = tr("Not downloaded"); break;
break; case prio::HIGH:
case prio::HIGH: text = tr("High", "High (priority)");
text = tr("High", "High (priority)"); break;
break; case prio::MAXIMUM:
case prio::MAXIMUM: text = tr("Maximum", "Maximum (priority)");
text = tr("Maximum", "Maximum (priority)"); break;
break; default:
default: text = tr("Normal", "Normal (priority)");
text = tr("Normal", "Normal (priority)"); break;
break; }
} QItemDelegate::drawDisplay(painter, opt, option.rect, text);
QItemDelegate::drawDisplay(painter, opt, option.rect, text);
} }
break; break;
default: default:
@ -145,9 +140,9 @@ void PropListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &opti
void PropListDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const void PropListDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
{ {
QComboBox *combobox = static_cast<QComboBox*>(editor); QComboBox *combobox = static_cast<QComboBox *>(editor);
// Set combobox index // Set combobox index
switch(index.data().toInt()) { switch (index.data().toInt()) {
case prio::IGNORED: case prio::IGNORED:
combobox->setCurrentIndex(0); combobox->setCurrentIndex(0);
break; break;
@ -176,7 +171,7 @@ QWidget *PropListDelegate::createEditor(QWidget *parent, const QStyleOptionViewI
if (index.data().toInt() == prio::MIXED) if (index.data().toInt() == prio::MIXED)
return 0; return 0;
QComboBox* editor = new QComboBox(parent); QComboBox *editor = new QComboBox(parent);
editor->setFocusPolicy(Qt::StrongFocus); editor->setFocusPolicy(Qt::StrongFocus);
editor->addItem(tr("Do not download", "Do not download (priority)")); editor->addItem(tr("Do not download", "Do not download (priority)"));
editor->addItem(tr("Normal", "Normal (priority)")); editor->addItem(tr("Normal", "Normal (priority)"));
@ -187,11 +182,11 @@ QWidget *PropListDelegate::createEditor(QWidget *parent, const QStyleOptionViewI
void PropListDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const void PropListDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
{ {
QComboBox *combobox = static_cast<QComboBox*>(editor); QComboBox *combobox = static_cast<QComboBox *>(editor);
int value = combobox->currentIndex(); int value = combobox->currentIndex();
qDebug("PropListDelegate: setModelData(%d)", value); qDebug("PropListDelegate: setModelData(%d)", value);
switch(value) { switch (value) {
case 0: case 0:
model->setData(index, prio::IGNORED); // IGNORED model->setData(index, prio::IGNORED); // IGNORED
break; break;

14
src/gui/properties/proplistdelegate.h

@ -49,20 +49,20 @@ enum PropColumn
REMAINING REMAINING
}; };
class PropListDelegate : public QItemDelegate 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;

12
src/gui/search/searchlistdelegate.cpp

@ -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);
switch(index.column()) { QItemDelegate::drawBackground(painter, opt, index);
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;
} }

6
src/gui/search/searchlistdelegate.h

@ -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…
Cancel
Save