86 |
86 |
87 const str license = |
87 const str license = |
88 ui.rb_license_ca->isChecked() ? CALicense : |
88 ui.rb_license_ca->isChecked() ? CALicense : |
89 ui.rb_license_nonca->isChecked() ? NonCALicense : ""; |
89 ui.rb_license_nonca->isChecked() ? NonCALicense : ""; |
90 |
90 |
91 LDFile::current()->addObjects ( |
91 getCurrentDocument()->addObjects ( |
92 { new LDComment (ui.le_title->text()), |
92 { new LDComment (ui.le_title->text()), |
93 new LDComment ("Name: <untitled>.dat"), |
93 new LDComment ("Name: <untitled>.dat"), |
94 new LDComment (fmt ("Author: %1", ui.le_author->text())), |
94 new LDComment (fmt ("Author: %1", ui.le_author->text())), |
95 new LDComment (fmt ("!LDRAW_ORG Unofficial_Part")), |
95 new LDComment (fmt ("!LDRAW_ORG Unofficial_Part")), |
96 (license != "" ? |
96 (license != "" ? |
122 } |
122 } |
123 |
123 |
124 // ============================================================================= |
124 // ============================================================================= |
125 // ----------------------------------------------------------------------------- |
125 // ----------------------------------------------------------------------------- |
126 DEFINE_ACTION (Save, CTRL (S)) |
126 DEFINE_ACTION (Save, CTRL (S)) |
127 { g_win->save (LDFile::current(), false); |
127 { g_win->save (getCurrentDocument(), false); |
128 } |
128 } |
129 |
129 |
130 // ============================================================================= |
130 // ============================================================================= |
131 // ----------------------------------------------------------------------------- |
131 // ----------------------------------------------------------------------------- |
132 DEFINE_ACTION (SaveAs, CTRL_SHIFT (S)) |
132 DEFINE_ACTION (SaveAs, CTRL_SHIFT (S)) |
133 { g_win->save (LDFile::current(), true); |
133 { g_win->save (getCurrentDocument(), true); |
134 } |
134 } |
135 |
135 |
136 // ============================================================================= |
136 // ============================================================================= |
137 // ----------------------------------------------------------------------------- |
137 // ----------------------------------------------------------------------------- |
138 DEFINE_ACTION (SaveAll, CTRL (L)) |
138 DEFINE_ACTION (SaveAll, CTRL (L)) |
139 { for (LDFile* file : g_loadedFiles) |
139 { for (LDDocument* file : g_loadedFiles) |
140 { if (file->isImplicit()) |
140 { if (file->isImplicit()) |
141 continue; |
141 continue; |
142 |
142 |
143 g_win->save (file, false); |
143 g_win->save (file, false); |
144 } |
144 } |
145 } |
145 } |
146 |
146 |
147 // ============================================================================= |
147 // ============================================================================= |
148 // ----------------------------------------------------------------------------- |
148 // ----------------------------------------------------------------------------- |
149 DEFINE_ACTION (Close, CTRL (W)) |
149 DEFINE_ACTION (Close, CTRL (W)) |
150 { if (!LDFile::current()->isSafeToClose()) |
150 { if (!getCurrentDocument()->isSafeToClose()) |
151 return; |
151 return; |
152 |
152 |
153 delete LDFile::current(); |
153 delete getCurrentDocument(); |
154 } |
154 } |
155 |
155 |
156 // ============================================================================= |
156 // ============================================================================= |
157 // ----------------------------------------------------------------------------- |
157 // ----------------------------------------------------------------------------- |
158 DEFINE_ACTION (CloseAll, 0) |
158 DEFINE_ACTION (CloseAll, 0) |
257 } |
257 } |
258 |
258 |
259 // ============================================================================= |
259 // ============================================================================= |
260 // ----------------------------------------------------------------------------- |
260 // ----------------------------------------------------------------------------- |
261 DEFINE_ACTION (SelectAll, CTRL (A)) |
261 DEFINE_ACTION (SelectAll, CTRL (A)) |
262 { for (LDObject* obj : LDFile::current()->getObjects()) |
262 { for (LDObject* obj : getCurrentDocument()->getObjects()) |
263 obj->select(); |
263 obj->select(); |
264 |
264 |
265 g_win->updateSelection(); |
265 g_win->updateSelection(); |
266 } |
266 } |
267 |
267 |
271 { int colnum = g_win->getSelectedColor(); |
271 { int colnum = g_win->getSelectedColor(); |
272 |
272 |
273 if (colnum == -1) |
273 if (colnum == -1) |
274 return; // no consensus on color |
274 return; // no consensus on color |
275 |
275 |
276 LDFile::current()->clearSelection(); |
276 getCurrentDocument()->clearSelection(); |
277 |
277 |
278 for (LDObject* obj : LDFile::current()->getObjects()) |
278 for (LDObject* obj : getCurrentDocument()->getObjects()) |
279 if (obj->getColor() == colnum) |
279 if (obj->getColor() == colnum) |
280 obj->select(); |
280 obj->select(); |
281 |
281 |
282 g_win->updateSelection(); |
282 g_win->updateSelection(); |
283 } |
283 } |
303 for (LDObject* obj : selection()) |
303 for (LDObject* obj : selection()) |
304 if (static_cast<LDSubfile*> (obj)->getFileInfo()->getName() != refName) |
304 if (static_cast<LDSubfile*> (obj)->getFileInfo()->getName() != refName) |
305 return; |
305 return; |
306 } |
306 } |
307 |
307 |
308 LDFile::current()->clearSelection(); |
308 getCurrentDocument()->clearSelection(); |
309 |
309 |
310 for (LDObject* obj : LDFile::current()->getObjects()) |
310 for (LDObject* obj : getCurrentDocument()->getObjects()) |
311 { if (obj->getType() != type) |
311 { if (obj->getType() != type) |
312 continue; |
312 continue; |
313 |
313 |
314 if (type == LDObject::Subfile && static_cast<LDSubfile*> (obj)->getFileInfo()->getName() != refName) |
314 if (type == LDObject::Subfile && static_cast<LDSubfile*> (obj)->getFileInfo()->getName() != refName) |
315 continue; |
315 continue; |
360 return; |
360 return; |
361 } |
361 } |
362 |
362 |
363 QList<LDObject*> objs = loadFileContents (&f, null); |
363 QList<LDObject*> objs = loadFileContents (&f, null); |
364 |
364 |
365 LDFile::current()->clearSelection(); |
365 getCurrentDocument()->clearSelection(); |
366 |
366 |
367 for (LDObject* obj : objs) |
367 for (LDObject* obj : objs) |
368 { LDFile::current()->insertObj (idx, obj); |
368 { getCurrentDocument()->insertObj (idx, obj); |
369 obj->select(); |
369 obj->select(); |
370 g_win->R()->compileObject (obj); |
370 g_win->R()->compileObject (obj); |
371 |
371 |
372 idx++; |
372 idx++; |
373 } |
373 } |
420 dlg->connect (bbx_buttons, SIGNAL (rejected()), dlg, SLOT (reject())); |
420 dlg->connect (bbx_buttons, SIGNAL (rejected()), dlg, SLOT (reject())); |
421 |
421 |
422 if (dlg->exec() == false) |
422 if (dlg->exec() == false) |
423 return; |
423 return; |
424 |
424 |
425 LDFile::current()->clearSelection(); |
425 getCurrentDocument()->clearSelection(); |
426 |
426 |
427 for (str line : str (te_edit->toPlainText()).split ("\n")) |
427 for (str line : str (te_edit->toPlainText()).split ("\n")) |
428 { LDObject* obj = parseLine (line); |
428 { LDObject* obj = parseLine (line); |
429 |
429 |
430 LDFile::current()->insertObj (idx, obj); |
430 getCurrentDocument()->insertObj (idx, obj); |
431 obj->select(); |
431 obj->select(); |
432 g_win->R()->compileObject (obj); |
432 g_win->R()->compileObject (obj); |
433 idx++; |
433 idx++; |
434 } |
434 } |
435 |
435 |
444 |
444 |
445 int w, h; |
445 int w, h; |
446 uchar* imgdata = g_win->R()->getScreencap (w, h); |
446 uchar* imgdata = g_win->R()->getScreencap (w, h); |
447 QImage img = imageFromScreencap (imgdata, w, h); |
447 QImage img = imageFromScreencap (imgdata, w, h); |
448 |
448 |
449 str root = basename (LDFile::current()->getName()); |
449 str root = basename (getCurrentDocument()->getName()); |
450 |
450 |
451 if (root.right (4) == ".dat") |
451 if (root.right (4) == ".dat") |
452 root.chop (4); |
452 root.chop (4); |
453 |
453 |
454 str defaultname = (root.length() > 0) ? fmt ("%1.png", root) : ""; |
454 str defaultname = (root.length() > 0) ? fmt ("%1.png", root) : ""; |
558 #if 0 |
558 #if 0 |
559 // This is a test to draw a dummy axle. Meant to be used as a primitive gallery, |
559 // This is a test to draw a dummy axle. Meant to be used as a primitive gallery, |
560 // but I can't figure how to generate these pictures properly. Multi-threading |
560 // but I can't figure how to generate these pictures properly. Multi-threading |
561 // these is an immense pain. |
561 // these is an immense pain. |
562 DEFINE_ACTION (testpic, "Test picture", "", "", (0)) |
562 DEFINE_ACTION (testpic, "Test picture", "", "", (0)) |
563 { LDFile* file = getFile ("axle.dat"); |
563 { LDDocument* file = getFile ("axle.dat"); |
564 setlocale (LC_ALL, "C"); |
564 setlocale (LC_ALL, "C"); |
565 |
565 |
566 if (!file) |
566 if (!file) |
567 { critical ("couldn't load axle.dat"); |
567 { critical ("couldn't load axle.dat"); |
568 return; |
568 return; |
623 |
623 |
624 if (selection().size() == 1) |
624 if (selection().size() == 1) |
625 defval = selection()[0]->getIndex(); |
625 defval = selection()[0]->getIndex(); |
626 |
626 |
627 int idx = QInputDialog::getInt (null, "Go to line", "Go to line:", defval, |
627 int idx = QInputDialog::getInt (null, "Go to line", "Go to line:", defval, |
628 1, LDFile::current()->getObjectCount(), 1, &ok); |
628 1, getCurrentDocument()->getObjectCount(), 1, &ok); |
629 |
629 |
630 if (!ok || (obj = LDFile::current()->getObject (idx - 1)) == null) |
630 if (!ok || (obj = getCurrentDocument()->getObject (idx - 1)) == null) |
631 return; |
631 return; |
632 |
632 |
633 LDFile::current()->clearSelection(); |
633 getCurrentDocument()->clearSelection(); |
634 obj->select(); |
634 obj->select(); |
635 g_win->updateSelection(); |
635 g_win->updateSelection(); |
636 } |
636 } |