]> sigrok.org Git - pulseview.git/commitdiff
Fix various focus- and hotkey-related issues
authorSoeren Apel <redacted>
Sat, 25 Jan 2020 22:47:31 +0000 (23:47 +0100)
committerSoeren Apel <redacted>
Sat, 25 Jan 2020 22:48:50 +0000 (23:48 +0100)
Also, the hotkeys '1' and '2' now show the cursor if it was hidden.

pv/mainwindow.cpp
pv/views/trace/standardbar.cpp
pv/views/trace/tracetreeitemowner.cpp
pv/views/trace/view.cpp
pv/views/trace/view.hpp

index 1fb46e13ec483c9fc7da5fb83e544d669baf9046..ceace369f982158b26668ed38d4e836655e84f2d 100644 (file)
@@ -222,6 +222,8 @@ shared_ptr<views::ViewBase> MainWindow::add_view(views::ViewType type,
                }
        }
 
+       v->setFocus();
+
        return v;
 }
 
@@ -257,7 +259,7 @@ shared_ptr<subwindows::SubWindowBase> MainWindow::add_subwindow(
        subwindows::SubWindowType type, Session &session)
 {
        GlobalSettings settings;
-       shared_ptr<subwindows::SubWindowBase> v;
+       shared_ptr<subwindows::SubWindowBase> w;
 
        QMainWindow *main_window = nullptr;
        for (auto& entry : session_windows_)
@@ -288,14 +290,14 @@ shared_ptr<subwindows::SubWindowBase> MainWindow::add_subwindow(
 
 #ifdef ENABLE_DECODE
        if (type == subwindows::SubWindowTypeDecoderSelector)
-               v = make_shared<subwindows::decoder_selector::SubWindow>(session, dock_main);
+               w = make_shared<subwindows::decoder_selector::SubWindow>(session, dock_main);
 #endif
 
-       if (!v)
+       if (!w)
                return nullptr;
 
-       sub_windows_[dock] = v;
-       dock_main->setCentralWidget(v.get());
+       sub_windows_[dock] = w;
+       dock_main->setCentralWidget(w.get());
        dock->setWidget(dock_main);
 
        dock->setContextMenuPolicy(Qt::PreventContextMenu);
@@ -312,13 +314,15 @@ shared_ptr<subwindows::SubWindowBase> MainWindow::add_subwindow(
        connect(close_btn, SIGNAL(clicked(bool)),
                this, SLOT(on_sub_window_close_clicked()));
 
-       if (v->has_toolbar())
-               dock_main->addToolBar(v->create_toolbar(dock_main));
+       if (w->has_toolbar())
+               dock_main->addToolBar(w->create_toolbar(dock_main));
 
-       if (v->minimum_width() > 0)
-               dock->setMinimumSize(v->minimum_width(), 0);
+       if (w->minimum_width() > 0)
+               dock->setMinimumSize(w->minimum_width(), 0);
 
-       return v;
+       w->setFocus();
+
+       return w;
 }
 
 shared_ptr<Session> MainWindow::add_session()
@@ -349,7 +353,7 @@ shared_ptr<Session> MainWindow::add_session()
 
        window->setDockNestingEnabled(true);
 
-       shared_ptr<views::ViewBase> main_view = add_view(views::ViewTypeTrace, *session);
+       add_view(views::ViewTypeTrace, *session);
 
        return session;
 }
@@ -885,6 +889,10 @@ void MainWindow::on_sub_window_close_clicked()
 
        sub_windows_.erase(dock);
        dock->close();
+
+       // Restore focus to the last used main view
+       if (last_focused_session_)
+               last_focused_session_->main_view()->setFocus();
 }
 
 void MainWindow::on_view_colored_bg_shortcut()
index 2269750600a984b2aba799cc9ca42f03015cb285..48d928919f54eb7d388ad6dcce2d6a4fc1d0023b 100644 (file)
@@ -203,7 +203,7 @@ void StandardBar::on_actionViewShowCursors_triggered()
        const bool show = action_view_show_cursors_->isChecked();
 
        if (show)
-               view_->centre_cursors();
+               view_->center_cursors();
 
        view_->show_cursors(show);
 }
