Debian Codegraph @

src/Gui/Dialogs/DlgCustomizeSpNavSettings.cpp

raw
1 /***************************************************************************
2 * Copyright (c) 2012 Petar Perisin <[email protected]> *
3 * *
4 * This file is part of the FreeCAD CAx development system. *
5 * *
6 * This library is free software; you can redistribute it and/or *
7 * modify it under the terms of the GNU Library General Public *
8 * License as published by the Free Software Foundation; either *
9 * version 2 of the License, or (at your option) any later version. *
10 * *
11 * This library 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 Library General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU Library General Public *
17 * License along with this library; see the file COPYING.LIB. If not, *
18 * write to the Free Software Foundation, Inc., 59 Temple Place, *
19 * Suite 330, Boston, MA 02111-1307, USA *
20 * *
21 ***************************************************************************/
22
23
24 #include "Dialogs/DlgCustomizeSpNavSettings.h"
25 #include "ui_DlgCustomizeSpNavSettings.h"
26 #include "Application.h"
27 #include "GuiApplicationNativeEventAware.h"
28
29
30 using namespace Gui::Dialog;
31
32 DlgCustomizeSpNavSettings::DlgCustomizeSpNavSettings(QWidget* parent)
33 : CustomizeActionPage(parent)
34 , ui(new Ui_DlgCustomizeSpNavSettings)
35 , init(false)
36 {
37 auto app = qobject_cast<GUIApplicationNativeEventAware*>(QApplication::instance());
38
39 if (!app) {
40 return;
41 }
42 if (!app->isSpaceballPresent()) {
43 this->setWindowTitle(tr("Spaceball Motion"));
44 this->setMessage(tr("No Spaceball present"));
45 return;
46 }
47 this->init = true;
48 ui->setupUi(this);
49 setupConnections();
50 initialize();
51 }
52
53 DlgCustomizeSpNavSettings::~DlgCustomizeSpNavSettings() = default;
54
55 void DlgCustomizeSpNavSettings::setupConnections()
56 {
57 // clang-format off
58 connect(ui->CBDominant, &QCheckBox::clicked,
59 this, &DlgCustomizeSpNavSettings::on_CBDominant_clicked);
60 connect(ui->CBFlipYZ, &QCheckBox::clicked,
61 this, &DlgCustomizeSpNavSettings::on_CBFlipYZ_clicked);
62 connect(ui->CBRotations, &QCheckBox::clicked,
63 this, &DlgCustomizeSpNavSettings::on_CBRotations_clicked);
64 connect(ui->CBTranslations, &QCheckBox::clicked,
65 this, &DlgCustomizeSpNavSettings::on_CBTranslations_clicked);
66 connect(ui->SliderGlobal, &QSlider::sliderReleased,
67 this, &DlgCustomizeSpNavSettings::on_SliderGlobal_sliderReleased);
68 connect(ui->CBEnablePanLR, &QCheckBox::clicked,
69 this, &DlgCustomizeSpNavSettings::on_CBEnablePanLR_clicked);
70 connect(ui->CBReversePanLR, &QCheckBox::clicked,
71 this, &DlgCustomizeSpNavSettings::on_CBReversePanLR_clicked);
72 connect(ui->SliderPanLR, &QSlider::sliderReleased,
73 this, &DlgCustomizeSpNavSettings::on_SliderPanLR_sliderReleased);
74 connect(ui->CBEnablePanUD, &QCheckBox::clicked,
75 this, &DlgCustomizeSpNavSettings::on_CBEnablePanUD_clicked);
76 connect(ui->CBReversePanUD, &QCheckBox::clicked,
77 this, &DlgCustomizeSpNavSettings::on_CBReversePanUD_clicked);
78 connect(ui->SliderPanUD, &QSlider::sliderReleased,
79 this, &DlgCustomizeSpNavSettings::on_SliderPanUD_sliderReleased);
80 connect(ui->CBEnableZoom, &QCheckBox::clicked,
81 this, &DlgCustomizeSpNavSettings::on_CBEnableZoom_clicked);
82 connect(ui->CBReverseZoom, &QCheckBox::clicked,
83 this, &DlgCustomizeSpNavSettings::on_CBReverseZoom_clicked);
84 connect(ui->SliderZoom, &QSlider::sliderReleased,
85 this, &DlgCustomizeSpNavSettings::on_SliderZoom_sliderReleased);
86 connect(ui->CBEnableTilt, &QCheckBox::clicked,
87 this, &DlgCustomizeSpNavSettings::on_CBEnableTilt_clicked);
88 connect(ui->CBReverseTilt, &QCheckBox::clicked,
89 this, &DlgCustomizeSpNavSettings::on_CBReverseTilt_clicked);
90 connect(ui->SliderTilt, &QSlider::sliderReleased,
91 this, &DlgCustomizeSpNavSettings::on_SliderTilt_sliderReleased);
92 connect(ui->CBEnableRoll, &QCheckBox::clicked,
93 this, &DlgCustomizeSpNavSettings::on_CBEnableRoll_clicked);
94 connect(ui->CBReverseRoll, &QCheckBox::clicked,
95 this, &DlgCustomizeSpNavSettings::on_CBReverseRoll_clicked);
96 connect(ui->SliderRoll, &QSlider::sliderReleased,
97 this, &DlgCustomizeSpNavSettings::on_SliderRoll_sliderReleased);
98 connect(ui->CBEnableSpin, &QCheckBox::clicked,
99 this, &DlgCustomizeSpNavSettings::on_CBEnableSpin_clicked);
100 connect(ui->CBReverseSpin, &QCheckBox::clicked,
101 this, &DlgCustomizeSpNavSettings::on_CBReverseSpin_clicked);
102 connect(ui->SliderSpin, &QSlider::sliderReleased,
103 this, &DlgCustomizeSpNavSettings::on_SliderSpin_sliderReleased);
104 connect(ui->ButtonDefaultSpNavMotions, &QPushButton::clicked,
105 this, &DlgCustomizeSpNavSettings::on_ButtonDefaultSpNavMotions_clicked);
106 connect(ui->ButtonCalibrate, &QPushButton::clicked,
107 this, &DlgCustomizeSpNavSettings::on_ButtonCalibrate_clicked);
108 // clang-format on
109 }
110
111 void DlgCustomizeSpNavSettings::setMessage(const QString& message)
112 {
113 auto messageLabel = new QLabel(message, this);
114 auto layout = new QVBoxLayout();
115 auto layout2 = new QHBoxLayout();
116 layout2->addStretch();
117 layout2->addWidget(messageLabel);
118 layout2->addStretch();
119 layout->addItem(layout2);
120 this->setLayout(layout);
121 }
122
123 void DlgCustomizeSpNavSettings::changeEvent(QEvent* e)
124 {
125 if (e->type() == QEvent::LanguageChange) {
126 if (this->init) {
127 ui->retranslateUi(this);
128 }
129 else {
130 this->setWindowTitle(tr("Spaceball Motion"));
131 QLabel* messageLabel = this->findChild<QLabel*>();
132 if (messageLabel) {
133 messageLabel->setText(tr("No Spaceball present"));
134 }
135 }
136 }
137 QWidget::changeEvent(e);
138 }
139
140 ParameterGrp::handle DlgCustomizeSpNavSettings::spaceballMotionGroup() const
141 {
142 static ParameterGrp::handle group = App::GetApplication()
143 .GetUserParameter()
144 .GetGroup("BaseApp")
145 ->GetGroup("Spaceball")
146 ->GetGroup("Motion");
147 return group;
148 }
149
150 void DlgCustomizeSpNavSettings::on_ButtonCalibrate_clicked()
151 {
152 spaceballMotionGroup()->SetBool("Calibrate", true);
153 }
154
155 void DlgCustomizeSpNavSettings::initialize()
156 {
157 ui->CBDominant->setChecked(spaceballMotionGroup()->GetBool("Dominant", false));
158 ui->CBFlipYZ->setChecked(spaceballMotionGroup()->GetBool("FlipYZ", false));
159 ui->CBRotations->setChecked(spaceballMotionGroup()->GetBool("Rotations", true));
160 ui->CBTranslations->setChecked(spaceballMotionGroup()->GetBool("Translations", true));
161 ui->SliderGlobal->setValue(spaceballMotionGroup()->GetInt("GlobalSensitivity", 0));
162
163 ui->CBEnablePanLR->setChecked(spaceballMotionGroup()->GetBool("PanLREnable", true));
164 ui->CBReversePanLR->setChecked(spaceballMotionGroup()->GetBool("PanLRReverse", false));
165 ui->SliderPanLR->setValue(spaceballMotionGroup()->GetInt("PanLRSensitivity", 0));
166
167 ui->CBEnablePanUD->setChecked(spaceballMotionGroup()->GetBool("PanUDEnable", true));
168 ui->CBReversePanUD->setChecked(spaceballMotionGroup()->GetBool("PanUDReverse", false));
169 ui->SliderPanUD->setValue(spaceballMotionGroup()->GetInt("PanUDSensitivity", 0));
170
171 ui->CBEnableZoom->setChecked(spaceballMotionGroup()->GetBool("ZoomEnable", true));
172 ui->CBReverseZoom->setChecked(spaceballMotionGroup()->GetBool("ZoomReverse", false));
173 ui->SliderZoom->setValue(spaceballMotionGroup()->GetInt("ZoomSensitivity", 0));
174
175 ui->CBEnableTilt->setChecked(spaceballMotionGroup()->GetBool("TiltEnable", true));
176 ui->CBReverseTilt->setChecked(spaceballMotionGroup()->GetBool("TiltReverse", false));
177 ui->SliderTilt->setValue(spaceballMotionGroup()->GetInt("TiltSensitivity", 0));
178
179 ui->CBEnableRoll->setChecked(spaceballMotionGroup()->GetBool("RollEnable", true));
180 ui->CBReverseRoll->setChecked(spaceballMotionGroup()->GetBool("RollReverse", false));
181 ui->SliderRoll->setValue(spaceballMotionGroup()->GetInt("RollSensitivity", 0));
182
183 ui->CBEnableSpin->setChecked(spaceballMotionGroup()->GetBool("SpinEnable", true));
184 ui->CBReverseSpin->setChecked(spaceballMotionGroup()->GetBool("SpinReverse", false));
185 ui->SliderSpin->setValue(spaceballMotionGroup()->GetInt("SpinSensitivity", 0));
186
187 ui->CBEnableTilt->setEnabled(ui->CBRotations->isChecked());
188 ui->CBReverseTilt->setEnabled(ui->CBRotations->isChecked() && ui->CBEnableTilt->isChecked());
189 ui->SliderTilt->setEnabled(ui->CBRotations->isChecked() && ui->CBEnableTilt->isChecked());
190 ui->CBEnableRoll->setEnabled(ui->CBRotations->isChecked());
191 ui->CBReverseRoll->setEnabled(ui->CBRotations->isChecked() && ui->CBEnableRoll->isChecked());
192 ui->SliderRoll->setEnabled(ui->CBRotations->isChecked() && ui->CBEnableRoll->isChecked());
193 ui->CBEnableSpin->setEnabled(ui->CBRotations->isChecked());
194 ui->CBReverseSpin->setEnabled(ui->CBRotations->isChecked() && ui->CBEnableSpin->isChecked());
195 ui->SliderSpin->setEnabled(ui->CBRotations->isChecked() && ui->CBEnableSpin->isChecked());
196
197 ui->CBEnablePanLR->setEnabled(ui->CBTranslations->isChecked());
198 ui->CBReversePanLR->setEnabled(ui->CBTranslations->isChecked() && ui->CBEnablePanLR->isChecked());
199 ui->SliderPanLR->setEnabled(ui->CBTranslations->isChecked() && ui->CBEnablePanLR->isChecked());
200 ui->CBEnablePanUD->setEnabled(ui->CBTranslations->isChecked());
201 ui->CBReversePanUD->setEnabled(ui->CBTranslations->isChecked() && ui->CBEnablePanUD->isChecked());
202 ui->SliderPanUD->setEnabled(ui->CBTranslations->isChecked() && ui->CBEnablePanUD->isChecked());
203 ui->CBEnableZoom->setEnabled(ui->CBTranslations->isChecked());
204 ui->CBReverseZoom->setEnabled(ui->CBTranslations->isChecked() && ui->CBEnableZoom->isChecked());
205 ui->SliderZoom->setEnabled(ui->CBTranslations->isChecked() && ui->CBEnableZoom->isChecked());
206 }
207
208 void DlgCustomizeSpNavSettings::on_ButtonDefaultSpNavMotions_clicked()
209 {
210 spaceballMotionGroup()->Clear();
211 initialize();
212 }
213
214 void DlgCustomizeSpNavSettings::on_CBDominant_clicked()
215 {
216 spaceballMotionGroup()->SetBool("Dominant", ui->CBDominant->isChecked());
217 }
218
219 void DlgCustomizeSpNavSettings::on_CBFlipYZ_clicked()
220 {
221 spaceballMotionGroup()->SetBool("FlipYZ", ui->CBFlipYZ->isChecked());
222 }
223
224 void DlgCustomizeSpNavSettings::on_CBRotations_clicked()
225 {
226 spaceballMotionGroup()->SetBool("Rotations", ui->CBRotations->isChecked());
227
228 ui->CBEnableTilt->setEnabled(ui->CBRotations->isChecked());
229 ui->CBReverseTilt->setEnabled(ui->CBRotations->isChecked() && ui->CBEnableTilt->isChecked());
230 ui->SliderTilt->setEnabled(ui->CBRotations->isChecked() && ui->CBEnableTilt->isChecked());
231 ui->CBEnableRoll->setEnabled(ui->CBRotations->isChecked());
232 ui->CBReverseRoll->setEnabled(ui->CBRotations->isChecked() && ui->CBEnableRoll->isChecked());
233 ui->SliderRoll->setEnabled(ui->CBRotations->isChecked() && ui->CBEnableRoll->isChecked());
234 ui->CBEnableSpin->setEnabled(ui->CBRotations->isChecked());
235 ui->CBReverseSpin->setEnabled(ui->CBRotations->isChecked() && ui->CBEnableSpin->isChecked());
236 ui->SliderSpin->setEnabled(ui->CBRotations->isChecked() && ui->CBEnableSpin->isChecked());
237 }
238
239 void DlgCustomizeSpNavSettings::on_CBTranslations_clicked()
240 {
241 spaceballMotionGroup()->SetBool("Translations", ui->CBTranslations->isChecked());
242
243 ui->CBEnablePanLR->setEnabled(ui->CBTranslations->isChecked());
244 ui->CBReversePanLR->setEnabled(ui->CBTranslations->isChecked() && ui->CBEnablePanLR->isChecked());
245 ui->SliderPanLR->setEnabled(ui->CBTranslations->isChecked() && ui->CBEnablePanLR->isChecked());
246 ui->CBEnablePanUD->setEnabled(ui->CBTranslations->isChecked());
247 ui->CBReversePanUD->setEnabled(ui->CBTranslations->isChecked() && ui->CBEnablePanUD->isChecked());
248 ui->SliderPanUD->setEnabled(ui->CBTranslations->isChecked() && ui->CBEnablePanUD->isChecked());
249 ui->CBEnableZoom->setEnabled(ui->CBTranslations->isChecked());
250 ui->CBReverseZoom->setEnabled(ui->CBTranslations->isChecked() && ui->CBEnableZoom->isChecked());
251 ui->SliderZoom->setEnabled(ui->CBTranslations->isChecked() && ui->CBEnableZoom->isChecked());
252 }
253
254 void DlgCustomizeSpNavSettings::on_SliderGlobal_sliderReleased()
255 {
256 spaceballMotionGroup()->SetInt("GlobalSensitivity", ui->SliderGlobal->value());
257 }
258
259 void DlgCustomizeSpNavSettings::on_CBEnablePanLR_clicked()
260 {
261 spaceballMotionGroup()->SetBool("PanLREnable", ui->CBEnablePanLR->isChecked());
262
263 ui->CBReversePanLR->setEnabled(ui->CBEnablePanLR->isChecked());
264 ui->SliderPanLR->setEnabled(ui->CBEnablePanLR->isChecked());
265 }
266
267 void DlgCustomizeSpNavSettings::on_CBReversePanLR_clicked()
268 {
269 spaceballMotionGroup()->SetBool("PanLRReverse", ui->CBReversePanLR->isChecked());
270 }
271
272 void DlgCustomizeSpNavSettings::on_SliderPanLR_sliderReleased()
273 {
274 spaceballMotionGroup()->SetInt("PanLRSensitivity", ui->SliderPanLR->value());
275 }
276
277 void DlgCustomizeSpNavSettings::on_CBEnablePanUD_clicked()
278 {
279 spaceballMotionGroup()->SetBool("PanUDEnable", ui->CBEnablePanUD->isChecked());
280
281 ui->CBReversePanUD->setEnabled(ui->CBEnablePanUD->isChecked());
282 ui->SliderPanUD->setEnabled(ui->CBEnablePanUD->isChecked());
283 }
284
285 void DlgCustomizeSpNavSettings::on_CBReversePanUD_clicked()
286 {
287 spaceballMotionGroup()->SetBool("PanUDReverse", ui->CBReversePanUD->isChecked());
288 }
289
290 void DlgCustomizeSpNavSettings::on_SliderPanUD_sliderReleased()
291 {
292 spaceballMotionGroup()->SetInt("PanUDSensitivity", ui->SliderPanUD->value());
293 }
294
295 void DlgCustomizeSpNavSettings::on_CBEnableZoom_clicked()
296 {
297 spaceballMotionGroup()->SetBool("ZoomEnable", ui->CBEnableZoom->isChecked());
298
299 ui->CBReverseZoom->setEnabled(ui->CBEnableZoom->isChecked());
300 ui->SliderZoom->setEnabled(ui->CBEnableZoom->isChecked());
301 }
302
303 void DlgCustomizeSpNavSettings::on_CBReverseZoom_clicked()
304 {
305 spaceballMotionGroup()->SetBool("ZoomReverse", ui->CBReverseZoom->isChecked());
306 }
307
308 void DlgCustomizeSpNavSettings::on_SliderZoom_sliderReleased()
309 {
310 spaceballMotionGroup()->SetInt("ZoomSensitivity", ui->SliderZoom->value());
311 }
312
313 void DlgCustomizeSpNavSettings::on_CBEnableTilt_clicked()
314 {
315 spaceballMotionGroup()->SetBool("TiltEnable", ui->CBEnableTilt->isChecked());
316
317 ui->CBReverseTilt->setEnabled(ui->CBEnableTilt->isChecked());
318 ui->SliderTilt->setEnabled(ui->CBEnableTilt->isChecked());
319 }
320
321 void DlgCustomizeSpNavSettings::on_CBReverseTilt_clicked()
322 {
323 spaceballMotionGroup()->SetBool("TiltReverse", ui->CBReverseTilt->isChecked());
324 }
325
326 void DlgCustomizeSpNavSettings::on_SliderTilt_sliderReleased()
327 {
328 spaceballMotionGroup()->SetInt("TiltSensitivity", ui->SliderTilt->value());
329 }
330
331 void DlgCustomizeSpNavSettings::on_CBEnableRoll_clicked()
332 {
333 spaceballMotionGroup()->SetBool("RollEnable", ui->CBEnableRoll->isChecked());
334
335 ui->CBReverseRoll->setEnabled(ui->CBEnableRoll->isChecked());
336 ui->SliderRoll->setEnabled(ui->CBEnableRoll->isChecked());
337 }
338
339 void DlgCustomizeSpNavSettings::on_CBReverseRoll_clicked()
340 {
341 spaceballMotionGroup()->SetBool("RollReverse", ui->CBReverseRoll->isChecked());
342 }
343
344 void DlgCustomizeSpNavSettings::on_SliderRoll_sliderReleased()
345 {
346 spaceballMotionGroup()->SetInt("RollSensitivity", ui->SliderRoll->value());
347 }
348
349 void DlgCustomizeSpNavSettings::on_CBEnableSpin_clicked()
350 {
351 spaceballMotionGroup()->SetBool("SpinEnable", ui->CBEnableSpin->isChecked());
352
353 ui->CBReverseSpin->setEnabled(ui->CBEnableSpin->isChecked());
354 ui->SliderSpin->setEnabled(ui->CBEnableSpin->isChecked());
355 }
356
357 void DlgCustomizeSpNavSettings::on_CBReverseSpin_clicked()
358 {
359 spaceballMotionGroup()->SetBool("SpinReverse", ui->CBReverseSpin->isChecked());
360 }
361
362 void DlgCustomizeSpNavSettings::on_SliderSpin_sliderReleased()
363 {
364 spaceballMotionGroup()->SetInt("SpinSensitivity", ui->SliderSpin->value());
365 }
366
367 void DlgCustomizeSpNavSettings::onAddMacroAction(const QByteArray& macroName)
368 {
369 // don't need to do anything here.
370 Q_UNUSED(macroName);
371 }
372
373 void DlgCustomizeSpNavSettings::onRemoveMacroAction(const QByteArray& macroName)
374 {
375 // don't need to do anything here.
376 Q_UNUSED(macroName);
377 }
378
379 void DlgCustomizeSpNavSettings::onModifyMacroAction(const QByteArray& macroName)
380 {
381 // don't need to do anything here.
382 Q_UNUSED(macroName);
383 }
384
385 #include "moc_DlgCustomizeSpNavSettings.cpp"