]> sigrok.org Git - pulseview.git/commitdiff
Fix #1440 by moving shortcuts from the main window to the view
authorSoeren Apel <redacted>
Sun, 24 Nov 2019 19:03:15 +0000 (20:03 +0100)
committerSoeren Apel <redacted>
Sun, 24 Nov 2019 19:44:17 +0000 (20:44 +0100)
pv/mainwindow.cpp
pv/mainwindow.hpp
pv/views/trace/view.cpp
pv/views/trace/view.hpp

index 0b68b1d7a9a9b2530bd58872b119f3ad5ae65fe2..f0a4c0714f12075a9d5ff2e6ca317d8392859595 100644 (file)
@@ -499,6 +499,7 @@ void MainWindow::setup_ui()
        icon.addFile(QString(":/icons/pulseview.png"));
        setWindowIcon(icon);
 
+       // Set up keyboard shortcuts that affect all views at once
        view_sticky_scrolling_shortcut_ = new QShortcut(QKeySequence(Qt::Key_S), this, SLOT(on_view_sticky_scrolling_shortcut()));
        view_sticky_scrolling_shortcut_->setAutoRepeat(false);
 
@@ -511,22 +512,6 @@ 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_in_shortcut_2_ = new QShortcut(QKeySequence(Qt::Key_Up), this, SLOT(on_zoom_in_shortcut_triggered()));
-
-       zoom_out_shortcut_ = new QShortcut(QKeySequence(Qt::Key_Minus), this, SLOT(on_zoom_out_shortcut_triggered()));
-       zoom_out_shortcut_->setAutoRepeat(false);
-
-       zoom_out_shortcut_2_ = new QShortcut(QKeySequence(Qt::Key_Down), this, SLOT(on_zoom_out_shortcut_triggered()));
-
-       home_shortcut_ = new QShortcut(QKeySequence(Qt::Key_Home), this, SLOT(on_scroll_to_start_triggered()));
-       home_shortcut_->setAutoRepeat(false);
-
-       end_shortcut_ = new QShortcut(QKeySequence(Qt::Key_End), this, SLOT(on_scroll_to_end_triggered()));
-       end_shortcut_->setAutoRepeat(false);
-
        // Set up the tab area
        new_session_button_ = new QToolButton();
        new_session_button_->setIcon(QIcon::fromTheme("document-new",
@@ -981,39 +966,6 @@ 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_scroll_to_start_triggered()
-{
-       scroll_to_start_or_end(true);
-}
-
-void MainWindow::on_scroll_to_end_triggered()
-{
-       scroll_to_start_or_end(false);
-}
-
-void MainWindow::scroll_to_start_or_end(bool start)
-{
-       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->set_h_offset(start ? 0 : tv->get_h_scrollbar_maximum());
-}
-
 void MainWindow::on_close_current_tab()
 {
        int tab = session_selector_.currentIndex();
index aa325e7373c0f3c21a414e35c0f045b07c8ffd9a..ea549c502a27c841001569bfe20b43d1d065f111 100644 (file)
@@ -151,11 +151,6 @@ 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_scroll_to_start_triggered();
-       void on_scroll_to_end_triggered();
-
        void on_close_current_tab();
 
 private:
@@ -185,12 +180,6 @@ private:
        QShortcut *run_stop_shortcut_;
        QShortcut *close_application_shortcut_;
        QShortcut *close_current_tab_shortcut_;
-       QShortcut *zoom_in_shortcut_;
-       QShortcut *zoom_in_shortcut_2_;
-       QShortcut *zoom_out_shortcut_;
-       QShortcut *zoom_out_shortcut_2_;
-       QShortcut *home_shortcut_;
-       QShortcut *end_shortcut_;
 };
 
 } // namespace pv
index 4ee791623d38d766404ef67d8854dfab8da1c46b..ae98dc3a85a50c30c377929dede032a81bbcb894 100644 (file)
@@ -206,11 +206,33 @@ View::View(Session &session, bool is_main_view, QWidget *parent) :
                this, SLOT(process_sticky_events()));
        lazy_event_handler_.setSingleShot(true);
 
