From 1e124d4b75b7b6b6a87b93a4e175d669909c2e04 Mon Sep 17 00:00:00 2001 From: Soeren Apel Date: Sat, 15 Aug 2015 23:05:18 +0200 Subject: [PATCH] View: Use max time to calculate label length, not offset_ Using offset_ gives false results, in particular when offset_ happens to be 0. With this fix, realistic values are used for the label length calculation. --- pv/view/view.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pv/view/view.cpp b/pv/view/view.cpp index 032546db..e6be30e0 100644 --- a/pv/view/view.cpp +++ b/pv/view/view.cpp @@ -496,6 +496,11 @@ void View::calculate_tick_spacing() const double SpacingIncrement = 32.0f; const double MinValueSpacing = 32.0f; + // Figure out the highest numeric value visible on a label + const QSize areaSize = viewport_->size(); + const double max_time = max(fabs(offset_), + fabs(offset_ + scale_ * areaSize.width())); + double min_width = SpacingIncrement; double label_width, tick_period_width; @@ -523,7 +528,7 @@ void View::calculate_tick_spacing() tick_period_width = tick_period_ / scale_; const QString label_text = - format_time(offset_, tick_prefix_, time_unit_, tick_precision_); + format_time(max_time, tick_prefix_, time_unit_, tick_precision_); label_width = m.boundingRect(0, 0, INT_MAX, INT_MAX, Qt::AlignLeft | Qt::AlignTop, label_text).width() + -- 2.30.2