Change the number of minor ticks to be either 4 or 5
[pulseview.git] / pv / views / trace / ruler.cpp
index 5455b2099ba77abf7315a4e9fa11a98c5494d499..0c2b6592cf3eb90f05f18a6ca95aadb2418acfb4 100644 (file)
@@ -37,7 +37,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
 
@@ -46,8 +45,8 @@ Ruler::Ruler(View &parent) :
 {
        setMouseTracking(true);
 
-       connect(&view_, SIGNAL(hover_point_changed()),
-               this, SLOT(hover_point_changed()));
+       connect(&view_, SIGNAL(hover_point_changed(QPoint)),
+               this, SLOT(hover_point_changed(QPoint)));
        connect(&view_, SIGNAL(offset_changed()),
                this, SLOT(invalidate_tick_position_cache()));
        connect(&view_, SIGNAL(scale_changed()),
@@ -140,9 +139,10 @@ void Ruler::paintEvent(QPaintEvent*)
 
                tick_position_cache_ = calculate_tick_positions(
                        view_.tick_period(),
-                       view_.offset(),
+                       view_.ruler_offset(),
                        view_.scale(),
                        width(),
+                       view_.minor_tick_count(),
                        ffunc);
        }
 
@@ -194,17 +194,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<QString(const pv::util::Timestamp&)> 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<int>() - 1;
+               first_major_division * minor_tick_count)).convert_to<int>() - 1;
 
        double x;
 
@@ -212,9 +213,9 @@ Ruler::TickPositions Ruler::calculate_tick_positions(
                pv::util::Timestamp t = t0 + division * minor_period;
                x = ((t - offset) / scale).convert_to<double>();
 
-               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);
@@ -228,7 +229,7 @@ Ruler::TickPositions Ruler::calculate_tick_positions(
 
 void Ruler::mouseDoubleClickEvent(QMouseEvent *event)
 {
-       view_.add_flag(view_.offset() + ((double)event->x() + 0.5) * view_.scale());
+       view_.add_flag(view_.ruler_offset() + ((double)event->x() + 0.5) * view_.scale());
 }
 
 void Ruler::draw_hover_mark(QPainter &p, int text_height)
@@ -256,8 +257,10 @@ int Ruler::calculate_text_height() const
        return QFontMetrics(font()).ascent();
 }
 
-void Ruler::hover_point_changed()
+void Ruler::hover_point_changed(const QPoint &hp)
 {
+       (void)hp;
+
        update();
 }