src/gui_actions.cpp

changeset 382
c1642530ea35
parent 379
f5f3faac60cd
child 388
7ff483614aa1
equal deleted inserted replaced
381:241f65769a57 382:c1642530ea35
41 extern_cfg (bool, gl_colorbfc); 41 extern_cfg (bool, gl_colorbfc);
42 42
43 // ============================================================================= 43 // =============================================================================
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
45 // ============================================================================= 45 // =============================================================================
46 MAKE_ACTION (newFile, "&New", "brick", "Create a new part model.", CTRL (N)) { 46 DEFINE_ACTION (New, CTRL (N)) {
47 if (safeToCloseAll() == false) 47 if (safeToCloseAll() == false)
48 return; 48 return;
49 49
50 QDialog* dlg = new QDialog (g_win); 50 QDialog* dlg = new QDialog (g_win);
51 Ui::NewPartUI ui; 51 Ui::NewPartUI ui;
82 } 82 }
83 83
84 // ============================================================================= 84 // =============================================================================
85 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 85 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
86 // ============================================================================= 86 // =============================================================================
87 MAKE_ACTION (open, "&Open", "file-open", "Load a part model from a file.", CTRL (O)) { 87 DEFINE_ACTION (Open, CTRL (O)) {
88 if (safeToCloseAll() == false) 88 if (safeToCloseAll() == false)
89 return; 89 return;
90 90
91 str name = QFileDialog::getOpenFileName (g_win, "Open File", "", "LDraw files (*.dat *.ldr)"); 91 str name = QFileDialog::getOpenFileName (g_win, "Open File", "", "LDraw files (*.dat *.ldr)");
92 92
98 } 98 }
99 99
100 // ============================================================================= 100 // =============================================================================
101 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 101 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
102 // ============================================================================= 102 // =============================================================================
103 MAKE_ACTION (save, "&Save", "file-save", "Save the part model.", CTRL (S)) 103 DEFINE_ACTION (Save, CTRL (S)) {
104 {
105 g_win->save (currentFile(), false); 104 g_win->save (currentFile(), false);
106 } 105 }
107 106
108 // ============================================================================= 107 // =============================================================================
109 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 108 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
110 // ============================================================================= 109 // =============================================================================
111 MAKE_ACTION (saveAs, "Save &As", "file-save-as", "Save the part model to a specific file.", CTRL_SHIFT (S)) 110 DEFINE_ACTION (SaveAs, CTRL_SHIFT (S)) {
112 {
113 g_win->save (currentFile(), true); 111 g_win->save (currentFile(), true);
114 } 112 }
115 113
116 // ============================================================================= 114 // =============================================================================
117 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 115 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
118 // ============================================================================= 116 // =============================================================================
119 MAKE_ACTION (settings, "Settin&gs", "settings", "Edit the settings of " APPNAME ".", (0)) { 117 DEFINE_ACTION (Settings, 0) {
120 ConfigDialog::staticDialog(); 118 ConfigDialog::staticDialog();
121 } 119 }
122 120
123 MAKE_ACTION (setLDrawPath, "Set LDraw Path", "settings", "Change the LDraw directory path.", (0)) { 121 DEFINE_ACTION (SetLDrawPath, 0) {
124 LDrawPathDialog dlg (true); 122 LDrawPathDialog dlg (true);
125 dlg.exec(); 123 dlg.exec();
126 } 124 }
127 125
128 // ============================================================================= 126 // =============================================================================
129 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 127 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
130 // ============================================================================= 128 // =============================================================================
131 MAKE_ACTION (exit, "&Exit", "exit", "Close " APPNAME ".", CTRL (Q)) { 129 DEFINE_ACTION (Exit, CTRL (Q)) {
132 exit (0); 130 exit (0);
133 } 131 }
134 132
135 // ============================================================================= 133 // =============================================================================
136 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 134 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
137 // ============================================================================= 135 // =============================================================================
138 MAKE_ACTION (newSubfile, "New Subfile", "add-subfile", "Creates a new subfile reference.", 0) { 136 DEFINE_ACTION (NewSubfile, 0) {
139 AddObjectDialog::staticDialog (LDObject::Subfile, null); 137 AddObjectDialog::staticDialog (LDObject::Subfile, null);
140 } 138 }
141 139
142 MAKE_ACTION (newLine, "New Line", "add-line", "Creates a new line.", 0) { 140 DEFINE_ACTION (NewLine, 0) {
143 AddObjectDialog::staticDialog (LDObject::Line, null); 141 AddObjectDialog::staticDialog (LDObject::Line, null);
144 } 142 }
145 143
146 MAKE_ACTION (newTriangle, "New Triangle", "add-triangle", "Creates a new triangle.", 0) { 144 DEFINE_ACTION (NewTriangle, 0) {
147 AddObjectDialog::staticDialog (LDObject::Triangle, null); 145 AddObjectDialog::staticDialog (LDObject::Triangle, null);
148 } 146 }
149 147
150 MAKE_ACTION (newQuad, "New Quadrilateral", "add-quad", "Creates a new quadrilateral.", 0) { 148 DEFINE_ACTION (NewQuad, 0) {
151 AddObjectDialog::staticDialog (LDObject::Quad, null); 149 AddObjectDialog::staticDialog (LDObject::Quad, null);
152 } 150 }
153 151
154 MAKE_ACTION (newCondLine, "New Conditional Line", "add-condline", "Creates a new conditional line.", 0) { 152 DEFINE_ACTION (NewCLine, 0) {
155 AddObjectDialog::staticDialog (LDObject::CondLine, null); 153 AddObjectDialog::staticDialog (LDObject::CondLine, null);
156 } 154 }
157 155
158 MAKE_ACTION (newComment, "New Comment", "add-comment", "Creates a new comment.", 0) { 156 DEFINE_ACTION (NewComment, 0) {
159 AddObjectDialog::staticDialog (LDObject::Comment, null); 157 AddObjectDialog::staticDialog (LDObject::Comment, null);
160 } 158 }
161 159
162 MAKE_ACTION (newBFC, "New BFC Statement", "add-bfc", "Creates a new BFC statement.", 0) { 160 DEFINE_ACTION (NewBFC, 0) {
163 AddObjectDialog::staticDialog (LDObject::BFC, null); 161 AddObjectDialog::staticDialog (LDObject::BFC, null);
164 } 162 }
165 163
166 MAKE_ACTION (newVertex, "New Vertex", "add-vertex", "Creates a new vertex.", 0) { 164 DEFINE_ACTION (NewVertex, 0) {
167 AddObjectDialog::staticDialog (LDObject::Vertex, null); 165 AddObjectDialog::staticDialog (LDObject::Vertex, null);
168 } 166 }
169 167
170 MAKE_ACTION (makePrimitive, "Make a Primitive", "radial", "Generate a new circular primitive.", 0) 168 DEFINE_ACTION (MakePrimitive, 0) {
171 {
172 generatePrimitive(); 169 generatePrimitive();
173 } 170 }
174 171
175 MAKE_ACTION (editObject, "Edit Object", "edit-object", "Edits this object.", 0) { 172 DEFINE_ACTION (Edit, 0) {
176 if (g_win->sel().size() != 1) 173 if (g_win->sel().size() != 1)
177 return; 174 return;
178 175
179 LDObject* obj = g_win->sel()[0]; 176 LDObject* obj = g_win->sel()[0];
180 AddObjectDialog::staticDialog (obj->getType(), obj); 177 AddObjectDialog::staticDialog (obj->getType(), obj);
181 } 178 }
182 179
183 MAKE_ACTION (help, "Help", "help", "Shows the " APPNAME " help manual.", KEY (F1)) { 180 DEFINE_ACTION (Help, KEY (F1)) {
184 181
185 } 182 }
186 183
187 // ============================================================================= 184 // =============================================================================
188 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 185 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
189 // ============================================================================= 186 // =============================================================================
190 MAKE_ACTION (about, "About " APPNAME, "ldforge", 187 DEFINE_ACTION (About, 0) {
191 "Shows information about " APPNAME ".", (0)) 188 AboutDialog().exec();
192 { 189 }
193 AboutDialog dlg; 190
194 dlg.exec(); 191 DEFINE_ACTION (AboutQt, 0) {
195 }
196
197 MAKE_ACTION (aboutQt, "About Qt", "qt", "Shows information about Qt.", (0)) {
198 QMessageBox::aboutQt (g_win); 192 QMessageBox::aboutQt (g_win);
199 } 193 }
200 194
201 // ============================================================================= 195 // =============================================================================
202 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 196 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
203 // ============================================================================= 197 // =============================================================================
204 MAKE_ACTION (selectAll, "Select All", "select-all", "Selects all objects.", CTRL (A)) { 198 DEFINE_ACTION (SelectAll, CTRL (A)) {
205 g_win->sel().clear(); 199 g_win->sel().clear();
206 200
207 for (LDObject* obj : currentFile()->objs()) 201 for (LDObject* obj : currentFile()->objs())
208 g_win->sel() << obj; 202 g_win->sel() << obj;
209 203
210 g_win->updateSelection(); 204 g_win->updateSelection();
211 } 205 }
212 206
213 // ============================================================================= 207 // =============================================================================
214 MAKE_ACTION (selectByColor, "Select by Color", "select-color", 208 DEFINE_ACTION (SelectByColor, CTRL_SHIFT (A)) {
215 "Select all objects by the given color.", CTRL_SHIFT (A))
216 {
217 short colnum = g_win->getSelectedColor(); 209 short colnum = g_win->getSelectedColor();
218 210
219 if (colnum == -1) 211 if (colnum == -1)
220 return; // no consensus on color 212 return; // no consensus on color
221 213
226 218
227 g_win->updateSelection(); 219 g_win->updateSelection();
228 } 220 }
229 221
230 // ============================================================================= 222 // =============================================================================
231 MAKE_ACTION (selectByType, "Select by Type", "select-type", 223 DEFINE_ACTION (SelectByType, 0) {
232 "Select all objects by the given type.", (0))
233 {
234 if (g_win->sel().size() == 0) 224 if (g_win->sel().size() == 0)
235 return; 225 return;
236 226
237 LDObject::Type type = g_win->uniformSelectedType(); 227 LDObject::Type type = g_win->uniformSelectedType();
238 228
266 } 256 }
267 257
268 // ============================================================================= 258 // =============================================================================
269 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 259 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
270 // ============================================================================= 260 // =============================================================================
271 MAKE_ACTION (gridCoarse, "Coarse Grid", "grid-coarse", "Set the grid to Coarse", (0)) { 261 DEFINE_ACTION (GridCoarse, 0) {
272 grid = Grid::Coarse; 262 grid = Grid::Coarse;
273 g_win->updateGridToolBar(); 263 g_win->updateGridToolBar();
274 } 264 }
275 265
276 MAKE_ACTION (gridMedium, "Medium Grid", "grid-medium", "Set the grid to Medium", (0)) { 266 DEFINE_ACTION (GridMedium, 0) {
277 grid = Grid::Medium; 267 grid = Grid::Medium;
278 g_win->updateGridToolBar(); 268 g_win->updateGridToolBar();
279 } 269 }
280 270
281 MAKE_ACTION (gridFine, "Fine Grid", "grid-fine", "Set the grid to Fine", (0)) { 271 DEFINE_ACTION (GridFine, 0) {
282 grid = Grid::Fine; 272 grid = Grid::Fine;
283 g_win->updateGridToolBar(); 273 g_win->updateGridToolBar();
284 } 274 }
285 275
286 // ============================================================================= 276 // =============================================================================
287 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 277 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
288 // ============================================================================= 278 // =============================================================================
289 MAKE_ACTION (resetView, "Reset View", "reset-view", "Reset view angles, pan and zoom", CTRL (0)) { 279 DEFINE_ACTION (ResetView, CTRL (0)) {
290 g_win->R()->resetAngles(); 280 g_win->R()->resetAngles();
291 g_win->R()->update(); 281 g_win->R()->update();
292 } 282 }
293 283
294 // ============================================================================= 284 // =============================================================================
295 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 285 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
296 // ============================================================================= 286 // =============================================================================
297 MAKE_ACTION (insertFrom, "Insert from File", "file-import", "Insert LDraw data from a file.", (0)) { 287 DEFINE_ACTION (InsertFrom, 0) {
298 str fname = QFileDialog::getOpenFileName(); 288 str fname = QFileDialog::getOpenFileName();
299 ulong idx = g_win->getInsertionPoint(); 289 ulong idx = g_win->getInsertionPoint();
300 290
301 if (!fname.length()) 291 if (!fname.length())
302 return; 292 return;
323 } 313 }
324 314
325 // ============================================================================= 315 // =============================================================================
326 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 316 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
327 // ============================================================================= 317 // =============================================================================
328 MAKE_ACTION (exportTo, "Export To File", "file-export", "Export current selection to file", (0)) { 318 DEFINE_ACTION (ExportTo, 0) {
329 if (g_win->sel().size() == 0) 319 if (g_win->sel().size() == 0)
330 return; 320 return;
331 321
332 str fname = QFileDialog::getSaveFileName(); 322 str fname = QFileDialog::getSaveFileName();
333 if (fname.length() == 0) 323 if (fname.length() == 0)
348 } 338 }
349 339
350 // ============================================================================= 340 // =============================================================================
351 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 341 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
352 // ============================================================================= 342 // =============================================================================
353 MAKE_ACTION (insertRaw, "Insert Raw", "insert-raw", "Type in LDraw code to insert.", (0)) { 343 DEFINE_ACTION (InsertRaw, 0) {
354 ulong idx = g_win->getInsertionPoint(); 344 ulong idx = g_win->getInsertionPoint();
355 345
356 QDialog* const dlg = new QDialog; 346 QDialog* const dlg = new QDialog;
357 QVBoxLayout* const layout = new QVBoxLayout; 347 QVBoxLayout* const layout = new QVBoxLayout;
358 QTextEdit* const te_edit = new QTextEdit; 348 QTextEdit* const te_edit = new QTextEdit;
380 370
381 g_win->fullRefresh(); 371 g_win->fullRefresh();
382 g_win->scrollToSelection(); 372 g_win->scrollToSelection();
383 } 373 }
384 374
385 // ========================================================================================================================================= 375 DEFINE_ACTION (Screenshot, 0) {
386 MAKE_ACTION (screencap, "Screencap Part", "screencap", "Save a picture of the model", (0)) {
387 setlocale (LC_ALL, "C"); 376 setlocale (LC_ALL, "C");
388 377
389 ushort w, h; 378 ushort w, h;
390 uchar* imgdata = g_win->R()->screencap (w, h); 379 uchar* imgdata = g_win->R()->screencap (w, h);
391 QImage img = imageFromScreencap (imgdata, w, h); 380 QImage img = imageFromScreencap (imgdata, w, h);
402 critical (fmt ("Couldn't open %1 for writing to save screencap: %2", fname, strerror (errno))); 391 critical (fmt ("Couldn't open %1 for writing to save screencap: %2", fname, strerror (errno)));
403 392
404 delete[] imgdata; 393 delete[] imgdata;
405 } 394 }
406 395
407 // ========================================================================================================================================= 396 // =============================================================================
408 extern_cfg (bool, gl_axes); 397 extern_cfg (bool, gl_axes);
409 MAKE_ACTION (axes, "Draw Axes", "axes", "Toggles drawing of axes", (0)) { 398 DEFINE_ACTION (Axes, 0) {
410 gl_axes = !gl_axes; 399 gl_axes = !gl_axes;
411 ACTION (axes)->setChecked (gl_axes); 400 ACTION (Axes)->setChecked (gl_axes);
412 g_win->R()->update(); 401 g_win->R()->update();
413 } 402 }
414 403
415 // ========================================================================================================================================= 404 // =============================================================================
416 MAKE_ACTION (visibility, "Toggle Visibility", "visibility", "Toggles visibility/hiding on objects.", (0)) { 405 DEFINE_ACTION (Visibility, 0) {
417 for (LDObject* obj : g_win->sel()) 406 for (LDObject* obj : g_win->sel())
418 obj->setHidden (!obj->hidden()); 407 obj->setHidden (!obj->hidden());
419 408
420 g_win->fullRefresh(); 409 g_win->fullRefresh();
421 } 410 }
422 411
423 MAKE_ACTION (wireframe, "Wireframe", "wireframe", "Toggle wireframe view", (0)) { 412 DEFINE_ACTION (Wireframe, 0) {
424 gl_wireframe = !gl_wireframe; 413 gl_wireframe = !gl_wireframe;
425 g_win->R()->refresh(); 414 g_win->R()->refresh();
426 } 415 }
427 416
428 MAKE_ACTION (setOverlay, "Set Overlay Image", "overlay", "Set an overlay image", 0) 417 DEFINE_ACTION (SetOverlay, 0)
429 { 418 {
430 OverlayDialog dlg; 419 OverlayDialog dlg;
431 420
432 if (!dlg.exec()) 421 if (!dlg.exec())
433 return; 422 return;
434 423
435 g_win->R()->setupOverlay ((GL::Camera) dlg.camera(), dlg.fpath(), dlg.ofsx(), 424 g_win->R()->setupOverlay ((GL::Camera) dlg.camera(), dlg.fpath(), dlg.ofsx(),
436 dlg.ofsy(), dlg.lwidth(), dlg.lheight() ); 425 dlg.ofsy(), dlg.lwidth(), dlg.lheight() );
437 } 426 }
438 427
439 MAKE_ACTION (clearOverlay, "Clear Overlay Image", "overlay-clear", "Clear the overlay image.", (0)) { 428 DEFINE_ACTION (ClearOverlay, 0) {
440 g_win->R()->clearOverlay(); 429 g_win->R()->clearOverlay();
441 } 430 }
442 431
443 MAKE_ACTION (modeSelect, "Select Mode", "mode-select", "Select objects from the camera view.", CTRL (1)) { 432 DEFINE_ACTION (ModeSelect, CTRL (1)) {
444 g_win->R()->setEditMode (Select); 433 g_win->R()->setEditMode (Select);
445 } 434 }
446 435
447 MAKE_ACTION (modeDraw, "Draw Mode", "mode-draw", "Draw objects into the camera view.", CTRL (2)) { 436 DEFINE_ACTION (ModeDraw, CTRL (2)) {
448 g_win->R()->setEditMode (Draw); 437 g_win->R()->setEditMode (Draw);
449 } 438 }
450 439
451 MAKE_ACTION (setDrawDepth, "Set Depth Value", "depth-value", "Set the depth coordinate of the current camera.", (0)) { 440 DEFINE_ACTION (SetDrawDepth, 0) {
452 if (g_win->R()->camera() == GL::Free) 441 if (g_win->R()->camera() == GL::Free)
453 return; 442 return;
454 443
455 bool ok; 444 bool ok;
456 double depth = QInputDialog::getDouble (g_win, "Set Draw Depth", 445 double depth = QInputDialog::getDouble (g_win, "Set Draw Depth",
459 448
460 if (ok) 449 if (ok)
461 g_win->R()->setDepthValue (depth); 450 g_win->R()->setDepthValue (depth);
462 } 451 }
463 452
464 #ifndef RELEASE 453 #if 0
465 // This is a test to draw a dummy axle. Meant to be used as a primitive gallery, 454 // This is a test to draw a dummy axle. Meant to be used as a primitive gallery,
466 // but I can't figure how to generate these pictures properly. Multi-threading 455 // but I can't figure how to generate these pictures properly. Multi-threading
467 // these is an immense pain. 456 // these is an immense pain.
468 MAKE_ACTION (testpic, "Test picture", "", "", (0)) { 457 DEFINE_ACTION (testpic, "Test picture", "", "", (0)) {
469 LDOpenFile* file = getFile ("axle.dat"); 458 LDOpenFile* file = getFile ("axle.dat");
470 setlocale (LC_ALL, "C"); 459 setlocale (LC_ALL, "C");
471 460
472 if (!file) { 461 if (!file) {
473 critical ("couldn't load axle.dat"); 462 critical ("couldn't load axle.dat");
503 delete[] imgdata; 492 delete[] imgdata;
504 rend->deleteLater(); 493 rend->deleteLater();
505 } 494 }
506 #endif 495 #endif
507 496
508 MAKE_ACTION (reloadPrimitives, "Scan Primitives", "", "", (0)) { 497 DEFINE_ACTION (ScanPrimitives, 0) {
509 PrimitiveLister::start(); 498 PrimitiveLister::start();
510 } 499 }
511 500
512 MAKE_ACTION (colorbfc, "BFC Red/Green View", "bfc-view", "", SHIFT (B)) 501 DEFINE_ACTION (BFCView, SHIFT (B)) {
513 {
514 gl_colorbfc = !gl_colorbfc; 502 gl_colorbfc = !gl_colorbfc;
515 ACTION (colorbfc)->setChecked (gl_colorbfc); 503 ACTION (BFCView)->setChecked (gl_colorbfc);
516 g_win->R()->refresh(); 504 g_win->R()->refresh();
517 } 505 }

mercurial