///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2022 Edouard Griffiths, F4EXB //
// //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation as version 3 of the License, or //
// (at your option) any later version. //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License V3 for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program. If not, see . //
///////////////////////////////////////////////////////////////////////////////////
#include
#include
#include
#include "doa2compass.h"
DOA2Compass::DOA2Compass(QWidget *parent)
: QWidget(parent)
{
connect(this, SIGNAL(canvasReplot(void)), this, SLOT(canvasReplot_slot(void)));
m_sizeMin = 200;
m_sizeMax = 600;
m_offset = 2;
m_size = m_sizeMin - 2*m_offset;
setMinimumSize(m_sizeMin, m_sizeMin);
setMaximumSize(m_sizeMax, m_sizeMax);
resize(m_sizeMin, m_sizeMin);
setFocusPolicy(Qt::NoFocus);
m_yaw = 0.0;
m_alt = 0.0;
m_h = 0.0;
}
DOA2Compass::~DOA2Compass()
{
}
void DOA2Compass::canvasReplot_slot(void)
{
update();
}
void DOA2Compass::resizeEvent(QResizeEvent *event)
{
m_size = qMin(width(),height()) - 2*m_offset;
}
void DOA2Compass::paintEvent(QPaintEvent *)
{
QPainter painter(this);
QBrush bgGround(QColor(48,172,220));
QPen whitePen(Qt::white);
QPen blackPen(Qt::black);
QPen redPen(Qt::red);
QPen bluePen(Qt::blue);
QPen greenPen(Qt::green);
whitePen.setWidth(1);
blackPen.setWidth(2);
redPen.setWidth(2);
bluePen.setWidth(2);
greenPen.setWidth(2);
painter.setRenderHint(QPainter::Antialiasing);
painter.translate(width() / 2, height() / 2);
// draw background
{
painter.setPen(blackPen);
painter.setBrush(bgGround);
painter.drawEllipse(-m_size/2, -m_size/2, m_size, m_size);
}
// draw yaw lines
{
int nyawLines = 36;
float rotAng = 360.0 / nyawLines;
int yawLineLeng = m_size/25;
double fx1, fy1, fx2, fy2;
int fontSize = 8;
QString s;
blackPen.setWidth(1);
painter.setPen(blackPen);
for(int i=0; ikey()) {
case Qt::Key_Left:
m_yaw -= 1.0;
break;
case Qt::Key_Right:
m_yaw += 1.0;
break;
case Qt::Key_Down:
m_alt -= 1.0;
break;
case Qt::Key_Up:
m_alt += 1.0;
break;
case Qt::Key_W:
m_h += 1.0;
break;
case Qt::Key_S:
m_h -= 1.0;
break;
default:
QWidget::keyPressEvent(event);
break;
}
update();
}