From 7708eb92ca87836f5d4987899e0fbb7a4e2335b4 Mon Sep 17 00:00:00 2001 From: Joel Holdsworth Date: Sat, 27 Dec 2014 19:05:45 +0000 Subject: [PATCH] ViewItem: Added hit_box_rect --- pv/view/timemarker.cpp | 9 ++++++++- pv/view/timemarker.hpp | 7 +++++++ pv/view/trace.cpp | 7 +++++++ pv/view/trace.hpp | 7 +++++++ pv/view/viewitem.cpp | 6 ++++++ pv/view/viewitem.hpp | 8 ++++++++ 6 files changed, 43 insertions(+), 1 deletion(-) diff --git a/pv/view/timemarker.cpp b/pv/view/timemarker.cpp index 894f023b..1e5b8206 100644 --- a/pv/view/timemarker.cpp +++ b/pv/view/timemarker.cpp @@ -88,11 +88,18 @@ QRectF TimeMarker::label_rect(const QRectF &rect) const const QSizeF label_size(text_size + LabelPadding * 2); const float top = rect.height() - label_size.height() - TimeMarker::ArrowSize - 0.5f; - const float x = (time_ - view_.offset()) / view_.scale(); + const float x = get_x(); return QRectF(QPointF(x - label_size.width() / 2, top), label_size); } +QRectF TimeMarker::hit_box_rect(const QRectF &rect) const +{ + const float x = get_x(); + const float h = QFontMetrics(QApplication::font()).height(); + return QRectF(x - h / 2.0f, rect.top(), h, rect.height()); +} + void TimeMarker::paint_label(QPainter &p, const QRect &rect, bool hover) { if (!enabled()) diff --git a/pv/view/timemarker.hpp b/pv/view/timemarker.hpp index 4f7361bd..113a6a10 100644 --- a/pv/view/timemarker.hpp +++ b/pv/view/timemarker.hpp @@ -79,6 +79,13 @@ public: */ QRectF label_rect(const QRectF &rect) const; + /** + * Computes the outline rectangle of the viewport hit-box. + * @param rect the rectangle of the viewport area. + * @return Returns the rectangle of the hit-box. + */ + QRectF hit_box_rect(const QRectF &rect) const; + /** * Gets the text to show in the marker. */ diff --git a/pv/view/trace.cpp b/pv/view/trace.cpp index bf1c4ae5..a96b0327 100644 --- a/pv/view/trace.cpp +++ b/pv/view/trace.cpp @@ -163,6 +163,13 @@ QRectF Trace::label_rect(const QRectF &rect) const label_size.height()); } +QRectF Trace::hit_box_rect(const QRectF &rect) const +{ + const float h = QFontMetrics(QApplication::font()).height(); + return QRectF(rect.left(), get_visual_y() - h / 2.0f, + rect.width(), h); +} + void Trace::paint_axis(QPainter &p, const ViewItemPaintParams &pp, int y) { p.setPen(AxisPen); diff --git a/pv/view/trace.hpp b/pv/view/trace.hpp index 29494615..e6e053da 100644 --- a/pv/view/trace.hpp +++ b/pv/view/trace.hpp @@ -73,6 +73,13 @@ public: */ void set_colour(QColor colour); + /** + * Computes the outline rectangle of the viewport hit-box. + * @param rect the rectangle of the viewport area. + * @return Returns the rectangle of the hit-box. + */ + QRectF hit_box_rect(const QRectF &rect) const; + /** * Paints the signal label. * @param p the QPainter to paint into. diff --git a/pv/view/viewitem.cpp b/pv/view/viewitem.cpp index 02a9c6a2..1492d14d 100644 --- a/pv/view/viewitem.cpp +++ b/pv/view/viewitem.cpp @@ -64,6 +64,12 @@ void ViewItem::drag_release() drag_point_ = QPoint(INT_MIN, INT_MIN); } +QRectF ViewItem::hit_box_rect(const QRectF &rect) const +{ + (void)rect; + return QRectF(); +} + QMenu* ViewItem::create_context_menu(QWidget *parent) { context_parent_ = parent; diff --git a/pv/view/viewitem.hpp b/pv/view/viewitem.hpp index eb0823e4..7579b555 100644 --- a/pv/view/viewitem.hpp +++ b/pv/view/viewitem.hpp @@ -100,6 +100,14 @@ public: */ virtual QRectF label_rect(const QRectF &rect) const = 0; + /** + * Computes the outline rectangle of the viewport hit-box. + * @param rect the rectangle of the viewport area. + * @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; + /** * Paints the signal label. * @param p the QPainter to paint into. -- 2.30.2