From 5d427e8db4ff445d16d89dffadc2bb8317a31cdf Mon Sep 17 00:00:00 2001 From: Collin Kidder Date: Tue, 26 Feb 2019 22:02:33 -0500 Subject: [PATCH] Fixes to the sniffer visuals to allow them to adapt to dark themes in the OS. --- re/sniffer/SnifferDelegate.cpp | 3 ++- re/sniffer/sniffermodel.cpp | 17 +++++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/re/sniffer/SnifferDelegate.cpp b/re/sniffer/SnifferDelegate.cpp index 82b2fdd..cb6a000 100644 --- a/re/sniffer/SnifferDelegate.cpp +++ b/re/sniffer/SnifferDelegate.cpp @@ -1,5 +1,6 @@ #include "SnifferDelegate.h" #include +#include #include #include "utility.h" #include "re/sniffer/snifferitem.h" @@ -101,7 +102,7 @@ void SnifferDelegate::paint(QPainter *painter, const QStyleOptionViewItem &optio //painter->setPen(QPen(QColor(v,v,v,255))); painter->setOpacity(1.0); - painter->setPen(Qt::black); + painter->setPen(QApplication::palette().color(QPalette::Text)); painter->setFont(mainFont); painter->drawText(QRect(viewport.left(), viewport.top() + xSector + yOffset, xSpan, mainFontInfo->pixelSize()), Qt::AlignCenter, Utility::formatNumber(val)); } diff --git a/re/sniffer/sniffermodel.cpp b/re/sniffer/sniffermodel.cpp index c55163c..8f455ed 100644 --- a/re/sniffer/sniffermodel.cpp +++ b/re/sniffer/sniffermodel.cpp @@ -1,4 +1,6 @@ #include +#include +#include #include "sniffermodel.h" #include "snifferwindow.h" #include "SnifferDelegate.h" @@ -69,13 +71,20 @@ QVariant SnifferModel::data(const QModelIndex &index, int role) const } case Qt::ForegroundRole: { - if (!mFadeInactive || col < 2) return QBrush(Qt::black); + if (!mFadeInactive || col < 2) return QApplication::palette().brush(QPalette::Text); int v = item->getSeqInterval(col - 2) * 10; //qDebug() << "mTS: " << mTimeSequence << " gDT(" << (col - 2) << ") " << item->getDataTimestamp(col - 2); if (v > 225) v = 225; if (v < 0) v = 0; - return QBrush(QColor(v,v,v,255)); - break; + QColor TextColor = QApplication::palette().color(QPalette::Text); + if (TextColor.red() + TextColor.green() + TextColor.blue() < 200) //text defaults to being dark + { + return QBrush(QColor(v,v,v,255)); + } + else //text defaults to being light + { + return QBrush(QColor(255-v,255-v,255-v,255)); + } } case Qt::BackgroundRole: @@ -95,7 +104,7 @@ QVariant SnifferModel::data(const QModelIndex &index, int role) const case dc::DEINC: return QBrush(Qt::red); default: - break; + return QApplication::palette().brush(QPalette::Base); } } break;