diff --git a/src/gui/transferlistdelegate.cpp b/src/gui/transferlistdelegate.cpp index 11ed7e416..7ada74ad5 100644 --- a/src/gui/transferlistdelegate.cpp +++ b/src/gui/transferlistdelegate.cpp @@ -32,53 +32,12 @@ #include "transferlistmodel.h" #include "uithememanager.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; - } -} +#include "utils.h" TransferListDelegate::TransferListDelegate(QObject *parent) : QStyledItemDelegate {parent} { - m_stateThemeColors = torrentStateColorsFromUITheme(); + m_stateThemeColors = m_stateThemeColors = Utils::Gui::torrentStateToColorHash();; } QWidget *TransferListDelegate::createEditor(QWidget *, const QStyleOptionViewItem &, const QModelIndex &) const diff --git a/src/gui/transferlistmodel.cpp b/src/gui/transferlistmodel.cpp index 0298db047..435326289 100644 --- a/src/gui/transferlistmodel.cpp +++ b/src/gui/transferlistmodel.cpp @@ -44,48 +44,7 @@ #include "base/utils/misc.h" #include "base/utils/string.h" #include "uithememanager.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; - } -} +#include "utils.h" // TransferListModel @@ -726,7 +685,7 @@ void TransferListModel::configure() void TransferListModel::loadUIThemeResources() { - m_stateThemeColors = torrentStateColorsFromUITheme(); + m_stateThemeColors = Utils::Gui::torrentStateToColorHash(); 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 e987d75c0..cf91f487d 100644 --- a/src/gui/utils.cpp +++ b/src/gui/utils.cpp @@ -40,9 +40,7 @@ #include #include #include -#include #include -#include #include #include #include @@ -52,11 +50,10 @@ #include #include -#include "base/global.h" +#include "uithememanager.h" #include "base/path.h" #include "base/tag.h" -#include "base/utils/fs.h" -#include "base/utils/version.h" +#include "base/bittorrent/torrent.h" QPixmap Utils::Gui::scaledPixmap(const Path &path, const int height) { @@ -243,3 +240,42 @@ 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 4d994815b..eb53ce652 100644 --- a/src/gui/utils.h +++ b/src/gui/utils.h @@ -30,6 +30,7 @@ #pragma once #include "base/pathfwd.h" +#include "base/bittorrent/torrent.h" class QPixmap; class QPoint; @@ -56,4 +57,6 @@ namespace Utils::Gui QString tagToWidgetText(const Tag &tag); Tag widgetTextToTag(const QString &text); + + QHash torrentStateToColorHash(); }