mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-08-20 13:23:34 -07:00
move duplicate code to utils.cpp
delete un-necessary includes
This commit is contained in:
parent
ed2090261b
commit
7e03430ad4
4 changed files with 48 additions and 91 deletions
|
@ -32,53 +32,12 @@
|
||||||
|
|
||||||
#include "transferlistmodel.h"
|
#include "transferlistmodel.h"
|
||||||
#include "uithememanager.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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
TransferListDelegate::TransferListDelegate(QObject *parent)
|
TransferListDelegate::TransferListDelegate(QObject *parent)
|
||||||
: QStyledItemDelegate {parent}
|
: QStyledItemDelegate {parent}
|
||||||
{
|
{
|
||||||
m_stateThemeColors = torrentStateColorsFromUITheme();
|
m_stateThemeColors = m_stateThemeColors = Utils::Gui::torrentStateToColorHash();;
|
||||||
}
|
}
|
||||||
|
|
||||||
QWidget *TransferListDelegate::createEditor(QWidget *, const QStyleOptionViewItem &, const QModelIndex &) const
|
QWidget *TransferListDelegate::createEditor(QWidget *, const QStyleOptionViewItem &, const QModelIndex &) const
|
||||||
|
|
|
@ -44,48 +44,7 @@
|
||||||
#include "base/utils/misc.h"
|
#include "base/utils/misc.h"
|
||||||
#include "base/utils/string.h"
|
#include "base/utils/string.h"
|
||||||
#include "uithememanager.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
|
// TransferListModel
|
||||||
|
|
||||||
|
@ -726,7 +685,7 @@ void TransferListModel::configure()
|
||||||
|
|
||||||
void TransferListModel::loadUIThemeResources()
|
void TransferListModel::loadUIThemeResources()
|
||||||
{
|
{
|
||||||
m_stateThemeColors = torrentStateColorsFromUITheme();
|
m_stateThemeColors = Utils::Gui::torrentStateToColorHash();
|
||||||
|
|
||||||
const auto *themeManager = UIThemeManager::instance();
|
const auto *themeManager = UIThemeManager::instance();
|
||||||
m_checkingIcon = themeManager->getIcon(u"force-recheck"_s, u"checking"_s);
|
m_checkingIcon = themeManager->getIcon(u"force-recheck"_s, u"checking"_s);
|
||||||
|
|
|
@ -40,9 +40,7 @@
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QDesktopServices>
|
#include <QDesktopServices>
|
||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
#include <QPixmapCache>
|
|
||||||
#include <QPoint>
|
#include <QPoint>
|
||||||
#include <QProcess>
|
|
||||||
#include <QRegularExpression>
|
#include <QRegularExpression>
|
||||||
#include <QScreen>
|
#include <QScreen>
|
||||||
#include <QSize>
|
#include <QSize>
|
||||||
|
@ -52,11 +50,10 @@
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <QWindow>
|
#include <QWindow>
|
||||||
|
|
||||||
#include "base/global.h"
|
#include "uithememanager.h"
|
||||||
#include "base/path.h"
|
#include "base/path.h"
|
||||||
#include "base/tag.h"
|
#include "base/tag.h"
|
||||||
#include "base/utils/fs.h"
|
#include "base/bittorrent/torrent.h"
|
||||||
#include "base/utils/version.h"
|
|
||||||
|
|
||||||
QPixmap Utils::Gui::scaledPixmap(const Path &path, const int height)
|
QPixmap Utils::Gui::scaledPixmap(const Path &path, const int height)
|
||||||
{
|
{
|
||||||
|
@ -243,3 +240,42 @@ Tag Utils::Gui::widgetTextToTag(const QString &text)
|
||||||
|
|
||||||
return Tag(cleanedText);
|
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;
|
||||||
|
}
|
|
@ -30,6 +30,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "base/pathfwd.h"
|
#include "base/pathfwd.h"
|
||||||
|
#include "base/bittorrent/torrent.h"
|
||||||
|
|
||||||
class QPixmap;
|
class QPixmap;
|
||||||
class QPoint;
|
class QPoint;
|
||||||
|
@ -56,4 +57,6 @@ namespace Utils::Gui
|
||||||
|
|
||||||
QString tagToWidgetText(const Tag &tag);
|
QString tagToWidgetText(const Tag &tag);
|
||||||
Tag widgetTextToTag(const QString &text);
|
Tag widgetTextToTag(const QString &text);
|
||||||
|
|
||||||
|
QHash<BitTorrent::TorrentState, QColor> torrentStateToColorHash();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue