]> sigrok.org Git - pulseview.git/commitdiff
Added zoom one-to-one
authorJoel Holdsworth <redacted>
Thu, 5 Dec 2013 23:16:09 +0000 (23:16 +0000)
committerBert Vermeulen <redacted>
Mon, 9 Dec 2013 16:09:57 +0000 (17:09 +0100)
icons/zoom-original.png [new file with mode: 0644]
pulseview.qrc
pv/mainwindow.cpp
pv/mainwindow.h
pv/view/view.cpp
pv/view/view.h

diff --git a/icons/zoom-original.png b/icons/zoom-original.png
new file mode 100644 (file)
index 0000000..8ae3043
Binary files /dev/null and b/icons/zoom-original.png differ
index 6830e00d66e3780df898d0464e9140f2edf5d269..d2e1c139c9afba70bed3f1f89c9631713a56f4b6 100644 (file)
@@ -17,6 +17,7 @@
        <file>icons/trigger-rising.svg</file>
        <file>icons/zoom-fit.png</file>
        <file>icons/zoom-in.png</file>
+       <file>icons/zoom-original.png</file>
        <file>icons/zoom-out.png</file>
     </qresource>
 </RCC>
index 5485ea75b6e0fe49c329fb7bde00da944bf80d8b..6cb482873baee69b1e9fde71634aeba27649da61 100644 (file)
@@ -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);
index 8895a5e7341242099557ba96782fc2cdd6532fc4..ca4475024d97f9b33e5e4fdc985c4ea3e797f004 100644 (file)
@@ -91,6 +91,8 @@ private slots:
 
        void on_actionViewZoomFit_triggered();
 
+       void on_actionViewZoomOneToOne_triggered();
+
        void on_actionViewShowCursors_triggered();
 
        void on_actionAbout_triggered();
index f8b0fc4537ef71b83d0be751fbd6ddee564bd198..f727cc33b540b4fddc18b77f154a08051d3a78d4 100644 (file)
@@ -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<Signal> > sigs(
+               session().get_signals());
+
+       // Make a set of all the visible data objects
+       set< shared_ptr<SignalData> > visible_data;
+       BOOST_FOREACH(const shared_ptr<Signal> sig, sigs)
+               if (sig->enabled())
+                       visible_data.insert(sig->data());
+
+       if (visible_data.empty())
+               return;
+
+       double samplerate = 0.0;
+       BOOST_FOREACH(const shared_ptr<SignalData> 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);
index bc99bdd775ef88c26fc235fef299d5a5eebe6a7a..db03ce9b43a81b1a7b6a5eda32e0986e15cb1c86 100644 (file)
@@ -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(