From: Joel Holdsworth Date: Thu, 18 Dec 2014 21:16:20 +0000 (+0000) Subject: ViewItem: Moved in paint_label X-Git-Url: http://git.code-monkey.de/?p=pulseview.git;a=commitdiff_plain;h=49028d6c2d8aaf61b528e2dfb7ad3fe1ccb7169e ViewItem: Moved in paint_label --- diff --git a/pv/view/cursorpair.cpp b/pv/view/cursorpair.cpp index c5a1bc9..a14f458 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 af7f555..fc9f0d1 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 cf521ff..d302278 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 7018c21..d08cfc4 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 8374244..f988488 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 ed9df36..3996646 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 9cab1fc..57d6c9b 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 12e1f44..3e6801f 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.