debian build fixed for new name mardrone
[mardrone] / mardrone / gaugehorizon.cpp
1 /*==================================================================
2   !
3   !  mardrone application AR-Drone for MeeGo
4
5   ! Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
6   ! All rights reserved.
7   !
8   !  Author:Kate Alhola  kate.alhola@nokia.com
9   !
10   ! GNU Lesser General Public License Usage
11   ! This file may be used under the terms of the GNU Lesser
12   ! General Public License version 2.1 as published by the Free Software
13   ! Foundation and appearing in the file LICENSE.LGPL included in the
14   ! packaging of this file.  Please review the following information to
15   ! ensure the GNU Lesser General Public License version 2.1 requirements
16   ! will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17   !
18   !
19   !
20   *===================================================================*/
21
22 #include "gaugehorizon.h"
23 #include <QDebug>
24 #include <math.h>
25
26 GaugeHorizon::GaugeHorizon(QGraphicsItem *parent) :
27     Gauge(parent)
28 {
29 }
30
31
32
33 void GaugeHorizon::paint(QPainter *painter,const QStyleOptionGraphicsItem *option,
34                        QWidget *widget)
35 {
36     drawHorizon(painter,-1.0*m_value,5*m_value2);
37 };
38 //////////////////////////////////////////////////////////////////////////
39 void GaugeHorizon::drawHorizon(QPainter *painter, float roll, float pitch)
40     {
41       QRect update_rect;
42       QPoint points[10];
43       //QPoint plane[10];
44       QVector<QLine> plane;
45       QVector<QLine>  fixo;
46       int tx, ctx, xd, i, j ;
47       int xo, yo, x1, x2, y1, y2;
48
49       xo=size().width()/2;
50       yo=size().height()/2;
51
52       plane+=QLine(xo-50,yo,xo-20,yo);
53       plane+=QLine(xo-20,yo,xo-10,yo+10);
54       plane+=QLine(xo-10,yo+10,xo,yo);
55       plane+=QLine(xo,yo,xo+10,yo+10);
56       plane+=QLine(xo+20,yo,xo+10,yo+10);
57       plane+=QLine(xo+50,yo,xo+20,yo);
58
59
60       static float sintable[]={sin(15*3.141592653/180.0),
61                                sin(30*3.141592653/180.0),
62                                sin(45*3.141592653/180.0),
63                                sin(60*3.141592653/180.0)};
64
65       static float costable[]={cos(15*3.141592653/180.0),
66                                cos(30*3.141592653/180.0),
67                                cos(45*3.141592653/180.0),
68                                cos(60*3.141592653/180.0)};
69
70       i = 0;
71       int arc0=130;
72       int arc1=150;
73       fixo+=QLine(xo,yo-arc0,xo,yo-arc1);
74       for (i = 0; i < 4; i++) {
75         fixo+=QLine(xo+arc0*costable[i],yo-arc0*sintable[i],xo+arc1*costable[i],yo-arc1*sintable[i]);
76         fixo+=QLine(xo-arc0*costable[i],yo-arc0*sintable[i],xo-arc1*costable[i],yo-arc1*sintable[i]);
77       };
78
79
80       tx = (int)(xo * tan(roll * 3.141592653/180.0));
81       xd = yo + pitch * 4;
82
83       QTransform savematrix= painter->transform ();
84      // painter->setClipRect(QRect(0,0, size().width(),size().height()/2));
85
86       painter->setTransform(QTransform().translate(xo+scenePos().x(), yo+scenePos().y()+pitch).rotate(roll));
87
88       QBrush whitebrush(Qt::green);
89       painter->setBrush(whitebrush);
90       QPen whitepen(Qt::green);
91       whitepen.setWidth(2);
92       painter->setPen(whitepen);
93       xo=0;yo=0;
94
95       painter->drawLine(50+xo,    0+yo,-50+xo,   0+yo);
96       painter->drawLine(40+xo,   50+yo,-40+xo,  50+yo);
97       painter->drawLine(40+xo,  100+yo,-40+xo, 100+yo);
98       painter->drawLine(40+xo,  -50+yo,-40+xo, -50+yo);
99       painter->drawLine(40+xo, -100+yo,-40+xo,-100+yo);
100
101       painter->drawText( 43+xo,-40+yo,"10");
102       painter->drawText(-63+xo,-40+yo,"10");
103       painter->drawText( 43+xo,-90+yo,"20");
104       painter->drawText(-63+xo,-90+yo,"20");
105       painter->drawText( 43+xo, 40+yo,"10");
106       painter->drawText(-63+xo, 40+yo,"10");
107       painter->drawText( 43+xo, 90+yo,"20");
108       painter->drawText(-63+xo, 90+yo,"20");
109
110
111       //  painter->rotate(0);
112       painter->setTransform(savematrix);
113       QPen bluepen(Qt::blue);
114       bluepen.setWidth(2);
115       painter->setPen(bluepen);
116       painter->drawLines(fixo);
117       painter->drawLines(plane);
118
119
120
121 }
122