src/tools/selecttool.cpp

Mon, 16 May 2022 01:40:49 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Mon, 16 May 2022 01:40:49 +0300
changeset 187
30204975694a
parent 185
a38a0eb007b0
permissions
-rw-r--r--

work on circle tool

96
165777a20dc7 added tool base code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
1 #include "selecttool.h"
165777a20dc7 added tool base code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
2
152
03f8e6d42e13 Major refactoring
Teemu Piippo <teemu@hecknology.net>
parents: 143
diff changeset
3 SelectTool::SelectTool(Document* document) :
03f8e6d42e13 Major refactoring
Teemu Piippo <teemu@hecknology.net>
parents: 143
diff changeset
4 BaseTool{document},
03f8e6d42e13 Major refactoring
Teemu Piippo <teemu@hecknology.net>
parents: 143
diff changeset
5 objectEditor{new ObjectEditor{document, ldraw::NULL_ID}}
03f8e6d42e13 Major refactoring
Teemu Piippo <teemu@hecknology.net>
parents: 143
diff changeset
6 {
03f8e6d42e13 Major refactoring
Teemu Piippo <teemu@hecknology.net>
parents: 143
diff changeset
7 }
96
165777a20dc7 added tool base code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
8
165777a20dc7 added tool base code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
9 QString SelectTool::name() const
165777a20dc7 added tool base code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
10 {
165777a20dc7 added tool base code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
11 static const QString result = tr("Select");
165777a20dc7 added tool base code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
12 return result;
165777a20dc7 added tool base code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
13 }
165777a20dc7 added tool base code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
14
165777a20dc7 added tool base code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
15 QString SelectTool::toolTip() const
165777a20dc7 added tool base code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
16 {
165777a20dc7 added tool base code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
17 static const QString result = tr("Select elements from the model.");
165777a20dc7 added tool base code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
18 return result;
165777a20dc7 added tool base code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
19 }
107
02f142b399b1 Move selection logic into select tool
Teemu Piippo <teemu@hecknology.net>
parents: 96
diff changeset
20
185
a38a0eb007b0 Added line path tool
Teemu Piippo <teemu@hecknology.net>
parents: 163
diff changeset
21 bool SelectTool::mouseClick(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 const ldraw::id_t highlighted = canvas->getHighlightedObject();
000781318c36 added right click support for draw tool
Teemu Piippo <teemu@hecknology.net>
parents: 111
diff changeset
26 canvas->clearSelection();
000781318c36 added right click support for draw tool
Teemu Piippo <teemu@hecknology.net>
parents: 111
diff changeset
27 if (highlighted != ldraw::NULL_ID)
000781318c36 added right click support for draw tool
Teemu Piippo <teemu@hecknology.net>
parents: 111
diff changeset
28 {
000781318c36 added right click support for draw tool
Teemu Piippo <teemu@hecknology.net>
parents: 111
diff changeset
29 canvas->addToSelection(highlighted);
000781318c36 added right click support for draw tool
Teemu Piippo <teemu@hecknology.net>
parents: 111
diff changeset
30 }
000781318c36 added right click support for draw tool
Teemu Piippo <teemu@hecknology.net>
parents: 111
diff changeset
31 return true;
107
02f142b399b1 Move selection logic into select tool
Teemu Piippo <teemu@hecknology.net>
parents: 96
diff changeset
32 }
121
000781318c36 added right click support for draw tool
Teemu Piippo <teemu@hecknology.net>
parents: 111
diff changeset
33 else
000781318c36 added right click support for draw tool
Teemu Piippo <teemu@hecknology.net>
parents: 111
diff changeset
34 {
000781318c36 added right click support for draw tool
Teemu Piippo <teemu@hecknology.net>
parents: 111
diff changeset
35 return false;
000781318c36 added right click support for draw tool
Teemu Piippo <teemu@hecknology.net>
parents: 111
diff changeset
36 }
107
02f142b399b1 Move selection logic into select tool
Teemu Piippo <teemu@hecknology.net>
parents: 96
diff changeset
37 }
126
a7c720aff97c moved ObjectEditor under SelectTool
Teemu Piippo <teemu@hecknology.net>
parents: 121
diff changeset
38
a7c720aff97c moved ObjectEditor under SelectTool
Teemu Piippo <teemu@hecknology.net>
parents: 121
diff changeset
39 QWidget* SelectTool::toolWidget()
a7c720aff97c moved ObjectEditor under SelectTool
Teemu Piippo <teemu@hecknology.net>
parents: 121
diff changeset
40 {
143
7b62c52835a1 Fix memory corruption involving document tools.
Teemu Piippo <teemu@hecknology.net>
parents: 126
diff changeset
41 return this->objectEditor;
126
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
a7c720aff97c moved ObjectEditor under SelectTool
Teemu Piippo <teemu@hecknology.net>
parents: 121
diff changeset
44 void SelectTool::selectionChanged(const QSet<ldraw::id_t>& newSelection)
a7c720aff97c moved ObjectEditor under SelectTool
Teemu Piippo <teemu@hecknology.net>
parents: 121
diff changeset
45 {
a7c720aff97c moved ObjectEditor under SelectTool
Teemu Piippo <teemu@hecknology.net>
parents: 121
diff changeset
46 if (newSelection.size() == 1)
a7c720aff97c moved ObjectEditor under SelectTool
Teemu Piippo <teemu@hecknology.net>
parents: 121
diff changeset
47 {
143
7b62c52835a1 Fix memory corruption involving document tools.
Teemu Piippo <teemu@hecknology.net>
parents: 126
diff changeset
48 this->objectEditor->setObjectId(*newSelection.begin());
126
a7c720aff97c moved ObjectEditor under SelectTool
Teemu Piippo <teemu@hecknology.net>
parents: 121
diff changeset
49 }
a7c720aff97c moved ObjectEditor under SelectTool
Teemu Piippo <teemu@hecknology.net>
parents: 121
diff changeset
50 else
a7c720aff97c moved ObjectEditor under SelectTool
Teemu Piippo <teemu@hecknology.net>
parents: 121
diff changeset
51 {
143
7b62c52835a1 Fix memory corruption involving document tools.
Teemu Piippo <teemu@hecknology.net>
parents: 126
diff changeset
52 this->objectEditor->setObjectId(ldraw::NULL_ID);
126
a7c720aff97c moved ObjectEditor under SelectTool
Teemu Piippo <teemu@hecknology.net>
parents: 121
diff changeset
53 }
a7c720aff97c moved ObjectEditor under SelectTool
Teemu Piippo <teemu@hecknology.net>
parents: 121
diff changeset
54 }
163
36ea1a8aee33 Add icons for tools
Teemu Piippo <teemu@hecknology.net>
parents: 152
diff changeset
55
36ea1a8aee33 Add icons for tools
Teemu Piippo <teemu@hecknology.net>
parents: 152
diff changeset
56 QString SelectTool::iconName() const
36ea1a8aee33 Add icons for tools
Teemu Piippo <teemu@hecknology.net>
parents: 152
diff changeset
57 {
36ea1a8aee33 Add icons for tools
Teemu Piippo <teemu@hecknology.net>
parents: 152
diff changeset
58 return ":/icons/navigate-outline.png";
36ea1a8aee33 Add icons for tools
Teemu Piippo <teemu@hecknology.net>
parents: 152
diff changeset
59 }

mercurial