From: Soeren Apel Date: Mon, 10 Oct 2016 17:22:38 +0000 (+0200) Subject: Move run/stop button from the menu bar to the tab widget X-Git-Tag: pulseview-0.4.0~230 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=3231fbf9374113d07d3d544a4822ae46032062a2;p=pulseview.git Move run/stop button from the menu bar to the tab widget --- diff --git a/pv/mainwindow.cpp b/pv/mainwindow.cpp index 8d728a79..22e4e80e 100644 --- a/pv/mainwindow.cpp +++ b/pv/mainwindow.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include @@ -71,9 +72,13 @@ MainWindow::MainWindow(DeviceManager &device_manager, QMainWindow(parent), device_manager_(device_manager), session_selector_(this), + session_state_mapper_(this), action_view_sticky_scrolling_(new QAction(this)), action_view_coloured_bg_(new QAction(this)), - action_about_(new QAction(this)) + action_about_(new QAction(this)), + icon_red_(":/icons/status-red.svg"), + icon_green_(":/icons/status-green.svg"), + icon_grey_(":/icons/status-grey.svg") { qRegisterMetaType("util::Timestamp"); @@ -230,6 +235,9 @@ shared_ptr MainWindow::add_session() this, SLOT(on_add_view(const QString&, 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(capture_state_changed(int)), + &session_state_mapper_, SLOT(map())); sessions_.push_back(session); @@ -329,9 +337,15 @@ void MainWindow::setup_ui() QIcon(":/icons/document-new.png"))); new_session_button_->setAutoRaise(true); + run_stop_button_ = new QToolButton(); + run_stop_button_->setAutoRaise(true); + run_stop_button_->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); + run_stop_button_->setShortcut(QKeySequence(Qt::Key_Space)); + QHBoxLayout* layout = new QHBoxLayout(); layout->setContentsMargins(2, 2, 2, 2); layout->addWidget(new_session_button_); + layout->addWidget(run_stop_button_); static_tab_widget_ = new QWidget(); static_tab_widget_->setLayout(layout); @@ -341,6 +355,10 @@ void MainWindow::setup_ui() connect(new_session_button_, SIGNAL(clicked(bool)), 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(&session_selector_, SIGNAL(tabCloseRequested(int)), this, SLOT(on_tab_close_requested(int))); @@ -441,6 +459,23 @@ bool MainWindow::restoreState(const QByteArray &state, int version) return false; } +void MainWindow::session_error(const QString text, const QString info_text) +{ + QMetaObject::invokeMethod(this, "show_session_error", + Qt::QueuedConnection, Q_ARG(QString, text), + Q_ARG(QString, info_text)); +} + +void MainWindow::show_session_error(const QString text, const QString info_text) +{ + QMessageBox msg(this); + msg.setText(text); + msg.setInformativeText(info_text); + msg.setStandardButtons(QMessageBox::Ok); + msg.setIcon(QMessageBox::Warning); + msg.exec(); +} + void MainWindow::on_add_view(const QString &title, views::ViewType type, Session *session) { @@ -483,6 +518,9 @@ void MainWindow::on_focus_changed() 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()); } void MainWindow::on_new_session_clicked() @@ -490,6 +528,22 @@ void MainWindow::on_new_session_clicked() add_session(); } +void MainWindow::on_run_stop_clicked() +{ + Session &session = get_active_view()->session(); + + switch (session.get_capture_state()) { + case Session::Stopped: + session.start_capture([&](QString message) { + session_error("Capture failed", message); }); + break; + case Session::AwaitingTrigger: + case Session::Running: + session.stop_capture(); + break; + } +} + void MainWindow::on_session_name_changed() { // Update the corresponding dock widget's name(s) @@ -512,6 +566,27 @@ void MainWindow::on_session_name_changed() setWindowTitle(session->name() + " - " + WindowTitle); } +void MainWindow::on_capture_state_changed(QObject *obj) +{ + Session *caller = qobject_cast(obj); + + // Ignore if caller is not the currently focused session + // unless there is only one session + if (sessions_.size() > 1) { + Session &focused_session = get_active_view()->session(); + + if (caller != &focused_session) + return; + } + + int state = caller->get_capture_state(); + + 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_new_view(Session *session) { // We get a pointer and need a reference diff --git a/pv/mainwindow.hpp b/pv/mainwindow.hpp index 0904845f..8ebf4a50 100644 --- a/pv/mainwindow.hpp +++ b/pv/mainwindow.hpp @@ -26,6 +26,7 @@ #include #include +#include #include #include @@ -92,13 +93,16 @@ private: std::shared_ptr get_tab_session(int index) const; -private: void closeEvent(QCloseEvent *event); virtual QMenu* createPopupMenu(); virtual bool restoreState(const QByteArray &state, int version = 0); + void session_error(const QString text, const QString info_text); + + void show_session_error(const QString text, const QString info_text); + private Q_SLOTS: void on_add_view(const QString &title, views::ViewType type, Session *session); @@ -107,7 +111,11 @@ private Q_SLOTS: void on_focused_session_changed(std::shared_ptr session); void on_new_session_clicked(); + void on_run_stop_clicked(); + void on_session_name_changed(); + void on_capture_state_changed(QObject *obj); + void on_new_view(Session *session); void on_view_close_clicked(); @@ -130,12 +138,17 @@ private: std::map< std::shared_ptr, QMainWindow*> session_windows_; QWidget *static_tab_widget_; - QToolButton *new_session_button_; + QToolButton *new_session_button_, *run_stop_button_; QTabWidget session_selector_; + QSignalMapper session_state_mapper_; QAction *const action_view_sticky_scrolling_; QAction *const action_view_coloured_bg_; QAction *const action_about_; + + QIcon icon_red_; + QIcon icon_green_; + QIcon icon_grey_; }; } // namespace pv diff --git a/pv/toolbars/mainbar.cpp b/pv/toolbars/mainbar.cpp index f928de51..871288c3 100644 --- a/pv/toolbars/mainbar.cpp +++ b/pv/toolbars/mainbar.cpp @@ -110,12 +110,7 @@ MainBar::MainBar(Session &session, MainWindow &main_window) : sample_rate_("Hz", this), updating_sample_rate_(false), updating_sample_count_(false), - sample_count_supported_(false), - icon_red_(":/icons/status-red.svg"), - icon_green_(":/icons/status-green.svg"), - icon_grey_(":/icons/status-grey.svg"), - run_stop_button_(this), - run_stop_button_action_(nullptr) + sample_count_supported_(false) #ifdef ENABLE_DECODE , menu_decoders_add_(new pv::widgets::DecoderMenu(this, true)) #endif @@ -274,8 +269,6 @@ MainBar::MainBar(Session &session, MainWindow &main_window) : addAction(action_view_show_cursors_); addSeparator(); - connect(&run_stop_button_, SIGNAL(clicked()), - this, SLOT(on_run_stop())); connect(&sample_count_, SIGNAL(value_changed()), this, SLOT(on_sample_count_changed())); connect(&sample_rate_, SIGNAL(value_changed()), @@ -291,14 +284,11 @@ MainBar::MainBar(Session &session, MainWindow &main_window) : channels_button_.setIcon(QIcon::fromTheme("channels", QIcon(":/icons/channels.svg"))); - run_stop_button_.setToolButtonStyle(Qt::ToolButtonTextBesideIcon); - addWidget(&device_selector_); configure_button_action_ = addWidget(&configure_button_); channels_button_action_ = addWidget(&channels_button_); addWidget(&sample_count_); addWidget(&sample_rate_); - run_stop_button_action_ = addWidget(&run_stop_button_); #ifdef ENABLE_DECODE addSeparator(); addWidget(add_decoder_button); @@ -339,12 +329,6 @@ void MainBar::update_device_list() void MainBar::set_capture_state(pv::Session::capture_state state) { - 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")); - run_stop_button_.setShortcut(QKeySequence(Qt::Key_Space)); - bool ui_enabled = (state == pv::Session::Stopped) ? true : false; device_selector_.setEnabled(ui_enabled); @@ -445,20 +429,6 @@ QAction* MainBar::action_view_show_cursors() const return action_view_show_cursors_; } -void MainBar::run_stop() -{ - switch (session_.get_capture_state()) { - case Session::Stopped: - session_.start_capture([&](QString message) { - session_error("Capture failed", message); }); - break; - case Session::AwaitingTrigger: - case Session::Running: - session_.stop_capture(); - break; - } -} - void MainBar::load_file(QString file_name, std::shared_ptr format, const std::map &options) @@ -651,7 +621,6 @@ void MainBar::update_device_config_widgets() // Hide the widgets if no device is selected channels_button_action_->setVisible(!!device); - run_stop_button_action_->setVisible(!!device); if (!device) { configure_button_action_->setVisible(false); sample_count_.show_none(); @@ -936,13 +905,6 @@ void MainBar::on_sample_rate_changed() commit_sample_rate(); } -void MainBar::on_run_stop() -{ - commit_sample_count(); - commit_sample_rate(); - run_stop(); -} - void MainBar::on_config_changed() { commit_sample_count(); diff --git a/pv/toolbars/mainbar.hpp b/pv/toolbars/mainbar.hpp index 0b82e95d..e5a7adce 100644 --- a/pv/toolbars/mainbar.hpp +++ b/pv/toolbars/mainbar.hpp @@ -152,7 +152,6 @@ private Q_SLOTS: void on_device_changed(); void on_sample_count_changed(); void on_sample_rate_changed(); - void on_run_stop(); void on_config_changed(); @@ -200,12 +199,6 @@ private: bool sample_count_supported_; - QIcon icon_red_; - QIcon icon_green_; - QIcon icon_grey_; - QToolButton run_stop_button_; - QAction *run_stop_button_action_; - #ifdef ENABLE_DECODE QMenu *const menu_decoders_add_; #endif