+       // Set up local keyboard shortcuts
+       zoom_in_shortcut_ = new QShortcut(QKeySequence(Qt::Key_Plus), this,
+                       SLOT(on_zoom_in_shortcut_triggered()), nullptr, Qt::WidgetWithChildrenShortcut);
+       zoom_in_shortcut_->setAutoRepeat(false);
+
+       zoom_out_shortcut_ = new QShortcut(QKeySequence(Qt::Key_Minus), this,
+               SLOT(on_zoom_out_shortcut_triggered()), nullptr, Qt::WidgetWithChildrenShortcut);
+       zoom_out_shortcut_->setAutoRepeat(false);
+
+       zoom_in_shortcut_2_ = new QShortcut(QKeySequence(Qt::Key_Up), this,
+               SLOT(on_zoom_in_shortcut_triggered()), nullptr, Qt::WidgetWithChildrenShortcut);
+       zoom_out_shortcut_2_ = new QShortcut(QKeySequence(Qt::Key_Down), this,
+               SLOT(on_zoom_out_shortcut_triggered()), nullptr, Qt::WidgetWithChildrenShortcut);
+
+       home_shortcut_ = new QShortcut(QKeySequence(Qt::Key_Home), this,
+               SLOT(on_scroll_to_start_shortcut_triggered()), nullptr, Qt::WidgetWithChildrenShortcut);
+       home_shortcut_->setAutoRepeat(false);
+
+       end_shortcut_ = new QShortcut(QKeySequence(Qt::Key_End), this,
+               SLOT(on_scroll_to_end_shortcut_triggered()), nullptr, Qt::WidgetWithChildrenShortcut);
+       end_shortcut_->setAutoRepeat(false);
+
        // Trigger the initial event manually. The default device has signals
        // which were created before this object came into being
        signals_changed();
 
-       // make sure the transparent widgets are on the top
+       // Make sure the transparent widgets are on the top
        ruler_->raise();
        header_->raise();
 
@@ -1491,6 +1513,26 @@ void View::on_splitter_moved()
                resize_header_to_fit();
 }
 
+void View::on_zoom_in_shortcut_triggered()
+{
+       zoom(1);
+}
+
+void View::on_zoom_out_shortcut_triggered()
+{
+       zoom(-1);
+}
+
+void View::on_scroll_to_start_shortcut_triggered()
+{
+       set_h_offset(0);
+}
+
+void View::on_scroll_to_end_shortcut_triggered()
+{
+       set_h_offset(get_h_scrollbar_maximum());
+}
+
 void View::h_scroll_value_changed(int value)
 {
        if (updating_scroll_)
index a0e6f6bcc1d237689b3e6bb67afce9600b56166b..439823c09a8994ce7f67b56623834c8b398202d6 100644 (file)
@@ -28,6 +28,7 @@
 #include <vector>
 
 #include <QAbstractScrollArea>
+#include <QShortcut>
 #include <QSizeF>
 #include <QSplitter>
 
@@ -442,6 +443,11 @@ private Q_SLOTS:
        void on_signal_name_changed();
        void on_splitter_moved();
 
+       void on_zoom_in_shortcut_triggered();
+       void on_zoom_out_shortcut_triggered();
+       void on_scroll_to_start_shortcut_triggered();
+       void on_scroll_to_end_shortcut_triggered();
+
        void h_scroll_value_changed(int value);
        void v_scroll_value_changed();
 
@@ -506,6 +512,10 @@ private:
        Header *header_;
        QSplitter *splitter_;
 
+       QShortcut *zoom_in_shortcut_, *zoom_in_shortcut_2_;
+       QShortcut *zoom_out_shortcut_, *zoom_out_shortcut_2_;
+       QShortcut *home_shortcut_, *end_shortcut_;
+
        unordered_set< shared_ptr<Signal> > signals_;
 
 #ifdef ENABLE_DECODE