]> sigrok.org Git - pulseview.git/blame - mainwindow.cpp
Added initial toolbar
[pulseview.git] / mainwindow.cpp
CommitLineData
d7bed479
JH
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
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"
009e1503 38#include "sigview.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
d7bed479 50MainWindow::MainWindow(QWidget *parent) :
7d5425ef 51 QMainWindow(parent)
d7bed479 52{
7d5425ef
JH
53 setup_ui();
54}
55
56void 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 _action_open = new QAction(this);
0a4db787 72 _action_open->setIcon(QIcon::fromTheme("document-open"));
7d5425ef
JH
73 _action_open->setObjectName(QString::fromUtf8("actionOpen"));
74
75 // Setup the menu bar
76 _menu_bar = new QMenuBar(this);
77 _menu_bar->setGeometry(QRect(0, 0, 400, 25));
78
79 _menu_file = new QMenu(_menu_bar);
80 _menu_file->addAction(_action_open);
009e1503 81
7d5425ef
JH
82 _menu_help = new QMenu(_menu_bar);
83 _menu_help->addAction(_action_about);
84
85 _menu_bar->addAction(_menu_file->menuAction());
86 _menu_bar->addAction(_menu_help->menuAction());
87
88 setMenuBar(_menu_bar);
89 QMetaObject::connectSlotsByName(this);
90
91 // Setup the toolbars
0a4db787
JH
92 _toolbar = new QToolBar(this);
93 _toolbar->addAction(_action_open);
94 addToolBar(_toolbar);
95
d4984fe7 96 _sampling_bar = new SamplingBar(this);
274d4f13
JH
97 connect(_sampling_bar, SIGNAL(run_stop()), this,
98 SLOT(run_stop()));
d4984fe7
JH
99 addToolBar(_sampling_bar);
100
7d5425ef
JH
101 // Setup the central widget
102 _central_widget = new QWidget(this);
103 _vertical_layout = new QVBoxLayout(_central_widget);
104 _vertical_layout->setSpacing(6);
105 _vertical_layout->setContentsMargins(0, 0, 0, 0);
106 setCentralWidget(_central_widget);
d7bed479 107
7d5425ef
JH
108 // Setup the status bar
109 _status_bar = new QStatusBar(this);
110 setStatusBar(_status_bar);
111
112 setWindowTitle(QApplication::translate("MainWindow", "sigrok-qt2", 0, QApplication::UnicodeUTF8));
113 _action_open->setText(QApplication::translate("MainWindow", "&Open...", 0, QApplication::UnicodeUTF8));
114 _action_about->setText(QApplication::translate("MainWindow", "&About...", 0, QApplication::UnicodeUTF8));
115 _menu_file->setTitle(QApplication::translate("MainWindow", "&File", 0, QApplication::UnicodeUTF8));
116 _menu_help->setTitle(QApplication::translate("MainWindow", "&Help", 0, QApplication::UnicodeUTF8));
117
118 _view = new SigView(_session, this);
119 _vertical_layout->addWidget(_view);
d7bed479 120}
30236a54 121
2953961c
JH
122void MainWindow::on_actionOpen_triggered()
123{
04abfae9 124 QString file_name = QFileDialog::getOpenFileName(
2953961c
JH
125 this, tr("Open File"), "",
126 tr("Sigrok Sessions (*.sr)"));
04abfae9 127 _session.load_file(file_name.toStdString());
2953961c
JH
128}
129
30236a54
JH
130void MainWindow::on_actionAbout_triggered()
131{
40eb2ff4
JH
132 About dlg(this);
133 dlg.exec();
30236a54 134}
274d4f13
JH
135
136void MainWindow::run_stop()
137{
04abfae9 138 _session.start_capture(
274d4f13 139 _sampling_bar->get_selected_device(),
215f9499 140 _sampling_bar->get_record_length(),
274d4f13
JH
141 _sampling_bar->get_sample_rate());
142}