]> sigrok.org Git - pulseview.git/commitdiff
Implement "always zoom to fit" feature
authorSoeren Apel <redacted>
Fri, 24 Jul 2015 05:55:29 +0000 (07:55 +0200)
committerSoeren Apel <redacted>
Fri, 24 Jul 2015 05:55:29 +0000 (07:55 +0200)
pv/mainwindow.cpp
pv/mainwindow.hpp
pv/view/view.cpp
pv/view/view.hpp

index 6d28194bb87cbed491e00a3aa2bc21436e8976b3..6b7fe4f530e94191f50da7f251d75b5f81205de9 100644 (file)
@@ -401,6 +401,7 @@ void MainWindow::setup_ui()
                QString::fromUtf8("actionViewZoomOut"));
        menu_view->addAction(action_view_zoom_out_);
 
+       action_view_zoom_fit_->setCheckable(true);
        action_view_zoom_fit_->setText(tr("Zoom to &Fit"));
        action_view_zoom_fit_->setIcon(QIcon::fromTheme("zoom-fit",
                QIcon(":/icons/zoom-fit.png")));
@@ -495,7 +496,8 @@ void MainWindow::setup_ui()
        // Setup view_ events
        connect(view_, SIGNAL(sticky_scrolling_changed(bool)), this,
                SLOT(sticky_scrolling_changed(bool)));
-
+       connect(view_, SIGNAL(always_zoom_to_fit_changed(bool)), this,
+               SLOT(always_zoom_to_fit_changed(bool)));
 }
 
 void MainWindow::select_init_device() {
@@ -730,7 +732,7 @@ void MainWindow::on_actionViewZoomOut_triggered()
 
 void MainWindow::on_actionViewZoomFit_triggered()
 {
-       view_->zoom_fit();
+       view_->zoom_fit(action_view_zoom_fit_->isChecked());
 }
 
 void MainWindow::on_actionViewZoomOneToOne_triggered()
@@ -765,6 +767,11 @@ void MainWindow::sticky_scrolling_changed(bool state)
        action_view_sticky_scrolling_->setChecked(state);
 }
 
+void MainWindow::always_zoom_to_fit_changed(bool state)
+{
+       action_view_zoom_fit_->setChecked(state);
+}
+
 void MainWindow::add_decoder(srd_decoder *decoder)
 {
 #ifdef ENABLE_DECODE
index ad7e6b2bdb6f48a0d2723335eb9cc598a682675e..e86dd183bbee32192a6511b58bf29441c585be9c 100644 (file)
@@ -166,6 +166,8 @@ private Q_SLOTS:
 
        void sticky_scrolling_changed(bool state);
 
+       void always_zoom_to_fit_changed(bool state);
+
 private:
        DeviceManager &device_manager_;
 
index 130d2d788cfaf862cbb2c83b03fbac8e48f7e4a0..d4aa161959ab2bc7829d05dad08b0c0c293b4e75 100644 (file)
@@ -86,7 +86,7 @@ const double View::MaxScale = 1e9;
 const double View::MinScale = 1e-15;
 
 const int View::MaxScrollValue = INT_MAX / 2;
-const int View::MaxViewAutoUpdateRate = 25; // No more than 25 Hz
+const int View::MaxViewAutoUpdateRate = 25; // No more than 25 Hz with sticky scrolling
 
 const int View::ScaleUnits[3] = {1, 2, 5};
 
@@ -100,6 +100,7 @@ View::View(Session &session, QWidget *parent) :
        offset_(0),
        updating_scroll_(false),
        sticky_scrolling_(false), // Default setting is set in MainWindow::setup_ui()
+       always_zoom_to_fit_(false),
        tick_period_(0.0),
        tick_prefix_(0),
        show_cursors_(false),
@@ -248,8 +249,17 @@ void View::zoom(double steps, int offset)
        set_zoom(scale_ * pow(3.0/2.0, -steps), offset);
 }
 
-void View::zoom_fit()
+void View::zoom_fit(bool gui_state)
 {
+       // Act as one-shot when stopped, toggle along with the GUI otherwise
+       if (session_.get_capture_state() == Session::Stopped) {
+               always_zoom_to_fit_ = false;
+               always_zoom_to_fit_changed(false);
+       } else {
+               always_zoom_to_fit_ = gui_state;
+               always_zoom_to_fit_changed(gui_state);
+       }
+
        const pair<double, double> extents = get_time_extents();
        const double delta = extents.second - extents.first;
        if (delta < 1e-12)
@@ -295,11 +305,20 @@ void View::zoom_one_to_one()
 
 void View::set_scale_offset(double scale, double offset)
 {
-       // Disable sticky scrolling when acquisition runs and user drags the viewport
+       // Disable sticky scrolling / always zoom to fit when acquisition runs
+       // and user drags the viewport
        if ((scale_ == scale) && (offset_ != offset) &&
-                       sticky_scrolling_ && (session_.get_capture_state() == Session::Running)) {
-               sticky_scrolling_ = false;
-               sticky_scrolling_changed(false);
+                       (session_.get_capture_state() == Session::Running)) {
+
+               if (sticky_scrolling_) {
+                       sticky_scrolling_ = false;
+                       sticky_scrolling_changed(false);
+               }
+
+               if (always_zoom_to_fit_) {
+                       always_zoom_to_fit_ = false;
+                       always_zoom_to_fit_changed(false);
+               }
        }
 
        scale_ = scale;
@@ -449,6 +468,10 @@ void View::get_scroll_layout(double &length, double &offset) const
 
 void View::set_zoom(double scale, int offset)
 {
+       // Reset the "always zoom to fit" feature as the user changed the zoom
+       always_zoom_to_fit_ = false;
+       always_zoom_to_fit_changed(false);
+
        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;
@@ -847,7 +870,13 @@ void View::signals_changed()
 
 void View::data_updated()
 {
-       if (sticky_scrolling_) {
+       // Reset "always zoom to fit" when we change to the stopped state
+       if (always_zoom_to_fit_ && (session_.get_capture_state() == Session::Stopped)) {
+               always_zoom_to_fit_ = false;
+               always_zoom_to_fit_changed(false);
+       }
+
+       if (always_zoom_to_fit_ || sticky_scrolling_) {
                if (!delayed_view_updater_.isActive())
                        delayed_view_updater_.start();
        } else {
@@ -859,6 +888,9 @@ void View::data_updated()
 
 void View::perform_delayed_view_update()
 {
+       if (always_zoom_to_fit_)
+               zoom_fit(true);
+
        if (sticky_scrolling_) {
                // Make right side of the view sticky
                double length = 0, offset;
index b29fb157dce383eec55535fcd187ecf104eaa9b7..2c81e74782cbbac3d3948aec2c9ca963d90632ae 100644 (file)
@@ -137,7 +137,7 @@ public:
        void zoom(double steps);
        void zoom(double steps, int offset);
 
-       void zoom_fit();
+       void zoom_fit(bool gui_state);
 
        void zoom_one_to_one();
 
@@ -209,6 +209,8 @@ Q_SIGNALS:
 
        void sticky_scrolling_changed(bool state);
 
+       void always_zoom_to_fit_changed(bool state);
+
 private:
        void get_scroll_layout(double &length, double &offset) const;
 
@@ -299,6 +301,7 @@ private:
 
        bool updating_scroll_;
        bool sticky_scrolling_;
+       bool always_zoom_to_fit_;
        QTimer delayed_view_updater_;
 
        double tick_period_;