+ int max_width = 0;
+
+ const vector< shared_ptr<RowItem> > row_items(_view.child_items());
+ for (shared_ptr<RowItem> r : row_items) {
+ assert(r);
+
+ if (r->enabled()) {
+ max_width = max(max_width, (int)r->label_rect(0).width());
+ }
+ }
+
+ return QSize(max_width + Padding + BaselineOffset, 0);
+}
+
+shared_ptr<RowItem> Header::get_mouse_over_row_item(const QPoint &pt)
+{
+ const int w = width() - BaselineOffset;
+ const vector< shared_ptr<RowItem> > row_items(_view.child_items());
+
+ for (const shared_ptr<RowItem> r : row_items)
+ {
+ assert(r);
+ if (r->enabled() && r->label_rect(w).contains(pt))
+ return r;
+ }
+
+ return shared_ptr<RowItem>();
+}
+
+void Header::clear_selection()
+{
+ const vector< shared_ptr<RowItem> > row_items(_view.child_items());
+ for (const shared_ptr<RowItem> r : row_items) {
+ assert(r);
+ r->select(false);
+ }
+
+ update();
+}
+
+void Header::show_popup(const shared_ptr<RowItem> &item)
+{
+ using pv::widgets::Popup;
+
+ Popup *const p = item->create_popup(&_view);
+ if (!p)
+ return;
+
+ const QPoint pt(width() - BaselineOffset, item->get_y());
+ p->set_position(mapToGlobal(pt), Popup::Right);
+ p->show();
+}
+
+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;
+
+ vector< shared_ptr<RowItem> > row_items(_view.child_items());
+ stable_sort(row_items.begin(), row_items.end(),
+ [](const shared_ptr<RowItem> &a, const shared_ptr<RowItem> &b) {
+ return a->v_offset() < b->v_offset(); });