MainWindow.h 4.95 KB
Newer Older
1 2
/****************************************************************************
 *
3
 *   (c) 2009-2018 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
4 5 6 7 8
 *
 * 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


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

18
#pragma once
dogmaphobic's avatar
dogmaphobic committed
19

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

24
#include <QMainWindow>
25 26 27
#include <QStatusBar>
#include <QStackedWidget>
#include <QSettings>
28
#include <QList>
29 30 31 32 33 34 35 36

#include "LinkManager.h"
#include "LinkInterface.h"
#include "UASInterface.h"
#include "LogCompressor.h"
#include "QGCMAVLinkInspector.h"
#include "QGCMAVLinkLogPlayer.h"
#include "MAVLinkDecoder.h"
37
#include "Vehicle.h"
38
#include "QGCDockWidget.h"
39 40 41
#include "QGCQmlWidgetHolder.h"

#include "ui_MainWindow.h"
42

43
class QGCStatusBar;
44
class Linecharts;
45 46 47 48 49 50 51 52 53 54

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

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

59 60
    /// @brief Deletes the MainWindow singleton
    void deleteInstance(void);
61

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

65 66
    ~MainWindow();

67

68
    /** @brief Get low power mode setting */
69
    bool lowPowerModeEnabled() const
70
    {
dogmaphobic's avatar
dogmaphobic committed
71
        return _lowPowerMode;
72 73
    }

74 75 76
    /// @brief Saves the last used connection
    void saveLastUsedConnection(const QString connection);

77
    // Called from MainWindow.qml when the user accepts the window close dialog
78
    void _reallyClose(void);
79

Don Gagne's avatar
Don Gagne committed
80 81 82
    /// @return Root qml object of main window QML
    QObject* rootQmlObject(void);

83 84
public slots:
    /** @brief Save power by reducing update rates */
dogmaphobic's avatar
dogmaphobic committed
85
    void enableLowPowerMode(bool enabled) { _lowPowerMode = enabled; }
86 87 88 89 90 91

    void closeEvent(QCloseEvent* event);

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

92
protected slots:
93 94 95 96
    /**
     * @brief Enable/Disable Status Bar
     */
    void showStatusBarCallback(bool checked);
97

98
signals:
99
    void initStatusChanged(const QString& message, int alignment, const QColor &color);
John Tapsell's avatar
John Tapsell committed
100 101
    /** 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);
102
    void reallyClose(void);
John Tapsell's avatar
John Tapsell committed
103

104 105 106
    // Used for unit tests to know when the main window closes
    void mainWindowClosed(void);

107 108 109 110 111
public:
    QGCMAVLinkLogPlayer* getLogPlayer()
    {
        return logPlayer;
    }
Don Gagne's avatar
Don Gagne committed
112

113 114 115 116 117 118 119 120 121
protected:
    void connectCommonActions();

    void loadSettings();
    void storeSettings();

    QSettings settings;

    QGCMAVLinkLogPlayer* logPlayer;
Don Gagne's avatar
Don Gagne committed
122
#ifdef QGC_MOUSE_ENABLED_WIN
123
    /** @brief 3d Mouse support (WIN only) */
124 125
    Mouse3DInput* mouseInput;               ///< 3dConnexion 3dMouse SDK
    Mouse6dofInput* mouse;                  ///< Implementation for 3dMouse input
Don Gagne's avatar
Don Gagne committed
126
#endif // QGC_MOUSE_ENABLED_WIN
127 128 129 130 131 132 133 134 135 136 137 138 139

    /** User interface actions **/
    QAction* connectUASAct;
    QAction* disconnectUASAct;
    QAction* startUASAct;
    QAction* returnUASAct;
    QAction* stopUASAct;
    QAction* killUASAct;


    LogCompressor* comp;
    QTimer* videoTimer;
    QTimer windowNameUpdateTimer;
140

Don Gagne's avatar
Don Gagne committed
141
private slots:
142
    void _closeWindow(void) { close(); }
143 144
    void _vehicleAdded(Vehicle* vehicle);
    void _showDockWidgetAction(bool show);
145
    void _showAdvancedUIChanged(bool advanced);
146

147 148 149
#ifdef UNITTEST_BUILD
    void _showQmlTestWidget(void);
#endif
150

151
private:
152
    /// Constructor is private since all creation should be through MainWindow::_create
Lorenz Meier's avatar
Lorenz Meier committed
153
    MainWindow();
154

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

157 158
    QMap<QString, QGCDockWidget*>   _mapName2DockWidget;
    QMap<QString, QAction*>         _mapName2Action;
159

160 161
    void _storeCurrentViewState(void);
    void _loadCurrentViewState(void);
dogmaphobic's avatar
dogmaphobic committed
162
    bool _createInnerDockWidget(const QString& widgetName);
163 164 165
    void _buildCommonWidgets(void);
    void _hideAllDockWidgets(void);
    void _showDockWidget(const QString &name, bool show);
166 167
    void _loadVisibleWidgetsSettings(void);
    void _storeVisibleWidgetsSettings(void);
168
    MAVLinkDecoder* _mavLinkDecoderInstance(void);
169

170
    MAVLinkDecoder*         _mavlinkDecoder;
dogmaphobic's avatar
dogmaphobic committed
171
    bool                    _lowPowerMode;           ///< If enabled, QGC reduces the update rates of all widgets
172
    bool                    _showStatusBar;
dogmaphobic's avatar
dogmaphobic committed
173 174
    QVBoxLayout*            _centralLayout;
    Ui::MainWindow          _ui;
175

176 177
    QGCQmlWidgetHolder*     _mainQmlWidgetHolder;

178 179
    bool    _forceClose;

dogmaphobic's avatar
dogmaphobic committed
180
    QString _getWindowGeometryKey();
181 182
};