Sun, 13 Mar 2022 14:51:39 +0200
fix saving
add color editing to object editor
96 | 1 | #include "selecttool.h" |
2 | ||
152 | 3 | SelectTool::SelectTool(Document* document) : |
4 | BaseTool{document}, | |
5 | objectEditor{new ObjectEditor{document, ldraw::NULL_ID}} | |
6 | { | |
7 | } | |
96 | 8 | |
9 | QString SelectTool::name() const | |
10 | { | |
11 | static const QString result = tr("Select"); | |
12 | return result; | |
13 | } | |
14 | ||
15 | QString SelectTool::toolTip() const | |
16 | { | |
17 | static const QString result = tr("Select elements from the model."); | |
18 | return result; | |
19 | } | |
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 | 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
|
22 | { |
121
000781318c36
added right click support for draw tool
Teemu Piippo <teemu@hecknology.net>
parents:
111
diff
changeset
|
23 | if (event->button() == Qt::LeftButton) |
107
02f142b399b1
Move selection logic into select tool
Teemu Piippo <teemu@hecknology.net>
parents:
96
diff
changeset
|
24 | { |
121
000781318c36
added right click support for draw tool
Teemu Piippo <teemu@hecknology.net>
parents:
111
diff
changeset
|
25 | static_cast<void>(document); |
000781318c36
added right click support for draw tool
Teemu Piippo <teemu@hecknology.net>
parents:
111
diff
changeset
|
26 | const ldraw::id_t highlighted = canvas->getHighlightedObject(); |
000781318c36
added right click support for draw tool
Teemu Piippo <teemu@hecknology.net>
parents:
111
diff
changeset
|
27 | canvas->clearSelection(); |
000781318c36
added right click support for draw tool
Teemu Piippo <teemu@hecknology.net>
parents:
111
diff
changeset
|
28 | if (highlighted != ldraw::NULL_ID) |
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 | canvas->addToSelection(highlighted); |
000781318c36
added right click support for draw tool
Teemu Piippo <teemu@hecknology.net>
parents:
111
diff
changeset
|
31 | } |
000781318c36
added right click support for draw tool
Teemu Piippo <teemu@hecknology.net>
parents:
111
diff
changeset
|
32 | return true; |
107
02f142b399b1
Move selection logic into select tool
Teemu Piippo <teemu@hecknology.net>
parents:
96
diff
changeset
|
33 | } |
121
000781318c36
added right click support for draw tool
Teemu Piippo <teemu@hecknology.net>
parents:
111
diff
changeset
|
34 | else |
000781318c36
added right click support for draw tool
Teemu Piippo <teemu@hecknology.net>
parents:
111
diff
changeset
|
35 | { |
000781318c36
added right click support for draw tool
Teemu Piippo <teemu@hecknology.net>
parents:
111
diff
changeset
|
36 | return false; |
000781318c36
added right click support for draw tool
Teemu Piippo <teemu@hecknology.net>
parents:
111
diff
changeset
|
37 | } |
107
02f142b399b1
Move selection logic into select tool
Teemu Piippo <teemu@hecknology.net>
parents:
96
diff
changeset
|
38 | } |
126
a7c720aff97c
moved ObjectEditor under SelectTool
Teemu Piippo <teemu@hecknology.net>
parents:
121
diff
changeset
|
39 | |
a7c720aff97c
moved ObjectEditor under SelectTool
Teemu Piippo <teemu@hecknology.net>
parents:
121
diff
changeset
|
40 | QWidget* SelectTool::toolWidget() |
a7c720aff97c
moved ObjectEditor under SelectTool
Teemu Piippo <teemu@hecknology.net>
parents:
121
diff
changeset
|
41 | { |
143
7b62c52835a1
Fix memory corruption involving document tools.
Teemu Piippo <teemu@hecknology.net>
parents:
126
diff
changeset
|
42 | return this->objectEditor; |
126
a7c720aff97c
moved ObjectEditor under SelectTool
Teemu Piippo <teemu@hecknology.net>
parents:
121
diff
changeset
|
43 | } |
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 | void SelectTool::selectionChanged(const QSet<ldraw::id_t>& newSelection) |
a7c720aff97c
moved ObjectEditor under SelectTool
Teemu Piippo <teemu@hecknology.net>
parents:
121
diff
changeset
|
46 | { |
a7c720aff97c
moved ObjectEditor under SelectTool
Teemu Piippo <teemu@hecknology.net>
parents:
121
diff
changeset
|
47 | if (newSelection.size() == 1) |
a7c720aff97c
moved ObjectEditor under SelectTool
Teemu Piippo <teemu@hecknology.net>
parents:
121
diff
changeset
|
48 | { |
143
7b62c52835a1
Fix memory corruption involving document tools.
Teemu Piippo <teemu@hecknology.net>
parents:
126
diff
changeset
|
49 | this->objectEditor->setObjectId(*newSelection.begin()); |
126
a7c720aff97c
moved ObjectEditor under SelectTool
Teemu Piippo <teemu@hecknology.net>
parents:
121
diff
changeset
|
50 | } |
a7c720aff97c
moved ObjectEditor under SelectTool
Teemu Piippo <teemu@hecknology.net>
parents:
121
diff
changeset
|
51 | else |
a7c720aff97c
moved ObjectEditor under SelectTool
Teemu Piippo <teemu@hecknology.net>
parents:
121
diff
changeset
|
52 | { |
143
7b62c52835a1
Fix memory corruption involving document tools.
Teemu Piippo <teemu@hecknology.net>
parents:
126
diff
changeset
|
53 | this->objectEditor->setObjectId(ldraw::NULL_ID); |
126
a7c720aff97c
moved ObjectEditor under SelectTool
Teemu Piippo <teemu@hecknology.net>
parents:
121
diff
changeset
|
54 | } |
a7c720aff97c
moved ObjectEditor under SelectTool
Teemu Piippo <teemu@hecknology.net>
parents:
121
diff
changeset
|
55 | } |
163 | 56 | |
57 | QString SelectTool::iconName() const | |
58 | { | |
59 | return ":/icons/navigate-outline.png"; | |
60 | } |