From: Joel Holdsworth Date: Tue, 26 Aug 2014 08:17:21 +0000 (+0100) Subject: TraceGroup: Implemented label_rect X-Git-Tag: pulseview-0.3.0~465 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=b781f8065271c6ce4b82f06f20dd37464f213d47;p=pulseview.git TraceGroup: Implemented label_rect --- diff --git a/pv/view/header.cpp b/pv/view/header.cpp index 50eefc43..f3849fbe 100644 --- a/pv/view/header.cpp +++ b/pv/view/header.cpp @@ -64,13 +64,11 @@ Header::Header(View &parent) : QSize Header::sizeHint() const { - int max_width = 0; - + QRectF max_rect(-Padding, 0, Padding, 0); for (auto &i : _view) if (i->enabled()) - max_width = max(max_width, (int)i->label_rect(0).width()); - - return QSize(max_width + Padding + BaselineOffset, 0); + max_rect = max_rect.united(i->label_rect(0)); + return QSize(max_rect.width() + Padding + BaselineOffset, 0); } shared_ptr Header::get_mouse_over_row_item(const QPoint &pt) diff --git a/pv/view/tracegroup.cpp b/pv/view/tracegroup.cpp index f99b1966..9d0465fc 100644 --- a/pv/view/tracegroup.cpp +++ b/pv/view/tracegroup.cpp @@ -29,6 +29,9 @@ using std::shared_ptr; namespace pv { namespace view { +const int TraceGroup::Padding = 8; +const int TraceGroup::Width = 12; + TraceGroup::~TraceGroup() { _owner = nullptr; @@ -74,8 +77,13 @@ void TraceGroup::paint_label(QPainter &p, int right, bool hover) QRectF TraceGroup::label_rect(int right) const { - (void)right; - return QRectF(); + QRectF rect; + for (const shared_ptr r : child_items()) + if (r) + rect = rect.united(r->label_rect(right)); + + return QRectF(rect.x() - Width - Padding, rect.y(), + Width, rect.height()); } bool TraceGroup::pt_in_label_rect(int left, int right, const QPoint &point) diff --git a/pv/view/tracegroup.h b/pv/view/tracegroup.h index 0d246cee..21298dcb 100644 --- a/pv/view/tracegroup.h +++ b/pv/view/tracegroup.h @@ -31,6 +31,10 @@ class TraceGroup : public RowItem, public RowItemOwner { Q_OBJECT +private: + static const int Padding; + static const int Width; + public: /** * Virtual destructor