2 * This file is part of the PulseView project.
4 * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
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.
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.
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
22 #include <sigrokdecode.h>
26 #include <QApplication>
27 #include <QButtonGroup>
28 #include <QFileDialog>
32 #include <QVBoxLayout>
35 #include "mainwindow.h"
36 #include "samplingbar.h"
37 #include "dialogs/about.h"
38 #include "view/view.h"
41 /* __STDC_FORMAT_MACROS is required for PRIu64 and friends (in C++). */
42 #define __STDC_FORMAT_MACROS
47 #include <libsigrok/libsigrok.h>
52 MainWindow::MainWindow(QWidget *parent) :
58 void MainWindow::setup_ui()
60 setObjectName(QString::fromUtf8("MainWindow"));
64 // Set the window icon
66 icon.addFile(QString::fromUtf8(":/icons/sigrok-logo-notext.png"),
67 QSize(), QIcon::Normal, QIcon::Off);
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);
77 _view = new pv::view::View(_session, this);
78 _vertical_layout->addWidget(_view);
81 _menu_bar = new QMenuBar(this);
82 _menu_bar->setGeometry(QRect(0, 0, 400, 25));
85 _menu_file = new QMenu(_menu_bar);
86 _menu_file->setTitle(QApplication::translate(
87 "MainWindow", "&File", 0, QApplication::UnicodeUTF8));
89 _action_open = new QAction(this);
90 _action_open->setText(QApplication::translate(
91 "MainWindow", "&Open...", 0, QApplication::UnicodeUTF8));
92 _action_open->setIcon(QIcon::fromTheme("document-open",
93 QIcon(":/icons/document-open.png")));
94 _action_open->setObjectName(QString::fromUtf8("actionOpen"));
96 _menu_file->addAction(_action_open);
99 _menu_view = new QMenu(_menu_bar);
100 _menu_view->setTitle(QApplication::translate(
101 "MainWindow", "&View", 0, QApplication::UnicodeUTF8));
103 _action_view_zoom_in = new QAction(this);
104 _action_view_zoom_in->setText(QApplication::translate(
105 "MainWindow", "Zoom &In", 0, QApplication::UnicodeUTF8));
106 _action_view_zoom_in->setIcon(QIcon::fromTheme("zoom-in",
107 QIcon(":/icons/zoom-in.png")));
108 _action_view_zoom_in->setObjectName(
109 QString::fromUtf8("actionViewZoomIn"));
110 _menu_view->addAction(_action_view_zoom_in);
112 _action_view_zoom_out = new QAction(this);
113 _action_view_zoom_out->setText(QApplication::translate(
114 "MainWindow", "Zoom &Out", 0, QApplication::UnicodeUTF8));
115 _action_view_zoom_out->setIcon(QIcon::fromTheme("zoom-out",
116 QIcon(":/icons/zoom-out.png")));
117 _action_view_zoom_out->setObjectName(
118 QString::fromUtf8("actionViewZoomOut"));
119 _menu_view->addAction(_action_view_zoom_out);
121 _menu_view->addSeparator();
123 _action_view_show_cursors = new QAction(this);
124 _action_view_show_cursors->setCheckable(true);
125 _action_view_show_cursors->setChecked(_view->cursors_shown());
126 _action_view_show_cursors->setObjectName(
127 QString::fromUtf8("actionViewShowCursors"));
128 _action_view_show_cursors->setText(QApplication::translate(
129 "MainWindow", "Show &Cursors", 0, QApplication::UnicodeUTF8));
130 _menu_view->addAction(_action_view_show_cursors);
133 _menu_help = new QMenu(_menu_bar);
134 _menu_help->setTitle(QApplication::translate(
135 "MainWindow", "&Help", 0, QApplication::UnicodeUTF8));
137 _action_about = new QAction(this);
138 _action_about->setObjectName(QString::fromUtf8("actionAbout"));
139 _action_about->setText(QApplication::translate(
140 "MainWindow", "&About...", 0, QApplication::UnicodeUTF8));
141 _menu_help->addAction(_action_about);
143 _menu_bar->addAction(_menu_file->menuAction());
144 _menu_bar->addAction(_menu_view->menuAction());
145 _menu_bar->addAction(_menu_help->menuAction());
147 setMenuBar(_menu_bar);
148 QMetaObject::connectSlotsByName(this);
150 // Setup the toolbars
151 _toolbar = new QToolBar(this);
152 _toolbar->addAction(_action_open);
153 _toolbar->addSeparator();
154 _toolbar->addAction(_action_view_zoom_in);
155 _toolbar->addAction(_action_view_zoom_out);
156 addToolBar(_toolbar);
158 _sampling_bar = new SamplingBar(this);
159 connect(_sampling_bar, SIGNAL(run_stop()), this,
161 addToolBar(_sampling_bar);
163 setWindowTitle(QApplication::translate("MainWindow", "PulseView", 0,
164 QApplication::UnicodeUTF8));
166 // Setup _session events
167 connect(&_session, SIGNAL(capture_state_changed(int)), this,
168 SLOT(capture_state_changed(int)));
172 void MainWindow::on_actionOpen_triggered()
174 QString file_name = QFileDialog::getOpenFileName(
175 this, tr("Open File"), "",
176 tr("Sigrok Sessions (*.sr)"));
177 _session.load_file(file_name.toStdString());
180 void MainWindow::on_actionViewZoomIn_triggered()
185 void MainWindow::on_actionViewZoomOut_triggered()
190 void MainWindow::on_actionViewShowCursors_triggered()
193 _view->show_cursors(_action_view_show_cursors->isChecked());
196 void MainWindow::on_actionAbout_triggered()
198 dialogs::About dlg(this);
202 void MainWindow::run_stop()
204 switch(_session.get_capture_state()) {
205 case SigSession::Stopped:
206 _session.start_capture(
207 _sampling_bar->get_selected_device(),
208 _sampling_bar->get_record_length(),
209 _sampling_bar->get_sample_rate());
212 case SigSession::Running:
213 _session.stop_capture();
218 void MainWindow::capture_state_changed(int state)
220 _sampling_bar->set_sampling(state != SigSession::Stopped);