mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2024-10-22 10:46:04 +03:00
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.
This commit is contained in:
parent
ab8d0d1dae
commit
3ab9fe55e5
3 changed files with 91 additions and 60 deletions
|
@ -42,7 +42,6 @@
|
||||||
#include "base/indexrange.h"
|
#include "base/indexrange.h"
|
||||||
#include "base/path.h"
|
#include "base/path.h"
|
||||||
#include "base/utils/misc.h"
|
#include "base/utils/misc.h"
|
||||||
#include "gui/uithememanager.h"
|
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
@ -119,13 +118,7 @@ PiecesBar::PiecesBar(QWidget *parent)
|
||||||
: QWidget(parent)
|
: QWidget(parent)
|
||||||
{
|
{
|
||||||
setMouseTracking(true);
|
setMouseTracking(true);
|
||||||
|
|
||||||
updateColorsImpl();
|
updateColorsImpl();
|
||||||
connect(UIThemeManager::instance(), &UIThemeManager::themeChanged, this, [this]
|
|
||||||
{
|
|
||||||
updateColors();
|
|
||||||
redraw();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PiecesBar::setTorrent(const BitTorrent::Torrent *torrent)
|
void PiecesBar::setTorrent(const BitTorrent::Torrent *torrent)
|
||||||
|
@ -143,12 +136,19 @@ void PiecesBar::clear()
|
||||||
|
|
||||||
bool PiecesBar::event(QEvent *e)
|
bool PiecesBar::event(QEvent *e)
|
||||||
{
|
{
|
||||||
if (e->type() == QEvent::ToolTip)
|
const QEvent::Type eventType = e->type();
|
||||||
|
if (eventType == QEvent::ToolTip)
|
||||||
{
|
{
|
||||||
showToolTip(static_cast<QHelpEvent *>(e));
|
showToolTip(static_cast<QHelpEvent *>(e));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (eventType == QEvent::PaletteChange)
|
||||||
|
{
|
||||||
|
updateColors();
|
||||||
|
redraw();
|
||||||
|
}
|
||||||
|
|
||||||
return base::event(e);
|
return base::event(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -126,6 +126,8 @@ RSSWidget::RSSWidget(IGUIApplication *app, QWidget *parent)
|
||||||
, this, &RSSWidget::handleSessionProcessingStateChanged);
|
, this, &RSSWidget::handleSessionProcessingStateChanged);
|
||||||
connect(RSS::Session::instance()->rootFolder(), &RSS::Folder::unreadCountChanged
|
connect(RSS::Session::instance()->rootFolder(), &RSS::Folder::unreadCountChanged
|
||||||
, this, &RSSWidget::handleUnreadCountChanged);
|
, this, &RSSWidget::handleUnreadCountChanged);
|
||||||
|
|
||||||
|
m_ui->textBrowser->installEventFilter(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
RSSWidget::~RSSWidget()
|
RSSWidget::~RSSWidget()
|
||||||
|
@ -494,60 +496,11 @@ void RSSWidget::handleCurrentArticleItemChanged(QListWidgetItem *currentItem, QL
|
||||||
article->markAsRead();
|
article->markAsRead();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!currentItem) return;
|
if (!currentItem)
|
||||||
|
return;
|
||||||
|
|
||||||
auto *article = m_articleListWidget->getRSSArticle(currentItem);
|
auto *article = m_articleListWidget->getRSSArticle(currentItem);
|
||||||
Q_ASSERT(article);
|
renderArticle(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();
|
|
||||||
|
|
||||||
QString html =
|
|
||||||
u"<div style='border: 2px solid red; margin-left: 5px; margin-right: 5px; margin-bottom: 5px;'>" +
|
|
||||||
u"<div style='background-color: \"%1\"; font-weight: bold; color: \"%2\";'>%3</div>"_s.arg(highlightedBaseColor, highlightedBaseTextColor, article->title());
|
|
||||||
if (article->date().isValid())
|
|
||||||
html += u"<div style='background-color: \"%1\";'><b>%2</b>%3</div>"_s.arg(alternateBaseColor, tr("Date: "), QLocale::system().toString(article->date().toLocalTime()));
|
|
||||||
if (m_feedListWidget->currentItem() == m_feedListWidget->stickyUnreadItem())
|
|
||||||
html += u"<div style='background-color: \"%1\";'><b>%2</b>%3</div>"_s.arg(alternateBaseColor, tr("Feed: "), article->feed()->title());
|
|
||||||
if (!article->author().isEmpty())
|
|
||||||
html += u"<div style='background-color: \"%1\";'><b>%2</b>%3</div>"_s.arg(alternateBaseColor, tr("Author: "), article->author());
|
|
||||||
html += u"</div>"
|
|
||||||
u"<div style='margin-left: 5px; margin-right: 5px;'>";
|
|
||||||
if (Qt::mightBeRichText(article->description()))
|
|
||||||
{
|
|
||||||
html += article->description();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
QString description = article->description();
|
|
||||||
QRegularExpression rx;
|
|
||||||
// If description is plain text, replace BBCode tags with HTML and wrap everything in <pre></pre> so it looks nice
|
|
||||||
rx.setPatternOptions(QRegularExpression::InvertedGreedinessOption
|
|
||||||
| QRegularExpression::CaseInsensitiveOption);
|
|
||||||
|
|
||||||
rx.setPattern(u"\\[img\\](.+)\\[/img\\]"_s);
|
|
||||||
description = description.replace(rx, u"<img src=\"\\1\">"_s);
|
|
||||||
|
|
||||||
rx.setPattern(u"\\[url=(\")?(.+)\\1\\]"_s);
|
|
||||||
description = description.replace(rx, u"<a href=\"\\2\">"_s);
|
|
||||||
description = description.replace(u"[/url]"_s, u"</a>"_s, Qt::CaseInsensitive);
|
|
||||||
|
|
||||||
rx.setPattern(u"\\[(/)?([bius])\\]"_s);
|
|
||||||
description = description.replace(rx, u"<\\1\\2>"_s);
|
|
||||||
|
|
||||||
rx.setPattern(u"\\[color=(\")?(.+)\\1\\]"_s);
|
|
||||||
description = description.replace(rx, u"<span style=\"color:\\2\">"_s);
|
|
||||||
description = description.replace(u"[/color]"_s, u"</span>"_s, Qt::CaseInsensitive);
|
|
||||||
|
|
||||||
rx.setPattern(u"\\[size=(\")?(.+)\\d\\1\\]"_s);
|
|
||||||
description = description.replace(rx, u"<span style=\"font-size:\\2px\">"_s);
|
|
||||||
description = description.replace(u"[/size]"_s, u"</span>"_s, Qt::CaseInsensitive);
|
|
||||||
|
|
||||||
html += u"<pre>" + description + u"</pre>";
|
|
||||||
}
|
|
||||||
html += u"</div>";
|
|
||||||
m_ui->textBrowser->setHtml(html);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RSSWidget::saveSlidersPosition()
|
void RSSWidget::saveSlidersPosition()
|
||||||
|
@ -590,3 +543,73 @@ void RSSWidget::handleUnreadCountChanged()
|
||||||
{
|
{
|
||||||
emit unreadCountUpdated(RSS::Session::instance()->rootFolder()->unreadCount());
|
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::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"<div style='border: 2px solid red; margin-left: 5px; margin-right: 5px; margin-bottom: 5px;'>" +
|
||||||
|
u"<div style='background-color: \"%1\"; font-weight: bold; color: \"%2\";'>%3</div>"_s.arg(highlightedBaseColor, highlightedBaseTextColor, article->title());
|
||||||
|
if (article->date().isValid())
|
||||||
|
html += u"<div style='background-color: \"%1\";'><b>%2</b>%3</div>"_s.arg(alternateBaseColor, tr("Date: "), QLocale::system().toString(article->date().toLocalTime()));
|
||||||
|
if (m_feedListWidget->currentItem() == m_feedListWidget->stickyUnreadItem())
|
||||||
|
html += u"<div style='background-color: \"%1\";'><b>%2</b>%3</div>"_s.arg(alternateBaseColor, tr("Feed: "), article->feed()->title());
|
||||||
|
if (!article->author().isEmpty())
|
||||||
|
html += u"<div style='background-color: \"%1\";'><b>%2</b>%3</div>"_s.arg(alternateBaseColor, tr("Author: "), article->author());
|
||||||
|
html += u"</div>"
|
||||||
|
u"<div style='margin-left: 5px; margin-right: 5px;'>";
|
||||||
|
if (Qt::mightBeRichText(article->description()))
|
||||||
|
{
|
||||||
|
html += article->description();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
QString description = article->description();
|
||||||
|
QRegularExpression rx;
|
||||||
|
// If description is plain text, replace BBCode tags with HTML and wrap everything in <pre></pre> so it looks nice
|
||||||
|
rx.setPatternOptions(QRegularExpression::InvertedGreedinessOption
|
||||||
|
| QRegularExpression::CaseInsensitiveOption);
|
||||||
|
|
||||||
|
rx.setPattern(u"\\[img\\](.+)\\[/img\\]"_s);
|
||||||
|
description = description.replace(rx, u"<img src=\"\\1\">"_s);
|
||||||
|
|
||||||
|
rx.setPattern(u"\\[url=(\")?(.+)\\1\\]"_s);
|
||||||
|
description = description.replace(rx, u"<a href=\"\\2\">"_s);
|
||||||
|
description = description.replace(u"[/url]"_s, u"</a>"_s, Qt::CaseInsensitive);
|
||||||
|
|
||||||
|
rx.setPattern(u"\\[(/)?([bius])\\]"_s);
|
||||||
|
description = description.replace(rx, u"<\\1\\2>"_s);
|
||||||
|
|
||||||
|
rx.setPattern(u"\\[color=(\")?(.+)\\1\\]"_s);
|
||||||
|
description = description.replace(rx, u"<span style=\"color:\\2\">"_s);
|
||||||
|
description = description.replace(u"[/color]"_s, u"</span>"_s, Qt::CaseInsensitive);
|
||||||
|
|
||||||
|
rx.setPattern(u"\\[size=(\")?(.+)\\d\\1\\]"_s);
|
||||||
|
description = description.replace(rx, u"<span style=\"font-size:\\2px\">"_s);
|
||||||
|
description = description.replace(u"[/size]"_s, u"</span>"_s, Qt::CaseInsensitive);
|
||||||
|
|
||||||
|
html += u"<pre>" + description + u"</pre>";
|
||||||
|
}
|
||||||
|
html += u"</div>";
|
||||||
|
m_ui->textBrowser->setHtml(html);
|
||||||
|
}
|
||||||
|
|
|
@ -40,6 +40,11 @@ class QTreeWidgetItem;
|
||||||
class ArticleListWidget;
|
class ArticleListWidget;
|
||||||
class FeedListWidget;
|
class FeedListWidget;
|
||||||
|
|
||||||
|
namespace RSS
|
||||||
|
{
|
||||||
|
class Article;
|
||||||
|
}
|
||||||
|
|
||||||
namespace Ui
|
namespace Ui
|
||||||
{
|
{
|
||||||
class RSSWidget;
|
class RSSWidget;
|
||||||
|
@ -85,6 +90,9 @@ private slots:
|
||||||
void handleUnreadCountChanged();
|
void handleUnreadCountChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
bool eventFilter(QObject *obj, QEvent *event) override;
|
||||||
|
void renderArticle(const RSS::Article *article) const;
|
||||||
|
|
||||||
Ui::RSSWidget *m_ui = nullptr;
|
Ui::RSSWidget *m_ui = nullptr;
|
||||||
ArticleListWidget *m_articleListWidget = nullptr;
|
ArticleListWidget *m_articleListWidget = nullptr;
|
||||||
FeedListWidget *m_feedListWidget = nullptr;
|
FeedListWidget *m_feedListWidget = nullptr;
|
||||||
|
|
Loading…
Reference in a new issue