+ 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();
+ }
+}
+
+void Ruler::draw_hover_mark(QPainter &p, int text_height)
+{
+ const int x = view_.hover_point().x();