From 9582bd5aba761244e68fb418c37040930a0f49dc Mon Sep 17 00:00:00 2001 From: Lorenz Meier Date: Sun, 9 Jun 2013 22:55:04 +0200 Subject: [PATCH] Removed OpenGL dependency in HUD, merged in HUD from Soren Kuula and config changes from Michael Carpenter --- files/styles/style-indoor.css | 3 - qgroundcontrol.pro | 2 + src/ui/HUD.cc | 167 ++-------------------------- src/ui/HUD.h | 9 +- src/ui/QGCRGBDView.cc | 6 +- src/ui/QGCToolBar.cc | 8 +- src/ui/UASRawStatusView.cpp | 5 +- src/ui/uas/UASQuickViewGaugeItem.cc | 25 +++++ src/ui/uas/UASQuickViewGaugeItem.h | 19 ++++ 9 files changed, 73 insertions(+), 171 deletions(-) create mode 100644 src/ui/uas/UASQuickViewGaugeItem.cc create mode 100644 src/ui/uas/UASQuickViewGaugeItem.h diff --git a/files/styles/style-indoor.css b/files/styles/style-indoor.css index f85124245..3da0058af 100644 --- a/files/styles/style-indoor.css +++ b/files/styles/style-indoor.css @@ -179,7 +179,6 @@ QDoubleSpinBox::down-button { QPushButton { min-height: 16px; - max-height: 20px; border: 1px solid #465158; margin: 1px; border-radius: 2px; @@ -203,8 +202,6 @@ QPushButton:pressed { QToolButton { font-weight: bold; min-height: 16px; - /*min-width: 24px;*/ - max-height: 20px; border: 1px solid #4A4A4F; margin: 1px; border-radius: 2px; diff --git a/qgroundcontrol.pro b/qgroundcontrol.pro index 3398c6e8f..91be4c17f 100644 --- a/qgroundcontrol.pro +++ b/qgroundcontrol.pro @@ -383,6 +383,7 @@ HEADERS += src/MG.h \ src/ui/uas/UASQuickViewItem.h \ src/ui/uas/UASQuickViewItemSelect.h \ src/ui/uas/UASQuickViewTextItem.h \ + src/ui/uas/UASQuickViewGaugeItem.h \ src/ui/uas/UASActionsWidget.h \ src/ui/designer/QGCRadioChannelDisplay.h \ src/ui/QGCTabbedInfoView.h \ @@ -557,6 +558,7 @@ SOURCES += src/main.cc \ src/ui/uas/UASQuickViewItem.cc \ src/ui/uas/UASQuickView.cc \ src/ui/uas/UASQuickViewTextItem.cc \ + src/ui/uas/UASQuickViewGaugeItem.cc \ src/ui/uas/UASQuickViewItemSelect.cc \ src/ui/uas/UASActionsWidget.cpp \ src/ui/designer/QGCRadioChannelDisplay.cpp \ diff --git a/src/ui/HUD.cc b/src/ui/HUD.cc index e4556ff62..815224445 100644 --- a/src/ui/HUD.cc +++ b/src/ui/HUD.cc @@ -60,7 +60,7 @@ This file is part of the QGROUNDCONTROL project * @param parent */ HUD::HUD(int width, int height, QWidget* parent) - : QGLWidget(QGLFormat(QGL::SampleBuffers), parent), + : QWidget(parent), uas(NULL), yawInt(0.0f), mode(tr("UNKNOWN MODE")), @@ -120,7 +120,7 @@ HUD::HUD(int width, int height, QWidget* parent) offlineDirectory(""), nextOfflineImage(""), HUDInstrumentsEnabled(true), - videoEnabled(false), + videoEnabled(true), xImageFactor(1.0), yImageFactor(1.0), imageRequested(false), @@ -147,14 +147,14 @@ HUD::HUD(int width, int height, QWidget* parent) //qDebug() << __FILE__ << __LINE__ << "template image:" << imagePath; //fill = QImage(imagePath); - glImage = QGLWidget::convertToGLFormat(fill); + glImage = fill; // Refresh timer refreshTimer->setInterval(updateInterval); connect(refreshTimer, SIGNAL(timeout()), this, SLOT(paintHUD())); // Resize to correct size and fill with image - resize(this->width(), this->height()); + QWidget::resize(this->width(), this->height()); //glDrawPixels(glImage.width(), glImage.height(), GL_RGBA, GL_UNSIGNED_BYTE, glImage.bits()); // Set size once @@ -200,7 +200,7 @@ void HUD::showEvent(QShowEvent* event) { // React only to internal (pre-display) // events - QGLWidget::showEvent(event); + QWidget::showEvent(event); refreshTimer->start(updateInterval); emit visibilityChanged(true); } @@ -210,7 +210,7 @@ void HUD::hideEvent(QHideEvent* event) // React only to internal (pre-display) // events refreshTimer->stop(); - QGLWidget::hideEvent(event); + QWidget::hideEvent(event); emit visibilityChanged(false); } @@ -447,73 +447,6 @@ float HUD::refToScreenY(float y) return (scalingFactor * y); } -/** - * This functions works in the OpenGL view, which is already translated by - * the x and y center offsets. - * - */ -void HUD::paintCenterBackground(float roll, float pitch, float yaw) -{ - Q_UNUSED(yaw); - - // Center indicator is 100 mm wide - float referenceWidth = 70.0; - float referenceHeight = 70.0; - - // HUD is assumed to be 200 x 150 mm - // so that positions can be hardcoded - // but can of course be scaled. - - double referencePositionX = vwidth / 2.0 - referenceWidth/2.0; - double referencePositionY = vheight / 2.0 - referenceHeight/2.0; - - //this->width()/2.0+(xCenterOffset*scalingFactor), this->height()/2.0+(yCenterOffset*scalingFactor); - - setupGLView(referencePositionX, referencePositionY, referenceWidth, referenceHeight); - - // Store current position in the model view - // the position will be restored after drawing - glMatrixMode(GL_MODELVIEW); - glPushMatrix(); - - // Move to the center of the window - glTranslatef(referenceWidth/2.0f,referenceHeight/2.0f,0); - - // Move based on the yaw difference - //glTranslatef(yaw, 0.0f, 0.0f); - - // Rotate based on the bank - glRotatef((roll/M_PI)*180.0f, 0.0f, 0.0f, 1.0f); - - // Translate in the direction of the rotation based - // on the pitch. On the 777, a pitch of 1 degree = 2 mm - //glTranslatef(0, ((-pitch/M_PI)*180.0f * vPitchPerDeg), 0); - glTranslatef(0.0f, (-pitch * vPitchPerDeg * 16.5f), 0.0f); - - // Ground - glColor3ub(179,102,0); - - glBegin(GL_POLYGON); - glVertex2f(-300,-900); - glVertex2f(-300,0); - glVertex2f(300,0); - glVertex2f(300,-900); - glVertex2f(-300,-900); - glEnd(); - - // Sky - glColor3ub(0,153,204); - - glBegin(GL_POLYGON); - glVertex2f(-300,0); - glVertex2f(-300,900); - glVertex2f(300,900); - glVertex2f(300,0); - glVertex2f(-300,0); - - glEnd(); -} - /** * Paint text on top of the image and OpenGL drawings * @@ -547,29 +480,6 @@ void HUD::paintText(QString text, QColor color, float fontSize, float refX, floa painter->setPen(prevPen); } -void HUD::initializeGL() -{ - bool antialiasing = true; - - // Antialiasing setup - if(antialiasing) { - glEnable(GL_MULTISAMPLE); - glEnable(GL_BLEND); - - glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); - - glEnable(GL_POINT_SMOOTH); - glEnable(GL_LINE_SMOOTH); - - glHint(GL_POINT_SMOOTH_HINT, GL_NICEST); - glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); - } else { - glDisable(GL_BLEND); - glDisable(GL_POINT_SMOOTH); - glDisable(GL_LINE_SMOOTH); - } -} - /** * @param referencePositionX horizontal position in the reference mm-unit space * @param referencePositionY horizontal position in the reference mm-unit space @@ -583,23 +493,6 @@ void HUD::setupGLView(float referencePositionX, float referencePositionY, float // Translate and scale the GL view in the virtual reference coordinate units on the screen int pixelPositionX = (int)((referencePositionX * scalingFactor) + xCenterOffset); int pixelPositionY = this->height() - (referencePositionY * scalingFactor) + yCenterOffset - pixelHeight; - - //qDebug() << "Pixel x" << pixelPositionX << "pixelY" << pixelPositionY; - //qDebug() << "xCenterOffset:" << xCenterOffset << "yCenterOffest" << yCenterOffset - - - //The viewport is established at the correct pixel position and clips everything - // out of the desired instrument location - glViewport(pixelPositionX, pixelPositionY, pixelWidth, pixelHeight); - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - - // The ortho projection is setup in a way that so that the drawing is done in the - // reference coordinate space - glOrtho(0, referenceWidth, 0, referenceHeight, -1, 1); - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - //glScalef(scaleX, scaleY, 1.0f); } void HUD::paintRollPitchStrips() @@ -668,22 +561,13 @@ void HUD::paintHUD() double scalingFactorH = this->height()/vheight; if (scalingFactorH < scalingFactor) scalingFactor = scalingFactorH; - - - // OPEN GL PAINTING - // Store model view matrix to be able to reset it to the previous state - makeCurrent(); - glMatrixMode(GL_MODELVIEW); - glPushMatrix(); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - // Fill with black background if (videoEnabled) { if (nextOfflineImage != "" && QFileInfo(nextOfflineImage).exists()) { qDebug() << __FILE__ << __LINE__ << "template image:" << nextOfflineImage; QImage fill = QImage(nextOfflineImage); - glImage = QGLWidget::convertToGLFormat(fill); + glImage = fill; // Reset to save load efforts nextOfflineImage = ""; @@ -693,22 +577,14 @@ void HUD::paintHUD() if (dataStreamEnabled || videoEnabled) { - glRasterPos2i(0, 0); xImageFactor = width() / (float)glImage.width(); yImageFactor = height() / (float)glImage.height(); float imageFactor = qMin(xImageFactor, yImageFactor); - glPixelZoom(imageFactor, imageFactor); // Resize to correct size and fill with image - glDrawPixels(glImage.width(), glImage.height(), GL_RGBA, GL_UNSIGNED_BYTE, glImage.bits()); - //qDebug() << "DRAWING GL IMAGE"; - } else { - // Blue / brown background - paintCenterBackground(roll, pitch, yawTrans); - } + // FIXME - glMatrixMode(GL_MODELVIEW); - glPopMatrix(); + } // END OF OPENGL PAINTING @@ -889,11 +765,6 @@ void HUD::paintHUD() painter.begin(this); painter.end(); } - //glDisable(GL_MULTISAMPLE); - - - - //glFlush(); } } @@ -1303,20 +1174,6 @@ void HUD::drawCircle(float refX, float refY, float radius, float startDeg, float drawEllipse(refX, refY, radius, radius, startDeg, endDeg, lineWidth, color, painter); } -void HUD::resizeGL(int w, int h) -{ - if (isVisible()) { - glViewport(0, 0, w, h); - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - glOrtho(0, w, 0, h, -1, 1); - glMatrixMode(GL_MODELVIEW); - glPolygonMode(GL_FRONT, GL_FILL); - //FIXME - paintHUD(); - } -} - void HUD::selectWaypoint(int uasId, int id) { Q_UNUSED(uasId); @@ -1364,7 +1221,7 @@ void HUD::setImageSize(int width, int height, int depth, int channels) // Fill first channel of image with black pixels image->fill(0); - glImage = QGLWidget::convertToGLFormat(*image); + glImage = *image; qDebug() << __FILE__ << __LINE__ << "Setting up image"; @@ -1415,7 +1272,7 @@ void HUD::commitRawDataToGL() } } - glImage = QGLWidget::convertToGLFormat(*newImage); + glImage = *newImage; delete image; image = newImage; // Switch buffers @@ -1516,7 +1373,7 @@ void HUD::copyImage() UAS* u = dynamic_cast(this->uas); if (u) { - this->glImage = QGLWidget::convertToGLFormat(u->getImage()); + this->glImage = u->getImage(); // Save to directory if logging is enabled if (imageLoggingEnabled) diff --git a/src/ui/HUD.h b/src/ui/HUD.h index e900d8d79..8352e6c1b 100644 --- a/src/ui/HUD.h +++ b/src/ui/HUD.h @@ -33,7 +33,7 @@ This file is part of the QGROUNDCONTROL project #define HUD_H #include -#include +#include #include #include #include @@ -47,7 +47,7 @@ This file is part of the QGROUNDCONTROL project * It can superimpose the HUD over the current live image stream (any arriving image stream will be auto- * matically used as background), or it draws the classic blue-brown background known from instruments. */ -class HUD : public QGLWidget +class HUD : public QWidget { Q_OBJECT public: @@ -55,10 +55,10 @@ public: ~HUD(); void setImageSize(int width, int height, int depth, int channels); - void resizeGL(int w, int h); + void resize(int w, int h); public slots: - void initializeGL(); +// void initializeGL(); //void paintGL(); /** @brief Set the currently monitored UAS */ @@ -98,7 +98,6 @@ public slots: protected slots: - void paintCenterBackground(float roll, float pitch, float yaw); void paintRollPitchStrips(); void paintPitchLines(float pitch, QPainter* painter); /** @brief Paint text on top of the image and OpenGL drawings */ diff --git a/src/ui/QGCRGBDView.cc b/src/ui/QGCRGBDView.cc index 27f3e34b4..9a06c04cc 100644 --- a/src/ui/QGCRGBDView.cc +++ b/src/ui/QGCRGBDView.cc @@ -78,7 +78,7 @@ void QGCRGBDView::clearData(void) QImage offlineImg; qDebug() << offlineImg.load(":/files/images/status/colorbars.png"); - glImage = QGLWidget::convertToGLFormat(offlineImg); + glImage = offlineImg; } void QGCRGBDView::contextMenuEvent(QContextMenuEvent* event) @@ -104,14 +104,14 @@ void QGCRGBDView::enableRGB(bool enabled) { rgbEnabled = enabled; dataStreamEnabled = rgbEnabled | depthEnabled; - resize(size()); + QWidget::resize(size().width(), size().height()); } void QGCRGBDView::enableDepth(bool enabled) { depthEnabled = enabled; dataStreamEnabled = rgbEnabled | depthEnabled; - resize(size()); + QWidget::resize(size().width(), size().height()); } float colormapJet[128][3] = { diff --git a/src/ui/QGCToolBar.cc b/src/ui/QGCToolBar.cc index bfd4789f9..e887658f5 100644 --- a/src/ui/QGCToolBar.cc +++ b/src/ui/QGCToolBar.cc @@ -163,7 +163,7 @@ void QGCToolBar::createUI() connectButton = new QPushButton(tr("Connect"), this); connectButton->setToolTip(tr("Connect wireless link to MAV")); connectButton->setCheckable(true); - connectButton->setStyleSheet("QPushButton {min-height: 20px; color: #222222; background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #5AAA49, stop: 1 #106B38); margin-left: 4px; margin-right: 4px; border-radius: 4px; border: 1px solid #085B35; } QPushButton:checked { background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #FF9000, stop: 1 #FFD450); color: #222222; border-color: #D1892A}"); + connectButton->setStyleSheet("QPushButton { min-height: 24px; max-height: 24px; color: #222222; background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #5AAA49, stop: 1 #106B38); margin-left: 4px; margin-right: 4px; border-radius: 4px; border: 1px solid #085B35; } QPushButton:checked { background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #FF9000, stop: 1 #FFD450); color: #222222; border-color: #D1892A}"); addWidget(connectButton); connect(connectButton, SIGNAL(clicked(bool)), this, SLOT(connectLink(bool))); @@ -209,7 +209,7 @@ void QGCToolBar::setPerspectiveChangeActions(const QList &actions) first->setCheckable(true); connect(first, SIGNAL(clicked(bool)), actions.first(), SIGNAL(triggered(bool))); connect(actions.first(),SIGNAL(triggered(bool)),first,SLOT(setChecked(bool))); - first->setStyleSheet("QToolButton { min-width: 60px; color: #222222; background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #A2A3A4, stop: 1 #B6B7B8); margin-left: 8px; margin-right: 0px; padding-left: 4px; padding-right: 8px; border-radius: 0px; border : 0px solid blue; border-bottom-left-radius: 6px; border-top-left-radius: 6px; border-left: 1px solid #484848; border-top: 1px solid #484848; border-bottom: 1px solid #484848; } QToolButton:checked { background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #555555, stop: 1 #787878); color: #DDDDDD; }"); + first->setStyleSheet("QToolButton { min-height: 24px; max-height: 24px; min-width: 60px; color: #222222; background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #A2A3A4, stop: 1 #B6B7B8); margin-left: 8px; margin-right: 0px; padding-left: 4px; padding-right: 8px; border-radius: 0px; border : 0px solid blue; border-bottom-left-radius: 6px; border-top-left-radius: 6px; border-left: 1px solid #484848; border-top: 1px solid #484848; border-bottom: 1px solid #484848; } QToolButton:checked { background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #555555, stop: 1 #787878); color: #DDDDDD; }"); addWidget(first); group->addButton(first); @@ -225,7 +225,7 @@ void QGCToolBar::setPerspectiveChangeActions(const QList &actions) btn->setCheckable(true); connect(btn, SIGNAL(clicked(bool)), actions.at(i), SIGNAL(triggered(bool))); connect(actions.at(i),SIGNAL(triggered(bool)),btn,SLOT(setChecked(bool))); - btn->setStyleSheet("QToolButton { min-width: 60px; color: #222222; background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #A2A3A4, stop: 1 #B6B7B8); margin-left: -2px; margin-right: -2px; padding-left: 0px; padding-right: 0px; border-radius: 0px; border-top: 1px solid #484848; border-bottom: 1px solid #484848; } QToolButton:checked { background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #555555, stop: 1 #787878); color: #DDDDDD; }"); + btn->setStyleSheet("QToolButton { min-height: 24px; max-height: 24px; min-width: 60px; color: #222222; background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #A2A3A4, stop: 1 #B6B7B8); margin-left: -2px; margin-right: -2px; padding-left: 0px; padding-right: 0px; border-radius: 0px; border-top: 1px solid #484848; border-bottom: 1px solid #484848; } QToolButton:checked { background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #555555, stop: 1 #787878); color: #DDDDDD; }"); addWidget(btn); group->addButton(btn); } @@ -237,7 +237,7 @@ void QGCToolBar::setPerspectiveChangeActions(const QList &actions) advancedButton->setText(tr("Pro")); advancedButton->setToolTip(tr("Options for advanced users")); advancedButton->setCheckable(true); - advancedButton->setStyleSheet("QPushButton { min-height: 20px; max-height: 20px; min-width: 60px; font-weight: bold; text-align: left; color: #222222; background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #A2A3A4, stop: 1 #B6B7B8); margin-left: 0px; margin-right: 13px; padding-left: 4px; padding-right: 8px; border-radius: 0px; border : 0px solid blue; border-bottom-right-radius: 6px; border-top-right-radius: 6px; border-right: 1px solid #484848; border-top: 1px solid #484848; border-bottom: 1px solid #484848; } QPushButton:checked { background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #555555, stop: 1 #787878); color: #DDDDDD; }"); + advancedButton->setStyleSheet("QPushButton { min-height: 24px; max-height: 24px; min-width: 60px; font-weight: bold; text-align: left; color: #222222; background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #A2A3A4, stop: 1 #B6B7B8); margin-left: 0px; margin-right: 13px; padding-left: 4px; padding-right: 8px; border-radius: 0px; border : 0px solid blue; border-bottom-right-radius: 6px; border-top-right-radius: 6px; border-right: 1px solid #484848; border-top: 1px solid #484848; border-bottom: 1px solid #484848; } QPushButton:checked { background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #555555, stop: 1 #787878); color: #DDDDDD; }"); addWidget(advancedButton); group->addButton(advancedButton); } else { diff --git a/src/ui/UASRawStatusView.cpp b/src/ui/UASRawStatusView.cpp index 21fa58a26..51c48191b 100644 --- a/src/ui/UASRawStatusView.cpp +++ b/src/ui/UASRawStatusView.cpp @@ -13,7 +13,10 @@ UASRawStatusView::UASRawStatusView(QWidget *parent) : QWidget(parent) ui.tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers); QTimer *timer = new QTimer(this); connect(timer,SIGNAL(timeout()),this,SLOT(updateTableTimerTick())); - timer->start(2000); + + // FIXME reinstate once fixed. + + //timer->start(2000); } void UASRawStatusView::addSource(MAVLinkDecoder *decoder) { diff --git a/src/ui/uas/UASQuickViewGaugeItem.cc b/src/ui/uas/UASQuickViewGaugeItem.cc new file mode 100644 index 000000000..0446e5280 --- /dev/null +++ b/src/ui/uas/UASQuickViewGaugeItem.cc @@ -0,0 +1,25 @@ +#include "UASQuickViewGaugeItem.h" +#include +UASQuickViewGaugeItem::UASQuickViewGaugeItem(QWidget *parent) : UASQuickViewItem(parent) +{ + +} +void UASQuickViewGaugeItem::setValue(double value) +{ + valueLabel->setText(QString::number(value,'f',4)); +} + +void UASQuickViewGaugeItem::setTitle(QString title) +{ + titleLabel->setText(title); +} +void UASQuickViewGaugeItem::resizeEvent(QResizeEvent *event) +{ + QFont valuefont = valueLabel->font(); + QFont titlefont = titleLabel->font(); + valuefont.setPixelSize(this->height() / 2.0); + titlefont.setPixelSize(this->height() / 4.0); + valueLabel->setFont(valuefont); + titleLabel->setFont(titlefont); + update(); +} diff --git a/src/ui/uas/UASQuickViewGaugeItem.h b/src/ui/uas/UASQuickViewGaugeItem.h new file mode 100644 index 000000000..9bc478cf6 --- /dev/null +++ b/src/ui/uas/UASQuickViewGaugeItem.h @@ -0,0 +1,19 @@ +#ifndef UASQuickViewGaugeItem_H +#define UASQuickViewGaugeItem_H + +#include "UASQuickViewItem.h" +#include +class UASQuickViewGaugeItem : public UASQuickViewItem +{ +public: + UASQuickViewGaugeItem(QWidget *parent=0); + void setValue(double value); + void setTitle(QString title); +protected: + void resizeEvent(QResizeEvent *event); +private: + QLabel *titleLabel; + QLabel *valueLabel; +}; + +#endif // UASQuickViewGaugeItem_H -- 2.22.0