From f54cc5796ef9561fd3142b566fdf69e5a5fb3620 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Fri, 27 May 2022 03:12:10 +0800 Subject: [PATCH] Move function into anonymous namespace --- src/gui/mainwindow.cpp | 32 ++-- src/gui/transferlistmodel.cpp | 327 ++++++++++++++++------------------ 2 files changed, 170 insertions(+), 189 deletions(-) diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index 4c5aea10a..7140a0692 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -121,6 +121,21 @@ namespace || (!str.startsWith(u"file:", Qt::CaseInsensitive) && Net::DownloadManager::hasSupportedScheme(str)); } + +#ifdef Q_OS_MACOS + MainWindow *dockMainWindowHandle = nullptr; + + bool dockClickHandler(id self, SEL cmd, ...) + { + Q_UNUSED(self) + Q_UNUSED(cmd) + + if (dockMainWindowHandle && !dockMainWindowHandle->isVisible()) + dockMainWindowHandle->activate(); + + return true; + } +#endif } MainWindow::MainWindow(QWidget *parent) @@ -1388,28 +1403,11 @@ void MainWindow::dragEnterEvent(QDragEnterEvent *event) } #ifdef Q_OS_MACOS - -static MainWindow *dockMainWindowHandle; - -static bool dockClickHandler(id self, SEL cmd, ...) -{ - Q_UNUSED(self) - Q_UNUSED(cmd) - - if (dockMainWindowHandle && !dockMainWindowHandle->isVisible()) - { - dockMainWindowHandle->activate(); - } - - return true; -} - void MainWindow::setupDockClickHandler() { dockMainWindowHandle = this; MacUtils::overrideDockClickHandler(dockClickHandler); } - #endif // Q_OS_MACOS /***************************************************** diff --git a/src/gui/transferlistmodel.cpp b/src/gui/transferlistmodel.cpp index 197d8f176..2fab81906 100644 --- a/src/gui/transferlistmodel.cpp +++ b/src/gui/transferlistmodel.cpp @@ -45,23 +45,163 @@ #include "base/utils/string.h" #include "uithememanager.h" -static QIcon getIconByState(BitTorrent::TorrentState state); -static QColor getDefaultColorByState(BitTorrent::TorrentState state); - -static QIcon getPausedIcon(); -static QIcon getQueuedIcon(); -static QIcon getDownloadingIcon(); -static QIcon getStalledDownloadingIcon(); -static QIcon getUploadingIcon(); -static QIcon getStalledUploadingIcon(); -static QIcon getCompletedIcon(); -static QIcon getCheckingIcon(); -static QIcon getErrorIcon(); - -static bool isDarkTheme(); - namespace { + QIcon getPausedIcon() + { + static QIcon cached = UIThemeManager::instance()->getIcon(u"paused"_qs); + return cached; + } + + QIcon getQueuedIcon() + { + static QIcon cached = UIThemeManager::instance()->getIcon(u"queued"_qs); + return cached; + } + + QIcon getDownloadingIcon() + { + static QIcon cached = UIThemeManager::instance()->getIcon(u"downloading"_qs); + return cached; + } + + QIcon getStalledDownloadingIcon() + { + static QIcon cached = UIThemeManager::instance()->getIcon(u"stalledDL"_qs); + return cached; + } + + QIcon getUploadingIcon() + { + static QIcon cached = UIThemeManager::instance()->getIcon(u"uploading"_qs); + return cached; + } + + QIcon getStalledUploadingIcon() + { + static QIcon cached = UIThemeManager::instance()->getIcon(u"stalledUP"_qs); + return cached; + } + + QIcon getCompletedIcon() + { + static QIcon cached = UIThemeManager::instance()->getIcon(u"completed"_qs); + return cached; + } + + QIcon getCheckingIcon() + { + static QIcon cached = UIThemeManager::instance()->getIcon(u"checking"_qs); + return cached; + } + + QIcon getErrorIcon() + { + static QIcon cached = UIThemeManager::instance()->getIcon(u"error"_qs); + return cached; + } + + bool isDarkTheme() + { + const QPalette pal = QApplication::palette(); + // QPalette::Base is used for the background of the Treeview + const QColor &color = pal.color(QPalette::Active, QPalette::Base); + return (color.lightness() < 127); + } + + QIcon getIconByState(const BitTorrent::TorrentState state) + { + switch (state) + { + case BitTorrent::TorrentState::Downloading: + case BitTorrent::TorrentState::ForcedDownloading: + case BitTorrent::TorrentState::DownloadingMetadata: + case BitTorrent::TorrentState::ForcedDownloadingMetadata: + return getDownloadingIcon(); + case BitTorrent::TorrentState::StalledDownloading: + return getStalledDownloadingIcon(); + case BitTorrent::TorrentState::StalledUploading: + return getStalledUploadingIcon(); + case BitTorrent::TorrentState::Uploading: + case BitTorrent::TorrentState::ForcedUploading: + return getUploadingIcon(); + case BitTorrent::TorrentState::PausedDownloading: + return getPausedIcon(); + case BitTorrent::TorrentState::PausedUploading: + return getCompletedIcon(); + case BitTorrent::TorrentState::QueuedDownloading: + case BitTorrent::TorrentState::QueuedUploading: + return getQueuedIcon(); + case BitTorrent::TorrentState::CheckingDownloading: + case BitTorrent::TorrentState::CheckingUploading: + case BitTorrent::TorrentState::CheckingResumeData: + case BitTorrent::TorrentState::Moving: + return getCheckingIcon(); + case BitTorrent::TorrentState::Unknown: + case BitTorrent::TorrentState::MissingFiles: + case BitTorrent::TorrentState::Error: + return getErrorIcon(); + default: + Q_ASSERT(false); + return getErrorIcon(); + } + } + + QColor getDefaultColorByState(const BitTorrent::TorrentState state) + { + // Color names taken from http://cloford.com/resources/colours/500col.htm + bool dark = isDarkTheme(); + + switch (state) + { + case BitTorrent::TorrentState::Downloading: + case BitTorrent::TorrentState::ForcedDownloading: + case BitTorrent::TorrentState::DownloadingMetadata: + case BitTorrent::TorrentState::ForcedDownloadingMetadata: + if (!dark) + return {34, 139, 34}; // Forest Green + else + return {50, 205, 50}; // Lime Green + case BitTorrent::TorrentState::StalledDownloading: + case BitTorrent::TorrentState::StalledUploading: + if (!dark) + return {0, 0, 0}; // Black + else + return {204, 204, 204}; // Gray 80 + case BitTorrent::TorrentState::Uploading: + case BitTorrent::TorrentState::ForcedUploading: + if (!dark) + return {65, 105, 225}; // Royal Blue + else + return {99, 184, 255}; // Steel Blue 1 + case BitTorrent::TorrentState::PausedDownloading: + return {250, 128, 114}; // Salmon + case BitTorrent::TorrentState::PausedUploading: + if (!dark) + return {0, 0, 139}; // Dark Blue + else + return {79, 148, 205}; // Steel Blue 3 + case BitTorrent::TorrentState::Error: + case BitTorrent::TorrentState::MissingFiles: + return {255, 0, 0}; // red + case BitTorrent::TorrentState::QueuedDownloading: + case BitTorrent::TorrentState::QueuedUploading: + case BitTorrent::TorrentState::CheckingDownloading: + case BitTorrent::TorrentState::CheckingUploading: + case BitTorrent::TorrentState::CheckingResumeData: + case BitTorrent::TorrentState::Moving: + if (!dark) + return {0, 128, 128}; // Teal + else + return {0, 205, 205}; // Cyan 3 + case BitTorrent::TorrentState::Unknown: + return {255, 0, 0}; // red + default: + Q_ASSERT(false); + return {255, 0, 0}; // red + } + } + QHash torrentStateColorsFromUITheme() { struct TorrentStateColorDescriptor @@ -656,160 +796,3 @@ void TransferListModel::configure() emit dataChanged(index(0, 0), index((rowCount() - 1), (columnCount() - 1))); } } - -// Static functions - -QIcon getIconByState(const BitTorrent::TorrentState state) -{ - switch (state) - { - case BitTorrent::TorrentState::Downloading: - case BitTorrent::TorrentState::ForcedDownloading: - case BitTorrent::TorrentState::DownloadingMetadata: - case BitTorrent::TorrentState::ForcedDownloadingMetadata: - return getDownloadingIcon(); - case BitTorrent::TorrentState::StalledDownloading: - return getStalledDownloadingIcon(); - case BitTorrent::TorrentState::StalledUploading: - return getStalledUploadingIcon(); - case BitTorrent::TorrentState::Uploading: - case BitTorrent::TorrentState::ForcedUploading: - return getUploadingIcon(); - case BitTorrent::TorrentState::PausedDownloading: - return getPausedIcon(); - case BitTorrent::TorrentState::PausedUploading: - return getCompletedIcon(); - case BitTorrent::TorrentState::QueuedDownloading: - case BitTorrent::TorrentState::QueuedUploading: - return getQueuedIcon(); - case BitTorrent::TorrentState::CheckingDownloading: - case BitTorrent::TorrentState::CheckingUploading: - case BitTorrent::TorrentState::CheckingResumeData: - case BitTorrent::TorrentState::Moving: - return getCheckingIcon(); - case BitTorrent::TorrentState::Unknown: - case BitTorrent::TorrentState::MissingFiles: - case BitTorrent::TorrentState::Error: - return getErrorIcon(); - default: - Q_ASSERT(false); - return getErrorIcon(); - } -} - -QColor getDefaultColorByState(const BitTorrent::TorrentState state) -{ - // Color names taken from http://cloford.com/resources/colours/500col.htm - bool dark = isDarkTheme(); - - switch (state) - { - case BitTorrent::TorrentState::Downloading: - case BitTorrent::TorrentState::ForcedDownloading: - case BitTorrent::TorrentState::DownloadingMetadata: - case BitTorrent::TorrentState::ForcedDownloadingMetadata: - if (!dark) - return {34, 139, 34}; // Forest Green - else - return {50, 205, 50}; // Lime Green - case BitTorrent::TorrentState::StalledDownloading: - case BitTorrent::TorrentState::StalledUploading: - if (!dark) - return {0, 0, 0}; // Black - else - return {204, 204, 204}; // Gray 80 - case BitTorrent::TorrentState::Uploading: - case BitTorrent::TorrentState::ForcedUploading: - if (!dark) - return {65, 105, 225}; // Royal Blue - else - return {99, 184, 255}; // Steel Blue 1 - case BitTorrent::TorrentState::PausedDownloading: - return {250, 128, 114}; // Salmon - case BitTorrent::TorrentState::PausedUploading: - if (!dark) - return {0, 0, 139}; // Dark Blue - else - return {79, 148, 205}; // Steel Blue 3 - case BitTorrent::TorrentState::Error: - case BitTorrent::TorrentState::MissingFiles: - return {255, 0, 0}; // red - case BitTorrent::TorrentState::QueuedDownloading: - case BitTorrent::TorrentState::QueuedUploading: - case BitTorrent::TorrentState::CheckingDownloading: - case BitTorrent::TorrentState::CheckingUploading: - case BitTorrent::TorrentState::CheckingResumeData: - case BitTorrent::TorrentState::Moving: - if (!dark) - return {0, 128, 128}; // Teal - else - return {0, 205, 205}; // Cyan 3 - case BitTorrent::TorrentState::Unknown: - return {255, 0, 0}; // red - default: - Q_ASSERT(false); - return {255, 0, 0}; // red - } -} - -QIcon getPausedIcon() -{ - static QIcon cached = UIThemeManager::instance()->getIcon(u"paused"_qs); - return cached; -} - -QIcon getQueuedIcon() -{ - static QIcon cached = UIThemeManager::instance()->getIcon(u"queued"_qs); - return cached; -} - -QIcon getDownloadingIcon() -{ - static QIcon cached = UIThemeManager::instance()->getIcon(u"downloading"_qs); - return cached; -} - -QIcon getStalledDownloadingIcon() -{ - static QIcon cached = UIThemeManager::instance()->getIcon(u"stalledDL"_qs); - return cached; -} - -QIcon getUploadingIcon() -{ - static QIcon cached = UIThemeManager::instance()->getIcon(u"uploading"_qs); - return cached; -} - -QIcon getStalledUploadingIcon() -{ - static QIcon cached = UIThemeManager::instance()->getIcon(u"stalledUP"_qs); - return cached; -} - -QIcon getCompletedIcon() -{ - static QIcon cached = UIThemeManager::instance()->getIcon(u"completed"_qs); - return cached; -} - -QIcon getCheckingIcon() -{ - static QIcon cached = UIThemeManager::instance()->getIcon(u"checking"_qs); - return cached; -} - -QIcon getErrorIcon() -{ - static QIcon cached = UIThemeManager::instance()->getIcon(u"error"_qs); - return cached; -} - -bool isDarkTheme() -{ - const QPalette pal = QApplication::palette(); - // QPalette::Base is used for the background of the Treeview - const QColor &color = pal.color(QPalette::Active, QPalette::Base); - return (color.lightness() < 127); -}