}
}
+ v->setFocus();
+
return v;
}
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_)
#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);
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()
window->setDockNestingEnabled(true);
- shared_ptr<views::ViewBase> main_view = add_view(views::ViewTypeTrace, *session);
+ add_view(views::ViewTypeTrace, *session);
return session;
}
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()
// 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,
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);
viewport_->update();
}
-void View::centre_cursors()
+void View::center_cursors()
{
assert(cursors_);
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()
bool colored_bg() const;
/**
- * Returns true if cursors are displayed. false otherwise.
+ * Returns true if cursors are displayed, false otherwise.
*/
bool cursors_shown() const;
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.