WSL/SLF GitLab Repository

MainWindow.h 5.93 KB
Newer Older
Mathias Bavay's avatar
Mathias Bavay committed
1
//SPDX-License-Identifier: GPL-3.0-or-later
2
3
4
5
6
/*****************************************************************************/
/*  Copyright 2019 WSL Institute for Snow and Avalanche Research  SLF-DAVOS  */
/*****************************************************************************/
/* This file is part of INIshell.
   INIshell 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
9
10
11
12
13
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.

   INIshell is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
   GNU General Public License for more details.
15

16
17
   You should have received a copy of the GNU General Public License
   along with INIshell.  If not, see <http://www.gnu.org/licenses/>.
18
19
20
21
22
*/

/*
 * The main program window.
 * Every widget that has this as ancestor will be destroyed when the application quits.
23
 * 2019-10
24
25
26
27
28
 */

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

29
30
31
32
33
34
35
#include <src/gui/Logger.h>
#include <src/gui/HelpWindow.h>
#include <src/gui/MainPanel.h>
#include <src/gui/PreviewWindow.h>
#include <src/gui/SettingsWindow.h>
#include <src/main/constants.h>
#include <src/main/INIParser.h>
36

37
#include <QAction>
38
#include <QCheckBox>
39
#include <QCommandLineParser>
40
#include <QKeyEvent>
41
42
#include <QIcon>
#include <QLabel>
43
#include <QList>
44
#include <QMainWindow>
45
#include <QString>
46
#include <QTabBar>
47
#include <QTimer>
48
#include <QtXml>
49
#include <QWidgetList>
50

51
class MouseEventFilter : public QObject { //handles all mouse clicks in the main window
52
53
54
55
	public:
		bool eventFilter(QObject *object, QEvent *event) override;
};

56
57
58
59
class MainWindow : public QMainWindow {
	Q_OBJECT //Qt macro to make code g++ ready

	public:
60
		explicit MainWindow(QString &settings_location, const QStringList &errors,
61
		    QMainWindow *parent = nullptr);
62
		~MainWindow() override;
63
		MainWindow(const MainWindow&) = delete; //we have non-Qt pointers, but copying does not make sense anyway
64
65
66
		MainWindow& operator =(MainWindow const&) = delete;
		MainWindow(MainWindow&&) = delete;
		MainWindow& operator=(MainWindow&&) = delete;
Mathias Bavay's avatar
Mathias Bavay committed
67
		
68
		MainPanel * getControlPanel() const { return control_panel_; }
69
		QList<Atomic *> getPanelsForKey(const QString &ini_key);
70
		void setStatus(const QString &message, const QString &color = "normal", const bool &status_light = false,
71
			const int &time_msec = -1);
72
		void setStatusLight(const bool &on);
Michael Reisecker's avatar
Michael Reisecker committed
73
		void refreshStatus();
74
		void log(const QString &message, const QString &color = "normal") { logger_.log(message, color); }
Mathias Bavay's avatar
Mathias Bavay committed
75
		void setIni(const INIParser &ini_in) {ini_ = ini_in;}
76
		INIParser * getIni() { return &ini_; }
77
		INIParser getIniCopy() { return ini_; }
78
		void openIni(const QString &path, const bool &is_autoopen = false, const bool &fresh = true);
79
		bool setGuiFromIni(INIParser &ini);
80
		void resetAppearance(const bool &restart = false);
81
		void openXml(const QString &path, const QString &app_name, const bool &fresh = true);
82
		QString getCurrentApplication() const noexcept { return current_application_; }
83
		QString getCurrentApplicationPath() const noexcept { return current_path_; }
84
		QString getXmlSettingsFilename() const noexcept { return xml_settings_filename_; }
85
		Logger * getLogger() noexcept { return &logger_; }
86

87
88
89
	public slots:
		void viewLogger();

90
91
92
	protected:
		void closeEvent(QCloseEvent* event) override;

93
94
	private:
		void createMenu();
95
96
97
#ifdef DEBUG
		void createDebugMenu();
#endif
98
		void createToolbar();
99
		void createStatusbar();
100
		void sizeAllWindows();
101
102
		QWidgetList findPanel(QWidget *parent, const Section &section, const KeyValue &keyval);
		QWidgetList findSimplePanel(QWidget *parent, const Section &section, const KeyValue &keyval);
103
		bool saveIni(const QString &filename = QString());
104
		void saveIniAs();
105
		void openIni();
106
		bool closeIni();
107
		void clearGui(const bool &set_default = true);
108
		void setWindowSizeSettings();
109
		void setSplitterSizeSettings();
110
		void createToolbarContextMenu();
111

112
		QToolBar *toolbar_ = nullptr; //toolbar items
113
		QAction *toolbar_open_ini_ = nullptr;
114
115
		QAction *toolbar_clear_gui_ = nullptr;
		QAction *toolbar_save_ini_ = nullptr;
116
		QAction *toolbar_save_ini_as_ = nullptr;
117
		QAction *toolbar_preview_ = nullptr;
118
119
120
		QAction *file_open_ini_ = nullptr; //menu items
		QAction *file_save_ini_ = nullptr;
		QAction *file_save_ini_as_ = nullptr;
121
		QAction *gui_reset_ = nullptr;
122
		QAction *gui_close_all_ = nullptr;
123
		QAction *gui_clear_ = nullptr;
124
		QAction *view_preview_ = nullptr;
125
		QMenu toolbar_context_menu_;
126

127
		MainPanel *control_panel_ = nullptr;
128
		PreviewWindow *preview_ = nullptr;
Michael Reisecker's avatar
Michael Reisecker committed
129
		HelpWindow *help_window_ = nullptr;
130
		SettingsWindow *settings_window_ = nullptr;
131
		Logger logger_;
132
		INIParser ini_;
133
		QString xml_settings_filename_; //OS-specifc path to the settings file
134
135
		QLabel *status_label_ = nullptr;
		QLabel *status_icon_ = nullptr;
136
		QTimer *status_timer_ = nullptr;
137
		QLabel *ini_filename_ = nullptr;
138
139
		QCheckBox *autoload_box_ = nullptr;
		QAction *autoload_ = nullptr;
140
		QString current_application_; //name of currently loaded XML
141
		QString current_path_; //path to currently loaded XML
142

143
144
		MouseEventFilter *mouse_events_toolbar_ = nullptr;
		MouseEventFilter *mouse_events_statusbar_ = nullptr;
145

146
147
	public slots:
		void viewPreview(); //can be called from the Logger
148
		void loadHelp(const QString &tab_name = QString(),
Michael Reisecker's avatar
Michael Reisecker committed
149
			const QString &frame_name = QString(), const bool &dev = false);
150
		void helpAbout();
151

152
	private slots:
153
		void clearStatus();
154
		void quitProgram();
155
		void resetGui();
156
		void viewSettings();
157
		void toggleWorkflow();
158
		void toolbarClick(const QString &function);
159
		void onAutoloadCheck(const int &state);
160
		void onToolbarContextMenuRequest(const QPoint &pos);
161
		void writeGuiFromIniHeader(bool &first_error_message, const INIParser &ini);
Michael Reisecker's avatar
Michael Reisecker committed
162
#ifdef DEBUG
163
		void debugRunClick();
Michael Reisecker's avatar
Michael Reisecker committed
164
#endif //def DEBUG
165

166
	friend class MouseEventFilter; //mouse clicks may access everything
167
168
169
};

#endif //MAINWINDOW_H