]>
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 JH |
21 | extern "C" { |
22 | #include <sigrokdecode.h> | |
23 | } | |
24 | ||
7d5425ef JH |
25 | #include <QAction> |
26 | #include <QApplication> | |
27 | #include <QButtonGroup> | |
2953961c | 28 | #include <QFileDialog> |
7d5425ef JH |
29 | #include <QMenu> |
30 | #include <QMenuBar> | |
31 | #include <QStatusBar> | |
32 | #include <QVBoxLayout> | |
33 | #include <QWidget> | |
2953961c | 34 | |
d7bed479 | 35 | #include "mainwindow.h" |
d4984fe7 | 36 | #include "samplingbar.h" |
acda14b8 | 37 | #include "dialogs/about.h" |
4104d7f3 | 38 | #include "view/view.h" |
d7bed479 | 39 | |
30236a54 JH |
40 | extern "C" { |
41 | /* __STDC_FORMAT_MACROS is required for PRIu64 and friends (in C++). */ | |
42 | #define __STDC_FORMAT_MACROS | |
43 | #include <inttypes.h> | |
44 | #include <stdint.h> | |
45 | #include <stdarg.h> | |
46 | #include <glib.h> | |
47 | #include <libsigrok/libsigrok.h> | |
48 | } | |
49 | ||
51e77110 JH |
50 | namespace pv { |
51 | ||
d7bed479 | 52 | MainWindow::MainWindow(QWidget *parent) : |
7d5425ef | 53 | QMainWindow(parent) |
d7bed479 | 54 | { |
7d5425ef JH |
55 | setup_ui(); |
56 | } | |
57 | ||
58 | void MainWindow::setup_ui() | |
59 | { | |
60 | setObjectName(QString::fromUtf8("MainWindow")); | |
61 | ||
62 | resize(1024, 768); | |
63 | ||
64 | // Set the window icon | |
65 | QIcon icon; | |
66 | icon.addFile(QString::fromUtf8(":/icons/sigrok-logo-notext.png"), | |
67 | QSize(), QIcon::Normal, QIcon::Off); | |
68 | setWindowIcon(icon); | |
69 | ||
e072efc8 JH |
70 | // Setup the central widget |
71 | _central_widget = new QWidget(this); | |
72 | _vertical_layout = new QVBoxLayout(_central_widget); | |
73 | _vertical_layout->setSpacing(6); | |
74 | _vertical_layout->setContentsMargins(0, 0, 0, 0); | |
75 | setCentralWidget(_central_widget); | |
76 | ||
77 | _view = new pv::view::View(_session, this); | |
78 | _vertical_layout->addWidget(_view); | |
79 | ||
ab1d13ee JH |
80 | // Setup the menu bar |
81 | _menu_bar = new QMenuBar(this); | |
82 | _menu_bar->setGeometry(QRect(0, 0, 400, 25)); | |
a429590b | 83 | |
ab1d13ee JH |
84 | // File Menu |
85 | _menu_file = new QMenu(_menu_bar); | |
86 | _menu_file->setTitle(QApplication::translate( | |
87 | "MainWindow", "&File", 0, QApplication::UnicodeUTF8)); | |
e072efc8 | 88 | |
7d5425ef | 89 | _action_open = new QAction(this); |
ab1d13ee JH |
90 | _action_open->setText(QApplication::translate( |
91 | "MainWindow", "&Open...", 0, QApplication::UnicodeUTF8)); | |
362eea96 JH |
92 | _action_open->setIcon(QIcon::fromTheme("document-open", |
93 | QIcon(":/icons/document-open.png"))); | |
7d5425ef | 94 | _action_open->setObjectName(QString::fromUtf8("actionOpen")); |
7d5425ef | 95 | _menu_file->addAction(_action_open); |
009e1503 | 96 | |
2a032dcb JH |
97 | _menu_file->addSeparator(); |
98 | ||
99 | _action_quit = new QAction(this); | |
100 | _action_quit->setText(QApplication::translate( | |
101 | "MainWindow", "&Quit", 0, QApplication::UnicodeUTF8)); | |
102 | _action_quit->setIcon(QIcon::fromTheme("application-exit", | |
103 | QIcon(":/icons/application-exit.png"))); | |
104 | _action_quit->setObjectName(QString::fromUtf8("actionQuit")); | |
105 | _menu_file->addAction(_action_quit); | |
106 | ||
ab1d13ee | 107 | // View Menu |
a429590b | 108 | _menu_view = new QMenu(_menu_bar); |
ab1d13ee JH |
109 | _menu_view->setTitle(QApplication::translate( |
110 | "MainWindow", "&View", 0, QApplication::UnicodeUTF8)); | |
111 | ||
112 | _action_view_zoom_in = new QAction(this); | |
113 | _action_view_zoom_in->setText(QApplication::translate( | |
114 | "MainWindow", "Zoom &In", 0, QApplication::UnicodeUTF8)); | |
115 | _action_view_zoom_in->setIcon(QIcon::fromTheme("zoom-in", | |
116 | QIcon(":/icons/zoom-in.png"))); | |
117 | _action_view_zoom_in->setObjectName( | |
118 | QString::fromUtf8("actionViewZoomIn")); | |
a429590b | 119 | _menu_view->addAction(_action_view_zoom_in); |
ab1d13ee JH |
120 | |
121 | _action_view_zoom_out = new QAction(this); | |
122 | _action_view_zoom_out->setText(QApplication::translate( | |
123 | "MainWindow", "Zoom &Out", 0, QApplication::UnicodeUTF8)); | |
124 | _action_view_zoom_out->setIcon(QIcon::fromTheme("zoom-out", | |
125 | QIcon(":/icons/zoom-out.png"))); | |
126 | _action_view_zoom_out->setObjectName( | |
127 | QString::fromUtf8("actionViewZoomOut")); | |
a429590b | 128 | _menu_view->addAction(_action_view_zoom_out); |
ab1d13ee | 129 | |
e072efc8 | 130 | _menu_view->addSeparator(); |
ab1d13ee JH |
131 | |
132 | _action_view_show_cursors = new QAction(this); | |
133 | _action_view_show_cursors->setCheckable(true); | |
134 | _action_view_show_cursors->setChecked(_view->cursors_shown()); | |
135 | _action_view_show_cursors->setObjectName( | |
136 | QString::fromUtf8("actionViewShowCursors")); | |
137 | _action_view_show_cursors->setText(QApplication::translate( | |
138 | "MainWindow", "Show &Cursors", 0, QApplication::UnicodeUTF8)); | |
e072efc8 | 139 | _menu_view->addAction(_action_view_show_cursors); |
a429590b | 140 | |
ab1d13ee | 141 | // Help Menu |
7d5425ef | 142 | _menu_help = new QMenu(_menu_bar); |
ab1d13ee JH |
143 | _menu_help->setTitle(QApplication::translate( |
144 | "MainWindow", "&Help", 0, QApplication::UnicodeUTF8)); | |
145 | ||
146 | _action_about = new QAction(this); | |
147 | _action_about->setObjectName(QString::fromUtf8("actionAbout")); | |
148 | _action_about->setText(QApplication::translate( | |
149 | "MainWindow", "&About...", 0, QApplication::UnicodeUTF8)); | |
7d5425ef JH |
150 | _menu_help->addAction(_action_about); |
151 | ||
152 | _menu_bar->addAction(_menu_file->menuAction()); | |
a429590b | 153 | _menu_bar->addAction(_menu_view->menuAction()); |
7d5425ef JH |
154 | _menu_bar->addAction(_menu_help->menuAction()); |
155 | ||
156 | setMenuBar(_menu_bar); | |
157 | QMetaObject::connectSlotsByName(this); | |
158 | ||
159 | // Setup the toolbars | |
0a4db787 JH |
160 | _toolbar = new QToolBar(this); |
161 | _toolbar->addAction(_action_open); | |
a429590b JH |
162 | _toolbar->addSeparator(); |
163 | _toolbar->addAction(_action_view_zoom_in); | |
164 | _toolbar->addAction(_action_view_zoom_out); | |
0a4db787 JH |
165 | addToolBar(_toolbar); |
166 | ||
d4984fe7 | 167 | _sampling_bar = new SamplingBar(this); |
274d4f13 JH |
168 | connect(_sampling_bar, SIGNAL(run_stop()), this, |
169 | SLOT(run_stop())); | |
d4984fe7 JH |
170 | addToolBar(_sampling_bar); |
171 | ||
a8d3fb2d JH |
172 | setWindowTitle(QApplication::translate("MainWindow", "PulseView", 0, |
173 | QApplication::UnicodeUTF8)); | |
174 | ||
6ac96c2e JH |
175 | // Setup _session events |
176 | connect(&_session, SIGNAL(capture_state_changed(int)), this, | |
177 | SLOT(capture_state_changed(int))); | |
178 | ||
d7bed479 | 179 | } |
30236a54 | 180 | |
2953961c JH |
181 | void MainWindow::on_actionOpen_triggered() |
182 | { | |
04abfae9 | 183 | QString file_name = QFileDialog::getOpenFileName( |
2953961c JH |
184 | this, tr("Open File"), "", |
185 | tr("Sigrok Sessions (*.sr)")); | |
04abfae9 | 186 | _session.load_file(file_name.toStdString()); |
2953961c JH |
187 | } |
188 | ||
2a032dcb JH |
189 | void MainWindow::on_actionQuit_triggered() |
190 | { | |
191 | close(); | |
192 | } | |
193 | ||
a429590b JH |
194 | void MainWindow::on_actionViewZoomIn_triggered() |
195 | { | |
196 | _view->zoom(1); | |
197 | } | |
198 | ||
199 | void MainWindow::on_actionViewZoomOut_triggered() | |
200 | { | |
201 | _view->zoom(-1); | |
202 | } | |
203 | ||
e072efc8 JH |
204 | void MainWindow::on_actionViewShowCursors_triggered() |
205 | { | |
206 | assert(_view); | |
207 | _view->show_cursors(_action_view_show_cursors->isChecked()); | |
208 | } | |
209 | ||
30236a54 JH |
210 | void MainWindow::on_actionAbout_triggered() |
211 | { | |
acda14b8 | 212 | dialogs::About dlg(this); |
40eb2ff4 | 213 | dlg.exec(); |
30236a54 | 214 | } |
274d4f13 JH |
215 | |
216 | void MainWindow::run_stop() | |
217 | { | |
5b7cf66c JH |
218 | switch(_session.get_capture_state()) { |
219 | case SigSession::Stopped: | |
220 | _session.start_capture( | |
221 | _sampling_bar->get_selected_device(), | |
222 | _sampling_bar->get_record_length(), | |
223 | _sampling_bar->get_sample_rate()); | |
224 | break; | |
225 | ||
226 | case SigSession::Running: | |
227 | _session.stop_capture(); | |
228 | break; | |
229 | } | |
274d4f13 | 230 | } |
51e77110 | 231 | |
6ac96c2e JH |
232 | void MainWindow::capture_state_changed(int state) |
233 | { | |
234 | _sampling_bar->set_sampling(state != SigSession::Stopped); | |
235 | } | |
236 | ||
51e77110 | 237 | } // namespace pv |