From b4d91e564cfb71d76e4aa8a4328b8a3b739ce383 Mon Sep 17 00:00:00 2001 From: Joel Holdsworth Date: Tue, 23 Apr 2013 23:22:24 +0100 Subject: [PATCH] Bring the cursors into view when they are shown --- pv/mainwindow.cpp | 7 ++++++- pv/view/view.cpp | 9 +++++++++ pv/view/view.h | 5 +++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/pv/mainwindow.cpp b/pv/mainwindow.cpp index 66bed74..3326b9b 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 9c793bb..6ea8cc0 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 4eb255a..0f5e254 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. */ -- 2.30.2