mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-08-21 13:53:37 -07:00
revert progressbarpainter.
add QColor param to progressbarpainter.paint transferlistdelegate.cpp determines progress bar color
This commit is contained in:
parent
01bb6b8d18
commit
ed2090261b
4 changed files with 57 additions and 59 deletions
|
@ -39,51 +39,8 @@
|
|||
#endif
|
||||
|
||||
#include "base/global.h"
|
||||
#include "base/bittorrent/torrent.h"
|
||||
#include "gui/uithememanager.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
QHash<BitTorrent::TorrentState, QColor> torrentStateColorsFromUITheme()
|
||||
{
|
||||
struct TorrentStateColorDescriptor
|
||||
{
|
||||
const BitTorrent::TorrentState state;
|
||||
const QString id;
|
||||
};
|
||||
|
||||
const TorrentStateColorDescriptor colorDescriptors[] =
|
||||
{
|
||||
{BitTorrent::TorrentState::Downloading, u"TransferList.Downloading"_s},
|
||||
{BitTorrent::TorrentState::StalledDownloading, u"TransferList.StalledDownloading"_s},
|
||||
{BitTorrent::TorrentState::DownloadingMetadata, u"TransferList.DownloadingMetadata"_s},
|
||||
{BitTorrent::TorrentState::ForcedDownloadingMetadata, u"TransferList.ForcedDownloadingMetadata"_s},
|
||||
{BitTorrent::TorrentState::ForcedDownloading, u"TransferList.ForcedDownloading"_s},
|
||||
{BitTorrent::TorrentState::Uploading, u"TransferList.Uploading"_s},
|
||||
{BitTorrent::TorrentState::StalledUploading, u"TransferList.StalledUploading"_s},
|
||||
{BitTorrent::TorrentState::ForcedUploading, u"TransferList.ForcedUploading"_s},
|
||||
{BitTorrent::TorrentState::QueuedDownloading, u"TransferList.QueuedDownloading"_s},
|
||||
{BitTorrent::TorrentState::QueuedUploading, u"TransferList.QueuedUploading"_s},
|
||||
{BitTorrent::TorrentState::CheckingDownloading, u"TransferList.CheckingDownloading"_s},
|
||||
{BitTorrent::TorrentState::CheckingUploading, u"TransferList.CheckingUploading"_s},
|
||||
{BitTorrent::TorrentState::CheckingResumeData, u"TransferList.CheckingResumeData"_s},
|
||||
{BitTorrent::TorrentState::StoppedDownloading, u"TransferList.StoppedDownloading"_s},
|
||||
{BitTorrent::TorrentState::StoppedUploading, u"TransferList.StoppedUploading"_s},
|
||||
{BitTorrent::TorrentState::Moving, u"TransferList.Moving"_s},
|
||||
{BitTorrent::TorrentState::MissingFiles, u"TransferList.MissingFiles"_s},
|
||||
{BitTorrent::TorrentState::Error, u"TransferList.Error"_s}
|
||||
};
|
||||
|
||||
QHash<BitTorrent::TorrentState, QColor> colors;
|
||||
for (const TorrentStateColorDescriptor &colorDescriptor : colorDescriptors)
|
||||
{
|
||||
const QColor themeColor = UIThemeManager::instance()->getColor(colorDescriptor.id);
|
||||
colors.insert(colorDescriptor.state, themeColor);
|
||||
}
|
||||
return colors;
|
||||
}
|
||||
}
|
||||
|
||||
ProgressBarPainter::ProgressBarPainter(QObject *parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
|
@ -93,12 +50,11 @@ ProgressBarPainter::ProgressBarPainter(QObject *parent)
|
|||
m_dummyProgressBar.setStyle(fusionStyle);
|
||||
#endif
|
||||
|
||||
loadUIThemeResources();
|
||||
applyUITheme();
|
||||
connect(UIThemeManager::instance(), &UIThemeManager::themeChanged, this, &ProgressBarPainter::applyUITheme);
|
||||
}
|
||||
|
||||
void ProgressBarPainter::paint(QPainter *painter, const QStyleOptionViewItem &option, const QString &text, const int progress, const BitTorrent::TorrentState torrentState) const
|
||||
void ProgressBarPainter::paint(QPainter *painter, const QStyleOptionViewItem &option, const QString &text, const int progress, const QColor color) const
|
||||
{
|
||||
QStyleOptionProgressBar styleOption;
|
||||
styleOption.initFrom(&m_dummyProgressBar);
|
||||
|
@ -116,9 +72,9 @@ void ProgressBarPainter::paint(QPainter *painter, const QStyleOptionViewItem &op
|
|||
const bool isEnabled = option.state.testFlag(QStyle::State_Enabled);
|
||||
styleOption.palette.setCurrentColorGroup(isEnabled ? QPalette::Active : QPalette::Disabled);
|
||||
|
||||
if (torrentState != BitTorrent::TorrentState::Unknown)
|
||||
if (color != nullptr)
|
||||
{
|
||||
styleOption.palette.setColor(QPalette::Highlight, m_stateThemeColors.value(torrentState));
|
||||
styleOption.palette.setColor(QPalette::Highlight, color);
|
||||
}
|
||||
else if (m_chunkColor.isValid())
|
||||
{
|
||||
|
@ -136,9 +92,3 @@ void ProgressBarPainter::applyUITheme()
|
|||
{
|
||||
m_chunkColor = UIThemeManager::instance()->getColor(u"ProgressBar"_s);
|
||||
}
|
||||
|
||||
void ProgressBarPainter::loadUIThemeResources()
|
||||
{
|
||||
m_stateThemeColors = torrentStateColorsFromUITheme();
|
||||
}
|
||||
|
||||
|
|
|
@ -33,8 +33,6 @@
|
|||
#include <QObject>
|
||||
#include <QProgressBar>
|
||||
|
||||
#include "base/bittorrent/torrent.h"
|
||||
|
||||
class QStyleOptionViewItem;
|
||||
|
||||
class ProgressBarPainter : public QObject
|
||||
|
@ -45,12 +43,10 @@ class ProgressBarPainter : public QObject
|
|||
public:
|
||||
explicit ProgressBarPainter(QObject *parent = nullptr);
|
||||
|
||||
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QString &text, int progress, BitTorrent::TorrentState state = BitTorrent::TorrentState::Unknown) const;
|
||||
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QString &text, int progress, QColor color = nullptr) const;
|
||||
|
||||
private:
|
||||
void applyUITheme();
|
||||
void loadUIThemeResources();
|
||||
QHash<BitTorrent::TorrentState, QColor> m_stateThemeColors;
|
||||
|
||||
QColor m_chunkColor;
|
||||
// for painting progressbar with stylesheet option, a dummy progress bar is required
|
||||
|
|
|
@ -31,10 +31,54 @@
|
|||
#include <QModelIndex>
|
||||
|
||||
#include "transferlistmodel.h"
|
||||
#include "uithememanager.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
QHash<BitTorrent::TorrentState, QColor> torrentStateColorsFromUITheme()
|
||||
{
|
||||
struct TorrentStateColorDescriptor
|
||||
{
|
||||
const BitTorrent::TorrentState state;
|
||||
const QString id;
|
||||
};
|
||||
|
||||
const TorrentStateColorDescriptor colorDescriptors[] =
|
||||
{
|
||||
{BitTorrent::TorrentState::Downloading, u"TransferList.Downloading"_s},
|
||||
{BitTorrent::TorrentState::StalledDownloading, u"TransferList.StalledDownloading"_s},
|
||||
{BitTorrent::TorrentState::DownloadingMetadata, u"TransferList.DownloadingMetadata"_s},
|
||||
{BitTorrent::TorrentState::ForcedDownloadingMetadata, u"TransferList.ForcedDownloadingMetadata"_s},
|
||||
{BitTorrent::TorrentState::ForcedDownloading, u"TransferList.ForcedDownloading"_s},
|
||||
{BitTorrent::TorrentState::Uploading, u"TransferList.Uploading"_s},
|
||||
{BitTorrent::TorrentState::StalledUploading, u"TransferList.StalledUploading"_s},
|
||||
{BitTorrent::TorrentState::ForcedUploading, u"TransferList.ForcedUploading"_s},
|
||||
{BitTorrent::TorrentState::QueuedDownloading, u"TransferList.QueuedDownloading"_s},
|
||||
{BitTorrent::TorrentState::QueuedUploading, u"TransferList.QueuedUploading"_s},
|
||||
{BitTorrent::TorrentState::CheckingDownloading, u"TransferList.CheckingDownloading"_s},
|
||||
{BitTorrent::TorrentState::CheckingUploading, u"TransferList.CheckingUploading"_s},
|
||||
{BitTorrent::TorrentState::CheckingResumeData, u"TransferList.CheckingResumeData"_s},
|
||||
{BitTorrent::TorrentState::StoppedDownloading, u"TransferList.StoppedDownloading"_s},
|
||||
{BitTorrent::TorrentState::StoppedUploading, u"TransferList.StoppedUploading"_s},
|
||||
{BitTorrent::TorrentState::Moving, u"TransferList.Moving"_s},
|
||||
{BitTorrent::TorrentState::MissingFiles, u"TransferList.MissingFiles"_s},
|
||||
{BitTorrent::TorrentState::Error, u"TransferList.Error"_s}
|
||||
};
|
||||
|
||||
QHash<BitTorrent::TorrentState, QColor> colors;
|
||||
for (const TorrentStateColorDescriptor &colorDescriptor : colorDescriptors)
|
||||
{
|
||||
const QColor themeColor = UIThemeManager::instance()->getColor(colorDescriptor.id);
|
||||
colors.insert(colorDescriptor.state, themeColor);
|
||||
}
|
||||
return colors;
|
||||
}
|
||||
}
|
||||
|
||||
TransferListDelegate::TransferListDelegate(QObject *parent)
|
||||
: QStyledItemDelegate {parent}
|
||||
{
|
||||
m_stateThemeColors = torrentStateColorsFromUITheme();
|
||||
}
|
||||
|
||||
QWidget *TransferListDelegate::createEditor(QWidget *, const QStyleOptionViewItem &, const QModelIndex &) const
|
||||
|
@ -90,7 +134,13 @@ void TransferListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &
|
|||
QStyleOptionViewItem customOption {option};
|
||||
customOption.state.setFlag(QStyle::State_Enabled, isEnableState(torrentState));
|
||||
|
||||
m_progressBarPainter.paint(painter, customOption, index.data().toString(), progress, torrentState);
|
||||
QColor color = nullptr;
|
||||
if (torrentState != TorrentState::Unknown)
|
||||
{
|
||||
color = m_stateThemeColors.value(torrentState);
|
||||
}
|
||||
|
||||
m_progressBarPainter.paint(painter, customOption, index.data().toString(), progress, color);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
#include <QStyledItemDelegate>
|
||||
|
||||
#include "progressbarpainter.h"
|
||||
#include "base/bittorrent/torrent.h"
|
||||
|
||||
class TransferListDelegate final : public QStyledItemDelegate
|
||||
{
|
||||
|
@ -47,4 +48,5 @@ public:
|
|||
private:
|
||||
ProgressBarPainter m_progressBarPainter;
|
||||
mutable int m_nameColHeight = -1;
|
||||
QHash<BitTorrent::TorrentState, QColor> m_stateThemeColors;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue