src/gui_editactions.cpp

changeset 522
afa691788bdb
parent 508
7ace3537a560
child 538
2f85d4d286e5
equal deleted inserted replaced
521:b85554206155 522:afa691788bdb
39 extern_cfg (String, ld_defaultuser); 39 extern_cfg (String, ld_defaultuser);
40 40
41 // ============================================================================= 41 // =============================================================================
42 // ----------------------------------------------------------------------------- 42 // -----------------------------------------------------------------------------
43 static int copyToClipboard() 43 static int copyToClipboard()
44 { QList<LDObject*> objs = g_win->sel(); 44 { QList<LDObject*> objs = selection();
45 int num = 0; 45 int num = 0;
46 46
47 // Clear the clipboard first. 47 // Clear the clipboard first.
48 qApp->clipboard()->clear(); 48 qApp->clipboard()->clear();
49 49
80 // ============================================================================= 80 // =============================================================================
81 // ----------------------------------------------------------------------------- 81 // -----------------------------------------------------------------------------
82 DEFINE_ACTION (Paste, CTRL (V)) 82 DEFINE_ACTION (Paste, CTRL (V))
83 { const str clipboardText = qApp->clipboard()->text(); 83 { const str clipboardText = qApp->clipboard()->text();
84 int idx = g_win->getInsertionPoint(); 84 int idx = g_win->getInsertionPoint();
85 g_win->sel().clear(); 85 LDFile::current()->clearSelection();
86 int num = 0; 86 int num = 0;
87 87
88 for (str line : clipboardText.split ("\n")) 88 for (str line : clipboardText.split ("\n"))
89 { LDObject* pasted = parseLine (line); 89 { LDObject* pasted = parseLine (line);
90 LDFile::current()->insertObj (idx++, pasted); 90 LDFile::current()->insertObj (idx++, pasted);
91 g_win->sel() << pasted; 91 pasted->select();
92 g_win->R()->compileObject (pasted); 92 g_win->R()->compileObject (pasted);
93 ++num; 93 ++num;
94 } 94 }
95 95
96 log (ForgeWindow::tr ("%1 objects pasted"), num); 96 log (ForgeWindow::tr ("%1 objects pasted"), num);
106 } 106 }
107 107
108 // ============================================================================= 108 // =============================================================================
109 // ----------------------------------------------------------------------------- 109 // -----------------------------------------------------------------------------
110 static void doInline (bool deep) 110 static void doInline (bool deep)
111 { QList<LDObject*> sel = g_win->sel(); 111 { QList<LDObject*> sel = selection();
112 112
113 for (LDObject* obj : sel) 113 for (LDObject* obj : sel)
114 { // Get the index of the subfile so we know where to insert the 114 { // Get the index of the subfile so we know where to insert the
115 // inlined contents. 115 // inlined contents.
116 long idx = obj->getIndex(); 116 long idx = obj->getIndex();
134 { str line = inlineobj->raw(); 134 { str line = inlineobj->raw();
135 delete inlineobj; 135 delete inlineobj;
136 136
137 LDObject* newobj = parseLine (line); 137 LDObject* newobj = parseLine (line);
138 LDFile::current()->insertObj (idx++, newobj); 138 LDFile::current()->insertObj (idx++, newobj);
139 g_win->sel() << newobj; 139 newobj->select();
140 g_win->R()->compileObject (newobj); 140 g_win->R()->compileObject (newobj);
141 } 141 }
142 142
143 // Delete the subfile now as it's been inlined. 143 // Delete the subfile now as it's been inlined.
144 LDFile::current()->forgetObject (obj); 144 LDFile::current()->forgetObject (obj);
157 } 157 }
158 158
159 // ============================================================================= 159 // =============================================================================
160 // ----------------------------------------------------------------------------- 160 // -----------------------------------------------------------------------------
161 DEFINE_ACTION (SplitQuads, 0) 161 DEFINE_ACTION (SplitQuads, 0)
162 { QList<LDObject*> objs = g_win->sel(); 162 { QList<LDObject*> objs = selection();
163 int num = 0; 163 int num = 0;
164 164
165 for (LDObject* obj : objs) 165 for (LDObject* obj : objs)
166 { if (obj->getType() != LDObject::Quad) 166 { if (obj->getType() != LDObject::Quad)
167 continue; 167 continue;
193 } 193 }
194 194
195 // ============================================================================= 195 // =============================================================================
196 // ----------------------------------------------------------------------------- 196 // -----------------------------------------------------------------------------
197 DEFINE_ACTION (EditRaw, KEY (F9)) 197 DEFINE_ACTION (EditRaw, KEY (F9))
198 { if (g_win->sel().size() != 1) 198 { if (selection().size() != 1)
199 return; 199 return;
200 200
201 LDObject* obj = g_win->sel() [0]; 201 LDObject* obj = selection()[0];
202 QDialog* dlg = new QDialog; 202 QDialog* dlg = new QDialog;
203 Ui::EditRawUI ui; 203 Ui::EditRawUI ui;
204 204
205 ui.setupUi (dlg); 205 ui.setupUi (dlg);
206 ui.code->setText (obj->raw()); 206 ui.code->setText (obj->raw());
227 } 227 }
228 228
229 // ============================================================================= 229 // =============================================================================
230 // ----------------------------------------------------------------------------- 230 // -----------------------------------------------------------------------------
231 DEFINE_ACTION (SetColor, KEY (C)) 231 DEFINE_ACTION (SetColor, KEY (C))
232 { if (g_win->sel().size() <= 0) 232 { if (selection().isEmpty())
233 return; 233 return;
234 234
235 short colnum; 235 short colnum;
236 short defcol = -1; 236 short defcol = -1;
237 237
238 QList<LDObject*> objs = g_win->sel(); 238 QList<LDObject*> objs = selection();
239 239
240 // If all selected objects have the same color, said color is our default 240 // If all selected objects have the same color, said color is our default
241 // value to the color selection dialog. 241 // value to the color selection dialog.
242 defcol = g_win->getSelectedColor(); 242 defcol = g_win->getSelectedColor();
243 243
256 } 256 }
257 257
258 // ============================================================================= 258 // =============================================================================
259 // ----------------------------------------------------------------------------- 259 // -----------------------------------------------------------------------------
260 DEFINE_ACTION (Borders, CTRL_SHIFT (B)) 260 DEFINE_ACTION (Borders, CTRL_SHIFT (B))
261 { QList<LDObject*> objs = g_win->sel(); 261 { QList<LDObject*> objs = selection();
262 int num = 0; 262 int num = 0;
263 263
264 for (LDObject* obj : objs) 264 for (LDObject* obj : objs)
265 { if (obj->getType() != LDObject::Quad && obj->getType() != LDObject::Triangle) 265 { const LDObject::Type type = obj->getType();
266 if (type != LDObject::Quad && type != LDObject::Triangle)
266 continue; 267 continue;
267 268
268 short numLines; 269 short numLines;
269 LDLine* lines[4]; 270 LDLine* lines[4];
270 271
271 if (obj->getType() == LDObject::Quad) 272 if (type == LDObject::Quad)
272 { numLines = 4; 273 { numLines = 4;
273 274
274 LDQuad* quad = static_cast<LDQuad*> (obj); 275 LDQuad* quad = static_cast<LDQuad*> (obj);
275 lines[0] = new LDLine (quad->getVertex (0), quad->getVertex (1)); 276 lines[0] = new LDLine (quad->getVertex (0), quad->getVertex (1));
276 lines[1] = new LDLine (quad->getVertex (1), quad->getVertex (2)); 277 lines[1] = new LDLine (quad->getVertex (1), quad->getVertex (2));
304 // ============================================================================= 305 // =============================================================================
305 // ----------------------------------------------------------------------------- 306 // -----------------------------------------------------------------------------
306 DEFINE_ACTION (CornerVerts, 0) 307 DEFINE_ACTION (CornerVerts, 0)
307 { int num = 0; 308 { int num = 0;
308 309
309 for (LDObject* obj : g_win->sel()) 310 for (LDObject* obj : selection())
310 { if (obj->vertices() < 2) 311 { if (obj->vertices() < 2)
311 continue; 312 continue;
312 313
313 int idx = obj->getIndex(); 314 int idx = obj->getIndex();
314 315
328 } 329 }
329 330
330 // ============================================================================= 331 // =============================================================================
331 // ----------------------------------------------------------------------------- 332 // -----------------------------------------------------------------------------
332 static void doMoveSelection (const bool up) 333 static void doMoveSelection (const bool up)
333 { QList<LDObject*> objs = g_win->sel(); 334 { QList<LDObject*> objs = selection();
334 LDObject::moveObjects (objs, up); 335 LDObject::moveObjects (objs, up);
335 g_win->buildObjList(); 336 g_win->buildObjList();
336 } 337 }
337 338
338 // ============================================================================= 339 // =============================================================================
361 { // Apply the grid values 362 { // Apply the grid values
362 vect[X] *= currentGrid().confs[Grid::X]->value; 363 vect[X] *= currentGrid().confs[Grid::X]->value;
363 vect[Y] *= currentGrid().confs[Grid::Y]->value; 364 vect[Y] *= currentGrid().confs[Grid::Y]->value;
364 vect[Z] *= currentGrid().confs[Grid::Z]->value; 365 vect[Z] *= currentGrid().confs[Grid::Z]->value;
365 366
366 for (LDObject* obj : g_win->sel()) 367 for (LDObject* obj : selection())
367 { obj->move (vect); 368 { obj->move (vect);
368 g_win->R()->compileObject (obj); 369 g_win->R()->compileObject (obj);
369 } 370 }
370 371
371 g_win->refresh(); 372 g_win->refresh();
398 } 399 }
399 400
400 // ============================================================================= 401 // =============================================================================
401 // ----------------------------------------------------------------------------- 402 // -----------------------------------------------------------------------------
402 DEFINE_ACTION (Invert, CTRL_SHIFT (W)) 403 DEFINE_ACTION (Invert, CTRL_SHIFT (W))
403 { QList<LDObject*> sel = g_win->sel(); 404 { QList<LDObject*> sel = selection();
404 405
405 for (LDObject* obj : sel) 406 for (LDObject* obj : sel)
406 { obj->invert(); 407 { obj->invert();
407 g_win->R()->compileObject (obj); 408 g_win->R()->compileObject (obj);
408 } 409 }
419 } 420 }
420 421
421 // ============================================================================= 422 // =============================================================================
422 // ----------------------------------------------------------------------------- 423 // -----------------------------------------------------------------------------
423 static void doRotate (const short l, const short m, const short n) 424 static void doRotate (const short l, const short m, const short n)
424 { QList<LDObject*> sel = g_win->sel(); 425 { QList<LDObject*> sel = selection();
425 QList<vertex*> queue; 426 QList<vertex*> queue;
426 const vertex rotpoint = rotPoint (sel); 427 const vertex rotpoint = rotPoint (sel);
427 const double angle = (pi * currentGrid().confs[Grid::Angle]->value) / 180, 428 const double angle = (pi * currentGrid().confs[Grid::Angle]->value) / 180,
428 cosangle = cos (angle), 429 cosangle = cos (angle),
429 sinangle = sin (angle); 430 sinangle = sin (angle);
504 // ----------------------------------------------------------------------------- 505 // -----------------------------------------------------------------------------
505 DEFINE_ACTION (RoundCoordinates, 0) 506 DEFINE_ACTION (RoundCoordinates, 0)
506 { setlocale (LC_ALL, "C"); 507 { setlocale (LC_ALL, "C");
507 int num = 0; 508 int num = 0;
508 509
509 for (LDObject* obj : g_win->sel()) 510 for (LDObject* obj : selection())
510 { for (short i = 0; i < obj->vertices(); ++i) 511 { for (short i = 0; i < obj->vertices(); ++i)
511 { vertex v = obj->getVertex (i); 512 { vertex v = obj->getVertex (i);
512 513
513 for (const Axis ax : g_Axes) 514 for (const Axis ax : g_Axes)
514 { // HACK: .. should find a better way to do this 515 { // HACK: .. should find a better way to do this
530 // ============================================================================= 531 // =============================================================================
531 // ----------------------------------------------------------------------------- 532 // -----------------------------------------------------------------------------
532 DEFINE_ACTION (Uncolorize, 0) 533 DEFINE_ACTION (Uncolorize, 0)
533 { int num = 0; 534 { int num = 0;
534 535
535 for (LDObject* obj : g_win->sel()) 536 for (LDObject* obj : selection())
536 { if (obj->isColored() == false) 537 { if (obj->isColored() == false)
537 continue; 538 continue;
538 539
539 int col = maincolor; 540 int col = maincolor;
540 541
559 560
560 if (!dlg->exec()) 561 if (!dlg->exec())
561 return; 562 return;
562 563
563 const double search = ui.search->value(), 564 const double search = ui.search->value(),
564 replacement = ui.replacement->value(); 565 replacement = ui.replacement->value();
565 const bool any = ui.any->isChecked(), 566 const bool any = ui.any->isChecked(),
566 rel = ui.relative->isChecked(); 567 rel = ui.relative->isChecked();
567 568
568 QList<Axis> sel; 569 QList<Axis> sel;
569 int num = 0; 570 int num = 0;
570 571
571 if (ui.x->isChecked()) sel << X; 572 if (ui.x->isChecked()) sel << X;
572
573 if (ui.y->isChecked()) sel << Y; 573 if (ui.y->isChecked()) sel << Y;
574
575 if (ui.z->isChecked()) sel << Z; 574 if (ui.z->isChecked()) sel << Z;
576 575
577 for (LDObject* obj : g_win->sel()) 576 for (LDObject* obj : selection())
578 for (short i = 0; i < obj->vertices(); ++i) 577 { for (short i = 0; i < obj->vertices(); ++i)
579 { vertex v = obj->getVertex (i); 578 { vertex v = obj->getVertex (i);
580 579
581 for (Axis ax : sel) 580 for (Axis ax : sel)
582 { double& coord = v[ax]; 581 { double& coord = v[ax];
583 582
591 } 590 }
592 591
593 obj->setVertex (i, v); 592 obj->setVertex (i, v);
594 g_win->R()->compileObject (obj); 593 g_win->R()->compileObject (obj);
595 } 594 }
595 }
596 596
597 log (ForgeWindow::tr ("Altered %1 values"), num); 597 log (ForgeWindow::tr ("Altered %1 values"), num);
598 g_win->refresh(); 598 g_win->refresh();
599 } 599 }
600 600
612 612
613 if (ui.x->isChecked()) sel << X; 613 if (ui.x->isChecked()) sel << X;
614 if (ui.y->isChecked()) sel << Y; 614 if (ui.y->isChecked()) sel << Y;
615 if (ui.z->isChecked()) sel << Z; 615 if (ui.z->isChecked()) sel << Z;
616 616
617 for (LDObject* obj : g_win->sel()) 617 for (LDObject* obj : selection())
618 for (short i = 0; i < obj->vertices(); ++i) 618 { for (short i = 0; i < obj->vertices(); ++i)
619 { vertex v = obj->getVertex (i); 619 { vertex v = obj->getVertex (i);
620 620
621 for (Axis ax : sel) 621 for (Axis ax : sel)
622 v[ax] *= -1; 622 v[ax] *= -1;
623 623
624 obj->setVertex (i, v); 624 obj->setVertex (i, v);
625 g_win->R()->compileObject (obj); 625 g_win->R()->compileObject (obj);
626 } 626 }
627 }
627 628
628 g_win->refresh(); 629 g_win->refresh();
629 } 630 }
630 631
631 // ============================================================================= 632 // =============================================================================
632 // ----------------------------------------------------------------------------- 633 // -----------------------------------------------------------------------------
633 DEFINE_ACTION (Demote, 0) 634 DEFINE_ACTION (Demote, 0)
634 { QList<LDObject*> sel = g_win->sel(); 635 { QList<LDObject*> sel = selection();
635 int num = 0; 636 int num = 0;
636 637
637 for (LDObject* obj : sel) 638 for (LDObject* obj : sel)
638 { if (obj->getType() != LDObject::CndLine) 639 { if (obj->getType() != LDObject::CndLine)
639 continue; 640 continue;
668 if (colnum >= MAX_COLORS) 669 if (colnum >= MAX_COLORS)
669 { log (ForgeWindow::tr ("Cannot auto-color: all colors are in use!")); 670 { log (ForgeWindow::tr ("Cannot auto-color: all colors are in use!"));
670 return; 671 return;
671 } 672 }
672 673
673 for (LDObject* obj : g_win->sel()) 674 for (LDObject* obj : selection())
674 { if (obj->isColored() == false) 675 { if (obj->isColored() == false)
675 continue; 676 continue;
676 677
677 obj->setColor (colnum); 678 obj->setColor (colnum);
678 g_win->R()->compileObject (obj); 679 g_win->R()->compileObject (obj);

mercurial