MainToolBar.h 10.3 KB
Newer Older
dogmaphobic's avatar
dogmaphobic committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
/*=====================================================================

QGroundControl Open Source Ground Control Station

(c) 2009, 2015 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>

This file is part of the QGROUNDCONTROL project

    QGROUNDCONTROL is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    QGROUNDCONTROL 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
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.

======================================================================*/

/**
 * @file
 *   @brief QGC Main Tool Bar
 *   @author Gus Grubba <mavlink@grubba.com>
 */

#ifndef MAINTOOLBAR_H
#define MAINTOOLBAR_H

#include "QGCQmlWidgetHolder.h"

35 36 37 38 39 40
#define TOOL_BAR_SETTINGS_GROUP "TOOLBAR_SETTINGS_GROUP"
#define TOOL_BAR_SHOW_BATTERY   "ShowBattery"
#define TOOL_BAR_SHOW_GPS       "ShowGPS"
#define TOOL_BAR_SHOW_MAV       "ShowMav"
#define TOOL_BAR_SHOW_MESSAGES  "ShowMessages"

dogmaphobic's avatar
dogmaphobic committed
41 42 43 44 45 46 47 48 49 50
class UASInterface;
class UASMessage;
class UASMessageViewRollDown;

class MainToolBar : public QGCQmlWidgetHolder
{
    Q_OBJECT
    Q_ENUMS(ViewType_t)
    Q_ENUMS(MessageType_t)
public:
Don Gagne's avatar
Don Gagne committed
51
    MainToolBar(QWidget* parent = NULL);
dogmaphobic's avatar
dogmaphobic committed
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
    ~MainToolBar();

    typedef enum {
        ViewNone    = -1,
        ViewAnalyze, // MainWindow::VIEW_ENGINEER
        ViewPlan   , // MainWindow::VIEW_MISSION
        ViewFly    , // MainWindow::VIEW_FLIGHT
        ViewSetup  , // MainWindow::VIEW_SETUP
    } ViewType_t;

    typedef enum {
        MessageNone,
        MessageNormal,
        MessageWarning,
        MessageError
    } MessageType_t;

    Q_INVOKABLE void    onSetupView();
    Q_INVOKABLE void    onPlanView();
    Q_INVOKABLE void    onFlyView();
    Q_INVOKABLE void    onAnalyzeView();
    Q_INVOKABLE void    onConnect(QString conf);
    Q_INVOKABLE void    onLinkConfigurationChanged(const QString& config);
    Q_INVOKABLE void    onEnterMessageArea(int x, int y);
    Q_INVOKABLE QString getMavIconColor();

