mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-08-20 21:33:27 -07:00
Add option to make progress bar to follow torrent state color
PR #22967. --------- Co-authored-by: Vladimir Golovnev <glassez@yandex.ru>
This commit is contained in:
parent
f5a93be544
commit
9fc7bd938f
7 changed files with 38 additions and 4 deletions
|
@ -186,6 +186,19 @@ void Preferences::setAlternatingRowColors(const bool b)
|
|||
setValue(u"Preferences/General/AlternatingRowColors"_s, b);
|
||||
}
|
||||
|
||||
bool Preferences::getProgressBarFollowsTextColor() const
|
||||
{
|
||||
return value(u"GUI/TransferList/ProgressBarFollowsTextColor"_s, false);
|
||||
}
|
||||
|
||||
void Preferences::setProgressBarFollowsTextColor(const bool value)
|
||||
{
|
||||
if (value == getProgressBarFollowsTextColor())
|
||||
return;
|
||||
|
||||
setValue(u"GUI/TransferList/ProgressBarFollowsTextColor"_s, value);
|
||||
}
|
||||
|
||||
bool Preferences::getHideZeroValues() const
|
||||
{
|
||||
return value(u"Preferences/General/HideZeroValues"_s, false);
|
||||
|
|
|
@ -113,6 +113,8 @@ public:
|
|||
void showSpeedInTitleBar(bool show);
|
||||
bool useAlternatingRowColors() const;
|
||||
void setAlternatingRowColors(bool b);
|
||||
bool getProgressBarFollowsTextColor() const;
|
||||
void setProgressBarFollowsTextColor(bool value);
|
||||
bool getHideZeroValues() const;
|
||||
void setHideZeroValues(bool b);
|
||||
int getHideZeroComboValues() const;
|
||||
|
|
|
@ -261,6 +261,7 @@ void OptionsDialog::loadBehaviorTabOptions()
|
|||
|
||||
m_ui->confirmDeletion->setChecked(pref->confirmTorrentDeletion());
|
||||
m_ui->checkAltRowColors->setChecked(pref->useAlternatingRowColors());
|
||||
m_ui->checkProgressBarFollowsTextColor->setChecked(pref->getProgressBarFollowsTextColor());
|
||||
m_ui->checkHideZero->setChecked(pref->getHideZeroValues());
|
||||
m_ui->comboHideZero->setCurrentIndex(pref->getHideZeroComboValues());
|
||||
m_ui->comboHideZero->setEnabled(m_ui->checkHideZero->isChecked());
|
||||
|
@ -389,6 +390,7 @@ void OptionsDialog::loadBehaviorTabOptions()
|
|||
|
||||
connect(m_ui->confirmDeletion, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
|
||||
connect(m_ui->checkAltRowColors, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
|
||||
connect(m_ui->checkProgressBarFollowsTextColor, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
|
||||
connect(m_ui->checkHideZero, &QAbstractButton::toggled, m_ui->comboHideZero, &QWidget::setEnabled);
|
||||
connect(m_ui->checkHideZero, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
|
||||
connect(m_ui->comboHideZero, qComboBoxCurrentIndexChanged, this, &ThisType::enableApplyButton);
|
||||
|
@ -483,6 +485,7 @@ void OptionsDialog::saveBehaviorTabOptions() const
|
|||
|
||||
pref->setConfirmTorrentDeletion(m_ui->confirmDeletion->isChecked());
|
||||
pref->setAlternatingRowColors(m_ui->checkAltRowColors->isChecked());
|
||||
pref->setProgressBarFollowsTextColor(m_ui->checkProgressBarFollowsTextColor->isChecked());
|
||||
pref->setHideZeroValues(m_ui->checkHideZero->isChecked());
|
||||
pref->setHideZeroComboValues(m_ui->comboHideZero->currentIndex());
|
||||
|
||||
|
|
|
@ -297,6 +297,13 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkProgressBarFollowsTextColor">
|
||||
<property name="text">
|
||||
<string extracomment="Progress bar color is based on text color.">Make progress bars follow text colors</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
|
|
|
@ -54,7 +54,7 @@ ProgressBarPainter::ProgressBarPainter(QObject *parent)
|
|||
connect(UIThemeManager::instance(), &UIThemeManager::themeChanged, this, &ProgressBarPainter::applyUITheme);
|
||||
}
|
||||
|
||||
void ProgressBarPainter::paint(QPainter *painter, const QStyleOptionViewItem &option, const QString &text, const int progress) 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);
|
||||
|
@ -72,8 +72,14 @@ 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 (m_chunkColor.isValid())
|
||||
if (color.isValid())
|
||||
{
|
||||
styleOption.palette.setColor(QPalette::Highlight, color);
|
||||
}
|
||||
else if (m_chunkColor.isValid())
|
||||
{
|
||||
styleOption.palette.setColor(QPalette::Highlight, m_chunkColor);
|
||||
}
|
||||
|
||||
painter->save();
|
||||
const QStyle *style = m_dummyProgressBar.style();
|
||||
|
|
|
@ -43,7 +43,7 @@ class ProgressBarPainter : public QObject
|
|||
public:
|
||||
explicit ProgressBarPainter(QObject *parent = nullptr);
|
||||
|
||||
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QString &text, int progress) const;
|
||||
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QString &text, int progress, const QColor &color = {}) const;
|
||||
|
||||
private:
|
||||
void applyUITheme();
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
|
||||
#include <QModelIndex>
|
||||
|
||||
#include "base/preferences.h"
|
||||
#include "transferlistmodel.h"
|
||||
|
||||
TransferListDelegate::TransferListDelegate(QObject *parent)
|
||||
|
@ -90,7 +91,9 @@ 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);
|
||||
const QColor color = Preferences::instance()->getProgressBarFollowsTextColor() ? index.data(Qt::ForegroundRole).value<QColor>() : QColor();
|
||||
|
||||
m_progressBarPainter.paint(painter, customOption, index.data().toString(), progress, color);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue