X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=pv%2Ftoolbars%2Fmainbar.cpp;h=4ff8235727fd3ffea81c118eb0ab62c847f3503b;hp=8aeb0254153ba4c0b558742d09cc41b2508462c3;hb=998b89fd858e0dfc09c97cc4e3de718643f0017b;hpb=f2dbf150d2d870e5b7edcef9a929476a61100456 diff --git a/pv/toolbars/mainbar.cpp b/pv/toolbars/mainbar.cpp index 8aeb0254..4ff82357 100644 --- a/pv/toolbars/mainbar.cpp +++ b/pv/toolbars/mainbar.cpp @@ -1,7 +1,7 @@ /* * This file is part of the PulseView project. * - * Copyright (C) 2012 Joel Holdsworth + * Copyright (C) 2012-2015 Joel Holdsworth * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -20,11 +20,13 @@ #include -#include +#include +#include #include #include #include +#include #include #include "mainbar.hpp" @@ -34,15 +36,19 @@ #include #include #include +#include -#include +#include +using std::back_inserter; +using std::copy; +using std::list; using std::map; -using std::vector; using std::max; using std::min; using std::shared_ptr; using std::string; +using std::vector; using sigrok::Capability; using sigrok::ConfigKey; @@ -60,8 +66,8 @@ MainBar::MainBar(Session &session, MainWindow &main_window) : QToolBar("Sampling Bar", &main_window), session_(session), main_window_(main_window), - device_selector_(this), - updating_device_selector_(false), + device_selector_(this, session.device_manager(), + main_window.action_connect()), configure_button_(this), configure_button_action_(NULL), channels_button_(this), @@ -73,17 +79,73 @@ MainBar::MainBar(Session &session, MainWindow &main_window) : 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_(this), + menu_button_(this) { setObjectName(QString::fromUtf8("MainBar")); setMovable(false); setFloatable(false); + setContextMenuPolicy(Qt::PreventContextMenu); + + // Save button + QToolButton *const save_button = new QToolButton(this); + + widgets::ExportMenu *export_menu = new widgets::ExportMenu(this, + session.device_manager().context(), + main_window.action_save_as()); + connect(export_menu, + SIGNAL(format_selected(std::shared_ptr)), + &main_window_, + SLOT(export_file(std::shared_ptr))); + + save_button->setMenu(export_menu); + save_button->setDefaultAction(main_window.action_save_as()); + save_button->setPopupMode(QToolButton::MenuButtonPopup); + + // Device selector menu + connect(&device_selector_, SIGNAL(device_selected()), + this, SLOT(on_device_selected())); + + // Setup the decoder button +#ifdef ENABLE_DECODE + QToolButton *add_decoder_button = new QToolButton(this); + add_decoder_button->setIcon(QIcon::fromTheme("add-decoder", + QIcon(":/icons/add-decoder.svg"))); + add_decoder_button->setPopupMode(QToolButton::InstantPopup); + add_decoder_button->setMenu(main_window_.menu_decoder_add()); +#endif + + // Setup the menu + QMenu *const menu = new QMenu(this); + + QMenu *const menu_help = new QMenu; + menu_help->setTitle(tr("&Help")); + menu_help->addAction(main_window.action_about()); + + menu->addAction(menu_help->menuAction()); + menu->addSeparator(); + menu->addAction(main_window.action_quit()); + + menu_button_.setMenu(menu); + menu_button_.setPopupMode(QToolButton::InstantPopup); + menu_button_.setIcon(QIcon::fromTheme("menu", + QIcon(":/icons/menu.svg"))); + + // Setup the toolbar + addAction(main_window.action_open()); + addWidget(save_button); + addSeparator(); + addAction(main_window.action_view_zoom_in()); + addAction(main_window.action_view_zoom_out()); + addAction(main_window.action_view_zoom_fit()); + addAction(main_window.action_view_zoom_one_to_one()); + addSeparator(); + addAction(main_window.action_view_show_cursors()); + addSeparator(); connect(&run_stop_button_, SIGNAL(clicked()), this, SLOT(on_run_stop())); - connect(&device_selector_, SIGNAL(currentIndexChanged (int)), - this, SLOT(on_device_selected())); connect(&sample_count_, SIGNAL(value_changed()), this, SLOT(on_sample_count_changed())); connect(&sample_rate_, SIGNAL(value_changed()), @@ -106,55 +168,38 @@ MainBar::MainBar(Session &session, MainWindow &main_window) : addWidget(&channels_button_); addWidget(&sample_count_); addWidget(&sample_rate_); - addWidget(&run_stop_button_); +#ifdef ENABLE_DECODE + addSeparator(); + addWidget(add_decoder_button); +#endif + + QWidget *const spacer = new QWidget(); + spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + addWidget(spacer); + + addWidget(&menu_button_); sample_count_.installEventFilter(this); sample_rate_.installEventFilter(this); } -void MainBar::set_device_list( - const std::list< std::shared_ptr > &devices, - shared_ptr selected) +void MainBar::update_device_list() { - int selected_index = -1; - - assert(selected); + DeviceManager &mgr = session_.device_manager(); + shared_ptr selected_device = session_.device(); + list< shared_ptr > devs; - updating_device_selector_ = true; + copy(mgr.devices().begin(), mgr.devices().end(), back_inserter(devs)); - device_selector_.clear(); - - for (auto device : devices) { - assert(device); - - string display_name = - session_.device_manager().get_display_name(device); - - if (selected == device) - selected_index = device_selector_.count(); - - device_selector_.addItem(display_name.c_str(), - qVariantFromValue(device)); - } - - // The selected device should have been in the list - assert(selected_index != -1); - device_selector_.setCurrentIndex(selected_index); + if (std::find(devs.begin(), devs.end(), selected_device) == devs.end()) + devs.push_back(selected_device); + assert(selected_device); + device_selector_.set_device_list(devs, selected_device); update_device_config_widgets(); - - updating_device_selector_ = false; } -shared_ptr MainBar::get_selected_device() const -{ - const int index = device_selector_.currentIndex(); - if (index < 0) - return shared_ptr(); - - return device_selector_.itemData(index).value>(); -} void MainBar::set_capture_state(pv::Session::capture_state state) { @@ -175,7 +220,7 @@ void MainBar::update_sample_rate_selector() if (updating_sample_rate_) return; - const shared_ptr device = get_selected_device(); + const shared_ptr device = device_selector_.selected_device(); if (!device) return; @@ -186,8 +231,6 @@ void MainBar::update_sample_rate_selector() const auto iter = keys.find(ConfigKey::SAMPLERATE); if (iter != keys.end() && (*iter).second.find(sigrok::LIST) != (*iter).second.end()) { - const auto keys = device->config_keys( - ConfigKey::DEVICE_OPTIONS); try { gvar_dict = device->config_list(ConfigKey::SAMPLERATE); } catch(const sigrok::Error &e) { @@ -248,7 +291,7 @@ void MainBar::update_sample_rate_selector_value() if (updating_sample_rate_) return; - const shared_ptr device = get_selected_device(); + const shared_ptr device = device_selector_.selected_device(); if (!device) return; @@ -271,7 +314,7 @@ void MainBar::update_sample_count_selector() if (updating_sample_count_) return; - const shared_ptr device = get_selected_device(); + const shared_ptr device = device_selector_.selected_device(); if (!device) return; @@ -332,7 +375,7 @@ void MainBar::update_device_config_widgets() { using namespace pv::popups; - const shared_ptr device = get_selected_device(); + const shared_ptr device = device_selector_.selected_device(); if (!device) return; @@ -390,7 +433,7 @@ void MainBar::commit_sample_count() if (updating_sample_count_) return; - const shared_ptr device = get_selected_device(); + const shared_ptr device = device_selector_.selected_device(); if (!device) return; @@ -420,7 +463,7 @@ void MainBar::commit_sample_rate() if (updating_sample_rate_) return; - const shared_ptr device = get_selected_device(); + const shared_ptr device = device_selector_.selected_device(); if (!device) return; @@ -444,10 +487,7 @@ void MainBar::commit_sample_rate() void MainBar::on_device_selected() { - if (updating_device_selector_) - return; - - shared_ptr device = get_selected_device(); + shared_ptr device = device_selector_.selected_device(); if (!device) return;