]> sigrok.org Git - pulseview.git/blame - pv/mainwindow.cpp
Moved Signal and LogicSignal into pv::view
[pulseview.git] / pv / mainwindow.cpp
CommitLineData
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
21extern "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
40extern "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
50namespace pv {
51
d7bed479 52MainWindow::MainWindow(QWidget *parent) :
7d5425ef 53 QMainWindow(parent)
d7bed479 54{
7d5425ef
JH
55 setup_ui();
56}
57
58void 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
e072efc8
JH
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);
76
77 _view = new pv::view::View(_session, this);
78 _vertical_layout->addWidget(_view);
79
7d5425ef
JH
80 // Setup the UI actions
81 _action_about = new QAction(this);
82 _action_about->setObjectName(QString::fromUtf8("actionAbout"));
a429590b
JH
83
84 _action_view_zoom_in = new QAction(this);
85 _action_view_zoom_in->setIcon(QIcon::fromTheme("zoom-in"));
86 _action_view_zoom_in->setObjectName(QString::fromUtf8("actionViewZoomIn"));
87
88 _action_view_zoom_out = new QAction(this);
89 _action_view_zoom_out->setIcon(QIcon::fromTheme("zoom-out"));
90 _action_view_zoom_out->setObjectName(QString::fromUtf8("actionViewZoomOut"));
91
e072efc8
JH
92 _action_view_show_cursors = new QAction(this);
93 _action_view_show_cursors->setCheckable(true);
94 _action_view_show_cursors->setChecked(_view->cursors_shown());
95 _action_view_show_cursors->setObjectName(QString::fromUtf8("actionViewShowCursors"));
96
7d5425ef 97 _action_open = new QAction(this);
0a4db787 98 _action_open->setIcon(QIcon::fromTheme("document-open"));
7d5425ef
JH
99 _action_open->setObjectName(QString::fromUtf8("actionOpen"));
100
101 // Setup the menu bar
102 _menu_bar = new QMenuBar(this);
103 _menu_bar->setGeometry(QRect(0, 0, 400, 25));
104
105 _menu_file = new QMenu(_menu_bar);
106 _menu_file->addAction(_action_open);
009e1503 107
a429590b
JH
108 _menu_view = new QMenu(_menu_bar);
109 _menu_view->addAction(_action_view_zoom_in);
110 _menu_view->addAction(_action_view_zoom_out);
e072efc8
JH
111 _menu_view->addSeparator();
112 _menu_view->addAction(_action_view_show_cursors);
a429590b 113
7d5425ef
JH
114 _menu_help = new QMenu(_menu_bar);
115 _menu_help->addAction(_action_about);
116
117 _menu_bar->addAction(_menu_file->menuAction());
a429590b 118 _menu_bar->addAction(_menu_view->menuAction());
7d5425ef
JH
119 _menu_bar->addAction(_menu_help->menuAction());
120
121 setMenuBar(_menu_bar);
122 QMetaObject::connectSlotsByName(this);
123
124 // Setup the toolbars
0a4db787
JH
125 _toolbar = new QToolBar(this);
126 _toolbar->addAction(_action_open);
a429590b
JH
127 _toolbar->addSeparator();
128 _toolbar->addAction(_action_view_zoom_in);
129 _toolbar->addAction(_action_view_zoom_out);
0a4db787
JH
130 addToolBar(_toolbar);
131
d4984fe7 132 _sampling_bar = new SamplingBar(this);
274d4f13
JH
133 connect(_sampling_bar, SIGNAL(run_stop()), this,
134 SLOT(run_stop()));
d4984fe7
JH
135 addToolBar(_sampling_bar);
136
7d5425ef
JH
137 // Setup the status bar
138 _status_bar = new QStatusBar(this);
139 setStatusBar(_status_bar);
140
a8d3fb2d
JH
141 setWindowTitle(QApplication::translate("MainWindow", "PulseView", 0,
142 QApplication::UnicodeUTF8));
143
7d5425ef 144 _action_open->setText(QApplication::translate("MainWindow", "&Open...", 0, QApplication::UnicodeUTF8));
a429590b
JH
145 _action_view_zoom_in->setText(QApplication::translate("MainWindow", "Zoom &In", 0, QApplication::UnicodeUTF8));
146 _action_view_zoom_out->setText(QApplication::translate("MainWindow", "Zoom &Out", 0, QApplication::UnicodeUTF8));
e072efc8 147 _action_view_show_cursors->setText(QApplication::translate("MainWindow", "Show &Cursors", 0, QApplication::UnicodeUTF8));
7d5425ef 148 _action_about->setText(QApplication::translate("MainWindow", "&About...", 0, QApplication::UnicodeUTF8));
a429590b 149
7d5425ef 150 _menu_file->setTitle(QApplication::translate("MainWindow", "&File", 0, QApplication::UnicodeUTF8));
a429590b 151 _menu_view->setTitle(QApplication::translate("MainWindow", "&View", 0, QApplication::UnicodeUTF8));
7d5425ef 152 _menu_help->setTitle(QApplication::translate("MainWindow", "&Help", 0, QApplication::UnicodeUTF8));
d7bed479 153}
30236a54 154
2953961c
JH
155void MainWindow::on_actionOpen_triggered()
156{
04abfae9 157 QString file_name = QFileDialog::getOpenFileName(
2953961c
JH
158 this, tr("Open File"), "",
159 tr("Sigrok Sessions (*.sr)"));
04abfae9 160 _session.load_file(file_name.toStdString());
2953961c
JH
161}
162
a429590b
JH
163void MainWindow::on_actionViewZoomIn_triggered()
164{
165 _view->zoom(1);
166}
167
168void MainWindow::on_actionViewZoomOut_triggered()
169{
170 _view->zoom(-1);
171}
172
e072efc8
JH
173void MainWindow::on_actionViewShowCursors_triggered()
174{
175 assert(_view);
176 _view->show_cursors(_action_view_show_cursors->isChecked());
177}
178
30236a54
JH
179void MainWindow::on_actionAbout_triggered()
180{
40eb2ff4
JH
181 About dlg(this);
182 dlg.exec();
30236a54 183}
274d4f13
JH
184
185void MainWindow::run_stop()
186{
04abfae9 187 _session.start_capture(
274d4f13 188 _sampling_bar->get_selected_device(),
215f9499 189 _sampling_bar->get_record_length(),
274d4f13
JH
190 _sampling_bar->get_sample_rate());
191}
51e77110
JH
192
193} // namespace pv