QGCGoogleEarthView.h 3.47 KB
Newer Older
pixhawk's avatar
pixhawk committed
1 2 3 4
#ifndef QGCGOOGLEEARTHVIEW_H
#define QGCGOOGLEEARTHVIEW_H

#include <QWidget>
5 6
#include <QTimer>
#include <UASInterface.h>
pixhawk's avatar
pixhawk committed
7

8 9 10 11
#if (defined Q_OS_MAC)
#include <QWebView>
#endif

12
#ifdef _MSC_VER
13
#include <ActiveQt/QAxWidget>
14
#include <ActiveQt/QAxObject>
15 16
#include "windows.h"

17
class QGCWebAxWidget : public QAxWidget
18 19
{
public:
20
	//Q_OBJECT
21
    QGCWebAxWidget(QWidget* parent = 0, Qt::WindowFlags f = 0)
22 23
        : QAxWidget(parent, f)/*,
		_document(NULL)*/
24
    {
25 26
		// Set web browser control
		setControl("{8856F961-340A-11D0-A96B-00C04FD705A2}");
27 28 29 30 31
		// WARNING: Makes it impossible to actually debug javascript. But useful in production mode
		setProperty("ScriptErrorsSuppressed", true);
		// see: http://www.codeproject.com/KB/cpp/ExtendedWebBrowser.aspx?fid=285594&df=90&mpp=25&noise=3&sort=Position&view=Quick&fr=151#GoalScriptError

			//this->dynamicCall("setProperty(const QString&, 
32 33 34
		//QObject::connect(this, SIGNAL(DocumentComplete(IDispatch*, QVariant&)), this, SLOT(setDocument(IDispatch*, QVariant&)));

		
35
    }
36
	/*
37 38 39
	QAxObject* document()
	{
		return _document;
40
	}*/
41

42 43
protected:
		/*
44 45 46 47
	void setDocument(IDispatch* dispatch, QVariant& variant)
	{
		_document = this->querySubObject("Document()");
	}
48
	QAxObject* _document;*/
49 50 51 52 53 54 55 56 57
    virtual bool translateKeyEvent(int message, int keycode) const
    {
        if (message >= WM_KEYFIRST && message <= WM_KEYLAST)
            return true;
        else
            return QAxWidget::translateKeyEvent(message, keycode);
    }

};
58 59
#endif

pixhawk's avatar
pixhawk committed
60
namespace Ui {
61 62
#ifdef _MSC_VER
    class QGCGoogleEarthView;
63
#else
pixhawk's avatar
pixhawk committed
64
    class QGCGoogleEarthView;
65
#endif
pixhawk's avatar
pixhawk committed
66 67 68 69 70 71 72 73 74 75
}

class QGCGoogleEarthView : public QWidget
{
    Q_OBJECT

public:
    explicit QGCGoogleEarthView(QWidget *parent = 0);
    ~QGCGoogleEarthView();

76 77 78
public slots:
    /** @brief Update the internal state. Does not trigger a redraw */
    void updateState();
pixhawk's avatar
pixhawk committed
79 80
    /** @brief Add a new MAV/UAS to the visualization */
    void addUAS(UASInterface* uas);
81 82
    /** @brief Set the currently selected UAS */
    void setActiveUAS(UASInterface* uas);
pixhawk's avatar
pixhawk committed
83 84
    /** @brief Update the global position */
    void updateGlobalPosition(UASInterface* uas, double lat, double lon, double alt, quint64 usec);
85
    /** @brief Show the vehicle trail */
pixhawk's avatar
pixhawk committed
86
    void showTrail(bool state);
87
    /** @brief Show the waypoints */
pixhawk's avatar
pixhawk committed
88
    void showWaypoints(bool state);
89 90
    /** @brief Follow the aircraft during flight */
    void follow(bool follow);
pixhawk's avatar
pixhawk committed
91 92 93 94 95 96
    /** @brief Go to the home location */
    void goHome();
    /** @brief Set the home location */
    void setHome(double lat, double lon, double alt);
    /** @brief Initialize Google Earth */
    void initializeGoogleEarth();
97 98 99 100 101 102
	/** @brief Print a Windows exception */
	void printWinException(int no, QString str1, QString str2, QString str3);

public:
	/** @brief Execute java script inside the Google Earth window */
	QVariant javaScript(QString javascript);
103

pixhawk's avatar
pixhawk committed
104 105
protected:
    void changeEvent(QEvent *e);
106
    QTimer* updateTimer;
pixhawk's avatar
pixhawk committed
107
    int refreshRateMs;
108 109
    UASInterface* mav;
    bool followCamera;
pixhawk's avatar
pixhawk committed
110
    bool trailEnabled;
pixhawk's avatar
pixhawk committed
111
    bool webViewInitialized;
112
	bool jScriptInitialized;
pixhawk's avatar
pixhawk committed
113
    bool gEarthInitialized;
114 115
#ifdef _MSC_VER
    QGCWebAxWidget* webViewWin;
116
	QAxObject* jScriptWin;
117 118 119 120
#endif
#if (defined Q_OS_MAC)
    QWebView* webViewMac;
#endif
pixhawk's avatar
pixhawk committed
121

122
    /** @brief Start widget updating */
123
    void showEvent(QShowEvent* event);
124 125
    /** @brief Stop widget updating */
    void hideEvent(QHideEvent* event);
126

pixhawk's avatar
pixhawk committed
127
private:
128 129
#ifdef _MSC_VER
    Ui::QGCGoogleEarthView* ui;
130 131
#else
    Ui::QGCGoogleEarthView* ui;
132
#endif
pixhawk's avatar
pixhawk committed
133 134
};

135
#endif // QGCGOOGLEEARTHVIEW_H