]>
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 | |
40eb2ff4 | 35 | #include "about.h" |
d7bed479 | 36 | #include "mainwindow.h" |
d4984fe7 | 37 | #include "samplingbar.h" |
cdf7bea7 | 38 | #include "pv/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 | ||
70 | // Setup the UI actions | |
71 | _action_about = new QAction(this); | |
72 | _action_about->setObjectName(QString::fromUtf8("actionAbout")); | |
a429590b JH |
73 | |
74 | _action_view_zoom_in = new QAction(this); | |
75 | _action_view_zoom_in->setIcon(QIcon::fromTheme("zoom-in")); | |
76 | _action_view_zoom_in->setObjectName(QString::fromUtf8("actionViewZoomIn")); | |
77 | ||
78 | _action_view_zoom_out = new QAction(this); | |
79 | _action_view_zoom_out->setIcon(QIcon::fromTheme("zoom-out")); | |
80 | _action_view_zoom_out->setObjectName(QString::fromUtf8("actionViewZoomOut")); | |
81 | ||
7d5425ef | 82 | _action_open = new QAction(this); |
0a4db787 | 83 | _action_open->setIcon(QIcon::fromTheme("document-open")); |
7d5425ef JH |
84 | _action_open->setObjectName(QString::fromUtf8("actionOpen")); |
85 | ||
86 | // Setup the menu bar | |
87 | _menu_bar = new QMenuBar(this); | |
88 | _menu_bar->setGeometry(QRect(0, 0, 400, 25)); | |
89 | ||
90 | _menu_file = new QMenu(_menu_bar); | |
91 | _menu_file->addAction(_action_open); | |
009e1503 | 92 | |
a429590b JH |
93 | _menu_view = new QMenu(_menu_bar); |
94 | _menu_view->addAction(_action_view_zoom_in); | |
95 | _menu_view->addAction(_action_view_zoom_out); | |
96 | ||
7d5425ef JH |
97 | _menu_help = new QMenu(_menu_bar); |
98 | _menu_help->addAction(_action_about); | |
99 | ||
100 | _menu_bar->addAction(_menu_file->menuAction()); | |
a429590b | 101 | _menu_bar->addAction(_menu_view->menuAction()); |
7d5425ef JH |
102 | _menu_bar->addAction(_menu_help->menuAction()); |
103 | ||
104 | setMenuBar(_menu_bar); | |
105 | QMetaObject::connectSlotsByName(this); | |
106 | ||
107 | // Setup the toolbars | |
0a4db787 JH |
108 | _toolbar = new QToolBar(this); |
109 | _toolbar->addAction(_action_open); | |
a429590b JH |
110 | _toolbar->addSeparator(); |
111 | _toolbar->addAction(_action_view_zoom_in); | |
112 | _toolbar->addAction(_action_view_zoom_out); | |
0a4db787 JH |
113 | addToolBar(_toolbar); |
114 | ||
d4984fe7 | 115 | _sampling_bar = new SamplingBar(this); |
274d4f13 JH |
116 | connect(_sampling_bar, SIGNAL(run_stop()), this, |
117 | SLOT(run_stop())); | |
d4984fe7 JH |
118 | addToolBar(_sampling_bar); |
119 | ||
7d5425ef JH |
120 | // Setup the central widget |
121 | _central_widget = new QWidget(this); | |
122 | _vertical_layout = new QVBoxLayout(_central_widget); | |
123 | _vertical_layout->setSpacing(6); | |
124 | _vertical_layout->setContentsMargins(0, 0, 0, 0); | |
125 | setCentralWidget(_central_widget); | |
d7bed479 | 126 | |
7d5425ef JH |
127 | // Setup the status bar |
128 | _status_bar = new QStatusBar(this); | |
129 | setStatusBar(_status_bar); | |
130 | ||
a8d3fb2d JH |
131 | setWindowTitle(QApplication::translate("MainWindow", "PulseView", 0, |
132 | QApplication::UnicodeUTF8)); | |
133 | ||
7d5425ef | 134 | _action_open->setText(QApplication::translate("MainWindow", "&Open...", 0, QApplication::UnicodeUTF8)); |
a429590b JH |
135 | _action_view_zoom_in->setText(QApplication::translate("MainWindow", "Zoom &In", 0, QApplication::UnicodeUTF8)); |
136 | _action_view_zoom_out->setText(QApplication::translate("MainWindow", "Zoom &Out", 0, QApplication::UnicodeUTF8)); | |
7d5425ef | 137 | _action_about->setText(QApplication::translate("MainWindow", "&About...", 0, QApplication::UnicodeUTF8)); |
a429590b | 138 | |
7d5425ef | 139 | _menu_file->setTitle(QApplication::translate("MainWindow", "&File", 0, QApplication::UnicodeUTF8)); |
a429590b | 140 | _menu_view->setTitle(QApplication::translate("MainWindow", "&View", 0, QApplication::UnicodeUTF8)); |
7d5425ef JH |
141 | _menu_help->setTitle(QApplication::translate("MainWindow", "&Help", 0, QApplication::UnicodeUTF8)); |
142 | ||
cdf7bea7 | 143 | _view = new pv::view::View(_session, this); |
7d5425ef | 144 | _vertical_layout->addWidget(_view); |
d7bed479 | 145 | } |
30236a54 | 146 | |
2953961c JH |
147 | void MainWindow::on_actionOpen_triggered() |
148 | { | |
04abfae9 | 149 | QString file_name = QFileDialog::getOpenFileName( |
2953961c JH |
150 | this, tr("Open File"), "", |
151 | tr("Sigrok Sessions (*.sr)")); | |
04abfae9 | 152 | _session.load_file(file_name.toStdString()); |
2953961c JH |
153 | } |
154 | ||
a429590b JH |
155 | void MainWindow::on_actionViewZoomIn_triggered() |
156 | { | |
157 | _view->zoom(1); | |
158 | } | |
159 | ||
160 | void MainWindow::on_actionViewZoomOut_triggered() | |
161 | { | |
162 | _view->zoom(-1); | |
163 | } | |
164 | ||
30236a54 JH |
165 | void MainWindow::on_actionAbout_triggered() |
166 | { | |
40eb2ff4 JH |
167 | About dlg(this); |
168 | dlg.exec(); | |
30236a54 | 169 | } |
274d4f13 JH |
170 | |
171 | void MainWindow::run_stop() | |
172 | { | |
04abfae9 | 173 | _session.start_capture( |
274d4f13 | 174 | _sampling_bar->get_selected_device(), |
215f9499 | 175 | _sampling_bar->get_record_length(), |
274d4f13 JH |
176 | _sampling_bar->get_sample_rate()); |
177 | } | |
51e77110 JH |
178 | |
179 | } // namespace pv |