X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;f=pv%2Fmainwindow.cpp;h=879c8a522d9121f8c27a907a9d1fc2bf78717dc4;hb=24c29d4f917ffac5a280d572cc04d1edb66a81b9;hp=1821ad1e67a69276bd3e6b04c607df0e2c1f121f;hpb=a2b9ac403cb540b5c6499d00d3d376384ec6c94f;p=pulseview.git diff --git a/pv/mainwindow.cpp b/pv/mainwindow.cpp index 1821ad1..879c8a5 100644 --- a/pv/mainwindow.cpp +++ b/pv/mainwindow.cpp @@ -34,13 +34,16 @@ #include #include #include +#include #include "mainwindow.hpp" #include "devicemanager.hpp" +#include "globalsettings.hpp" #include "util.hpp" #include "devices/hardwaredevice.hpp" #include "dialogs/about.hpp" +#include "dialogs/settings.hpp" #include "toolbars/mainbar.hpp" #include "view/view.hpp" #include "views/trace/standardbar.hpp" @@ -64,6 +67,9 @@ class ViewItem; using toolbars::MainBar; +using std::bind; +using std::placeholders::_1; + const QString MainWindow::WindowTitle = tr("PulseView"); MainWindow::MainWindow(DeviceManager &device_manager, @@ -73,14 +79,16 @@ MainWindow::MainWindow(DeviceManager &device_manager, 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)), icon_red_(":/icons/status-red.svg"), icon_green_(":/icons/status-green.svg"), icon_grey_(":/icons/status-grey.svg") { qRegisterMetaType("util::Timestamp"); + qRegisterMetaType("uint64_t"); + + GlobalSettings::register_change_handler(GlobalSettings::Key_View_ColouredBG, + bind(&MainWindow::on_settingViewColouredBg_changed, this, _1)); setup_ui(); restore_ui_settings(); @@ -117,16 +125,6 @@ MainWindow::~MainWindow() remove_session(sessions_.front()); } -QAction* MainWindow::action_view_sticky_scrolling() const -{ - return action_view_sticky_scrolling_; -} - -QAction* MainWindow::action_view_coloured_bg() const -{ - return action_view_coloured_bg_; -} - QAction* MainWindow::action_about() const { return action_about_; @@ -160,6 +158,8 @@ shared_ptr MainWindow::get_active_view() const shared_ptr MainWindow::add_view(const QString &title, views::ViewType type, Session &session) { + GlobalSettings settings; + QMainWindow *main_window = nullptr; for (auto entry : session_windows_) if (entry.first.get() == &session) @@ -199,8 +199,8 @@ shared_ptr MainWindow::add_view(const QString &title, qobject_cast(v.get()), SLOT(trigger_event(util::Timestamp))); - v->enable_sticky_scrolling(action_view_sticky_scrolling_->isChecked()); - v->enable_coloured_bg(action_view_coloured_bg_->isChecked()); + v->enable_sticky_scrolling(true); + v->enable_coloured_bg(settings.value(GlobalSettings::Key_View_ColouredBG).toBool()); shared_ptr main_bar = session.main_bar(); if (!main_bar) { @@ -266,7 +266,7 @@ void MainWindow::remove_view(shared_ptr view) shared_ptr MainWindow::add_session() { static int last_session_id = 1; - QString name = tr("Untitled-%1").arg(last_session_id++); + QString name = tr("Session %1").arg(last_session_id++); shared_ptr session = make_shared(device_manager_, name); @@ -342,19 +342,11 @@ void MainWindow::setup_ui() icon.addFile(QString(":/icons/sigrok-logo-notext.png")); setWindowIcon(icon); - action_view_sticky_scrolling_->setCheckable(true); - action_view_sticky_scrolling_->setChecked(true); - action_view_sticky_scrolling_->setShortcut(QKeySequence(Qt::Key_S)); - action_view_sticky_scrolling_->setObjectName( - QString::fromUtf8("actionViewStickyScrolling")); - action_view_sticky_scrolling_->setText(tr("&Sticky Scrolling")); + view_sticky_scrolling_shortcut_ = new QShortcut(QKeySequence(Qt::Key_S), this, SLOT(on_view_sticky_scrolling_shortcut())); + view_sticky_scrolling_shortcut_->setAutoRepeat(false); - action_view_coloured_bg_->setCheckable(true); - action_view_coloured_bg_->setChecked(true); - action_view_coloured_bg_->setShortcut(QKeySequence(Qt::Key_B)); - action_view_coloured_bg_->setObjectName( - QString::fromUtf8("actionViewColouredBg")); - action_view_coloured_bg_->setText(tr("Use &Coloured Backgrounds")); + view_coloured_bg_shortcut_ = new QShortcut(QKeySequence(Qt::Key_B), this, SLOT(on_view_coloured_bg_shortcut())); + view_coloured_bg_shortcut_->setAutoRepeat(false); action_about_->setObjectName(QString::fromUtf8("actionAbout")); action_about_->setToolTip(tr("&About...")); @@ -369,9 +361,11 @@ void MainWindow::setup_ui() run_stop_button_ = new QToolButton(); run_stop_button_->setAutoRaise(true); run_stop_button_->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); - run_stop_button_->setShortcut(QKeySequence(Qt::Key_Space)); 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("configure", QIcon(":/icons/configure.png"))); @@ -397,12 +391,19 @@ void MainWindow::setup_ui() 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))); @@ -602,6 +603,12 @@ void MainWindow::on_run_stop_clicked() } } +void MainWindow::on_settings_clicked() +{ + dialogs::Settings dlg; + dlg.exec(); +} + void MainWindow::on_session_name_changed() { // Update the corresponding dock widget's name(s) @@ -714,22 +721,36 @@ void MainWindow::on_tab_close_requested(int index) remove_session(session); } -void MainWindow::on_actionViewStickyScrolling_triggered() +void MainWindow::on_view_sticky_scrolling_shortcut() { shared_ptr viewbase = get_active_view(); views::TraceView::View* view = qobject_cast(viewbase.get()); if (view) - view->enable_sticky_scrolling(action_view_sticky_scrolling_->isChecked()); + view->toggle_sticky_scrolling(); } -void MainWindow::on_actionViewColouredBg_triggered() +void MainWindow::on_view_coloured_bg_shortcut() { - shared_ptr viewbase = get_active_view(); - views::TraceView::View* view = - qobject_cast(viewbase.get()); - if (view) - view->enable_coloured_bg(action_view_coloured_bg_->isChecked()); + GlobalSettings settings; + + bool state = settings.value(GlobalSettings::Key_View_ColouredBG).toBool(); + settings.setValue(GlobalSettings::Key_View_ColouredBG, !state); +} + +void MainWindow::on_settingViewColouredBg_changed(const QVariant new_value) +{ + bool state = new_value.toBool(); + + for (auto entry : view_docks_) { + shared_ptr viewbase = entry.second; + + // Only trace views have this setting + views::TraceView::View* view = + qobject_cast(viewbase.get()); + if (view) + view->enable_coloured_bg(state); + } } void MainWindow::on_actionAbout_triggered() @@ -738,4 +759,11 @@ void MainWindow::on_actionAbout_triggered() dlg.exec(); } +void MainWindow::on_close_current_tab() +{ + int tab = session_selector_.currentIndex(); + + on_tab_close_requested(tab); +} + } // namespace pv