48 |
48 |
49 data += obj->asText(); |
49 data += obj->asText(); |
50 ++count; |
50 ++count; |
51 } |
51 } |
52 |
52 |
53 qApp->clipboard()->setText (data); |
53 qApp->clipboard()->setText(data); |
54 return count; |
54 return count; |
55 } |
55 } |
56 |
56 |
57 void BasicToolset::cut() |
57 void BasicToolset::cut() |
58 { |
58 { |
59 int num = copyToClipboard(); |
59 int num = copyToClipboard(); |
60 m_window->deleteSelection(); |
60 m_window->deleteSelection(); |
61 print (tr ("%1 objects cut"), num); |
61 print(tr("%1 objects cut"), num); |
62 } |
62 } |
63 |
63 |
64 void BasicToolset::copy() |
64 void BasicToolset::copy() |
65 { |
65 { |
66 int num = copyToClipboard(); |
66 int num = copyToClipboard(); |
67 print (tr ("%1 objects copied"), num); |
67 print(tr("%1 objects copied"), num); |
68 } |
68 } |
69 |
69 |
70 void BasicToolset::paste() |
70 void BasicToolset::paste() |
71 { |
71 { |
72 const QString clipboardText = qApp->clipboard()->text(); |
72 const QString clipboardText = qApp->clipboard()->text(); |
73 int idx = m_window->suggestInsertPoint(); |
73 int idx = m_window->suggestInsertPoint(); |
74 currentDocument()->clearSelection(); |
74 currentDocument()->clearSelection(); |
75 int num = 0; |
75 int num = 0; |
76 |
76 |
77 for (QString line : clipboardText.split ("\n")) |
77 for (QString line : clipboardText.split("\n")) |
78 { |
78 { |
79 LDObject* pasted = ParseLine (line); |
79 LDObject* pasted = ParseLine(line); |
80 currentDocument()->insertObj (idx++, pasted); |
80 currentDocument()->insertObj(idx++, pasted); |
81 pasted->select(); |
81 pasted->select(); |
82 ++num; |
82 ++num; |
83 } |
83 } |
84 |
84 |
85 print (tr ("%1 objects pasted"), num); |
85 print(tr("%1 objects pasted"), num); |
86 m_window->refresh(); |
86 m_window->refresh(); |
87 m_window->scrollToSelection(); |
87 m_window->scrollToSelection(); |
88 } |
88 } |
89 |
89 |
90 void BasicToolset::remove() |
90 void BasicToolset::remove() |
91 { |
91 { |
92 int num = m_window->deleteSelection(); |
92 int num = m_window->deleteSelection(); |
93 print (tr ("%1 objects deleted"), num); |
93 print(tr("%1 objects deleted"), num); |
94 } |
94 } |
95 |
95 |
96 void BasicToolset::doInline (bool deep) |
96 void BasicToolset::doInline(bool deep) |
97 { |
97 { |
98 for (LDSubfileReference* ref : filterByType<LDSubfileReference> (selectedObjects())) |
98 for (LDSubfileReference* ref : filterByType<LDSubfileReference>(selectedObjects())) |
99 { |
99 { |
100 // Get the index of the subfile so we know where to insert the |
100 // Get the index of the subfile so we know where to insert the |
101 // inlined contents. |
101 // inlined contents. |
102 int idx = ref->lineNumber(); |
102 int idx = ref->lineNumber(); |
103 |
103 |
104 if (idx != -1) |
104 if (idx != -1) |
105 { |
105 { |
106 LDObjectList objs = ref->inlineContents (deep, false); |
106 LDObjectList objs = ref->inlineContents(deep, false); |
107 |
107 |
108 // Merge in the inlined objects |
108 // Merge in the inlined objects |
109 for (LDObject* inlineobj : objs) |
109 for (LDObject* inlineobj : objs) |
110 { |
110 { |
111 QString line = inlineobj->asText(); |
111 QString line = inlineobj->asText(); |
112 inlineobj->destroy(); |
112 inlineobj->destroy(); |
113 LDObject* newobj = ParseLine (line); |
113 LDObject* newobj = ParseLine(line); |
114 currentDocument()->insertObj (idx++, newobj); |
114 currentDocument()->insertObj(idx++, newobj); |
115 newobj->select(); |
115 newobj->select(); |
116 } |
116 } |
117 |
117 |
118 // Delete the subfile now as it's been inlined. |
118 // Delete the subfile now as it's been inlined. |
119 ref->destroy(); |
119 ref->destroy(); |
120 } |
120 } |
121 } |
121 } |
122 |
122 |
123 for (LDBezierCurve* curve : filterByType<LDBezierCurve> (selectedObjects())) |
123 for (LDBezierCurve* curve : filterByType<LDBezierCurve>(selectedObjects())) |
124 curve->replace (curve->rasterize()); |
124 curve->replace(curve->rasterize()); |
125 } |
125 } |
126 |
126 |
127 void BasicToolset::inlineShallow() |
127 void BasicToolset::inlineShallow() |
128 { |
128 { |
129 doInline (false); |
129 doInline(false); |
130 } |
130 } |
131 |
131 |
132 void BasicToolset::inlineDeep() |
132 void BasicToolset::inlineDeep() |
133 { |
133 { |
134 doInline (true); |
134 doInline(true); |
135 } |
135 } |
136 |
136 |
137 void BasicToolset::undo() |
137 void BasicToolset::undo() |
138 { |
138 { |
139 currentDocument()->undo(); |
139 currentDocument()->undo(); |
151 for (LDObject* obj : selectedObjects()) |
151 for (LDObject* obj : selectedObjects()) |
152 { |
152 { |
153 if (not obj->isColored()) |
153 if (not obj->isColored()) |
154 continue; |
154 continue; |
155 |
155 |
156 obj->setColor (obj->defaultColor()); |
156 obj->setColor(obj->defaultColor()); |
157 num++; |
157 num++; |
158 } |
158 } |
159 |
159 |
160 print (tr ("%1 objects uncolored"), num); |
160 print(tr("%1 objects uncolored"), num); |
161 } |
161 } |
162 |
162 |
163 void BasicToolset::insertRaw() |
163 void BasicToolset::insertRaw() |
164 { |
164 { |
165 int idx = m_window->suggestInsertPoint(); |
165 int idx = m_window->suggestInsertPoint(); |
166 |
166 |
167 QDialog* const dlg = new QDialog; |
167 QDialog* const dlg = new QDialog; |
168 QVBoxLayout* const layout = new QVBoxLayout; |
168 QVBoxLayout* const layout = new QVBoxLayout; |
169 QTextEdit* const inputbox = new QTextEdit; |
169 QTextEdit* const inputbox = new QTextEdit; |
170 QDialogButtonBox* const buttons = new QDialogButtonBox (QDialogButtonBox::Ok | QDialogButtonBox::Cancel); |
170 QDialogButtonBox* const buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); |
171 |
171 |
172 layout->addWidget (inputbox); |
172 layout->addWidget(inputbox); |
173 layout->addWidget (buttons); |
173 layout->addWidget(buttons); |
174 dlg->setLayout (layout); |
174 dlg->setLayout(layout); |
175 dlg->setWindowTitle (APPNAME " - Insert Raw"); |
175 dlg->setWindowTitle(APPNAME " - Insert Raw"); |
176 dlg->connect (buttons, SIGNAL (accepted()), dlg, SLOT (accept())); |
176 dlg->connect(buttons, SIGNAL(accepted()), dlg, SLOT(accept())); |
177 dlg->connect (buttons, SIGNAL (rejected()), dlg, SLOT (reject())); |
177 dlg->connect(buttons, SIGNAL(rejected()), dlg, SLOT(reject())); |
178 |
178 |
179 if (dlg->exec() == QDialog::Rejected) |
179 if (dlg->exec() == QDialog::Rejected) |
180 return; |
180 return; |
181 |
181 |
182 currentDocument()->clearSelection(); |
182 currentDocument()->clearSelection(); |
183 |
183 |
184 for (QString line : QString (inputbox->toPlainText()).split ("\n")) |
184 for (QString line : QString(inputbox->toPlainText()).split("\n")) |
185 { |
185 { |
186 LDObject* obj = ParseLine (line); |
186 LDObject* obj = ParseLine(line); |
187 |
187 |
188 currentDocument()->insertObj (idx, obj); |
188 currentDocument()->insertObj(idx, obj); |
189 obj->select(); |
189 obj->select(); |
190 idx++; |
190 idx++; |
191 } |
191 } |
192 |
192 |
193 m_window->refresh(); |
193 m_window->refresh(); |
205 // value to the color selection dialog. |
205 // value to the color selection dialog. |
206 LDColor color; |
206 LDColor color; |
207 LDColor defaultcol = m_window->getUniformSelectedColor(); |
207 LDColor defaultcol = m_window->getUniformSelectedColor(); |
208 |
208 |
209 // Show the dialog to the user now and ask for a color. |
209 // Show the dialog to the user now and ask for a color. |
210 if (ColorSelector::selectColor (m_window, color, defaultcol)) |
210 if (ColorSelector::selectColor(m_window, color, defaultcol)) |
211 { |
211 { |
212 for (LDObject* obj : objs) |
212 for (LDObject* obj : objs) |
213 { |
213 { |
214 if (obj->isColored()) |
214 if (obj->isColored()) |
215 obj->setColor (color); |
215 obj->setColor(color); |
216 } |
216 } |
217 } |
217 } |
218 } |
218 } |
219 |
219 |
220 void BasicToolset::invert() |
220 void BasicToolset::invert() |
223 obj->invert(); |
223 obj->invert(); |
224 } |
224 } |
225 |
225 |
226 void BasicToolset::newSubfile() |
226 void BasicToolset::newSubfile() |
227 { |
227 { |
228 AddObjectDialog::staticDialog (OBJ_SubfileReference, nullptr); |
228 AddObjectDialog::staticDialog(OBJ_SubfileReference, nullptr); |
229 } |
229 } |
230 |
230 |
231 void BasicToolset::newLine() |
231 void BasicToolset::newLine() |
232 { |
232 { |
233 AddObjectDialog::staticDialog (OBJ_Line, nullptr); |
233 AddObjectDialog::staticDialog(OBJ_Line, nullptr); |
234 } |
234 } |
235 |
235 |
236 void BasicToolset::newTriangle() |
236 void BasicToolset::newTriangle() |
237 { |
237 { |
238 AddObjectDialog::staticDialog (OBJ_Triangle, nullptr); |
238 AddObjectDialog::staticDialog(OBJ_Triangle, nullptr); |
239 } |
239 } |
240 |
240 |
241 void BasicToolset::newQuadrilateral() |
241 void BasicToolset::newQuadrilateral() |
242 { |
242 { |
243 AddObjectDialog::staticDialog (OBJ_Quad, nullptr); |
243 AddObjectDialog::staticDialog(OBJ_Quad, nullptr); |
244 } |
244 } |
245 |
245 |
246 void BasicToolset::newConditionalLine() |
246 void BasicToolset::newConditionalLine() |
247 { |
247 { |
248 AddObjectDialog::staticDialog (OBJ_CondLine, nullptr); |
248 AddObjectDialog::staticDialog(OBJ_CondLine, nullptr); |
249 } |
249 } |
250 |
250 |
251 void BasicToolset::newComment() |
251 void BasicToolset::newComment() |
252 { |
252 { |
253 AddObjectDialog::staticDialog (OBJ_Comment, nullptr); |
253 AddObjectDialog::staticDialog(OBJ_Comment, nullptr); |
254 } |
254 } |
255 |
255 |
256 void BasicToolset::newBFC() |
256 void BasicToolset::newBFC() |
257 { |
257 { |
258 AddObjectDialog::staticDialog (OBJ_Bfc, nullptr); |
258 AddObjectDialog::staticDialog(OBJ_Bfc, nullptr); |
259 } |
259 } |
260 |
260 |
261 void BasicToolset::edit() |
261 void BasicToolset::edit() |
262 { |
262 { |
263 if (selectedObjects().size() != 1) |
263 if (selectedObjects().size() != 1) |
264 return; |
264 return; |
265 |
265 |
266 LDObject* obj = selectedObjects().first(); |
266 LDObject* obj = selectedObjects().first(); |
267 AddObjectDialog::staticDialog (obj->type(), obj); |
267 AddObjectDialog::staticDialog(obj->type(), obj); |
268 } |
268 } |
269 |
269 |
270 void BasicToolset::modeSelect() |
270 void BasicToolset::modeSelect() |
271 { |
271 { |
272 m_window->renderer()->setEditMode (EditModeType::Select); |
272 m_window->renderer()->setEditMode(EditModeType::Select); |
273 } |
273 } |
274 |
274 |
275 void BasicToolset::modeCurve() |
275 void BasicToolset::modeCurve() |
276 { |
276 { |
277 m_window->renderer()->setEditMode (EditModeType::Curve); |
277 m_window->renderer()->setEditMode(EditModeType::Curve); |
278 } |
278 } |
279 |
279 |
280 void BasicToolset::modeDraw() |
280 void BasicToolset::modeDraw() |
281 { |
281 { |
282 m_window->renderer()->setEditMode (EditModeType::Draw); |
282 m_window->renderer()->setEditMode(EditModeType::Draw); |
283 } |
283 } |
284 |
284 |
285 void BasicToolset::modeRectangle() |
285 void BasicToolset::modeRectangle() |
286 { |
286 { |
287 m_window->renderer()->setEditMode (EditModeType::Rectangle); |
287 m_window->renderer()->setEditMode(EditModeType::Rectangle); |
288 } |
288 } |
289 |
289 |
290 void BasicToolset::modeCircle() |
290 void BasicToolset::modeCircle() |
291 { |
291 { |
292 m_window->renderer()->setEditMode (EditModeType::Circle); |
292 m_window->renderer()->setEditMode(EditModeType::Circle); |
293 } |
293 } |
294 |
294 |
295 void BasicToolset::modeMagicWand() |
295 void BasicToolset::modeMagicWand() |
296 { |
296 { |
297 m_window->renderer()->setEditMode (EditModeType::MagicWand); |
297 m_window->renderer()->setEditMode(EditModeType::MagicWand); |
298 } |
298 } |
299 |
299 |
300 void BasicToolset::modeLinePath() |
300 void BasicToolset::modeLinePath() |
301 { |
301 { |
302 m_window->renderer()->setEditMode (EditModeType::LinePath); |
302 m_window->renderer()->setEditMode(EditModeType::LinePath); |
303 } |
303 } |