direcs  2012-09-30
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
joystickDialog.cpp
Go to the documentation of this file.
1 /*************************************************************************
2  * Copyright (C) Markus Knapp *
3  * www.direcs.de *
4  * *
5  * This file is part of direcs. *
6  * *
7  * direcs is free software: you can redistribute it and/or modify it *
8  * under the terms of the GNU General Public License as published *
9  * by the Free Software Foundation, version 3 of the License. *
10  * *
11  * direcs is distributed in the hope that it will be useful, *
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14  * GNU General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU General Public License *
17  * along with direcs. If not, see <http://www.gnu.org/licenses/>. *
18  * *
19  *************************************************************************/
20 
21 #include "joystickDialog.h"
22 
23 JoystickDialog::JoystickDialog(QWidget* parent) : QDialog(parent)
24 {
25  ui.setupUi(this);
26 }
27 
28 
29 void JoystickDialog::showJoystickButtons(int buttonNumber, bool buttonState)
30 {
32  static bool toggle0 = false;
33  static bool toggle1 = false;
34  //static bool toggle2 = false;
35  //static bool toggle3 = false;
36  static bool toggle4 = false;
37  //static bool toggle5 = false;
38  static bool toggle10 = false;
39  static bool toggle11 = false;
40 
41 
43  switch (buttonNumber)
44  {
45  case 0:
46  if (buttonState==true)
47  {
48  toggle0 = !toggle0;
49  }
50  ui.radioBtnJoy0->setChecked(toggle0);
51  break;
52  case 1:
53  if (buttonState)
54  {
55  toggle1 = !toggle1;
56  }
57  ui.radioBtnJoy1->setChecked(toggle1);
58  break;
59  case 2:
60  ui.radioBtnJoy2->setChecked(buttonState);
61  break;
62  case 3:
63  ui.radioBtnJoy3->setChecked(buttonState);
64  break;
65  case 4:
66  if (buttonState==true)
67  {
68  toggle4 = !toggle4;
69  }
70  ui.radioBtnJoy4->setChecked(toggle4);
71  break;
72  case 5:
73  ui.radioBtnJoy5->setChecked(buttonState);
74  break;
75  case 10:
76  if (buttonState)
77  {
78  toggle10 = !toggle10;
79  }
80  ui.radioBtnJoy10->setChecked(toggle10);
81  break;
82  case 11:
83  if (buttonState==true)
84  {
85  toggle11 = !toggle11;
86  }
87  ui.radioBtnJoy11->setChecked(toggle11);
88  break;
89  }
90 }
91 
92 
94 {
95  switch (buttonsState)
96  {
97  case 0:
98  ui.radioBtnJoy4Left->setChecked(false);
99  ui.radioBtnJoy4Right->setChecked(false);
100  ui.radioBtnJoy5Up->setChecked(false);
101  ui.radioBtnJoy5Down->setChecked(false);
102  break;
103  case 1: // up
104  ui.radioBtnJoy4Left->setChecked(false);
105  ui.radioBtnJoy4Right->setChecked(false);
106  ui.radioBtnJoy5Up->setChecked(true);
107  ui.radioBtnJoy5Down->setChecked(false);
108  break;
109  case 2: // up right
110  ui.radioBtnJoy4Left->setChecked(false);
111  ui.radioBtnJoy4Right->setChecked(true);
112  ui.radioBtnJoy5Up->setChecked(true);
113  ui.radioBtnJoy5Down->setChecked(false);
114  break;
115  case 3: // right
116  ui.radioBtnJoy4Left->setChecked(false);
117  ui.radioBtnJoy4Right->setChecked(true);
118  ui.radioBtnJoy5Up->setChecked(false);
119  ui.radioBtnJoy5Down->setChecked(false);
120  break;
121  case 4: // down right
122  ui.radioBtnJoy4Left->setChecked(false);
123  ui.radioBtnJoy4Right->setChecked(true);
124  ui.radioBtnJoy5Up->setChecked(false);
125  ui.radioBtnJoy5Down->setChecked(true);
126  break;
127  case 5: // down
128  ui.radioBtnJoy4Left->setChecked(false);
129  ui.radioBtnJoy4Right->setChecked(false);
130  ui.radioBtnJoy5Up->setChecked(false);
131  ui.radioBtnJoy5Down->setChecked(true);
132  break;
133  case 6: // down left
134  ui.radioBtnJoy4Left->setChecked(true);
135  ui.radioBtnJoy4Right->setChecked(false);
136  ui.radioBtnJoy5Up->setChecked(false);
137  ui.radioBtnJoy5Down->setChecked(true);
138  break;
139  case 7: // left
140  ui.radioBtnJoy4Left->setChecked(true);
141  ui.radioBtnJoy4Right->setChecked(false);
142  ui.radioBtnJoy5Up->setChecked(false);
143  ui.radioBtnJoy5Down->setChecked(false);
144  break;
145  case 8: // up left
146  ui.radioBtnJoy4Left->setChecked(true);
147  ui.radioBtnJoy4Right->setChecked(false);
148  ui.radioBtnJoy5Up->setChecked(true);
149  ui.radioBtnJoy5Down->setChecked(false);
150  break;
151  }
152 }
153 
154 
155 void JoystickDialog::showJoystickAxes(int axisNumber, int axisValue)
156 {
158  switch (axisNumber)
159  {
160  case JOYSTICKAXISX3:
161  // X axis
162  ui.sliderJoystickX->setValue(axisValue);
163  break;
164 
165  case JOYSTICKAXISY2:
166  // Y axis
167  ui.sliderJoystickY->setValue(axisValue);
168  break;
169 
170  case JOYSTICKAXISY5:
171  // Y axis "buttons"
172  // up
173  if (axisValue < 0)
174  {
175  ui.radioBtnJoy5Up->setChecked(true);
176  }
177 
178  // down
179  if (axisValue > 0)
180  {
181  ui.radioBtnJoy5Down->setChecked(true);
182  }
183 
184  if (axisValue == 0)
185  {
186  ui.radioBtnJoy5Up->setChecked(false);
187  ui.radioBtnJoy5Down->setChecked(false);
188  }
189  break;
190 
191  case JOYSTICKAXISX4:
192  // X axis "buttons"
193  // left
194  if (axisValue < 0)
195  {
196  ui.radioBtnJoy4Left->setChecked(true);
197  }
198 
199  // right
200  if (axisValue > 0)
201  {
202  ui.radioBtnJoy4Right->setChecked(true);
203  }
204 
205  if (axisValue == 0)
206  {
207  ui.radioBtnJoy4Left->setChecked(false);
208  ui.radioBtnJoy4Right->setChecked(false);
209  }
210  break;
211  }
212 }