    Q_PROPERTY(int           connectionCount    READ connectionCount    NOTIFY connectionCountChanged)
    Q_PROPERTY(double        batteryVoltage     READ batteryVoltage     NOTIFY batteryVoltageChanged)
    Q_PROPERTY(double        batteryPercent     READ batteryPercent     NOTIFY batteryPercentChanged)
    Q_PROPERTY(ViewType_t    currentView        READ currentView        NOTIFY currentViewChanged)
    Q_PROPERTY(QStringList   configList         READ configList         NOTIFY configListChanged)
    Q_PROPERTY(bool          systemArmed        READ systemArmed        NOTIFY systemArmedChanged)
    Q_PROPERTY(unsigned int  heartbeatTimeout   READ heartbeatTimeout   NOTIFY heartbeatTimeoutChanged)
    Q_PROPERTY(QString       currentMode        READ currentMode        NOTIFY currentModeChanged)
    Q_PROPERTY(MessageType_t messageType        READ messageType        NOTIFY messageTypeChanged)
dogmaphobic's avatar
dogmaphobic committed
87
    Q_PROPERTY(int           newMessageCount    READ newMessageCount    NOTIFY newMessageCountChanged)
dogmaphobic's avatar
dogmaphobic committed
88 89 90 91 92 93 94 95
    Q_PROPERTY(int           messageCount       READ messageCount       NOTIFY messageCountChanged)
    Q_PROPERTY(QString       currentConfig      READ currentConfig      NOTIFY currentConfigChanged)
    Q_PROPERTY(QString       systemPixmap       READ systemPixmap       NOTIFY systemPixmapChanged)
    Q_PROPERTY(int           satelliteCount     READ satelliteCount     NOTIFY satelliteCountChanged)
    Q_PROPERTY(QStringList   connectedList      READ connectedList      NOTIFY connectedListChanged)
    Q_PROPERTY(bool          mavPresent         READ mavPresent         NOTIFY mavPresentChanged)
    Q_PROPERTY(QString       currentState       READ currentState       NOTIFY currentStateChanged)
    Q_PROPERTY(double        dotsPerInch        READ dotsPerInch        NOTIFY dotsPerInchChanged)
dogmaphobic's avatar
dogmaphobic committed
96
    Q_PROPERTY(int           satelliteLock      READ satelliteLock      NOTIFY satelliteLockChanged)
97 98 99 100
    Q_PROPERTY(bool          showGPS            READ showGPS            NOTIFY showGPSChanged)
    Q_PROPERTY(bool          showMav            READ showMav            NOTIFY showMavChanged)
    Q_PROPERTY(bool          showMessages       READ showMessages       NOTIFY showMessagesChanged)
    Q_PROPERTY(bool          showBattery        READ showBattery        NOTIFY showBatteryChanged)
101
    Q_PROPERTY(bool          repaintRequested   READ repaintRequested   NOTIFY repaintRequestedChanged)
dogmaphobic's avatar
dogmaphobic committed
102 103 104 105 106 107 108 109 110 111

    int           connectionCount        () { return _connectionCount; }
    double        batteryVoltage         () { return _batteryVoltage; }
    double        batteryPercent         () { return _batteryPercent; }
    ViewType_t    currentView            () { return _currentView; }
    QStringList   configList             () { return _linkConfigurations; }
    bool          systemArmed            () { return _systemArmed; }
    unsigned int  heartbeatTimeout       () { return _currentHeartbeatTimeout; }
    QString       currentMode            () { return _currentMode; }
    MessageType_t messageType            () { return _currentMessageType; }
dogmaphobic's avatar
dogmaphobic committed
112 113
    int           newMessageCount        () { return _currentMessageCount; }
    int           messageCount           () { return _messageCount; }
dogmaphobic's avatar
dogmaphobic committed
114 115 116 117 118 119 120
    QString       currentConfig          () { return _currentConfig; }
    QString       systemPixmap           () { return _systemPixmap; }
    int           satelliteCount         () { return _satelliteCount; }
    QStringList   connectedList          () { return _connectedList; }
    bool          mavPresent             () { return _mav != NULL; }
    QString       currentState           () { return _currentState; }
    double        dotsPerInch            () { return _dotsPerInch; }
dogmaphobic's avatar
dogmaphobic committed
121
    int           satelliteLock          () { return _satelliteLock; }
122 123 124 125
    bool          showGPS                () { return _showGPS; }
    bool          showMav                () { return _showMav; }
    bool          showMessages           () { return _showMessages; }
    bool          showBattery            () { return _showBattery; }
126
    bool          repaintRequested       () { return true; }
dogmaphobic's avatar
dogmaphobic committed
127 128

