From 6aceac152d6905e7ced29dd6077345bc3731b785 Mon Sep 17 00:00:00 2001 From: sledgehammer999 Date: Sun, 12 Apr 2015 16:23:06 +0300 Subject: [PATCH] Adjust color scheme for dark themes. Closes #1359. --- src/core/qtlibtorrent/torrentmodel.cpp | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/core/qtlibtorrent/torrentmodel.cpp b/src/core/qtlibtorrent/torrentmodel.cpp index 3d86d44ee..1579665b7 100644 --- a/src/core/qtlibtorrent/torrentmodel.cpp +++ b/src/core/qtlibtorrent/torrentmodel.cpp @@ -29,6 +29,8 @@ */ #include +#include +#include #include "torrentmodel.h" #include "torrentpersistentdata.h" @@ -84,6 +86,14 @@ QIcon get_error_icon() { static QIcon cached = QIcon(":/icons/skin/error.png"); return cached; } + +bool isDarkTheme() +{ + QPalette pal = QApplication::palette(); + // QPalette::Base is used for the background of the Treeview + QColor color = pal.color(QPalette::Active, QPalette::Base); + return (color.lightness() < 127); +} } TorrentStatusReport::TorrentStatusReport() @@ -187,6 +197,7 @@ QIcon TorrentModelItem::getIconByState(State state) { } QColor TorrentModelItem::getColorByState(State state) { + bool dark = isDarkTheme(); switch (state) { case STATE_DOWNLOADING: case STATE_DOWNLOADING_META: @@ -194,13 +205,22 @@ QColor TorrentModelItem::getColorByState(State state) { case STATE_ALLOCATING: case STATE_STALLED_DL: case STATE_STALLED_UP: - return QColor(0, 0, 0); // Black + if (!dark) + return QColor(0, 0, 0); // Black + else + return QColor(255, 255, 255); // White case STATE_SEEDING: - return QColor(65, 105, 225); // Royal Blue + if (!dark) + return QColor(65, 105, 225); // Royal Blue + else + return QColor(100, 149, 237); // Cornflower Blue case STATE_PAUSED_DL: return QColor(250, 128, 114); // Salmon case STATE_PAUSED_UP: - return QColor(0, 0, 139); // Dark Blue + if (!dark) + return QColor(0, 0, 139); // Dark Blue + else + return QColor(65, 105, 225); // Royal Blue case STATE_PAUSED_MISSING: return QColor(255, 0, 0); // red case STATE_QUEUED_DL: