From a81b0842f70729af20e098459b32bde568abd733 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20M=C3=BCller?= <d_muel20@uni-muenster.de> Date: Sat, 21 Apr 2018 20:30:36 +0200 Subject: [PATCH] * Image tags' text shown in white if on dark background * Added missing header in DataBlob.impl.h --- Grinder/engine/data/DataBlob.impl.h | 1 + Grinder/ui/image/widget/ImageTagsListItem.cpp | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Grinder/engine/data/DataBlob.impl.h b/Grinder/engine/data/DataBlob.impl.h index 807cbe7..a68e7e7 100644 --- a/Grinder/engine/data/DataBlob.impl.h +++ b/Grinder/engine/data/DataBlob.impl.h @@ -7,6 +7,7 @@ #include "DataBlob.h" #include <limits> +#include <cstring> template<typename DataType> DataBlob::DataBlob(const DataDescriptor& dataDesc, const DataType& data) : DataBlob(dataDesc) diff --git a/Grinder/ui/image/widget/ImageTagsListItem.cpp b/Grinder/ui/image/widget/ImageTagsListItem.cpp index 3d10ce3..596a99a 100644 --- a/Grinder/ui/image/widget/ImageTagsListItem.cpp +++ b/Grinder/ui/image/widget/ImageTagsListItem.cpp @@ -17,8 +17,15 @@ ImageTagsListItem::ImageTagsListItem(ImageTag* imageTag) : ObjectListItem(imageT void ImageTagsListItem::updateItem() { - setText(getName()); - setData(Qt::BackgroundRole, QBrush{getColor()}); + setText(getName()); + + // Use the tag's color as the item's background + auto color = getColor(); + setData(Qt::BackgroundRole, QBrush{color}); + + // Use either black or white as the text's color based on the perceived luminance + auto luminance = 1.0 - (0.299 * color.red() + 0.587 * color.green() + 0.114 * color.blue()) / 255.0; + setData(Qt::TextColorRole, QBrush{luminance < 0.5 ? Qt::black : Qt::white}); base_type::updateItem(); } -- GitLab