#include <QCloseEvent>
#include <QDockWidget>
#include <QHBoxLayout>
+#include <QMessageBox>
#include <QSettings>
#include <QWidget>
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");
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);
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);
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)));
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)
{
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()
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)
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
#include <memory>
#include <QMainWindow>
+#include <QSignalMapper>
#include <QToolButton>
#include <QTabWidget>
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);
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();
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
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
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()),
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);
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);
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)
// 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();
commit_sample_rate();
}
-void MainBar::on_run_stop()
-{
- commit_sample_count();
- commit_sample_rate();
- run_stop();
-}
-
void MainBar::on_config_changed()
{
commit_sample_count();