From: Joel Holdsworth Date: Tue, 23 Apr 2013 22:22:24 +0000 (+0100) Subject: Bring the cursors into view when they are shown X-Git-Tag: pulseview-0.1.0~22 X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=commitdiff_plain;h=b4d91e564cfb71d76e4aa8a4328b8a3b739ce383 Bring the cursors into view when they are shown --- diff --git a/pv/mainwindow.cpp b/pv/mainwindow.cpp index 66bed748..3326b9b1 100644 --- a/pv/mainwindow.cpp +++ b/pv/mainwindow.cpp @@ -287,7 +287,12 @@ void MainWindow::on_actionViewZoomOut_triggered() void MainWindow::on_actionViewShowCursors_triggered() { assert(_view); - _view->show_cursors(_action_view_show_cursors->isChecked()); + + const bool show = !_view->cursors_shown(); + if(show) + _view->centre_cursors(); + + _view->show_cursors(show); } void MainWindow::on_actionAbout_triggered() diff --git a/pv/view/view.cpp b/pv/view/view.cpp index 9c793bb8..6ea8cc0a 100644 --- a/pv/view/view.cpp +++ b/pv/view/view.cpp @@ -161,6 +161,15 @@ void View::show_cursors(bool show) _viewport->update(); } +void View::centre_cursors() +{ + const double time_width = _scale * _viewport->width(); + _cursors.first().set_time(_offset + time_width * 0.4); + _cursors.second().set_time(_offset + time_width * 0.6); + _ruler->update(); + _viewport->update(); +} + CursorPair& View::cursors() { return _cursors; diff --git a/pv/view/view.h b/pv/view/view.h index 4eb255a2..0f5e254d 100644 --- a/pv/view/view.h +++ b/pv/view/view.h @@ -96,6 +96,11 @@ public: */ void show_cursors(bool show = true); + /** + * Moves the cursors to a convenient position in the view. + */ + void centre_cursors(); + /** * Returns a reference to the pair of cursors. */