+
+ } while (x < width());
+
+ // Draw the hover mark
+ draw_hover_mark(p, text_height);
+
+ // The cursor labels are not drawn with the arrows exactly on the
+ // bottom line of the widget, because then the selection shadow
+ // would be clipped away.
+ const QRect r = rect().adjusted(0, 0, 0, -ViewItem::HighlightRadius);
+
+ // Draw the items
+ const vector< shared_ptr<TimeItem> > items(view_.time_items());
+ for (auto &i : items) {
+ const bool highlight = !dragging_ &&
+ i->label_rect(r).contains(mouse_point_);
+ i->paint_label(p, r, highlight);
+ }
+}
+
+void Ruler::mouseMoveEvent(QMouseEvent *e)
+{
+ mouse_point_ = e->pos();
+
+ if (!(e->buttons() & Qt::LeftButton))
+ return;
+
+ if ((e->pos() - mouse_down_point_).manhattanLength() <
+ QApplication::startDragDistance())
+ return;
+
+ // Do the drag
+ dragging_ = true;
+
+ const QPoint delta = e->pos() - mouse_down_point_;
+ const vector< shared_ptr<TimeItem> > items(view_.time_items());
+ for (auto &i : items)
+ if (i->dragging())
+ i->drag_by(delta);
+}
+
+void Ruler::mousePressEvent(QMouseEvent *e)
+{
+ if (e->buttons() & Qt::LeftButton) {
+ mouse_down_point_ = e->pos();
+ mouse_down_item_ = get_mouse_over_item(e->pos());
+
+ clear_selection();
+
+ if (mouse_down_item_) {
+ mouse_down_item_->select();
+ mouse_down_item_->drag();
+ }
+
+ selection_changed();
+ }
+}
+
+void Ruler::mouseReleaseEvent(QMouseEvent *)
+{
+ using pv::widgets::Popup;
+
+ if (!dragging_ && mouse_down_item_)
+ show_popup(mouse_down_item_);
+
+ dragging_ = false;
+ mouse_down_item_.reset();
+
+ const vector< shared_ptr<TimeItem> > items(view_.time_items());
+ for (auto &i : items)
+ i->drag_release();
+}
+
+void Ruler::mouseDoubleClickEvent(QMouseEvent *e)
+{
+ view_.add_flag(view_.offset() + ((double)e->x() + 0.5) * view_.scale());
+}
+
+void Ruler::keyPressEvent(QKeyEvent *e)
+{
+ assert(e);
+
+ if (e->key() == Qt::Key_Delete)
+ {
+ const vector< shared_ptr<TimeItem> > items(view_.time_items());
+ for (auto &i : items)
+ if (i->selected())
+ i->delete_pressed();