Commit 768be0e5 authored by lm's avatar lm

Added style to preferences menu, added option to auto-reconnect link on startup

parent a11ca3da
...@@ -85,6 +85,7 @@ ...@@ -85,6 +85,7 @@
<file>images/earth.html</file> <file>images/earth.html</file>
<file>images/mapproviders/googleearth.svg</file> <file>images/mapproviders/googleearth.svg</file>
<file>images/contrib/slugs.png</file> <file>images/contrib/slugs.png</file>
<file>images/style-outdoor.css</file>
</qresource> </qresource>
<qresource prefix="/general"> <qresource prefix="/general">
<file alias="vera.ttf">images/Vera.ttf</file> <file alias="vera.ttf">images/Vera.ttf</file>
......
...@@ -16,8 +16,10 @@ namespace QGC ...@@ -16,8 +16,10 @@ namespace QGC
const QColor colorRed(154, 20, 20); const QColor colorRed(154, 20, 20);
const QColor colorGreen(20, 200, 20); const QColor colorGreen(20, 200, 20);
const QColor colorYellow(255, 255, 0); const QColor colorYellow(255, 255, 0);
const QColor colorOrange(255, 140, 0);
const QColor colorDarkYellow(180, 180, 0); const QColor colorDarkYellow(180, 180, 0);
const QColor colorBackground("#050508"); const QColor colorBackground("#050508");
const QColor colorBlack(0, 0, 0);
/** @brief Get the current ground time in microseconds */ /** @brief Get the current ground time in microseconds */
quint64 groundTimeUsecs(); quint64 groundTimeUsecs();
......
...@@ -39,22 +39,12 @@ SerialLink::SerialLink(QString portname, BaudRateType baudrate, FlowType flow, P ...@@ -39,22 +39,12 @@ SerialLink::SerialLink(QString portname, BaudRateType baudrate, FlowType flow, P
// Set unique ID and add link to the list of links // Set unique ID and add link to the list of links
this->id = getNextLinkId(); this->id = getNextLinkId();
// *nix (Linux, MacOS tested) serial port support
// port = new QextSerialPort(porthandle, QextSerialPort::Polling);
//port = new QextSerialPort(porthandle, QextSerialPort::EventDriven);
this->baudrate = baudrate; this->baudrate = baudrate;
this->flow = flow; this->flow = flow;
this->parity = parity; this->parity = parity;
this->dataBits = dataBits; this->dataBits = dataBits;
this->stopBits = stopBits; this->stopBits = stopBits;
this->timeout = 1; ///< The timeout controls how long the program flow should wait for new serial bytes. As we're polling, we don't want to wait at all. this->timeout = 1; ///< The timeout controls how long the program flow should wait for new serial bytes. As we're polling, we don't want to wait at all.
// port->setTimeout(timeout); // Timeout of 0 ms, we don't want to wait for data, we just poll again next time
// port->setBaudRate(baudrate);
// port->setFlowControl(flow);
// port->setParity(parity);
// port->setDataBits(dataBits);
// port->setStopBits(stopBits);
// Set the port name // Set the port name
if (porthandle == "") if (porthandle == "")
...@@ -103,7 +93,7 @@ void SerialLink::loadSettings() ...@@ -103,7 +93,7 @@ void SerialLink::loadSettings()
settings.sync(); settings.sync();
if (settings.contains("SERIALLINK_COMM_PORT")) if (settings.contains("SERIALLINK_COMM_PORT"))
{ {
setPortName(settings.value("SERIALLINK_COMM_PORT").toString()); if (porthandle == "") setPortName(settings.value("SERIALLINK_COMM_PORT").toString());
setBaudRateType(settings.value("SERIALLINK_COMM_BAUD").toInt()); setBaudRateType(settings.value("SERIALLINK_COMM_BAUD").toInt());
setParityType(settings.value("SERIALLINK_COMM_PARITY").toInt()); setParityType(settings.value("SERIALLINK_COMM_PARITY").toInt());
setStopBits(settings.value("SERIALLINK_COMM_STOPBITS").toInt()); setStopBits(settings.value("SERIALLINK_COMM_STOPBITS").toInt());
......
...@@ -772,7 +772,7 @@ void DebugConsole::setConnectionState(bool connected) ...@@ -772,7 +772,7 @@ void DebugConsole::setConnectionState(bool connected)
else else
{ {
m_ui->connectButton->setText(tr("Connect")); m_ui->connectButton->setText(tr("Connect"));
m_ui->receiveText->appendHtml(QString("<font color=\"%1\">%2</font>\n").arg(QGC::colorYellow.name(), tr("Link %1 is unconnected.").arg(currLink->getName()))); m_ui->receiveText->appendHtml(QString("<font color=\"%1\">%2</font>\n").arg(QGC::colorOrange.name(), tr("Link %1 is unconnected.").arg(currLink->getName())));
} }
} }
......
...@@ -104,6 +104,9 @@ HSIDisplay::HSIDisplay(QWidget *parent) : ...@@ -104,6 +104,9 @@ HSIDisplay::HSIDisplay(QWidget *parent) :
columns = 1; columns = 1;
this->setAutoFillBackground(true); this->setAutoFillBackground(true);
QPalette pal = palette();
pal.setColor(backgroundRole(), QGC::colorBlack);
setPalette(pal);
vwidth = 80.0f; vwidth = 80.0f;
vheight = 80.0f; vheight = 80.0f;
......
...@@ -68,8 +68,11 @@ MainWindow::MainWindow(QWidget *parent): ...@@ -68,8 +68,11 @@ MainWindow::MainWindow(QWidget *parent):
currentView(VIEW_UNCONNECTED), currentView(VIEW_UNCONNECTED),
aboutToCloseFlag(false), aboutToCloseFlag(false),
changingViewsFlag(false), changingViewsFlag(false),
styleFileName(QCoreApplication::applicationDirPath() + "/style-indoor.css") styleFileName(QCoreApplication::applicationDirPath() + "/style-indoor.css"),
autoReconnect(false),
currentStyle(QGC_MAINWINDOW_STYLE_INDOOR)
{ {
loadSettings();
if (!settings.contains("CURRENT_VIEW")) if (!settings.contains("CURRENT_VIEW"))
{ {
// Set this view as default view // Set this view as default view
...@@ -104,18 +107,20 @@ MainWindow::MainWindow(QWidget *parent): ...@@ -104,18 +107,20 @@ MainWindow::MainWindow(QWidget *parent):
configureWindowName(); configureWindowName();
// Set the application style (not the same as a style sheet) loadStyle(currentStyle);
// Set the style to Plastique
qApp->setStyle("plastique");
// Set style sheet as last step // // Set the application style (not the same as a style sheet)
QFile* styleSheet = new QFile(":/images/style-mission.css"); // // Set the style to Plastique
if (styleSheet->open(QIODevice::ReadOnly | QIODevice::Text)) // qApp->setStyle("plastique");
{
QString style = QString(styleSheet->readAll()); // // Set style sheet as last step
style.replace("ICONDIR", QCoreApplication::applicationDirPath()+ "/images/"); // QFile* styleSheet = new QFile(":/images/style-mission.css");
qApp->setStyleSheet(style); // if (styleSheet->open(QIODevice::ReadOnly | QIODevice::Text))
} // {
// QString style = QString(styleSheet->readAll());
// style.replace("ICONDIR", QCoreApplication::applicationDirPath()+ "/images/");
// qApp->setStyleSheet(style);
// }
// Create actions // Create actions
connectCommonActions(); connectCommonActions();
...@@ -157,10 +162,23 @@ MainWindow::MainWindow(QWidget *parent): ...@@ -157,10 +162,23 @@ MainWindow::MainWindow(QWidget *parent):
// Enable and update view // Enable and update view
presentView(); presentView();
// Connect link
if (autoReconnect)
{
SerialLink* link = new SerialLink();
// Add to registry
LinkManager::instance()->add(link);
LinkManager::instance()->addProtocol(link, mavlink);
link->connect();
}
} }
MainWindow::~MainWindow() MainWindow::~MainWindow()
{ {
// Store settings
storeSettings();
delete mavlink; delete mavlink;
delete joystick; delete joystick;
...@@ -918,17 +936,9 @@ QString MainWindow::buildMenuKey(SETTINGS_SECTIONS section, TOOLS_WIDGET_NAMES t ...@@ -918,17 +936,9 @@ QString MainWindow::buildMenuKey(SETTINGS_SECTIONS section, TOOLS_WIDGET_NAMES t
void MainWindow::closeEvent(QCloseEvent *event) void MainWindow::closeEvent(QCloseEvent *event)
{ {
settings.setValue(getWindowGeometryKey(), saveGeometry()); storeSettings();
//settings.setValue("windowState", saveState());
aboutToCloseFlag = true; aboutToCloseFlag = true;
mavlink->storeSettings(); mavlink->storeSettings();
// Save the last current view in any case
settings.setValue("CURRENT_VIEW", currentView);
// Save the current window state, but only if a system is connected (else no real number of widgets would be present)
if (UASManager::instance()->getUASList().length() > 0) settings.setValue(getWindowStateKey(), saveState(QGC::applicationVersion()));
// Save the current view only if a UAS is connected
if (UASManager::instance()->getUASList().length() > 0) settings.setValue("CURRENT_VIEW_WITH_UAS_CONNECTED", currentView);
settings.sync();
QMainWindow::closeEvent(event); QMainWindow::closeEvent(event);
} }
...@@ -1113,6 +1123,32 @@ void MainWindow::arrangeSlugsCenterStack() ...@@ -1113,6 +1123,32 @@ void MainWindow::arrangeSlugsCenterStack()
} }
void MainWindow::loadSettings()
{
QSettings settings;
settings.beginGroup("QGC_MAINWINDOW");
autoReconnect = settings.value("AUTO_RECONNECT", autoReconnect).toBool();
currentStyle = (QGC_MAINWINDOW_STYLE)settings.value("CURRENT_STYLE", currentStyle).toInt();
settings.endGroup();
}
void MainWindow::storeSettings()
{
QSettings settings;
settings.beginGroup("QGC_MAINWINDOW");
settings.setValue("AUTO_RECONNECT", autoReconnect);
settings.setValue("CURRENT_STYLE", currentStyle);
settings.endGroup();
settings.setValue(getWindowGeometryKey(), saveGeometry());
// Save the last current view in any case
settings.setValue("CURRENT_VIEW", currentView);
// Save the current window state, but only if a system is connected (else no real number of widgets would be present)
if (UASManager::instance()->getUASList().length() > 0) settings.setValue(getWindowStateKey(), saveState(QGC::applicationVersion()));
// Save the current view only if a UAS is connected
if (UASManager::instance()->getUASList().length() > 0) settings.setValue("CURRENT_VIEW_WITH_UAS_CONNECTED", currentView);
settings.sync();
}
void MainWindow::configureWindowName() void MainWindow::configureWindowName()
{ {
QList<QHostAddress> hostAddresses = QNetworkInterface::allAddresses(); QList<QHostAddress> hostAddresses = QNetworkInterface::allAddresses();
...@@ -1176,6 +1212,57 @@ void MainWindow::saveScreen() ...@@ -1176,6 +1212,57 @@ void MainWindow::saveScreen()
} }
} }
void MainWindow::enableAutoReconnect(bool enabled)
{
autoReconnect = enabled;
}
void MainWindow::loadNativeStyle()
{
loadStyle(QGC_MAINWINDOW_STYLE_NATIVE);
}
void MainWindow::loadIndoorStyle()
{
loadStyle(QGC_MAINWINDOW_STYLE_INDOOR);
}
void MainWindow::loadOutdoorStyle()
{
loadStyle(QGC_MAINWINDOW_STYLE_OUTDOOR);
}
void MainWindow::loadStyle(QGC_MAINWINDOW_STYLE style)
{
switch (style)
{
case QGC_MAINWINDOW_STYLE_NATIVE:
{
// Native mode means setting no style
// so if we were already in native mode
// take no action
// Only if a style was set, remove it.
if (style != currentStyle)
{
qApp->setStyleSheet("");
showInfoMessage(tr("Please restart QGroundControl"), tr("Please restart QGroundControl to switch to fully native look and feel. Currently you have loaded Qt's plastique style."));
}
}
break;
case QGC_MAINWINDOW_STYLE_INDOOR:
qApp->setStyle("plastique");
styleFileName = ":/images/style-mission.css";
reloadStylesheet();
break;
case QGC_MAINWINDOW_STYLE_OUTDOOR:
qApp->setStyle("plastique");
styleFileName = ":/images/style-outdoor.css";
reloadStylesheet();
break;
}
currentStyle = style;
}
void MainWindow::selectStylesheet() void MainWindow::selectStylesheet()
{ {
// Let user select style sheet // Let user select style sheet
...@@ -1451,9 +1538,30 @@ void MainWindow::addLink() ...@@ -1451,9 +1538,30 @@ void MainWindow::addLink()
void MainWindow::addLink(LinkInterface *link) void MainWindow::addLink(LinkInterface *link)
{ {
// IMPORTANT! KEEP THESE TWO LINES
// THEY MAKE SURE THE LINK IS PROPERLY REGISTERED
// BEFORE LINKING THE UI AGAINST IT
// Register (does nothing if already registered)
LinkManager::instance()->add(link); LinkManager::instance()->add(link);
LinkManager::instance()->addProtocol(link, mavlink); LinkManager::instance()->addProtocol(link, mavlink);
// Go fishing for this link's configuration window
QList<QAction*> actions = ui.menuNetwork->actions();
bool found = false;
foreach (QAction* act, actions)
{
if (act->data().toInt() == LinkManager::instance()->getLinks().indexOf(link))
{
found = true;
}
}
UDPLink* udp = dynamic_cast<UDPLink*>(link);
if (!found || udp)
{
CommConfigurationWindow* commWidget = new CommConfigurationWindow(link, mavlink, this); CommConfigurationWindow* commWidget = new CommConfigurationWindow(link, mavlink, this);
QAction* action = commWidget->getAction(); QAction* action = commWidget->getAction();
ui.menuNetwork->addAction(action); ui.menuNetwork->addAction(action);
...@@ -1467,6 +1575,7 @@ void MainWindow::addLink(LinkInterface *link) ...@@ -1467,6 +1575,7 @@ void MainWindow::addLink(LinkInterface *link)
//connect(sim, SIGNAL(valueChanged(int,QString,double,quint64)), linechart, SLOT(appendData(int,QString,double,quint64))); //connect(sim, SIGNAL(valueChanged(int,QString,double,quint64)), linechart, SLOT(appendData(int,QString,double,quint64)));
connect(ui.actionSimulate, SIGNAL(triggered(bool)), sim, SLOT(connectLink(bool))); connect(ui.actionSimulate, SIGNAL(triggered(bool)), sim, SLOT(connectLink(bool)));
} }
}
} }
void MainWindow::setActiveUAS(UASInterface* uas) void MainWindow::setActiveUAS(UASInterface* uas)
......
...@@ -88,6 +88,18 @@ public: ...@@ -88,6 +88,18 @@ public:
static MainWindow* instance(); static MainWindow* instance();
~MainWindow(); ~MainWindow();
enum QGC_MAINWINDOW_STYLE
{
QGC_MAINWINDOW_STYLE_NATIVE,
QGC_MAINWINDOW_STYLE_INDOOR,
QGC_MAINWINDOW_STYLE_OUTDOOR
};
/** @brief Get current visual style */
int getStyle() { return currentStyle; }
/** @brief Get auto link reconnect setting */
bool autoReconnectEnabled() { return autoReconnect; }
public slots: public slots:
// /** @brief Store the mainwindow settings */ // /** @brief Store the mainwindow settings */
// void storeSettings(); // void storeSettings();
...@@ -142,32 +154,25 @@ public slots: ...@@ -142,32 +154,25 @@ public slots:
void reloadStylesheet(); void reloadStylesheet();
/** @brief Let the user select the CSS style sheet */ /** @brief Let the user select the CSS style sheet */
void selectStylesheet(); void selectStylesheet();
/** @brief Automatically reconnect last link */
void enableAutoReconnect(bool enabled);
/** @brief Switch to native application style */
void loadNativeStyle();
/** @brief Switch to indoor mission style */
void loadIndoorStyle();
/** @brief Switch to outdoor mission style */
void loadOutdoorStyle();
/** @brief Load a specific style */
void loadStyle(QGC_MAINWINDOW_STYLE style);
/** @brief Add a custom tool widget */ /** @brief Add a custom tool widget */
void createCustomWidget(); void createCustomWidget();
void closeEvent(QCloseEvent* event); void closeEvent(QCloseEvent* event);
/*
==========================================================
Potentially Deprecated
==========================================================
*/
// void loadWidgets();
/** @brief Load data view, allowing to plot flight data */ /** @brief Load data view, allowing to plot flight data */
void loadDataView(QString fileName); void loadDataView(QString fileName);
// /** @brief Load 3D map view */
// void load3DMapView();
// /** @brief Load 3D Google Earth view */
// void loadGoogleEarthView();
// /** @brief Load 3D view */
// void load3DView();
/** /**
* @brief Shows a Docked Widget based on the action sender * @brief Shows a Docked Widget based on the action sender
* *
...@@ -343,6 +348,8 @@ protected: ...@@ -343,6 +348,8 @@ protected:
void configureWindowName(); void configureWindowName();
void loadSettings();
void storeSettings();
// TODO Should be moved elsewhere, as the protocol does not belong to the UI // TODO Should be moved elsewhere, as the protocol does not belong to the UI
MAVLinkProtocol* mavlink; MAVLinkProtocol* mavlink;
...@@ -417,6 +424,8 @@ protected: ...@@ -417,6 +424,8 @@ protected:
QString screenFileName; QString screenFileName;
QTimer* videoTimer; QTimer* videoTimer;
QString styleFileName; QString styleFileName;
bool autoReconnect;
QGC_MAINWINDOW_STYLE currentStyle;
private: private:
Ui::MainWindow ui; Ui::MainWindow ui;
......
#include <QSettings>
#include "QGCSettingsWidget.h" #include "QGCSettingsWidget.h"
#include "MainWindow.h"
#include "ui_QGCSettingsWidget.h" #include "ui_QGCSettingsWidget.h"
#include "LinkManager.h" #include "LinkManager.h"
...@@ -33,6 +36,28 @@ QGCSettingsWidget::QGCSettingsWidget(QWidget *parent, Qt::WindowFlags flags) : ...@@ -33,6 +36,28 @@ QGCSettingsWidget::QGCSettingsWidget(QWidget *parent, Qt::WindowFlags flags) :
connect(ui->audioMuteCheckBox, SIGNAL(toggled(bool)), GAudioOutput::instance(), SLOT(mute(bool))); connect(ui->audioMuteCheckBox, SIGNAL(toggled(bool)), GAudioOutput::instance(), SLOT(mute(bool)));
connect(GAudioOutput::instance(), SIGNAL(mutedChanged(bool)), ui->audioMuteCheckBox, SLOT(setChecked(bool))); connect(GAudioOutput::instance(), SIGNAL(mutedChanged(bool)), ui->audioMuteCheckBox, SLOT(setChecked(bool)));
// Reconnect
ui->reconnectCheckBox->setChecked(MainWindow::instance()->autoReconnectEnabled());
connect(ui->reconnectCheckBox, SIGNAL(clicked(bool)), MainWindow::instance(), SLOT(enableAutoReconnect(bool)));
// Style
MainWindow::QGC_MAINWINDOW_STYLE style = (MainWindow::QGC_MAINWINDOW_STYLE)MainWindow::instance()->getStyle();
switch (style)
{
case MainWindow::QGC_MAINWINDOW_STYLE_NATIVE:
ui->nativeStyle->setChecked(true);
break;
case MainWindow::QGC_MAINWINDOW_STYLE_INDOOR:
ui->indoorStyle->setChecked(true);
break;
case MainWindow::QGC_MAINWINDOW_STYLE_OUTDOOR:
ui->outdoorStyle->setChecked(true);
break;
}
connect(ui->nativeStyle, SIGNAL(clicked()), MainWindow::instance(), SLOT(loadNativeStyle()));
connect(ui->indoorStyle, SIGNAL(clicked()), MainWindow::instance(), SLOT(loadIndoorStyle()));
connect(ui->outdoorStyle, SIGNAL(clicked()), MainWindow::instance(), SLOT(loadOutdoorStyle()));
// Close / destroy // Close / destroy
connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(deleteLater())); connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(deleteLater()));
......
...@@ -15,6 +15,8 @@ public: ...@@ -15,6 +15,8 @@ public:
QGCSettingsWidget(QWidget *parent = 0, Qt::WindowFlags flags = Qt::Sheet); QGCSettingsWidget(QWidget *parent = 0, Qt::WindowFlags flags = Qt::Sheet);
~QGCSettingsWidget(); ~QGCSettingsWidget();
public slots:
private: private:
Ui::QGCSettingsWidget *ui; Ui::QGCSettingsWidget *ui;
}; };
......
...@@ -35,6 +35,41 @@ ...@@ -35,6 +35,41 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="0">
<widget class="QCheckBox" name="reconnectCheckBox">
<property name="text">
<string>Automatically reconnect last link on application startup</string>
</property>
<property name="icon">
<iconset resource="../../mavground.qrc">
<normaloff>:/images/devices/network-wireless.svg</normaloff>:/images/devices/network-wireless.svg</iconset>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QRadioButton" name="nativeStyle">
<property name="text">
<string>Use native platform look and feel (Windows/Linux/Mac OS)</string>
</property>
<property name="autoExclusive">
<bool>true</bool>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QRadioButton" name="indoorStyle">
<property name="text">
<string>Use indoor mission style (black background)</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QRadioButton" name="outdoorStyle">
<property name="text">
<string>Use outdoor mission style (light background)</string>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
</widget> </widget>
......
...@@ -334,6 +334,7 @@ void WaypointView::updateFrameView(int frame) ...@@ -334,6 +334,7 @@ void WaypointView::updateFrameView(int frame)
void WaypointView::deleted(QObject* waypoint) void WaypointView::deleted(QObject* waypoint)
{ {
Q_UNUSED(waypoint);
// if (waypoint == this->wp) // if (waypoint == this->wp)
// { // {
// deleteLater(); // deleteLater();
......
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