54 this->setMouseTracking(true); |
54 this->setMouseTracking(true); |
55 connect(this->ui.viewportListSplitter, &QSplitter::splitterMoved, this, &Document::splitterChanged); |
55 connect(this->ui.viewportListSplitter, &QSplitter::splitterMoved, this, &Document::splitterChanged); |
56 connect(this->canvas, &Canvas::mouseClick, this, &Document::canvasMouseClick); |
56 connect(this->canvas, &Canvas::mouseClick, this, &Document::canvasMouseClick); |
57 connect(this->canvas, &Canvas::mouseMove, this, &Document::canvasMouseMove); |
57 connect(this->canvas, &Canvas::mouseMove, this, &Document::canvasMouseMove); |
58 connect(this->canvas, &Canvas::newStatusText, this, &Document::newStatusText); |
58 connect(this->canvas, &Canvas::newStatusText, this, &Document::newStatusText); |
59 connect(this->canvas, &Canvas::selectionChanged, [&](const QSet<ldraw::id_t>& newSelection) |
|
60 { |
|
61 QItemSelectionModel* selectionModel = this->ui.listView->selectionModel(); |
|
62 QItemSelection selection; |
|
63 for (const ldraw::id_t id : newSelection) |
|
64 { |
|
65 QModelIndex index = this->model->find(id); |
|
66 if (index != QModelIndex{}) |
|
67 { |
|
68 selection.select(index, index); |
|
69 } |
|
70 } |
|
71 QSignalBlocker blocker{this}; |
|
72 selectionModel->select(selection, QItemSelectionModel::ClearAndSelect); |
|
73 }); |
|
74 connect(this->ui.listView->selectionModel(), &QItemSelectionModel::selectionChanged, |
59 connect(this->ui.listView->selectionModel(), &QItemSelectionModel::selectionChanged, |
75 [&](const QItemSelection& selected, const QItemSelection& deselected) |
60 [&](const QItemSelection& selected, const QItemSelection& deselected) |
76 { |
61 { |
77 auto resolveIndex = [this](const QModelIndex& index){ return (*this->model)[index.row()]->id; }; |
62 auto resolveIndex = [this](const QModelIndex& index){ return (*this->model)[index.row()]->id; }; |
78 auto resolve = [resolveIndex](const QItemSelection& selection) |
63 auto resolve = [resolveIndex](const QItemSelection& selection) |
84 connect(this->model, &Model::dataChanged, this->canvas, qOverload<>(&Canvas::update)); |
69 connect(this->model, &Model::dataChanged, this->canvas, qOverload<>(&Canvas::update)); |
85 connect(&this->vertexMap, &VertexMap::verticesChanged, [&]() |
70 connect(&this->vertexMap, &VertexMap::verticesChanged, [&]() |
86 { |
71 { |
87 this->canvas->rebuildVertices(this); |
72 this->canvas->rebuildVertices(this); |
88 }); |
73 }); |
|
74 this->canvas->drawState = &this->drawState; |
89 this->initializeTools(); |
75 this->initializeTools(); |
90 } |
76 } |
91 |
77 |
92 Document::~Document() |
78 Document::~Document() |
93 { |
79 { |
165 { |
151 { |
166 QAction* triggeredAction = qobject_cast<QAction*>(this->sender()); |
152 QAction* triggeredAction = qobject_cast<QAction*>(this->sender()); |
167 if (triggeredAction != nullptr) |
153 if (triggeredAction != nullptr) |
168 { |
154 { |
169 const int index = triggeredAction->property(INDEX_PROPERTY).toInt(); |
155 const int index = triggeredAction->property(INDEX_PROPERTY).toInt(); |
170 this->mode = static_cast<EditingMode>(index); |
156 this->drawState.mode = static_cast<EditingMode>(index); |
171 this->ui.toolWidgetStack->setCurrentIndex(index); |
157 this->ui.toolWidgetStack->setCurrentIndex(index); |
172 for (QAction* action : this->toolActions) { |
158 for (QAction* action : this->toolActions) { |
173 action->setChecked(action == triggeredAction); |
159 action->setChecked(action == triggeredAction); |
174 } |
160 } |
175 } |
161 } |
200 return any(points, std::bind(geom::isclose, std::placeholders::_1, pos)); |
186 return any(points, std::bind(geom::isclose, std::placeholders::_1, pos)); |
201 } |
187 } |
202 |
188 |
203 void Document::canvasMouseClick(QMouseEvent *event) |
189 void Document::canvasMouseClick(QMouseEvent *event) |
204 { |
190 { |
205 switch(this->mode) |
191 switch(this->drawState.mode) |
206 { |
192 { |
207 case SelectMode: |
193 case SelectMode: |
208 if (event->button() == Qt::LeftButton) |
194 if (event->button() == Qt::LeftButton) |
209 { |
195 { |
210 const ldraw::id_t highlighted = this->canvas->getHighlightedObject(); |
196 const ldraw::id_t highlighted = this->canvas->getHighlightedObject(); |