]> sigrok.org Git - pulseview.git/blobdiff - pv/view/ruler.cpp
Added clear_selection to Ruler and Header
[pulseview.git] / pv / view / ruler.cpp
index adab57dbed21344dab3cf39a072492a40950e82f..049cc4af196a8c2203d0ef3ee285e9fa33f17a84 100644 (file)
@@ -49,8 +49,7 @@ const int Ruler::FirstSIPrefixPower = -15;
 const int Ruler::HoverArrowSize = 5;
 
 Ruler::Ruler(View &parent) :
-       QWidget(&parent),
-       _view(parent),
+       MarginWidget(parent),
        _grabbed_marker(NULL)
 {
        setMouseTracking(true);
@@ -59,6 +58,14 @@ Ruler::Ruler(View &parent) :
                this, SLOT(hover_point_changed()));
 }
 
+void Ruler::clear_selection()
+{
+       CursorPair &cursors = _view.cursors();
+       cursors.first().select(false);
+       cursors.second().select(false);
+       update();
+}
+
 QString Ruler::format_time(double t, unsigned int prefix,
        unsigned int precision)
 {
@@ -130,19 +137,17 @@ void Ruler::paintEvent(QPaintEvent*)
        const double t0 = first_major_division * tick_period;
 
        int division = (int)round(first_minor_division -
-               first_major_division * MinorTickSubdivision);
+               first_major_division * MinorTickSubdivision) - 1;
 
        const int major_tick_y1 = text_height + ValueMargin * 2;
        const int tick_y2 = height();
        const int minor_tick_y1 = (major_tick_y1 + tick_y2) / 2;
 
-       while (1)
-       {
-               const double t = t0 + division * minor_tick_period;
-               const double x = (t - _view.offset()) / _view.scale();
+       double x;
 
-               if (x >= width())
-                       break;
+       do {
+               const double t = t0 + division * minor_tick_period;
+               x = (t - _view.offset()) / _view.scale();
 
                if (division % MinorTickSubdivision == 0)
                {
@@ -161,10 +166,12 @@ void Ruler::paintEvent(QPaintEvent*)
                }
 
                division++;
-       }
+
+       } while (x < width());
 
        // Draw the cursors
-       draw_cursors(p, prefix);
+       if (_view.cursors_shown())
+               _view.cursors().draw_markers(p, rect(), prefix);
 
        // Draw the hover mark
        draw_hover_mark(p);
@@ -187,14 +194,13 @@ void Ruler::mousePressEvent(QMouseEvent *e)
                _grabbed_marker = NULL;
 
                if (_view.cursors_shown()) {
-                       std::pair<Cursor, Cursor> &cursors =
-                               _view.cursors();
-                       if (cursors.first.get_label_rect(
+                       CursorPair &cursors = _view.cursors();
+                       if (cursors.first().get_label_rect(
                                rect()).contains(e->pos()))
-                               _grabbed_marker = &cursors.first;
-                       else if (cursors.second.get_label_rect(
+                               _grabbed_marker = &cursors.first();
+                       else if (cursors.second().get_label_rect(
                                rect()).contains(e->pos()))
-                               _grabbed_marker = &cursors.second;
+                               _grabbed_marker = &cursors.second();
                }
        }
 }
@@ -204,17 +210,6 @@ 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();
@@ -223,7 +218,7 @@ void Ruler::draw_hover_mark(QPainter &p)
                return;
 
        p.setPen(QPen(Qt::NoPen));
-       p.setBrush(QBrush(QColor(Qt::black)));
+       p.setBrush(QBrush(palette().color(foregroundRole())));
 
        const int b = height() - 1;
        const QPointF points[] = {