X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;f=pv%2Fmainwindow.cpp;h=39ce7ed6f4b0034ad3b0adfc7241cdcd76340779;hb=e7aff437662e4a7dc891952bcb632d67c457d689;hp=31e9f2f9764e8b4603b0264401e065153b597278;hpb=4a4e20f5e5e3601b99c763dafe1cbfb8c7d6a387;p=pulseview.git diff --git a/pv/mainwindow.cpp b/pv/mainwindow.cpp index 31e9f2f..39ce7ed 100644 --- a/pv/mainwindow.cpp +++ b/pv/mainwindow.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include @@ -203,8 +204,6 @@ shared_ptr MainWindow::add_view(const QString &title, dock_main->addToolBar(main_bar.get()); session.set_main_bar(main_bar); - connect(main_bar.get(), SIGNAL(new_session()), - this, SLOT(on_new_session())); connect(main_bar.get(), SIGNAL(new_view(Session*)), this, SLOT(on_new_view(Session*))); } @@ -239,6 +238,8 @@ shared_ptr MainWindow::add_session() session_windows_[session] = window; session_selector_.addTab(window, name); + window->setDockNestingEnabled(true); + shared_ptr main_view = add_view(name, views::ViewTypeTrace, *session); @@ -307,12 +308,31 @@ void MainWindow::setup_ui() action_about_->setObjectName(QString::fromUtf8("actionAbout")); action_about_->setText(tr("&About...")); + // Set up the tab area + new_session_button_ = new QToolButton(); + new_session_button_->setIcon(QIcon::fromTheme("document-new", + QIcon(":/icons/document-new.png"))); + new_session_button_->setAutoRaise(true); + + QHBoxLayout* layout = new QHBoxLayout(); + layout->setContentsMargins(2, 2, 2, 2); + layout->addWidget(new_session_button_); + + QWidget* static_tab_widget_ = new QWidget(); + static_tab_widget_->setLayout(layout); + + session_selector_.setCornerWidget(static_tab_widget_, Qt::TopLeftCorner); + session_selector_.setTabsClosable(true); + connect(new_session_button_, SIGNAL(clicked(bool)), + this, SLOT(on_new_session_clicked())); + connect(&session_selector_, SIGNAL(tabCloseRequested(int)), this, SLOT(on_tab_close_requested(int))); + connect(&session_selector_, SIGNAL(currentChanged(int)), + this, SLOT(on_tab_changed(int))); - setDockNestingEnabled(true); connect(static_cast(QCoreApplication::instance()), SIGNAL(focusChanged(QWidget*, QWidget*)), @@ -375,6 +395,16 @@ void MainWindow::restore_ui_settings() } } +std::shared_ptr MainWindow::get_tab_session(int index) const +{ + // Find the session that belongs to the tab's main window + for (auto entry : session_windows_) + if (entry.second == session_selector_.widget(index)) + return entry.first; + + return nullptr; +} + void MainWindow::closeEvent(QCloseEvent *event) { save_ui_settings(); @@ -408,24 +438,40 @@ void MainWindow::on_add_view(const QString &title, views::ViewType type, void MainWindow::on_focus_changed() { - shared_ptr view; - bool title_set = false; - - view = get_active_view(); - - for (shared_ptr session : sessions_) { - if (!session->has_view(view)) - continue; - - setWindowTitle(session->name() + " - " + WindowTitle); - title_set = true; + static shared_ptr prev_session; + + shared_ptr view = get_active_view(); + + if (view) { + for (shared_ptr session : sessions_) { + if (session->has_view(view)) { + if (session != prev_session) { + // Activate correct tab if necessary + shared_ptr tab_session = get_tab_session( + session_selector_.currentIndex()); + if (tab_session != session) + session_selector_.setCurrentWidget( + session_windows_.at(session)); + + on_focused_session_changed(session); + } + + prev_session = session; + break; + } + } } - if (!title_set) + if (sessions_.empty()) setWindowTitle(WindowTitle); } -void MainWindow::on_new_session() +void MainWindow::on_focused_session_changed(shared_ptr session) +{ + setWindowTitle(session->name() + " - " + WindowTitle); +} + +void MainWindow::on_new_session_clicked() { add_session(); } @@ -446,7 +492,10 @@ void MainWindow::on_session_name_changed() } // Refresh window title if the affected session has focus - on_focus_changed(); + shared_ptr view = get_active_view(); + + if (view && session->has_view(view)) + setWindowTitle(session->name() + " - " + WindowTitle); } void MainWindow::on_new_view(Session *session) @@ -491,16 +540,22 @@ void MainWindow::on_view_close_clicked() } } +void MainWindow::on_tab_changed(int index) +{ + shared_ptr session = get_tab_session(index); + + if (session) + on_focused_session_changed(session); +} + void MainWindow::on_tab_close_requested(int index) { // TODO Ask user if this is intended in case data is unsaved - // Find the session that belongs to this main window and remove it - for (auto entry : session_windows_) - if (entry.second == session_selector_.widget(index)) { - remove_session(entry.first); - break; - } + shared_ptr session = get_tab_session(index); + + if (session) + remove_session(session); } void MainWindow::on_actionViewStickyScrolling_triggered()