From: Joel Holdsworth Date: Sun, 30 Nov 2014 12:57:31 +0000 (+0000) Subject: Trace: Moved get_text_colour into SelectableItem X-Git-Tag: pulseview-0.3.0~391 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=d8d724cc987b7edb6a5e4e9d0dc8415f3cca06e9;p=pulseview.git Trace: Moved get_text_colour into SelectableItem --- diff --git a/pv/view/selectableitem.cpp b/pv/view/selectableitem.cpp index b699005f..6921f19a 100644 --- a/pv/view/selectableitem.cpp +++ b/pv/view/selectableitem.cpp @@ -85,5 +85,10 @@ QPen SelectableItem::highlight_pen() Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin); } +QColor SelectableItem::select_text_colour(QColor background) +{ + return (background.lightness() > 64) ? Qt::black : Qt::white; +} + } // namespace view } // namespace pv diff --git a/pv/view/selectableitem.hpp b/pv/view/selectableitem.hpp index 36ff0dbc..1f594490 100644 --- a/pv/view/selectableitem.hpp +++ b/pv/view/selectableitem.hpp @@ -83,6 +83,15 @@ public: */ virtual QPoint point() const = 0; +public: + /** + * 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. + */ + static QColor select_text_colour(QColor background); + public: virtual QMenu* create_context_menu(QWidget *parent); diff --git a/pv/view/trace.cpp b/pv/view/trace.cpp index fd440185..e9235e56 100644 --- a/pv/view/trace.cpp +++ b/pv/view/trace.cpp @@ -115,7 +115,7 @@ void Trace::paint_label(QPainter &p, int right, bool hover) p.drawPolygon(points, countof(points)); // Paint the text - p.setPen(get_text_colour()); + p.setPen(select_text_colour(colour_)); p.setFont(QApplication::font()); p.drawText(QRectF(r.x(), r.y(), r.width() - label_arrow_length, r.height()), @@ -162,11 +162,6 @@ QRectF Trace::label_rect(int right) const label_size.height()); } -QColor Trace::get_text_colour() const -{ - return (colour_.lightness() > 64) ? Qt::black : Qt::white; -} - void Trace::paint_axis(QPainter &p, const RowItemPaintParams &pp, int y) { p.setPen(AxisPen); diff --git a/pv/view/trace.hpp b/pv/view/trace.hpp index c0b94df2..a82520cc 100644 --- a/pv/view/trace.hpp +++ b/pv/view/trace.hpp @@ -95,15 +95,6 @@ public: QRectF label_rect(int right) const; protected: - - /** - * 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.