+shared_ptr<pv::view::View> MainWindow::get_active_view() const
+{
+ // If there's only one view, use it...
+ if (view_docks_.size() == 1)
+ return view_docks_.begin()->second;
+
+ // ...otherwise find the dock widget the widget with focus is contained in
+ QObject *w = QApplication::focusWidget();
+ QDockWidget *dock = 0;
+
+ while (w) {
+ dock = qobject_cast<QDockWidget*>(w);
+ if (dock)
+ break;
+ w = w->parent();
+ }
+
+ // Get the view contained in the dock widget
+ for (auto entry : view_docks_)
+ if (entry.first.get() == dock)
+ return entry.second;
+
+ return shared_ptr<pv::view::View>();
+}
+
+shared_ptr<pv::view::View> MainWindow::add_view(const QString &title,
+ view::ViewType type, Session &session)
+{
+ shared_ptr<pv::view::View> v;
+
+ if (type == pv::view::TraceView)
+ v = make_shared<pv::view::View>(session, this);
+
+ if (v) {
+ shared_ptr<QDockWidget> dock = make_shared<QDockWidget>(title, this);
+ dock->setWidget(v.get());
+ dock->setObjectName(title);
+ addDockWidget(Qt::TopDockWidgetArea, dock.get());
+ view_docks_[dock] = v;
+
+ dock->setFeatures(QDockWidget::DockWidgetMovable |
+ QDockWidget::DockWidgetFloatable);
+
+ if (type == view::TraceView) {
+ connect(&session, SIGNAL(trigger_event(util::Timestamp)), v.get(),
+ SLOT(trigger_event(util::Timestamp)));
+ connect(v.get(), SIGNAL(sticky_scrolling_changed(bool)), this,
+ SLOT(sticky_scrolling_changed(bool)));
+ connect(v.get(), SIGNAL(always_zoom_to_fit_changed(bool)), this,
+ SLOT(always_zoom_to_fit_changed(bool)));
+
+ v->enable_sticky_scrolling(action_view_sticky_scrolling_->isChecked());
+ v->enable_coloured_bg(action_view_coloured_bg_->isChecked());
+ action_view_show_cursors_->setChecked(v->cursors_shown());
+ }
+
+ session.register_view(v);
+ }
+
+ return v;
+}
+