]> sigrok.org Git - pulseview.git/blob - pv/views/trace/standardbar.cpp
eee00b3f2f642b2d5b9c0a41e22faaf0f8492293
[pulseview.git] / pv / views / trace / standardbar.cpp
1 /*
2  * This file is part of the PulseView project.
3  *
4  * Copyright (C) 2016 Soeren Apel <soeren@apelpie.net>
5  * Copyright (C) 2012-2015 Joel Holdsworth <joel@airwebreathe.org.uk>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
20  */
21
22 #include <QAction>
23 #include <QMessageBox>
24
25 #include "standardbar.hpp"
26
27 #include <pv/mainwindow.hpp>
28 #include <pv/view/view.hpp>
29
30 using pv::views::TraceView::View;
31
32 namespace pv {
33 namespace views {
34
35 namespace trace {
36
37 StandardBar::StandardBar(Session &session, QWidget *parent,
38         View *view, bool add_default_widgets) :
39         QToolBar("Standard Trace View Toolbar", parent),
40         session_(session),
41         view_(view),
42         action_view_zoom_in_(new QAction(this)),
43         action_view_zoom_out_(new QAction(this)),
44         action_view_zoom_fit_(new QAction(this)),
45         action_view_zoom_one_to_one_(new QAction(this)),
46         action_view_show_cursors_(new QAction(this))
47 {
48         setObjectName(QString::fromUtf8("StandardBar"));
49
50         // Actions
51         action_view_zoom_in_->setText(tr("Zoom &In"));
52         action_view_zoom_in_->setIcon(QIcon::fromTheme("zoom-in",
53                 QIcon(":/icons/zoom-in.png")));
54         // simply using Qt::Key_Plus shows no + in the menu
55         action_view_zoom_in_->setShortcut(QKeySequence::ZoomIn);
56         connect(action_view_zoom_in_, SIGNAL(triggered(bool)),
57                 this, SLOT(on_actionViewZoomIn_triggered()));
58
59         action_view_zoom_out_->setText(tr("Zoom &Out"));
60         action_view_zoom_out_->setIcon(QIcon::fromTheme("zoom-out",
61                 QIcon(":/icons/zoom-out.png")));
62         action_view_zoom_out_->setShortcut(QKeySequence::ZoomOut);
63         connect(action_view_zoom_out_, SIGNAL(triggered(bool)),
64                 this, SLOT(on_actionViewZoomOut_triggered()));
65
66         action_view_zoom_fit_->setCheckable(true);
67         action_view_zoom_fit_->setText(tr("Zoom to &Fit"));
68         action_view_zoom_fit_->setIcon(QIcon::fromTheme("zoom-fit",
69                 QIcon(":/icons/zoom-fit.png")));
70         action_view_zoom_fit_->setShortcut(QKeySequence(Qt::Key_F));
71         connect(action_view_zoom_fit_, SIGNAL(triggered(bool)),
72                 this, SLOT(on_actionViewZoomFit_triggered(bool)));
73
74         action_view_zoom_one_to_one_->setText(tr("Zoom to O&ne-to-One"));
75         action_view_zoom_one_to_one_->setIcon(QIcon::fromTheme("zoom-original",
76                 QIcon(":/icons/zoom-original.png")));
77         action_view_zoom_one_to_one_->setShortcut(QKeySequence(Qt::Key_O));
78         connect(action_view_zoom_one_to_one_, SIGNAL(triggered(bool)),
79                 this, SLOT(on_actionViewZoomOneToOne_triggered()));
80
81         action_view_show_cursors_->setCheckable(true);
82         action_view_show_cursors_->setIcon(QIcon::fromTheme("show-cursors",
83                 QIcon(":/icons/show-cursors.svg")));
84         action_view_show_cursors_->setShortcut(QKeySequence(Qt::Key_C));
85         connect(action_view_show_cursors_, SIGNAL(triggered(bool)),
86                 this, SLOT(on_actionViewShowCursors_triggered()));
87         action_view_show_cursors_->setText(tr("Show &Cursors"));
88
89         connect(view_, SIGNAL(always_zoom_to_fit_changed(bool)),
90                 this, SLOT(on_always_zoom_to_fit_changed(bool)));
91
92         if (add_default_widgets)
93                 add_toolbar_widgets();
94 }
95
96 Session &StandardBar::session(void) const
97 {
98         return session_;
99 }
100
101 void StandardBar::add_toolbar_widgets()
102 {
103         // Setup the toolbar
104         addAction(action_view_zoom_in_);
105         addAction(action_view_zoom_out_);
106         addAction(action_view_zoom_fit_);
107         addAction(action_view_zoom_one_to_one_);
108         addSeparator();
109         addAction(action_view_show_cursors_);
110 }
111
112 QAction* StandardBar::action_view_zoom_in() const
113 {
114         return action_view_zoom_in_;
115 }
116
117 QAction* StandardBar::action_view_zoom_out() const
118 {
119         return action_view_zoom_out_;
120 }
121
122 QAction* StandardBar::action_view_zoom_fit() const
123 {
124         return action_view_zoom_fit_;
125 }
126
127 QAction* StandardBar::action_view_zoom_one_to_one() const
128 {
129         return action_view_zoom_one_to_one_;
130 }
131
132 QAction* StandardBar::action_view_show_cursors() const
133 {
134         return action_view_show_cursors_;
135 }
136
137 void StandardBar::on_actionViewZoomIn_triggered()
138 {
139         view_->zoom(1);
140 }
141
142 void StandardBar::on_actionViewZoomOut_triggered()
143 {
144         view_->zoom(-1);
145 }
146
147 void StandardBar::on_actionViewZoomFit_triggered(bool checked)
148 {
149         view_->zoom_fit(checked);
150 }
151
152 void StandardBar::on_actionViewZoomOneToOne_triggered()
153 {
154         view_->zoom_one_to_one();
155 }
156
157 void StandardBar::on_actionViewShowCursors_triggered()
158 {
159         const bool show = !view_->cursors_shown();
160         if (show)
161                 view_->centre_cursors();
162
163         view_->show_cursors(show);
164 }
165
166 void StandardBar::on_always_zoom_to_fit_changed(bool state)
167 {
168         action_view_zoom_fit_->setChecked(state);
169 }
170
171 } // namespace trace
172 } // namespace views
173 } // namespace pv