]> sigrok.org Git - pulseview.git/blame_incremental - pv/mainwindow.hpp
Implement MainWindow::add_view()
[pulseview.git] / pv / mainwindow.hpp
... / ...
CommitLineData
1/*
2 * This file is part of the PulseView 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#ifndef PULSEVIEW_PV_MAINWINDOW_HPP
22#define PULSEVIEW_PV_MAINWINDOW_HPP
23
24#include <list>
25#include <map>
26#include <memory>
27
28#include <glibmm/variant.h>
29
30#include <QMainWindow>
31
32#include "session.hpp"
33#include "view/viewwidget.hpp"
34
35struct srd_decoder;
36
37class QVBoxLayout;
38
39namespace sigrok {
40class InputFormat;
41class OutputFormat;
42}
43
44namespace pv {
45
46class DeviceManager;
47
48namespace toolbars {
49class ContextBar;
50class MainBar;
51}
52
53namespace view {
54class View;
55}
56
57namespace widgets {
58#ifdef ENABLE_DECODE
59class DecoderMenu;
60#endif
61}
62
63class MainWindow : public QMainWindow
64{
65 Q_OBJECT
66
67private:
68 /**
69 * Name of the setting used to remember the directory
70 * containing the last file that was opened.
71 */
72 static const char *SettingOpenDirectory;
73
74 /**
75 * Name of the setting used to remember the directory
76 * containing the last file that was saved.
77 */
78 static const char *SettingSaveDirectory;
79
80public:
81 explicit MainWindow(DeviceManager &device_manager,
82 std::string open_file_name = std::string(),
83 std::string open_file_format = std::string(),
84 QWidget *parent = 0);
85
86 QAction* action_open() const;
87 QAction* action_save_as() const;
88 QAction* action_save_selection_as() const;
89 QAction* action_connect() const;
90 QAction* action_quit() const;
91 QAction* action_view_zoom_in() const;
92 QAction* action_view_zoom_out() const;
93 QAction* action_view_zoom_fit() const;
94 QAction* action_view_zoom_one_to_one() const;
95 QAction* action_view_sticky_scrolling() const;
96 QAction* action_view_coloured_bg() const;
97 QAction* action_view_show_cursors() const;
98 QAction* action_about() const;
99
100#ifdef ENABLE_DECODE
101 QMenu* menu_decoder_add() const;
102#endif
103
104 std::shared_ptr<pv::view::View> get_active_view() const;
105
106 std::shared_ptr<pv::view::View> add_view(const QString &title,
107 view::ViewType type, Session &session);
108
109 void run_stop();
110
111 void select_device(std::shared_ptr<devices::Device> device);
112
113public Q_SLOTS:
114 void export_file(std::shared_ptr<sigrok::OutputFormat> format,
115 bool selection_only = false);
116 void import_file(std::shared_ptr<sigrok::InputFormat> format);
117
118private:
119 void setup_ui();
120
121 void select_init_device();
122
123 void load_init_file(const std::string &file_name,
124 const std::string &format);
125
126 void save_ui_settings();
127
128 void restore_ui_settings();
129
130 void session_error(const QString text, const QString info_text);
131
132 /**
133 * Updates the device list in the toolbar
134 */
135 void update_device_list();
136
137 void load_file(QString file_name,
138 std::shared_ptr<sigrok::InputFormat> format = nullptr,
139 const std::map<std::string, Glib::VariantBase> &options =
140 std::map<std::string, Glib::VariantBase>());
141
142 void save_selection_to_file();
143
144private:
145 void closeEvent(QCloseEvent *event);
146
147 void keyReleaseEvent(QKeyEvent *event);
148
149private Q_SLOTS:
150 void show_session_error(
151 const QString text, const QString info_text);
152
153 void on_actionOpen_triggered();
154 void on_actionSaveAs_triggered();
155 void on_actionSaveSelectionAs_triggered();
156 void on_actionQuit_triggered();
157
158 void on_actionConnect_triggered();
159
160 void on_actionViewZoomIn_triggered();
161
162 void on_actionViewZoomOut_triggered();
163
164 void on_actionViewZoomFit_triggered();
165
166 void on_actionViewZoomOneToOne_triggered();
167
168 void on_actionViewStickyScrolling_triggered();
169
170 void on_actionViewColouredBg_triggered();
171
172 void on_actionViewShowCursors_triggered();
173
174 void on_actionAbout_triggered();
175
176 void add_decoder(srd_decoder *decoder);
177
178 void capture_state_changed(int state);
179 void device_selected();
180
181 void sticky_scrolling_changed(bool state);
182
183 void always_zoom_to_fit_changed(bool state);
184
185private:
186 DeviceManager &device_manager_;
187
188 Session session_;
189
190 std::map< std::shared_ptr<QDockWidget>,
191 std::shared_ptr<pv::view::View> > view_docks_;
192
193 toolbars::MainBar *main_bar_;
194
195 QAction *const action_open_;
196 QAction *const action_save_as_;
197 QAction *const action_save_selection_as_;
198 QAction *const action_connect_;
199 QAction *const action_quit_;
200 QAction *const action_view_zoom_in_;
201 QAction *const action_view_zoom_out_;
202 QAction *const action_view_zoom_fit_;
203 QAction *const action_view_zoom_one_to_one_;
204 QAction *const action_view_sticky_scrolling_;
205 QAction *const action_view_coloured_bg_;
206 QAction *const action_view_show_cursors_;
207 QAction *const action_about_;
208
209#ifdef ENABLE_DECODE
210 QMenu *const menu_decoders_add_;
211#endif
212};
213
214} // namespace pv
215
216#endif // PULSEVIEW_PV_MAINWINDOW_HPP