Commit 4e74c374 authored by Don Gagne's avatar Don Gagne

Merge pull request #1321 from dogmaphobic/toolBarPreferences

Completed Tool Bar settings in Preferences Dialog
parents 0eb51f49 3d00780b
...@@ -126,11 +126,8 @@ public: ...@@ -126,11 +126,8 @@ public:
/// @brief Restore (and connects) the last used connection (if any) /// @brief Restore (and connects) the last used connection (if any)
void restoreLastUsedConnection(); void restoreLastUsedConnection();
#ifdef UNITTEST_BUILD /// @brief Gets a pointer to the Main Tool Bar
// Returns a pointer to the MainToolBar so that unit tests can change views.
MainToolBar* getMainToolBar(void) { return _mainToolBar; } MainToolBar* getMainToolBar(void) { return _mainToolBar; }
#endif
public slots: public slots:
/** @brief Show the application settings */ /** @brief Show the application settings */
......
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
#include "QGCApplication.h" #include "QGCApplication.h"
#include "QGCFileDialog.h" #include "QGCFileDialog.h"
#include "QGCMessageBox.h" #include "QGCMessageBox.h"
#include "MainToolBar.h"
SettingsDialog::SettingsDialog(JoystickInput *joystick, QWidget *parent, int showTab, Qt::WindowFlags flags) : SettingsDialog::SettingsDialog(JoystickInput *joystick, QWidget *parent, int showTab, Qt::WindowFlags flags) :
QDialog(parent, flags), QDialog(parent, flags),
...@@ -63,6 +64,14 @@ _ui(new Ui::SettingsDialog) ...@@ -63,6 +64,14 @@ _ui(new Ui::SettingsDialog)
this->window()->setWindowTitle(tr("QGroundControl Settings")); this->window()->setWindowTitle(tr("QGroundControl Settings"));
// Tool Bar Preferences
QSettings settings;
settings.beginGroup(TOOL_BAR_SETTINGS_GROUP);
_ui->showBattery->setChecked(settings.value( TOOL_BAR_SHOW_BATTERY, true).toBool());
_ui->showGPS->setChecked(settings.value( TOOL_BAR_SHOW_GPS, true).toBool());
_ui->showMav->setChecked(settings.value( TOOL_BAR_SHOW_MAV, true).toBool());
_ui->showMessages->setChecked(settings.value(TOOL_BAR_SHOW_MESSAGES, true).toBool());
settings.endGroup();
// Audio preferences // Audio preferences
_ui->audioMuteCheckBox->setChecked(GAudioOutput::instance()->isMuted()); _ui->audioMuteCheckBox->setChecked(GAudioOutput::instance()->isMuted());
connect(_ui->audioMuteCheckBox, SIGNAL(toggled(bool)), GAudioOutput::instance(), SLOT(mute(bool))); connect(_ui->audioMuteCheckBox, SIGNAL(toggled(bool)), GAudioOutput::instance(), SLOT(mute(bool)));
...@@ -115,10 +124,11 @@ void SettingsDialog::styleChanged(int index) ...@@ -115,10 +124,11 @@ void SettingsDialog::styleChanged(int index)
void SettingsDialog::_deleteSettingsToggled(bool checked) void SettingsDialog::_deleteSettingsToggled(bool checked)
{ {
if (checked){ if (checked){
QGCMessageBox::StandardButton answer = QGCMessageBox::question(tr("Delete Settings"), QGCMessageBox::StandardButton answer =
tr("All saved settings will be deleted the next time you start QGroundControl. Is this really what you want?"), QGCMessageBox::question(tr("Delete Settings"),
QMessageBox::Yes | QMessageBox::No, tr("All saved settings will be deleted the next time you start QGroundControl. Is this really what you want?"),
QMessageBox::No); QMessageBox::Yes | QMessageBox::No,
QMessageBox::No);
if (answer == QMessageBox::Yes) { if (answer == QMessageBox::Yes) {
qgcApp()->deleteAllSettingsNextBoot(); qgcApp()->deleteAllSettingsNextBoot();
} else { } else {
...@@ -133,21 +143,17 @@ void SettingsDialog::_deleteSettingsToggled(bool checked) ...@@ -133,21 +143,17 @@ void SettingsDialog::_deleteSettingsToggled(bool checked)
void SettingsDialog::_validateBeforeClose(void) void SettingsDialog::_validateBeforeClose(void)
{ {
QGCApplication* app = qgcApp(); QGCApplication* app = qgcApp();
// Validate the saved file location // Validate the saved file location
QString saveLocation = _ui->savedFilesLocation->text(); QString saveLocation = _ui->savedFilesLocation->text();
if (!app->validatePossibleSavedFilesLocation(saveLocation)) { if (!app->validatePossibleSavedFilesLocation(saveLocation)) {
QGCMessageBox::warning(tr("Bad save location"), QGCMessageBox::warning(
tr("The location to save files to is invalid, or cannot be written to. Please provide a valid directory.")); tr("Invalid Save Location"),
tr("The location to save files is invalid, or cannot be written to. Please provide a valid directory."));
return; return;
} }
// Locations is valid, save // Locations is valid, save
app->setSavedFilesLocation(saveLocation); app->setSavedFilesLocation(saveLocation);
qgcApp()->setPromptFlightDataSave(_ui->promptFlightDataSave->checkState() == Qt::Checked); qgcApp()->setPromptFlightDataSave(_ui->promptFlightDataSave->checkState() == Qt::Checked);
// Close dialog // Close dialog
accept(); accept();
} }
...@@ -155,10 +161,36 @@ void SettingsDialog::_validateBeforeClose(void) ...@@ -155,10 +161,36 @@ void SettingsDialog::_validateBeforeClose(void)
/// @brief Displays a directory picker dialog to allow the user to select a saved file location /// @brief Displays a directory picker dialog to allow the user to select a saved file location
void SettingsDialog::_selectSavedFilesDirectory(void) void SettingsDialog::_selectSavedFilesDirectory(void)
{ {
QString newLocation = QGCFileDialog::getExistingDirectory(this, QString newLocation = QGCFileDialog::getExistingDirectory(
tr("Select the directory where you want to save files to."), this,
_ui->savedFilesLocation->text()); tr("Select the directory where you want to save files to."),
_ui->savedFilesLocation->text());
if (!newLocation.isEmpty()) { if (!newLocation.isEmpty()) {
_ui->savedFilesLocation->setText(newLocation); _ui->savedFilesLocation->setText(newLocation);
} }
// TODO:
// Once a directory is selected, we need to display the various subdirectories used underneath:
// * Flight data logs
// * Parameters
}
void SettingsDialog::on_showGPS_clicked(bool checked)
{
_mainWindow->getMainToolBar()->viewStateChanged(TOOL_BAR_SHOW_GPS, checked);
}
void SettingsDialog::on_showBattery_clicked(bool checked)
{
_mainWindow->getMainToolBar()->viewStateChanged(TOOL_BAR_SHOW_BATTERY, checked);
}
void SettingsDialog::on_showMessages_clicked(bool checked)
{
_mainWindow->getMainToolBar()->viewStateChanged(TOOL_BAR_SHOW_MESSAGES, checked);
}
void SettingsDialog::on_showMav_clicked(bool checked)
{
_mainWindow->getMainToolBar()->viewStateChanged(TOOL_BAR_SHOW_MAV, checked);
} }
...@@ -56,6 +56,11 @@ private slots: ...@@ -56,6 +56,11 @@ private slots:
void _selectSavedFilesDirectory(void); void _selectSavedFilesDirectory(void);
void _validateBeforeClose(void); void _validateBeforeClose(void);
void on_showGPS_clicked(bool checked);
void on_showBattery_clicked(bool checked);
void on_showMessages_clicked(bool checked);
void on_showMav_clicked(bool checked);
private: private:
MainWindow* _mainWindow; MainWindow* _mainWindow;
Ui::SettingsDialog* _ui; Ui::SettingsDialog* _ui;
......
This diff is collapsed.
...@@ -57,6 +57,10 @@ MainToolBar::MainToolBar(QWidget* parent) ...@@ -57,6 +57,10 @@ MainToolBar::MainToolBar(QWidget* parent)
, _satelliteCount(-1) , _satelliteCount(-1)
, _dotsPerInch(96.0) // Default to Windows as it's more likely not to report below , _dotsPerInch(96.0) // Default to Windows as it's more likely not to report below
, _satelliteLock(0) , _satelliteLock(0)
, _showGPS(true)
, _showMav(true)
, _showMessages(true)
, _showBattery(true)
, _rollDownMessages(0) , _rollDownMessages(0)
{ {
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
...@@ -76,7 +80,16 @@ MainToolBar::MainToolBar(QWidget* parent) ...@@ -76,7 +80,16 @@ MainToolBar::MainToolBar(QWidget* parent)
} else { } else {
qWarning() << "System not reporting logical DPI, which is used to compute the appropriate font size. The default being used is 96dpi. If the text within buttons and UI elements are too big or too small, that's the reason."; qWarning() << "System not reporting logical DPI, which is used to compute the appropriate font size. The default being used is 96dpi. If the text within buttons and UI elements are too big or too small, that's the reason.";
} }
// Give the QML code a way to reach us
// Tool Bar Preferences
QSettings settings;
settings.beginGroup(TOOL_BAR_SETTINGS_GROUP);
_showBattery = settings.value(TOOL_BAR_SHOW_BATTERY, true).toBool();
_showGPS = settings.value(TOOL_BAR_SHOW_GPS, true).toBool();
_showMav = settings.value(TOOL_BAR_SHOW_MAV, true).toBool();
_showMessages = settings.value(TOOL_BAR_SHOW_MESSAGES, true).toBool();
settings.endGroup();
setContextPropertyObject("mainToolBar", this); setContextPropertyObject("mainToolBar", this);
setSource(QUrl::fromUserInput("qrc:/qml/MainToolBar.qml")); setSource(QUrl::fromUserInput("qrc:/qml/MainToolBar.qml"));
setVisible(true); setVisible(true);
...@@ -97,6 +110,32 @@ MainToolBar::~MainToolBar() ...@@ -97,6 +110,32 @@ MainToolBar::~MainToolBar()
} }
void MainToolBar::_setToolBarState(const QString& key, bool value)
{
QSettings settings;
settings.beginGroup(TOOL_BAR_SETTINGS_GROUP);
settings.setValue(key, value);
settings.endGroup();
if(key == TOOL_BAR_SHOW_GPS) {
_showGPS = value;
emit showGPSChanged(value);
} else if(key == TOOL_BAR_SHOW_MAV) {
_showMav = value;
emit showMavChanged(value);
}else if(key == TOOL_BAR_SHOW_BATTERY) {
_showBattery = value;
emit showBatteryChanged(value);
} else if(key == TOOL_BAR_SHOW_MESSAGES) {
_showMessages = value;
emit showMessagesChanged(value);
}
}
void MainToolBar::viewStateChanged(const QString &key, bool value)
{
_setToolBarState(key, value);
}
void MainToolBar::onSetupView() void MainToolBar::onSetupView()
{ {
setCurrentView(ViewSetup); setCurrentView(ViewSetup);
......
...@@ -32,6 +32,12 @@ This file is part of the QGROUNDCONTROL project ...@@ -32,6 +32,12 @@ This file is part of the QGROUNDCONTROL project
#include "QGCQmlWidgetHolder.h" #include "QGCQmlWidgetHolder.h"
#define TOOL_BAR_SETTINGS_GROUP "TOOLBAR_SETTINGS_GROUP"
#define TOOL_BAR_SHOW_BATTERY "ShowBattery"
#define TOOL_BAR_SHOW_GPS "ShowGPS"
#define TOOL_BAR_SHOW_MAV "ShowMav"
#define TOOL_BAR_SHOW_MESSAGES "ShowMessages"
class UASInterface; class UASInterface;
class UASMessage; class UASMessage;
class UASMessageViewRollDown; class UASMessageViewRollDown;
...@@ -88,6 +94,10 @@ public: ...@@ -88,6 +94,10 @@ public:
Q_PROPERTY(QString currentState READ currentState NOTIFY currentStateChanged) Q_PROPERTY(QString currentState READ currentState NOTIFY currentStateChanged)
Q_PROPERTY(double dotsPerInch READ dotsPerInch NOTIFY dotsPerInchChanged) Q_PROPERTY(double dotsPerInch READ dotsPerInch NOTIFY dotsPerInchChanged)
Q_PROPERTY(int satelliteLock READ satelliteLock NOTIFY satelliteLockChanged) Q_PROPERTY(int satelliteLock READ satelliteLock NOTIFY satelliteLockChanged)
Q_PROPERTY(bool showGPS READ showGPS NOTIFY showGPSChanged)
Q_PROPERTY(bool showMav READ showMav NOTIFY showMavChanged)
Q_PROPERTY(bool showMessages READ showMessages NOTIFY showMessagesChanged)
Q_PROPERTY(bool showBattery READ showBattery NOTIFY showBatteryChanged)
int connectionCount () { return _connectionCount; } int connectionCount () { return _connectionCount; }
double batteryVoltage () { return _batteryVoltage; } double batteryVoltage () { return _batteryVoltage; }
...@@ -108,8 +118,13 @@ public: ...@@ -108,8 +118,13 @@ public:
QString currentState () { return _currentState; } QString currentState () { return _currentState; }
double dotsPerInch () { return _dotsPerInch; } double dotsPerInch () { return _dotsPerInch; }
int satelliteLock () { return _satelliteLock; } int satelliteLock () { return _satelliteLock; }
bool showGPS () { return _showGPS; }
bool showMav () { return _showMav; }
bool showMessages () { return _showMessages; }
bool showBattery () { return _showBattery; }
void setCurrentView (int currentView); void setCurrentView (int currentView);
void viewStateChanged (const QString& key, bool value);
signals: signals:
void connectionCountChanged (int count); void connectionCountChanged (int count);
...@@ -131,6 +146,10 @@ signals: ...@@ -131,6 +146,10 @@ signals:
void currentStateChanged (QString state); void currentStateChanged (QString state);
void dotsPerInchChanged (); void dotsPerInchChanged ();
void satelliteLockChanged (int lock); void satelliteLockChanged (int lock);
void showGPSChanged (bool value);
void showMavChanged (bool value);
void showMessagesChanged (bool value);
void showBatteryChanged (bool value);
private slots: private slots:
void _setActiveUAS (UASInterface* active); void _setActiveUAS (UASInterface* active);
...@@ -154,6 +173,7 @@ private slots: ...@@ -154,6 +173,7 @@ private slots:
private: private:
void _updateConnection (LinkInterface *disconnectedLink = NULL); void _updateConnection (LinkInterface *disconnectedLink = NULL);
void _setToolBarState (const QString& key, bool value);
private: private:
UASInterface* _mav; UASInterface* _mav;
...@@ -183,6 +203,10 @@ private: ...@@ -183,6 +203,10 @@ private:
QStringList _connectedList; QStringList _connectedList;
qreal _dotsPerInch; qreal _dotsPerInch;
int _satelliteLock; int _satelliteLock;
bool _showGPS;
bool _showMav;
bool _showMessages;
bool _showBattery;
UASMessageViewRollDown* _rollDownMessages; UASMessageViewRollDown* _rollDownMessages;
}; };
......
...@@ -190,7 +190,7 @@ Rectangle { ...@@ -190,7 +190,7 @@ Rectangle {
id: messages id: messages
width: (mainToolBar.newMessageCount > 99) ? 70 : 60 width: (mainToolBar.newMessageCount > 99) ? 70 : 60
height: cellHeight height: cellHeight
visible: (mainToolBar.connectionCount > 0) visible: (mainToolBar.connectionCount > 0) && (mainToolBar.showMessages)
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
color: getMessageColor() color: getMessageColor()
radius: cellRadius radius: cellRadius
...@@ -266,7 +266,7 @@ Rectangle { ...@@ -266,7 +266,7 @@ Rectangle {
id: mavIcon id: mavIcon
width: cellHeight width: cellHeight
height: cellHeight height: cellHeight
visible: showMavStatus() visible: showMavStatus() && (mainToolBar.showMav)
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
color: colorBlue color: colorBlue
radius: cellRadius radius: cellRadius
...@@ -285,7 +285,7 @@ Rectangle { ...@@ -285,7 +285,7 @@ Rectangle {
id: satelitte id: satelitte
width: 60 width: 60
height: cellHeight height: cellHeight
visible: showMavStatus(); visible: showMavStatus() && (mainToolBar.showGPS)
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
color: getSatelliteColor(); color: getSatelliteColor();
radius: cellRadius radius: cellRadius
...@@ -320,7 +320,7 @@ Rectangle { ...@@ -320,7 +320,7 @@ Rectangle {
id: battery id: battery
width: 80 width: 80
height: cellHeight height: cellHeight
visible: showMavStatus() visible: showMavStatus() && (mainToolBar.showBattery)
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
color: (mainToolBar.batteryPercent > 40.0 || mainToolBar.batteryPercent < 0.01) ? colorGreen : colorRed color: (mainToolBar.batteryPercent > 40.0 || mainToolBar.batteryPercent < 0.01) ? colorGreen : colorRed
radius: cellRadius radius: cellRadius
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment