+ const int w = width() - BaselineOffset;
+ for (auto &i : _view)
+ if (i->enabled() && i->label_rect(w).contains(pt))
+ return i;
+ return shared_ptr<RowItem>();
+}
+
+void Header::clear_selection()
+{
+ for (auto &i : _view)
+ i->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_visual_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.begin(), _view.end());
+
+ stable_sort(row_items.begin(), row_items.end(),
+ [](const shared_ptr<RowItem> &a, const shared_ptr<RowItem> &b) {
+ return a->visual_v_offset() < b->visual_v_offset(); });