Bonjour (ou bonsoir),
Voici une autre de mes contributions, un exemple de commande graphique.
Dans ce programme, Il y a 4 commandes de direction, nord ,sud ,est et ouest, un doneute jaune (la forme la plus proche) un rectangle en dégradé de rouge ,le tout sur un fond de petits carrés bleus dégradés.
Le doneute jaune est commandable par les 4 boutons ,et peut permettre de pousser, activer le déplacement automatique, du rectangle rouge vers 4 directions.
Les librairies c++ qt5 QGraphic* ne sont pas utilisées dans ce programme.
Il a été créé sans le qcreator sous linux 64 bureau graphique cinnamon, il est compilable avec qmake et make.
g++ et qt5 doivent être instalés.
objehexpedi3.cpp
objehexpedi3.h
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65 //version numero 0.36 #include "objehexpedi3.h" #include <QApplication> //#include <QPainter> #include <QPushButton> //include <QAbstractButton> #include <QPixmap> #include <QGridLayout> #include <QTimer> int main(int argc,char ** argv) { QApplication app(argc,argv) ; QPushButton * nordpb = new QPushButton("Nord") ; QPushButton * sudpb = new QPushButton("Sud") ; QPushButton * estepb = new QPushButton("Est") ; QPushButton * ouestepb = new QPushButton("Ouest") ; nordpb->setAutoRepeat(true) ; nordpb->setAutoRepeatInterval(33) ; sudpb->setAutoRepeat(true) ; sudpb->setAutoRepeatInterval(33) ; estepb->setAutoRepeat(true) ; estepb->setAutoRepeatInterval(33) ; ouestepb->setAutoRepeat(true) ; ouestepb->setAutoRepeatInterval(33) ; QPixmap image(600,600) ; image.fill(Qt::blue) ; QLabel * elemnt = new QLabel ; elemnt->setPixmap(image) ; QGridLayout * ordre = new QGridLayout ; ordre->addWidget(elemnt,0,0,1,3) ; ordre->addWidget(nordpb,1,1) ; ordre->addWidget(ouestepb,2,0) ; ordre->addWidget(estepb,2,2) ; ordre->addWidget(sudpb,3,1) ; QWidget * fenetre = new QWidget ; fenetre->setLayout(ordre) ; fenetre->show() ; QTimer * secoule = new QTimer ; secoule->setInterval(33) ; Objexpedi obj ; obj.config(fenetre,elemnt,image) ; QObject::connect(nordpb,SIGNAL(clicked()),&obj,SLOT(nord()) ) ; QObject::connect(sudpb,SIGNAL(clicked()),&obj,SLOT(sud()) ) ; QObject::connect(estepb,SIGNAL(clicked()),&obj,SLOT(este()) ) ; QObject::connect(ouestepb,SIGNAL(clicked()),&obj,SLOT(oueste()) ) ; QObject::connect(&obj,SIGNAL(sarretepa()),&obj,SLOT(valid()) ) ; QObject::connect(&obj,SIGNAL(sarretepa1()),&obj,SLOT(valid()) ) ; QObject::connect(&obj,SIGNAL(sarretepa2()),&obj,SLOT(valid()) ) ; QObject::connect(&obj,SIGNAL(sarretepa3()),&obj,SLOT(valid()) ) ; QObject::connect(&obj,SIGNAL(deroule()),&obj,SLOT(y2_expedionord()) ) ; QObject::connect(&obj,SIGNAL(deroule()),&obj,SLOT(y2_expediosud()) ) ; QObject::connect(&obj,SIGNAL(deroule()),&obj,SLOT(x2_expedialeste()) ) ; QObject::connect(&obj,SIGNAL(deroule()),&obj,SLOT(x2_expedialoueste()) ) ; QObject::connect(&obj,SIGNAL(apressetemp()),secoule,SLOT(start()) ) ; QObject::connect(secoule,SIGNAL(timeout()),&obj,SLOT(affich()) ) ; secoule->start() ; app.exec() ; return 0 ; }
objets3.h
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268 //version numero 0.38 #ifndef _OBJEHEXPEDI3_H_ #define _OBJEHEXPEDI3_H_ #include "objets3.h" #include <QPixmap> #include <QLabel> #include <QPainter> #include <QWidget> #include <QString> #include <QObject> class Objexpedi : public QObject { Q_OBJECT public : void config(QWidget * fenetre,QLabel * composan1,QPixmap image) { a_widget = new QWidget ; a_widget = fenetre ; a_label = new QLabel ; a_label = composan1 ; a_image = image ; i_x = 240 ; i_y = 240 ; i_x2 = 0 ; i_y2 = 0 ; validenord = 2 ; validesud = 2 ; valideeste = 2 ; valideoueste = 2 ; } //objet expedieh est un rectangle 300,300 ,100,120 //ligne a du rectangle : 300,300 , 400,300 //ligne b du rectangle : 300,300 , 300,420 //ligne c du rectangle : 400,300 , 400,420 //ligne d du rectangle : 300,420 , 400,420 public slots : void y2_expedionord() { if ((i_y2 > -300 ) and (validenord == 0)) { i_y2-=2 ; } if((i_y2 <= -300 ) and (validenord == 0)) { i_y2 = -300 ; validenord = 1 ;} } void y2_expediosud() { if ((i_y2 < 80 ) and (validesud == 0)) { i_y2+=2 ; } if ((i_y2 >= 80 ) and (validesud == 0)) { i_y2 = 80 ; validesud = 1 ;} } void x2_expedialeste() { if ((i_x2 < 100 ) and (valideeste == 0)) { i_x2+=2 ; } if ((i_x2 >= 100 ) and (valideeste == 0)) { i_x2 = 100 ; valideeste = 1 ;} } void x2_expedialoueste() { if ((i_x2 > -300 ) and (valideoueste == 0) ) { i_x2-=2 ; } if((i_x2 <= -300 ) and (valideoueste == 0) ) { i_x2 = -300 ; valideoueste = 1 ; } } void nord() { i_y-= 2 ; if(i_y2 <= -300 ) { i_y2 = -300 ;} //ligne a 300,300 , 400,300 if( (i_y == (300 + i_y2)) and (i_x <= (400 + i_x2)) and ((i_x + 50 ) >= (300 + i_x2)) ) { validenord = 0 ; if ( i_y2 > -300 ) { i_y2-=2 ; } i_y = 302 + i_y2 ; } //ligne b 300,300 , 300,420 if( (i_y == (420 + i_y2)) and (i_x <= (300 + i_x2)) and ((i_x + 50 ) >= (300 + i_x2)) ) { validenord = 0 ; if ( i_y2 > -300 ) { i_y2-=2 ; } i_y = 422 + i_y2 ; } //ligne c 400,300 , 400,420 if( (i_y == (420 + i_y2)) and (i_x <= (400 + i_x2)) and ((i_x + 50) >= (400 + i_x2)) ) { validenord = 0 ; if ( i_y2 > -300 ) { i_y2-=2 ; } i_y = 422 + i_y2 ; } //ligne d 300,420 , 400,420 if( (i_y == (420 + i_y2)) and (i_x <= (400 + i_x2)) and ((i_x + 50 ) >= (300 + i_x2)) ) { validenord = 0 ; if ( i_y2 > -300 ) { i_y2-=2 ; } i_y = 422 + i_y2 ; } } void sud() { i_y+= 2 ; if (i_y2 >= 80 ) { i_y2 = 80 ; } //ligne a if( ((i_y + 50 ) == ( 300 + i_y2)) and (i_x <= ( 400 + i_x2)) and ((i_x + 50 ) >= (300 + i_x2)) ) { validesud = 0 ; if (i_y2 < 80 ) { i_y2+=2 ; } i_y = 248 + i_y2; } //ligne b if( ((i_y + 50) == ( 300 + i_y2)) and (i_x <= ( 300 + i_x2)) and ((i_x + 50 ) >= (300 + i_x2)) ) { validesud = 0 ; if (i_y2 < 80 ) { i_y2+=2 ; } i_y = 248 + i_y2; } //ligne c if( ((i_y + 50 ) == (300 + i_y2)) and (i_x <= (400 + i_x2)) and ((i_x + 50) >= (400 + i_x2)) ) { validesud = 0 ; if (i_y2 < 80 ) { i_y2+=2 ; } i_y = 248 + i_y2; } //ligne d 300,420 , 400,420 if( ((i_y + 50 ) == (420 + i_y2) ) and (i_x <= (400 + i_x2) ) and ( (i_x + 50 ) >= (300 + i_x2)) ) { validesud = 0 ; if (i_y2 < 80 ) { i_y2+=2 ; } i_y = 368 + d_cal + i_y2; } } void este() { i_x+= 2 ; if (i_x2 >= 100 ) { i_x2 = 100 ; } //ligne a 300,300 , 400,300 if( ((i_y +50) >= (300 + i_y2) ) and (i_y <= (300 + i_y2) ) and ((i_x + 50) == (300 + i_x2)) ) { valideeste = 0 ; if (i_x2 < 100 ) { i_x2+=2 ; } i_x = 248 + i_x2 ; } //linge b 300,300 , 300,420 if( ((i_y +50 ) >= (300 + i_y2) ) and (i_y <= (420 + i_y2) ) and ((i_x + 50) == (300 + i_x2 )) ) { valideeste = 0 ; if (i_x2 < 100 ) { i_x2+=2 ; } i_x = 248 + i_x2 ; } //linge c 400,300 , 400,420 if( ((i_y +50 ) >= (300 + i_y2) ) and (i_y <= (420 + i_y2) ) and ((i_x + 50 ) == (400 + i_x2)) ) { valideeste = 0 ; if (i_x2 < 100 ) { i_x2+=2 ; } i_x = 348 + i_x2 ; } //linge d 300,420 , 400,420 if( ((i_y +50 ) >= (420 + i_y2) ) and (i_y <= (420 + i_y2) ) and ((i_x + 50) == (300 + i_x2)) ) { valideeste = 0 ; if (i_x2 < 100 ) { i_x2+=2 ; } i_x = 248 + i_x2 ; } } void oueste() { i_x-= 2 ; if(i_x2 <= -300 ) { i_x2 = -300 ; } if( ((i_y +50) >= (300 + i_y2) ) and (i_y <= (300 + i_y2) ) and (i_x == (400 + i_x2) ) ) { valideoueste = 0 ; if (i_x2 > -300 ) { i_x2-=2 ; } i_x = 402 + i_x2 ; } //ligne b if( ((i_y + 50) >= (300 + i_y2) ) and (i_y <= (420 + i_y2) ) and (i_x == (300 + i_x2)) ) { valideoueste = 0 ; if (i_x2 > -300 ) { i_x2-=2 ; } i_x = 302 + i_x2 ; } //ligne c if( ((i_y +50 ) >= (300 + i_y2) ) and (i_y <= (420 + i_y2) ) and (i_x == (400 + i_x2)) ) { valideoueste = 0 ; if (i_x2 > -300 ) { i_x2-=2 ; } i_x = 402 + i_x2 ; } //ligne d if( ((i_y +50 ) >= (420 + i_y2) ) and (i_y <= (420 + i_y2) ) and (i_x == (400 + i_x2)) ) { valideoueste = 0 ; if (i_x2 > -300 ) { i_x2-=2 ; } i_x = 402 + i_x2 ; } } void valid() { emit apressetemp() ; } void affich() { if (validenord == 0) { emit sarretepa() ; } if (validesud == 0) { emit sarretepa1() ; } if (valideeste == 0) { emit sarretepa2() ; } if (valideoueste == 0) { emit sarretepa3() ; } Objdpldev obje1 ; a_image.fill() ; a_image = obje1.bofond() ; a_label->clear() ; QPainter crayon(&a_image) ; crayon.translate(50,50) ; crayon.drawPixmap(i_x ,i_y ,obje1.doneutedegraD()) ; crayon.drawPixmap(i_x2 + 300 ,i_y2 + 300 ,obje1.rectangldegraD()) ; crayon.end() ; a_label->setPixmap(a_image) ; a_label->update() ; a_widget->update() ; emit deroule() ; } signals : void apressetemp() ; void sarretepa() ; void sarretepa1() ; void sarretepa2() ; void sarretepa3() ; void deroule() ; private : int d_cal ; int i_x ; int i_y ; int i_x2 ; int i_y2 ; int validenord ; int validesud ; int valideeste ; int valideoueste ; QWidget * a_widget ; QLabel * a_label ; QPixmap a_image ; }; #endif
Image capturé :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89 #include <QPixmap> #include <QPainter> #include <QColor> #include <QPen> class Objdpldev { public : QPixmap bofond() { QPixmap dallebleu(25,25) ; dallebleu.fill() ; QPainter stylet(&dallebleu) ; QColor degradbleu(0,0,0) ; int cpt = 0 ; for(cpt = 0 ;cpt < 25 ; cpt++) { degradbleu.setRgb(0,0,(5 * cpt)) ; stylet.setPen(degradbleu) ; stylet.drawLine(0,cpt,cpt,0) ; } for (cpt = 0;cpt < 25; cpt++) { degradbleu.setRgb(0,0,((cpt * 5)+ 125) ) ; stylet.setPen(degradbleu) ; stylet.drawLine(cpt,25,25,cpt) ; } stylet.end() ; QPixmap fond(500,500) ; fond.fill() ; QPainter stylet2(&fond) ; int cpt2 = 0 ; for (cpt = 0; cpt < 500 ;cpt+= 25) { stylet2.drawPixmap(cpt, cpt2 ,dallebleu) ; if (cpt >= 475) { cpt = -25 ;cpt2+= 25 ; } //----------------------------------------------- if (cpt2 > 475) { cpt = 500; } } stylet2.end() ; QColor gris(35,35,35) ; QPixmap fond2(600,600) ; fond2.fill(gris) ; QPainter stylet3(&fond2) ; stylet3.drawPixmap(50,50,fond) ; stylet3.end() ; return fond2 ; } QPixmap doneutedegraD() { QColor feu(0, 0, 0) ; QColor transparent(0,0,0,0) ; QPixmap image0(50, 50) ; image0.fill(transparent) ; QPen mince; mince.setWidth(2) ; QPainter stylet(&image0) ; int cpt1 = 0 ; int cpt2 = 0 ; for (cpt1 = 0 ; cpt1 <= 25 ;cpt1++) { if ( (25-cpt1) <= 10 ) { cpt2 = 255 - cpt1 * 10 ; } else { cpt2 = cpt1 * 10 ; } feu.setRgb(cpt2, cpt2, 0) ; mince.setColor(feu) ; stylet.setPen(mince) ; stylet.drawEllipse(cpt1,cpt1,((25-cpt1) *2),((25-cpt1) *2)) ; } stylet.end() ; return image0 ; } QPixmap rectangldegraD() { QPixmap image58(100,120) ; image58.fill() ; int cpt99 = 0 ; int cpt57 = 10 ; QColor lignes(0,0,0) ; QPainter stylet(&image58) ; for(cpt99 = 0 ; cpt99 < 120 ; cpt99++) { if (cpt99 > 60) { cpt57-= 2 ; } if (cpt99 <= 60) { cpt57+= 2 ; } lignes.setRgb(cpt57,0,0) ; stylet.setPen(lignes) ; stylet.drawLine(0,cpt99,100,cpt99) ; } stylet.end() ; return image58 ; } };
Partager