diff --git a/src/gui/progressbarpainter.cpp b/src/gui/progressbarpainter.cpp index 8788f5f7a..1f0d40c7c 100644 --- a/src/gui/progressbarpainter.cpp +++ b/src/gui/progressbarpainter.cpp @@ -1,5 +1,6 @@ /* * Bittorrent Client using Qt and libtorrent. + * Copyright (C) 2025 Vladimir Golovnev * Copyright (C) 2020 Prince Gupta * * This program is free software; you can redistribute it and/or @@ -38,14 +39,19 @@ #endif #include "base/global.h" +#include "gui/uithememanager.h" -ProgressBarPainter::ProgressBarPainter() +ProgressBarPainter::ProgressBarPainter(QObject *parent) + : QObject(parent) { #if (defined(Q_OS_WIN) || defined(Q_OS_MACOS)) - auto *fusionStyle = new QProxyStyle {u"fusion"_s}; + auto *fusionStyle = new QProxyStyle(u"fusion"_s); fusionStyle->setParent(&m_dummyProgressBar); m_dummyProgressBar.setStyle(fusionStyle); #endif + + applyUITheme(); + connect(UIThemeManager::instance(), &UIThemeManager::themeChanged, this, &ProgressBarPainter::applyUITheme); } void ProgressBarPainter::paint(QPainter *painter, const QStyleOptionViewItem &option, const QString &text, const int progress) const @@ -66,9 +72,17 @@ 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()) + styleOption.palette.setColor(QPalette::Highlight, m_chunkColor); + painter->save(); const QStyle *style = m_dummyProgressBar.style(); style->drawPrimitive(QStyle::PE_PanelItemViewItem, &option, painter, option.widget); style->drawControl(QStyle::CE_ProgressBar, &styleOption, painter, &m_dummyProgressBar); painter->restore(); } + +void ProgressBarPainter::applyUITheme() +{ + m_chunkColor = UIThemeManager::instance()->getColor(u"ProgressBar"_s); +} diff --git a/src/gui/progressbarpainter.h b/src/gui/progressbarpainter.h index b6ecac377..cf0ea1932 100644 --- a/src/gui/progressbarpainter.h +++ b/src/gui/progressbarpainter.h @@ -1,5 +1,6 @@ /* * Bittorrent Client using Qt and libtorrent. + * Copyright (C) 2025 Vladimir Golovnev * Copyright (C) 2020 Prince Gupta * * This program is free software; you can redistribute it and/or @@ -28,18 +29,26 @@ #pragma once +#include +#include #include class QStyleOptionViewItem; -class ProgressBarPainter +class ProgressBarPainter : public QObject { + Q_OBJECT + Q_DISABLE_COPY_MOVE(ProgressBarPainter) + public: - ProgressBarPainter(); + explicit ProgressBarPainter(QObject *parent = nullptr); void paint(QPainter *painter, const QStyleOptionViewItem &option, const QString &text, int progress) const; private: + void applyUITheme(); + + QColor m_chunkColor; // for painting progressbar with stylesheet option, a dummy progress bar is required QProgressBar m_dummyProgressBar; }; diff --git a/src/gui/uithemecommon.h b/src/gui/uithemecommon.h index 0be241fb3..2b808101e 100644 --- a/src/gui/uithemecommon.h +++ b/src/gui/uithemecommon.h @@ -85,7 +85,9 @@ inline QHash defaultUIThemeColors() {u"PiecesBar.Border"_s, {{}, {}}}, {u"PiecesBar.Piece"_s, {{}, {}}}, {u"PiecesBar.PartialPiece"_s, {{}, {}}}, - {u"PiecesBar.MissingPiece"_s, {{}, {}}} + {u"PiecesBar.MissingPiece"_s, {{}, {}}}, + + {u"ProgressBar"_s, {{}, {}}} }; } diff --git a/src/gui/uithemedialog.cpp b/src/gui/uithemedialog.cpp index 2d06ceeba..5b629d171 100644 --- a/src/gui/uithemedialog.cpp +++ b/src/gui/uithemedialog.cpp @@ -28,6 +28,7 @@ #include "uithemedialog.h" +#include #include #include #include @@ -233,6 +234,10 @@ UIThemeDialog::UIThemeDialog(QWidget *parent) { m_ui->setupUi(this); +#if (defined(Q_OS_WIN) || defined(Q_OS_MACOS)) + m_ui->colorsWarningLabel->hide(); +#endif + connect(m_ui->buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept); connect(m_ui->buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject); diff --git a/src/gui/uithemedialog.ui b/src/gui/uithemedialog.ui index c2de159d0..8c8f1a7ca 100644 --- a/src/gui/uithemedialog.ui +++ b/src/gui/uithemedialog.ui @@ -72,6 +72,21 @@ + + + + Note that some custom colors may not be applied in some desktop environments. + + + true + + + + true + + + +