]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * This file is part of the PulseView project. | |
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 | ||
21 | #include <sigrokdecode.h> | |
22 | ||
23 | #include <QAction> | |
24 | #include <QApplication> | |
25 | #include <QButtonGroup> | |
26 | #include <QFileDialog> | |
27 | #include <QMenu> | |
28 | #include <QMenuBar> | |
29 | #include <QStatusBar> | |
30 | #include <QVBoxLayout> | |
31 | #include <QWidget> | |
32 | ||
33 | #include "mainwindow.h" | |
34 | #include "samplingbar.h" | |
35 | #include "dialogs/about.h" | |
36 | #include "view/view.h" | |
37 | ||
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> | |
45 | ||
46 | ||
47 | namespace pv { | |
48 | ||
49 | MainWindow::MainWindow(QWidget *parent) : | |
50 | QMainWindow(parent) | |
51 | { | |
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 | ||
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 | ||
77 | // Setup the menu bar | |
78 | _menu_bar = new QMenuBar(this); | |
79 | _menu_bar->setGeometry(QRect(0, 0, 400, 25)); | |
80 | ||
81 | // File Menu | |
82 | _menu_file = new QMenu(_menu_bar); | |
83 | _menu_file->setTitle(QApplication::translate( | |
84 | "MainWindow", "&File", 0, QApplication::UnicodeUTF8)); | |
85 | ||
86 | _action_open = new QAction(this); | |
87 | _action_open->setText(QApplication::translate( | |
88 | "MainWindow", "&Open...", 0, QApplication::UnicodeUTF8)); | |
89 | _action_open->setIcon(QIcon::fromTheme("document-open", | |
90 | QIcon(":/icons/document-open.png"))); | |
91 | _action_open->setObjectName(QString::fromUtf8("actionOpen")); | |
92 | _menu_file->addAction(_action_open); | |
93 | ||
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 | ||
104 | // View Menu | |
105 | _menu_view = new QMenu(_menu_bar); | |
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")); | |
116 | _menu_view->addAction(_action_view_zoom_in); | |
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")); | |
125 | _menu_view->addAction(_action_view_zoom_out); | |
126 | ||
127 | _menu_view->addSeparator(); | |
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)); | |
136 | _menu_view->addAction(_action_view_show_cursors); | |
137 | ||
138 | // Help Menu | |
139 | _menu_help = new QMenu(_menu_bar); | |
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)); | |
147 | _menu_help->addAction(_action_about); | |
148 | ||
149 | _menu_bar->addAction(_menu_file->menuAction()); | |
150 | _menu_bar->addAction(_menu_view->menuAction()); | |
151 | _menu_bar->addAction(_menu_help->menuAction()); | |
152 | ||
153 | setMenuBar(_menu_bar); | |
154 | QMetaObject::connectSlotsByName(this); | |
155 | ||
156 | // Setup the toolbars | |
157 | _toolbar = new QToolBar(this); | |
158 | _toolbar->addAction(_action_open); | |
159 | _toolbar->addSeparator(); | |
160 | _toolbar->addAction(_action_view_zoom_in); | |
161 | _toolbar->addAction(_action_view_zoom_out); | |
162 | addToolBar(_toolbar); | |
163 | ||
164 | _sampling_bar = new SamplingBar(this); | |
165 | connect(_sampling_bar, SIGNAL(run_stop()), this, | |
166 | SLOT(run_stop())); | |
167 | addToolBar(_sampling_bar); | |
168 | ||
169 | setWindowTitle(QApplication::translate("MainWindow", "PulseView", 0, | |
170 | QApplication::UnicodeUTF8)); | |
171 | ||
172 | // Setup _session events | |
173 | connect(&_session, SIGNAL(capture_state_changed(int)), this, | |
174 | SLOT(capture_state_changed(int))); | |
175 | ||
176 | } | |
177 | ||
178 | void MainWindow::on_actionOpen_triggered() | |
179 | { | |
180 | QString file_name = QFileDialog::getOpenFileName( | |
181 | this, tr("Open File"), "", | |
182 | tr("Sigrok Sessions (*.sr)")); | |
183 | _session.load_file(file_name.toStdString()); | |
184 | } | |
185 | ||
186 | void MainWindow::on_actionQuit_triggered() | |
187 | { | |
188 | close(); | |
189 | } | |
190 | ||
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 | ||
201 | void MainWindow::on_actionViewShowCursors_triggered() | |
202 | { | |
203 | assert(_view); | |
204 | _view->show_cursors(_action_view_show_cursors->isChecked()); | |
205 | } | |
206 | ||
207 | void MainWindow::on_actionAbout_triggered() | |
208 | { | |
209 | dialogs::About dlg(this); | |
210 | dlg.exec(); | |
211 | } | |
212 | ||
213 | void MainWindow::run_stop() | |
214 | { | |
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 | } | |
227 | } | |
228 | ||
229 | void MainWindow::capture_state_changed(int state) | |
230 | { | |
231 | _sampling_bar->set_sampling(state != SigSession::Stopped); | |
232 | } | |
233 | ||
234 | } // namespace pv |