]> sigrok.org Git - pulseview.git/commitdiff
Added pv::view::View::normalize_layout to normalize out-of-bounds drags
authorJoel Holdsworth <redacted>
Sun, 18 Nov 2012 14:01:24 +0000 (14:01 +0000)
committerJoel Holdsworth <redacted>
Sun, 18 Nov 2012 14:01:24 +0000 (14:01 +0000)
pv/view/header.cpp
pv/view/view.cpp
pv/view/view.h

index e167bffc5c8e38535e82d94692bf96a8193de8f2..744e4aff06b2072006c68fe4880b973f195e05d7 100644 (file)
@@ -161,8 +161,10 @@ void Header::mousePressEvent(QMouseEvent *event)
 void Header::mouseReleaseEvent(QMouseEvent *event)
 {
        assert(event);
-       if(event->button() == Qt::LeftButton)
+       if(event->button() == Qt::LeftButton) {
                _drag_sigs.clear();
+               _view.normalize_layout();
+       }
 }
 
 void Header::mouseMoveEvent(QMouseEvent *event)
index 98b5c65dd1fc37f8b3084e5363bb936b4fc1611a..c5465ff3c6ba19eef1cd68ba2082ba40d7f413c4 100644 (file)
@@ -168,6 +168,22 @@ const QPoint& View::hover_point() const
        return _hover_point;
 }
 
+void View::normalize_layout()
+{
+       vector< shared_ptr<Signal> > &sigs = _session.get_signals();
+
+       int v_min = INT_MAX;
+       BOOST_FOREACH(const shared_ptr<Signal> s, sigs)
+               v_min = min(s->get_v_offset(), v_min);
+
+       const int delta = -min(v_min, 0);
+       BOOST_FOREACH(shared_ptr<Signal> s, sigs)
+               s->set_v_offset(s->get_v_offset() + delta);
+
+       verticalScrollBar()->setSliderPosition(_v_offset + delta);
+       v_scroll_value_changed(verticalScrollBar()->sliderPosition());
+}
+
 void View::get_scroll_layout(double &length, double &offset) const
 {
        const shared_ptr<SignalData> sig_data = _session.get_data();
@@ -203,7 +219,8 @@ void View::update_scroll()
        // Set the vertical scrollbar
        verticalScrollBar()->setPageStep(areaSize.height());
        verticalScrollBar()->setRange(0,
-               _viewport->get_total_height() - areaSize.height());
+               _viewport->get_total_height() + SignalMargin -
+               areaSize.height());
 }
 
 void View::reset_signal_layout()
@@ -214,6 +231,8 @@ void View::reset_signal_layout()
                s->set_v_offset(offset);
                offset += SignalHeight + 2 * SignalMargin;
        }
+
+       normalize_layout();
 }
 
 bool View::eventFilter(QObject *object, QEvent *event)
index 1bf7132267a6d29d03dd9e95d8a7ff96d15016db..3cd2646e91e8016cbe8543cc3d86717488b5e6f6 100644 (file)
@@ -105,6 +105,8 @@ public:
 
        const QPoint& hover_point() const;
 
+       void normalize_layout();
+
 signals:
        void hover_point_changed();