diff --git a/src/base/bittorrent/torrenthandle.cpp b/src/base/bittorrent/torrenthandle.cpp index 4cd72a250..9e9e4eb16 100644 --- a/src/base/bittorrent/torrenthandle.cpp +++ b/src/base/bittorrent/torrenthandle.cpp @@ -177,6 +177,11 @@ CreateTorrentParams::CreateTorrentParams(const AddTorrentParams ¶ms) savePath = Session::instance()->defaultSavePath(); } +uint BitTorrent::qHash(const BitTorrent::TorrentState key, const uint seed) +{ + return ::qHash(static_cast>(key), seed); +} + // TorrentHandle const qreal TorrentHandle::USE_GLOBAL_RATIO = -2.; diff --git a/src/base/bittorrent/torrenthandle.h b/src/base/bittorrent/torrenthandle.h index 6c5c31341..348dd540b 100644 --- a/src/base/bittorrent/torrenthandle.h +++ b/src/base/bittorrent/torrenthandle.h @@ -129,6 +129,8 @@ namespace BitTorrent Error }; + uint qHash(TorrentState key, uint seed); + class TorrentHandle : public QObject { Q_DISABLE_COPY(TorrentHandle) diff --git a/src/gui/transferlistmodel.cpp b/src/gui/transferlistmodel.cpp index 57492b353..a9d5a8a34 100644 --- a/src/gui/transferlistmodel.cpp +++ b/src/gui/transferlistmodel.cpp @@ -59,6 +59,27 @@ static bool isDarkTheme(); TransferListModel::TransferListModel(QObject *parent) : QAbstractListModel(parent) + , m_stateForegroundColors { + {BitTorrent::TorrentState::Unknown, getColorByState(BitTorrent::TorrentState::Unknown)}, + {BitTorrent::TorrentState::ForcedDownloading, getColorByState(BitTorrent::TorrentState::ForcedDownloading)}, + {BitTorrent::TorrentState::Downloading, getColorByState(BitTorrent::TorrentState::Downloading)}, + {BitTorrent::TorrentState::DownloadingMetadata, getColorByState(BitTorrent::TorrentState::DownloadingMetadata)}, + {BitTorrent::TorrentState::Allocating, getColorByState(BitTorrent::TorrentState::Allocating)}, + {BitTorrent::TorrentState::StalledDownloading, getColorByState(BitTorrent::TorrentState::StalledDownloading)}, + {BitTorrent::TorrentState::ForcedUploading, getColorByState(BitTorrent::TorrentState::ForcedUploading)}, + {BitTorrent::TorrentState::Uploading, getColorByState(BitTorrent::TorrentState::Uploading)}, + {BitTorrent::TorrentState::StalledUploading, getColorByState(BitTorrent::TorrentState::StalledUploading)}, + {BitTorrent::TorrentState::CheckingResumeData, getColorByState(BitTorrent::TorrentState::CheckingResumeData)}, + {BitTorrent::TorrentState::QueuedDownloading, getColorByState(BitTorrent::TorrentState::QueuedDownloading)}, + {BitTorrent::TorrentState::QueuedUploading, getColorByState(BitTorrent::TorrentState::QueuedUploading)}, + {BitTorrent::TorrentState::CheckingUploading, getColorByState(BitTorrent::TorrentState::CheckingUploading)}, + {BitTorrent::TorrentState::CheckingDownloading, getColorByState(BitTorrent::TorrentState::CheckingDownloading)}, + {BitTorrent::TorrentState::PausedDownloading, getColorByState(BitTorrent::TorrentState::PausedDownloading)}, + {BitTorrent::TorrentState::PausedUploading, getColorByState(BitTorrent::TorrentState::PausedUploading)}, + {BitTorrent::TorrentState::Moving, getColorByState(BitTorrent::TorrentState::Moving)}, + {BitTorrent::TorrentState::MissingFiles, getColorByState(BitTorrent::TorrentState::MissingFiles)}, + {BitTorrent::TorrentState::Error, getColorByState(BitTorrent::TorrentState::Error)} + } { // Load the torrents using namespace BitTorrent; @@ -169,7 +190,7 @@ QVariant TransferListModel::data(const QModelIndex &index, const int role) const return getIconByState(torrent->state()); if (role == Qt::ForegroundRole) - return getColorByState(torrent->state()); + return stateForeground(torrent->state()); if ((role != Qt::DisplayRole) && (role != Qt::UserRole)) return {}; @@ -337,6 +358,16 @@ void TransferListModel::handleTorrentsUpdated(const QVector +#include #include namespace BitTorrent { class InfoHash; class TorrentHandle; + enum class TorrentState; } class TransferListModel : public QAbstractListModel @@ -93,6 +95,9 @@ public: BitTorrent::TorrentHandle *torrentHandle(const QModelIndex &index) const; + void setStateForeground(BitTorrent::TorrentState state, const QColor& color); + QColor stateForeground(BitTorrent::TorrentState state) const; + private slots: void addTorrent(BitTorrent::TorrentHandle *const torrent); void handleTorrentAboutToBeRemoved(BitTorrent::TorrentHandle *const torrent); @@ -102,6 +107,9 @@ private slots: private: QList m_torrentList; // maps row number to torrent handle QHash m_torrentMap; // maps torrent handle to row number + + // row text colors + QHash m_stateForegroundColors; }; #endif // TRANSFERLISTMODEL_H diff --git a/src/gui/transferlistwidget.cpp b/src/gui/transferlistwidget.cpp index bdc123e72..efec4784f 100644 --- a/src/gui/transferlistwidget.cpp +++ b/src/gui/transferlistwidget.cpp @@ -239,6 +239,197 @@ TransferListModel *TransferListWidget::getSourceModel() const return m_listModel; } +QColor TransferListWidget::unknownStateForeground() const +{ + return m_listModel->stateForeground(BitTorrent::TorrentState::Unknown); +} + +QColor TransferListWidget::forcedDownloadingStateForeground() const +{ + return m_listModel->stateForeground(BitTorrent::TorrentState::ForcedDownloading); +} + +QColor TransferListWidget::downloadingStateForeground() const +{ + return m_listModel->stateForeground(BitTorrent::TorrentState::Downloading); +} + +QColor TransferListWidget::downloadingMetadataStateForeground() const +{ + return m_listModel->stateForeground(BitTorrent::TorrentState::DownloadingMetadata); +} + +QColor TransferListWidget::allocatingStateForeground() const +{ + return m_listModel->stateForeground(BitTorrent::TorrentState::Allocating); +} + +QColor TransferListWidget::stalledDownloadingStateForeground() const +{ + return m_listModel->stateForeground(BitTorrent::TorrentState::StalledDownloading); +} + +QColor TransferListWidget::forcedUploadingStateForeground() const +{ + return m_listModel->stateForeground(BitTorrent::TorrentState::ForcedUploading); +} + +QColor TransferListWidget::uploadingStateForeground() const +{ + return m_listModel->stateForeground(BitTorrent::TorrentState::Uploading); +} + +QColor TransferListWidget::stalledUploadingStateForeground() const +{ + return m_listModel->stateForeground(BitTorrent::TorrentState::StalledUploading); +} + +QColor TransferListWidget::checkingResumeDataStateForeground() const +{ + return m_listModel->stateForeground(BitTorrent::TorrentState::CheckingResumeData); +} + +QColor TransferListWidget::queuedDownloadingStateForeground() const +{ + return m_listModel->stateForeground(BitTorrent::TorrentState::QueuedDownloading); +} + +QColor TransferListWidget::queuedUploadingStateForeground() const +{ + return m_listModel->stateForeground(BitTorrent::TorrentState::QueuedUploading); +} + +QColor TransferListWidget::checkingUploadingStateForeground() const +{ + return m_listModel->stateForeground(BitTorrent::TorrentState::CheckingUploading); +} + +QColor TransferListWidget::checkingDownloadingStateForeground() const +{ + return m_listModel->stateForeground(BitTorrent::TorrentState::CheckingDownloading); +} + +QColor TransferListWidget::pausedDownloadingStateForeground() const +{ + return m_listModel->stateForeground(BitTorrent::TorrentState::PausedDownloading); +} + +QColor TransferListWidget::pausedUploadingStateForeground() const +{ + return m_listModel->stateForeground(BitTorrent::TorrentState::PausedUploading); +} + +QColor TransferListWidget::movingStateForeground() const +{ + return m_listModel->stateForeground(BitTorrent::TorrentState::Moving); +} + +QColor TransferListWidget::missingFilesStateForeground() const +{ + return m_listModel->stateForeground(BitTorrent::TorrentState::MissingFiles); +} + +QColor TransferListWidget::errorStateForeground() const +{ + return m_listModel->stateForeground(BitTorrent::TorrentState::Error); +} + +void TransferListWidget::setUnknownStateForeground(const QColor &color) +{ + m_listModel->setStateForeground(BitTorrent::TorrentState::Unknown, color); +} + +void TransferListWidget::setForcedDownloadingStateForeground(const QColor &color) +{ + m_listModel->setStateForeground(BitTorrent::TorrentState::ForcedDownloading, color); +} + +void TransferListWidget::setDownloadingStateForeground(const QColor &color) +{ + m_listModel->setStateForeground(BitTorrent::TorrentState::Downloading, color); +} + +void TransferListWidget::setDownloadingMetadataStateForeground(const QColor &color) +{ + m_listModel->setStateForeground(BitTorrent::TorrentState::DownloadingMetadata, color); +} + +void TransferListWidget::setAllocatingStateForeground(const QColor &color) +{ + m_listModel->setStateForeground(BitTorrent::TorrentState::Allocating, color); +} + +void TransferListWidget::setStalledDownloadingStateForeground(const QColor &color) +{ + m_listModel->setStateForeground(BitTorrent::TorrentState::StalledDownloading, color); +} + +void TransferListWidget::setForcedUploadingStateForeground(const QColor &color) +{ + m_listModel->setStateForeground(BitTorrent::TorrentState::ForcedUploading, color); +} + +void TransferListWidget::setUploadingStateForeground(const QColor &color) +{ + m_listModel->setStateForeground(BitTorrent::TorrentState::Uploading, color); +} + +void TransferListWidget::setStalledUploadingStateForeground(const QColor &color) +{ + m_listModel->setStateForeground(BitTorrent::TorrentState::StalledUploading, color); +} + +void TransferListWidget::setCheckingResumeDataStateForeground(const QColor &color) +{ + m_listModel->setStateForeground(BitTorrent::TorrentState::CheckingResumeData, color); +} + +void TransferListWidget::setQueuedDownloadingStateForeground(const QColor &color) +{ + m_listModel->setStateForeground(BitTorrent::TorrentState::QueuedDownloading, color); +} + +void TransferListWidget::setQueuedUploadingStateForeground(const QColor &color) +{ + m_listModel->setStateForeground(BitTorrent::TorrentState::QueuedUploading, color); +} + +void TransferListWidget::setCheckingUploadingStateForeground(const QColor &color) +{ + m_listModel->setStateForeground(BitTorrent::TorrentState::CheckingUploading, color); +} + +void TransferListWidget::setCheckingDownloadingStateForeground(const QColor &color) +{ + m_listModel->setStateForeground(BitTorrent::TorrentState::CheckingDownloading, color); +} + +void TransferListWidget::setPausedDownloadingStateForeground(const QColor &color) +{ + m_listModel->setStateForeground(BitTorrent::TorrentState::PausedDownloading, color); +} + +void TransferListWidget::setPausedUploadingStateForeground(const QColor &color) +{ + m_listModel->setStateForeground(BitTorrent::TorrentState::PausedUploading, color); +} + +void TransferListWidget::setMovingStateForeground(const QColor &color) +{ + m_listModel->setStateForeground(BitTorrent::TorrentState::Moving, color); +} + +void TransferListWidget::setMissingFilesStateForeground(const QColor &color) +{ + m_listModel->setStateForeground(BitTorrent::TorrentState::MissingFiles, color); +} + +void TransferListWidget::setErrorStateForeground(const QColor &color) +{ + m_listModel->setStateForeground(BitTorrent::TorrentState::Error, color); +} + + void TransferListWidget::previewFile(const QString &filePath) { Utils::Gui::openPath(filePath); diff --git a/src/gui/transferlistwidget.h b/src/gui/transferlistwidget.h index f80e883d3..7608b1612 100644 --- a/src/gui/transferlistwidget.h +++ b/src/gui/transferlistwidget.h @@ -47,6 +47,26 @@ class TransferListWidget : public QTreeView { Q_OBJECT + Q_PROPERTY(QColor unknownStateForeground READ unknownStateForeground WRITE setUnknownStateForeground) + Q_PROPERTY(QColor forcedDownloadingStateForeground READ forcedDownloadingStateForeground WRITE setForcedDownloadingStateForeground) + Q_PROPERTY(QColor downloadingStateForeground READ downloadingStateForeground WRITE setDownloadingStateForeground) + Q_PROPERTY(QColor downloadingMetadataStateForeground READ downloadingMetadataStateForeground WRITE setDownloadingMetadataStateForeground) + Q_PROPERTY(QColor allocatingStateForeground READ allocatingStateForeground WRITE setAllocatingStateForeground) + Q_PROPERTY(QColor stalledDownloadingStateForeground READ stalledDownloadingStateForeground WRITE setStalledDownloadingStateForeground) + Q_PROPERTY(QColor forcedUploadingStateForeground READ forcedUploadingStateForeground WRITE setForcedUploadingStateForeground) + Q_PROPERTY(QColor uploadingStateForeground READ uploadingStateForeground WRITE setUploadingStateForeground) + Q_PROPERTY(QColor stalledUploadingStateForeground READ stalledUploadingStateForeground WRITE setStalledUploadingStateForeground) + Q_PROPERTY(QColor checkingResumeDataStateForeground READ checkingResumeDataStateForeground WRITE setCheckingResumeDataStateForeground) + Q_PROPERTY(QColor queuedDownloadingStateForeground READ queuedDownloadingStateForeground WRITE setQueuedDownloadingStateForeground) + Q_PROPERTY(QColor queuedUploadingStateForeground READ queuedUploadingStateForeground WRITE setQueuedUploadingStateForeground) + Q_PROPERTY(QColor checkingUploadingStateForeground READ checkingUploadingStateForeground WRITE setCheckingUploadingStateForeground) + Q_PROPERTY(QColor checkingDownloadingStateForeground READ checkingDownloadingStateForeground WRITE setCheckingDownloadingStateForeground) + Q_PROPERTY(QColor pausedDownloadingStateForeground READ pausedDownloadingStateForeground WRITE setPausedDownloadingStateForeground) + Q_PROPERTY(QColor pausedUploadingStateForeground READ pausedUploadingStateForeground WRITE setPausedUploadingStateForeground) + Q_PROPERTY(QColor movingStateForeground READ movingStateForeground WRITE setMovingStateForeground) + Q_PROPERTY(QColor missingFilesStateForeground READ missingFilesStateForeground WRITE setMissingFilesStateForeground) + Q_PROPERTY(QColor errorStateForeground READ errorStateForeground WRITE setErrorStateForeground) + public: TransferListWidget(QWidget *parent, MainWindow *mainWindow); ~TransferListWidget() override; @@ -122,6 +142,47 @@ private: QStringList askTagsForSelection(const QString &dialogTitle); void applyToSelectedTorrents(const std::function &fn); + // supposed to be used with qss only + QColor unknownStateForeground() const; + QColor forcedDownloadingStateForeground() const; + QColor downloadingStateForeground() const; + QColor downloadingMetadataStateForeground() const; + QColor allocatingStateForeground() const; + QColor stalledDownloadingStateForeground() const; + QColor forcedUploadingStateForeground() const; + QColor uploadingStateForeground() const; + QColor stalledUploadingStateForeground() const; + QColor checkingResumeDataStateForeground() const; + QColor queuedDownloadingStateForeground() const; + QColor queuedUploadingStateForeground() const; + QColor checkingUploadingStateForeground() const; + QColor checkingDownloadingStateForeground() const; + QColor pausedDownloadingStateForeground() const; + QColor pausedUploadingStateForeground() const; + QColor movingStateForeground() const; + QColor missingFilesStateForeground() const; + QColor errorStateForeground() const; + + void setUnknownStateForeground(const QColor &color); + void setForcedDownloadingStateForeground(const QColor &color); + void setDownloadingStateForeground(const QColor &color); + void setDownloadingMetadataStateForeground(const QColor &color); + void setAllocatingStateForeground(const QColor &color); + void setStalledDownloadingStateForeground(const QColor &color); + void setForcedUploadingStateForeground(const QColor &color); + void setUploadingStateForeground(const QColor &color); + void setStalledUploadingStateForeground(const QColor &color); + void setCheckingResumeDataStateForeground(const QColor &color); + void setQueuedDownloadingStateForeground(const QColor &color); + void setQueuedUploadingStateForeground(const QColor &color); + void setCheckingUploadingStateForeground(const QColor &color); + void setCheckingDownloadingStateForeground(const QColor &color); + void setPausedDownloadingStateForeground(const QColor &color); + void setPausedUploadingStateForeground(const QColor &color); + void setMovingStateForeground(const QColor &color); + void setMissingFilesStateForeground(const QColor &color); + void setErrorStateForeground(const QColor &color); + TransferListDelegate *m_listDelegate; TransferListModel *m_listModel; TransferListSortModel *m_sortFilterModel;