MainWindow.h 5.51 KB
Newer Older
1
2
3
4
5
6
7
8
/****************************************************************************
 *
 *   (c) 2009-2016 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/
9
10
11
12
13
14
15
16
17
18
19


/**
 * @file
 *   @brief Definition of class MainWindow
 *   @author Lorenz Meier <mavteam@student.ethz.ch>
 *
 */

#ifndef _MAINWINDOW_H_
#define _MAINWINDOW_H_
dogmaphobic's avatar
dogmaphobic committed
20

Don Gagne's avatar
Don Gagne committed
21
22
23
24
#ifdef __mobile__
#error Should not be include in mobile build
#endif

25
#include <QMainWindow>
26
27
28
#include <QStatusBar>
#include <QStackedWidget>
#include <QSettings>
Don Gagne's avatar
Don Gagne committed
29
#include <QList>
30
31
32
33
34
35
36
37

#include "LinkManager.h"
#include "LinkInterface.h"
#include "UASInterface.h"
#include "LogCompressor.h"
#include "QGCMAVLinkInspector.h"
#include "QGCMAVLinkLogPlayer.h"
#include "MAVLinkDecoder.h"
38
#include "Vehicle.h"
Don Gagne's avatar
Don Gagne committed
39
#include "QGCDockWidget.h"
40
41
42
#include "QGCQmlWidgetHolder.h"

#include "ui_MainWindow.h"
Don Gagne's avatar
Don Gagne committed
43
44
45
46
47

#if (defined QGC_MOUSE_ENABLED_WIN) | (defined QGC_MOUSE_ENABLED_LINUX)
    #include "Mouse6dofInput.h"
#endif // QGC_MOUSE_ENABLED_WIN

48
class QGCStatusBar;
49
class Linecharts;
50
51
52
53
54
55
56
57
58
59

/**
 * @brief Main Application Window
 *
 **/
class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
Don Gagne's avatar
Don Gagne committed
60
61
62
    /// @brief Returns the MainWindow singleton. Will not create the MainWindow if it has not already
    ///         been created.
    static MainWindow* instance(void);
63

Don Gagne's avatar
Don Gagne committed
64
65
    /// @brief Deletes the MainWindow singleton
    void deleteInstance(void);
66

Don Gagne's avatar
Don Gagne committed
67
    /// @brief Creates the MainWindow singleton. Should only be called once by QGCApplication.
Lorenz Meier's avatar
Lorenz Meier committed
68
    static MainWindow* _create();
69

70
71
    ~MainWindow();

72

73
    /** @brief Get low power mode setting */
74
    bool lowPowerModeEnabled() const
75
    {
dogmaphobic's avatar
dogmaphobic committed
76
        return _lowPowerMode;
77
78
    }

79
80
81
    /// @brief Saves the last used connection
    void saveLastUsedConnection(const QString connection);

82
    // Called from MainWindow.qml when the user accepts the window close dialog
83
    Q_INVOKABLE void reallyClose(void);
84

Don Gagne's avatar
Don Gagne committed
85
86
87
    /// @return Root qml object of main window QML
    QObject* rootQmlObject(void);

88
89
public slots:
    /** @brief Save power by reducing update rates */
dogmaphobic's avatar
dogmaphobic committed
90
    void enableLowPowerMode(bool enabled) { _lowPowerMode = enabled; }
91
92
93
94
95
96

    void closeEvent(QCloseEvent* event);

    /** @brief Update the window name */
    void configureWindowName();

97
protected slots:
98
99
100
101
    /**
     * @brief Enable/Disable Status Bar
     */
    void showStatusBarCallback(bool checked);
102

103
signals:
104
    void initStatusChanged(const QString& message, int alignment, const QColor &color);
John Tapsell's avatar
John Tapsell committed
105
106
107
    /** Emitted when any value changes from any source */
    void valueChanged(const int uasId, const QString& name, const QString& unit, const QVariant& value, const quint64 msec);

108
109
110
    // Used for unit tests to know when the main window closes
    void mainWindowClosed(void);

Don Gagne's avatar
Don Gagne committed
111
#ifdef QGC_MOUSE_ENABLED_LINUX
112
113
    /** @brief Forward X11Event to catch 3DMouse inputs */
    void x11EventOccured(XEvent *event);
