Commit d8ef1095 authored by pixhawk's avatar pixhawk

Added Qt text painting to 3D widget, removed thus the dependency to FTGL

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