From: Joel Holdsworth Date: Thu, 5 Dec 2013 23:16:09 +0000 (+0000) Subject: Added zoom one-to-one X-Git-Tag: pulseview-0.2.0~192 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=d1e7d82c6327c15f38d66602e65c4d3abe114df7;p=pulseview.git Added zoom one-to-one --- diff --git a/icons/zoom-original.png b/icons/zoom-original.png new file mode 100644 index 00000000..8ae30433 Binary files /dev/null and b/icons/zoom-original.png differ diff --git a/pulseview.qrc b/pulseview.qrc index 6830e00d..d2e1c139 100644 --- a/pulseview.qrc +++ b/pulseview.qrc @@ -17,6 +17,7 @@ icons/trigger-rising.svg icons/zoom-fit.png icons/zoom-in.png + icons/zoom-original.png icons/zoom-out.png diff --git a/pv/mainwindow.cpp b/pv/mainwindow.cpp index 5485ea75..6cb48287 100644 --- a/pv/mainwindow.cpp +++ b/pv/mainwindow.cpp @@ -170,6 +170,17 @@ void MainWindow::setup_ui() QString::fromUtf8("actionViewZoomFit")); menu_view->addAction(action_view_zoom_fit); + QAction *const action_view_zoom_one_to_one = new QAction(this); + action_view_zoom_one_to_one->setText(QApplication::translate( + "MainWindow", "Zoom to &One-to-One", 0, + QApplication::UnicodeUTF8)); + action_view_zoom_one_to_one->setIcon(QIcon::fromTheme("zoom-original", + QIcon(":/icons/zoom-original.png"))); + action_view_zoom_one_to_one->setShortcut(QKeySequence(Qt::Key_O)); + action_view_zoom_one_to_one->setObjectName( + QString::fromUtf8("actionViewZoomOneToOne")); + menu_view->addAction(action_view_zoom_one_to_one); + menu_view->addSeparator(); QAction *action_view_show_cursors = new QAction(this); @@ -345,6 +356,11 @@ void MainWindow::on_actionViewZoomFit_triggered() _view->zoom_fit(); } +void MainWindow::on_actionViewZoomOneToOne_triggered() +{ + _view->zoom_one_to_one(); +} + void MainWindow::on_actionViewShowCursors_triggered() { assert(_view); diff --git a/pv/mainwindow.h b/pv/mainwindow.h index 8895a5e7..ca447502 100644 --- a/pv/mainwindow.h +++ b/pv/mainwindow.h @@ -91,6 +91,8 @@ private slots: void on_actionViewZoomFit_triggered(); + void on_actionViewZoomOneToOne_triggered(); + void on_actionViewShowCursors_triggered(); void on_actionAbout_triggered(); diff --git a/pv/view/view.cpp b/pv/view/view.cpp index f8b0fc45..f727cc33 100644 --- a/pv/view/view.cpp +++ b/pv/view/view.cpp @@ -148,11 +148,9 @@ void View::zoom(double steps) void View::zoom(double steps, int offset) { - const double cursor_offset = _offset + _scale * offset; const double new_scale = max(min(_scale * pow(3.0/2.0, -steps), MaxScale), MinScale); - const double new_offset = cursor_offset - new_scale * offset; - set_scale_offset(new_scale, new_offset); + set_zoom(new_scale, offset); } void View::zoom_fit() @@ -192,6 +190,39 @@ void View::zoom_fit() set_scale_offset((right_time - left_time) / w, left_time); } +void View::zoom_one_to_one() +{ + using pv::data::SignalData; + + const vector< shared_ptr > sigs( + session().get_signals()); + + // Make a set of all the visible data objects + set< shared_ptr > visible_data; + BOOST_FOREACH(const shared_ptr sig, sigs) + if (sig->enabled()) + visible_data.insert(sig->data()); + + if (visible_data.empty()) + return; + + double samplerate = 0.0; + BOOST_FOREACH(const shared_ptr d, visible_data) { + assert(d); + samplerate = max(samplerate, d->samplerate()); + } + + if (samplerate == 0.0) + return; + + assert(_viewport); + const int w = _viewport->width(); + if (w <= 0) + return; + + set_zoom(1.0 / samplerate, w / 2); +} + void View::set_scale_offset(double scale, double offset) { _scale = scale; @@ -309,6 +340,14 @@ void View::get_scroll_layout(double &length, double &offset) const offset = _offset / _scale; } +void View::set_zoom(double scale, int offset) +{ + const double cursor_offset = _offset + _scale * offset; + const double new_scale = max(min(scale, MaxScale), MinScale); + const double new_offset = cursor_offset - new_scale * offset; + set_scale_offset(new_scale, new_offset); +} + void View::update_scroll() { assert(_viewport); diff --git a/pv/view/view.h b/pv/view/view.h index bc99bdd7..db03ce9b 100644 --- a/pv/view/view.h +++ b/pv/view/view.h @@ -88,6 +88,8 @@ public: void zoom_fit(); + void zoom_one_to_one(); + /** * Sets the scale and offset. * @param scale The new view scale in seconds per pixel. @@ -142,6 +144,8 @@ signals: private: void get_scroll_layout(double &length, double &offset) const; + void set_zoom(double scale, int offset); + void update_scroll(); static bool compare_trace_v_offsets(