Don Gagne's avatar
Don Gagne committed
114
#endif //QGC_MOUSE_ENABLED_LINUX
115
116
117
118
119
120

public:
    QGCMAVLinkLogPlayer* getLogPlayer()
    {
        return logPlayer;
    }
Don Gagne's avatar
Don Gagne committed
121

122
123
124
125
126
127
128
129
130
131
protected:
    void connectCommonActions();

    void loadSettings();
    void storeSettings();

    QSettings settings;

    QPointer<MAVLinkDecoder> mavlinkDecoder;
    QGCMAVLinkLogPlayer* logPlayer;
Don Gagne's avatar
Don Gagne committed
132
#ifdef QGC_MOUSE_ENABLED_WIN
133
    /** @brief 3d Mouse support (WIN only) */
134
135
    Mouse3DInput* mouseInput;               ///< 3dConnexion 3dMouse SDK
    Mouse6dofInput* mouse;                  ///< Implementation for 3dMouse input
Don Gagne's avatar
Don Gagne committed
136
#endif // QGC_MOUSE_ENABLED_WIN
137

Don Gagne's avatar
Don Gagne committed
138
#ifdef QGC_MOUSE_ENABLED_LINUX
139
140
141
    /** @brief Reimplementation of X11Event to handle 3dMouse Events (magellan) */
    bool x11Event(XEvent *event);
    Mouse6dofInput* mouse;                  ///< Implementation for 3dMouse input
Don Gagne's avatar
Don Gagne committed
142
#endif // QGC_MOUSE_ENABLED_LINUX
143

144
145
146
147
148
149
150
151
152
153
154
155
    /** User interface actions **/
    QAction* connectUASAct;
    QAction* disconnectUASAct;
    QAction* startUASAct;
    QAction* returnUASAct;
    QAction* stopUASAct;
    QAction* killUASAct;


    LogCompressor* comp;
    QTimer* videoTimer;
    QTimer windowNameUpdateTimer;
156

Don Gagne's avatar
Don Gagne committed
157
private slots:
158
    void _closeWindow(void) { close(); }
159
160
    void _vehicleAdded(Vehicle* vehicle);
    void _showDockWidgetAction(bool show);
161
    void _showAdvancedUIChanged(bool advanced);
162

163
164
165
#ifdef UNITTEST_BUILD
    void _showQmlTestWidget(void);
#endif
166

167
private:
Don Gagne's avatar
Don Gagne committed
168
    /// Constructor is private since all creation should be through MainWindow::_create
Lorenz Meier's avatar
Lorenz Meier committed
169
    MainWindow();
170

Don Gagne's avatar
Don Gagne committed
171
    void _openUrl(const QString& url, const QString& errorMessage);
172

Don Gagne's avatar
Don Gagne committed
173
174
    QMap<QString, QGCDockWidget*>   _mapName2DockWidget;
    QMap<QString, QAction*>         _mapName2Action;
175

176
177
    void _storeCurrentViewState(void);
    void _loadCurrentViewState(void);
dogmaphobic's avatar
dogmaphobic committed
178
    bool _createInnerDockWidget(const QString& widgetName);
179
180
181
    void _buildCommonWidgets(void);
    void _hideAllDockWidgets(void);
    void _showDockWidget(const QString &name, bool show);
Don Gagne's avatar
Don Gagne committed
182
183
    void _loadVisibleWidgetsSettings(void);
    void _storeVisibleWidgetsSettings(void);
184

dogmaphobic's avatar
dogmaphobic committed
185
    bool                    _lowPowerMode;           ///< If enabled, QGC reduces the update rates of all widgets
186
    bool                    _showStatusBar;
dogmaphobic's avatar
dogmaphobic committed
187
188
    QVBoxLayout*            _centralLayout;
    Ui::MainWindow          _ui;
189

190
191
    QGCQmlWidgetHolder*     _mainQmlWidgetHolder;

192
193
    bool    _forceClose;

dogmaphobic's avatar
dogmaphobic committed
194
    QString _getWindowGeometryKey();
195
196
197
};

#endif /* _MAINWINDOW_H_ */