]> Shamusworld >> Repos - architektonas/blob - src/actions/rs_actionselectintersected.cpp
Scrubbed out all references to RS2::qtToRsButton(). Gone!
[architektonas] / src / actions / rs_actionselectintersected.cpp
1 // rs_actionselectintersected.cpp
2 //
3 // Part of the Architektonas Project
4 // Originally part of QCad Community Edition by Andrew Mustun
5 // Extensively rewritten and refactored by James L. Hammons
6 // (C) 2010 Underground Software
7 //
8 // JLH = James L. Hammons <jlhamm@acm.org>
9 //
10 // Who  When        What
11 // ---  ----------  -----------------------------------------------------------
12 // JLH  05/22/2010  Added this text. :-)
13 //
14
15 #include "rs_actionselectintersected.h"
16
17 #include "rs_dialogfactory.h"
18 #include "rs_selection.h"
19 #include "rs_preview.h"
20
21 /**
22  * Constructor.
23  *
24  * @param select true: select window. false: deselect window
25  */
26 RS_ActionSelectIntersected::RS_ActionSelectIntersected(
27         RS_EntityContainer & container, RS_GraphicView & graphicView, bool select):
28         RS_PreviewActionInterface("Select Intersected", container, graphicView)
29 {
30         this->select = select;
31 }
32
33 RS_ActionSelectIntersected::~RS_ActionSelectIntersected()
34 {
35 }
36
37 /*virtual*/ RS2::ActionType RS_ActionSelectIntersected::rtti()
38 {
39         return RS2::ActionSelectIntersected;
40 }
41
42 void RS_ActionSelectIntersected::init(int status)
43 {
44         RS_PreviewActionInterface::init(status);
45
46         v1 = v2 = Vector(false);
47         snapMode = RS2::SnapFree;
48         snapRes = RS2::RestrictNothing;
49 }
50
51 void RS_ActionSelectIntersected::trigger()
52 {
53         RS_PreviewActionInterface::trigger();
54
55         if (v1.valid && v2.valid)
56                 if (graphicView->toGuiDX(v1.distanceTo(v2)) > 10)
57                 {
58                         deleteSnapper();
59
60                         RS_Selection s(*container, graphicView);
61                         s.selectIntersected(v1, v2, select);
62
63                         if (RS_DIALOGFACTORY != NULL)
64                                 RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
65
66                         init();
67                 }
68 }
69
70 void RS_ActionSelectIntersected::mouseMoveEvent(QMouseEvent * e)
71 {
72         if (getStatus() == SetPoint2 && v1.valid)
73         {
74                 v2 = snapPoint(e);
75                 deletePreview();
76                 clearPreview();
77                 preview->addEntity(new RS_Line(preview,
78                                 RS_LineData(Vector(v1.x, v1.y),
79                                         Vector(v2.x, v2.y))));
80                 drawPreview();
81         }
82 }
83
84 void RS_ActionSelectIntersected::mousePressEvent(QMouseEvent * e)
85 {
86         if (e->button() == Qt::LeftButton)
87         {
88                 switch (getStatus())
89                 {
90                 case SetPoint1:
91                         v1 = snapPoint(e);
92                         setStatus(SetPoint2);
93                         break;
94
95                 default:
96                         break;
97                 }
98         }
99
100         RS_DEBUG->print("RS_ActionSelectIntersected::mousePressEvent(): %f %f",
101                 v1.x, v1.y);
102 }
103
104 void RS_ActionSelectIntersected::mouseReleaseEvent(QMouseEvent * e)
105 {
106         RS_DEBUG->print("RS_ActionSelectIntersected::mouseReleaseEvent()");
107
108         if (e->button() == Qt::RightButton)
109         {
110                 if (getStatus() == SetPoint2)
111                         deletePreview();
112                 deleteSnapper();
113                 init(getStatus() - 1);
114         }
115         else if (e->button() == Qt::LeftButton)
116                 if (getStatus() == SetPoint2)
117                 {
118                         v2 = snapPoint(e);
119                         trigger();
120                 }
121 }
122
123 void RS_ActionSelectIntersected::updateMouseButtonHints()
124 {
125         if (RS_DIALOGFACTORY != NULL)
126         {
127                 switch (getStatus())
128                 {
129                 case SetPoint1:
130                         RS_DIALOGFACTORY->updateMouseWidget(tr("Choose first point of intersection line"), tr("Cancel"));
131                         break;
132
133                 case SetPoint2:
134                         RS_DIALOGFACTORY->updateMouseWidget(tr("Choose second point of intersection line"), tr("Back"));
135                         break;
136
137                 default:
138                         RS_DIALOGFACTORY->updateMouseWidget("", "");
139                         break;
140                 }
141         }
142 }
143
144 void RS_ActionSelectIntersected::updateMouseCursor()
145 {
146         graphicView->setMouseCursor(RS2::SelectCursor);
147 }
148
149 void RS_ActionSelectIntersected::updateToolBar()
150 {
151         if (RS_DIALOGFACTORY != NULL)
152         {
153                 if (!isFinished())
154                         //RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
155                         RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSelect);
156                 else
157                         RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSelect);
158         }
159 }
160
161 // EOF