]> sigrok.org Git - pulseview.git/blobdiff - pv/toolbars/mainbar.cpp
Various minor whitespace and consistency fixes.
[pulseview.git] / pv / toolbars / mainbar.cpp
index b404b3da45b32666f335fbee88d773c657b0b855..30cff789a3436abdd1216f94d25e4abca6668bc1 100644 (file)
@@ -110,9 +110,13 @@ MainBar::MainBar(Session &session, MainWindow &main_window) :
        // Save button
        QToolButton *const save_button = new QToolButton(this);
 
+       vector<QAction *> open_actions;
+       open_actions.push_back(main_window.action_save_as());
+       open_actions.push_back(main_window.action_save_selection_as());
+
        widgets::ExportMenu *export_menu = new widgets::ExportMenu(this,
                session.device_manager().context(),
-               main_window.action_save_as());
+               open_actions);
        connect(export_menu,
                SIGNAL(format_selected(std::shared_ptr<sigrok::OutputFormat>)),
                &main_window_,
@@ -135,13 +139,19 @@ MainBar::MainBar(Session &session, MainWindow &main_window) :
        add_decoder_button->setMenu(main_window_.menu_decoder_add());
 #endif
 
-       // Setup the menu
+       // Setup the burger menu
        QMenu *const menu = new QMenu(this);
 
+       QMenu *const menu_view = new QMenu;
+       menu_view->setTitle(tr("&View"));
+       menu_view->addAction(main_window.action_view_sticky_scrolling());
+
        QMenu *const menu_help = new QMenu;
        menu_help->setTitle(tr("&Help"));
        menu_help->addAction(main_window.action_about());
 
+       menu->addAction(menu_view->menuAction());
+       menu->addSeparator();
        menu->addAction(menu_help->menuAction());
        menu->addSeparator();
        menu->addAction(main_window.action_quit());
@@ -226,6 +236,14 @@ void MainBar::set_capture_state(pv::Session::capture_state 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);
+       configure_button_.setEnabled(ui_enabled);
+       channels_button_.setEnabled(ui_enabled);
+       sample_count_.setEnabled(ui_enabled);
+       sample_rate_.setEnabled(ui_enabled);
 }
 
 void MainBar::update_sample_rate_selector()
@@ -260,7 +278,7 @@ void MainBar::update_sample_rate_selector()
                (*iter).second.find(sigrok::LIST) != (*iter).second.end()) {
                try {
                        gvar_dict = sr_dev->config_list(ConfigKey::SAMPLERATE);
-               } catch(const sigrok::Error &e) {
+               } catch (const sigrok::Error &e) {
                        // Failed to enunmerate samplerate
                        (void)e;
                }
@@ -273,8 +291,7 @@ void MainBar::update_sample_rate_selector()
        }
 
        if ((gvar_list = g_variant_lookup_value(gvar_dict.gobj(),
-                       "samplerate-steps", G_VARIANT_TYPE("at"))))
-       {
+                       "samplerate-steps", G_VARIANT_TYPE("at")))) {
                elements = (const uint64_t *)g_variant_get_fixed_array(
                                gvar_list, &num_elements, sizeof(uint64_t));
 
@@ -291,18 +308,15 @@ void MainBar::update_sample_rate_selector()
 
                if (step == 1)
                        sample_rate_.show_125_list(min, max);
-               else
-               {
+               else {
                        // When the step is not 1, we cam't make a 1-2-5-10
                        // list of sample rates, because we may not be able to
                        // make round numbers. Therefore in this case, show a
                        // spin box.
                        sample_rate_.show_min_max_step(min, max, step);
                }
-       }
-       else if ((gvar_list = g_variant_lookup_value(gvar_dict.gobj(),
-                       "samplerates", G_VARIANT_TYPE("at"))))
-       {
+       } else if ((gvar_list = g_variant_lookup_value(gvar_dict.gobj(),
+                       "samplerates", G_VARIANT_TYPE("at")))) {
                elements = (const uint64_t *)g_variant_get_fixed_array(
                                gvar_list, &num_elements, sizeof(uint64_t));
                sample_rate_.show_list(elements, num_elements);
@@ -352,8 +366,7 @@ void MainBar::update_sample_count_selector()
        assert(!updating_sample_count_);
        updating_sample_count_ = true;
 
-       if (!sample_count_supported_)
-       {
+       if (!sample_count_supported_) {
                sample_count_.show_none();
                updating_sample_count_ = false;
                return;
@@ -376,7 +389,7 @@ void MainBar::update_sample_count_selector()
                        if (gvar.gobj())
                                g_variant_get(gvar.gobj(), "(tt)",
                                        &min_sample_count, &max_sample_count);
-               } catch(const sigrok::Error &e) {
+               } catch (const sigrok::Error &e) {
                        // Failed to query sample limit
                        (void)e;
                }
@@ -437,8 +450,7 @@ void MainBar::update_device_config_widgets()
        sample_count_supported_ = false;
 
        try {
-               for (auto entry : sr_dev->config_keys(ConfigKey::DEVICE_OPTIONS))
-               {
+               for (auto entry : sr_dev->config_keys(ConfigKey::DEVICE_OPTIONS)) {
                        auto key = entry.first;
                        auto capabilities = entry.second;
                        switch (key->id()) {
@@ -447,8 +459,7 @@ void MainBar::update_device_config_widgets()
                                        sample_count_supported_ = true;
                                break;
                        case SR_CONF_LIMIT_FRAMES:
-                               if (capabilities.count(Capability::SET))
-                               {
+                               if (capabilities.count(Capability::SET)) {
                                        sr_dev->config_set(ConfigKey::LIMIT_FRAMES,
                                                Glib::Variant<guint64>::create(1));
                                        on_config_changed();
@@ -482,8 +493,7 @@ void MainBar::commit_sample_count()
        const shared_ptr<sigrok::Device> sr_dev = device->device();
 
        sample_count = sample_count_.value();
-       if (sample_count_supported_)
-       {
+       if (sample_count_supported_) {
                try {
                        sr_dev->config_set(ConfigKey::LIMIT_SAMPLES,
                                Glib::Variant<guint64>::create(sample_count));
@@ -568,12 +578,14 @@ void MainBar::on_config_changed()
 
 bool MainBar::eventFilter(QObject *watched, QEvent *event)
 {
-       if ((watched == &sample_count_ || watched == &sample_rate_) &&
-               (event->type() == QEvent::ToolTip)) {
-               double sec = (double)sample_count_.value() / sample_rate_.value();
+       if (sample_count_supported_ && (watched == &sample_count_ ||
+                       watched == &sample_rate_) &&
+                       (event->type() == QEvent::ToolTip)) {
+               auto sec = pv::util::Timestamp(sample_count_.value()) / sample_rate_.value();
                QHelpEvent *help_event = static_cast<QHelpEvent*>(event);
 
-               QString str = tr("Total sampling time: %1").arg(pv::util::format_second(sec));
+               QString str = tr("Total sampling time: %1").arg(
+                       pv::util::format_time_si(sec, pv::util::SIPrefix::unspecified, 0, "s", false));
                QToolTip::showText(help_event->globalPos(), str);
 
                return true;