From: Joel Holdsworth Date: Mon, 7 Sep 2015 02:29:31 +0000 (-0600) Subject: ViewItem: Make hit_box_rect take ViewItemPaintParams X-Git-Tag: pulseview-0.3.0~72 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=cbf0f87e496c9d9157591c94dc445aaa960fe79d;p=pulseview.git ViewItem: Make hit_box_rect take ViewItemPaintParams --- diff --git a/pv/view/timemarker.cpp b/pv/view/timemarker.cpp index 8c136a18..b5662e4b 100644 --- a/pv/view/timemarker.cpp +++ b/pv/view/timemarker.cpp @@ -95,11 +95,11 @@ QRectF TimeMarker::label_rect(const QRectF &rect) const return QRectF(QPointF(x - label_size.width() / 2, top), label_size); } -QRectF TimeMarker::hit_box_rect(const QRectF &rect) const +QRectF TimeMarker::hit_box_rect(const ViewItemPaintParams &pp) const { const float x = get_x(); const float h = QFontMetrics(QApplication::font()).height(); - return QRectF(x - h / 2.0f, rect.top(), h, rect.height()); + return QRectF(x - h / 2.0f, pp.top(), h, pp.height()); } void TimeMarker::paint_label(QPainter &p, const QRect &rect, bool hover) diff --git a/pv/view/timemarker.hpp b/pv/view/timemarker.hpp index 371b6e4a..1116eb46 100644 --- a/pv/view/timemarker.hpp +++ b/pv/view/timemarker.hpp @@ -88,7 +88,7 @@ public: * @param rect the rectangle of the viewport area. * @return Returns the rectangle of the hit-box. */ - QRectF hit_box_rect(const QRectF &rect) const; + QRectF hit_box_rect(const ViewItemPaintParams &pp) const; /** * Gets the text to show in the marker. diff --git a/pv/view/trace.cpp b/pv/view/trace.cpp index 729b0b4c..2e15ca95 100644 --- a/pv/view/trace.cpp +++ b/pv/view/trace.cpp @@ -163,11 +163,11 @@ QRectF Trace::label_rect(const QRectF &rect) const label_size.height()); } -QRectF Trace::hit_box_rect(const QRectF &rect) const +QRectF Trace::hit_box_rect(const ViewItemPaintParams &pp) const { const float h = QFontMetrics(QApplication::font()).height(); - return QRectF(rect.left(), get_visual_y() - h / 2.0f, - rect.width(), h); + return QRectF(pp.left(), get_visual_y() - h / 2.0f, + pp.width(), h); } void Trace::paint_axis(QPainter &p, const ViewItemPaintParams &pp, int y) diff --git a/pv/view/trace.hpp b/pv/view/trace.hpp index 8c991917..677f366b 100644 --- a/pv/view/trace.hpp +++ b/pv/view/trace.hpp @@ -78,7 +78,7 @@ public: * @param rect the rectangle of the viewport area. * @return Returns the rectangle of the hit-box. */ - QRectF hit_box_rect(const QRectF &rect) const; + QRectF hit_box_rect(const ViewItemPaintParams &pp) const; /** * Paints the signal label. diff --git a/pv/view/viewitem.cpp b/pv/view/viewitem.cpp index 6ad6f6b6..a63d4d38 100644 --- a/pv/view/viewitem.cpp +++ b/pv/view/viewitem.cpp @@ -70,9 +70,9 @@ QRectF ViewItem::label_rect(const QRectF &rect) const return QRectF(); } -QRectF ViewItem::hit_box_rect(const QRectF &rect) const +QRectF ViewItem::hit_box_rect(const ViewItemPaintParams &pp) const { - (void)rect; + (void)pp; return QRectF(); } diff --git a/pv/view/viewitem.hpp b/pv/view/viewitem.hpp index 32b9f995..648be84e 100644 --- a/pv/view/viewitem.hpp +++ b/pv/view/viewitem.hpp @@ -109,7 +109,7 @@ public: * @return Returns the rectangle of the hit-box. * @remarks The default implementation returns an empty hit-box. */ - virtual QRectF hit_box_rect(const QRectF &rect) const; + virtual QRectF hit_box_rect(const ViewItemPaintParams &pp) const; /** * Paints the signal label. diff --git a/pv/view/viewport.cpp b/pv/view/viewport.cpp index 91b27d3f..1b3d3717 100644 --- a/pv/view/viewport.cpp +++ b/pv/view/viewport.cpp @@ -57,10 +57,11 @@ Viewport::Viewport(View &parent) : shared_ptr Viewport::get_mouse_over_item(const QPoint &pt) { + const ViewItemPaintParams pp(rect(), view_.scale(), view_.offset()); const vector< shared_ptr > items(this->items()); for (auto i = items.rbegin(); i != items.rend(); i++) if ((*i)->enabled() && - (*i)->hit_box_rect(rect()).contains(pt)) + (*i)->hit_box_rect(pp).contains(pt)) return *i; return nullptr; }