+void Ruler::mouseMoveEvent(QMouseEvent *e)
+{
+ if (!_grabbed_marker)
+ return;
+
+ _grabbed_marker->set_time(_view.offset() +
+ ((double)e->x() + 0.5) * _view.scale());
+}
+
+void Ruler::mousePressEvent(QMouseEvent *e)
+{
+ if (e->buttons() & Qt::LeftButton) {
+ _grabbed_marker = NULL;
+
+ if (_view.cursors_shown()) {
+ std::pair<Cursor, Cursor> &cursors =
+ _view.cursors();
+ if (cursors.first.get_label_rect(
+ rect()).contains(e->pos()))
+ _grabbed_marker = &cursors.first;
+ else if (cursors.second.get_label_rect(
+ rect()).contains(e->pos()))
+ _grabbed_marker = &cursors.second;
+ }
+ }
+}
+
+void Ruler::mouseReleaseEvent(QMouseEvent *)
+{
+ _grabbed_marker = NULL;
+}
+
+void Ruler::draw_cursors(QPainter &p, unsigned int prefix)
+{
+ if (!_view.cursors_shown())
+ return;
+
+ const QRect r = rect();
+ pair<Cursor, Cursor> &cursors = _view.cursors();
+ cursors.first.paint_label(p, r, prefix);
+ cursors.second.paint_label(p, r, prefix);
+}
+
+void Ruler::draw_hover_mark(QPainter &p)
+{
+ const int x = _view.hover_point().x();
+
+ if (x == -1 || _grabbed_marker)
+ return;
+
+ p.setPen(QPen(Qt::NoPen));
+ p.setBrush(QBrush(palette().color(foregroundRole())));
+
+ const int b = height() - 1;
+ const QPointF points[] = {
+ QPointF(x, b),
+ QPointF(x - HoverArrowSize, b - HoverArrowSize),
+ QPointF(x + HoverArrowSize, b - HoverArrowSize)
+ };
+ p.drawPolygon(points, countof(points));
+}
+
+void Ruler::hover_point_changed()
+{
+ update();
+}
+