]> sigrok.org Git - pulseview.git/commitdiff
Move run/stop button from the menu bar to the tab widget
authorSoeren Apel <redacted>
Mon, 10 Oct 2016 17:22:38 +0000 (19:22 +0200)
committerSoeren Apel <redacted>
Sun, 4 Dec 2016 13:37:37 +0000 (14:37 +0100)
pv/mainwindow.cpp
pv/mainwindow.hpp
pv/toolbars/mainbar.cpp
pv/toolbars/mainbar.hpp

index 8d728a797c86ff0b4e95b66b2f3337a917887ad7..22e4e80e10f6a2ad3b803abcedfd4a88f5500bec 100644 (file)
@@ -32,6 +32,7 @@
 #include <QCloseEvent>
 #include <QDockWidget>
 #include <QHBoxLayout>
+#include <QMessageBox>
 #include <QSettings>
 #include <QWidget>
 
@@ -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>("util::Timestamp");
 
@@ -230,6 +235,9 @@ shared_ptr<Session> 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> 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<Session*>(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
index 0904845f983e5362c8ad56ee76633dcac8ce5e6e..8ebf4a50bd3344518b991aea4bf9322ebeaa1835 100644 (file)
@@ -26,6 +26,7 @@
 #include <memory>
 
 #include <QMainWindow>
+#include <QSignalMapper>
 #include <QToolButton>
 #include <QTabWidget>
 
@@ -92,13 +93,16 @@ private:
 
        std::shared_ptr<Session> 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> 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<Session>, 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
index f928de5166afe46063be9ccaf6215063961d3689..871288c39f9947e23c17648d116cbc629ad89d97 100644 (file)
@@ -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<sigrok::InputFormat> format,
        const std::map<std::string, Glib::VariantBase> &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();
index 0b82e95d833ed550fe0203718b02e97a6bab12fd..e5a7adce5483969690015e655606ef09b69318be 100644 (file)
@@ -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