00001
00002
00003
00004
00005
00006
00007 #include "pieDisplay.h"
00008 #include <QPolygon>
00009 #include <QLabel>
00010 #include <math.h>
00011
00012 pieDisplay::pieDisplay( QWidget *parent)
00013 : QWidget( parent )
00014 {
00015 threatIndex = 0;
00016 setPalette( QPalette( QColor( 0, 0,0) ) );
00017 this->setAutoFillBackground(true);
00018 QFont f("Helvetica", 16, QFont::Bold);
00019 this->setFont(f);
00020 }
00021
00022 void pieDisplay::paintEvent( QPaintEvent * )
00023 {
00024
00025 QPainter p( this );
00026
00027 std::list<threatListItem>::iterator threatIter;
00028 for (threatIter=tList.begin(); threatIter != tList.end(); threatIter++)
00029 {
00030 paintThreat( &p, threatIter );
00031 }
00032
00033 p.resetMatrix();
00034 drawAircraftSymbol(&p);
00035 }
00036
00037
00038 QSizePolicy pieDisplay::sizePolicy() const
00039 {
00040 return QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
00041 }
00042
00043 void pieDisplay::paintThreat(QPainter *p, std::list<threatListItem>::iterator item)
00044 {
00045 QPolygon a;
00046
00047 p->setBrush(Qt::NoBrush);
00048 p->setPen(Qt::white);
00049 int hwidth = this->width()/2;
00050 int hheight = this->height()/2+this->height()/5;
00051
00052
00053 int mradius = 250;
00054 QRectF rectangle(hwidth - mradius, hheight - mradius, mradius*2, mradius*2);
00055 p->drawPie(rectangle, 340*16, 220*16);
00056
00057
00058 switch(item->type)
00059 {
00060 case threatOther:
00061 p->setBrush(Qt::cyan);
00062 p->setPen(Qt::cyan);
00063 break;
00064 case threatProximate:
00065 p->setBrush(Qt::NoBrush);
00066 p->setPen(QPen(Qt::cyan,2));
00067 break;
00068 case threatIntruding:
00069 p->setBrush(Qt::yellow);
00070 p->setPen(Qt::NoPen);
00071 break;
00072 case threatReal :
00073 p->setBrush(Qt::red);
00074 p->setPen(Qt::NoPen);
00075 break;
00076
00077 }
00078 drawTriangle(p, item->vecangle, item->relAlt, item->type, item->relangle);
00079
00080 }
00081
00082 void pieDisplay::drawTriangle(QPainter *p, int angle, int relalt, threatType type, int lrAngle)
00083 {
00084 int x = 250;
00085 int y = 90;
00086
00087 int hwidth = this->width()/2;
00088 int hheight = this->height()/2+this->height()/5;
00089
00090 QPolygon a;
00091 a.putPoints(0,3, -10,0, 0,-30, 10,0);
00092
00093 p->translate(hwidth,hheight);
00094 p->rotate(lrAngle);
00095 p->translate(0,-250);
00096 p->rotate(angle-lrAngle);
00097 p->drawPolygon(a);
00098
00099 QString s;
00100 if (relalt <= 0)
00101 s = "B";
00102 else
00103 s = "A";
00104 p->setPen(QPen(Qt::white,2));
00105 p->drawText( -6, 17, s );
00106 p->resetMatrix();
00107 }
00108
00109 void pieDisplay::addThreat(threatType t, trendDir d, int relAlt, int anglepos, int vecangle, unsigned long &key)
00110 {
00111
00112
00113 if (d == none)
00114 {
00115 threatIndex++;
00116 threatListItem *ti = new threatListItem(t, d, relAlt, threatIndex, 0, 0, anglepos, vecangle);
00117 tList.push_back(*ti);
00118 this->repaint();
00119 key = threatIndex;
00120 }
00121 else
00122 key = -1;
00123 }
00124
00125 void pieDisplay::removeThreat(int idx)
00126 {
00127
00128
00129 std::list<threatListItem>::iterator threatIter;
00130 for (threatIter=tList.begin(); threatIter != tList.end(); threatIter++)
00131 {
00132 if(threatIter->id == idx)
00133 tList.erase(threatIter);
00134 }
00135 this->repaint();
00136 }
00137
00138 void pieDisplay::drawAircraftSymbol(QPainter *p)
00139 {
00140 int mwidth = this->width();
00141 int mheight = this->height()+ this->height()/2.5;
00142 p->setPen( QPen(Qt::white,3) );
00143 p->translate(0,0);
00144
00145 p->drawLine(mwidth/2, mheight/2 + 15, mwidth/2, mheight/2 - 15);
00146
00147 p->drawLine(mwidth/2 - 3, mheight/2 + 10, mwidth/2 + 3, mheight/2 + 10);
00148
00149 p->drawLine(mwidth/2 - 10, mheight/2 - 5, mwidth/2 + 10, mheight/2 - 5);
00150 }
00151
00152