+ const int text_height = calculate_text_height();
+ return QSize(0, RulerHeight * text_height);
+}
+
+QSize Ruler::extended_size_hint() const
+{
+ QRectF max_rect;
+ std::vector< std::shared_ptr<TimeItem> > items(view_.time_items());
+ for (auto &i : items)
+ max_rect = max_rect.united(i->label_rect(QRect()));
+ return QSize(0, sizeHint().height() - max_rect.top() / 2 +
+ ViewItem::HighlightRadius);
+}
+
+QString Ruler::format_time_with_distance(
+ const pv::util::Timestamp& distance,
+ const pv::util::Timestamp& t,
+ pv::util::SIPrefix prefix,
+ pv::util::TimeUnit unit,
+ unsigned precision,
+ bool sign)
+{
+ const unsigned limit = 60;
+
+ if (t.is_zero())
+ return "0";
+
+ // If we have to use samples then we have no alternative formats
+ if (unit == pv::util::TimeUnit::Samples)
+ return pv::util::format_time_si_adjusted(t, prefix, precision, "sa", sign);
+
+ // View zoomed way out -> low precision (0), big distance (>=60s)
+ // -> DD:HH:MM
+ if ((precision == 0) && (distance >= limit))
+ return pv::util::format_time_minutes(t, 0, sign);
+
+ // View in "normal" range -> medium precision, medium step size
+ // -> HH:MM:SS.mmm... or xxxx (si unit) if less than limit seconds
+ // View zoomed way in -> high precision (>3), low step size (<1s)
+ // -> HH:MM:SS.mmm... or xxxx (si unit) if less than limit seconds
+ if (abs(t) < limit)
+ return pv::util::format_time_si_adjusted(t, prefix, precision, "s", sign);
+ else
+ return pv::util::format_time_minutes(t, precision, sign);
+}
+
+vector< shared_ptr<ViewItem> > Ruler::items()
+{
+ const vector< shared_ptr<TimeItem> > time_items(view_.time_items());
+ return vector< shared_ptr<ViewItem> >(
+ time_items.begin(), time_items.end());
+}
+
+shared_ptr<ViewItem> Ruler::get_mouse_over_item(const QPoint &pt)
+{
+ const vector< shared_ptr<TimeItem> > items(view_.time_items());
+ for (auto i = items.rbegin(); i != items.rend(); i++)
+ if ((*i)->enabled() && (*i)->label_rect(rect()).contains(pt))
+ return *i;
+ return nullptr;