]>
Commit | Line | Data |
---|---|---|
d7bed479 | 1 | /* |
b3f22de0 | 2 | * This file is part of the PulseView project. |
d7bed479 JH |
3 | * |
4 | * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk> | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License as published by | |
8 | * the Free Software Foundation; either version 2 of the License, or | |
9 | * (at your option) any later version. | |
10 | * | |
11 | * This program is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | * GNU General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License | |
17 | * along with this program; if not, write to the Free Software | |
18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
19 | */ | |
20 | ||
30236a54 | 21 | #include <sigrokdecode.h> |
30236a54 | 22 | |
7d5425ef JH |
23 | #include <QAction> |
24 | #include <QApplication> | |
25 | #include <QButtonGroup> | |
2953961c | 26 | #include <QFileDialog> |
7d5425ef JH |
27 | #include <QMenu> |
28 | #include <QMenuBar> | |
29 | #include <QStatusBar> | |
30 | #include <QVBoxLayout> | |
31 | #include <QWidget> | |
2953961c | 32 | |
d7bed479 | 33 | #include "mainwindow.h" |
d4984fe7 | 34 | #include "samplingbar.h" |
acda14b8 | 35 | #include "dialogs/about.h" |
4104d7f3 | 36 | #include "view/view.h" |
d7bed479 | 37 | |
30236a54 JH |
38 | /* __STDC_FORMAT_MACROS is required for PRIu64 and friends (in C++). */ |
39 | #define __STDC_FORMAT_MACROS | |
40 | #include <inttypes.h> | |
41 | #include <stdint.h> | |
42 | #include <stdarg.h> | |
43 | #include <glib.h> | |
44 | #include <libsigrok/libsigrok.h> | |
e82fd481 | 45 | |
30236a54 | 46 | |
51e77110 JH |
47 | namespace pv { |
48 | ||
d7bed479 | 49 | MainWindow::MainWindow(QWidget *parent) : |
7d5425ef | 50 | QMainWindow(parent) |
d7bed479 | 51 | { |
7d5425ef JH |
52 | setup_ui(); |
53 | } | |
54 | ||
55 | void MainWindow::setup_ui() | |
56 | { | |
57 | setObjectName(QString::fromUtf8("MainWindow")); | |
58 | ||
59 | resize(1024, 768); | |
60 | ||
61 | // Set the window icon | |
62 | QIcon icon; | |
63 | icon.addFile(QString::fromUtf8(":/icons/sigrok-logo-notext.png"), | |
64 | QSize(), QIcon::Normal, QIcon::Off); | |
65 | setWindowIcon(icon); | |
66 | ||
e072efc8 JH |
67 | // Setup the central widget |
68 | _central_widget = new QWidget(this); | |
69 | _vertical_layout = new QVBoxLayout(_central_widget); | |
70 | _vertical_layout->setSpacing(6); | |
71 | _vertical_layout->setContentsMargins(0, 0, 0, 0); | |
72 | setCentralWidget(_central_widget); | |
73 | ||
74 | _view = new pv::view::View(_session, this); | |
75 | _vertical_layout->addWidget(_view); | |
76 | ||
ab1d13ee JH |
77 | // Setup the menu bar |
78 | _menu_bar = new QMenuBar(this); | |
79 | _menu_bar->setGeometry(QRect(0, 0, 400, 25)); | |
a429590b | 80 | |
ab1d13ee JH |
81 | // File Menu |
82 | _menu_file = new QMenu(_menu_bar); | |
83 | _menu_file->setTitle(QApplication::translate( | |
84 | "MainWindow", "&File", 0, QApplication::UnicodeUTF8)); | |
e072efc8 | 85 | |
7d5425ef | 86 | _action_open = new QAction(this); |
ab1d13ee JH |
87 | _action_open->setText(QApplication::translate( |
88 | "MainWindow", "&Open...", 0, QApplication::UnicodeUTF8)); | |
362eea96 JH |
89 | _action_open->setIcon(QIcon::fromTheme("document-open", |
90 | QIcon(":/icons/document-open.png"))); | |
7d5425ef | 91 | _action_open->setObjectName(QString::fromUtf8("actionOpen")); |
7d5425ef | 92 | _menu_file->addAction(_action_open); |
009e1503 | 93 | |
2a032dcb JH |
94 | _menu_file->addSeparator(); |
95 | ||
96 | _action_quit = new QAction(this); | |
97 | _action_quit->setText(QApplication::translate( | |
98 | "MainWindow", "&Quit", 0, QApplication::UnicodeUTF8)); | |
99 | _action_quit->setIcon(QIcon::fromTheme("application-exit", | |
100 | QIcon(":/icons/application-exit.png"))); | |
101 | _action_quit->setObjectName(QString::fromUtf8("actionQuit")); | |
102 | _menu_file->addAction(_action_quit); | |
103 | ||
ab1d13ee | 104 | // View Menu |
a429590b | 105 | _menu_view = new QMenu(_menu_bar); |
ab1d13ee JH |
106 | _menu_view->setTitle(QApplication::translate( |
107 | "MainWindow", "&View", 0, QApplication::UnicodeUTF8)); | |
108 | ||
109 | _action_view_zoom_in = new QAction(this); | |
110 | _action_view_zoom_in->setText(QApplication::translate( | |
111 | "MainWindow", "Zoom &In", 0, QApplication::UnicodeUTF8)); | |
112 | _action_view_zoom_in->setIcon(QIcon::fromTheme("zoom-in", | |
113 | QIcon(":/icons/zoom-in.png"))); | |
114 | _action_view_zoom_in->setObjectName( | |
115 | QString::fromUtf8("actionViewZoomIn")); | |
a429590b | 116 | _menu_view->addAction(_action_view_zoom_in); |
ab1d13ee JH |
117 | |
118 | _action_view_zoom_out = new QAction(this); | |
119 | _action_view_zoom_out->setText(QApplication::translate( | |
120 | "MainWindow", "Zoom &Out", 0, QApplication::UnicodeUTF8)); | |
121 | _action_view_zoom_out->setIcon(QIcon::fromTheme("zoom-out", | |
122 | QIcon(":/icons/zoom-out.png"))); | |
123 | _action_view_zoom_out->setObjectName( | |
124 | QString::fromUtf8("actionViewZoomOut")); | |
a429590b | 125 | _menu_view->addAction(_action_view_zoom_out); |
ab1d13ee | 126 | |
e072efc8 | 127 | _menu_view->addSeparator(); |
ab1d13ee JH |
128 | |
129 | _action_view_show_cursors = new QAction(this); | |
130 | _action_view_show_cursors->setCheckable(true); | |
131 | _action_view_show_cursors->setChecked(_view->cursors_shown()); | |
132 | _action_view_show_cursors->setObjectName( | |
133 | QString::fromUtf8("actionViewShowCursors")); | |
134 | _action_view_show_cursors->setText(QApplication::translate( | |
135 | "MainWindow", "Show &Cursors", 0, QApplication::UnicodeUTF8)); | |
e072efc8 | 136 | _menu_view->addAction(_action_view_show_cursors); |
a429590b | 137 | |
ab1d13ee | 138 | // Help Menu |
7d5425ef | 139 | _menu_help = new QMenu(_menu_bar); |
ab1d13ee JH |
140 | _menu_help->setTitle(QApplication::translate( |
141 | "MainWindow", "&Help", 0, QApplication::UnicodeUTF8)); | |
142 | ||
143 | _action_about = new QAction(this); | |
144 | _action_about->setObjectName(QString::fromUtf8("actionAbout")); | |
145 | _action_about->setText(QApplication::translate( | |
146 | "MainWindow", "&About...", 0, QApplication::UnicodeUTF8)); | |
7d5425ef JH |
147 | _menu_help->addAction(_action_about); |
148 | ||
149 | _menu_bar->addAction(_menu_file->menuAction()); | |
a429590b | 150 | _menu_bar->addAction(_menu_view->menuAction()); |
7d5425ef JH |
151 | _menu_bar->addAction(_menu_help->menuAction()); |
152 | ||
153 | setMenuBar(_menu_bar); | |
154 | QMetaObject::connectSlotsByName(this); | |
155 | ||
156 | // Setup the toolbars | |
0a4db787 JH |
157 | _toolbar = new QToolBar(this); |
158 | _toolbar->addAction(_action_open); | |
a429590b JH |
159 | _toolbar->addSeparator(); |
160 | _toolbar->addAction(_action_view_zoom_in); | |
161 | _toolbar->addAction(_action_view_zoom_out); | |
0a4db787 JH |
162 | addToolBar(_toolbar); |
163 | ||
d4984fe7 | 164 | _sampling_bar = new SamplingBar(this); |
274d4f13 JH |
165 | connect(_sampling_bar, SIGNAL(run_stop()), this, |
166 | SLOT(run_stop())); | |
d4984fe7 JH |
167 | addToolBar(_sampling_bar); |
168 | ||
a8d3fb2d JH |
169 | setWindowTitle(QApplication::translate("MainWindow", "PulseView", 0, |
170 | QApplication::UnicodeUTF8)); | |
171 | ||
6ac96c2e JH |
172 | // Setup _session events |
173 | connect(&_session, SIGNAL(capture_state_changed(int)), this, | |
174 | SLOT(capture_state_changed(int))); | |
175 | ||
d7bed479 | 176 | } |
30236a54 | 177 | |
2953961c JH |
178 | void MainWindow::on_actionOpen_triggered() |
179 | { | |
04abfae9 | 180 | QString file_name = QFileDialog::getOpenFileName( |
2953961c JH |
181 | this, tr("Open File"), "", |
182 | tr("Sigrok Sessions (*.sr)")); | |
04abfae9 | 183 | _session.load_file(file_name.toStdString()); |
2953961c JH |
184 | } |
185 | ||
2a032dcb JH |
186 | void MainWindow::on_actionQuit_triggered() |
187 | { | |
188 | close(); | |
189 | } | |
190 | ||
a429590b JH |
191 | void MainWindow::on_actionViewZoomIn_triggered() |
192 | { | |
193 | _view->zoom(1); | |
194 | } | |
195 | ||
196 | void MainWindow::on_actionViewZoomOut_triggered() | |
197 | { | |
198 | _view->zoom(-1); | |
199 | } | |
200 | ||
e072efc8 JH |
201 | void MainWindow::on_actionViewShowCursors_triggered() |
202 | { | |
203 | assert(_view); | |
204 | _view->show_cursors(_action_view_show_cursors->isChecked()); | |
205 | } | |
206 | ||
30236a54 JH |
207 | void MainWindow::on_actionAbout_triggered() |
208 | { | |
acda14b8 | 209 | dialogs::About dlg(this); |
40eb2ff4 | 210 | dlg.exec(); |
30236a54 | 211 | } |
274d4f13 JH |
212 | |
213 | void MainWindow::run_stop() | |
214 | { | |
5b7cf66c JH |
215 | switch(_session.get_capture_state()) { |
216 | case SigSession::Stopped: | |
217 | _session.start_capture( | |
218 | _sampling_bar->get_selected_device(), | |
219 | _sampling_bar->get_record_length(), | |
220 | _sampling_bar->get_sample_rate()); | |
221 | break; | |
222 | ||
223 | case SigSession::Running: | |
224 | _session.stop_capture(); | |
225 | break; | |
226 | } | |
274d4f13 | 227 | } |
51e77110 | 228 | |
6ac96c2e JH |
229 | void MainWindow::capture_state_changed(int state) |
230 | { | |
231 | _sampling_bar->set_sampling(state != SigSession::Stopped); | |
232 | } | |
233 | ||
51e77110 | 234 | } // namespace pv |