QGCQuickWidget.cc 1.85 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 12

#include "QGCQuickWidget.h"
#include "AutoPilotPluginManager.h"
13
#include "MultiVehicleManager.h"
14
#include "JoystickManager.h"
15
#include "QGCApplication.h"
Don Gagne's avatar
Don Gagne committed
16 17 18 19 20 21 22 23 24 25 26 27 28

#include <QQmlContext>
#include <QQmlEngine>

/// @file
///     @brief Subclass of QQuickWidget which injects Facts and the Pallete object into
///             the QML context.
///
///     @author Don Gagne <don@thegagnes.com>

QGCQuickWidget::QGCQuickWidget(QWidget* parent) :
    QQuickWidget(parent)
{
29 30 31 32
#ifndef __macos__
    // 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
33
    setAttribute(Qt::WA_AcceptTouchEvents);
34
#endif
Don Gagne's avatar
Don Gagne committed
35
    rootContext()->engine()->addImportPath("qrc:/qml");
36
    rootContext()->setContextProperty("joystickManager", qgcApp()->toolbox()->joystickManager());
37 38 39 40 41
}

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

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