///////////////////////////////////////////////////////////////////////////////////
// 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;
m_drawLegend = false;
setMinimumSize(m_sizeMin, m_sizeMin);
setMaximumSize(m_sizeMax, m_sizeMax);
resize(m_sizeMin, m_sizeMin);
setFocusPolicy(Qt::NoFocus);
m_azPos = 0.0;
m_azNeg = 0.0;
m_azAnt = 0.0;
m_blindAngle = 0.0;
m_blindColor = QColor(32, 32, 32);
}
DOA2Compass::~DOA2Compass()
{
}
void DOA2Compass::canvasReplot_slot(void)
{
update();
}
void DOA2Compass::resizeEvent(QResizeEvent *event)
{
m_size = qMin(width(),height()) - 2*m_offset;
QWidget::resizeEvent(event);
}
void DOA2Compass::paintEvent(QPaintEvent *)
{
QPainter painter(this);
QBrush bgGround(palette().button().color());
QPen whitePen(Qt::white);
QPen blackPen(Qt::black);
QPen redPen(Qt::red);
QPen bluePen(Qt::blue);
QPen greenPen(Qt::green);
QPen borderPen(palette().button().color().lighter(200));
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(whitePen);
painter.setBrush(bgGround);
painter.drawEllipse(-m_size/2, -m_size/2, m_size, m_size);
}
// draw blind angle
if (m_blindAngle != 0)
{
painter.setBrush(m_blindColor);
painter.setPen(m_blindAngleBorder ? borderPen : Qt::NoPen);
painter.rotate(m_azAnt - 90);
painter.drawPie(-m_size/2, -m_size/2, m_size, m_size, -m_blindAngle*16, m_blindAngle*32);
painter.rotate(180);
painter.drawPie(-m_size/2, -m_size/2, m_size, m_size, -m_blindAngle*16, m_blindAngle*32);
painter.rotate(-m_azAnt - 90);
painter.setBrush(Qt::NoBrush);
painter.setPen(whitePen);
painter.drawEllipse(-m_size/2, -m_size/2, m_size, m_size);
}
// draw compass 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(whitePen);
painter.setFont(font());
for(int i=0; i