MainWindow.h 5.71 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>
29
#include <QList>
30 31 32 33 34 35

#include "LinkManager.h"
#include "LinkInterface.h"
#include "UASInterface.h"
#include "LogCompressor.h"
#include "QGCMAVLinkInspector.h"
dogmaphobic's avatar
dogmaphobic committed
36
#ifndef __mobile__
37
#include "QGCMAVLinkLogPlayer.h"
dogmaphobic's avatar
dogmaphobic committed
38
#endif
39
#include "MAVLinkDecoder.h"
40
#include "Vehicle.h"
41
#include "QGCDockWidget.h"
42 43 44
#include "QGCQmlWidgetHolder.h"

#include "ui_MainWindow.h"
45 46 47 48 49

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

50
class QGCStatusBar;
51 52
class Linecharts;
class QGCDataPlot2D;
53 54 55 56 57 58 59 60 61 62

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

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

67 68
    /// @brief Deletes the MainWindow singleton
    void deleteInstance(void);
69

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

73 74
    ~MainWindow();

75

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

82 83 84
    /// @brief Saves the last used connection
    void saveLastUsedConnection(const QString connection);

85
    // Called from MainWindow.qml when the user accepts the window close dialog
86
    Q_INVOKABLE void reallyClose(void);
87

Don Gagne's avatar
Don Gagne committed
88 89 90
    /// @return Root qml object of main window QML
    QObject* rootQmlObject(void);

91
public slots:
92
#ifndef __mobile__
93
    void showSettings();
94
#endif
95 96

    /** @brief Save power by reducing update rates */
dogmaphobic's avatar
dogmaphobic committed
97
    void enableLowPowerMode(bool enabled) { _lowPowerMode = enabled; }
98 99 100 101 102 103

    void closeEvent(QCloseEvent* event);

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

104
protected slots:
105 106 107 108
    /**
     * @brief Enable/Disable Status Bar
     */
    void showStatusBarCallback(bool checked);
109

110
signals:
111
    void initStatusChanged(const QString& message, int alignment, const QColor &color);
John Tapsell's avatar
John Tapsell committed
112 113 114
    /** 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);

115 116 117
    // Used for unit tests to know when the main window closes
    void mainWindowClosed(void);

Don Gagne's avatar
Don Gagne committed
118
#ifdef QGC_MOUSE_ENABLED_LINUX
119 120
    /** @brief Forward X11Event to catch 3DMouse inputs */
    void x11EventOccured(XEvent *event);
Don Gagne's avatar
Don Gagne committed
121
#endif //QGC_MOUSE_ENABLED_LINUX
122 123

public:
dogmaphobic's avatar
dogmaphobic committed
124
#ifndef __mobile__
125 126 127 128
    QGCMAVLinkLogPlayer* getLogPlayer()
    {
        return logPlayer;
    }
dogmaphobic's avatar
dogmaphobic committed
129
#endif
Don Gagne's avatar
Don Gagne committed
130

131 132 133 134 135 136 137 138 139
protected:
    void connectCommonActions();

    void loadSettings();
    void storeSettings();

    QSettings settings;

    QPointer<MAVLinkDecoder> mavlinkDecoder;
dogmaphobic's avatar
dogmaphobic committed
140
#ifndef __mobile__
141
    QGCMAVLinkLogPlayer* logPlayer;
dogmaphobic's avatar
dogmaphobic committed
142
#endif
Don Gagne's avatar
Don Gagne committed
143
#ifdef QGC_MOUSE_ENABLED_WIN
144
    /** @brief 3d Mouse support (WIN only) */
145 146
    Mouse3DInput* mouseInput;               ///< 3dConnexion 3dMouse SDK
    Mouse6dofInput* mouse;                  ///< Implementation for 3dMouse input
Don Gagne's avatar
Don Gagne committed
147
#endif // QGC_MOUSE_ENABLED_WIN
148

Don Gagne's avatar
Don Gagne committed
149
#ifdef QGC_MOUSE_ENABLED_LINUX
150 151 152
    /** @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
153
#endif // QGC_MOUSE_ENABLED_LINUX
154

155 156 157 158 159 160 161 162 163 164 165 166
    /** User interface actions **/
    QAction* connectUASAct;
    QAction* disconnectUASAct;
    QAction* startUASAct;
    QAction* returnUASAct;
    QAction* stopUASAct;
    QAction* killUASAct;


    LogCompressor* comp;
    QTimer* videoTimer;
    QTimer windowNameUpdateTimer;
167

Don Gagne's avatar
Don Gagne committed
168
private slots:
169
    void _closeWindow(void) { close(); }
170
    void _vehicleAdded(Vehicle* vehicle);
171

172 173 174
#ifndef __mobile__
    void _showDockWidgetAction(bool show);
#endif
175

176 177 178
#ifdef UNITTEST_BUILD
    void _showQmlTestWidget(void);
#endif
179

180
private:
181
    /// Constructor is private since all creation should be through MainWindow::_create
Lorenz Meier's avatar
Lorenz Meier committed
182
    MainWindow();
183

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

186
#ifndef __mobile__
187 188
    QMap<QString, QGCDockWidget*>   _mapName2DockWidget;
    QMap<QString, QAction*>         _mapName2Action;
189
#endif
190

191 192
    void _storeCurrentViewState(void);
    void _loadCurrentViewState(void);
193

194
#ifndef __mobile__
dogmaphobic's avatar
dogmaphobic committed
195
    bool _createInnerDockWidget(const QString& widgetName);
196 197 198
    void _buildCommonWidgets(void);
    void _hideAllDockWidgets(void);
    void _showDockWidget(const QString &name, bool show);
199 200
    void _loadVisibleWidgetsSettings(void);
    void _storeVisibleWidgetsSettings(void);
201
#endif
202

dogmaphobic's avatar
dogmaphobic committed
203
    bool                    _lowPowerMode;           ///< If enabled, QGC reduces the update rates of all widgets
204
    bool                    _showStatusBar;
dogmaphobic's avatar
dogmaphobic committed
205 206
    QVBoxLayout*            _centralLayout;
    Ui::MainWindow          _ui;
207

208 209
    QGCQmlWidgetHolder*     _mainQmlWidgetHolder;

210 211
    bool    _forceClose;

dogmaphobic's avatar
dogmaphobic committed
212
    QString _getWindowGeometryKey();
213 214 215
};

#endif /* _MAINWINDOW_H_ */