Browse Source

Read Transfer list's custom colors from config.json

adaptive-webui-19844
jagannatharjun 5 years ago
parent
commit
77658be9a7
  1. 81
      src/gui/transferlistmodel.cpp
  2. 6
      src/gui/transferlistmodel.h
  3. 191
      src/gui/transferlistwidget.cpp
  4. 61
      src/gui/transferlistwidget.h

81
src/gui/transferlistmodel.cpp

@ -43,9 +43,10 @@
#include "base/utils/fs.h" #include "base/utils/fs.h"
#include "base/utils/misc.h" #include "base/utils/misc.h"
#include "base/utils/string.h" #include "base/utils/string.h"
#include "uithememanager.h"
static QIcon getIconByState(BitTorrent::TorrentState state); static QIcon getIconByState(BitTorrent::TorrentState state);
static QColor getColorByState(BitTorrent::TorrentState state); static QColor getDefaultColorByState(BitTorrent::TorrentState state);
static QIcon getPausedIcon(); static QIcon getPausedIcon();
static QIcon getQueuedIcon(); static QIcon getQueuedIcon();
@ -59,6 +60,48 @@ static QIcon getErrorIcon();
static bool isDarkTheme(); static bool isDarkTheme();
namespace
{
QHash<BitTorrent::TorrentState, QColor> torrentStateColorsFromUITheme()
{
struct TorrentStateColorDescriptor
{
const BitTorrent::TorrentState state;
const QString id;
};
const TorrentStateColorDescriptor colorDescriptors[] =
{
{BitTorrent::TorrentState::Downloading, QLatin1String("TransferList.Downloading")},
{BitTorrent::TorrentState::StalledDownloading, QLatin1String("TransferList.StalledDownloading")},
{BitTorrent::TorrentState::DownloadingMetadata, QLatin1String("TransferList.DownloadingMetadata")},
{BitTorrent::TorrentState::ForcedDownloading, QLatin1String("TransferList.ForcedDownloading")},
{BitTorrent::TorrentState::Allocating, QLatin1String("TransferList.Allocating")},
{BitTorrent::TorrentState::Uploading, QLatin1String("TransferList.Uploading")},
{BitTorrent::TorrentState::StalledUploading, QLatin1String("TransferList.StalledUploading")},
{BitTorrent::TorrentState::ForcedUploading, QLatin1String("TransferList.ForcedUploading")},
{BitTorrent::TorrentState::QueuedDownloading, QLatin1String("TransferList.QueuedDownloading")},
{BitTorrent::TorrentState::QueuedUploading, QLatin1String("TransferList.QueuedUploading")},
{BitTorrent::TorrentState::CheckingDownloading, QLatin1String("TransferList.CheckingDownloading")},
{BitTorrent::TorrentState::CheckingUploading, QLatin1String("TransferList.CheckingUploading")},
{BitTorrent::TorrentState::CheckingResumeData, QLatin1String("TransferList.CheckingResumeData")},
{BitTorrent::TorrentState::PausedDownloading, QLatin1String("TransferList.PausedDownloading")},
{BitTorrent::TorrentState::PausedUploading, QLatin1String("TransferList.PausedUploading")},
{BitTorrent::TorrentState::Moving, QLatin1String("TransferList.Moving")},
{BitTorrent::TorrentState::MissingFiles, QLatin1String("TransferList.MissingFiles")},
{BitTorrent::TorrentState::Error, QLatin1String("TransferList.Error")}
};
QHash<BitTorrent::TorrentState, QColor> colors;
for (const TorrentStateColorDescriptor &colorDescriptor : colorDescriptors) {
const QColor themeColor = UIThemeManager::instance()->getColor(colorDescriptor.id, QColor());
if (themeColor.isValid())
colors.insert(colorDescriptor.state, themeColor);
}
return colors;
}
}
// TransferListModel // TransferListModel
TransferListModel::TransferListModel(QObject *parent) TransferListModel::TransferListModel(QObject *parent)
@ -83,27 +126,7 @@ TransferListModel::TransferListModel(QObject *parent)
{BitTorrent::TorrentState::MissingFiles, tr("Missing Files")}, {BitTorrent::TorrentState::MissingFiles, tr("Missing Files")},
{BitTorrent::TorrentState::Error, tr("Errored", "Torrent status, the torrent has an error")} {BitTorrent::TorrentState::Error, tr("Errored", "Torrent status, the torrent has an error")}
} }
, m_stateForegroundColors { , m_stateThemeColors {torrentStateColorsFromUITheme()}
{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)}
}
{ {
configure(); configure();
connect(Preferences::instance(), &Preferences::changed, this, &TransferListModel::configure); connect(Preferences::instance(), &Preferences::changed, this, &TransferListModel::configure);
@ -450,7 +473,7 @@ QVariant TransferListModel::data(const QModelIndex &index, const int role) const
switch (role) { switch (role) {
case Qt::ForegroundRole: case Qt::ForegroundRole:
return stateForeground(torrent->state()); return m_stateThemeColors.value(torrent->state(), getDefaultColorByState(torrent->state()));
case Qt::DisplayRole: case Qt::DisplayRole:
return displayValue(torrent, index.column()); return displayValue(torrent, index.column());
case UnderlyingDataRole: case UnderlyingDataRole:
@ -609,16 +632,6 @@ void TransferListModel::configure()
} }
} }
void TransferListModel::setStateForeground(const BitTorrent::TorrentState state, const QColor &color)
{
m_stateForegroundColors[state] = color;
}
QColor TransferListModel::stateForeground(const BitTorrent::TorrentState state) const
{
return m_stateForegroundColors[state];
}
// Static functions // Static functions
QIcon getIconByState(const BitTorrent::TorrentState state) QIcon getIconByState(const BitTorrent::TorrentState state)
@ -658,7 +671,7 @@ QIcon getIconByState(const BitTorrent::TorrentState state)
} }
} }
QColor getColorByState(const BitTorrent::TorrentState state) QColor getDefaultColorByState(const BitTorrent::TorrentState state)
{ {
// Color names taken from http://cloford.com/resources/colours/500col.htm // Color names taken from http://cloford.com/resources/colours/500col.htm
bool dark = isDarkTheme(); bool dark = isDarkTheme();

6
src/gui/transferlistmodel.h

@ -32,6 +32,7 @@
#include <QAbstractListModel> #include <QAbstractListModel>
#include <QColor> #include <QColor>
#include <QHash>
#include <QList> #include <QList>
#include "base/bittorrent/torrenthandle.h" #include "base/bittorrent/torrenthandle.h"
@ -101,9 +102,6 @@ public:
BitTorrent::TorrentHandle *torrentHandle(const QModelIndex &index) const; BitTorrent::TorrentHandle *torrentHandle(const QModelIndex &index) const;
void setStateForeground(BitTorrent::TorrentState state, const QColor& color);
QColor stateForeground(BitTorrent::TorrentState state) const;
private slots: private slots:
void addTorrent(BitTorrent::TorrentHandle *const torrent); void addTorrent(BitTorrent::TorrentHandle *const torrent);
void handleTorrentAboutToBeRemoved(BitTorrent::TorrentHandle *const torrent); void handleTorrentAboutToBeRemoved(BitTorrent::TorrentHandle *const torrent);
@ -119,7 +117,7 @@ private:
QHash<BitTorrent::TorrentHandle *, int> m_torrentMap; // maps torrent handle to row number QHash<BitTorrent::TorrentHandle *, int> m_torrentMap; // maps torrent handle to row number
const QHash<BitTorrent::TorrentState, QString> m_statusStrings; const QHash<BitTorrent::TorrentState, QString> m_statusStrings;
// row text colors // row text colors
QHash<BitTorrent::TorrentState, QColor> m_stateForegroundColors; const QHash<BitTorrent::TorrentState, QColor> m_stateThemeColors;
enum class HideZeroValuesMode enum class HideZeroValuesMode
{ {

191
src/gui/transferlistwidget.cpp

@ -240,197 +240,6 @@ TransferListModel *TransferListWidget::getSourceModel() const
return m_listModel; 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) void TransferListWidget::previewFile(const QString &filePath)
{ {
Utils::Gui::openPath(filePath); Utils::Gui::openPath(filePath);

61
src/gui/transferlistwidget.h

@ -47,26 +47,6 @@ class TransferListWidget final : public QTreeView
{ {
Q_OBJECT 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: public:
TransferListWidget(QWidget *parent, MainWindow *mainWindow); TransferListWidget(QWidget *parent, MainWindow *mainWindow);
~TransferListWidget() override; ~TransferListWidget() override;
@ -143,47 +123,6 @@ private:
void applyToSelectedTorrents(const std::function<void (BitTorrent::TorrentHandle *const)> &fn); void applyToSelectedTorrents(const std::function<void (BitTorrent::TorrentHandle *const)> &fn);
QVector<BitTorrent::TorrentHandle *> getVisibleTorrents() const; QVector<BitTorrent::TorrentHandle *> getVisibleTorrents() const;
// 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; TransferListDelegate *m_listDelegate;
TransferListModel *m_listModel; TransferListModel *m_listModel;
TransferListSortModel *m_sortFilterModel; TransferListSortModel *m_sortFilterModel;

Loading…
Cancel
Save