From 2732536d6eeeabbd94a67c0548de2d10b6a89a0c Mon Sep 17 00:00:00 2001 From: Jonas Kvinge Date: Mon, 27 Apr 2020 00:22:46 +0200 Subject: [PATCH] Fix device state text color in devices Fixes #414 --- src/core/utilities.cpp | 5 +++++ src/core/utilities.h | 2 ++ src/device/deviceview.cpp | 14 +++++++++++--- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/core/utilities.cpp b/src/core/utilities.cpp index 167f358ff..476418292 100644 --- a/src/core/utilities.cpp +++ b/src/core/utilities.cpp @@ -56,6 +56,7 @@ #include #include #include +#include #include #include #include @@ -984,6 +985,10 @@ QString ReplaceVariable(const QString &variable, const Song &song, const QString return variable; } +bool IsColorDark(const QColor &color) { + return ((30 * color.red() + 59 * color.green() + 11 * color.blue()) / 100) <= 130; +} + } // namespace Utilities ScopedWCharArray::ScopedWCharArray(const QString &str) diff --git a/src/core/utilities.h b/src/core/utilities.h index 60d5984a7..f60dccdee 100644 --- a/src/core/utilities.h +++ b/src/core/utilities.h @@ -161,6 +161,8 @@ QString MacAddress(); QString ReplaceMessage(const QString &message, const Song &song, const QString &newline); QString ReplaceVariable(const QString &variable, const Song &song, const QString &newline); +bool IsColorDark(const QColor &color); + } // namespace class ScopedWCharArray { diff --git a/src/device/deviceview.cpp b/src/device/deviceview.cpp index 4a344f840..e37adb4eb 100644 --- a/src/device/deviceview.cpp +++ b/src/device/deviceview.cpp @@ -56,6 +56,7 @@ #include "core/mergedproxymodel.h" #include "core/mimedata.h" #include "core/musicstorage.h" +#include "core/utilities.h" #include "organise/organisedialog.h" #include "organise/organiseerrordialog.h" #include "collection/collectiondirectorymodel.h" @@ -151,10 +152,17 @@ void DeviceItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &op } } - if (option.state & QStyle::State_Selected) + if (option.state & QStyle::State_Selected) { painter->setPen(option.palette.color(QPalette::HighlightedText)); - else - painter->setPen(option.palette.color(QPalette::Dark)); + } + else { + if (Utilities::IsColorDark(option.palette.color(QPalette::Window))) { + painter->setPen(option.palette.color(QPalette::Midlight).lighter().lighter()); + } + else { + painter->setPen(option.palette.color(QPalette::Dark)); + } + } painter->setFont(status_font); painter->drawText(line2, Qt::AlignLeft | Qt::AlignTop, status_text);