QGCSettingsWidget.cc 4.97 KB
Newer Older
1
#include <QSettings>
2
#include <QDesktopWidget>
3

lm's avatar
lm committed
4
#include "QGCSettingsWidget.h"
5
#include "MainWindow.h"
lm's avatar
lm committed
6 7
#include "ui_QGCSettingsWidget.h"

8
#include "JoystickWidget.h"
9 10 11
#include "LinkManager.h"
#include "MAVLinkProtocol.h"
#include "MAVLinkSettingsWidget.h"
12
#include "GAudioOutput.h"
13
#include "QGCCore.h"
14

15
QGCSettingsWidget::QGCSettingsWidget(JoystickInput *joystick, QWidget *parent, Qt::WindowFlags flags) :
16
    QDialog(parent, flags),
Don Gagne's avatar
Don Gagne committed
17 18
    mainWindow((MainWindow*)parent),
    ui(new Ui::QGCSettingsWidget)
lm's avatar
lm committed
19 20
{
    ui->setupUi(this);
21

22 23
    // Center the window on the screen.
    QRect position = frameGeometry();
24
    position.moveCenter(QApplication::desktop()->availableGeometry().center());
25 26
    move(position.topLeft());

27 28 29
    // Add the joystick settings pane
    ui->tabWidget->addTab(new JoystickWidget(joystick, this), "Controllers");

30 31
    // Add all protocols
    QList<ProtocolInterface*> protocols = LinkManager::instance()->getProtocols();
32
    foreach (ProtocolInterface* protocol, protocols) {
33
        MAVLinkProtocol* mavlink = dynamic_cast<MAVLinkProtocol*>(protocol);
34
        if (mavlink) {
35 36 37 38 39 40 41
            MAVLinkSettingsWidget* msettings = new MAVLinkSettingsWidget(mavlink, this);
            ui->tabWidget->addTab(msettings, "MAVLink");
        }
    }

    this->window()->setWindowTitle(tr("QGroundControl Settings"));

42 43 44 45 46
    // Audio preferences
    ui->audioMuteCheckBox->setChecked(GAudioOutput::instance()->isMuted());
    connect(ui->audioMuteCheckBox, SIGNAL(toggled(bool)), GAudioOutput::instance(), SLOT(mute(bool)));
    connect(GAudioOutput::instance(), SIGNAL(mutedChanged(bool)), ui->audioMuteCheckBox, SLOT(setChecked(bool)));

47
    // Reconnect
48 49
    ui->reconnectCheckBox->setChecked(mainWindow->autoReconnectEnabled());
    connect(ui->reconnectCheckBox, SIGNAL(clicked(bool)), mainWindow, SLOT(enableAutoReconnect(bool)));
50

51
    // Low power mode
52 53
    ui->lowPowerCheckBox->setChecked(mainWindow->lowPowerModeEnabled());
    connect(ui->lowPowerCheckBox, SIGNAL(clicked(bool)), mainWindow, SLOT(enableLowPowerMode(bool)));
54

55
    // Dock widget title bars
56 57
    ui->titleBarCheckBox->setChecked(mainWindow->dockWidgetTitleBarsEnabled());
    connect(ui->titleBarCheckBox,SIGNAL(clicked(bool)),mainWindow,SLOT(enableDockWidgetTitleBars(bool)));
58 59
    
    connect(ui->deleteSettings, &QAbstractButton::toggled, this, &QGCSettingsWidget::_deleteSettingsToggled);
60

61 62 63 64 65
    // Custom mode

    ui->customModeComboBox->addItem(tr("Default: Generic MAVLink and serial links"), MainWindow::CUSTOM_MODE_NONE);
    ui->customModeComboBox->addItem(tr("Wifi: Generic MAVLink, wifi or serial links"), MainWindow::CUSTOM_MODE_WIFI);
    ui->customModeComboBox->addItem(tr("PX4: Optimized for PX4 Autopilot Users"), MainWindow::CUSTOM_MODE_PX4);
66 67
    // XXX we need to polish the APM view mode before re-enabling this
    //ui->customModeComboBox->addItem(tr("APM: Optimized for ArduPilot Users"), MainWindow::CUSTOM_MODE_APM);
68 69 70 71

    ui->customModeComboBox->setCurrentIndex(ui->customModeComboBox->findData(mainWindow->getCustomMode()));
    connect(ui->customModeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(selectCustomMode(int)));

72 73
    // Intialize the style UI to the proper values obtained from the MainWindow.
    MainWindow::QGC_MAINWINDOW_STYLE style = mainWindow->getStyle();
74
    ui->styleChooser->setCurrentIndex(style);
75 76

    // And then connect all the signals for the UI for changing styles.
77
    connect(ui->styleChooser, SIGNAL(currentIndexChanged(int)), this, SLOT(styleChanged(int)));
78

79 80
    // Close / destroy
    connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(deleteLater()));
lm's avatar
lm committed
81 82 83 84 85 86
}

QGCSettingsWidget::~QGCSettingsWidget()
{
    delete ui;
}
87 88

void QGCSettingsWidget::styleChanged(int index)
89
{
90
    mainWindow->loadStyle((index == 1) ? MainWindow::QGC_MAINWINDOW_STYLE_LIGHT : MainWindow::QGC_MAINWINDOW_STYLE_DARK);
91
}
92 93 94 95 96 97

void QGCSettingsWidget::selectCustomMode(int mode)
{
    MainWindow::instance()->setCustomMode(static_cast<enum MainWindow::CUSTOM_MODE>(ui->customModeComboBox->itemData(mode).toInt()));
    MainWindow::instance()->showInfoMessage(tr("Please restart QGroundControl"), tr("The optimization selection was changed. The application needs to be closed and restarted to put all optimizations into effect."));
}
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114

void QGCSettingsWidget::_deleteSettingsToggled(bool checked)
{
    if (checked){
        QMessageBox::StandardButton answer = QMessageBox::question(this,
                                                                   tr("Delete Settings"),
                                                                   tr("All saved settgings will be deleted the next time you start QGroundControl. Is this really what you want?"),
                                                                   QMessageBox::Yes | QMessageBox::No,
                                                                   QMessageBox::No);
        if (answer == QMessageBox::Yes) {
            QSettings settings;
            settings.setValue(QGCCore::deleteAllSettingsKey, 1);
        } else {
            ui->deleteSettings->setChecked(false);
        }
    }
}