+void MainWindow::restore_sessions()
+{
+ QSettings settings;
+ int i, session_count;
+
+ session_count = settings.value("sessions", 0).toInt();
+
+ for (i = 0; i < session_count; i++) {
+ settings.beginGroup("Session" + QString::number(i));
+ shared_ptr<Session> session = add_session();
+ session->restore_settings(settings);
+ settings.endGroup();
+ }
+}
+
+void MainWindow::on_setting_changed(const QString &key, const QVariant &value)
+{
+ if (key == GlobalSettings::Key_View_ColouredBG)
+ on_settingViewColouredBg_changed(value);
+
+ if (key == GlobalSettings::Key_View_ShowSamplingPoints)
+ on_settingViewShowSamplingPoints_changed(value);
+
+ if (key == GlobalSettings::Key_View_ShowAnalogMinorGrid)
+ on_settingViewShowAnalogMinorGrid_changed(value);
+}
+
+void MainWindow::setup_ui()
+{
+ setObjectName(QString::fromUtf8("MainWindow"));
+
+ setCentralWidget(&session_selector_);
+
+ // Set the window icon
+ QIcon icon;
+ icon.addFile(QString(":/icons/pulseview.png"));
+ setWindowIcon(icon);
+
+ view_sticky_scrolling_shortcut_ = new QShortcut(QKeySequence(Qt::Key_S), this, SLOT(on_view_sticky_scrolling_shortcut()));
+ view_sticky_scrolling_shortcut_->setAutoRepeat(false);
+
+ view_show_sampling_points_shortcut_ = new QShortcut(QKeySequence(Qt::Key_Period), this, SLOT(on_view_show_sampling_points_shortcut()));
+ view_show_sampling_points_shortcut_->setAutoRepeat(false);
+
+ view_show_analog_minor_grid_shortcut_ = new QShortcut(QKeySequence(Qt::Key_G), this, SLOT(on_view_show_analog_minor_grid_shortcut()));
+ view_show_analog_minor_grid_shortcut_->setAutoRepeat(false);
+
+ view_coloured_bg_shortcut_ = new QShortcut(QKeySequence(Qt::Key_B), this, SLOT(on_view_coloured_bg_shortcut()));
+ view_coloured_bg_shortcut_->setAutoRepeat(false);
+
+ // 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_->setToolTip(tr("Create New Session"));
+ new_session_button_->setAutoRaise(true);
+
+ run_stop_button_ = new QToolButton();
+ run_stop_button_->setAutoRaise(true);
+ run_stop_button_->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
+ run_stop_button_->setToolTip(tr("Start/Stop Acquisition"));
+
+ run_stop_shortcut_ = new QShortcut(QKeySequence(Qt::Key_Space), run_stop_button_, SLOT(click()));
+ run_stop_shortcut_->setAutoRepeat(false);
+
+ settings_button_ = new QToolButton();
+ settings_button_->setIcon(QIcon::fromTheme("preferences-system",
+ QIcon(":/icons/preferences-system.png")));
+ settings_button_->setToolTip(tr("Settings"));
+ settings_button_->setAutoRaise(true);
+
+ QFrame *separator1 = new QFrame();
+ separator1->setFrameStyle(QFrame::VLine | QFrame::Raised);
+ QFrame *separator2 = new QFrame();
+ separator2->setFrameStyle(QFrame::VLine | QFrame::Raised);
+
+ QHBoxLayout* layout = new QHBoxLayout();
+ layout->setContentsMargins(2, 2, 2, 2);
+ layout->addWidget(new_session_button_);
+ layout->addWidget(separator1);
+ layout->addWidget(run_stop_button_);
+ layout->addWidget(separator2);
+ layout->addWidget(settings_button_);
+
+ static_tab_widget_ = new QWidget();
+ static_tab_widget_->setLayout(layout);
+
+ session_selector_.setCornerWidget(static_tab_widget_, Qt::TopLeftCorner);
+ session_selector_.setTabsClosable(true);
+
+ close_application_shortcut_ = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q), this, SLOT(close()));
+ close_application_shortcut_->setAutoRepeat(false);
+
+ close_current_tab_shortcut_ = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_W), this, SLOT(on_close_current_tab()));
+
+ 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(settings_button_, SIGNAL(clicked(bool)),
+ this, SLOT(on_settings_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)));
+
+
+ connect(static_cast<QApplication *>(QCoreApplication::instance()),
+ SIGNAL(focusChanged(QWidget*, QWidget*)),
+ this, SLOT(on_focus_changed()));
+}
+
+void MainWindow::save_ui_settings()
+{
+ QSettings settings;
+
+ settings.beginGroup("MainWindow");
+ settings.setValue("state", saveState());
+ settings.setValue("geometry", saveGeometry());
+ settings.endGroup();
+}
+
+void MainWindow::restore_ui_settings()
+{
+ QSettings settings;
+
+ settings.beginGroup("MainWindow");
+
+ if (settings.contains("geometry")) {
+ restoreGeometry(settings.value("geometry").toByteArray());
+ restoreState(settings.value("state").toByteArray());
+ } else
+ resize(1000, 720);
+
+ settings.endGroup();
+}
+
+shared_ptr<Session> 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)
+{
+ bool data_saved = true;
+
+ for (auto entry : session_windows_)
+ if (!entry.first->data_saved())
+ data_saved = false;
+
+ if (!data_saved && (QMessageBox::question(this, tr("Confirmation"),
+ tr("There is unsaved data. Close anyway?"),
+ QMessageBox::Yes | QMessageBox::No) == QMessageBox::No)) {
+ event->ignore();
+ } else {
+ save_ui_settings();
+ save_sessions();
+ event->accept();
+ }
+}
+
+QMenu* MainWindow::createPopupMenu()
+{
+ return nullptr;
+}
+
+bool MainWindow::restoreState(const QByteArray &state, int version)
+{
+ (void)state;
+ (void)version;
+
+ // Do nothing. We don't want Qt to handle this, or else it
+ // will try to restore all the dock widgets and create havoc.
+
+ 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)