From 1cede857946a7bccfaef0ea531e96a8cdf390e6c Mon Sep 17 00:00:00 2001 From: Mark Date: Mon, 7 Jul 2025 06:43:52 +0400 Subject: [PATCH] revert utils.cpp/h get color from model --- src/gui/transferlistdelegate.cpp | 4 +-- src/gui/transferlistdelegate.h | 2 -- src/gui/transferlistmodel.cpp | 45 +++++++++++++++++++++++++++++-- src/gui/utils.cpp | 46 ++++---------------------------- src/gui/utils.h | 3 --- 5 files changed, 49 insertions(+), 51 deletions(-) diff --git a/src/gui/transferlistdelegate.cpp b/src/gui/transferlistdelegate.cpp index d6d070857..57e62f1bb 100644 --- a/src/gui/transferlistdelegate.cpp +++ b/src/gui/transferlistdelegate.cpp @@ -31,12 +31,10 @@ #include #include "transferlistmodel.h" -#include "utils.h" TransferListDelegate::TransferListDelegate(QObject *parent) : QStyledItemDelegate {parent} { - m_stateThemeColors = Utils::Gui::torrentStateToColorHash(); } QWidget *TransferListDelegate::createEditor(QWidget *, const QStyleOptionViewItem &, const QModelIndex &) const @@ -95,7 +93,7 @@ void TransferListDelegate::paint(QPainter *painter, const QStyleOptionViewItem & QColor color = {}; if (torrentState != TorrentState::Unknown) { - color = m_stateThemeColors.value(torrentState); + color = index.data(Qt::ForegroundRole).value(); } m_progressBarPainter.paint(painter, customOption, index.data().toString(), progress, color); diff --git a/src/gui/transferlistdelegate.h b/src/gui/transferlistdelegate.h index de4939897..01194d118 100644 --- a/src/gui/transferlistdelegate.h +++ b/src/gui/transferlistdelegate.h @@ -31,7 +31,6 @@ #include #include "progressbarpainter.h" -#include "base/bittorrent/torrent.h" class TransferListDelegate final : public QStyledItemDelegate { @@ -48,5 +47,4 @@ public: private: ProgressBarPainter m_progressBarPainter; mutable int m_nameColHeight = -1; - QHash m_stateThemeColors; }; diff --git a/src/gui/transferlistmodel.cpp b/src/gui/transferlistmodel.cpp index 435326289..0298db047 100644 --- a/src/gui/transferlistmodel.cpp +++ b/src/gui/transferlistmodel.cpp @@ -44,7 +44,48 @@ #include "base/utils/misc.h" #include "base/utils/string.h" #include "uithememanager.h" -#include "utils.h" + +namespace +{ + QHash torrentStateColorsFromUITheme() + { + struct TorrentStateColorDescriptor + { + const BitTorrent::TorrentState state; + const QString id; + }; + + const TorrentStateColorDescriptor colorDescriptors[] = + { + {BitTorrent::TorrentState::Downloading, u"TransferList.Downloading"_s}, + {BitTorrent::TorrentState::StalledDownloading, u"TransferList.StalledDownloading"_s}, + {BitTorrent::TorrentState::DownloadingMetadata, u"TransferList.DownloadingMetadata"_s}, + {BitTorrent::TorrentState::ForcedDownloadingMetadata, u"TransferList.ForcedDownloadingMetadata"_s}, + {BitTorrent::TorrentState::ForcedDownloading, u"TransferList.ForcedDownloading"_s}, + {BitTorrent::TorrentState::Uploading, u"TransferList.Uploading"_s}, + {BitTorrent::TorrentState::StalledUploading, u"TransferList.StalledUploading"_s}, + {BitTorrent::TorrentState::ForcedUploading, u"TransferList.ForcedUploading"_s}, + {BitTorrent::TorrentState::QueuedDownloading, u"TransferList.QueuedDownloading"_s}, + {BitTorrent::TorrentState::QueuedUploading, u"TransferList.QueuedUploading"_s}, + {BitTorrent::TorrentState::CheckingDownloading, u"TransferList.CheckingDownloading"_s}, + {BitTorrent::TorrentState::CheckingUploading, u"TransferList.CheckingUploading"_s}, + {BitTorrent::TorrentState::CheckingResumeData, u"TransferList.CheckingResumeData"_s}, + {BitTorrent::TorrentState::StoppedDownloading, u"TransferList.StoppedDownloading"_s}, + {BitTorrent::TorrentState::StoppedUploading, u"TransferList.StoppedUploading"_s}, + {BitTorrent::TorrentState::Moving, u"TransferList.Moving"_s}, + {BitTorrent::TorrentState::MissingFiles, u"TransferList.MissingFiles"_s}, + {BitTorrent::TorrentState::Error, u"TransferList.Error"_s} + }; + + QHash colors; + for (const TorrentStateColorDescriptor &colorDescriptor : colorDescriptors) + { + const QColor themeColor = UIThemeManager::instance()->getColor(colorDescriptor.id); + colors.insert(colorDescriptor.state, themeColor); + } + return colors; + } +} // TransferListModel @@ -685,7 +726,7 @@ void TransferListModel::configure() void TransferListModel::loadUIThemeResources() { - m_stateThemeColors = Utils::Gui::torrentStateToColorHash(); + m_stateThemeColors = torrentStateColorsFromUITheme(); const auto *themeManager = UIThemeManager::instance(); m_checkingIcon = themeManager->getIcon(u"force-recheck"_s, u"checking"_s); diff --git a/src/gui/utils.cpp b/src/gui/utils.cpp index cf91f487d..e987d75c0 100644 --- a/src/gui/utils.cpp +++ b/src/gui/utils.cpp @@ -40,7 +40,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -50,10 +52,11 @@ #include #include -#include "uithememanager.h" +#include "base/global.h" #include "base/path.h" #include "base/tag.h" -#include "base/bittorrent/torrent.h" +#include "base/utils/fs.h" +#include "base/utils/version.h" QPixmap Utils::Gui::scaledPixmap(const Path &path, const int height) { @@ -240,42 +243,3 @@ Tag Utils::Gui::widgetTextToTag(const QString &text) return Tag(cleanedText); } - -QHash Utils::Gui::torrentStateToColorHash() -{ - struct TorrentStateColorDescriptor - { - const BitTorrent::TorrentState state; - const QString id; - }; - - const TorrentStateColorDescriptor colorDescriptors[] = - { - {BitTorrent::TorrentState::Downloading, u"TransferList.Downloading"_s}, - {BitTorrent::TorrentState::StalledDownloading, u"TransferList.StalledDownloading"_s}, - {BitTorrent::TorrentState::DownloadingMetadata, u"TransferList.DownloadingMetadata"_s}, - {BitTorrent::TorrentState::ForcedDownloadingMetadata, u"TransferList.ForcedDownloadingMetadata"_s}, - {BitTorrent::TorrentState::ForcedDownloading, u"TransferList.ForcedDownloading"_s}, - {BitTorrent::TorrentState::Uploading, u"TransferList.Uploading"_s}, - {BitTorrent::TorrentState::StalledUploading, u"TransferList.StalledUploading"_s}, - {BitTorrent::TorrentState::ForcedUploading, u"TransferList.ForcedUploading"_s}, - {BitTorrent::TorrentState::QueuedDownloading, u"TransferList.QueuedDownloading"_s}, - {BitTorrent::TorrentState::QueuedUploading, u"TransferList.QueuedUploading"_s}, - {BitTorrent::TorrentState::CheckingDownloading, u"TransferList.CheckingDownloading"_s}, - {BitTorrent::TorrentState::CheckingUploading, u"TransferList.CheckingUploading"_s}, - {BitTorrent::TorrentState::CheckingResumeData, u"TransferList.CheckingResumeData"_s}, - {BitTorrent::TorrentState::StoppedDownloading, u"TransferList.StoppedDownloading"_s}, - {BitTorrent::TorrentState::StoppedUploading, u"TransferList.StoppedUploading"_s}, - {BitTorrent::TorrentState::Moving, u"TransferList.Moving"_s}, - {BitTorrent::TorrentState::MissingFiles, u"TransferList.MissingFiles"_s}, - {BitTorrent::TorrentState::Error, u"TransferList.Error"_s} - }; - - QHash colors; - for (const TorrentStateColorDescriptor &colorDescriptor : colorDescriptors) - { - const QColor themeColor = UIThemeManager::instance()->getColor(colorDescriptor.id); - colors.insert(colorDescriptor.state, themeColor); - } - return colors; -} \ No newline at end of file diff --git a/src/gui/utils.h b/src/gui/utils.h index eb53ce652..4d994815b 100644 --- a/src/gui/utils.h +++ b/src/gui/utils.h @@ -30,7 +30,6 @@ #pragma once #include "base/pathfwd.h" -#include "base/bittorrent/torrent.h" class QPixmap; class QPoint; @@ -57,6 +56,4 @@ namespace Utils::Gui QString tagToWidgetText(const Tag &tag); Tag widgetTextToTag(const QString &text); - - QHash torrentStateToColorHash(); }