diff --git a/src/ui/HUD.cc b/src/ui/HUD.cc index 5a198a4..88b19db 100644 --- a/src/ui/HUD.cc +++ b/src/ui/HUD.cc @@ -448,7 +448,7 @@ void HUD::paintText(QString text, QColor color, float fontSize, float refX, floa QFont font("Bitstream Vera Sans"); // Enforce minimum font size of 5 pixels - int fSize = qMax(1, (int)(fontSize*scalingFactor*1.26f)); + int fSize = qMax(5, (int)(fontSize*scalingFactor*1.26f)); font.setPixelSize(fSize); QFontMetrics metrics = QFontMetrics(font); diff --git a/src/ui/map3D/Q3DWidget.cc b/src/ui/map3D/Q3DWidget.cc index 33bc1b3..8945075 100755 --- a/src/ui/map3D/Q3DWidget.cc +++ b/src/ui/map3D/Q3DWidget.cc @@ -481,6 +481,18 @@ Q3DWidget::initializeGL(void) glEnable(GL_LIGHT0); glDisable(GL_LIGHTING); glEnable(GL_NORMALIZE); + + // TODO: Added these, please check + 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); } void diff --git a/src/ui/map3D/QMap3DWidget.cc b/src/ui/map3D/QMap3DWidget.cc index 5ae2027..5b7d9dd 100644 --- a/src/ui/map3D/QMap3DWidget.cc +++ b/src/ui/map3D/QMap3DWidget.cc @@ -55,8 +55,8 @@ QMap3DWidget::buildLayout(void) lockCameraCheckBox->setText("Lock Camera"); lockCameraCheckBox->setChecked(lockCamera); - positionLabel = new QLabel(this); - positionLabel->setText(tr("Waiting for first position update.. ")); + //positionLabel = new QLabel(this); + //positionLabel->setText(tr("Waiting for first position update.. ")); QGridLayout* layout = new QGridLayout(this); layout->setMargin(0); @@ -66,7 +66,7 @@ QMap3DWidget::buildLayout(void) layout->addWidget(trailCheckBox, 1, 1); layout->addWidget(recenterButton, 1, 2); layout->addWidget(lockCameraCheckBox, 1, 3); - layout->addWidget(positionLabel, 1, 4); + // layout->addWidget(positionLabel, 1, 4); layout->setRowStretch(0, 100); layout->setRowStretch(1, 1); layout->setColumnStretch(0, 1); @@ -147,29 +147,43 @@ QMap3DWidget::displayHandler(void) glVertex2f(getWindowWidth(), 0.0f); glEnd(); + // QT QPAINTER OPENGL PAINTING + + QPainter painter; + painter.begin(this); + painter.setRenderHint(QPainter::Antialiasing, true); + painter.setRenderHint(QPainter::HighQualityAntialiasing, true); + paintText(QString("x = %1 y = %2 z = %3 r = %4 p = %5 y = %6").arg(robotX, 0, 'f', 2).arg(robotY, 0, 'f', 2).arg(robotZ, 0, 'f', 2).arg(robotRoll, 0, 'f', 2).arg(robotPitch, 0, 'f', 2).arg(robotYaw, 0, 'f', 2), + QColor(255, 255, 255), + 12, + 5, + 5, + &painter); +} -// char buffer[6][255]; -// -// sprintf(buffer[0], "x = %.2f", robotX); -// sprintf(buffer[1], "y = %.2f", robotY); -// sprintf(buffer[2], "z = %.2f", robotZ); -// sprintf(buffer[3], "r = %.2f", robotRoll); -// sprintf(buffer[4], "p = %.2f", robotPitch); -// sprintf(buffer[5], "y = %.2f", robotYaw); - - positionLabel->setText(QString("x = %1 y = %2 z = %3 r = %4 p = %5 y = %6").arg(robotX).arg(robotY).arg(robotZ).arg(robotRoll).arg(robotPitch).arg(robotYaw)); - -// font->FaceSize(10); -// glColor3f(1.0f, 1.0f, 1.0f); -// glPushMatrix(); -// -// glTranslatef(0.0f, 30.0f, 0.0f); -// for (int32_t i = 0; i < 6; ++i) -// { -// glTranslatef(60.0f, 0.0f, 0.0f); -// font->Render(buffer[i]); -// } -// glPopMatrix(); +void QMap3DWidget::paintText(QString text, QColor color, float fontSize, float refX, float refY, QPainter* painter) +{ + QPen prevPen = painter->pen(); + + float pPositionX = refX; + float pPositionY = refY; + + QFont font("Bitstream Vera Sans"); + // Enforce minimum font size of 5 pixels + int fSize = qMax(5, (int)(fontSize)); + font.setPixelSize(fSize); + + QFontMetrics metrics = QFontMetrics(font); + int border = qMax(4, metrics.leading()); + QRect rect = metrics.boundingRect(0, 0, width() - 2*border, int(height()*0.125), + Qt::AlignLeft | Qt::TextWordWrap, text); + painter->setPen(color); + painter->setFont(font); + painter->setRenderHint(QPainter::TextAntialiasing); + painter->drawText(pPositionX, pPositionY, + rect.width(), rect.height(), + Qt::AlignCenter | Qt::TextWordWrap, text); + painter->setPen(prevPen); } /** diff --git a/src/ui/map3D/QMap3DWidget.h b/src/ui/map3D/QMap3DWidget.h index 2e08958..2c9d52e 100644 --- a/src/ui/map3D/QMap3DWidget.h +++ b/src/ui/map3D/QMap3DWidget.h @@ -37,7 +37,7 @@ private slots: protected: UASInterface* uas; - QLabel* positionLabel; + void paintText(QString text, QColor color, float fontSize, float refX, float refY, QPainter* painter); private: void drawPlatform(float roll, float pitch, float yaw); diff --git a/src/ui/uas/UASView.cc b/src/ui/uas/UASView.cc index 764bcf7..fd99a5b 100644 --- a/src/ui/uas/UASView.cc +++ b/src/ui/uas/UASView.cc @@ -109,7 +109,7 @@ UASView::UASView(UASInterface* uas, QWidget *parent) : // Heartbeat fade refreshTimer = new QTimer(this); connect(refreshTimer, SIGNAL(timeout()), this, SLOT(refresh())); - refreshTimer->start(180); + refreshTimer->start(updateInterval); } UASView::~UASView() @@ -195,7 +195,7 @@ void UASView::receiveHeartbeat(UASInterface* uas) m_ui->heartbeatIcon->setStyleSheet(colorstyle); m_ui->heartbeatIcon->setAutoFillBackground(true); refreshTimer->stop(); - refreshTimer->start(100); + refreshTimer->start(updateInterval); } } @@ -330,6 +330,20 @@ void UASView::updateLoad(UASInterface* uas, double load) void UASView::refresh() { + //setUpdatesEnabled(false); + setUpdatesEnabled(true); + + static quint64 lastupdate = 0; + qDebug() << "UASVIEW update diff: " << MG::TIME::getGroundTimeNow() - lastupdate; + lastupdate = MG::TIME::getGroundTimeNow(); + + // FIXME + static int generalUpdateCount = 0; + + if (generalUpdateCount == 4) + { + generalUpdateCount = 0; + qDebug() << "UPDATING EVERYTHING"; // State m_ui->stateLabel->setText(state); m_ui->statusTextLabel->setText(stateDesc); @@ -411,6 +425,8 @@ void UASView::refresh() QString timeText; timeText = timeText.sprintf("%02d:%02d:%02d", hours, min, sec); m_ui->timeElapsedLabel->setText(timeText); +} + generalUpdateCount++; // Fade heartbeat icon // Make color darker @@ -421,6 +437,9 @@ void UASView::refresh() heartbeatColor.red(), heartbeatColor.green(), heartbeatColor.blue()); m_ui->heartbeatIcon->setStyleSheet(colorstyle); m_ui->heartbeatIcon->setAutoFillBackground(true); + //setUpdatesEnabled(true); + repaint(); + setUpdatesEnabled(false); } void UASView::changeEvent(QEvent *e) diff --git a/src/ui/uas/UASView.h b/src/ui/uas/UASView.h index ba7ccf4..3404153 100644 --- a/src/ui/uas/UASView.h +++ b/src/ui/uas/UASView.h @@ -99,6 +99,7 @@ protected: float lon; float alt; float groundDistance; + static const int updateInterval = 180; void mouseDoubleClickEvent (QMouseEvent * event);