QGroundControlQmlGlobal.cc 6 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.
 *
 ****************************************************************************/
9

10 11 12 13 14

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

#include "QGroundControlQmlGlobal.h"
15 16

#include <QSettings>
Don Gagne's avatar
Don Gagne committed
17 18
#include <QLineF>
#include <QPointF>
19

Don Gagne's avatar
Don Gagne committed
20
static const char* kQmlGlobalKeyName = "QGCQml";
21

22
const char* QGroundControlQmlGlobal::_virtualTabletJoystickKey  = "VirtualTabletJoystick";
23
const char* QGroundControlQmlGlobal::_baseFontPointSizeKey      = "BaseDeviceFontPointSize";
24

25 26 27 28 29
QGroundControlQmlGlobal::QGroundControlQmlGlobal(QGCApplication* app)
    : QGCTool(app)
    , _flightMapSettings(NULL)
    , _linkManager(NULL)
    , _multiVehicleManager(NULL)
dogmaphobic's avatar
dogmaphobic committed
30
    , _mapEngineManager(NULL)
31 32
    , _qgcPositionManager(NULL)
    , _missionCommandTree(NULL)
33
    , _videoManager(NULL)
Gus Grubba's avatar
Gus Grubba committed
34
    , _mavlinkLogManager(NULL)
35
    , _corePlugin(NULL)
Gus Grubba's avatar
Gus Grubba committed
36
    , _firmwarePluginManager(NULL)
37
    , _settingsManager(NULL)
38
    , _virtualTabletJoystick(false)
39
    , _baseFontPointSize(0.0)
40
{
41
    QSettings settings;
42 43
    _virtualTabletJoystick  = settings.value(_virtualTabletJoystickKey, false).toBool();
    _baseFontPointSize      = settings.value(_baseFontPointSizeKey, 0.0).toDouble();
44

45 46
    // We clear the parent on this object since we run into shutdown problems caused by hybrid qml app. Instead we let it leak on shutdown.
    setParent(NULL);
47 48 49 50 51
}

QGroundControlQmlGlobal::~QGroundControlQmlGlobal()
{

52
}
53

54 55 56
void QGroundControlQmlGlobal::setToolbox(QGCToolbox* toolbox)
{
    QGCTool::setToolbox(toolbox);
57

dogmaphobic's avatar
dogmaphobic committed
58 59 60
    _flightMapSettings      = toolbox->flightMapSettings();
    _linkManager            = toolbox->linkManager();
    _multiVehicleManager    = toolbox->multiVehicleManager();
Jimmy Johnson's avatar
Jimmy Johnson committed
61
    _mapEngineManager       = toolbox->mapEngineManager();
62 63
    _qgcPositionManager     = toolbox->qgcPositionManager();
    _missionCommandTree     = toolbox->missionCommandTree();
64
    _videoManager           = toolbox->videoManager();
Gus Grubba's avatar
Gus Grubba committed
65
    _mavlinkLogManager      = toolbox->mavlinkLogManager();
66
    _corePlugin             = toolbox->corePlugin();
Gus Grubba's avatar
Gus Grubba committed
67
    _firmwarePluginManager  = toolbox->firmwarePluginManager();
68
    _settingsManager        = toolbox->settingsManager();
69 70
}

71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
void QGroundControlQmlGlobal::saveGlobalSetting (const QString& key, const QString& value)
{
    QSettings settings;
    settings.beginGroup(kQmlGlobalKeyName);
    settings.setValue(key, value);
}

QString QGroundControlQmlGlobal::loadGlobalSetting (const QString& key, const QString& defaultValue)
{
    QSettings settings;
    settings.beginGroup(kQmlGlobalKeyName);
    return settings.value(key, defaultValue).toString();
}

void QGroundControlQmlGlobal::saveBoolGlobalSetting (const QString& key, bool value)
{
    QSettings settings;
    settings.beginGroup(kQmlGlobalKeyName);
    settings.setValue(key, value);
}

bool QGroundControlQmlGlobal::loadBoolGlobalSetting (const QString& key, bool defaultValue)
{
    QSettings settings;
    settings.beginGroup(kQmlGlobalKeyName);
    return settings.value(key, defaultValue).toBool();
}
98 99 100 101

void QGroundControlQmlGlobal::startPX4MockLink(bool sendStatusText)
{
#ifdef QT_DEBUG
102
    MockLink::startPX4MockLink(sendStatusText);
Don Gagne's avatar
Don Gagne committed
103 104
#else
    Q_UNUSED(sendStatusText);
105 106 107 108 109 110
#endif
}

