MAV2DIcon.cc 2.15 KB
Newer Older
1 2 3
#include "MAV2DIcon.h"
#include <QPainter>

4 5 6
MAV2DIcon::MAV2DIcon(qreal x, qreal y, int radius, QString name, Alignment alignment, QPen* pen)
    : Point(x, y, name, alignment),
    yaw(0.0f)
7
{
8 9
    size = QSize(radius, radius);
    drawIcon(pen);
10 11
}

12 13 14 15 16
MAV2DIcon::MAV2DIcon(qreal x, qreal y, QString name, Alignment alignment, QPen* pen)
    : Point(x, y, name, alignment)
{
    int radius = 10;
    size = QSize(radius, radius);
17 18 19 20
    if (pen)
    {
        drawIcon(pen);
    }
21 22 23 24 25 26 27 28
}

MAV2DIcon::~MAV2DIcon()
{
    delete mypixmap;
}

void MAV2DIcon::setPen(QPen* pen)
29
{
30 31 32 33 34
    if (pen)
    {
        mypen = pen;
        drawIcon(pen);
    }
35 36 37
}

/**
38
 * @param yaw in radians, 0 = north, positive = clockwise
39
 */
40
void MAV2DIcon::setYaw(float yaw)
41
{
42
    this->yaw = yaw;
43
    drawIcon(mypen);
44 45 46 47 48
}

void MAV2DIcon::drawIcon(QPen* pen)
{

49 50 51
//    mypixmap = new QPixmap(radius+1, radius+1);
//    mypixmap->fill(Qt::transparent);
//    QPainter painter(mypixmap);
52

53 54
//    // DRAW WAYPOINT
//    QPointF p(radius/2, radius/2);
55

56 57 58 59 60 61 62 63 64
//    float waypointSize = radius;
//    QPolygonF poly(4);
//    // Top point
//    poly.replace(0, QPointF(p.x(), p.y()-waypointSize/2.0f));
//    // Right point
//    poly.replace(1, QPointF(p.x()+waypointSize/2.0f, p.y()));
//    // Bottom point
//    poly.replace(2, QPointF(p.x(), p.y() + waypointSize/2.0f));
//    poly.replace(3, QPointF(p.x() - waypointSize/2.0f, p.y()));
65

66 67 68 69 70 71 72 73 74 75 76 77 78 79
////    // Select color based on if this is the current waypoint
////    if (list.at(i)->getCurrent())
////    {
////        color = QGC::colorCyan;//uas->getColor();
////        pen.setWidthF(refLineWidthToPen(0.8f));
////    }
////    else
////    {
////        color = uas->getColor();
////        pen.setWidthF(refLineWidthToPen(0.4f));
////    }

//    //pen.setColor(color);
//    if (pen)
80
//    {
81 82
//        pen->setWidthF(2);
//        painter.setPen(*pen);
83 84 85
//    }
//    else
//    {
86 87 88
//        QPen pen2(Qt::red);
//        pen2.setWidth(2);
//        painter.setPen(pen2);
89
//    }
90
//    painter.setBrush(Qt::NoBrush);
91

92 93 94
//    float rad = (waypointSize/2.0f) * 0.8 * (1/sqrt(2.0f));
//    painter.drawLine(p.x(), p.y(), p.x()+sin(yaw) * radius, p.y()-cos(yaw) * rad);
//    painter.drawPolygon(poly);
95
}