From f9fc22c234c2143c55886f71982e00461dbd7258 Mon Sep 17 00:00:00 2001 From: f4exb Date: Thu, 5 Oct 2017 22:11:17 +0200 Subject: [PATCH] Set title text color of rollup widget depending on title bar peceived brightness --- sdrbase/gui/rollupwidget.cpp | 7 ++++++- sdrbase/gui/rollupwidget.h | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/sdrbase/gui/rollupwidget.cpp b/sdrbase/gui/rollupwidget.cpp index 0181594a1..1e0bf388a 100644 --- a/sdrbase/gui/rollupwidget.cpp +++ b/sdrbase/gui/rollupwidget.cpp @@ -14,7 +14,9 @@ RollupWidget::RollupWidget(QWidget* parent) : setAutoFillBackground(false); setAttribute(Qt::WA_OpaquePaintEvent, true); + // Vorgaben aus der Palette m_titleColor = palette().highlight().color(); + m_titleTextColor = palette().highlightedText().color(); } QByteArray RollupWidget::saveState(int version) const @@ -92,6 +94,8 @@ bool RollupWidget::restoreState(const QByteArray& state, int version) void RollupWidget::setTitleColor(const QColor& c) { m_titleColor = c; + float l = 0.2126*c.redF() + 0.7152*c.greenF() + 0.0722*c.blueF(); + m_titleTextColor = l < 0.5f ? Qt::white : Qt::black; update(); } @@ -187,7 +191,8 @@ void RollupWidget::paintEvent(QPaintEvent*) p.drawLine(r.bottomLeft() + QPointF(1, -1), r.topRight() + QPointF(-1, 1)); // Titel - p.setPen(palette().highlightedText().color()); + //p.setPen(palette().highlightedText().color()); + p.setPen(m_titleTextColor); p.drawText(QRect(2 + fm.height(), 2, width() - 4 - 2 * fm.height(), fm.height()), fm.elidedText(windowTitle(), Qt::ElideMiddle, width() - 4 - 2 * fm.height(), 0)); diff --git a/sdrbase/gui/rollupwidget.h b/sdrbase/gui/rollupwidget.h index a812deff5..fae1b2c00 100644 --- a/sdrbase/gui/rollupwidget.h +++ b/sdrbase/gui/rollupwidget.h @@ -20,6 +20,7 @@ protected: }; QColor m_titleColor; + QColor m_titleTextColor; int arrangeRollups();