rock_widget_collection  0.1
artificialhorizon.cc
Go to the documentation of this file.
1 #include "artificialhorizon.h"
2 #include <QPixmap>
3 #include <QPainter>
4 #include <math.h>
5 #include <QtCore/QtPlugin>
6  #include <QtCore/QDir>
7 #include <iostream>
8 
10 QWidget(parent)
11 {
12  rollangle = 0;
13  pitchangle = 0;
14  setDataDir(":/");
15 }
16 
17 void ArtificialHorizon::setDataDir(QString const& data_dir)
18 {
19  stationary_o = QImage(data_dir + "stationary.svg");
20  background_o = QPixmap(stationary_o.size());
21  rotate_o = QImage(data_dir + "rotate.svg");
22  dial_o = QImage(data_dir + "dial.svg");
23  background = background_o;
24  stationary = stationary_o;
25  rotate = rotate_o;
26  dial = dial_o;
27 
28 
29 }
30 
32 {
33  return new ArtificialHorizon();
34 }
35 
36 void ArtificialHorizon::setRollAngle(double myvalue)
37 {
38  if (myvalue!=rollangle)
39  {
40  rollangle = myvalue;
41  this->update();
42  }
43 }
45 {
46  if (myvalue!=pitchangle)
47  {
48  pitchangle = myvalue;
49  this->update();
50  }
51 }
53 {
54  QPoint point=QPoint(0,0);
55  QTransform transform;
56  transform.translate(background.width()/2.0,background.height()/2.0);
57  transform.rotate(-rollangle*180.0/M_PI);
58  transform.translate(0,-pitchangle*180.0/M_PI*3.5);
59  transform.translate(-background.width()/2.0,-background.height()/2.0);
60 
61  QPainter painter(this);
62  painter.save(); // save the current painter settings before changing them
63  painter.setClipRect(0,0,background.width(),background.height());
64 
65  painter.setTransform(transform);
66  painter.translate(0,-background.height()/2.0-background.height()*0.0328947368421);
67  painter.drawImage(0,0, rotate); // draw the stationary
68 
69  transform.translate(background.width()/2.0,background.height()/2.0);
70  transform.translate(0,pitchangle*180.0/M_PI*3.5);
71  transform.translate(-background.width()/2.0,-background.height()/2.0);
72  painter.setTransform(transform);
73 
74  painter.drawImage(0,0, dial); // draw the stationary
75  painter.restore(); // restore the previous painter settings
76  painter.drawImage( point,stationary);
77  painter.end();
78 }
79 
80 void ArtificialHorizon::resizeEvent(QResizeEvent *event){
81  QWidget::resizeEvent(event);
82 
83  background = background_o.scaled(size(),Qt::KeepAspectRatio);
84  stationary = stationary_o.scaled(size(),Qt::KeepAspectRatio);
85  dial = dial_o.scaled(size(),Qt::KeepAspectRatio);
86  rotate = rotate_o.scaledToWidth(dial.width()*1.01315789474);
87 }
88 
90 {
91 
92 }
void setRollAngle(double myvalue)
ArtificialHorizon(QWidget *parent=NULL)
void paintEvent(QPaintEvent *)
void setPitchAngle(double myval)
ArtificialHorizon * newInstance()
void setDataDir(QString const &data_dir)
void resizeEvent(QResizeEvent *event)