From 3ab9fe55e5ce6a435a9d739d1f2b7966128c33c8 Mon Sep 17 00:00:00 2001 From: Vladimir Golovnev Date: Mon, 21 Oct 2024 09:50:53 +0300 Subject: [PATCH] Improve color scheme change detection * Fix pieces bars won't correctly detect color scheme change with Qt 6.8. * Update RSS article content view on color scheme changed. PR #21625. Closes #21327. --- src/gui/properties/piecesbar.cpp | 16 +++--- src/gui/rss/rsswidget.cpp | 115 +++++++++++++++++++++++---------------- src/gui/rss/rsswidget.h | 8 +++ 3 files changed, 85 insertions(+), 54 deletions(-) diff --git a/src/gui/properties/piecesbar.cpp b/src/gui/properties/piecesbar.cpp index 780d63db5..87b941493 100644 --- a/src/gui/properties/piecesbar.cpp +++ b/src/gui/properties/piecesbar.cpp @@ -42,7 +42,6 @@ #include "base/indexrange.h" #include "base/path.h" #include "base/utils/misc.h" -#include "gui/uithememanager.h" namespace { @@ -119,13 +118,7 @@ PiecesBar::PiecesBar(QWidget *parent) : QWidget(parent) { setMouseTracking(true); - updateColorsImpl(); - connect(UIThemeManager::instance(), &UIThemeManager::themeChanged, this, [this] - { - updateColors(); - redraw(); - }); } void PiecesBar::setTorrent(const BitTorrent::Torrent *torrent) @@ -143,12 +136,19 @@ void PiecesBar::clear() bool PiecesBar::event(QEvent *e) { - if (e->type() == QEvent::ToolTip) + const QEvent::Type eventType = e->type(); + if (eventType == QEvent::ToolTip) { showToolTip(static_cast(e)); return true; } + if (eventType == QEvent::PaletteChange) + { + updateColors(); + redraw(); + } + return base::event(e); } diff --git a/src/gui/rss/rsswidget.cpp b/src/gui/rss/rsswidget.cpp index 75d0be77a..a6ca52b6c 100644 --- a/src/gui/rss/rsswidget.cpp +++ b/src/gui/rss/rsswidget.cpp @@ -126,6 +126,8 @@ RSSWidget::RSSWidget(IGUIApplication *app, QWidget *parent) , this, &RSSWidget::handleSessionProcessingStateChanged); connect(RSS::Session::instance()->rootFolder(), &RSS::Folder::unreadCountChanged , this, &RSSWidget::handleUnreadCountChanged); + + m_ui->textBrowser->installEventFilter(this); } RSSWidget::~RSSWidget() @@ -494,14 +496,76 @@ void RSSWidget::handleCurrentArticleItemChanged(QListWidgetItem *currentItem, QL article->markAsRead(); } - if (!currentItem) return; + if (!currentItem) + return; auto *article = m_articleListWidget->getRSSArticle(currentItem); + renderArticle(article); +} + +void RSSWidget::saveSlidersPosition() +{ + // Remember sliders positions + Preferences *const pref = Preferences::instance(); + pref->setRssSideSplitterState(m_ui->splitterSide->saveState()); + pref->setRssMainSplitterState(m_ui->splitterMain->saveState()); +} + +void RSSWidget::restoreSlidersPosition() +{ + const Preferences *const pref = Preferences::instance(); + const QByteArray stateSide = pref->getRssSideSplitterState(); + if (!stateSide.isEmpty()) + m_ui->splitterSide->restoreState(stateSide); + const QByteArray stateMain = pref->getRssMainSplitterState(); + if (!stateMain.isEmpty()) + m_ui->splitterMain->restoreState(stateMain); +} + +void RSSWidget::updateRefreshInterval(int val) const +{ + RSS::Session::instance()->setRefreshInterval(val); +} + +void RSSWidget::on_rssDownloaderBtn_clicked() +{ + auto *downloader = new AutomatedRssDownloader(this); + downloader->setAttribute(Qt::WA_DeleteOnClose); + downloader->open(); +} + +void RSSWidget::handleSessionProcessingStateChanged(bool enabled) +{ + m_ui->labelWarn->setVisible(!enabled); +} + +void RSSWidget::handleUnreadCountChanged() +{ + emit unreadCountUpdated(RSS::Session::instance()->rootFolder()->unreadCount()); +} + +bool RSSWidget::eventFilter(QObject *obj, QEvent *event) +{ + if ((obj == m_ui->textBrowser) && (event->type() == QEvent::PaletteChange)) + { + QListWidgetItem *currentItem = m_articleListWidget->currentItem(); + if (currentItem) + { + const RSS::Article *article = m_articleListWidget->getRSSArticle(currentItem); + renderArticle(article); + } + } + + return false; +} + +void RSSWidget::renderArticle(const RSS::Article *article) const +{ Q_ASSERT(article); - const QString highlightedBaseColor = m_ui->textBrowser->palette().color(QPalette::Highlight).name(); - const QString highlightedBaseTextColor = m_ui->textBrowser->palette().color(QPalette::HighlightedText).name(); - const QString alternateBaseColor = m_ui->textBrowser->palette().color(QPalette::AlternateBase).name(); + const QString highlightedBaseColor = m_ui->textBrowser->palette().color(QPalette::Active, QPalette::Highlight).name(); + const QString highlightedBaseTextColor = m_ui->textBrowser->palette().color(QPalette::Active, QPalette::HighlightedText).name(); + const QString alternateBaseColor = m_ui->textBrowser->palette().color(QPalette::Active, QPalette::AlternateBase).name(); QString html = u"
" + @@ -524,7 +588,7 @@ void RSSWidget::handleCurrentArticleItemChanged(QListWidgetItem *currentItem, QL QRegularExpression rx; // If description is plain text, replace BBCode tags with HTML and wrap everything in
 so it looks nice
         rx.setPatternOptions(QRegularExpression::InvertedGreedinessOption
-            | QRegularExpression::CaseInsensitiveOption);
+                             | QRegularExpression::CaseInsensitiveOption);
 
         rx.setPattern(u"\\[img\\](.+)\\[/img\\]"_s);
         description = description.replace(rx, u""_s);
