From 3d1a54df28b34f40fa9848bafee29d8b757f213f Mon Sep 17 00:00:00 2001 From: Bryant Date: Sun, 2 Jun 2013 09:51:07 -0700 Subject: [PATCH] The HUD now responds to changes in the MainWindow theme. --- src/ui/HUD.cc | 89 ++++++++++++++++++++++++++-------------------------- src/ui/HUD.h | 3 +- src/ui/MainWindow.cc | 4 +++ src/ui/MainWindow.h | 2 +- 4 files changed, 51 insertions(+), 47 deletions(-) diff --git a/src/ui/HUD.cc b/src/ui/HUD.cc index 806e7a4..fcd3b28 100644 --- a/src/ui/HUD.cc +++ b/src/ui/HUD.cc @@ -34,8 +34,8 @@ This file is part of the QGROUNDCONTROL project #include #include #include - #include + #include #include #include @@ -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) diff --git a/src/ui/HUD.h b/src/ui/HUD.h index 92c3d30..6356829 100644 --- a/src/ui/HUD.h +++ b/src/ui/HUD.h @@ -39,6 +39,7 @@ This file is part of the QGROUNDCONTROL project #include #include #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); diff --git a/src/ui/MainWindow.cc b/src/ui/MainWindow.cc index c5f311e..2bd1b83 100644 --- a/src/ui/MainWindow.cc +++ b/src/ui/MainWindow.cc @@ -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; diff --git a/src/ui/MainWindow.h b/src/ui/MainWindow.h index 3ec196f..ede1dff 100644 --- a/src/ui/MainWindow.h +++ b/src/ui/MainWindow.h @@ -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 */