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) :
29 m_horizonLineColor=QColor("white");
30 m_horizonSkyColor=QColor("darkBlue");
31 m_horizonGroundColor=QColor("darkRed");
35 int xo=size().width()/2;
36 int yo=size().height()/2;
38 #define DR 3.141592653/180.0
39 int arcTable[]={30,45,60,70,80};
44 fixo+=QLine(xo,yo-arc0,xo,yo-arc1);
45 for (i = 0; i < 5; i++) {
46 fixo+=QLine(xo+arc0*cos(arcTable[i]*DR),yo-arc0*sin(arcTable[i]*DR),xo+arc1*cos(arcTable[i]*DR),yo-arc1*sin(arcTable[i]*DR));
47 fixo+=QLine(xo-arc0*cos(arcTable[i]*DR),yo-arc0*sin(arcTable[i]*DR),xo-arc1*cos(arcTable[i]*DR),yo-arc1*sin(arcTable[i]*DR));
49 plane+=QPoint(-40,15);
53 plane+=QPoint(-40,15);
55 planel+=QPoint(-140,2);
56 planel+=QPoint(-75,2);
57 planel+=QPoint(-70,0);
58 planel+=QPoint(-75,-2);
59 planel+=QPoint(-140,-2);
60 planel+=QPoint(-140,2);
62 planer+=QPoint(140,2);
65 planer+=QPoint(75,-2);
66 planer+=QPoint(140,-2);
67 planer+=QPoint(140,2);
69 zeroTriangle+=QPoint(0,-arc1);
70 zeroTriangle+=QPoint(-8,-arc1-16);
71 zeroTriangle+=QPoint(8,-arc1-16);
72 zeroTriangle+=QPoint(0,-arc1);
74 angleTriangle+=QPoint(0,-arc1);
75 angleTriangle+=QPoint(-8,-arc1+16);
76 angleTriangle+=QPoint(8, -arc1+16);
77 angleTriangle+=QPoint(0,-arc1);
82 void GaugeHorizon::paint(QPainter *painter,const QStyleOptionGraphicsItem *option,
85 drawHorizon(painter,-1.0*m_value,5*m_value2);
87 //////////////////////////////////////////////////////////////////////////
88 void GaugeHorizon::drawHorizon(QPainter *painter, float roll, float pitch)
95 xo=(size().width()/2)/m_scale;
96 if(m_ypos) yo=m_ypos/m_scale;
97 else yo=(size().height()/2)/m_scale;
99 painter->setClipRect(QRect(0,0, size().width(),size().height()));
100 painter->setTransform(QTransform().scale(m_scale,m_scale));
101 QTransform savematrix= painter->transform ();
102 // painter->setClipRect(QRect(0,0, size().width()/m_scale,size().height()/m_scale));
104 painter->setTransform(QTransform().translate(xo+scenePos().x()/m_scale, yo+scenePos().y()/m_scale).rotate(roll).translate(0,pitch),true);
105 // painter->setTransform(QTransform().translate(xo, yo).rotate(roll).translate(0,pitch),true);
107 // qDebug("roll=%f pitch=%f xo=%d yo=%d x=%f y=%f",roll,pitch,xo,yo ,xo+scenePos().x(),yo+scenePos().y());
109 QBrush skyBrush(m_horizonSkyColor);
110 QBrush groundBrush(m_horizonGroundColor);
111 painter->fillRect(QRect(-500,0,size().width()*2/m_scale,size().height()*2/m_scale),groundBrush);
112 QBrush bbrush(m_backColor);
113 QBrush cbrush(m_color);
115 painter->setBrush(bbrush);
116 painter->fillRect(QRect(-500,0,size().width()*2/m_scale,-1*size().height()*2/m_scale),skyBrush);
120 painter->setPen(pen);
122 painter->setTransform(savematrix);
123 painter->setTransform(QTransform().translate(xo+scenePos().x()/m_scale, yo+scenePos().y()/m_scale).rotate(roll),true);
125 painter->setClipRect(QRect(-100,-105, 200,210));
126 painter->setTransform(QTransform().translate(0,pitch),true);
128 for(int i=0;i<90;i++) {
129 painter->drawLine(40, 50*i,-40, 50*i);
130 painter->drawLine(20, 50*i+25,-20, 50*i+25);
131 painter->drawText(43,50*i+5,QString("%1").arg(10*i));
132 painter->drawText(-63,50*i+5,QString("%1").arg(10*i));
133 painter->drawLine(40, -50*i,-40, -50*i);
134 painter->drawLine(20, -50*i-25,-20, -50*i-25);
135 painter->drawText(43,-50*i+5,QString("%1").arg(10*i));
136 painter->drawText(-63,-50*i+5,QString("%1").arg(10*i));
140 painter->setTransform(savematrix);
141 painter->setTransform(QTransform().translate(xo+scenePos().x()/m_scale, yo+scenePos().y()/m_scale).rotate(roll),true);
143 painter->setBrush(cbrush);
144 painter->drawPolygon(angleTriangle);
147 painter->setTransform(savematrix);
148 painter->setTransform(QTransform().translate(xo+scenePos().x()/m_scale, yo+scenePos().y()/m_scale),true);
149 painter->setPen(pen);
150 painter->drawLines(fixo);
151 painter->drawConvexPolygon(plane);
152 painter->drawConvexPolygon(planel);
153 painter->drawConvexPolygon(planer);
154 painter->drawPolygon(zeroTriangle);
155 painter->drawArc(-150,-150,300,300,30*16,120*16);
156 // painter->setTransform(savematrix);