@@ -549,44 +613,3 @@ void RSSWidget::handleCurrentArticleItemChanged(QListWidgetItem *currentItem, QL
     html += u"
"; m_ui->textBrowser->setHtml(html); } - -void RSSWidget::saveSlidersPosition() -{ - // Remember sliders positions - Preferences *const pref = Preferences::instance(); - pref->setRssSideSplitterState(m_ui->splitterSide->saveState()); - pref->setRssMainSplitterState(m_ui->splitterMain->saveState()); -} - -void RSSWidget::restoreSlidersPosition() -{ - const Preferences *const pref = Preferences::instance(); - const QByteArray stateSide = pref->getRssSideSplitterState(); - if (!stateSide.isEmpty()) - m_ui->splitterSide->restoreState(stateSide); - const QByteArray stateMain = pref->getRssMainSplitterState(); - if (!stateMain.isEmpty()) - m_ui->splitterMain->restoreState(stateMain); -} - -void RSSWidget::updateRefreshInterval(int val) const -{ - RSS::Session::instance()->setRefreshInterval(val); -} - -void RSSWidget::on_rssDownloaderBtn_clicked() -{ - auto *downloader = new AutomatedRssDownloader(this); - downloader->setAttribute(Qt::WA_DeleteOnClose); - downloader->open(); -} - -void RSSWidget::handleSessionProcessingStateChanged(bool enabled) -{ - m_ui->labelWarn->setVisible(!enabled); -} - -void RSSWidget::handleUnreadCountChanged() -{ - emit unreadCountUpdated(RSS::Session::instance()->rootFolder()->unreadCount()); -} diff --git a/src/gui/rss/rsswidget.h b/src/gui/rss/rsswidget.h index 5c5aaaa1b..cc1da53bc 100644 --- a/src/gui/rss/rsswidget.h +++ b/src/gui/rss/rsswidget.h @@ -40,6 +40,11 @@ class QTreeWidgetItem; class ArticleListWidget; class FeedListWidget; +namespace RSS +{ + class Article; +} + namespace Ui { class RSSWidget; @@ -85,6 +90,9 @@ private slots: void handleUnreadCountChanged(); private: + bool eventFilter(QObject *obj, QEvent *event) override; + void renderArticle(const RSS::Article *article) const; + Ui::RSSWidget *m_ui = nullptr; ArticleListWidget *m_articleListWidget = nullptr; FeedListWidget *m_feedListWidget = nullptr; -- 2.11.4.GIT