]>
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" |
9663c82b | 36 | #include "dialogs/connect.h" |
4104d7f3 | 37 | #include "view/view.h" |
d7bed479 | 38 | |
30236a54 JH |
39 | /* __STDC_FORMAT_MACROS is required for PRIu64 and friends (in C++). */ |
40 | #define __STDC_FORMAT_MACROS | |
41 | #include <inttypes.h> | |
42 | #include <stdint.h> | |
43 | #include <stdarg.h> | |
44 | #include <glib.h> | |
45 | #include <libsigrok/libsigrok.h> | |
e82fd481 | 46 | |
30236a54 | 47 | |
51e77110 JH |
48 | namespace pv { |
49 | ||
1d478458 JH |
50 | MainWindow::MainWindow(const char *open_file_name, |
51 | QWidget *parent) : | |
7d5425ef | 52 | QMainWindow(parent) |
d7bed479 | 53 | { |
7d5425ef | 54 | setup_ui(); |
1d478458 JH |
55 | if (open_file_name) { |
56 | const QString s(QString::fromUtf8(open_file_name)); | |
57 | QMetaObject::invokeMethod(this, "load_file", | |
58 | Qt::QueuedConnection, | |
59 | Q_ARG(QString, s)); | |
60 | } | |
7d5425ef JH |
61 | } |
62 | ||
63 | void MainWindow::setup_ui() | |
64 | { | |
65 | setObjectName(QString::fromUtf8("MainWindow")); | |
66 | ||
67 | resize(1024, 768); | |
68 | ||
69 | // Set the window icon | |
70 | QIcon icon; | |
71 | icon.addFile(QString::fromUtf8(":/icons/sigrok-logo-notext.png"), | |
72 | QSize(), QIcon::Normal, QIcon::Off); | |
73 | setWindowIcon(icon); | |
74 | ||
e072efc8 JH |
75 | // Setup the central widget |
76 | _central_widget = new QWidget(this); | |
77 | _vertical_layout = new QVBoxLayout(_central_widget); | |
78 | _vertical_layout->setSpacing(6); | |
79 | _vertical_layout->setContentsMargins(0, 0, 0, 0); | |
80 | setCentralWidget(_central_widget); | |
81 | ||
82 | _view = new pv::view::View(_session, this); | |
83 | _vertical_layout->addWidget(_view); | |
84 | ||
ab1d13ee JH |
85 | // Setup the menu bar |
86 | _menu_bar = new QMenuBar(this); | |
87 | _menu_bar->setGeometry(QRect(0, 0, 400, 25)); | |
a429590b | 88 | |
ab1d13ee JH |
89 | // File Menu |
90 | _menu_file = new QMenu(_menu_bar); | |
91 | _menu_file->setTitle(QApplication::translate( | |
92 | "MainWindow", "&File", 0, QApplication::UnicodeUTF8)); | |
e072efc8 | 93 | |
7d5425ef | 94 | _action_open = new QAction(this); |
ab1d13ee JH |
95 | _action_open->setText(QApplication::translate( |
96 | "MainWindow", "&Open...", 0, QApplication::UnicodeUTF8)); | |
362eea96 JH |
97 | _action_open->setIcon(QIcon::fromTheme("document-open", |
98 | QIcon(":/icons/document-open.png"))); | |
7d5425ef | 99 | _action_open->setObjectName(QString::fromUtf8("actionOpen")); |
7d5425ef | 100 | _menu_file->addAction(_action_open); |
009e1503 | 101 | |
2a032dcb JH |
102 | _menu_file->addSeparator(); |
103 | ||
9663c82b JH |
104 | _action_connect = new QAction(this); |
105 | _action_connect->setText(QApplication::translate( | |
106 | "MainWindow", "&Connect to Device...", 0, | |
107 | QApplication::UnicodeUTF8)); | |
108 | _action_connect->setObjectName(QString::fromUtf8("actionConnect")); | |
109 | _menu_file->addAction(_action_connect); | |
110 | ||
111 | _menu_file->addSeparator(); | |
112 | ||
2a032dcb JH |
113 | _action_quit = new QAction(this); |
114 | _action_quit->setText(QApplication::translate( | |
115 | "MainWindow", "&Quit", 0, QApplication::UnicodeUTF8)); | |
116 | _action_quit->setIcon(QIcon::fromTheme("application-exit", | |
117 | QIcon(":/icons/application-exit.png"))); | |
118 | _action_quit->setObjectName(QString::fromUtf8("actionQuit")); | |
119 | _menu_file->addAction(_action_quit); | |
120 | ||
ab1d13ee | 121 | // View Menu |
a429590b | 122 | _menu_view = new QMenu(_menu_bar); |
ab1d13ee JH |
123 | _menu_view->setTitle(QApplication::translate( |
124 | "MainWindow", "&View", 0, QApplication::UnicodeUTF8)); | |
125 | ||
126 | _action_view_zoom_in = new QAction(this); | |
127 | _action_view_zoom_in->setText(QApplication::translate( | |
128 | "MainWindow", "Zoom &In", 0, QApplication::UnicodeUTF8)); | |
129 | _action_view_zoom_in->setIcon(QIcon::fromTheme("zoom-in", | |
130 | QIcon(":/icons/zoom-in.png"))); | |
131 | _action_view_zoom_in->setObjectName( | |
132 | QString::fromUtf8("actionViewZoomIn")); | |
a429590b | 133 | _menu_view->addAction(_action_view_zoom_in); |
ab1d13ee JH |
134 | |
135 | _action_view_zoom_out = new QAction(this); | |
136 | _action_view_zoom_out->setText(QApplication::translate( | |
137 | "MainWindow", "Zoom &Out", 0, QApplication::UnicodeUTF8)); | |
138 | _action_view_zoom_out->setIcon(QIcon::fromTheme("zoom-out", | |
139 | QIcon(":/icons/zoom-out.png"))); | |
140 | _action_view_zoom_out->setObjectName( | |
141 | QString::fromUtf8("actionViewZoomOut")); | |
a429590b | 142 | _menu_view->addAction(_action_view_zoom_out); |
ab1d13ee | 143 | |
e072efc8 | 144 | _menu_view->addSeparator(); |
ab1d13ee JH |
145 | |
146 | _action_view_show_cursors = new QAction(this); | |
147 | _action_view_show_cursors->setCheckable(true); | |
148 | _action_view_show_cursors->setChecked(_view->cursors_shown()); | |
149 | _action_view_show_cursors->setObjectName( | |
150 | QString::fromUtf8("actionViewShowCursors")); | |
151 | _action_view_show_cursors->setText(QApplication::translate( | |
152 | "MainWindow", "Show &Cursors", 0, QApplication::UnicodeUTF8)); | |
e072efc8 | 153 | _menu_view->addAction(_action_view_show_cursors); |
a429590b | 154 | |
ab1d13ee | 155 | // Help Menu |
7d5425ef | 156 | _menu_help = new QMenu(_menu_bar); |
ab1d13ee JH |
157 | _menu_help->setTitle(QApplication::translate( |
158 | "MainWindow", "&Help", 0, QApplication::UnicodeUTF8)); | |
159 | ||
160 | _action_about = new QAction(this); | |
161 | _action_about->setObjectName(QString::fromUtf8("actionAbout")); | |
162 | _action_about->setText(QApplication::translate( | |
163 | "MainWindow", "&About...", 0, QApplication::UnicodeUTF8)); | |
7d5425ef JH |
164 | _menu_help->addAction(_action_about); |
165 | ||
166 | _menu_bar->addAction(_menu_file->menuAction()); | |
a429590b | 167 | _menu_bar->addAction(_menu_view->menuAction()); |
7d5425ef JH |
168 | _menu_bar->addAction(_menu_help->menuAction()); |
169 | ||
170 | setMenuBar(_menu_bar); | |
171 | QMetaObject::connectSlotsByName(this); | |
172 | ||
173 | // Setup the toolbars | |
0a4db787 JH |
174 | _toolbar = new QToolBar(this); |
175 | _toolbar->addAction(_action_open); | |
a429590b JH |
176 | _toolbar->addSeparator(); |
177 | _toolbar->addAction(_action_view_zoom_in); | |
178 | _toolbar->addAction(_action_view_zoom_out); | |
0a4db787 JH |
179 | addToolBar(_toolbar); |
180 | ||
d4984fe7 | 181 | _sampling_bar = new SamplingBar(this); |
18203d86 | 182 | scan_devices(); |
274d4f13 JH |
183 | connect(_sampling_bar, SIGNAL(run_stop()), this, |
184 | SLOT(run_stop())); | |
d4984fe7 JH |
185 | addToolBar(_sampling_bar); |
186 | ||
a8d3fb2d JH |
187 | setWindowTitle(QApplication::translate("MainWindow", "PulseView", 0, |
188 | QApplication::UnicodeUTF8)); | |
189 | ||
6ac96c2e JH |
190 | // Setup _session events |
191 | connect(&_session, SIGNAL(capture_state_changed(int)), this, | |
192 | SLOT(capture_state_changed(int))); | |
193 | ||
d7bed479 | 194 | } |
30236a54 | 195 | |
18203d86 JH |
196 | void MainWindow::scan_devices() |
197 | { | |
198 | _devices.clear(); | |
199 | ||
200 | /* Scan all drivers for all devices. */ | |
201 | struct sr_dev_driver **const drivers = sr_driver_list(); | |
202 | for (struct sr_dev_driver **driver = drivers; *driver; driver++) { | |
203 | GSList *const devices = sr_driver_scan(*driver, NULL); | |
204 | for (GSList *l = devices; l; l = l->next) | |
205 | _devices.push_back((sr_dev_inst*)l->data); | |
206 | g_slist_free(devices); | |
207 | } | |
208 | ||
209 | assert(_sampling_bar); | |
210 | _sampling_bar->set_device_list(_devices); | |
211 | } | |
212 | ||
1d478458 JH |
213 | void MainWindow::load_file(QString file_name) |
214 | { | |
215 | _session.load_file(file_name.toStdString()); | |
216 | } | |
217 | ||
2953961c JH |
218 | void MainWindow::on_actionOpen_triggered() |
219 | { | |
1d478458 | 220 | const QString file_name = QFileDialog::getOpenFileName( |
2953961c JH |
221 | this, tr("Open File"), "", |
222 | tr("Sigrok Sessions (*.sr)")); | |
1d478458 | 223 | load_file(file_name); |
2953961c JH |
224 | } |
225 | ||
9663c82b JH |
226 | void MainWindow::on_actionConnect_triggered() |
227 | { | |
228 | dialogs::Connect dlg(this); | |
229 | dlg.exec(); | |
230 | } | |
231 | ||
2a032dcb JH |
232 | void MainWindow::on_actionQuit_triggered() |
233 | { | |
234 | close(); | |
235 | } | |
236 | ||
a429590b JH |
237 | void MainWindow::on_actionViewZoomIn_triggered() |
238 | { | |
239 | _view->zoom(1); | |
240 | } | |
241 | ||
242 | void MainWindow::on_actionViewZoomOut_triggered() | |
243 | { | |
244 | _view->zoom(-1); | |
245 | } | |
246 | ||
e072efc8 JH |
247 | void MainWindow::on_actionViewShowCursors_triggered() |
248 | { | |
249 | assert(_view); | |
250 | _view->show_cursors(_action_view_show_cursors->isChecked()); | |
251 | } | |
252 | ||
30236a54 JH |
253 | void MainWindow::on_actionAbout_triggered() |
254 | { | |
acda14b8 | 255 | dialogs::About dlg(this); |
40eb2ff4 | 256 | dlg.exec(); |
30236a54 | 257 | } |
274d4f13 JH |
258 | |
259 | void MainWindow::run_stop() | |
260 | { | |
5b7cf66c JH |
261 | switch(_session.get_capture_state()) { |
262 | case SigSession::Stopped: | |
263 | _session.start_capture( | |
264 | _sampling_bar->get_selected_device(), | |
6745ffbb | 265 | _sampling_bar->get_record_length()); |
5b7cf66c JH |
266 | break; |
267 | ||
268 | case SigSession::Running: | |
269 | _session.stop_capture(); | |
270 | break; | |
271 | } | |
274d4f13 | 272 | } |
51e77110 | 273 | |
6ac96c2e JH |
274 | void MainWindow::capture_state_changed(int state) |
275 | { | |
276 | _sampling_bar->set_sampling(state != SigSession::Stopped); | |
277 | } | |
278 | ||
51e77110 | 279 | } // namespace pv |