From: Soeren Apel Date: Mon, 28 Nov 2016 19:02:17 +0000 (+0100) Subject: Implement views::trace::StandardBar and derive MainBar from it X-Git-Tag: pulseview-0.4.0~219 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=e0ba4f6fb263b4cc1dae96df2a0ff1e1ef8984ce;p=pulseview.git Implement views::trace::StandardBar and derive MainBar from it --- diff --git a/CMakeLists.txt b/CMakeLists.txt index b70a905e..ee58ce2c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -263,6 +263,7 @@ set(pulseview_SOURCES pv/view/viewport.cpp pv/view/viewwidget.cpp pv/views/viewbase.cpp + pv/views/trace/standardbar.cpp pv/widgets/colourbutton.cpp pv/widgets/colourpopup.cpp pv/widgets/devicetoolbutton.cpp @@ -316,6 +317,7 @@ set(pulseview_HEADERS pv/view/viewport.hpp pv/view/viewwidget.hpp pv/views/viewbase.hpp + pv/views/trace/standardbar.hpp pv/widgets/colourbutton.hpp pv/widgets/colourpopup.hpp pv/widgets/devicetoolbutton.hpp diff --git a/pv/mainwindow.cpp b/pv/mainwindow.cpp index f777bfd6..4a98e408 100644 --- a/pv/mainwindow.cpp +++ b/pv/mainwindow.cpp @@ -44,6 +44,7 @@ #include "dialogs/about.hpp" #include "toolbars/mainbar.hpp" #include "view/view.hpp" +#include "views/trace/standardbar.hpp" #include #include @@ -204,12 +205,17 @@ shared_ptr MainWindow::add_view(const QString &title, shared_ptr main_bar = session.main_bar(); if (!main_bar) { - main_bar = make_shared(session, *this); + /* Initial view, create the main bar */ + main_bar = make_shared(session, this, v.get()); dock_main->addToolBar(main_bar.get()); session.set_main_bar(main_bar); connect(main_bar.get(), SIGNAL(new_view(Session*)), this, SLOT(on_new_view(Session*))); + } else { + /* Additional view, create a standard bar */ + dock_main->addToolBar( + new pv::views::trace::StandardBar(session, this, v.get())); } main_bar->action_view_show_cursors()->setChecked(v->cursors_shown()); diff --git a/pv/toolbars/mainbar.cpp b/pv/toolbars/mainbar.cpp index b670b75a..e77f18bb 100644 --- a/pv/toolbars/mainbar.cpp +++ b/pv/toolbars/mainbar.cpp @@ -86,20 +86,17 @@ const uint64_t MainBar::DefaultSampleCount = 1000000; const char *MainBar::SettingOpenDirectory = "MainWindow/OpenDirectory"; const char *MainBar::SettingSaveDirectory = "MainWindow/SaveDirectory"; -MainBar::MainBar(Session &session, MainWindow &main_window) : - QToolBar("Sampling Bar", &main_window), +MainBar::MainBar(Session &session, QWidget *parent, + pv::views::TraceView::View *view) : + StandardBar(session, parent, view, false), action_new_view_(new QAction(this)), action_open_(new QAction(this)), action_save_as_(new QAction(this)), action_save_selection_as_(new QAction(this)), action_connect_(new QAction(this)), - action_view_zoom_in_(new QAction(this)), - action_view_zoom_out_(new QAction(this)), - action_view_zoom_fit_(new QAction(this)), - action_view_zoom_one_to_one_(new QAction(this)), - action_view_show_cursors_(new QAction(this)), - session_(session), - device_selector_(&main_window, session.device_manager(), + open_button_(new QToolButton()), + save_button_(new QToolButton()), + device_selector_(parent, session.device_manager(), action_connect_), configure_button_(this), configure_button_action_(nullptr), @@ -111,15 +108,12 @@ MainBar::MainBar(Session &session, MainWindow &main_window) : updating_sample_count_(false), sample_count_supported_(false) #ifdef ENABLE_DECODE - , menu_decoders_add_(new pv::widgets::DecoderMenu(this, true)) + , add_decoder_button_(new QToolButton()), + menu_decoders_add_(new pv::widgets::DecoderMenu(this, true)) #endif { setObjectName(QString::fromUtf8("MainBar")); - setMovable(false); - setFloatable(false); - setContextMenuPolicy(Qt::PreventContextMenu); - // Actions action_new_view_->setText(tr("New &View")); action_new_view_->setIcon(QIcon::fromTheme("window-new", @@ -166,47 +160,7 @@ MainBar::MainBar(Session &session, MainWindow &main_window) : connect(action_connect_, SIGNAL(triggered(bool)), this, SLOT(on_actionConnect_triggered())); - action_view_zoom_in_->setText(tr("Zoom &In")); - action_view_zoom_in_->setIcon(QIcon::fromTheme("zoom-in", - QIcon(":/icons/zoom-in.png"))); - // simply using Qt::Key_Plus shows no + in the menu - action_view_zoom_in_->setShortcut(QKeySequence::ZoomIn); - connect(action_view_zoom_in_, SIGNAL(triggered(bool)), - this, SLOT(on_actionViewZoomIn_triggered())); - - action_view_zoom_out_->setText(tr("Zoom &Out")); - action_view_zoom_out_->setIcon(QIcon::fromTheme("zoom-out", - QIcon(":/icons/zoom-out.png"))); - action_view_zoom_out_->setShortcut(QKeySequence::ZoomOut); - connect(action_view_zoom_out_, SIGNAL(triggered(bool)), - this, SLOT(on_actionViewZoomOut_triggered())); - - action_view_zoom_fit_->setCheckable(true); - action_view_zoom_fit_->setText(tr("Zoom to &Fit")); - action_view_zoom_fit_->setIcon(QIcon::fromTheme("zoom-fit", - QIcon(":/icons/zoom-fit.png"))); - action_view_zoom_fit_->setShortcut(QKeySequence(Qt::Key_F)); - connect(action_view_zoom_fit_, SIGNAL(triggered(bool)), - this, SLOT(on_actionViewZoomFit_triggered())); - - action_view_zoom_one_to_one_->setText(tr("Zoom to O&ne-to-One")); - action_view_zoom_one_to_one_->setIcon(QIcon::fromTheme("zoom-original", - QIcon(":/icons/zoom-original.png"))); - action_view_zoom_one_to_one_->setShortcut(QKeySequence(Qt::Key_O)); - connect(action_view_zoom_one_to_one_, SIGNAL(triggered(bool)), - this, SLOT(on_actionViewZoomOneToOne_triggered())); - - action_view_show_cursors_->setCheckable(true); - action_view_show_cursors_->setIcon(QIcon::fromTheme("show-cursors", - QIcon(":/icons/show-cursors.svg"))); - action_view_show_cursors_->setShortcut(QKeySequence(Qt::Key_C)); - connect(action_view_show_cursors_, SIGNAL(triggered(bool)), - this, SLOT(on_actionViewShowCursors_triggered())); - action_view_show_cursors_->setText(tr("Show &Cursors")); - // Open button - QToolButton *const open_button = new QToolButton(this); - widgets::ImportMenu *import_menu = new widgets::ImportMenu(this, session.device_manager().context(), action_open_); connect(import_menu, @@ -214,13 +168,11 @@ MainBar::MainBar(Session &session, MainWindow &main_window) : this, SLOT(import_file(std::shared_ptr))); - open_button->setMenu(import_menu); - open_button->setDefaultAction(action_open_); - open_button->setPopupMode(QToolButton::MenuButtonPopup); + open_button_->setMenu(import_menu); + open_button_->setDefaultAction(action_open_); + open_button_->setPopupMode(QToolButton::MenuButtonPopup); // Save button - QToolButton *const save_button = new QToolButton(this); - vector open_actions; open_actions.push_back(action_save_as_); open_actions.push_back(action_save_selection_as_); @@ -233,9 +185,9 @@ MainBar::MainBar(Session &session, MainWindow &main_window) : this, SLOT(export_file(std::shared_ptr))); - save_button->setMenu(export_menu); - save_button->setDefaultAction(action_save_as_); - save_button->setPopupMode(QToolButton::MenuButtonPopup); + save_button_->setMenu(export_menu); + save_button_->setDefaultAction(action_save_as_); + save_button_->setPopupMode(QToolButton::MenuButtonPopup); // Device selector menu connect(&device_selector_, SIGNAL(device_selected()), @@ -247,27 +199,12 @@ MainBar::MainBar(Session &session, MainWindow &main_window) : connect(menu_decoders_add_, SIGNAL(decoder_selected(srd_decoder*)), this, SLOT(add_decoder(srd_decoder*))); - QToolButton *add_decoder_button = new QToolButton(this); - add_decoder_button->setIcon(QIcon::fromTheme("add-decoder", + add_decoder_button_->setIcon(QIcon::fromTheme("add-decoder", QIcon(":/icons/add-decoder.svg"))); - add_decoder_button->setPopupMode(QToolButton::InstantPopup); - add_decoder_button->setMenu(menu_decoders_add_); + add_decoder_button_->setPopupMode(QToolButton::InstantPopup); + add_decoder_button_->setMenu(menu_decoders_add_); #endif - // Setup the toolbar - addAction(action_new_view_); - addSeparator(); - addWidget(open_button); - addWidget(save_button); - addSeparator(); - addAction(action_view_zoom_in_); - addAction(action_view_zoom_out_); - addAction(action_view_zoom_fit_); - addAction(action_view_zoom_one_to_one_); - addSeparator(); - addAction(action_view_show_cursors_); - addSeparator(); - connect(&sample_count_, SIGNAL(value_changed()), this, SLOT(on_sample_count_changed())); connect(&sample_rate_, SIGNAL(value_changed()), @@ -283,15 +220,7 @@ MainBar::MainBar(Session &session, MainWindow &main_window) : channels_button_.setIcon(QIcon::fromTheme("channels", QIcon(":/icons/channels.svg"))); - addWidget(&device_selector_); - configure_button_action_ = addWidget(&configure_button_); - channels_button_action_ = addWidget(&channels_button_); - addWidget(&sample_count_); - addWidget(&sample_rate_); -#ifdef ENABLE_DECODE - addSeparator(); - addWidget(add_decoder_button); -#endif + add_toolbar_widgets(); sample_count_.installEventFilter(this); sample_rate_.installEventFilter(this); @@ -305,11 +234,6 @@ MainBar::MainBar(Session &session, MainWindow &main_window) : update_device_list(); } -Session &MainBar::session(void) const -{ - return session_; -} - void MainBar::update_device_list() { DeviceManager &mgr = session_.device_manager(); @@ -362,31 +286,6 @@ QAction* MainBar::action_connect() const return action_connect_; } -QAction* MainBar::action_view_zoom_in() const -{ - return action_view_zoom_in_; -} - -QAction* MainBar::action_view_zoom_out() const -{ - return action_view_zoom_out_; -} - -QAction* MainBar::action_view_zoom_fit() const -{ - return action_view_zoom_fit_; -} - -QAction* MainBar::action_view_zoom_one_to_one() const -{ - return action_view_zoom_one_to_one_; -} - -QAction* MainBar::action_view_show_cursors() const -{ - return action_view_show_cursors_; -} - void MainBar::update_sample_rate_selector() { Glib::VariantContainerBase gvar_dict; @@ -883,53 +782,25 @@ void MainBar::on_actionConnect_triggered() update_device_list(); } -void MainBar::on_actionViewZoomIn_triggered() +void MainBar::add_toolbar_widgets() { - views::TraceView::View *trace_view = - qobject_cast(session_.main_view().get()); - - trace_view->zoom(1); -} - -void MainBar::on_actionViewZoomOut_triggered() -{ - views::TraceView::View *trace_view = - qobject_cast(session_.main_view().get()); - - trace_view->zoom(-1); -} - -void MainBar::on_actionViewZoomFit_triggered() -{ - views::TraceView::View *trace_view = - qobject_cast(session_.main_view().get()); - - trace_view->zoom_fit(action_view_zoom_fit_->isChecked()); -} - -void MainBar::on_actionViewZoomOneToOne_triggered() -{ - views::TraceView::View *trace_view = - qobject_cast(session_.main_view().get()); - - trace_view->zoom_one_to_one(); -} - -void MainBar::on_actionViewShowCursors_triggered() -{ - views::TraceView::View *trace_view = - qobject_cast(session_.main_view().get()); - - const bool show = !trace_view->cursors_shown(); - if (show) - trace_view->centre_cursors(); + addAction(action_new_view_); + addSeparator(); + addWidget(open_button_); + addWidget(save_button_); + addSeparator(); - trace_view->show_cursors(show); -} + StandardBar::add_toolbar_widgets(); -void MainBar::on_always_zoom_to_fit_changed(bool state) -{ - action_view_zoom_fit_->setChecked(state); + addWidget(&device_selector_); + configure_button_action_ = addWidget(&configure_button_); + channels_button_action_ = addWidget(&channels_button_); + addWidget(&sample_count_); + addWidget(&sample_rate_); +#ifdef ENABLE_DECODE + addSeparator(); + addWidget(add_decoder_button_); +#endif } bool MainBar::eventFilter(QObject *watched, QEvent *event) diff --git a/pv/toolbars/mainbar.hpp b/pv/toolbars/mainbar.hpp index 95959e17..50c30fd2 100644 --- a/pv/toolbars/mainbar.hpp +++ b/pv/toolbars/mainbar.hpp @@ -35,6 +35,7 @@ #include #include +#include #include #include #include @@ -54,9 +55,15 @@ namespace pv { class MainWindow; class Session; +namespace views { +namespace TraceView { +class View; +} +} + namespace toolbars { -class MainBar : public QToolBar +class MainBar : public pv::views::trace::StandardBar { Q_OBJECT @@ -78,9 +85,8 @@ private: static const char *SettingSaveDirectory; public: - MainBar(Session &session, pv::MainWindow &main_window); - - Session &session(void) const; + MainBar(Session &session, QWidget *parent, + pv::views::TraceView::View *view); void update_device_list(); @@ -93,12 +99,6 @@ public: QAction* action_save_as() const; QAction* action_save_selection_as() const; QAction* action_connect() const; - QAction* action_quit() const; - QAction* action_view_zoom_in() const; - QAction* action_view_zoom_out() const; - QAction* action_view_zoom_fit() const; - QAction* action_view_zoom_one_to_one() const; - QAction* action_view_show_cursors() const; void session_error(const QString text, const QString info_text); @@ -121,11 +121,6 @@ private: QAction *const action_save_as_; QAction *const action_save_selection_as_; QAction *const action_connect_; - QAction *const action_view_zoom_in_; - QAction *const action_view_zoom_out_; - QAction *const action_view_zoom_fit_; - QAction *const action_view_zoom_one_to_one_; - QAction *const action_view_show_cursors_; private Q_SLOTS: void show_session_error(const QString text, const QString info_text); @@ -153,26 +148,16 @@ private Q_SLOTS: void on_actionConnect_triggered(); - void on_actionViewZoomIn_triggered(); - - void on_actionViewZoomOut_triggered(); - - void on_actionViewZoomFit_triggered(); - - void on_actionViewZoomOneToOne_triggered(); - - void on_actionViewShowCursors_triggered(); - - void on_always_zoom_to_fit_changed(bool state); - protected: + void add_toolbar_widgets(); + bool eventFilter(QObject *watched, QEvent *event); Q_SIGNALS: void new_view(Session *session); private: - Session &session_; + QToolButton *open_button_, *save_button_; pv::widgets::DeviceToolButton device_selector_; @@ -190,6 +175,7 @@ private: bool sample_count_supported_; #ifdef ENABLE_DECODE + QToolButton *add_decoder_button_; QMenu *const menu_decoders_add_; #endif }; diff --git a/pv/views/trace/standardbar.cpp b/pv/views/trace/standardbar.cpp new file mode 100644 index 00000000..def3ebc5 --- /dev/null +++ b/pv/views/trace/standardbar.cpp @@ -0,0 +1,170 @@ +/* + * This file is part of the PulseView project. + * + * Copyright (C) 2016 Soeren Apel + * 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 + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include +#include + +#include "standardbar.hpp" + +#include +#include + +using pv::views::TraceView::View; + +namespace pv { +namespace views { + +namespace trace { + +StandardBar::StandardBar(Session &session, QWidget *parent, + View *view, bool add_default_widgets) : + QToolBar("Standard Trace View Toolbar", parent), + session_(session), + view_(view), + action_view_zoom_in_(new QAction(this)), + action_view_zoom_out_(new QAction(this)), + action_view_zoom_fit_(new QAction(this)), + action_view_zoom_one_to_one_(new QAction(this)), + action_view_show_cursors_(new QAction(this)) +{ + setObjectName(QString::fromUtf8("StandardBar")); + + // Actions + action_view_zoom_in_->setText(tr("Zoom &In")); + action_view_zoom_in_->setIcon(QIcon::fromTheme("zoom-in", + QIcon(":/icons/zoom-in.png"))); + // simply using Qt::Key_Plus shows no + in the menu + action_view_zoom_in_->setShortcut(QKeySequence::ZoomIn); + connect(action_view_zoom_in_, SIGNAL(triggered(bool)), + this, SLOT(on_actionViewZoomIn_triggered())); + + action_view_zoom_out_->setText(tr("Zoom &Out")); + action_view_zoom_out_->setIcon(QIcon::fromTheme("zoom-out", + QIcon(":/icons/zoom-out.png"))); + action_view_zoom_out_->setShortcut(QKeySequence::ZoomOut); + connect(action_view_zoom_out_, SIGNAL(triggered(bool)), + this, SLOT(on_actionViewZoomOut_triggered())); + + action_view_zoom_fit_->setCheckable(true); + action_view_zoom_fit_->setText(tr("Zoom to &Fit")); + action_view_zoom_fit_->setIcon(QIcon::fromTheme("zoom-fit", + QIcon(":/icons/zoom-fit.png"))); + action_view_zoom_fit_->setShortcut(QKeySequence(Qt::Key_F)); + connect(action_view_zoom_fit_, SIGNAL(triggered(bool)), + this, SLOT(on_actionViewZoomFit_triggered())); + + action_view_zoom_one_to_one_->setText(tr("Zoom to O&ne-to-One")); + action_view_zoom_one_to_one_->setIcon(QIcon::fromTheme("zoom-original", + QIcon(":/icons/zoom-original.png"))); + action_view_zoom_one_to_one_->setShortcut(QKeySequence(Qt::Key_O)); + connect(action_view_zoom_one_to_one_, SIGNAL(triggered(bool)), + this, SLOT(on_actionViewZoomOneToOne_triggered())); + + action_view_show_cursors_->setCheckable(true); + action_view_show_cursors_->setIcon(QIcon::fromTheme("show-cursors", + QIcon(":/icons/show-cursors.svg"))); + action_view_show_cursors_->setShortcut(QKeySequence(Qt::Key_C)); + connect(action_view_show_cursors_, SIGNAL(triggered(bool)), + this, SLOT(on_actionViewShowCursors_triggered())); + action_view_show_cursors_->setText(tr("Show &Cursors")); + + if (add_default_widgets) + add_toolbar_widgets(); +} + +Session &StandardBar::session(void) const +{ + return session_; +} + +void StandardBar::add_toolbar_widgets() +{ + // Setup the toolbar + addAction(action_view_zoom_in_); + addAction(action_view_zoom_out_); + addAction(action_view_zoom_fit_); + addAction(action_view_zoom_one_to_one_); + addSeparator(); + addAction(action_view_show_cursors_); +} + +QAction* StandardBar::action_view_zoom_in() const +{ + return action_view_zoom_in_; +} + +QAction* StandardBar::action_view_zoom_out() const +{ + return action_view_zoom_out_; +} + +QAction* StandardBar::action_view_zoom_fit() const +{ + return action_view_zoom_fit_; +} + +QAction* StandardBar::action_view_zoom_one_to_one() const +{ + return action_view_zoom_one_to_one_; +} + +QAction* StandardBar::action_view_show_cursors() const +{ + return action_view_show_cursors_; +} + +void StandardBar::on_actionViewZoomIn_triggered() +{ + view_->zoom(1); +} + +void StandardBar::on_actionViewZoomOut_triggered() +{ + view_->zoom(-1); +} + +void StandardBar::on_actionViewZoomFit_triggered() +{ + view_->zoom_fit(action_view_zoom_fit_->isChecked()); +} + +void StandardBar::on_actionViewZoomOneToOne_triggered() +{ + view_->zoom_one_to_one(); +} + +void StandardBar::on_actionViewShowCursors_triggered() +{ + const bool show = !view_->cursors_shown(); + if (show) + view_->centre_cursors(); + + view_->show_cursors(show); +} + +void StandardBar::on_always_zoom_to_fit_changed(bool state) +{ + action_view_zoom_fit_->setChecked(state); +} + +} // namespace trace +} // namespace views +} // namespace pv diff --git a/pv/views/trace/standardbar.hpp b/pv/views/trace/standardbar.hpp new file mode 100644 index 00000000..e41beebc --- /dev/null +++ b/pv/views/trace/standardbar.hpp @@ -0,0 +1,92 @@ +/* + * This file is part of the PulseView project. + * + * Copyright (C) 2016 Soeren Apel + * Copyright (C) 2012 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 + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef PULSEVIEW_PV_VIEWS_TRACE_STANDARDBAR_HPP +#define PULSEVIEW_PV_VIEWS_TRACE_STANDARDBAR_HPP + +#include + +#include +#include +#include + +#include + +namespace pv { + +class MainWindow; +class Session; + +namespace views { + +namespace TraceView { +class View; +} + +namespace trace { + +class StandardBar : public QToolBar +{ + Q_OBJECT + +public: + StandardBar(Session &session, QWidget *parent, + TraceView::View *view, bool add_default_widgets=true); + + Session &session(void) const; + + QAction* action_view_zoom_in() const; + QAction* action_view_zoom_out() const; + QAction* action_view_zoom_fit() const; + QAction* action_view_zoom_one_to_one() const; + QAction* action_view_show_cursors() const; + +protected: + virtual void add_toolbar_widgets(); + + Session &session_; + TraceView::View *view_; + + QAction *const action_view_zoom_in_; + QAction *const action_view_zoom_out_; + QAction *const action_view_zoom_fit_; + QAction *const action_view_zoom_one_to_one_; + QAction *const action_view_show_cursors_; + +protected Q_SLOTS: + void on_actionViewZoomIn_triggered(); + + void on_actionViewZoomOut_triggered(); + + void on_actionViewZoomFit_triggered(); + + void on_actionViewZoomOneToOne_triggered(); + + void on_actionViewShowCursors_triggered(); + + void on_always_zoom_to_fit_changed(bool state); +}; + +} // namespace trace +} // namespace views +} // namespace pv + +#endif // PULSEVIEW_PV_VIEWS_TRACE_STANDARDBAR_HPP