-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFenetrePrincipale.cpp
More file actions
320 lines (229 loc) · 8.63 KB
/
FenetrePrincipale.cpp
File metadata and controls
320 lines (229 loc) · 8.63 KB
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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
#include "FenetrePrincipale.h"
#include "wiimote.h"
Fenetre::Fenetre()
{
// =====Démarrage Fenêtre=====
setMinimumSize(250,350);
QString titre("WiiSouris par Bastnt v");
titre += VERSION;
setWindowTitle(titre);
setWindowIcon(QPixmap("icone.png"));
clic_gauche = 0;
screen_height = GetSystemMetrics(SM_CYSCREEN);
screen_width = GetSystemMetrics(SM_CXSCREEN);
// =====Démarrage Fenêtre=====
// =====Information de la Wiimote=====
group_informations = new QGroupBox("Informations");
informations = new QFormLayout();
batterie = new QLabel("Batterie :");
QLabel *IRled = new QLabel();
batterie_info = new QProgressBar;
batterie_info->setValue(0);
informations->addRow("&Batterie :", batterie_info);
informations->addRow("&LED Visible :", IRled);
group_informations->setLayout(informations);
// =====Information de la Wiimote=====
// =====Controle de la Wiimote=====
QGroupBox *group_controle = new QGroupBox("Contrôle");
QBoxLayout *controle = new QBoxLayout(QBoxLayout::TopToBottom);
QLabel *info = new QLabel("<U><B>Boutons :</B></U><br /> - A : Clique (glisser/déposer)<br /> - B : Clique ponctuel<br /> - 1 : Clique droit<br /> - Home : Activer / Désactiver la souris<br /> - Flèches directionnelles<br /><hr />");
info->setTextFormat(Qt::RichText);
precision = new QLabel(QString("Lissage : %1").arg(INTERVALLE));
smooth = new QSlider(Qt::Horizontal);
smooth->setRange(10,100);
smooth->setTickPosition(QSlider::TicksAbove);
smooth->setValue(INTERVALLE);
souris = new QCheckBox("Contrôle de la souris");
souris->setCheckState(Qt::Checked);
controle->addWidget(info);
controle->addWidget(souris);
controle->addWidget(precision);
controle->addWidget(smooth);
group_controle->setLayout(controle);
QObject::connect(smooth, SIGNAL(valueChanged(int)), this, SLOT(Lissage(int)));
// =====Controle de la Wiimote=====
// ===== Boutons =====
QBoxLayout *boutons = new QBoxLayout(QBoxLayout::LeftToRight);
propos = new QPushButton(" A propos");
quitter = new QPushButton("Quitter");
boutons->addWidget(propos);
boutons->addWidget(quitter);
connect(quitter, SIGNAL(clicked()), qApp, SLOT(quit()));
connect(propos, SIGNAL(clicked()), this, SLOT(about()));
// ===== Boutons =====
// =====Initialisation fenêtre=====
layout_principal = new QBoxLayout(QBoxLayout::TopToBottom);
layout_principal->addWidget(group_informations);
layout_principal->addWidget(group_controle);
layout_principal->addLayout(boutons);
setLayout(layout_principal);
setDisabled(1);
// =====Initialisation fenêtre=====
// =====Démarrage de la wiimote=====
demarrage = new FenDemarre(this, Qt::Tool);
demarrage->show();
remote = new wiimote();
timer = new QTimer(this);
QObject::connect(timer, SIGNAL(timeout()), this, SLOT(FConnection()));
timer->start(200);
// =====Démarrage de la wiimote=====
// =====Création du systemTray=====
menu = new QSystemTrayIcon(QIcon(QPixmap("icone.png")), this);
strestorer = new QAction(tr("&Restorer"), this);
connect(strestorer, SIGNAL(triggered()), this, SLOT(Restorer()));
stquitter = new QAction(tr("&Quitter"), this);
connect(stquitter, SIGNAL(triggered()), qApp, SLOT(quit()));
stmenu = new QMenu(this);
stmenu->addAction(strestorer);
stmenu->addSeparator();
stmenu->addAction(stquitter);
menu->setContextMenu(stmenu);
menu->setToolTip(titre);
connect(menu, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(Restorer(QSystemTrayIcon::ActivationReason)));
menu->show();
// =====Création du systemTray=====
}
void Fenetre::FConnection() // Recher de la wiimote
{
if(remote->Connect(wiimote::FIRST_AVAILABLE)) // Wiimote trouvé !
{
timer->stop();
Beep(600,500);
demarrage->hide();
setDisabled(0);
if(remote->bExtension)
remote->SetReportType(wiimote::IN_BUTTONS_ACCEL_IR_EXT); // no IR dots
else
remote->SetReportType(wiimote::IN_BUTTONS_ACCEL_IR); // IR dots
remote->SetLEDs((BYTE)(1<<0));
remote->RefreshState();
batterie_info->setValue(remote->BatteryPercent);
QObject::disconnect(timer, 0, this, 0);
QObject::connect(timer, SIGNAL(timeout()), this, SLOT(continuer()));
timer->start(INTERVALLE);
}
}
void Fenetre::continuer() // Boucle de programme
{
if(remote->ConnectionLost())
{
QMessageBox::warning(this, "Erreur", "La connexion avec la wiimote a été perdu.");
qApp->quit();
}
if(remote->RefreshState() != NO_CHANGE)
{
//=============Touches==================
if (remote->Button.Left())
keybd_event(VK_LEFT,0,0,0);
else
keybd_event(VK_LEFT,0,KEYEVENTF_KEYUP,0);
if (remote->Button.Right())
keybd_event(VK_RIGHT,0,0,0);
else
keybd_event(VK_RIGHT,0,KEYEVENTF_KEYUP,0);
if (remote->Button.Up())
keybd_event(VK_UP,0,0,0);
else
keybd_event(VK_UP,0,KEYEVENTF_KEYUP,0);
if (remote->Button.Down())
keybd_event(VK_DOWN,0,0,0);
else
keybd_event(VK_DOWN,0,KEYEVENTF_KEYUP,0);
if (remote->Button.A()){
if(!clic_gauche)
{
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
clic_gauche = 1;
}
}
else if(clic_gauche)
{
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
clic_gauche=0;
}
if (remote->Button.B())
{
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
Sleep(200);
}
if (remote->Button.One())
{
mouse_event(MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0);
mouse_event(MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0);
Sleep(200);
}
if (remote->Button.Home())
{
if(souris->isChecked())
{
souris->setCheckState(Qt::Unchecked);
remote->SetLEDs(0);
}
else
{
souris->setCheckState(Qt::Checked);
remote->SetLEDs((BYTE)(1<<0));
}
Sleep(300);
}
//=============Touches==================
//=============Souris===================
if(remote->IR.Dot[0].bVisible && souris->isChecked())
{
x = (remote->IR.Dot[0].X * screen_width);
y = (remote->IR.Dot[0].Y * screen_height);
SetCursorPos(x, y);
}
//=============Souris===================
}
}
void Fenetre::Restorer(QSystemTrayIcon::ActivationReason raseon)
{
if(raseon == QSystemTrayIcon::DoubleClick && isHidden())
{
setWindowFlags(Qt::Window);
showNormal();
}
}
void Fenetre::about()
{
QMessageBox::information(this, "A propos de Wiisouris", "Wiisouris vous permet de contrôler votre souris avec une Wiimote.<br />Vous devez connecter votre manette par bluetooth.<br />Informations :<br /><ul><li>Wiisouris v3.6 license GPL</li><li>Codeur : Bastnt</li><li>langage : C++</li><li>Librairie Tierce : Qt</li></ul><br /><a href='http://bastnt.free.fr/'>bastnt.free.fr</a>(bastien45@gmail.com)");
}
void Fenetre::hideEvent ( QHideEvent * event ) //Notification lors de la réduction
{
setWindowFlags(Qt::Tool);
hide();
}
void Fenetre::Lissage(int valeur) //Changement de lissage
{
QString resultat;
resultat = QString("Lissage : %1").arg(valeur);
precision->setText(resultat);
timer->setInterval(valeur);
}
void Fenetre::closeEvent(QCloseEvent *event)
{
qApp->quit();
}
Fenetre::~Fenetre() //Destruction wiimote
{
remote->Disconnect();
delete remote;
}
FenDemarre::FenDemarre(QWidget *parent=0, Qt::WindowFlags f=0) : QWidget(parent, f) //Création fenetre de Démarrage
{
setWindowModality(Qt::WindowModal);
setWindowTitle("Démarrage ...");
QLabel *lancement = new QLabel("Recherche d'une wiimote ...");
QPushButton *annuler = new QPushButton("Annuler");
QBoxLayout *group_demarrage = new QBoxLayout(QBoxLayout::TopToBottom);
group_demarrage->addWidget(lancement);
group_demarrage->addWidget(annuler);
setLayout(group_demarrage);
QObject::connect(annuler, SIGNAL(clicked()), qApp, SLOT(quit()));
}
void FenDemarre::closeEvent(QCloseEvent *event) // Empêcher la fermeture
{
event->ignore();
}