X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=pv%2Fmainwindow.cpp;h=ceace369f982158b26668ed38d4e836655e84f2d;hp=c652e3e861ac0fd31d40888b8e2e8fc064886273;hb=3d6ff1cd572a55e92779420c2d1a708cdb003fe0;hpb=8ba6f8b7541409dd33fd4ddd1b51494f555773c9 diff --git a/pv/mainwindow.cpp b/pv/mainwindow.cpp index c652e3e8..ceace369 100644 --- a/pv/mainwindow.cpp +++ b/pv/mainwindow.cpp @@ -40,6 +40,7 @@ #include "mainwindow.hpp" +#include "application.hpp" #include "devicemanager.hpp" #include "devices/hardwaredevice.hpp" #include "dialogs/settings.hpp" @@ -71,7 +72,6 @@ MainWindow::MainWindow(DeviceManager &device_manager, QWidget *parent) : QMainWindow(parent), device_manager_(device_manager), session_selector_(this), - session_state_mapper_(this), icon_red_(":/icons/status-red.svg"), icon_green_(":/icons/status-green.svg"), icon_grey_(":/icons/status-grey.svg") @@ -128,8 +128,8 @@ shared_ptr MainWindow::get_active_view() const return nullptr; } -shared_ptr MainWindow::add_view(const QString &title, - views::ViewType type, Session &session) +shared_ptr MainWindow::add_view(views::ViewType type, + Session &session) { GlobalSettings settings; shared_ptr v; @@ -143,6 +143,13 @@ shared_ptr MainWindow::add_view(const QString &title, shared_ptr main_bar = session.main_bar(); + // Only use the view type in the name if it's not the main view + QString title; + if (main_bar) + title = QString("%1 (%2)").arg(session.name(), views::ViewTypeNames[type]); + else + title = session.name(); + QDockWidget* dock = new QDockWidget(title, main_window); dock->setObjectName(title); main_window->addDockWidget(Qt::TopDockWidgetArea, dock); @@ -153,8 +160,7 @@ shared_ptr MainWindow::add_view(const QString &title, if (type == views::ViewTypeTrace) // This view will be the main view if there's no main bar yet - v = make_shared(session, - (main_bar ? false : true), dock_main); + v = make_shared(session, (main_bar ? false : true), dock_main); #ifdef ENABLE_DECODE if (type == views::ViewTypeDecoderOutput) v = make_shared(session, false, dock_main); @@ -194,8 +200,8 @@ 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_view(Session*)), - this, SLOT(on_new_view(Session*))); + connect(main_bar.get(), SIGNAL(new_view(Session*, int)), + this, SLOT(on_new_view(Session*, int))); connect(main_bar.get(), SIGNAL(show_decoder_selector(Session*)), this, SLOT(on_show_decoder_selector(Session*))); @@ -216,6 +222,8 @@ shared_ptr MainWindow::add_view(const QString &title, } } + v->setFocus(); + return v; } @@ -251,7 +259,7 @@ shared_ptr MainWindow::add_subwindow( subwindows::SubWindowType type, Session &session) { GlobalSettings settings; - shared_ptr v; + shared_ptr w; QMainWindow *main_window = nullptr; for (auto& entry : session_windows_) @@ -282,14 +290,14 @@ shared_ptr MainWindow::add_subwindow( #ifdef ENABLE_DECODE if (type == subwindows::SubWindowTypeDecoderSelector) - v = make_shared(session, dock_main); + w = make_shared(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); @@ -300,16 +308,21 @@ shared_ptr MainWindow::add_subwindow( dock->findChildren // clazy:exclude=detaching-temporary ("qt_dockwidget_closebutton").front(); + // Allow all subwindows to be closed via ESC. + close_btn->setShortcut(QKeySequence(Qt::Key_Escape)); + 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 MainWindow::add_session() @@ -319,13 +332,14 @@ shared_ptr MainWindow::add_session() shared_ptr session = make_shared(device_manager_, name); - connect(session.get(), SIGNAL(add_view(const QString&, views::ViewType, Session*)), - this, SLOT(on_add_view(const QString&, views::ViewType, Session*))); + connect(session.get(), SIGNAL(add_view(views::ViewType, Session*)), + this, SLOT(on_add_view(views::ViewType, Session*))); connect(session.get(), SIGNAL(name_changed()), this, SLOT(on_session_name_changed())); - session_state_mapper_.setMapping(session.get(), session.get()); + connect(session.get(), SIGNAL(device_changed()), + this, SLOT(on_session_device_changed())); connect(session.get(), SIGNAL(capture_state_changed(int)), - &session_state_mapper_, SLOT(map())); + this, SLOT(on_session_capture_state_changed(int))); sessions_.push_back(session); @@ -339,8 +353,7 @@ shared_ptr MainWindow::add_session() window->setDockNestingEnabled(true); - shared_ptr main_view = - add_view(name, views::ViewTypeTrace, *session); + add_view(views::ViewTypeTrace, *session); return session; } @@ -542,8 +555,6 @@ void MainWindow::setup_ui() this, SLOT(on_new_session_clicked())); connect(run_stop_button_, SIGNAL(clicked(bool)), this, SLOT(on_run_stop_clicked())); - connect(&session_state_mapper_, SIGNAL(mapped(QObject*)), - this, SLOT(on_capture_state_changed(QObject*))); connect(settings_button_, SIGNAL(clicked(bool)), this, SLOT(on_settings_clicked())); @@ -558,6 +569,19 @@ void MainWindow::setup_ui() this, SLOT(on_focus_changed())); } +void MainWindow::update_acq_button(Session *session) +{ + int state = session->get_capture_state(); + + const QString run_caption = + session->using_file_device() ? tr("Reload") : tr("Run"); + + const QIcon *icons[] = {&icon_grey_, &icon_red_, &icon_green_}; + run_stop_button_->setIcon(*icons[state]); + run_stop_button_->setText((state == pv::Session::Stopped) ? + run_caption : tr("Stop")); +} + void MainWindow::save_ui_settings() { QSettings settings; @@ -628,13 +652,12 @@ bool MainWindow::restoreState(const QByteArray &state, int version) return false; } -void MainWindow::on_add_view(const QString &title, views::ViewType type, - Session *session) +void MainWindow::on_add_view(views::ViewType type, Session *session) { // We get a pointer and need a reference for (shared_ptr& s : sessions_) if (s.get() == session) - add_view(title, type, *s); + add_view(type, *s); } void MainWindow::on_focus_changed() @@ -671,7 +694,7 @@ void MainWindow::on_focused_session_changed(shared_ptr session) setWindowTitle(session->name() + " - " + WindowTitle); // Update the state of the run/stop button, too - on_capture_state_changed(session.get()); + update_acq_button(session.get()); } void MainWindow::on_new_session_clicked() @@ -732,29 +755,40 @@ void MainWindow::on_session_name_changed() setWindowTitle(session->name() + " - " + WindowTitle); } -void MainWindow::on_capture_state_changed(QObject *obj) +void MainWindow::on_session_device_changed() { - Session *caller = qobject_cast(obj); + Session *session = qobject_cast(QObject::sender()); + assert(session); // Ignore if caller is not the currently focused session // unless there is only one session - if ((sessions_.size() > 1) && (caller != last_focused_session_.get())) + if ((sessions_.size() > 1) && (session != last_focused_session_.get())) return; - int state = caller->get_capture_state(); + update_acq_button(session); +} - const QIcon *icons[] = {&icon_grey_, &icon_red_, &icon_green_}; - run_stop_button_->setIcon(*icons[state]); - run_stop_button_->setText((state == pv::Session::Stopped) ? - tr("Run") : tr("Stop")); +void MainWindow::on_session_capture_state_changed(int state) +{ + (void)state; + + Session *session = qobject_cast(QObject::sender()); + assert(session); + + // Ignore if caller is not the currently focused session + // unless there is only one session + if ((sessions_.size() > 1) && (session != last_focused_session_.get())) + return; + + update_acq_button(session); } -void MainWindow::on_new_view(Session *session) +void MainWindow::on_new_view(Session *session, int view_type) { // We get a pointer and need a reference for (shared_ptr& s : sessions_) if (s.get() == session) - add_view(session->name(), views::ViewTypeTrace, *s); + add_view((views::ViewType)view_type, *s); } void MainWindow::on_view_close_clicked() @@ -855,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()