Commit 3d1a54df authored by Bryant's avatar Bryant

The HUD now responds to changes in the MainWindow theme.

parent fc3080e8
...@@ -34,8 +34,8 @@ This file is part of the QGROUNDCONTROL project ...@@ -34,8 +34,8 @@ This file is part of the QGROUNDCONTROL project
#include <QMenu> #include <QMenu>
#include <QDesktopServices> #include <QDesktopServices>
#include <QFileDialog> #include <QFileDialog>
#include <QDebug> #include <QDebug>
#include <cmath> #include <cmath>
#include <qmath.h> #include <qmath.h>
#include <limits> #include <limits>
...@@ -130,42 +130,9 @@ HUD::HUD(int width, int height, QWidget* parent) ...@@ -130,42 +130,9 @@ HUD::HUD(int width, int height, QWidget* parent)
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
scalingFactor = this->width()/vwidth; scalingFactor = this->width()/vwidth;
// Generate a background image that's dependent on the current color scheme. // Set up the initial color theme. This can be updated by a styleChanged
QImage fill = QImage(width, height, QImage::Format_Indexed8); // signal from MainWindow.
if (((MainWindow*)parent)->getStyle() == MainWindow::QGC_MAINWINDOW_STYLE_LIGHT) styleChanged(((MainWindow*)parent)->getStyle());
{
fill.fill(255);
}
else
{
fill.fill(0);
}
glImage = QGLWidget::convertToGLFormat(fill);
// Now set the other default colors based on the current color scheme.
if (((MainWindow*)parent)->getStyle() == MainWindow::QGC_MAINWINDOW_STYLE_LIGHT)
{
defaultColor = QColor(0x01, 0x47, 0x01);
setPointColor = QColor(0x82, 0x17, 0x82);
warningColor = Qt::darkYellow;
criticalColor = Qt::darkRed;
infoColor = QColor(0x07, 0x82, 0x07);
fuelColor = criticalColor;
}
else
{
defaultColor = QColor(70, 200, 70);
setPointColor = QColor(200, 20, 200);
warningColor = Qt::yellow;
criticalColor = Qt::red;
infoColor = QColor(20, 200, 20);
fuelColor = criticalColor;
}
//QString imagePath = "/Users/user/Desktop/frame0000.png";
//qDebug() << __FILE__ << __LINE__ << "template image:" << imagePath;
//fill = QImage(imagePath);
// Refresh timer // Refresh timer
refreshTimer->setInterval(updateInterval); refreshTimer->setInterval(updateInterval);
...@@ -173,14 +140,6 @@ HUD::HUD(int width, int height, QWidget* parent) ...@@ -173,14 +140,6 @@ HUD::HUD(int width, int height, QWidget* parent)
// Resize to correct size and fill with image // Resize to correct size and fill with image
resize(this->width(), this->height()); resize(this->width(), this->height());
//glDrawPixels(glImage.width(), glImage.height(), GL_RGBA, GL_UNSIGNED_BYTE, glImage.bits());
// Set size once
//setFixedSize(fill.size());
//setMinimumSize(fill.size());
//setMaximumSize(fill.size());
// Lock down the size
//setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
fontDatabase = QFontDatabase(); fontDatabase = QFontDatabase();
const QString fontFileName = ":/general/vera.ttf"; ///< Font file is part of the QRC file and compiled into the app const QString fontFileName = ":/general/vera.ttf"; ///< Font file is part of the QRC file and compiled into the app
...@@ -196,6 +155,11 @@ HUD::HUD(int width, int height, QWidget* parent) ...@@ -196,6 +155,11 @@ HUD::HUD(int width, int height, QWidget* parent)
if (font.family() != fontFamilyName) qDebug() << "ERROR! WRONG FONT LOADED: " << fontFamilyName; if (font.family() != fontFamilyName) qDebug() << "ERROR! WRONG FONT LOADED: " << fontFamilyName;
} }
// Connect the themeChanged signal from the MainWindow to this widget, so it
// can change it's styling accordingly.
connect((MainWindow*)parent, SIGNAL(styleChanged(MainWindow::QGC_MAINWINDOW_STYLE)),
this, SLOT(styleChanged(MainWindow::QGC_MAINWINDOW_STYLE)));
// Connect with UAS // Connect with UAS
connect(UASManager::instance(), SIGNAL(activeUASSet(UASInterface*)), this, SLOT(setActiveUAS(UASInterface*))); connect(UASManager::instance(), SIGNAL(activeUASSet(UASInterface*)), this, SLOT(setActiveUAS(UASInterface*)));
...@@ -214,6 +178,41 @@ QSize HUD::sizeHint() const ...@@ -214,6 +178,41 @@ QSize HUD::sizeHint() const
return QSize(width(), (width()*3.0f)/4); return QSize(width(), (width()*3.0f)/4);
} }
void HUD::styleChanged(MainWindow::QGC_MAINWINDOW_STYLE newTheme)
{
// Generate a background image that's dependent on the current color scheme.
QImage fill = QImage(width(), height(), QImage::Format_Indexed8);
if (newTheme == MainWindow::QGC_MAINWINDOW_STYLE_LIGHT)
{
fill.fill(255);
}
else
{
fill.fill(0);
}
glImage = QGLWidget::convertToGLFormat(fill);
// Now set the other default colors based on the current color scheme.
if (newTheme == MainWindow::QGC_MAINWINDOW_STYLE_LIGHT)
{
defaultColor = QColor(0x01, 0x47, 0x01);
setPointColor = QColor(0x82, 0x17, 0x82);
warningColor = Qt::darkYellow;
criticalColor = Qt::darkRed;
infoColor = QColor(0x07, 0x82, 0x07);
fuelColor = criticalColor;
}
else
{
defaultColor = QColor(70, 200, 70);
setPointColor = QColor(200, 20, 200);
warningColor = Qt::yellow;
criticalColor = Qt::red;
infoColor = QColor(20, 200, 20);
fuelColor = criticalColor;
}
}
void HUD::showEvent(QShowEvent* event) void HUD::showEvent(QShowEvent* event)
{ {
// React only to internal (pre-display) // React only to internal (pre-display)
......
...@@ -39,6 +39,7 @@ This file is part of the QGROUNDCONTROL project ...@@ -39,6 +39,7 @@ This file is part of the QGROUNDCONTROL project
#include <QTimer> #include <QTimer>
#include <QVector3D> #include <QVector3D>
#include "UASInterface.h" #include "UASInterface.h"
#include "MainWindow.h"
/** /**
* @brief Displays a Head Up Display (HUD) * @brief Displays a Head Up Display (HUD)
...@@ -59,7 +60,7 @@ public: ...@@ -59,7 +60,7 @@ public:
public slots: public slots:
void initializeGL(); void initializeGL();
//void paintGL(); void styleChanged(MainWindow::QGC_MAINWINDOW_STYLE newTheme);
/** @brief Set the currently monitored UAS */ /** @brief Set the currently monitored UAS */
virtual void setActiveUAS(UASInterface* uas); virtual void setActiveUAS(UASInterface* uas);
......
...@@ -1260,6 +1260,10 @@ bool MainWindow::loadStyle(QGC_MAINWINDOW_STYLE style, QString cssFile) ...@@ -1260,6 +1260,10 @@ bool MainWindow::loadStyle(QGC_MAINWINDOW_STYLE style, QString cssFile)
darkStyleFileName = cssFile; darkStyleFileName = cssFile;
} }
// And trigger any changes to other UI elements that are watching for
// theme changes.
emit styleChanged(style);
// Finally restore the cursor before returning. // Finally restore the cursor before returning.
qApp->restoreOverrideCursor(); qApp->restoreOverrideCursor();
return true; return true;
......
...@@ -51,7 +51,6 @@ This file is part of the QGROUNDCONTROL project ...@@ -51,7 +51,6 @@ This file is part of the QGROUNDCONTROL project
#include "MAVLinkProtocol.h" #include "MAVLinkProtocol.h"
#include "MAVLinkSimulationLink.h" #include "MAVLinkSimulationLink.h"
#include "ObjectDetectionView.h" #include "ObjectDetectionView.h"
#include "HUD.h"
#include "submainwindow.h" #include "submainwindow.h"
#include "JoystickWidget.h" #include "JoystickWidget.h"
#include "input/JoystickInput.h" #include "input/JoystickInput.h"
...@@ -257,6 +256,7 @@ public slots: ...@@ -257,6 +256,7 @@ public slots:
void configureWindowName(); void configureWindowName();
signals: signals:
void styleChanged(MainWindow::QGC_MAINWINDOW_STYLE newTheme);
void initStatusChanged(const QString& message); void initStatusChanged(const QString& message);
#ifdef MOUSE_ENABLED_LINUX #ifdef MOUSE_ENABLED_LINUX
/** @brief Forward X11Event to catch 3DMouse inputs */ /** @brief Forward X11Event to catch 3DMouse inputs */
......
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