Tue, 01 Mar 2022 17:00:19 +0200
work on edit history
96 | 1 | #include "selecttool.h" |
2 | ||
143
7b62c52835a1
Fix memory corruption involving document tools.
Teemu Piippo <teemu@hecknology.net>
parents:
126
diff
changeset
|
3 | SelectTool::SelectTool(Model* model, QWidget* parent) : |
126
a7c720aff97c
moved ObjectEditor under SelectTool
Teemu Piippo <teemu@hecknology.net>
parents:
121
diff
changeset
|
4 | BaseTool{model, parent}, |
143
7b62c52835a1
Fix memory corruption involving document tools.
Teemu Piippo <teemu@hecknology.net>
parents:
126
diff
changeset
|
5 | objectEditor{new ObjectEditor{model, ldraw::NULL_ID, parent}} {} |
96 | 6 | |
7 | QString SelectTool::name() const | |
8 | { | |
9 | static const QString result = tr("Select"); | |
10 | return result; | |
11 | } | |
12 | ||
13 | QString SelectTool::toolTip() const | |
14 | { | |
15 | static const QString result = tr("Select elements from the model."); | |
16 | return result; | |
17 | } | |
107
02f142b399b1
Move selection logic into select tool
Teemu Piippo <teemu@hecknology.net>
parents:
96
diff
changeset
|
18 | |
121
000781318c36
added right click support for draw tool
Teemu Piippo <teemu@hecknology.net>
parents:
111
diff
changeset
|
19 | bool SelectTool::mouseClick(Document* document, Canvas* canvas, QMouseEvent* event) |
107
02f142b399b1
Move selection logic into select tool
Teemu Piippo <teemu@hecknology.net>
parents:
96
diff
changeset
|
20 | { |
121
000781318c36
added right click support for draw tool
Teemu Piippo <teemu@hecknology.net>
parents:
111
diff
changeset
|
21 | if (event->button() == Qt::LeftButton) |
107
02f142b399b1
Move selection logic into select tool
Teemu Piippo <teemu@hecknology.net>
parents:
96
diff
changeset
|
22 | { |
121
000781318c36
added right click support for draw tool
Teemu Piippo <teemu@hecknology.net>
parents:
111
diff
changeset
|
23 | static_cast<void>(document); |
000781318c36
added right click support for draw tool
Teemu Piippo <teemu@hecknology.net>
parents:
111
diff
changeset
|
24 | const ldraw::id_t highlighted = canvas->getHighlightedObject(); |
000781318c36
added right click support for draw tool
Teemu Piippo <teemu@hecknology.net>
parents:
111
diff
changeset
|
25 | canvas->clearSelection(); |
000781318c36
added right click support for draw tool
Teemu Piippo <teemu@hecknology.net>
parents:
111
diff
changeset
|
26 | if (highlighted != ldraw::NULL_ID) |
000781318c36
added right click support for draw tool
Teemu Piippo <teemu@hecknology.net>
parents:
111
diff
changeset
|
27 | { |
000781318c36
added right click support for draw tool
Teemu Piippo <teemu@hecknology.net>
parents:
111
diff
changeset
|
28 | canvas->addToSelection(highlighted); |
000781318c36
added right click support for draw tool
Teemu Piippo <teemu@hecknology.net>
parents:
111
diff
changeset
|
29 | } |
000781318c36
added right click support for draw tool
Teemu Piippo <teemu@hecknology.net>
parents:
111
diff
changeset
|
30 | return true; |
107
02f142b399b1
Move selection logic into select tool
Teemu Piippo <teemu@hecknology.net>
parents:
96
diff
changeset
|
31 | } |
121
000781318c36
added right click support for draw tool
Teemu Piippo <teemu@hecknology.net>
parents:
111
diff
changeset
|
32 | else |
000781318c36
added right click support for draw tool
Teemu Piippo <teemu@hecknology.net>
parents:
111
diff
changeset
|
33 | { |
000781318c36
added right click support for draw tool
Teemu Piippo <teemu@hecknology.net>
parents:
111
diff
changeset
|
34 | return false; |
000781318c36
added right click support for draw tool
Teemu Piippo <teemu@hecknology.net>
parents:
111
diff
changeset
|
35 | } |
107
02f142b399b1
Move selection logic into select tool
Teemu Piippo <teemu@hecknology.net>
parents:
96
diff
changeset
|
36 | } |
126
a7c720aff97c
moved ObjectEditor under SelectTool
Teemu Piippo <teemu@hecknology.net>
parents:
121
diff
changeset
|
37 | |
a7c720aff97c
moved ObjectEditor under SelectTool
Teemu Piippo <teemu@hecknology.net>
parents:
121
diff
changeset
|
38 | QWidget* SelectTool::toolWidget() |
a7c720aff97c
moved ObjectEditor under SelectTool
Teemu Piippo <teemu@hecknology.net>
parents:
121
diff
changeset
|
39 | { |
143
7b62c52835a1
Fix memory corruption involving document tools.
Teemu Piippo <teemu@hecknology.net>
parents:
126
diff
changeset
|
40 | return this->objectEditor; |
126
a7c720aff97c
moved ObjectEditor under SelectTool
Teemu Piippo <teemu@hecknology.net>
parents:
121
diff
changeset
|
41 | } |
a7c720aff97c
moved ObjectEditor under SelectTool
Teemu Piippo <teemu@hecknology.net>
parents:
121
diff
changeset
|
42 | |
a7c720aff97c
moved ObjectEditor under SelectTool
Teemu Piippo <teemu@hecknology.net>
parents:
121
diff
changeset
|
43 | void SelectTool::selectionChanged(const QSet<ldraw::id_t>& newSelection) |
a7c720aff97c
moved ObjectEditor under SelectTool
Teemu Piippo <teemu@hecknology.net>
parents:
121
diff
changeset
|
44 | { |
a7c720aff97c
moved ObjectEditor under SelectTool
Teemu Piippo <teemu@hecknology.net>
parents:
121
diff
changeset
|
45 | if (newSelection.size() == 1) |
a7c720aff97c
moved ObjectEditor under SelectTool
Teemu Piippo <teemu@hecknology.net>
parents:
121
diff
changeset
|
46 | { |
143
7b62c52835a1
Fix memory corruption involving document tools.
Teemu Piippo <teemu@hecknology.net>
parents:
126
diff
changeset
|
47 | this->objectEditor->setObjectId(*newSelection.begin()); |
126
a7c720aff97c
moved ObjectEditor under SelectTool
Teemu Piippo <teemu@hecknology.net>
parents:
121
diff
changeset
|
48 | } |
a7c720aff97c
moved ObjectEditor under SelectTool
Teemu Piippo <teemu@hecknology.net>
parents:
121
diff
changeset
|
49 | else |
a7c720aff97c
moved ObjectEditor under SelectTool
Teemu Piippo <teemu@hecknology.net>
parents:
121
diff
changeset
|
50 | { |
143
7b62c52835a1
Fix memory corruption involving document tools.
Teemu Piippo <teemu@hecknology.net>
parents:
126
diff
changeset
|
51 | this->objectEditor->setObjectId(ldraw::NULL_ID); |
126
a7c720aff97c
moved ObjectEditor under SelectTool
Teemu Piippo <teemu@hecknology.net>
parents:
121
diff
changeset
|
52 | } |
a7c720aff97c
moved ObjectEditor under SelectTool
Teemu Piippo <teemu@hecknology.net>
parents:
121
diff
changeset
|
53 | } |