    void          setCurrentView         (int currentView);
129
    void          viewStateChanged       (const QString& key, bool value);
130
    void          updateCanvas           ();
dogmaphobic's avatar
dogmaphobic committed
131 132 133 134 135 136 137 138 139 140 141

signals:
    void connectionCountChanged         (int count);
    void batteryVoltageChanged          (double value);
    void batteryPercentChanged          (double value);
    void currentViewChanged             ();
    void configListChanged              ();
    void systemArmedChanged             (bool systemArmed);
    void heartbeatTimeoutChanged        (unsigned int hbTimeout);
    void currentModeChanged             ();
    void messageTypeChanged             (MessageType_t type);
dogmaphobic's avatar
dogmaphobic committed
142
    void newMessageCountChanged         (int count);
dogmaphobic's avatar
dogmaphobic committed
143 144 145 146 147 148 149 150
    void messageCountChanged            (int count);
    void currentConfigChanged           (QString config);
    void systemPixmapChanged            (QPixmap pix);
    void satelliteCountChanged          (int count);
    void connectedListChanged           (QStringList connectedList);
    void mavPresentChanged              (bool present);
    void currentStateChanged            (QString state);
    void dotsPerInchChanged             ();
dogmaphobic's avatar
dogmaphobic committed
151
    void satelliteLockChanged           (int lock);
152 153 154 155
    void showGPSChanged                 (bool value);
    void showMavChanged                 (bool value);
    void showMessagesChanged            (bool value);
    void showBatteryChanged             (bool value);
156
    void repaintRequestedChanged        ();
dogmaphobic's avatar
dogmaphobic committed
157 158 159 160 161 162 163 164 165 166 167 168 169

private slots:
    void _setActiveUAS                  (UASInterface* active);
    void _updateBatteryRemaining        (UASInterface*, double voltage, double, double percent, int);
    void _updateArmingState             (bool armed);
    void _updateConfigurations          ();
    void _linkConnected                 (LinkInterface* link);
    void _linkDisconnected              (LinkInterface* link);
    void _updateState                   (UASInterface* system, QString name, QString description);
    void _updateMode                    (int system, QString name, QString description);
    void _updateName                    (const QString& name);
    void _setSystemType                 (UASInterface* uas, unsigned int systemType);
    void _heartbeatTimeout              (bool timeout, unsigned int ms);
dogmaphobic's avatar
dogmaphobic committed
170
    void _handleTextMessage             (int newCount);
dogmaphobic's avatar
dogmaphobic committed
171 172 173 174
    void _updateCurrentWaypoint         (quint16 id);
    void _updateWaypointDistance        (double distance);
    void _setSatelliteCount             (double val, QString name);
    void _leaveMessageView              ();
dogmaphobic's avatar
dogmaphobic committed
175 176
    void _setSatLoc                     (UASInterface* uas, int fix);

dogmaphobic's avatar
dogmaphobic committed
177 178 179

private:
    void _updateConnection              (LinkInterface *disconnectedLink = NULL);
180
    void _setToolBarState               (const QString& key, bool value);
dogmaphobic's avatar
dogmaphobic committed
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200

private:
    UASInterface*   _mav;
    QQuickItem*     _toolBar;
    ViewType_t      _currentView;
    double          _batteryVoltage;
    double          _batteryPercent;
    QStringList     _linkConfigurations;
    QString         _currentConfig;
    bool            _linkSelected;
    int             _connectionCount;
    bool            _systemArmed;
    QString         _currentState;
    QString         _currentMode;
    QString         _systemName;
    QString         _systemPixmap;
    unsigned int    _currentHeartbeatTimeout;
    double          _waypointDistance;
    quint16         _currentWaypoint;
    int             _currentMessageCount;
dogmaphobic's avatar
dogmaphobic committed
201
    int             _messageCount;
dogmaphobic's avatar
dogmaphobic committed
202 203 204 205 206 207 208
    int             _currentErrorCount;
    int             _currentWarningCount;
    int             _currentNormalCount;
    MessageType_t   _currentMessageType;
    int             _satelliteCount;
    QStringList     _connectedList;
    qreal           _dotsPerInch;
dogmaphobic's avatar
dogmaphobic committed
209
    int             _satelliteLock;
210 211 212 213
    bool            _showGPS;
    bool            _showMav;
    bool            _showMessages;
    bool            _showBattery;
dogmaphobic's avatar
dogmaphobic committed
214 215 216 217 218

    UASMessageViewRollDown* _rollDownMessages;
};

#endif // MAINTOOLBAR_H