]> sigrok.org Git - pulseview.git/blob - pv/mainwindow.hpp
Confirm with user also when trying to close the session's main dock
[pulseview.git] / pv / mainwindow.hpp
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, see <http://www.gnu.org/licenses/>.
18  */
19
20 #ifndef PULSEVIEW_PV_MAINWINDOW_HPP
21 #define PULSEVIEW_PV_MAINWINDOW_HPP
22
23 #include <list>
24 #include <map>
25 #include <memory>
26
27 #include <QMainWindow>
28 #include <QSignalMapper>
29 #include <QToolButton>
30 #include <QTabWidget>
31
32 #include "session.hpp"
33 #include "views/viewbase.hpp"
34
35 struct srd_decoder;
36
37 class QVBoxLayout;
38
39 namespace pv {
40
41 class DeviceManager;
42
43 namespace toolbars {
44 class ContextBar;
45 class MainBar;
46 }
47
48 namespace view {
49 class View;
50 }
51
52 namespace widgets {
53 #ifdef ENABLE_DECODE
54 class DecoderMenu;
55 #endif
56 }
57
58 class MainWindow : public QMainWindow
59 {
60         Q_OBJECT
61
62 private:
63         static const QString WindowTitle;
64
65 public:
66         explicit MainWindow(DeviceManager &device_manager,
67                 std::string open_file_name = std::string(),
68                 std::string open_file_format = std::string(),
69                 QWidget *parent = 0);
70
71         ~MainWindow();
72
73         QAction* action_view_sticky_scrolling() const;
74         QAction* action_view_coloured_bg() const;
75         QAction* action_about() const;
76
77         std::shared_ptr<views::ViewBase> get_active_view() const;
78
79         std::shared_ptr<views::ViewBase> add_view(const QString &title,
80                 views::ViewType type, Session &session);
81
82         void remove_view(std::shared_ptr<views::ViewBase> view);
83
84         std::shared_ptr<Session> add_session();
85
86         void remove_session(std::shared_ptr<Session> session);
87
88 private:
89         void setup_ui();
90
91         void save_ui_settings();
92
93         void restore_ui_settings();
94
95         std::shared_ptr<Session> get_tab_session(int index) const;
96
97         void closeEvent(QCloseEvent *event);
98
99         virtual QMenu* createPopupMenu();
100
101         virtual bool restoreState(const QByteArray &state, int version = 0);
102
103         void session_error(const QString text, const QString info_text);
104
105 private Q_SLOTS:
106         void show_session_error(const QString text, const QString info_text);
107
108         void on_add_view(const QString &title, views::ViewType type,
109                 Session *session);
110
111         void on_focus_changed();
112         void on_focused_session_changed(std::shared_ptr<Session> session);
113
114         void on_new_session_clicked();
115         void on_run_stop_clicked();
116
117         void on_session_name_changed();
118         void on_capture_state_changed(QObject *obj);
119
120         void on_new_view(Session *session);
121         void on_view_close_clicked();
122
123         void on_tab_changed(int index);
124         void on_tab_close_requested(int index);
125
126         void on_actionViewStickyScrolling_triggered();
127
128         void on_actionViewColouredBg_triggered();
129
130         void on_actionAbout_triggered();
131
132 private:
133         DeviceManager &device_manager_;
134
135         std::list< std::shared_ptr<Session> > sessions_;
136         std::shared_ptr<Session> last_focused_session_;
137
138         std::map< QDockWidget*, std::shared_ptr<views::ViewBase> > view_docks_;
139
140         std::map< std::shared_ptr<Session>, QMainWindow*> session_windows_;
141
142         QWidget *static_tab_widget_;
143         QToolButton *new_session_button_, *run_stop_button_, *settings_button_;
144         QTabWidget session_selector_;
145         QSignalMapper session_state_mapper_;
146
147         QAction *const action_view_sticky_scrolling_;
148         QAction *const action_view_coloured_bg_;
149         QAction *const action_about_;
150
151         QIcon icon_red_;
152         QIcon icon_green_;
153         QIcon icon_grey_;
154 };
155
156 } // namespace pv
157
158 #endif // PULSEVIEW_PV_MAINWINDOW_HPP