src/document.cpp

changeset 204
52e10e8d88cc
parent 203
1909a0123c72
child 205
1a4342d80de7
equal deleted inserted replaced
203:1909a0123c72 204:52e10e8d88cc
30 QWidget* parent) : 30 QWidget* parent) :
31 QWidget{parent}, 31 QWidget{parent},
32 colorTable{colorTable}, 32 colorTable{colorTable},
33 canvas{new Canvas{model, this, documents, colorTable, this}}, 33 canvas{new Canvas{model, this, documents, colorTable, this}},
34 model{model}, 34 model{model},
35 documents{documents},
36 vertexMap{model} 35 vertexMap{model}
37 { 36 {
38 this->setMouseTracking(true); 37 this->setMouseTracking(true);
39 connect(this->canvas, &Canvas::mouseClick, this, &EditorTabWidget::canvasMouseClick); 38 connect(this->canvas, &Canvas::mouseClick, this, &EditorTabWidget::canvasMouseClick);
40 connect(this->canvas, &Canvas::mouseMove, this, &EditorTabWidget::canvasMouseMove); 39 connect(this->canvas, &Canvas::mouseMove, this, &EditorTabWidget::canvasMouseMove);
181 if (this->drawState.polygon.size() >= 2 and this->drawState.polygon.size() <= 4) 180 if (this->drawState.polygon.size() >= 2 and this->drawState.polygon.size() <= 4)
182 { 181 {
183 switch (this->drawState.polygon.size()) 182 switch (this->drawState.polygon.size())
184 { 183 {
185 case 2: 184 case 2:
186 this->model->append(Colored<LineSegment>{ 185 Q_EMIT this->modelAction(AppendToModel{
187 LineSegment{ 186 .newElement = Colored<LineSegment>{
188 .p1 = this->drawState.polygon[0], 187 LineSegment{
189 .p2 = this->drawState.polygon[1], 188 .p1 = this->drawState.polygon[0],
190 }, 189 .p2 = this->drawState.polygon[1],
191 ldraw::EDGE_COLOR}); 190 },
191 ldraw::EDGE_COLOR,
192 }
193 });
192 break; 194 break;
193 case 3: 195 case 3:
194 this->model->append(Colored<Triangle>{ 196 Q_EMIT this->modelAction(AppendToModel{
195 Triangle{ 197 .newElement = Colored<Triangle>{
196 .p1 = this->drawState.polygon[0], 198 Triangle{
197 .p2 = this->drawState.polygon[1], 199 .p1 = this->drawState.polygon[0],
198 .p3 = this->drawState.polygon[2], 200 .p2 = this->drawState.polygon[1],
199 }, 201 .p3 = this->drawState.polygon[2],
200 ldraw::MAIN_COLOR}); 202 },
203 ldraw::MAIN_COLOR,
204 }
205 });
201 break; 206 break;
202 case 4: 207 case 4:
203 this->model->append(Colored<Quadrilateral>{ 208 Q_EMIT this->modelAction(AppendToModel{
204 Quadrilateral{ 209 .newElement = Colored<Quadrilateral>{
205 .p1 = this->drawState.polygon[0], 210 Quadrilateral{
206 .p2 = this->drawState.polygon[1], 211 .p1 = this->drawState.polygon[0],
207 .p3 = this->drawState.polygon[2], 212 .p2 = this->drawState.polygon[1],
208 .p4 = this->drawState.polygon[3], 213 .p3 = this->drawState.polygon[2],
209 }, 214 .p4 = this->drawState.polygon[3],
210 ldraw::MAIN_COLOR}); 215 },
216 ldraw::MAIN_COLOR,
217 }
218 });
211 break; 219 break;
212 } 220 }
213 } 221 }
214 this->drawState.polygon.clear(); 222 this->drawState.polygon.clear();
215 updatePreviewPolygon(&this->drawState); 223 updatePreviewPolygon(&this->drawState);

mercurial