1 /*==================================================================
3 ! mardrone application AR-Drone for MeeGo
5 ! Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
8 ! Author:Kate Alhola kate.alhola@nokia.com
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.
20 *===================================================================*/
22 #include "gaugehorizon.h"
26 GaugeHorizon::GaugeHorizon(QGraphicsItem *parent) :
33 void GaugeHorizon::paint(QPainter *painter,const QStyleOptionGraphicsItem *option,
36 drawHorizon(painter,-1.0*m_value,5*m_value2);
38 //////////////////////////////////////////////////////////////////////////
39 void GaugeHorizon::drawHorizon(QPainter *painter, float roll, float pitch)
46 int tx, ctx, xd, i, j ;
47 int xo, yo, x1, x2, y1, y2;
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);
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)};
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)};
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]);
80 tx = (int)(xo * tan(roll * 3.141592653/180.0));
83 QTransform savematrix= painter->transform ();
84 // painter->setClipRect(QRect(0,0, size().width(),size().height()/2));
86 painter->setTransform(QTransform().translate(xo+scenePos().x(), yo+scenePos().y()+pitch).rotate(roll));
88 QBrush whitebrush(Qt::green);
89 painter->setBrush(whitebrush);
90 QPen whitepen(Qt::green);
92 painter->setPen(whitepen);
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);
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");
111 // painter->rotate(0);
112 painter->setTransform(savematrix);
113 QPen bluepen(Qt::blue);
115 painter->setPen(bluepen);
116 painter->drawLines(fixo);
117 painter->drawLines(plane);