src/document.cpp

changeset 214
8e1fe64ce4e3
parent 205
1a4342d80de7
child 217
6d95c1a41e6e
equal deleted inserted replaced
213:ee5758ddb6d2 214:8e1fe64ce4e3
21 #include <QVBoxLayout> 21 #include <QVBoxLayout>
22 #include "document.h" 22 #include "document.h"
23 #include "model.h" 23 #include "model.h"
24 #include "ui/objecteditor.h" 24 #include "ui/objecteditor.h"
25 25
26 EditorTabWidget::EditorTabWidget( 26 EditTools::EditTools(
27 Model* model, 27 Model* model,
28 DocumentManager* documents,
29 const ColorTable& colorTable, 28 const ColorTable& colorTable,
30 QWidget* parent) : 29 QObject* parent) :
31 QWidget{parent}, 30 QObject{parent},
32 colorTable{colorTable}, 31 colorTable{colorTable},
33 canvas{new Canvas{model, this, documents, colorTable, this}},
34 model{model}, 32 model{model},
35 vertexMap{model} 33 vertexMap{model}
36 { 34 {
37 this->setMouseTracking(true); 35 #if 0
38 connect(this->canvas, &Canvas::mouseClick, this, &EditorTabWidget::canvasMouseClick); 36 connect(this->canvas, &Canvas::mouseClick, this, &EditTools::canvasMouseClick);
39 connect(this->canvas, &Canvas::mouseMove, this, &EditorTabWidget::canvasMouseMove); 37 connect(this->canvas, &Canvas::mouseMove, this, &EditTools::canvasMouseMove);
40 connect(this->canvas, &Canvas::newStatusText, this, &EditorTabWidget::newStatusText); 38 connect(this->canvas, &Canvas::newStatusText, this, &EditTools::newStatusText);
41 connect(this->model, &Model::dataChanged, this->canvas, qOverload<>(&Canvas::update)); 39 connect(this->model, &Model::dataChanged, this->canvas, qOverload<>(&Canvas::update));
42 connect(&this->vertexMap, &VertexMap::verticesChanged, [&]() 40 connect(&this->vertexMap, &VertexMap::verticesChanged, [&]()
43 { 41 {
44 this->canvas->rebuildVertices(this); 42 this->canvas->rebuildVertices(&this->vertexMap);
45 }); 43 });
46 this->canvas->drawState = &this->drawState; 44 this->canvas->drawState = &this->drawState;
47 QVBoxLayout* layout = new QVBoxLayout{this}; 45 #endif
48 layout->addWidget(this->canvas); 46 }
49 } 47
50 48 EditTools::~EditTools()
51 EditorTabWidget::~EditorTabWidget() 49 {
52 { 50 }
53 } 51
54 52 void EditTools::applyToVertices(VertexMap::ApplyFunction fn) const
55 void EditorTabWidget::applyToVertices(VertexMap::ApplyFunction fn) const
56 { 53 {
57 this->vertexMap.apply(fn); 54 this->vertexMap.apply(fn);
58 } 55 }
59 56
60 void EditorTabWidget::setEditMode(EditingMode mode) 57 void EditTools::setEditMode(EditingMode mode)
61 { 58 {
62 this->drawState.mode = mode; 59 this->drawState.mode = mode;
63 } 60 }
64 61
65 void updatePreviewPolygon(DrawState* drawState) 62 void updatePreviewPolygon(DrawState* drawState)
85 bool isCloseToExistingPoints(const std::vector<glm::vec3>& points, const glm::vec3 &pos) 82 bool isCloseToExistingPoints(const std::vector<glm::vec3>& points, const glm::vec3 &pos)
86 { 83 {
87 return any(points, std::bind(isclose, std::placeholders::_1, pos)); 84 return any(points, std::bind(isclose, std::placeholders::_1, pos));
88 } 85 }
89 86
90 void EditorTabWidget::canvasMouseClick(QMouseEvent *event) 87 void EditTools::canvasMouseClick(QMouseEvent*)
91 { 88 {
89 #if 0
92 switch(this->drawState.mode) 90 switch(this->drawState.mode)
93 { 91 {
94 case SelectMode: 92 case SelectMode:
95 if (event->button() == Qt::LeftButton) 93 if (event->button() == Qt::LeftButton)
96 { 94 {
102 //this->select(selected); 100 //this->select(selected);
103 event->accept(); 101 event->accept();
104 } 102 }
105 break; 103 break;
106 case DrawMode: 104 case DrawMode:
107 if (event->button() == Qt::LeftButton and this->canvas->worldPosition.has_value()) 105 if (event->button() == Qt::LeftButton) {
108 { 106 if (isCloseToExistingPoints(this->drawState.polygon, worldPosition)) {
109 const glm::vec3& pos = this->canvas->worldPosition.value();
110 if (isCloseToExistingPoints(this->drawState.polygon, pos))
111 {
112 this->closeShape(); 107 this->closeShape();
113 } 108 }
114 else 109 else {
115 {
116 this->drawState.polygon.push_back(pos); 110 this->drawState.polygon.push_back(pos);
117 updatePreviewPolygon(&this->drawState); 111 updatePreviewPolygon(&this->drawState);
118 } 112 }
119 event->accept(); 113 event->accept();
120 } 114 }
126 updatePreviewPolygon(&this->drawState); 120 updatePreviewPolygon(&this->drawState);
127 event->accept(); 121 event->accept();
128 } 122 }
129 break; 123 break;
130 } 124 }
131 } 125 #endif
132 126 }
133 void EditorTabWidget::canvasMouseMove(QMouseEvent *event) 127 void EditTools::canvasMouseMove(QMouseEvent*)
134 { 128 {
129 #if 0
135 switch(this->drawState.mode) 130 switch(this->drawState.mode)
136 { 131 {
137 case SelectMode: 132 case SelectMode:
138 break; 133 break;
139 case DrawMode: 134 case DrawMode:
144 this->update(); 139 this->update();
145 } 140 }
146 event->accept(); 141 event->accept();
147 break; 142 break;
148 } 143 }
149 } 144 #endif
145 }
146 #if 0
150 /* 147 /*
151 148
152 void EditorTabWidget::select(const QSet<ModelId> &selected) 149 void EditorTabWidget::select(const QSet<ModelId> &selected)
153 { 150 {
154 QItemSelectionModel* selectionModel = this->ui.listView->selectionModel(); 151 QItemSelectionModel* selectionModel = this->ui.listView->selectionModel();
163 } 160 }
164 } 161 }
165 selectionModel->select(itemSelection, QItemSelectionModel::ClearAndSelect); 162 selectionModel->select(itemSelection, QItemSelectionModel::ClearAndSelect);
166 } 163 }
167 */ 164 */
168 const QSet<ModelId> EditorTabWidget::selectedObjects() const 165 const QSet<ModelId> EditTools::selectedObjects() const
169 { 166 {
170 return this->canvas->selectedObjects(); 167 return this->canvas->selectedObjects();
171 } 168 }
172 169 #endif
173 EditingMode EditorTabWidget::currentEditingMode() const 170 EditingMode EditTools::currentEditingMode() const
174 { 171 {
175 return this->drawState.mode; 172 return this->drawState.mode;
176 } 173 }
177 174 #if 0
178 void EditorTabWidget::closeShape() 175 void EditTools::closeShape()
179 { 176 {
180 if (this->drawState.polygon.size() >= 2 and this->drawState.polygon.size() <= 4) 177 if (this->drawState.polygon.size() >= 2 and this->drawState.polygon.size() <= 4)
181 { 178 {
182 switch (this->drawState.polygon.size()) 179 switch (this->drawState.polygon.size())
183 { 180 {
220 } 217 }
221 } 218 }
222 this->drawState.polygon.clear(); 219 this->drawState.polygon.clear();
223 updatePreviewPolygon(&this->drawState); 220 updatePreviewPolygon(&this->drawState);
224 } 221 }
222
223 #endif

mercurial