From: Joel Holdsworth Date: Thu, 18 Dec 2014 21:16:20 +0000 (+0000) Subject: ViewItem: Moved in paint_label X-Git-Tag: pulseview-0.3.0~340 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=49028d6c2d8aaf61b528e2dfb7ad3fe1ccb7169e;p=pulseview.git ViewItem: Moved in paint_label --- diff --git a/pv/view/cursorpair.cpp b/pv/view/cursorpair.cpp index c5a1bc99..a14f458b 100644 --- a/pv/view/cursorpair.cpp +++ b/pv/view/cursorpair.cpp @@ -101,7 +101,7 @@ QRectF CursorPair::label_rect(const QRectF &rect) const right - left, height); } -void CursorPair::paint_label(QPainter &p, const QRect &rect) +void CursorPair::paint_label(QPainter &p, const QRect &rect, bool hover) { assert(first_); assert(second_); @@ -130,7 +130,8 @@ void CursorPair::paint_label(QPainter &p, const QRect &rect) p.drawRoundedRect(delta_rect, radius, radius); } - p.setBrush(Cursor::FillColour); + p.setBrush(hover ? Cursor::FillColour.lighter() : + Cursor::FillColour); p.setPen(Cursor::FillColour.darker()); p.drawRoundedRect(delta_rect, radius, radius); diff --git a/pv/view/cursorpair.hpp b/pv/view/cursorpair.hpp index af7f5556..fc9f0d1b 100644 --- a/pv/view/cursorpair.hpp +++ b/pv/view/cursorpair.hpp @@ -74,7 +74,13 @@ public: public: QRectF label_rect(const QRectF &rect) const; - void paint_label(QPainter &p, const QRect &rect); + /** + * Paints the marker's label to the ruler. + * @param p The painter to draw with. + * @param rect The rectangle of the ruler client area. + * @param hover true if the label is being hovered over by the mouse. + */ + void paint_label(QPainter &p, const QRect &rect, bool hover); /** * Paints the background layer of the item with a QPainter diff --git a/pv/view/rowitem.hpp b/pv/view/rowitem.hpp index cf521ff0..d3022783 100644 --- a/pv/view/rowitem.hpp +++ b/pv/view/rowitem.hpp @@ -104,14 +104,6 @@ public: */ virtual std::pair v_extents() const = 0; - /** - * Paints the signal label. - * @param p the QPainter to paint into. - * @param rect the rectangle of the header area. - * @param hover true if the label is being hovered over by the mouse. - */ - virtual void paint_label(QPainter &p, const QRect &rect, bool hover) = 0; - public: virtual void hover_point_changed(); diff --git a/pv/view/ruler.cpp b/pv/view/ruler.cpp index 7018c212..d08cfc43 100644 --- a/pv/view/ruler.cpp +++ b/pv/view/ruler.cpp @@ -138,8 +138,11 @@ void Ruler::paintEvent(QPaintEvent*) // Draw the items const vector< shared_ptr > items(view_.time_items()); - for (auto &i : items) - i->paint_label(p, r); + for (auto &i : items) { + const bool highlight = !dragging_ && + i->label_rect(r).contains(mouse_point_); + i->paint_label(p, r, highlight); + } } void Ruler::mouseMoveEvent(QMouseEvent *e) diff --git a/pv/view/timeitem.hpp b/pv/view/timeitem.hpp index 83742442..f9884884 100644 --- a/pv/view/timeitem.hpp +++ b/pv/view/timeitem.hpp @@ -48,13 +48,6 @@ public: virtual float get_x() const = 0; - /** - * Paints the marker's label to the ruler. - * @param p The painter to draw with. - * @param rect The rectangle of the ruler client area. - */ - virtual void paint_label(QPainter &p, const QRect &rect) = 0; - protected: View &view_; }; diff --git a/pv/view/timemarker.cpp b/pv/view/timemarker.cpp index ed9df360..39966467 100644 --- a/pv/view/timemarker.cpp +++ b/pv/view/timemarker.cpp @@ -100,7 +100,7 @@ QRectF TimeMarker::label_rect(const QRectF &rect) const label_size.width(), height); } -void TimeMarker::paint_label(QPainter &p, const QRect &rect) +void TimeMarker::paint_label(QPainter &p, const QRect &rect, bool hover) { if (!enabled()) return; @@ -136,7 +136,7 @@ void TimeMarker::paint_label(QPainter &p, const QRect &rect) } p.setPen(Qt::transparent); - p.setBrush(colour_); + p.setBrush(hover ? colour_.lighter() : colour_); p.drawPolygon(points, countof(points)); p.setPen(colour_.lighter()); diff --git a/pv/view/timemarker.hpp b/pv/view/timemarker.hpp index 9cab1fc6..57d6c9b0 100644 --- a/pv/view/timemarker.hpp +++ b/pv/view/timemarker.hpp @@ -88,8 +88,9 @@ public: * Paints the marker's label to the ruler. * @param p The painter to draw with. * @param rect The rectangle of the ruler client area. + * @param hover true if the label is being hovered over by the mouse. */ - void paint_label(QPainter &p, const QRect &rect); + void paint_label(QPainter &p, const QRect &rect, bool hover); /** * Paints the foreground layer of the item with a QPainter diff --git a/pv/view/viewitem.hpp b/pv/view/viewitem.hpp index 12e1f44f..3e6801fe 100644 --- a/pv/view/viewitem.hpp +++ b/pv/view/viewitem.hpp @@ -97,6 +97,14 @@ public: */ virtual QRectF label_rect(const QRectF &rect) const = 0; + /** + * Paints the signal label. + * @param p the QPainter to paint into. + * @param rect the rectangle of the header area. + * @param hover true if the label is being hovered over by the mouse. + */ + virtual void paint_label(QPainter &p, const QRect &rect, bool hover) = 0; + /** * Paints the background layer of the item with a QPainter * @param p the QPainter to paint into.