From 0904f4a89bf93594d431650a1ffa4a95c9db7481 Mon Sep 17 00:00:00 2001 From: Vladimir Golovnev Date: Wed, 21 Aug 2024 15:08:14 +0300 Subject: [PATCH] Refresh search results colors once color scheme is changed * Refresh search results colors once color scheme is changed * Improve color of visited search result items PR #21189. Closes #21187. --- src/gui/search/searchjobwidget.cpp | 44 +++++++++++++++++++++++++++++++++++--- src/gui/search/searchjobwidget.h | 6 ++++-- 2 files changed, 45 insertions(+), 5 deletions(-) diff --git a/src/gui/search/searchjobwidget.cpp b/src/gui/search/searchjobwidget.cpp index ae280adb4..bd637262e 100644 --- a/src/gui/search/searchjobwidget.cpp +++ b/src/gui/search/searchjobwidget.cpp @@ -1,6 +1,6 @@ /* * Bittorrent Client using Qt and libtorrent. - * Copyright (C) 2018 Vladimir Golovnev + * Copyright (C) 2018-2024 Vladimir Golovnev * Copyright (C) 2006 Christophe Dumez * * This program is free software; you can redistribute it and/or @@ -50,6 +50,19 @@ #include "searchsortmodel.h" #include "ui_searchjobwidget.h" +namespace +{ + enum DataRole + { + LinkVisitedRole = Qt::UserRole + 100 + }; + + QColor visitedRowColor() + { + return QApplication::palette().color(QPalette::Disabled, QPalette::WindowText); + } +} + SearchJobWidget::SearchJobWidget(SearchHandler *searchHandler, IGUIApplication *app, QWidget *parent) : GUIApplicationComponent(app, parent) , m_ui {new Ui::SearchJobWidget} @@ -158,6 +171,8 @@ SearchJobWidget::SearchJobWidget(SearchHandler *searchHandler, IGUIApplication * connect(this, &QObject::destroyed, searchHandler, &QObject::deleteLater); setStatusTip(statusText(m_status)); + + connect(UIThemeManager::instance(), &UIThemeManager::themeChanged, this, &SearchJobWidget::onUIThemeChanged); } SearchJobWidget::~SearchJobWidget() @@ -179,9 +194,31 @@ QHeaderView *SearchJobWidget::header() const // Set the color of a row in data model void SearchJobWidget::setRowColor(int row, const QColor &color) { - m_proxyModel->setDynamicSortFilter(false); for (int i = 0; i < m_proxyModel->columnCount(); ++i) m_proxyModel->setData(m_proxyModel->index(row, i), color, Qt::ForegroundRole); +} + +void SearchJobWidget::setRowVisited(const int row) +{ + m_proxyModel->setDynamicSortFilter(false); + + m_proxyModel->setData(m_proxyModel->index(row, 0), true, LinkVisitedRole); + setRowColor(row, visitedRowColor()); + + m_proxyModel->setDynamicSortFilter(true); +} + +void SearchJobWidget::onUIThemeChanged() +{ + m_proxyModel->setDynamicSortFilter(false); + + for (int row = 0; row < m_proxyModel->rowCount(); ++row) + { + const QVariant userData = m_proxyModel->data(m_proxyModel->index(row, 0), LinkVisitedRole); + const bool isVisited = userData.toBool(); + if (isVisited) + setRowColor(row, visitedRowColor()); + } m_proxyModel->setDynamicSortFilter(true); } @@ -284,7 +321,8 @@ void SearchJobWidget::downloadTorrent(const QModelIndex &rowIndex, const AddTorr , this, [this, option](const QString &source) { addTorrentToSession(source, option); }); connect(downloadHandler, &SearchDownloadHandler::downloadFinished, downloadHandler, &SearchDownloadHandler::deleteLater); } - setRowColor(rowIndex.row(), QApplication::palette().color(QPalette::LinkVisited)); + + setRowVisited(rowIndex.row()); } void SearchJobWidget::addTorrentToSession(const QString &source, const AddTorrentOption option) diff --git a/src/gui/search/searchjobwidget.h b/src/gui/search/searchjobwidget.h index 05e415c89..78d0ee5ab 100644 --- a/src/gui/search/searchjobwidget.h +++ b/src/gui/search/searchjobwidget.h @@ -1,6 +1,6 @@ /* * Bittorrent Client using Qt and libtorrent. - * Copyright (C) 2018 Vladimir Golovnev + * Copyright (C) 2018-2024 Vladimir Golovnev * Copyright (C) 2006 Christophe Dumez * * This program is free software; you can redistribute it and/or @@ -113,8 +113,10 @@ private: void fillFilterComboBoxes(); NameFilteringMode filteringMode() const; QHeaderView *header() const; - void setRowColor(int row, const QColor &color); int visibleColumnsCount() const; + void setRowColor(int row, const QColor &color); + void setRowVisited(int row); + void onUIThemeChanged(); void downloadTorrents(AddTorrentOption option = AddTorrentOption::Default); void openTorrentPages() const; -- 2.11.4.GIT