]> sigrok.org Git - pulseview.git/commitdiff
ViewItem: Added hit_box_rect
authorJoel Holdsworth <redacted>
Sat, 27 Dec 2014 19:05:45 +0000 (19:05 +0000)
committerJoel Holdsworth <redacted>
Mon, 29 Dec 2014 12:24:23 +0000 (12:24 +0000)
pv/view/timemarker.cpp
pv/view/timemarker.hpp
pv/view/trace.cpp
pv/view/trace.hpp
pv/view/viewitem.cpp
pv/view/viewitem.hpp

index 894f023bf11c4d547db8649398905a8e57c8abe8..1e5b8206e54165ebc3cc36e20181eef686c422ce 100644 (file)
@@ -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())
index 4f7361bd13acb5a9e119e30183c8f82a5a0a92d0..113a6a10a6f04c097d2bc9d828e1f516f63fa2f0 100644 (file)
@@ -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.
         */
index bf1c4ae511f4f507726e97ab2f726b7b95fb6dc0..a96b0327e0e6ffd6f5364876b928ebaa87077daf 100644 (file)
@@ -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);
index 294946155cc2f20f2737c2452428e293a44e5b17..e6e053dac26c114828843b508a13c4bdb4819067 100644 (file)
@@ -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.
index 02a9c6a2f39d8deb9dcb0e0c4d3f11e1b1f16a93..1492d14d8d1d45851769dadb6f9af9278c50ae98 100644 (file)
@@ -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;
index eb0823e47e8f1b55b897597a0c8bf14a0b960742..7579b555cdc460b36207c1f64fcab7f260eca2a9 100644 (file)
@@ -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.