]> sigrok.org Git - pulseview.git/blob - pv/views/trace/standardbar.cpp
Trace View: Add doxygen comments to some classes
[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, see <http://www.gnu.org/licenses/>.
19  */
20
21 #include <QAction>
22 #include <QMessageBox>
23
24 #include "standardbar.hpp"
25 #include "view.hpp"
26
27 #include <pv/mainwindow.hpp>
28
29 using pv::views::trace::View;
30
31 namespace pv {
32 namespace views {
33
34 namespace trace {
35
36 StandardBar::StandardBar(Session &session, QWidget *parent,
37         View *view, bool add_default_widgets) :
38         QToolBar("Standard Trace View Toolbar", parent),
39         session_(session),
40         view_(view),
41         action_view_zoom_in_(new QAction(this)),
42         action_view_zoom_out_(new QAction(this)),
43         action_view_zoom_fit_(new QAction(this)),
44         action_view_zoom_one_to_one_(new QAction(this)),
45         action_view_show_cursors_(new QAction(this))
46 {
47         setObjectName(QString::fromUtf8("StandardBar"));
48
49         // Actions
50         action_view_zoom_in_->setText(tr("Zoom &In"));
51         action_view_zoom_in_->setIcon(QIcon::fromTheme("zoom-in",
52                 QIcon(":/icons/zoom-in.png")));
53         // simply using Qt::Key_Plus shows no + in the menu
54         action_view_zoom_in_->setShortcut(QKeySequence::ZoomIn);
55         connect(action_view_zoom_in_, SIGNAL(triggered(bool)),
56                 this, SLOT(on_actionViewZoomIn_triggered()));
57
58         action_view_zoom_out_->setText(tr("Zoom &Out"));
59         action_view_zoom_out_->setIcon(QIcon::fromTheme("zoom-out",
60                 QIcon(":/icons/zoom-out.png")));
61         action_view_zoom_out_->setShortcut(QKeySequence::ZoomOut);
62         connect(action_view_zoom_out_, SIGNAL(triggered(bool)),
63                 this, SLOT(on_actionViewZoomOut_triggered()));
64
65         action_view_zoom_fit_->setCheckable(true);
66         action_view_zoom_fit_->setText(tr("Zoom to &Fit"));
67         action_view_zoom_fit_->setIcon(QIcon::fromTheme("zoom-fit-best",
68                 QIcon(":/icons/zoom-fit-best.png")));
69         action_view_zoom_fit_->setShortcut(QKeySequence(Qt::Key_F));
70         connect(action_view_zoom_fit_, SIGNAL(triggered(bool)),
71                 this, SLOT(on_actionViewZoomFit_triggered(bool)));
72
73         action_view_zoom_one_to_one_->setText(tr("Zoom to O&ne-to-One"));
74         action_view_zoom_one_to_one_->setIcon(QIcon::fromTheme("zoom-original",
75                 QIcon(":/icons/zoom-original.png")));
76         action_view_zoom_one_to_one_->setShortcut(QKeySequence(Qt::Key_O));
77         connect(action_view_zoom_one_to_one_, SIGNAL(triggered(bool)),
78                 this, SLOT(on_actionViewZoomOneToOne_triggered()));
79
80         action_view_show_cursors_->setCheckable(true);
81         action_view_show_cursors_->setIcon(QIcon(":/icons/show-cursors.svg"));
82         action_view_show_cursors_->setShortcut(QKeySequence(Qt::Key_C));
83         connect(action_view_show_cursors_, SIGNAL(triggered(bool)),
84                 this, SLOT(on_actionViewShowCursors_triggered()));
85         action_view_show_cursors_->setText(tr("Show &Cursors"));
86
87         connect(view_, SIGNAL(always_zoom_to_fit_changed(bool)),
88                 this, SLOT(on_always_zoom_to_fit_changed(bool)));
89
90         if (add_default_widgets)
91                 add_toolbar_widgets();
92 }
93
94 Session &StandardBar::session() const
95 {
96         return session_;
97 }
98
99 void StandardBar::add_toolbar_widgets()
100 {
101         // Setup the toolbar
102         addAction(action_view_zoom_in_);
103         addAction(action_view_zoom_out_);
104         addAction(action_view_zoom_fit_);
105         addAction(action_view_zoom_one_to_one_);
106         addSeparator();
107         addAction(action_view_show_cursors_);
108 }
109
110 QAction* StandardBar::action_view_zoom_in() const
111 {
112         return action_view_zoom_in_;
113 }
114
115 QAction* StandardBar::action_view_zoom_out() const
116 {
117         return action_view_zoom_out_;
118 }
119
120 QAction* StandardBar::action_view_zoom_fit() const
121 {
122         return action_view_zoom_fit_;
123 }
124
125 QAction* StandardBar::action_view_zoom_one_to_one() const
126 {
127         return action_view_zoom_one_to_one_;
128 }
129
130 QAction* StandardBar::action_view_show_cursors() const
131 {
132         return action_view_show_cursors_;
133 }
134
135 void StandardBar::on_actionViewZoomIn_triggered()
136 {
137         view_->zoom(1);
138 }
139
140 void StandardBar::on_actionViewZoomOut_triggered()
141 {
142         view_->zoom(-1);
143 }
144
145 void StandardBar::on_actionViewZoomFit_triggered(bool checked)
146 {
147         view_->zoom_fit(checked);
148 }
149
150 void StandardBar::on_actionViewZoomOneToOne_triggered()
151 {
152         view_->zoom_one_to_one();
153 }
154
155 void StandardBar::on_actionViewShowCursors_triggered()
156 {
157         const bool show = !view_->cursors_shown();
158         if (show)
159                 view_->centre_cursors();
160
161         view_->show_cursors(show);
162 }
163
164 void StandardBar::on_always_zoom_to_fit_changed(bool state)
165 {
166         action_view_zoom_fit_->setChecked(state);
167 }
168
169 } // namespace trace
170 } // namespace views
171 } // namespace pv