QGCQuickWidget.cc 1.81 KB
Newer Older
1 2 3 4 5 6 7 8 9
/****************************************************************************
 *
 *   (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.
 *
 ****************************************************************************/

Don Gagne's avatar
Don Gagne committed
10 11

#include "QGCQuickWidget.h"
12
#include "MultiVehicleManager.h"
13
#include "JoystickManager.h"
14
#include "QGCApplication.h"
Don Gagne's avatar
Don Gagne committed
15 16 17 18 19

#include <QQmlContext>
#include <QQmlEngine>

/// @file
Ricardo de Almeida Gonzaga's avatar
Ricardo de Almeida Gonzaga committed
20
///     @brief Subclass of QQuickWidget which injects Facts and the Palette object into
Don Gagne's avatar
Don Gagne committed
21 22 23 24 25 26 27
///             the QML context.
///
///     @author Don Gagne <don@thegagnes.com>

QGCQuickWidget::QGCQuickWidget(QWidget* parent) :
    QQuickWidget(parent)
{
28
#ifndef Q_OS_MAC
29 30 31
    // The following causes the Map control to hang after doing a pinch gesture on mac trackpads.
    // By not turning this on for macos we lose pinch gesture, but two finger scroll still zooms the map.
    // So it's a decent workaround. Qt bug reported: 53634
Don Gagne's avatar
Don Gagne committed
32
    setAttribute(Qt::WA_AcceptTouchEvents);
33
#endif
Don Gagne's avatar
Don Gagne committed
34
    rootContext()->engine()->addImportPath("qrc:/qml");
35
    rootContext()->setContextProperty("joystickManager", qgcApp()->toolbox()->joystickManager());
36 37 38 39 40
}

void QGCQuickWidget::setAutoPilot(AutoPilotPlugin* autoPilot)
{
    rootContext()->setContextProperty("autopilot", autoPilot);
Don Gagne's avatar
Don Gagne committed
41
}
42 43 44 45 46 47 48 49 50 51 52

bool QGCQuickWidget::setSource(const QUrl& qmlUrl)
{
    QQuickWidget::setSource(qmlUrl);
    if (status() != Ready) {
        QString errorList;
        
        foreach (QQmlError error, errors()) {
            errorList += error.toString();
            errorList += "\n";
        }
53
        qgcApp()->showMessage(tr("Source not ready: Status(%1)\nErrors:\n%2").arg(status()).arg(errorList));
54 55 56 57 58
        return false;
    }
    
    return true;
}