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