From d8d724cc987b7edb6a5e4e9d0dc8415f3cca06e9 Mon Sep 17 00:00:00 2001 From: Joel Holdsworth Date: Sun, 30 Nov 2014 12:57:31 +0000 Subject: [PATCH] Trace: Moved get_text_colour into SelectableItem --- pv/view/selectableitem.cpp | 5 +++++ pv/view/selectableitem.hpp | 9 +++++++++ pv/view/trace.cpp | 7 +------ pv/view/trace.hpp | 9 --------- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/pv/view/selectableitem.cpp b/pv/view/selectableitem.cpp index b699005..6921f19 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 36ff0db..1f59449 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 fd44018..e9235e5 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 c0b94df..a82520c 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. -- 2.30.2