revert utils.cpp/h

get color from model
This commit is contained in:
Mark 2025-07-07 06:43:52 +04:00
commit 1cede85794
5 changed files with 49 additions and 51 deletions

View file

@ -31,12 +31,10 @@
#include <QModelIndex>
#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<QColor>();
}
m_progressBarPainter.paint(painter, customOption, index.data().toString(), progress, color);

View file

@ -31,7 +31,6 @@
#include <QStyledItemDelegate>
#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<BitTorrent::TorrentState, QColor> m_stateThemeColors;
};

View file

@ -44,7 +44,48 @@
#include "base/utils/misc.h"
#include "base/utils/string.h"
#include "uithememanager.h"
#include "utils.h"
namespace
{
QHash<BitTorrent::TorrentState, QColor> 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<BitTorrent::TorrentState, QColor> 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);

View file

@ -40,7 +40,9 @@
#include <QApplication>
#include <QDesktopServices>
#include <QPixmap>
#include <QPixmapCache>
#include <QPoint>
#include <QProcess>
#include <QRegularExpression>
#include <QScreen>
#include <QSize>
@ -50,10 +52,11 @@
#include <QWidget>
#include <QWindow>
#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<BitTorrent::TorrentState, QColor> 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<BitTorrent::TorrentState, QColor> colors;
for (const TorrentStateColorDescriptor &colorDescriptor : colorDescriptors)
{
const QColor themeColor = UIThemeManager::instance()->getColor(colorDescriptor.id);
colors.insert(colorDescriptor.state, themeColor);
}
return colors;
}

View file

@ -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<BitTorrent::TorrentState, QColor> torrentStateToColorHash();
}