index ccf9b9123637ea498abfe800145eca070f03d211..95ea83732c7bb4743b0abfb6c1afa70f2384e50a 100644 (file)
@@ -114,7 +114,7 @@ void TraceTreeItemOwner::restack_items()
 {
        vector<shared_ptr<TraceTreeItem>> items(trace_tree_child_items());
 
-       // Sort by the centre line of the extents
+       // Sort by the center line of the extents
        stable_sort(items.begin(), items.end(),
                [](const shared_ptr<TraceTreeItem> &a, const shared_ptr<TraceTreeItem> &b) {
                        const auto aext = a->v_extents();
index c8a7a2b88d08ce8aff081dee9c98c39238f27e53..15e65127b2932062b46a5734575febf9d163631c 100644 (file)
@@ -208,7 +208,7 @@ View::View(Session &session, bool is_main_view, QMainWindow *parent) :
 
        // Set up local keyboard shortcuts
        zoom_in_shortcut_ = new QShortcut(QKeySequence(Qt::Key_Plus), this,
-                       SLOT(on_zoom_in_shortcut_triggered()), nullptr, Qt::WidgetWithChildrenShortcut);
+               SLOT(on_zoom_in_shortcut_triggered()), nullptr, Qt::WidgetWithChildrenShortcut);
        zoom_in_shortcut_->setAutoRepeat(false);
 
        zoom_out_shortcut_ = new QShortcut(QKeySequence(Qt::Key_Minus), this,
@@ -228,17 +228,20 @@ View::View(Session &session, bool is_main_view, QMainWindow *parent) :
                SLOT(on_scroll_to_end_shortcut_triggered()), nullptr, Qt::WidgetWithChildrenShortcut);
        end_shortcut_->setAutoRepeat(false);
 
-       grab_ruler_left_shortcut_ = new QShortcut(QKeySequence(Qt::Key_1), this);
+       grab_ruler_left_shortcut_ = new QShortcut(QKeySequence(Qt::Key_1), this,
+               nullptr, nullptr, Qt::WidgetWithChildrenShortcut);
        connect(grab_ruler_left_shortcut_, &QShortcut::activated,
                this, [=]{on_grab_ruler(1);});
        grab_ruler_left_shortcut_->setAutoRepeat(false);
 
-       grab_ruler_right_shortcut_ = new QShortcut(QKeySequence(Qt::Key_2), this);
+       grab_ruler_right_shortcut_ = new QShortcut(QKeySequence(Qt::Key_2), this,
+               nullptr, nullptr, Qt::WidgetWithChildrenShortcut);
        connect(grab_ruler_right_shortcut_, &QShortcut::activated,
                this, [=]{on_grab_ruler(2);});
        grab_ruler_right_shortcut_->setAutoRepeat(false);
 
-       cancel_grab_shortcut_ = new QShortcut(QKeySequence(Qt::Key_Escape), this);
+       cancel_grab_shortcut_ = new QShortcut(QKeySequence(Qt::Key_Escape), this,
+               nullptr, nullptr, Qt::WidgetWithChildrenShortcut);
        connect(cancel_grab_shortcut_, &QShortcut::activated,
                this, [=]{grabbed_widget_ = nullptr;});
        cancel_grab_shortcut_->setAutoRepeat(false);
@@ -874,7 +877,7 @@ void View::set_cursors(pv::util::Timestamp& first, pv::util::Timestamp& second)
        viewport_->update();
 }
 
-void View::centre_cursors()
+void View::center_cursors()
 {
        assert(cursors_);
 
@@ -1623,18 +1626,22 @@ void View::v_scroll_value_changed()
 
 void View::on_grab_ruler(int ruler_id)
 {
-       if (cursors_shown()) {
-               // Release the grabbed widget if its trigger hotkey was pressed twice
-               if (ruler_id == 1)
-                       grabbed_widget_ = (grabbed_widget_ == cursors_->first().get()) ?
-                               nullptr : cursors_->first().get();
-               else
-                       grabbed_widget_ = (grabbed_widget_ == cursors_->second().get()) ?
-                               nullptr : cursors_->second().get();
-
-               if (grabbed_widget_)
-                       grabbed_widget_->set_time(offset_ + mapFromGlobal(QCursor::pos()).x() * scale_);
+       if (!cursors_shown()) {
+               center_cursors();
+               show_cursors();
        }
+
+       // Release the grabbed widget if its trigger hotkey was pressed twice
+       if (ruler_id == 1)
+               grabbed_widget_ = (grabbed_widget_ == cursors_->first().get()) ?
+                       nullptr : cursors_->first().get();
+       else
+               grabbed_widget_ = (grabbed_widget_ == cursors_->second().get()) ?
+                       nullptr : cursors_->second().get();
+
+       if (grabbed_widget_)
+               grabbed_widget_->set_time(ruler_->get_absolute_time_from_x_pos(
+                       mapFromGlobal(QCursor::pos()).x() - header_width()));
 }
 
 void View::signals_changed()
index 040bac1b828590514fe22937041f050a3b426aef..2938d00fc0014296712adecc921ada3f2e5511d2 100644 (file)
@@ -271,7 +271,7 @@ public:
        bool colored_bg() const;
 
        /**
-        * Returns true if cursors are displayed. false otherwise.
+        * Returns true if cursors are displayed, false otherwise.
         */
        bool cursors_shown() const;
 
@@ -281,14 +281,16 @@ public:
        void show_cursors(bool show = true);
 
        /**
-        * Sets the cursors to the given offsets. You will still have to call show_cursors separately.
+        * Sets the cursors to the given offsets.
+        * You still have to call show_cursors() separately.
         */
        void set_cursors(pv::util::Timestamp& first, pv::util::Timestamp& second);
 
        /**
         * Moves the cursors to a convenient position in the view.
+        * You still have to call show_cursors() separately.
         */
-       void centre_cursors();
+       void center_cursors();
 
        /**
         * Returns a reference to the pair of cursors.