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
#include <QMenu>
#include <QDesktopServices>
#include <QFileDialog>
#include <QDebug>
#include <cmath>
#include <qmath.h>
#include <limits>
......@@ -130,42 +130,9 @@ HUD::HUD(int width, int height, QWidget* parent)
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
scalingFactor = this->width()/vwidth;
// Generate a background image that's dependent on the current color scheme.
QImage fill = QImage(width, height, QImage::Format_Indexed8);
if (((MainWindow*)parent)->getStyle() == 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 (((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);
// Set up the initial color theme. This can be updated by a styleChanged
// signal from MainWindow.
styleChanged(((MainWindow*)parent)->getStyle());
// Refresh timer
refreshTimer->setInterval(updateInterval);
......@@ -173,14 +140,6 @@ HUD::HUD(int width, int height, QWidget* parent)
// Resize to correct size and fill with image
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();
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)
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(UASManager::instance(), SIGNAL(activeUASSet(UASInterface*)), this, SLOT(setActiveUAS(UASInterface*)));
......@@ -214,6 +178,41 @@ QSize HUD::sizeHint() const
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)
{
// React only to internal (pre-display)
......
......@@ -39,6 +39,7 @@ This file is part of the QGROUNDCONTROL project
#include <QTimer>
#include <QVector3D>
#include "UASInterface.h"
#include "MainWindow.h"
/**
* @brief Displays a Head Up Display (HUD)
......@@ -59,7 +60,7 @@ public:
public slots:
void initializeGL();
//void paintGL();
void styleChanged(MainWindow::QGC_MAINWINDOW_STYLE newTheme);
/** @brief Set the currently monitored UAS */
virtual void setActiveUAS(UASInterface* uas);
......
......@@ -1260,6 +1260,10 @@ bool MainWindow::loadStyle(QGC_MAINWINDOW_STYLE style, QString 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.
qApp->restoreOverrideCursor();
return true;
......
......@@ -51,7 +51,6 @@ This file is part of the QGROUNDCONTROL project
#include "MAVLinkProtocol.h"
#include "MAVLinkSimulationLink.h"
#include "ObjectDetectionView.h"
#include "HUD.h"
#include "submainwindow.h"
#include "JoystickWidget.h"
#include "input/JoystickInput.h"
......@@ -257,6 +256,7 @@ public slots:
void configureWindowName();
signals:
void styleChanged(MainWindow::QGC_MAINWINDOW_STYLE newTheme);
void initStatusChanged(const QString& message);
#ifdef MOUSE_ENABLED_LINUX
/** @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