]> 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_WHITE:
133                         ui->our_color->setStyleSheet("background-color: white");
134                 break;
135                 case TC_GREEN:
136                         ui->our_color->setStyleSheet("background-color: green");
137                 break;
138                 case TC_YELLOW:
139                         ui->our_color->setStyleSheet("background-color: yellow");
140                 break;
141         }
142 }
143
144 void DisplayQT::setPosition(double x, double y, double phi)
145 {
146         this->pos.x=x;
147         this->pos.y=y;
148         this->pos.phi=phi;
149
150         //prevod z radianu na stupne a uprava
151         pos.phi = RAD2DEG(pos.phi);
152         pos.phi = fmod(pos.phi, 360);
153         if ( pos.phi < 0 )
154                 pos.phi += 360;
155
156         ui->position_x->setText("x: "+QString::number(pos.x, 10, 3)+" m");
157         ui->position_y->setText("y: "+QString::number(pos.y, 10, 3)+" m");
158         ui->position_phi->setText("phi: "+QString::number(pos.phi, 10, 1)+" deg");
159
160         pos.positionIsActual=true;
161         emit repaintCompass();
162 }
163
164 void DisplayQT::display_status(UDE_component_t c, UDE_hw_status_t s)
165 {
166         switch(c){
167                 case 0:break;
168                 case MOT:
169                         if(s==UDE_HW_STATUS_OK)
170                                 ui->comp_MOT->setStyleSheet(GREEN);
171                         else if(s==UDE_HW_STATUS_FAILED)
172                                 ui->comp_MOT->setStyleSheet(RED);
173                         else
174                                 ui->comp_MOT->setStyleSheet(YELLOW);
175                 break;
176                 case ODO:
177                         if(s==UDE_HW_STATUS_OK)
178                                 ui->comp_ODO->setStyleSheet(GREEN);
179                         else if(s==UDE_HW_STATUS_FAILED)
180                                 ui->comp_ODO->setStyleSheet(RED);
181                         else
182                                 ui->comp_ODO->setStyleSheet(YELLOW);
183                 break;
184                 case PWR:
185                         if(s==UDE_HW_STATUS_OK)
186                                 ui->comp_PWR->setStyleSheet(GREEN);
187                         else if(s==UDE_HW_STATUS_FAILED){
188                                 ui->comp_PWR->setStyleSheet(RED);
189
190                                 ui->voltage_33->setText("v.33 = ?");
191                                 ui->voltage_50->setText("v.50 = ?");
192                                 ui->voltage_80->setText("v.80 = ?");
193                                 ui->voltage_BAT->setText("v.BAT = ?");
194
195                                 ui->voltage_33->setStyleSheet(YELLOW);
196                                 ui->voltage_50->setStyleSheet(YELLOW);
197                                 ui->voltage_80->setStyleSheet(YELLOW);
198                                 ui->voltage_BAT->setStyleSheet(YELLOW);
199                         }
200                         else
201                                 ui->comp_PWR->setStyleSheet(YELLOW);
202                 break;
203                 case HOK:
204                         if(s==UDE_HW_STATUS_OK)
205                                 ui->comp_HOK->setStyleSheet(GREEN);
206                         else if(s==UDE_HW_STATUS_FAILED)
207                                 ui->comp_HOK->setStyleSheet(RED);
208                         else
209                                 ui->comp_HOK->setStyleSheet(YELLOW);
210                         break;
211                 case APP:
212                         if(s==UDE_HW_STATUS_OK)
213                                 ui->comp_APP->setStyleSheet(GREEN);
214                         else if(s==UDE_HW_STATUS_FAILED){
215                                 ui->comp_APP->setStyleSheet(RED);
216
217                                 pos.positionIsActual=false;
218                                 ui->position_x->setText("x: ?");
219                                 ui->position_y->setText("y: ?");
220                                 ui->position_phi->setText("phi: ?");
221                                 emit repaintCompass();
222                         }
223                         else
224                                 ui->comp_APP->setStyleSheet(YELLOW);
225                         break;
226                 case SIC:
227                         if(s==UDE_HW_STATUS_OK)
228                                 ui->comp_SIC->setStyleSheet(GREEN);
229                         else if(s==UDE_HW_STATUS_FAILED)
230                                 ui->comp_SIC->setStyleSheet(RED);
231                         else
232                                 ui->comp_SIC->setStyleSheet(YELLOW);
233                         break;
234                 case STA:
235                         if(s==UDE_HW_STATUS_OK)
236                                 ui->comp_STA->setStyleSheet(GREEN);
237                         else if(s==UDE_HW_STATUS_FAILED)
238                                 ui->comp_STA->setStyleSheet(RED);
239                         else
240                                 ui->comp_STA->setStyleSheet(YELLOW);
241                         break;
242                 case TIM:
243                         if(s==UDE_HW_STATUS_OK)
244                                 ui->matchTime->setStyleSheet(GREEN);
245                         else if(s==UDE_HW_STATUS_FAILED)
246                                 ui->matchTime->setStyleSheet(RED);
247                         else
248                                 ui->matchTime->setStyleSheet(YELLOW);
249                         break;
250         }
251 }
252
253 void DisplayQT::display_fsm(UDE_fsm_t fsm, QString state){
254
255         switch(fsm){
256                 case FSM_MAIN:
257                         ui->fsm_main->setText(state);
258                 break;
259                 case FSM_MOVE:
260                         ui->fsm_move->setText(state);
261                 break;
262                 case FSM_ACT:
263                         ui->fsm_act->setText(state);
264                 break;
265         }
266 }
267
268 void DisplayQT::display_voltage(double voltage33, double voltage50, double voltage80, double voltageBAT){
269         ui->voltage_33->setText("v.33 = "+QString::number(voltage33, 10, 2)+" V");
270         ui->voltage_50->setText("v.50 = "+QString::number(voltage50, 10, 2)+" V");
271         ui->voltage_80->setText("v.80 = "+QString::number(voltage80, 10, 2)+" V");
272         ui->voltage_BAT->setText("v.BAT = "+QString::number(voltageBAT, 10, 2)+" V");
273
274
275         if( voltageBAT < WARNING_VOLTAGEBAT && voltageBAT > TRESHOLDS_VOLTAGEBAT )
276                 ui->voltage_BAT->setStyleSheet(YELLOW);
277         else if( voltageBAT < TRESHOLDS_VOLTAGEBAT )
278                 ui->voltage_BAT->setStyleSheet(RED);
279         else
280                 ui->voltage_BAT->setStyleSheet(GREEN);
281
282         if( voltage33 < TRESHOLDS_VOLTAGE33 )
283                 ui->voltage_33->setStyleSheet(YELLOW);
284         else
285                 ui->voltage_33->setStyleSheet(GREEN);
286
287         if( voltage50 < TRESHOLDS_VOLTAGE50 )
288                 ui->voltage_50->setStyleSheet(YELLOW);
289         else
290                 ui->voltage_50->setStyleSheet(GREEN);
291
292         if( voltage80 < TRESHOLDS_VOLTAGE80 )
293                 ui->voltage_80->setStyleSheet(YELLOW);
294         else
295                 ui->voltage_80->setStyleSheet(GREEN);
296 }