void ConfigCustomWidget::registerWidgets(ConfigTaskWidget &parent)
{
    parent.addWidget(m_aircraft->customMixerTable);
    parent.addWidget(m_aircraft->customThrottle1Curve->getCurveWidget());
    parent.addWidget(m_aircraft->customThrottle1Curve);
    parent.addWidget(m_aircraft->customThrottle2Curve->getCurveWidget());
    parent.addWidget(m_aircraft->customThrottle2Curve);
}
void ConfigGadgetWidget::onOPLinkConnect()
{
    // qDebug() << "ConfigGadgetWidget::onOPLinkConnect";

    ConfigTaskWidget *widget = new ConfigOPLinkWidget(this);

    widget->bind();
    stackWidget->replaceTab(ConfigGadgetWidget::OPLink, widget);
}
void ConfigGroundVehicleWidget::registerWidgets(ConfigTaskWidget &parent)
{
    parent.addWidget(m_aircraft->groundVehicleThrottle1->getCurveWidget());
    parent.addWidget(m_aircraft->groundVehicleThrottle1);
    parent.addWidget(m_aircraft->groundVehicleThrottle2->getCurveWidget());
    parent.addWidget(m_aircraft->groundVehicleThrottle2);
    parent.addWidget(m_aircraft->groundVehicleType);
    parent.addWidget(m_aircraft->gvEngineChannelBox);
    parent.addWidget(m_aircraft->gvAileron1ChannelBox);
    parent.addWidget(m_aircraft->gvAileron2ChannelBox);
    parent.addWidget(m_aircraft->gvMotor1ChannelBox);
    parent.addWidget(m_aircraft->gvMotor2ChannelBox);
    parent.addWidget(m_aircraft->gvSteering1ChannelBox);
    parent.addWidget(m_aircraft->gvSteering2ChannelBox);
}
void ConfigGadgetWidget::tabAboutToChange(int index, bool *proceed)
{
    Q_UNUSED(index);
    *proceed = true;
    ConfigTaskWidget *wid = qobject_cast<ConfigTaskWidget *>(stackWidget->currentWidget());
    if (!wid) {
        return;
    }
    if (wid->isDirty()) {
        int ans = QMessageBox::warning(this, tr("Unsaved changes"), tr("The tab you are leaving has unsaved changes, "
                                                                       "if you proceed they will be lost.\n"
                                                                       "Do you still want to proceed?"), QMessageBox::Yes, QMessageBox::No);
        if (ans == QMessageBox::No) {
            *proceed = false;
        } else {
            wid->setDirty(false);
        }
    }
}
void ConfigGadgetWidget::onAutopilotConnect()
{
    // qDebug() << "ConfigGadgetWidget::onAutopilotConnect";

    // Check what Board type we are talking to, and if necessary, remove/add tabs in the config gadget
    ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
    UAVObjectUtilManager *utilMngr     = pm->getObject<UAVObjectUtilManager>();

    if (utilMngr) {
        int board = utilMngr->getBoardModel();
        if ((board & 0xff00) == 0x0400) {
            // CopterControl family
            ConfigTaskWidget *widget;
            widget = new ConfigCCAttitudeWidget(this);
            widget->bind();
            stackWidget->replaceTab(ConfigGadgetWidget::Sensors, widget);
            widget = new ConfigCCHWWidget(this);
            widget->bind();
            stackWidget->replaceTab(ConfigGadgetWidget::Hardware, widget);
        } else if ((board & 0xff00) == 0x0900) {
            // Revolution family
            ConfigTaskWidget *widget;
            widget = new ConfigRevoWidget(this);
            widget->bind();
            stackWidget->replaceTab(ConfigGadgetWidget::Sensors, widget);
            if (board == 0x0903 || board == 0x0904) {
                widget = new ConfigRevoHWWidget(this);
            } else if (board == 0x0905) {
                widget = new ConfigRevoNanoHWWidget(this);
            }
            widget->bind();
            stackWidget->replaceTab(ConfigGadgetWidget::Hardware, widget);
        } else if ((board & 0xff00) == 0x9200) {
            // Sparky2
            ConfigTaskWidget *widget;
            widget = new ConfigRevoWidget(this);
            widget->bind();
            stackWidget->replaceTab(ConfigGadgetWidget::Sensors, widget);
            widget = new ConfigSparky2HWWidget(this);
            widget->bind();
            stackWidget->replaceTab(ConfigGadgetWidget::Hardware, widget);
        } else {
            // Unknown board
            qWarning() << "Unknown board " << board;
        }
    }
}
void ConfigFixedWingWidget::registerWidgets(ConfigTaskWidget &parent)
{
    parent.addWidget(m_aircraft->fixedWingThrottle->getCurveWidget());
    parent.addWidget(m_aircraft->fixedWingThrottle);
    parent.addWidget(m_aircraft->fixedWingType);

    parent.addWidget(m_aircraft->fwEngineChannelBox);
    parent.addWidget(m_aircraft->fwAileron1ChannelBox);
    parent.addWidget(m_aircraft->fwAileron2ChannelBox);
    parent.addWidget(m_aircraft->fwElevator1ChannelBox);
    parent.addWidget(m_aircraft->fwElevator2ChannelBox);
    parent.addWidget(m_aircraft->fwRudder1ChannelBox);
    parent.addWidget(m_aircraft->fwRudder2ChannelBox);
    parent.addWidget(m_aircraft->elevonSlider1);
    parent.addWidget(m_aircraft->elevonSlider2);
    parent.addWidget(m_aircraft->elevonSlider3);
}
void ConfigCustomWidget::registerWidgets(ConfigTaskWidget &parent)
{
    parent.addWidget(m_aircraft->customMixerTable);
    parent.addWidget(m_aircraft->customThrottle1Curve->getCurveWidget());
    parent.addWidget(m_aircraft->customThrottle1Curve);
    parent.addWidget(m_aircraft->customThrottle2Curve->getCurveWidget());
    parent.addWidget(m_aircraft->customThrottle2Curve);
    parent.addWidgetBinding("MixerSettings", "Curve2Source", m_aircraft->curve2SourceCombo);
    parent.addWidget(m_aircraft->curve2SourceCombo);
}