From: Joel Holdsworth Date: Sun, 18 Nov 2012 14:01:24 +0000 (+0000) Subject: Added pv::view::View::normalize_layout to normalize out-of-bounds drags X-Git-Tag: pulseview-0.1.0~211 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=4b192962559bb212408a94f48a9a8efead024aa7;p=pulseview.git Added pv::view::View::normalize_layout to normalize out-of-bounds drags --- diff --git a/pv/view/header.cpp b/pv/view/header.cpp index e167bffc..744e4aff 100644 --- a/pv/view/header.cpp +++ b/pv/view/header.cpp @@ -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) diff --git a/pv/view/view.cpp b/pv/view/view.cpp index 98b5c65d..c5465ff3 100644 --- a/pv/view/view.cpp +++ b/pv/view/view.cpp @@ -168,6 +168,22 @@ const QPoint& View::hover_point() const return _hover_point; } +void View::normalize_layout() +{ + vector< shared_ptr > &sigs = _session.get_signals(); + + int v_min = INT_MAX; + BOOST_FOREACH(const shared_ptr s, sigs) + v_min = min(s->get_v_offset(), v_min); + + const int delta = -min(v_min, 0); + BOOST_FOREACH(shared_ptr 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 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) diff --git a/pv/view/view.h b/pv/view/view.h index 1bf71322..3cd2646e 100644 --- a/pv/view/view.h +++ b/pv/view/view.h @@ -105,6 +105,8 @@ public: const QPoint& hover_point() const; + void normalize_layout(); + signals: void hover_point_changed();