void QGroundControlQmlGlobal::startGenericMockLink(bool sendStatusText)
{
#ifdef QT_DEBUG
111
    MockLink::startGenericMockLink(sendStatusText);
Don Gagne's avatar
Don Gagne committed
112 113
#else
    Q_UNUSED(sendStatusText);
114 115 116 117 118 119
#endif
}

void QGroundControlQmlGlobal::startAPMArduCopterMockLink(bool sendStatusText)
{
#ifdef QT_DEBUG
120
    MockLink::startAPMArduCopterMockLink(sendStatusText);
Don Gagne's avatar
Don Gagne committed
121 122
#else
    Q_UNUSED(sendStatusText);
123 124 125 126 127 128
#endif
}

void QGroundControlQmlGlobal::startAPMArduPlaneMockLink(bool sendStatusText)
{
#ifdef QT_DEBUG
129
    MockLink::startAPMArduPlaneMockLink(sendStatusText);
Don Gagne's avatar
Don Gagne committed
130 131
#else
    Q_UNUSED(sendStatusText);
132 133 134
#endif
}

135 136 137 138 139 140 141 142 143
void QGroundControlQmlGlobal::startAPMArduSubMockLink(bool sendStatusText)
{
#ifdef QT_DEBUG
    MockLink::startAPMArduSubMockLink(sendStatusText);
#else
    Q_UNUSED(sendStatusText);
#endif
}

144 145 146 147 148
void QGroundControlQmlGlobal::stopAllMockLinks(void)
{
#ifdef QT_DEBUG
    LinkManager* linkManager = qgcApp()->toolbox()->linkManager();

149 150
    for (int i=0; i<linkManager->links().count(); i++) {
        LinkInterface* link = linkManager->links()[i];
151
        MockLink* mockLink = qobject_cast<MockLink*>(link);
Don Gagne's avatar
Don Gagne committed
152

153
        if (mockLink) {
Don Gagne's avatar
Don Gagne committed
154
            linkManager->disconnectLink(mockLink);
155 156 157 158
        }
    }
#endif
}
159 160 161 162 163 164 165

void QGroundControlQmlGlobal::setIsDarkStyle(bool dark)
{
    qgcApp()->setStyle(dark);
    emit isDarkStyleChanged(dark);
}

Don Gagne's avatar
Don Gagne committed
166 167 168 169 170 171
void QGroundControlQmlGlobal::setIsVersionCheckEnabled(bool enable)
{
    qgcApp()->toolbox()->mavlinkProtocol()->enableVersionCheck(enable);
    emit isVersionCheckEnabledChanged(enable);
}

172 173 174 175 176 177
void QGroundControlQmlGlobal::setMavlinkSystemID(int id)
{
    qgcApp()->toolbox()->mavlinkProtocol()->setSystemId(id);
    emit mavlinkSystemIDChanged(id);
}

178 179 180 181 182 183 184 185 186
void QGroundControlQmlGlobal::setVirtualTabletJoystick(bool enabled)
{
    if (_virtualTabletJoystick != enabled) {
        QSettings settings;
        settings.setValue(_virtualTabletJoystickKey, enabled);
        _virtualTabletJoystick = enabled;
        emit virtualTabletJoystickChanged(enabled);
    }
}
187

188 189 190 191 192 193 194 195 196 197
void QGroundControlQmlGlobal::setBaseFontPointSize(qreal size)
{
    if (size >= 6.0 && size <= 48.0) {
        QSettings settings;
        settings.setValue(_baseFontPointSizeKey, size);
        _baseFontPointSize = size;
        emit baseFontPointSizeChanged(size);
    }
}

Gus Grubba's avatar
Gus Grubba committed
198 199 200 201 202 203
int QGroundControlQmlGlobal::supportedFirmwareCount()
{
    return _firmwarePluginManager->knownFirmwareTypes().count();
}


204 205 206 207 208 209 210
bool QGroundControlQmlGlobal::linesIntersect(QPointF line1A, QPointF line1B, QPointF line2A, QPointF line2B)
{
    QPointF intersectPoint;

    return QLineF(line1A, line1B).intersect(QLineF(line2A, line2B), &intersectPoint) == QLineF::BoundedIntersection &&
            intersectPoint != line1A && intersectPoint != line1B;
}