]> rtime.felk.cvut.cz Git - eurobot/public.git/blob - src/display-qt/displayqt.cpp
display-qt: Hiding the cursor.
[eurobot/public.git] / src / display-qt / displayqt.cpp
1 #include "displayqt.h"
2 #include "ui_displayqt.h"
3 #include <QtGui>
4 #include <QObject>
5 #include <QTimer>
6 #include <QString>
7 #include <robomath.h>
8
9 //backround colors for labels
10 #define GREEN "background-color:rgb(27, 255, 11)"
11 #define RED "background-color:red"
12 #define YELLOW "background-color:yellow"
13
14 DisplayQT::DisplayQT(QWidget *parent) :
15         QWidget(parent),
16         ui(new Ui::DisplayQT)
17 {
18         ui->setupUi(this);
19
20         /* create the window without the title bar */
21         Qt::WindowFlags flags = this->windowFlags();
22         flags |= Qt::FramelessWindowHint;
23         this->setWindowFlags(flags);
24
25         //cursor will be hidden
26         setCursor(QCursor(Qt::BlankCursor));
27
28         //na zacatku nazname polohu
29         this->pos.positionIsActual=false;
30
31         /*ASCII tocitko
32         pomoci timeru je kazdych 500 ms
33         vyvolan signal pro pohnuti tocitka
34         */
35
36         QTimer *timer = new QTimer(this);
37         timer->start(500);
38         connect(timer, SIGNAL(timeout()), this, SLOT(alive()));
39     ///***///
40
41     //premalovavani kompasu
42     connect(this, SIGNAL(repaintCompass()), this, SLOT(update()));
43 }
44
45 //sipka od uhlu natoceni
46 void DisplayQT::paintEvent(QPaintEvent *)
47 {
48         //umisteni stredu kompasu
49         int const x=410;
50         int const y=95;
51         int const dimension=80;
52
53         static const QPoint arrow[3] = {
54                 QPoint(4, 4),
55                 QPoint(-4, 4),
56                 QPoint(0, -((dimension/2)-15))
57     };
58
59
60         //barvy pro malovani
61         QColor prvniColor(127, 0, 127);
62         QColor druhaColor(0, 127, 127, 191);
63         QColor pozadi(240, 240, 240);
64
65         QPainter painter(this);
66
67         //background
68         painter.fillRect(x-dimension/2, y-dimension/2, dimension, dimension, pozadi);
69
70         painter.setRenderHint(QPainter::Antialiasing);
71         painter.translate(x,y);
72
73         painter.setPen(Qt::NoPen);
74         painter.setBrush(prvniColor);
75         painter.save();
76
77     //namalovani sipky p.t.k. je aktualni pozice
78         if(pos.positionIsActual){
79                 painter.rotate(90-pos.phi);
80                 painter.drawConvexPolygon(arrow, 3);
81         }
82         painter.restore();
83
84     //namaluju 4 cary po 90 stupnich
85         painter.setPen(prvniColor);
86         for(int i=0; i<4; i++){
87                 painter.drawLine((dimension/2)-10, 0, (dimension/2)-5, 0);
88                 painter.rotate(90.0);
89         }
90
91         //namaluju mensi cary mezi ty predchozi
92         painter.setPen(druhaColor);
93
94         for(int j=0; j<12; j++){
95                 if(j%3)
96                         painter.drawLine((dimension/2)-12, 0, (dimension/2)-7, 0);
97                 painter.rotate(30.0);
98         }
99 }
100
101 DisplayQT::~DisplayQT()
102 {
103         delete ui;
104 }
105
106 void DisplayQT::alive(void)
107 {
108         static char aliveState=0;
109         if(++aliveState==4)
110                 aliveState=0;
111
112         switch(aliveState){
113                 case 0: ui->ziju->setText("|");break;
114                 case 1: ui->ziju->setText("/");break;
115                 case 2: ui->ziju->setText("-");break;
116                 case 3: ui->ziju->setText("\\");break;
117         }
118 }
119
120 // 0-modra
121 // 1-cervena
122 void DisplayQT::setTeamColor(char color)
123 {
124         if(color==0){
125                 color=0;
126                 ui->our_color->setStyleSheet("background-color: blue");
127         }else if(color==1){
128                 color=1;
129                 ui->our_color->setStyleSheet("background-color: rgb(213, 40, 24)");
130         }
131 }
132
133 void DisplayQT::setPosition(double x, double y, double phi)
134 {
135         this->pos.x=x;
136         this->pos.y=y;
137         this->pos.phi=phi;
138
139         //prevod z radianu na stupne a uprava
140         pos.phi = RAD2DEG(pos.phi);
141         pos.phi = fmod(pos.phi, 360);
142         if ( pos.phi < 0 )
143                 pos.phi += 360;
144
145         ui->position_x->setText("x: "+QString::number(pos.x, 10, 3)+" m");
146         ui->position_y->setText("y: "+QString::number(pos.y, 10, 3)+" m");
147         ui->position_phi->setText("phi: "+QString::number(pos.phi, 10, 1)+" deg");
148
149         pos.positionIsActual=true;
150         emit repaintCompass();
151 }
152
153 void DisplayQT::display_status(UDE_component_t c, UDE_hw_status_t s)
154 {
155         switch(c){
156                 case 0:break;
157                 case MOT:
158                         if(s==STATUS_OK)
159                                 ui->comp_MOT->setStyleSheet(GREEN);
160                         else if(s==STATUS_FAILED)
161                                 ui->comp_MOT->setStyleSheet(RED);
162                         else
163                                 ui->comp_MOT->setStyleSheet(YELLOW);
164                 break;
165                 case ODO:
166                         if(s==STATUS_OK)
167                                 ui->comp_ODO->setStyleSheet(GREEN);
168                         else if(s==STATUS_FAILED)
169                                 ui->comp_ODO->setStyleSheet(RED);
170                         else
171                                 ui->comp_ODO->setStyleSheet(YELLOW);
172                 break;
173                 case CAM:
174                         if(s==STATUS_OK)
175                                 ui->comp_CAM->setStyleSheet(GREEN);
176                         else if(s==STATUS_FAILED)
177                                 ui->comp_CAM->setStyleSheet(RED);
178                         else
179                                 ui->comp_CAM->setStyleSheet(YELLOW);
180                         break;
181                 case PWR:
182                         if(s==STATUS_OK)
183                                 ui->comp_PWR->setStyleSheet(GREEN);
184                         else if(s==STATUS_FAILED){
185                                 ui->comp_PWR->setStyleSheet(RED);
186
187                                 ui->voltage_33->setText("v.33 = ?");
188                                 ui->voltage_50->setText("v.50 = ?");
189                                 ui->voltage_80->setText("v.80 = ?");
190                                 ui->voltage_BAT->setText("v.BAT = ?");
191
192                                 ui->voltage_33->setStyleSheet(YELLOW);
193                                 ui->voltage_50->setStyleSheet(YELLOW);
194                                 ui->voltage_80->setStyleSheet(YELLOW);
195                                 ui->voltage_BAT->setStyleSheet(YELLOW);
196                         }
197                         else
198                                 ui->comp_PWR->setStyleSheet(YELLOW);
199                 break;
200                 case HOK:
201                         if(s==STATUS_OK)
202                                 ui->comp_HOK->setStyleSheet(GREEN);
203                         else if(s==STATUS_FAILED)
204                                 ui->comp_HOK->setStyleSheet(RED);
205                         else
206                                 ui->comp_HOK->setStyleSheet(YELLOW);
207                         break;
208                 case APP:
209                         if(s==STATUS_OK)
210                                 ui->comp_APP->setStyleSheet(GREEN);
211                         else if(s==STATUS_FAILED){
212                                 ui->comp_APP->setStyleSheet(RED);
213
214                                 pos.positionIsActual=false;
215                                 ui->position_x->setText("x: ?");
216                                 ui->position_y->setText("y: ?");
217                                 ui->position_phi->setText("phi: ?");
218                                 emit repaintCompass();
219                         }
220                         else
221                                 ui->comp_APP->setStyleSheet(YELLOW);
222                         break;
223                 case VID:
224                         if(s==STATUS_OK)
225                                 ui->comp_VID->setStyleSheet(GREEN);
226                         else if(s==STATUS_FAILED)
227                                 ui->comp_VID->setStyleSheet(RED);
228                         else
229                                 ui->comp_VID->setStyleSheet(YELLOW);
230                         break;
231                 case STA:
232                         if(s==STATUS_OK)
233                                 ui->comp_STA->setStyleSheet(GREEN);
234                         else if(s==STATUS_FAILED)
235                                 ui->comp_STA->setStyleSheet(RED);
236                         else
237                                 ui->comp_STA->setStyleSheet(YELLOW);
238                 break;
239         }
240 }
241
242 void DisplayQT::display_fsm(UDE_fsm_t fsm, QString state){
243
244         switch(fsm){
245                 case FSM_MAIN:
246                         ui->fsm_main->setText(state);
247                 break;
248                 case FSM_MOVE:
249                         ui->fsm_move->setText(state);
250                 break;
251                 case FSM_ACT:
252                         ui->fsm_act->setText(state);
253                 break;
254         }
255 }
256
257 void DisplayQT::display_voltage(double voltage33, double voltage50, double voltage80, double voltageBAT){
258         ui->voltage_33->setText("v.33 = "+QString::number(voltage33, 10, 2)+" V");
259         ui->voltage_50->setText("v.50 = "+QString::number(voltage50, 10, 2)+" V");
260         ui->voltage_80->setText("v.80 = "+QString::number(voltage80, 10, 2)+" V");
261         ui->voltage_BAT->setText("v.BAT = "+QString::number(voltageBAT, 10, 2)+" V");
262
263
264         if( voltageBAT < WARNING_VOLTAGEBAT && voltageBAT > TRESHOLDS_VOLTAGEBAT )
265                 ui->voltage_BAT->setStyleSheet(YELLOW);
266         else if( voltageBAT < TRESHOLDS_VOLTAGEBAT )
267                 ui->voltage_BAT->setStyleSheet(RED);
268         else
269                 ui->voltage_BAT->setStyleSheet(GREEN);
270
271
272
273
274         if( voltage33 < TRESHOLDS_VOLTAGE33 )
275                 ui->voltage_33->setStyleSheet(YELLOW);
276         else
277                 ui->voltage_33->setStyleSheet(GREEN);
278
279         if( voltage50 < TRESHOLDS_VOLTAGE50 )
280                 ui->voltage_50->setStyleSheet(YELLOW);
281         else
282                 ui->voltage_50->setStyleSheet(GREEN);
283
284         if( voltage80 < TRESHOLDS_VOLTAGE80 )
285                 ui->voltage_80->setStyleSheet(YELLOW);
286         else
287                 ui->voltage_80->setStyleSheet(GREEN);
288 }