From 476ca5f48e8a528d529f36b8b0c8471c655415ad Mon Sep 17 00:00:00 2001 From: Soeren Apel Date: Sun, 24 Nov 2019 20:03:15 +0100 Subject: [PATCH] Fix #1440 by moving shortcuts from the main window to the view --- pv/mainwindow.cpp | 50 +---------------------------------------- pv/mainwindow.hpp | 11 --------- pv/views/trace/view.cpp | 44 +++++++++++++++++++++++++++++++++++- pv/views/trace/view.hpp | 10 +++++++++ 4 files changed, 54 insertions(+), 61 deletions(-) diff --git a/pv/mainwindow.cpp b/pv/mainwindow.cpp index 0b68b1d7..f0a4c071 100644 --- a/pv/mainwindow.cpp +++ b/pv/mainwindow.cpp @@ -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 = get_tab_session(session_selector_.currentIndex()); - - if (!session) - return; - - shared_ptr v = session.get()->main_view(); - views::trace::View *tv = - qobject_cast(v.get()); - tv->set_h_offset(start ? 0 : tv->get_h_scrollbar_maximum()); -} - void MainWindow::on_close_current_tab() { int tab = session_selector_.currentIndex(); diff --git a/pv/mainwindow.hpp b/pv/mainwindow.hpp index aa325e73..ea549c50 100644 --- a/pv/mainwindow.hpp +++ b/pv/mainwindow.hpp @@ -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 diff --git a/pv/views/trace/view.cpp b/pv/views/trace/view.cpp index 4ee79162..ae98dc3a 100644 --- a/pv/views/trace/view.cpp +++ b/pv/views/trace/view.cpp @@ -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_) diff --git a/pv/views/trace/view.hpp b/pv/views/trace/view.hpp index a0e6f6bc..439823c0 100644 --- a/pv/views/trace/view.hpp +++ b/pv/views/trace/view.hpp @@ -28,6 +28,7 @@ #include #include +#include #include #include @@ -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 > signals_; #ifdef ENABLE_DECODE -- 2.30.2