QGCQmlWidgetHolder.cpp 1.58 KB
Newer Older
1 2 3 4 5 6 7 8
/****************************************************************************
 *
 *   (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.
 *
 ****************************************************************************/
dogmaphobic's avatar
dogmaphobic committed
9

Don Gagne's avatar
Don Gagne committed
10 11 12 13 14 15

/// @file
///     @author Don Gagne <don@thegagnes.com>

#include "QGCQmlWidgetHolder.h"

16 17
QGCQmlWidgetHolder::QGCQmlWidgetHolder(const QString& title, QAction* action, QWidget *parent) :
    QGCDockWidget(title, action, parent)
Don Gagne's avatar
Don Gagne committed
18 19
{
    _ui.setupUi(this);
dogmaphobic's avatar
dogmaphobic committed
20

21 22
    layout()->setContentsMargins(0,0,0,0);

23 24 25
    if (action) {
        setWindowTitle(title);
    }
Don Gagne's avatar
Don Gagne committed
26
    setResizeMode(QQuickWidget::SizeRootObjectToView);
Don Gagne's avatar
Don Gagne committed
27 28 29 30 31 32 33 34 35
}

QGCQmlWidgetHolder::~QGCQmlWidgetHolder()
{

}

void QGCQmlWidgetHolder::setAutoPilot(AutoPilotPlugin* autoPilot)
{
36
    setContextPropertyObject("autopilot", autoPilot);
Don Gagne's avatar
Don Gagne committed
37 38
}

Don Gagne's avatar
Don Gagne committed
39
bool QGCQmlWidgetHolder::setSource(const QUrl& qmlUrl)
Don Gagne's avatar
Don Gagne committed
40
{
41
    return _ui.qmlWidget->setSource(qmlUrl);
Don Gagne's avatar
Don Gagne committed
42
}
43 44 45 46 47

void QGCQmlWidgetHolder::setContextPropertyObject(const QString& name, QObject* object)
{
    _ui.qmlWidget->rootContext()->setContextProperty(name, object);
}
dogmaphobic's avatar
dogmaphobic committed
48

49
QQmlContext* QGCQmlWidgetHolder::getRootContext(void)
dogmaphobic's avatar
dogmaphobic committed
50 51 52
{
    return _ui.qmlWidget->rootContext();
}
53 54 55 56 57

QQuickItem* QGCQmlWidgetHolder::getRootObject(void)
{
    return _ui.qmlWidget->rootObject();
}
Don Gagne's avatar
Don Gagne committed
58

dogmaphobic's avatar
dogmaphobic committed
59 60 61 62 63 64
QQmlEngine*	QGCQmlWidgetHolder::getEngine()
{
    return _ui.qmlWidget->engine();
}


Don Gagne's avatar
Don Gagne committed
65 66 67
void QGCQmlWidgetHolder::setResizeMode(QQuickWidget::ResizeMode resizeMode)
{
    _ui.qmlWidget->setResizeMode(resizeMode);
68
}