]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * This file is part of the sigrok 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 | extern "C" { | |
22 | #include <sigrokdecode.h> | |
23 | } | |
24 | ||
25 | #include <QAction> | |
26 | #include <QApplication> | |
27 | #include <QButtonGroup> | |
28 | #include <QFileDialog> | |
29 | #include <QMenu> | |
30 | #include <QMenuBar> | |
31 | #include <QStatusBar> | |
32 | #include <QVBoxLayout> | |
33 | #include <QWidget> | |
34 | ||
35 | #include "about.h" | |
36 | #include "mainwindow.h" | |
37 | #include "samplingbar.h" | |
38 | #include "sigview.h" | |
39 | ||
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 | ||
50 | MainWindow::MainWindow(QWidget *parent) : | |
51 | QMainWindow(parent) | |
52 | { | |
53 | setup_ui(); | |
54 | } | |
55 | ||
56 | void MainWindow::setup_ui() | |
57 | { | |
58 | setObjectName(QString::fromUtf8("MainWindow")); | |
59 | ||
60 | resize(1024, 768); | |
61 | ||
62 | // Set the window icon | |
63 | QIcon icon; | |
64 | icon.addFile(QString::fromUtf8(":/icons/sigrok-logo-notext.png"), | |
65 | QSize(), QIcon::Normal, QIcon::Off); | |
66 | setWindowIcon(icon); | |
67 | ||
68 | // Setup the UI actions | |
69 | _action_about = new QAction(this); | |
70 | _action_about->setObjectName(QString::fromUtf8("actionAbout")); | |
71 | ||
72 | _action_view_zoom_in = new QAction(this); | |
73 | _action_view_zoom_in->setIcon(QIcon::fromTheme("zoom-in")); | |
74 | _action_view_zoom_in->setObjectName(QString::fromUtf8("actionViewZoomIn")); | |
75 | ||
76 | _action_view_zoom_out = new QAction(this); | |
77 | _action_view_zoom_out->setIcon(QIcon::fromTheme("zoom-out")); | |
78 | _action_view_zoom_out->setObjectName(QString::fromUtf8("actionViewZoomOut")); | |
79 | ||
80 | _action_open = new QAction(this); | |
81 | _action_open->setIcon(QIcon::fromTheme("document-open")); | |
82 | _action_open->setObjectName(QString::fromUtf8("actionOpen")); | |
83 | ||
84 | // Setup the menu bar | |
85 | _menu_bar = new QMenuBar(this); | |
86 | _menu_bar->setGeometry(QRect(0, 0, 400, 25)); | |
87 | ||
88 | _menu_file = new QMenu(_menu_bar); | |
89 | _menu_file->addAction(_action_open); | |
90 | ||
91 | _menu_view = new QMenu(_menu_bar); | |
92 | _menu_view->addAction(_action_view_zoom_in); | |
93 | _menu_view->addAction(_action_view_zoom_out); | |
94 | ||
95 | _menu_help = new QMenu(_menu_bar); | |
96 | _menu_help->addAction(_action_about); | |
97 | ||
98 | _menu_bar->addAction(_menu_file->menuAction()); | |
99 | _menu_bar->addAction(_menu_view->menuAction()); | |
100 | _menu_bar->addAction(_menu_help->menuAction()); | |
101 | ||
102 | setMenuBar(_menu_bar); | |
103 | QMetaObject::connectSlotsByName(this); | |
104 | ||
105 | // Setup the toolbars | |
106 | _toolbar = new QToolBar(this); | |
107 | _toolbar->addAction(_action_open); | |
108 | _toolbar->addSeparator(); | |
109 | _toolbar->addAction(_action_view_zoom_in); | |
110 | _toolbar->addAction(_action_view_zoom_out); | |
111 | addToolBar(_toolbar); | |
112 | ||
113 | _sampling_bar = new SamplingBar(this); | |
114 | connect(_sampling_bar, SIGNAL(run_stop()), this, | |
115 | SLOT(run_stop())); | |
116 | addToolBar(_sampling_bar); | |
117 | ||
118 | // Setup the central widget | |
119 | _central_widget = new QWidget(this); | |
120 | _vertical_layout = new QVBoxLayout(_central_widget); | |
121 | _vertical_layout->setSpacing(6); | |
122 | _vertical_layout->setContentsMargins(0, 0, 0, 0); | |
123 | setCentralWidget(_central_widget); | |
124 | ||
125 | // Setup the status bar | |
126 | _status_bar = new QStatusBar(this); | |
127 | setStatusBar(_status_bar); | |
128 | ||
129 | setWindowTitle(QApplication::translate("MainWindow", "sigrok-qt2", 0, QApplication::UnicodeUTF8)); | |
130 | _action_open->setText(QApplication::translate("MainWindow", "&Open...", 0, QApplication::UnicodeUTF8)); | |
131 | _action_view_zoom_in->setText(QApplication::translate("MainWindow", "Zoom &In", 0, QApplication::UnicodeUTF8)); | |
132 | _action_view_zoom_out->setText(QApplication::translate("MainWindow", "Zoom &Out", 0, QApplication::UnicodeUTF8)); | |
133 | _action_about->setText(QApplication::translate("MainWindow", "&About...", 0, QApplication::UnicodeUTF8)); | |
134 | ||
135 | _menu_file->setTitle(QApplication::translate("MainWindow", "&File", 0, QApplication::UnicodeUTF8)); | |
136 | _menu_view->setTitle(QApplication::translate("MainWindow", "&View", 0, QApplication::UnicodeUTF8)); | |
137 | _menu_help->setTitle(QApplication::translate("MainWindow", "&Help", 0, QApplication::UnicodeUTF8)); | |
138 | ||
139 | _view = new SigView(_session, this); | |
140 | _vertical_layout->addWidget(_view); | |
141 | } | |
142 | ||
143 | void MainWindow::on_actionOpen_triggered() | |
144 | { | |
145 | QString file_name = QFileDialog::getOpenFileName( | |
146 | this, tr("Open File"), "", | |
147 | tr("Sigrok Sessions (*.sr)")); | |
148 | _session.load_file(file_name.toStdString()); | |
149 | } | |
150 | ||
151 | void MainWindow::on_actionViewZoomIn_triggered() | |
152 | { | |
153 | _view->zoom(1); | |
154 | } | |
155 | ||
156 | void MainWindow::on_actionViewZoomOut_triggered() | |
157 | { | |
158 | _view->zoom(-1); | |
159 | } | |
160 | ||
161 | void MainWindow::on_actionAbout_triggered() | |
162 | { | |
163 | About dlg(this); | |
164 | dlg.exec(); | |
165 | } | |
166 | ||
167 | void MainWindow::run_stop() | |
168 | { | |
169 | _session.start_capture( | |
170 | _sampling_bar->get_selected_device(), | |
171 | _sampling_bar->get_record_length(), | |
172 | _sampling_bar->get_sample_rate()); | |
173 | } |