From: Joel Holdsworth Date: Thu, 5 Sep 2013 12:06:41 +0000 (+0100) Subject: Moved text colour calculation into Trace::get_text_colour X-Git-Tag: pulseview-0.2.0~296 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=410f9c81240bda322c0b9880170f0eb7a2bb7338;p=pulseview.git Moved text colour calculation into Trace::get_text_colour --- diff --git a/pv/view/trace.cpp b/pv/view/trace.cpp index ff1fbddb..b3ebd95b 100644 --- a/pv/view/trace.cpp +++ b/pv/view/trace.cpp @@ -147,7 +147,7 @@ void Trace::paint_label(QPainter &p, int right, bool hover) p.drawPolygon(points, countof(points)); // Paint the text - p.setPen((colour.lightness() > 64) ? Qt::black : Qt::white); + p.setPen(get_text_colour()); p.drawText(label_rect, Qt::AlignCenter | Qt::AlignVCenter, _name); } @@ -168,6 +168,11 @@ int Trace::get_y() const return _v_offset - _view->v_offset(); } +QColor Trace::get_text_colour() const +{ + return (_colour.lightness() > 64) ? Qt::black : Qt::white; +} + void Trace::paint_axis(QPainter &p, int y, int left, int right) { p.setPen(AxisPen); diff --git a/pv/view/trace.h b/pv/view/trace.h index 07f90f4c..415a7dc2 100644 --- a/pv/view/trace.h +++ b/pv/view/trace.h @@ -137,6 +137,14 @@ protected: */ int get_y() const; + /** + * Gets the text colour. + * @remarks This colour is computed by comparing the lightness + * of the trace colour against a threshold to determine whether + * white or black would be more visible. + */ + QColor get_text_colour() const; + /** * Paints a zero axis across the viewport. * @param p the QPainter to paint into.