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