src/gui_actions.cpp

changeset 455
c5d14d112034
parent 421
7d26db0be944
child 460
b230ae09c8e5
equal deleted inserted replaced
454:d6b4ed3bf169 455:c5d14d112034
1 /* 1 /*
2 * LDForge: LDraw parts authoring CAD 2 * LDForge: LDraw parts authoring CAD
3 * Copyright (C) 2013 Santeri Piippo 3 * Copyright (C) 2013 Santeri Piippo
4 * 4 *
5 * This program is free software: you can redistribute it and/or modify 5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by 6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or 7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version. 8 * (at your option) any later version.
9 * 9 *
10 * This program is distributed in the hope that it will be useful, 10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details. 13 * GNU General Public License for more details.
14 * 14 *
15 * You should have received a copy of the GNU General Public License 15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */ 17 */
18 18
19 #include <QFileDialog> 19 #include <QFileDialog>
39 39
40 extern_cfg (bool, gl_wireframe); 40 extern_cfg (bool, gl_wireframe);
41 extern_cfg (bool, gl_colorbfc); 41 extern_cfg (bool, gl_colorbfc);
42 42
43 // ============================================================================= 43 // =============================================================================
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 44 // -----------------------------------------------------------------------------
45 // =============================================================================
46 DEFINE_ACTION (New, CTRL_SHIFT (N)) { 45 DEFINE_ACTION (New, CTRL_SHIFT (N)) {
47 QDialog* dlg = new QDialog (g_win); 46 QDialog* dlg = new QDialog (g_win);
48 Ui::NewPartUI ui; 47 Ui::NewPartUI ui;
49 ui.setupUi (dlg); 48 ui.setupUi (dlg);
50 49
76 75
77 g_win->fullRefresh(); 76 g_win->fullRefresh();
78 } 77 }
79 78
80 // ============================================================================= 79 // =============================================================================
81 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 80 // -----------------------------------------------------------------------------
82 // =============================================================================
83 DEFINE_ACTION (NewFile, CTRL (N)) { 81 DEFINE_ACTION (NewFile, CTRL (N)) {
84 newFile(); 82 newFile();
85 } 83 }
86 84
87 // ============================================================================= 85 // =============================================================================
88 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 86 // -----------------------------------------------------------------------------
89 // =============================================================================
90 DEFINE_ACTION (Open, CTRL (O)) { 87 DEFINE_ACTION (Open, CTRL (O)) {
91 str name = QFileDialog::getOpenFileName (g_win, "Open File", "", "LDraw files (*.dat *.ldr)"); 88 str name = QFileDialog::getOpenFileName (g_win, "Open File", "", "LDraw files (*.dat *.ldr)");
92 89
93 if (name.length() == 0) 90 if (name.length() == 0)
94 return; 91 return;
95 92
96 openMainFile (name); 93 openMainFile (name);
97 } 94 }
98 95
99 // ============================================================================= 96 // =============================================================================
100 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 97 // -----------------------------------------------------------------------------
101 // =============================================================================
102 DEFINE_ACTION (Save, CTRL (S)) { 98 DEFINE_ACTION (Save, CTRL (S)) {
103 g_win->save (LDFile::current(), false); 99 g_win->save (LDFile::current(), false);
104 } 100 }
105 101
106 // ============================================================================= 102 // =============================================================================
107 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 103 // -----------------------------------------------------------------------------
108 // =============================================================================
109 DEFINE_ACTION (SaveAs, CTRL_SHIFT (S)) { 104 DEFINE_ACTION (SaveAs, CTRL_SHIFT (S)) {
110 g_win->save (LDFile::current(), true); 105 g_win->save (LDFile::current(), true);
111 } 106 }
112 107
113 // ============================================================================= 108 // =============================================================================
114 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 109 // -----------------------------------------------------------------------------
115 // =============================================================================
116 DEFINE_ACTION (SaveAll, CTRL (L)) { 110 DEFINE_ACTION (SaveAll, CTRL (L)) {
117 for (LDFile* file : g_loadedFiles) { 111 for (LDFile* file : g_loadedFiles) {
118 if (file->implicit()) 112 if (file->implicit())
119 continue; 113 continue;
120 114
121 g_win->save (file, false); 115 g_win->save (file, false);
122 } 116 }
123 } 117 }
124 118
125 // ============================================================================= 119 // =============================================================================
126 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 120 // -----------------------------------------------------------------------------
127 // =============================================================================
128 DEFINE_ACTION (Close, CTRL (W)) { 121 DEFINE_ACTION (Close, CTRL (W)) {
129 if (!LDFile::current()->safeToClose()) 122 if (!LDFile::current()->safeToClose())
130 return; 123 return;
131 124
132 delete LDFile::current(); 125 delete LDFile::current();
133 } 126 }
134 127
135 // ============================================================================= 128 // =============================================================================
136 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 129 // -----------------------------------------------------------------------------
137 // =============================================================================
138 DEFINE_ACTION (CloseAll, 0) { 130 DEFINE_ACTION (CloseAll, 0) {
139 if (!safeToCloseAll()) 131 if (!safeToCloseAll())
140 return; 132 return;
141 133
142 closeAll(); 134 closeAll();
143 } 135 }
144 136
145 // ============================================================================= 137 // =============================================================================
146 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 138 // -----------------------------------------------------------------------------
147 // =============================================================================
148 DEFINE_ACTION (Settings, 0) { 139 DEFINE_ACTION (Settings, 0) {
149 ConfigDialog::staticDialog(); 140 ConfigDialog::staticDialog();
150 } 141 }
151 142
143 // =============================================================================
144 // -----------------------------------------------------------------------------
152 DEFINE_ACTION (SetLDrawPath, 0) { 145 DEFINE_ACTION (SetLDrawPath, 0) {
153 LDrawPathDialog dlg (true); 146 LDrawPathDialog dlg (true);
154 dlg.exec(); 147 dlg.exec();
155 } 148 }
156 149
157 // ============================================================================= 150 // =============================================================================
158 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 151 // -----------------------------------------------------------------------------
159 // =============================================================================
160 DEFINE_ACTION (Exit, CTRL (Q)) { 152 DEFINE_ACTION (Exit, CTRL (Q)) {
161 exit (0); 153 exit (0);
162 } 154 }
163 155
164 // ============================================================================= 156 // =============================================================================
165 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 157 // -----------------------------------------------------------------------------
166 // =============================================================================
167 DEFINE_ACTION (NewSubfile, 0) { 158 DEFINE_ACTION (NewSubfile, 0) {
168 AddObjectDialog::staticDialog (LDObject::Subfile, null); 159 AddObjectDialog::staticDialog (LDObject::Subfile, null);
169 } 160 }
170 161
162 // =============================================================================
163 // -----------------------------------------------------------------------------
171 DEFINE_ACTION (NewLine, 0) { 164 DEFINE_ACTION (NewLine, 0) {
172 AddObjectDialog::staticDialog (LDObject::Line, null); 165 AddObjectDialog::staticDialog (LDObject::Line, null);
173 } 166 }
174 167
168 // =============================================================================
169 // -----------------------------------------------------------------------------
175 DEFINE_ACTION (NewTriangle, 0) { 170 DEFINE_ACTION (NewTriangle, 0) {
176 AddObjectDialog::staticDialog (LDObject::Triangle, null); 171 AddObjectDialog::staticDialog (LDObject::Triangle, null);
177 } 172 }
178 173
174 // =============================================================================
175 // -----------------------------------------------------------------------------
179 DEFINE_ACTION (NewQuad, 0) { 176 DEFINE_ACTION (NewQuad, 0) {
180 AddObjectDialog::staticDialog (LDObject::Quad, null); 177 AddObjectDialog::staticDialog (LDObject::Quad, null);
181 } 178 }
182 179
180 // =============================================================================
181 // -----------------------------------------------------------------------------
183 DEFINE_ACTION (NewCLine, 0) { 182 DEFINE_ACTION (NewCLine, 0) {
184 AddObjectDialog::staticDialog (LDObject::CondLine, null); 183 AddObjectDialog::staticDialog (LDObject::CondLine, null);
185 } 184 }
186 185
186 // =============================================================================
187 // -----------------------------------------------------------------------------
187 DEFINE_ACTION (NewComment, 0) { 188 DEFINE_ACTION (NewComment, 0) {
188 AddObjectDialog::staticDialog (LDObject::Comment, null); 189 AddObjectDialog::staticDialog (LDObject::Comment, null);
189 } 190 }
190 191
192 // =============================================================================
193 // -----------------------------------------------------------------------------
191 DEFINE_ACTION (NewBFC, 0) { 194 DEFINE_ACTION (NewBFC, 0) {
192 AddObjectDialog::staticDialog (LDObject::BFC, null); 195 AddObjectDialog::staticDialog (LDObject::BFC, null);
193 } 196 }
194 197
198 // =============================================================================
199 // -----------------------------------------------------------------------------
195 DEFINE_ACTION (NewVertex, 0) { 200 DEFINE_ACTION (NewVertex, 0) {
196 AddObjectDialog::staticDialog (LDObject::Vertex, null); 201 AddObjectDialog::staticDialog (LDObject::Vertex, null);
197 } 202 }
198 203
204 // =============================================================================
205 // -----------------------------------------------------------------------------
199 DEFINE_ACTION (MakePrimitive, 0) { 206 DEFINE_ACTION (MakePrimitive, 0) {
200 generatePrimitive(); 207 generatePrimitive();
201 } 208 }
202 209
210 // =============================================================================
211 // -----------------------------------------------------------------------------
203 DEFINE_ACTION (Edit, 0) { 212 DEFINE_ACTION (Edit, 0) {
204 if (g_win->sel().size() != 1) 213 if (g_win->sel().size() != 1)
205 return; 214 return;
206 215
207 LDObject* obj = g_win->sel()[0]; 216 LDObject* obj = g_win->sel()[0];
208 AddObjectDialog::staticDialog (obj->getType(), obj); 217 AddObjectDialog::staticDialog (obj->getType(), obj);
209 } 218 }
210 219
220 // =============================================================================
221 // -----------------------------------------------------------------------------
211 DEFINE_ACTION (Help, KEY (F1)) { 222 DEFINE_ACTION (Help, KEY (F1)) {
212 223
213 } 224 }
214 225
215 // ============================================================================= 226 // =============================================================================
216 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 227 // -----------------------------------------------------------------------------
217 // =============================================================================
218 DEFINE_ACTION (About, 0) { 228 DEFINE_ACTION (About, 0) {
219 AboutDialog().exec(); 229 AboutDialog().exec();
220 } 230 }
221 231
232 // =============================================================================
233 // -----------------------------------------------------------------------------
222 DEFINE_ACTION (AboutQt, 0) { 234 DEFINE_ACTION (AboutQt, 0) {
223 QMessageBox::aboutQt (g_win); 235 QMessageBox::aboutQt (g_win);
224 } 236 }
225 237
226 // ============================================================================= 238 // =============================================================================
227 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 239 // -----------------------------------------------------------------------------
228 // =============================================================================
229 DEFINE_ACTION (SelectAll, CTRL (A)) { 240 DEFINE_ACTION (SelectAll, CTRL (A)) {
230 g_win->sel().clear(); 241 g_win->sel().clear();
231 242
232 for (LDObject* obj : LDFile::current()->objs()) 243 for (LDObject* obj : LDFile::current()->objs())
233 g_win->sel() << obj; 244 g_win->sel() << obj;
234 245
235 g_win->updateSelection(); 246 g_win->updateSelection();
236 } 247 }
237 248
238 // ============================================================================= 249 // =============================================================================
250 // -----------------------------------------------------------------------------
239 DEFINE_ACTION (SelectByColor, CTRL_SHIFT (A)) { 251 DEFINE_ACTION (SelectByColor, CTRL_SHIFT (A)) {
240 short colnum = g_win->getSelectedColor(); 252 short colnum = g_win->getSelectedColor();
241 253
242 if (colnum == -1) 254 if (colnum == -1)
243 return; // no consensus on color 255 return; // no consensus on color
249 261
250 g_win->updateSelection(); 262 g_win->updateSelection();
251 } 263 }
252 264
253 // ============================================================================= 265 // =============================================================================
266 // -----------------------------------------------------------------------------
254 DEFINE_ACTION (SelectByType, 0) { 267 DEFINE_ACTION (SelectByType, 0) {
255 if (g_win->sel().size() == 0) 268 if (g_win->sel().size() == 0)
256 return; 269 return;
257 270
258 LDObject::Type type = g_win->uniformSelectedType(); 271 LDObject::Type type = g_win->uniformSelectedType();
285 298
286 g_win->updateSelection(); 299 g_win->updateSelection();
287 } 300 }
288 301
289 // ============================================================================= 302 // =============================================================================
290 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 303 // -----------------------------------------------------------------------------
291 // =============================================================================
292 DEFINE_ACTION (GridCoarse, 0) { 304 DEFINE_ACTION (GridCoarse, 0) {
293 grid = Grid::Coarse; 305 grid = Grid::Coarse;
294 g_win->updateGridToolBar(); 306 g_win->updateGridToolBar();
295 } 307 }
296 308
303 grid = Grid::Fine; 315 grid = Grid::Fine;
304 g_win->updateGridToolBar(); 316 g_win->updateGridToolBar();
305 } 317 }
306 318
307 // ============================================================================= 319 // =============================================================================
308 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 320 // -----------------------------------------------------------------------------
309 // =============================================================================
310 DEFINE_ACTION (ResetView, CTRL (0)) { 321 DEFINE_ACTION (ResetView, CTRL (0)) {
311 g_win->R()->resetAngles(); 322 g_win->R()->resetAngles();
312 g_win->R()->update(); 323 g_win->R()->update();
313 } 324 }
314 325
315 // ============================================================================= 326 // =============================================================================
316 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 327 // -----------------------------------------------------------------------------
317 // =============================================================================
318 DEFINE_ACTION (InsertFrom, 0) { 328 DEFINE_ACTION (InsertFrom, 0) {
319 str fname = QFileDialog::getOpenFileName(); 329 str fname = QFileDialog::getOpenFileName();
320 ulong idx = g_win->getInsertionPoint(); 330 ulong idx = g_win->getInsertionPoint();
321 331
322 if (!fname.length()) 332 if (!fname.length())
343 g_win->refresh(); 353 g_win->refresh();
344 g_win->scrollToSelection(); 354 g_win->scrollToSelection();
345 } 355 }
346 356
347 // ============================================================================= 357 // =============================================================================
348 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 358 // -----------------------------------------------------------------------------
349 // =============================================================================
350 DEFINE_ACTION (ExportTo, 0) { 359 DEFINE_ACTION (ExportTo, 0) {
351 if (g_win->sel().size() == 0) 360 if (g_win->sel().size() == 0)
352 return; 361 return;
353 362
354 str fname = QFileDialog::getSaveFileName(); 363 str fname = QFileDialog::getSaveFileName();
368 file.write ("\r\n", 2); 377 file.write ("\r\n", 2);
369 } 378 }
370 } 379 }
371 380
372 // ============================================================================= 381 // =============================================================================
373 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 382 // -----------------------------------------------------------------------------
374 // =============================================================================
375 DEFINE_ACTION (InsertRaw, 0) { 383 DEFINE_ACTION (InsertRaw, 0) {
376 ulong idx = g_win->getInsertionPoint(); 384 ulong idx = g_win->getInsertionPoint();
377 385
378 QDialog* const dlg = new QDialog; 386 QDialog* const dlg = new QDialog;
379 QVBoxLayout* const layout = new QVBoxLayout; 387 QVBoxLayout* const layout = new QVBoxLayout;
403 411
404 g_win->refresh(); 412 g_win->refresh();
405 g_win->scrollToSelection(); 413 g_win->scrollToSelection();
406 } 414 }
407 415
416 // =============================================================================
417 // -----------------------------------------------------------------------------
408 DEFINE_ACTION (Screenshot, 0) { 418 DEFINE_ACTION (Screenshot, 0) {
409 setlocale (LC_ALL, "C"); 419 setlocale (LC_ALL, "C");
410 420
411 ushort w, h; 421 ushort w, h;
412 uchar* imgdata = g_win->R()->screencap (w, h); 422 uchar* imgdata = g_win->R()->screencap (w, h);
425 435
426 delete[] imgdata; 436 delete[] imgdata;
427 } 437 }
428 438
429 // ============================================================================= 439 // =============================================================================
440 // -----------------------------------------------------------------------------
430 extern_cfg (bool, gl_axes); 441 extern_cfg (bool, gl_axes);
431 DEFINE_ACTION (Axes, 0) { 442 DEFINE_ACTION (Axes, 0) {
432 gl_axes = !gl_axes; 443 gl_axes = !gl_axes;
433 ACTION (Axes)->setChecked (gl_axes); 444 ACTION (Axes)->setChecked (gl_axes);
434 g_win->R()->update(); 445 g_win->R()->update();
435 } 446 }
436 447
437 // ============================================================================= 448 // =============================================================================
449 // -----------------------------------------------------------------------------
438 DEFINE_ACTION (Visibility, 0) { 450 DEFINE_ACTION (Visibility, 0) {
439 for (LDObject* obj : g_win->sel()) 451 for (LDObject* obj : g_win->sel())
440 obj->setHidden (!obj->hidden()); 452 obj->setHidden (!obj->hidden());
441 453
442 g_win->refresh(); 454 g_win->refresh();
443 } 455 }
444 456
457 // =============================================================================
458 // -----------------------------------------------------------------------------
445 DEFINE_ACTION (Wireframe, 0) { 459 DEFINE_ACTION (Wireframe, 0) {
446 gl_wireframe = !gl_wireframe; 460 gl_wireframe = !gl_wireframe;
447 g_win->R()->refresh(); 461 g_win->R()->refresh();
448 } 462 }
449 463
450 DEFINE_ACTION (SetOverlay, 0) 464 // =============================================================================
451 { 465 // -----------------------------------------------------------------------------
466 DEFINE_ACTION (SetOverlay, 0) {
452 OverlayDialog dlg; 467 OverlayDialog dlg;
453 468
454 if (!dlg.exec()) 469 if (!dlg.exec())
455 return; 470 return;
456 471
457 g_win->R()->setupOverlay ((GL::Camera) dlg.camera(), dlg.fpath(), dlg.ofsx(), 472 g_win->R()->setupOverlay ((GL::Camera) dlg.camera(), dlg.fpath(), dlg.ofsx(),
458 dlg.ofsy(), dlg.lwidth(), dlg.lheight() ); 473 dlg.ofsy(), dlg.lwidth(), dlg.lheight() );
459 } 474 }
460 475
476 // =============================================================================
477 // -----------------------------------------------------------------------------
461 DEFINE_ACTION (ClearOverlay, 0) { 478 DEFINE_ACTION (ClearOverlay, 0) {
462 g_win->R()->clearOverlay(); 479 g_win->R()->clearOverlay();
463 } 480 }
464 481
482 // =============================================================================
483 // -----------------------------------------------------------------------------
465 DEFINE_ACTION (ModeSelect, CTRL (1)) { 484 DEFINE_ACTION (ModeSelect, CTRL (1)) {
466 g_win->R()->setEditMode (Select); 485 g_win->R()->setEditMode (Select);
467 } 486 }
468 487
488 // =============================================================================
489 // -----------------------------------------------------------------------------
469 DEFINE_ACTION (ModeDraw, CTRL (2)) { 490 DEFINE_ACTION (ModeDraw, CTRL (2)) {
470 g_win->R()->setEditMode (Draw); 491 g_win->R()->setEditMode (Draw);
471 } 492 }
472 493
494 // =============================================================================
495 // -----------------------------------------------------------------------------
473 DEFINE_ACTION (SetDrawDepth, 0) { 496 DEFINE_ACTION (SetDrawDepth, 0) {
474 if (g_win->R()->camera() == GL::Free) 497 if (g_win->R()->camera() == GL::Free)
475 return; 498 return;
476 499
477 bool ok; 500 bool ok;
525 delete[] imgdata; 548 delete[] imgdata;
526 rend->deleteLater(); 549 rend->deleteLater();
527 } 550 }
528 #endif 551 #endif
529 552
553 // =============================================================================
554 // -----------------------------------------------------------------------------
530 DEFINE_ACTION (ScanPrimitives, 0) { 555 DEFINE_ACTION (ScanPrimitives, 0) {
531 PrimitiveLister::start(); 556 PrimitiveLister::start();
532 } 557 }
533 558
559 // =============================================================================
560 // -----------------------------------------------------------------------------
534 DEFINE_ACTION (BFCView, SHIFT (B)) { 561 DEFINE_ACTION (BFCView, SHIFT (B)) {
535 gl_colorbfc = !gl_colorbfc; 562 gl_colorbfc = !gl_colorbfc;
536 ACTION (BFCView)->setChecked (gl_colorbfc); 563 ACTION (BFCView)->setChecked (gl_colorbfc);
537 g_win->R()->refresh(); 564 g_win->R()->refresh();
538 } 565 }

mercurial