-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpolarwidget.cpp
90 lines (75 loc) · 2.45 KB
/
polarwidget.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include "polarwidget.h"
PolarWidget::PolarWidget(QWidget *parent) : QChartView(parent)
{
chart = new QPolarChart();
angularAxis = new QValueAxis();
angularAxis->setTickCount(9); // First and last ticks are co-located on 0/360 angle.
angularAxis->setLabelFormat("%.1f");
angularAxis->setShadesVisible(true);
angularAxis->setShadesBrush(QBrush(QColor(249, 249, 255)));
angularAxis->setRange(angularMin, angularMax);
chart->addAxis(angularAxis, QPolarChart::PolarOrientationAngular);
radialAxis = new QValueAxis();
radialAxis->setTickCount(4);
radialAxis->setLabelsVisible(false);
radialAxis->setRange(radialMin, radialMax);
chart->addAxis(radialAxis, QPolarChart::PolarOrientationRadial);
crosshair = new QScatterSeries();
chart->addSeries(crosshair);
crosshair->setName("ANT");
crosshair->attachAxis(radialAxis);
crosshair->attachAxis(angularAxis);
circle = new QScatterSeries();
chart->addSeries(circle);
circle->setName("SATE");
circle->attachAxis(radialAxis);
circle->attachAxis(angularAxis);
chart->legend()->hide();
chart->setBackgroundBrush(QBrush(QColor("transparent")));
this->setChart(chart);
this->setRenderHint(QPainter::Antialiasing);
}
void PolarWidget::setCrosshairPoint(float yaw, float pitch)
{
crosshair->clear();
if(yaw < angularMin)
yaw += angularMax - angularMin;
if(yaw > angularMax)
yaw -= angularMax - angularMin;
if(pitch<radialMin)
{
pitch = radialMin;
crosshair->setColor(QColor("red"));
}
else
crosshair->setColor(QColor("blue"));
if(rotationLock)
{
chart->setTransformOriginPoint(this->width()/2, this->height()/2);
chart->setRotation(yaw * -1);
}
crosshair->append(yaw, pitch * -1 + radialMax);
}
void PolarWidget::setCirclePoint(float yaw, float pitch)
{
circle->clear();
if(yaw < angularMin)
yaw += angularMax - angularMin;
if(yaw > angularMax)
yaw -= angularMax - angularMin;
pitch = pitch<radialMin ? radialMin : pitch;
circle->append(yaw, pitch * -1 + radialMax);
}
void PolarWidget::setRotationUnlock(bool rotationUnlock)
{
this->rotationLock = !rotationUnlock;
if(rotationUnlock)
chart->legend()->show();
else
chart->legend()->hide();
}
void PolarWidget::resetRotationAngle()
{
chart->setTransformOriginPoint(this->width()/2, this->height()/2);
chart->setRotation(0);
}