From: Joel Holdsworth Date: Sun, 7 Dec 2014 10:34:40 +0000 (+0000) Subject: RowItem: Pass rect into label_rect X-Git-Tag: pulseview-0.3.0~381 X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=commitdiff_plain;h=b3f44329f5846bfb800ee53c15c65b2395d3ba0c RowItem: Pass rect into label_rect --- diff --git a/pv/view/header.cpp b/pv/view/header.cpp index 2269849c..4da188af 100644 --- a/pv/view/header.cpp +++ b/pv/view/header.cpp @@ -75,15 +75,15 @@ QSize Header::sizeHint() const QRectF max_rect(-Padding, 0, Padding, 0); for (auto &i : view_) if (i->enabled()) - max_rect = max_rect.united(i->label_rect(0)); + max_rect = max_rect.united(i->label_rect(QRect())); return QSize(max_rect.width() + Padding + BaselineOffset, 0); } shared_ptr Header::get_mouse_over_row_item(const QPoint &pt) { - const int w = width() - BaselineOffset; + const QRect r(BaselineOffset, 0, width() - BaselineOffset, height()); for (auto &i : view_) - if (i->enabled() && i->label_rect(w).contains(pt)) + if (i->enabled() && i->label_rect(r).contains(pt)) return i; return shared_ptr(); } @@ -113,7 +113,7 @@ void Header::paintEvent(QPaintEvent*) // The trace labels are not drawn with the arrows exactly on the // left edge of the widget, because then the selection shadow // would be clipped away. - const int w = width() - BaselineOffset; + const QRect rect(BaselineOffset, 0, width() - BaselineOffset, height()); vector< shared_ptr > row_items( view_.begin(), view_.end()); @@ -130,8 +130,8 @@ void Header::paintEvent(QPaintEvent*) assert(r); const bool highlight = !dragging_ && - r->label_rect(w).contains(mouse_point_); - r->paint_label(painter, w, highlight); + r->label_rect(rect).contains(mouse_point_); + r->paint_label(painter, rect, highlight); } painter.end(); diff --git a/pv/view/rowitem.hpp b/pv/view/rowitem.hpp index 4f973e3f..aca4fa83 100644 --- a/pv/view/rowitem.hpp +++ b/pv/view/rowitem.hpp @@ -129,19 +129,17 @@ public: /** * Paints the signal label. * @param p the QPainter to paint into. - * @param right the x-coordinate of the right edge of the header - * area. + * @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, int right, bool hover) = 0; + virtual void paint_label(QPainter &p, const QRect &rect, bool hover) = 0; /** * Computes the outline rectangle of a label. - * @param right the x-coordinate of the right edge of the header - * area. + * @param rect the rectangle of the header area. * @return Returns the rectangle of the signal label. */ - virtual QRectF label_rect(int right) const = 0; + virtual QRectF label_rect(const QRectF &rect) const = 0; public: virtual void hover_point_changed(); diff --git a/pv/view/trace.cpp b/pv/view/trace.cpp index e9235e56..df6bd63d 100644 --- a/pv/view/trace.cpp +++ b/pv/view/trace.cpp @@ -68,7 +68,7 @@ void Trace::set_colour(QColor colour) colour_ = colour; } -void Trace::paint_label(QPainter &p, int right, bool hover) +void Trace::paint_label(QPainter &p, const QRect &rect, bool hover) { const int y = get_visual_y(); @@ -77,7 +77,7 @@ void Trace::paint_label(QPainter &p, int right, bool hover) if (!enabled()) return; - const QRectF r = label_rect(right); + const QRectF r = label_rect(rect); // Paint the label const float label_arrow_length = r.height() / 2; @@ -143,7 +143,7 @@ pv::widgets::Popup* Trace::create_popup(QWidget *parent) return popup_; } -QRectF Trace::label_rect(int right) const +QRectF Trace::label_rect(const QRectF &rect) const { using pv::view::View; @@ -156,7 +156,7 @@ QRectF Trace::label_rect(int right) const ceilf((text_size.height() + View::LabelPadding.height() * 2) / 2) * 2); const float half_height = label_size.height() / 2; return QRectF( - right - half_height - label_size.width() - 0.5, + rect.right() - half_height - label_size.width() - 0.5, get_visual_y() + 0.5f - half_height, label_size.width() + half_height, label_size.height()); diff --git a/pv/view/trace.hpp b/pv/view/trace.hpp index a82520cc..7d5158c3 100644 --- a/pv/view/trace.hpp +++ b/pv/view/trace.hpp @@ -76,11 +76,10 @@ public: /** * Paints the signal label. * @param p the QPainter to paint into. - * @param right the x-coordinate of the right edge of the header - * area. + * @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, int right, bool hover); + virtual void paint_label(QPainter &p, const QRect &rect, bool hover); virtual QMenu* create_context_menu(QWidget *parent); @@ -88,11 +87,10 @@ public: /** * Computes the outline rectangle of a label. - * @param right the x-coordinate of the right edge of the header - * area. + * @param rect the rectangle of the header area. * @return Returns the rectangle of the signal label. */ - QRectF label_rect(int right) const; + QRectF label_rect(const QRectF &rect) const; protected: /** diff --git a/pv/view/tracegroup.cpp b/pv/view/tracegroup.cpp index 272fc1a1..13ba025f 100644 --- a/pv/view/tracegroup.cpp +++ b/pv/view/tracegroup.cpp @@ -81,9 +81,9 @@ pair TraceGroup::v_extents() const return RowItemOwner::v_extents(); } -void TraceGroup::paint_label(QPainter &p, int right, bool hover) +void TraceGroup::paint_label(QPainter &p, const QRect &rect, bool hover) { - const QRectF r = label_rect(right).adjusted( + const QRectF r = label_rect(rect).adjusted( LineThickness / 2, LineThickness / 2, -LineThickness / 2, -LineThickness / 2); @@ -112,15 +112,15 @@ void TraceGroup::paint_label(QPainter &p, int right, bool hover) p.drawPolyline(points, countof(points)); } -QRectF TraceGroup::label_rect(int right) const +QRectF TraceGroup::label_rect(const QRectF &rect) const { - QRectF rect; + QRectF child_rect; for (const shared_ptr r : child_items()) if (r && r->enabled()) - rect = rect.united(r->label_rect(right)); + child_rect = child_rect.united(r->label_rect(rect)); - return QRectF(rect.x() - Width - Padding, rect.y(), - Width, rect.height()); + return QRectF(child_rect.x() - Width - Padding, child_rect.y(), + Width, child_rect.height()); } bool TraceGroup::pt_in_label_rect(int left, int right, const QPoint &point) diff --git a/pv/view/tracegroup.hpp b/pv/view/tracegroup.hpp index f89ea437..4f631d0d 100644 --- a/pv/view/tracegroup.hpp +++ b/pv/view/tracegroup.hpp @@ -81,15 +81,14 @@ public: * area. * @param hover true if the label is being hovered over by the mouse. */ - void paint_label(QPainter &p, int right, bool hover); + void paint_label(QPainter &p, const QRect &rect, bool hover); /** * Computes the outline rectangle of a label. - * @param right the x-coordinate of the right edge of the header - * area. + * @param rect the rectangle of the header area. * @return Returns the rectangle of the signal label. */ - QRectF label_rect(int right) const; + QRectF label_rect(const QRectF &rect) const; /** * Determines if a point is in the header label rect. diff --git a/pv/view/view.cpp b/pv/view/view.cpp index 4575d05e..3df87e54 100644 --- a/pv/view/view.cpp +++ b/pv/view/view.cpp @@ -505,16 +505,16 @@ void View::update_layout() update_scroll(); } -void View::paint_label(QPainter &p, int right, bool hover) +void View::paint_label(QPainter &p, const QRect &rect, bool hover) { (void)p; - (void)right; + (void)rect; (void)hover; } -QRectF View::label_rect(int right) +QRectF View::label_rect(const QRectF &rect) { - (void)right; + (void)rect; return QRectF(); } diff --git a/pv/view/view.hpp b/pv/view/view.hpp index 026c7683..5fc6e4e0 100644 --- a/pv/view/view.hpp +++ b/pv/view/view.hpp @@ -200,19 +200,17 @@ private: /** * Satisifies RowItem functionality. * @param p the QPainter to paint into. - * @param right the x-coordinate of the right edge of the header - * area. + * @param rect the rectangle of the header area. * @param hover true if the label is being hovered over by the mouse. */ - void paint_label(QPainter &p, int right, bool hover); + void paint_label(QPainter &p, const QRect &rect, bool hover); /** * Computes the outline rectangle of a label. - * @param right the x-coordinate of the right edge of the header - * area. + * @param rect the rectangle of the header area. * @return Returns the rectangle of the signal label. */ - QRectF label_rect(int right); + QRectF label_rect(const QRectF &rect); static bool add_channels_to_owner( const std::vector< std::shared_ptr > &channels,