Browse Source

Use a disabled progressbar's palette for unselected files.

Thanks to evsh(Eugene Shalygin) for example code.
adaptive-webui-19844
sledgehammer999 8 years ago
parent
commit
3e375128c0
No known key found for this signature in database
GPG Key ID: 6E4A2D025B7CC9A2
  1. 30
      src/gui/properties/proplistdelegate.cpp
  2. 1
      src/gui/torrentcontentfiltermodel.h
  3. 7
      src/gui/torrentcontentmodel.cpp

30
src/gui/properties/proplistdelegate.cpp

@ -28,14 +28,12 @@
* Contact : chris@qbittorrent.org * Contact : chris@qbittorrent.org
*/ */
#include <QStyleOptionProgressBar>
#include <QStyleOptionViewItem>
#include <QStyleOptionComboBox>
#include <QComboBox> #include <QComboBox>
#include <QModelIndex> #include <QModelIndex>
#include <QPainter> #include <QPainter>
#include <QPalette>
#include <QProgressBar> #include <QProgressBar>
#include <QApplication> #include <QStyleOptionProgressBar>
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
#ifndef QBT_USES_QT5 #ifndef QBT_USES_QT5
@ -51,6 +49,23 @@
#include "proplistdelegate.h" #include "proplistdelegate.h"
#include "torrentcontentmodelitem.h" #include "torrentcontentmodelitem.h"
namespace {
QPalette progressBarDisabledPalette()
{
auto getPalette = []()
{
QProgressBar bar;
bar.setEnabled(false);
QStyleOptionProgressBar opt;
opt.initFrom(&bar);
return opt.palette;
};
static QPalette palette = getPalette();
return palette;
}
}
PropListDelegate::PropListDelegate(PropertiesWidget *properties, QObject *parent) PropListDelegate::PropListDelegate(PropertiesWidget *properties, QObject *parent)
: QItemDelegate(parent) : QItemDelegate(parent)
, m_properties(properties) , m_properties(properties)
@ -85,8 +100,13 @@ void PropListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &opti
newopt.progress = (int)progress; newopt.progress = (int)progress;
newopt.maximum = 100; newopt.maximum = 100;
newopt.minimum = 0; newopt.minimum = 0;
newopt.state |= QStyle::State_Enabled;
newopt.textVisible = true; newopt.textVisible = true;
if (index.sibling(index.row(), PRIORITY).data().toInt() == prio::IGNORED) {
newopt.state &= ~QStyle::State_Enabled;
newopt.palette = progressBarDisabledPalette();
}
else
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

1
src/gui/torrentcontentfiltermodel.h

@ -33,7 +33,6 @@
#include <QSortFilterProxyModel> #include <QSortFilterProxyModel>
#include "torrentcontentmodelitem.h" #include "torrentcontentmodelitem.h"
#include "proplistdelegate.h"
class TorrentContentModel; class TorrentContentModel;

7
src/gui/torrentcontentmodel.cpp

@ -181,12 +181,14 @@ QVariant TorrentContentModel::data(const QModelIndex& index, int role) const
return QVariant(); return QVariant();
TorrentContentModelItem* item = static_cast<TorrentContentModelItem*>(index.internalPointer()); TorrentContentModelItem* item = static_cast<TorrentContentModelItem*>(index.internalPointer());
if ((index.column() == 0) && (role == Qt::DecorationRole)) { if ((index.column() == 0) && (role == Qt::DecorationRole)) {
if (item->itemType() == TorrentContentModelItem::FolderType) if (item->itemType() == TorrentContentModelItem::FolderType)
return getDirectoryIcon(); return getDirectoryIcon();
else else
return getFileIcon(); return getFileIcon();
} }
if ((index.column() == 0) && (role == Qt::CheckStateRole)) { if ((index.column() == 0) && (role == Qt::CheckStateRole)) {
if (item->data(TorrentContentModelItem::COL_PRIO).toInt() == prio::IGNORED) if (item->data(TorrentContentModelItem::COL_PRIO).toInt() == prio::IGNORED)
return Qt::Unchecked; return Qt::Unchecked;
@ -194,10 +196,11 @@ QVariant TorrentContentModel::data(const QModelIndex& index, int role) const
return Qt::PartiallyChecked; return Qt::PartiallyChecked;
return Qt::Checked; return Qt::Checked;
} }
if (role != Qt::DisplayRole)
return QVariant();
if (role == Qt::DisplayRole)
return item->data(index.column()); return item->data(index.column());
return QVariant();
} }
Qt::ItemFlags TorrentContentModel::flags(const QModelIndex& index) const Qt::ItemFlags TorrentContentModel::flags(const QModelIndex& index) const

Loading…
Cancel
Save