X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=pv%2Fviews%2Ftrace%2Fruler.cpp;h=63d3d23fcb946536f173ee0e184aacd1084d0039;hp=fe08cb06ceaa56cd874b77ec35a836c89cdfd323;hb=4bd0ecb8d08b655a4e2a1d60b3166e97b290475c;hpb=ffc00fdd5946593ad2a587078fd4ee9ba0a507ec diff --git a/pv/views/trace/ruler.cpp b/pv/views/trace/ruler.cpp index fe08cb06..63d3d23f 100644 --- a/pv/views/trace/ruler.cpp +++ b/pv/views/trace/ruler.cpp @@ -29,6 +29,8 @@ using namespace Qt; using std::function; +using std::max; +using std::min; using std::shared_ptr; using std::vector; @@ -37,7 +39,6 @@ namespace views { namespace trace { const float Ruler::RulerHeight = 2.5f; // x Text Height -const int Ruler::MinorTickSubdivision = 4; const float Ruler::HoverArrowSize = 0.5f; // x Text Height @@ -143,6 +144,7 @@ void Ruler::paintEvent(QPaintEvent*) view_.ruler_offset(), view_.scale(), width(), + view_.minor_tick_count(), ffunc); } @@ -159,10 +161,18 @@ void Ruler::paintEvent(QPaintEvent*) p.setPen(palette().color(foregroundRole())); for (const auto& tick: tick_position_cache_->major) { - p.drawText(tick.first, ValueMargin, 0, text_height, + const int leftedge = 0; + const int rightedge = width(); + const int x_tick = tick.first; + if ((x_tick > leftedge) && (x_tick < rightedge)) { + const int x_left_bound = QFontMetrics(font()).width(tick.second) / 2; + const int x_right_bound = rightedge - x_left_bound; + const int x_legend = min(max(x_tick, x_left_bound), x_right_bound); + p.drawText(x_legend, ValueMargin, 0, text_height, AlignCenter | AlignTop | TextDontClip, tick.second); - p.drawLine(QPointF(tick.first, major_tick_y1), + p.drawLine(QPointF(x_tick, major_tick_y1), QPointF(tick.first, ruler_height)); + } } for (const auto& tick: tick_position_cache_->minor) { @@ -194,17 +204,18 @@ Ruler::TickPositions Ruler::calculate_tick_positions( const pv::util::Timestamp& offset, const double scale, const int width, + const unsigned int minor_tick_count, function format_function) { TickPositions tp; - const pv::util::Timestamp minor_period = major_period / MinorTickSubdivision; + const pv::util::Timestamp minor_period = major_period / minor_tick_count; const pv::util::Timestamp first_major_division = floor(offset / major_period); const pv::util::Timestamp first_minor_division = ceil(offset / minor_period); const pv::util::Timestamp t0 = first_major_division * major_period; int division = (round(first_minor_division - - first_major_division * MinorTickSubdivision)).convert_to() - 1; + first_major_division * minor_tick_count)).convert_to() - 1; double x; @@ -212,9 +223,9 @@ Ruler::TickPositions Ruler::calculate_tick_positions( pv::util::Timestamp t = t0 + division * minor_period; x = ((t - offset) / scale).convert_to(); - if (division % MinorTickSubdivision == 0) { + if (division % minor_tick_count == 0) { // Recalculate 't' without using 'minor_period' which is a fraction - t = t0 + division / MinorTickSubdivision * major_period; + t = t0 + division / minor_tick_count * major_period; tp.major.emplace_back(x, format_function(t)); } else { tp.minor.emplace_back(x);