]> sigrok.org Git - pulseview.git/commitdiff
Add shortcuts to + and - buttons for zooming in and out horizontally
authorMiklos Marton <redacted>
Mon, 20 May 2019 09:27:37 +0000 (11:27 +0200)
committerUwe Hermann <redacted>
Fri, 5 Jul 2019 21:10:58 +0000 (23:10 +0200)
pv/mainwindow.cpp
pv/mainwindow.hpp

index fb749f5701724e37be0fffae8d55c3edd3d22a7e..d04759cfe380d0920c2408ba10aaeaea065b0eb5 100644 (file)
@@ -511,6 +511,12 @@ void MainWindow::setup_ui()
        view_colored_bg_shortcut_ = new QShortcut(QKeySequence(Qt::Key_B), this, SLOT(on_view_colored_bg_shortcut()));
        view_colored_bg_shortcut_->setAutoRepeat(false);
 
+       zoom_in_shortcut_ = new QShortcut(QKeySequence(Qt::Key_Plus), this, SLOT(on_zoom_in_shortcut_triggered()));
+       zoom_in_shortcut_->setAutoRepeat(false);
+
+       zoom_out_shortcut_ = new QShortcut(QKeySequence(Qt::Key_Minus), this, SLOT(on_zoom_out_shortcut_triggered()));
+       zoom_out_shortcut_->setAutoRepeat(false);
+
        // Set up the tab area
        new_session_button_ = new QToolButton();
        new_session_button_->setIcon(QIcon::fromTheme("document-new",
@@ -601,6 +607,19 @@ void MainWindow::restore_ui_settings()
        settings.endGroup();
 }
 
+void MainWindow::zoom_current_view(double steps)
+{
+       shared_ptr<Session> session = get_tab_session(session_selector_.currentIndex());
+
+       if (!session)
+               return;
+
+       shared_ptr<views::ViewBase> v = session.get()->main_view();
+       views::trace::View *tv =
+               qobject_cast<views::trace::View*>(v.get());
+       tv->zoom(steps);
+}
+
 shared_ptr<Session> MainWindow::get_tab_session(int index) const
 {
        // Find the session that belongs to the tab's main window
@@ -949,6 +968,16 @@ void MainWindow::on_settingViewShowAnalogMinorGrid_changed(const QVariant new_va
        }
 }
 
+void MainWindow::on_zoom_out_shortcut_triggered()
+{
+       zoom_current_view(-1);
+}
+
+void MainWindow::on_zoom_in_shortcut_triggered()
+{
+       zoom_current_view(1);
+}
+
 void MainWindow::on_close_current_tab()
 {
        int tab = session_selector_.currentIndex();
index 92fba45f622a93d96337d0937fd0248a62a0435f..6f2fded904d426a57257780c8be62b461c680c17 100644 (file)
@@ -108,6 +108,8 @@ private:
        void save_ui_settings();
        void restore_ui_settings();
 
+       void zoom_current_view(double steps);
+
        shared_ptr<Session> get_tab_session(int index) const;
 
        void closeEvent(QCloseEvent *event);
@@ -148,6 +150,9 @@ private Q_SLOTS:
        void on_settingViewShowSamplingPoints_changed(const QVariant new_value);
        void on_settingViewShowAnalogMinorGrid_changed(const QVariant new_value);
 
+       void on_zoom_out_shortcut_triggered();
+       void on_zoom_in_shortcut_triggered();
+
        void on_close_current_tab();
 
 private:
@@ -177,6 +182,8 @@ private:
        QShortcut *run_stop_shortcut_;
        QShortcut *close_application_shortcut_;
        QShortcut *close_current_tab_shortcut_;
+       QShortcut *zoom_in_shortcut_;
+       QShortcut *zoom_out_shortcut_;
 };
 
 } // namespace pv