]> Shamusworld >> Repos - architektonas/blob - src/actions/rs_actionselectwindow.cpp
Last checkin before major refactor...
[architektonas] / src / actions / rs_actionselectwindow.cpp
1 // rs_actionselectwindow.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_actionselectwindow.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_ActionSelectWindow::RS_ActionSelectWindow(RS_EntityContainer & container,
27         GraphicView & graphicView, bool select):
28         RS_PreviewActionInterface("Select Window", container, graphicView)
29 {
30         this->select = select;
31 }
32
33 RS_ActionSelectWindow::~RS_ActionSelectWindow()
34 {
35 }
36
37 /*virtual*/ RS2::ActionType RS_ActionSelectWindow::rtti()
38 {
39         return RS2::ActionSelectWindow;
40 }
41
42 void RS_ActionSelectWindow::init(int status)
43 {
44         RS_PreviewActionInterface::init(status);
45         v1 = v2 = Vector(false);
46         snapMode = RS2::SnapFree;
47         snapRes = RS2::RestrictNothing;
48 }
49
50 void RS_ActionSelectWindow::trigger()
51 {
52         RS_PreviewActionInterface::trigger();
53
54         if (v1.valid && v2.valid)
55         {
56                 if (graphicView->toGuiDX(v1.distanceTo(v2)) > 10)
57                 {
58                         deleteSnapper();
59
60                         bool cross = (v2.y > v1.y);
61
62                         RS_Selection s(*container, graphicView);
63                         s.selectWindow(v1, v2, select, cross);
64
65                         RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
66
67                         init();
68                 }
69         }
70 }
71
72 void RS_ActionSelectWindow::mouseMoveEvent(QMouseEvent * e)
73 {
74         if (getStatus() == SetCorner2 && v1.valid)
75         {
76                 v2 = snapPoint(e);
77                 deletePreview();
78                 clearPreview();
79                 preview->addEntity(new RS_Line(preview,
80                                 RS_LineData(Vector(v1.x, v1.y),
81                                         Vector(v2.x, v1.y))));
82                 preview->addEntity(new RS_Line(preview,
83                                 RS_LineData(Vector(v2.x, v1.y),
84                                         Vector(v2.x, v2.y))));
85                 preview->addEntity(new RS_Line(preview,
86                                 RS_LineData(Vector(v2.x, v2.y),
87                                         Vector(v1.x, v2.y))));
88                 preview->addEntity(new RS_Line(preview,
89                                 RS_LineData(Vector(v1.x, v2.y),
90                                         Vector(v1.x, v1.y))));
91                 drawPreview();
92         }
93 }
94
95 void RS_ActionSelectWindow::mousePressEvent(QMouseEvent * e)
96 {
97         if (e->button() == Qt::LeftButton)
98         {
99                 switch (getStatus())
100                 {
101                 case SetCorner1:
102                         v1 = snapPoint(e);
103                         setStatus(SetCorner2);
104                         break;
105
106                 default:
107                         break;
108                 }
109         }
110
111         RS_DEBUG->print("RS_ActionSelectWindow::mousePressEvent(): %f %f",
112                 v1.x, v1.y);
113 }
114
115 void RS_ActionSelectWindow::mouseReleaseEvent(QMouseEvent * e)
116 {
117         RS_DEBUG->print("RS_ActionSelectWindow::mouseReleaseEvent()");
118
119         if (e->button() == Qt::LeftButton)
120         {
121                 if (getStatus() == SetCorner2)
122                 {
123                         v2 = snapPoint(e);
124                         trigger();
125                 }
126         }
127         else if (e->button() == Qt::RightButton)
128         {
129                 if (getStatus() == SetCorner2)
130                         deletePreview();
131                 deleteSnapper();
132                 init(getStatus() - 1);
133         }
134 }
135
136 void RS_ActionSelectWindow::updateMouseButtonHints()
137 {
138         switch (getStatus())
139         {
140         case SetCorner1:
141                 RS_DIALOGFACTORY->updateMouseWidget(tr("Choose first edge"), tr("Cancel"));
142                 break;
143
144         case SetCorner2:
145                 RS_DIALOGFACTORY->updateMouseWidget(tr("Choose second edge"), tr("Back"));
146                 break;
147
148         default:
149                 RS_DIALOGFACTORY->updateMouseWidget("", "");
150                 break;
151         }
152 }
153
154 void RS_ActionSelectWindow::updateMouseCursor()
155 {
156         graphicView->setMouseCursor(RS2::SelectCursor);
157 }
158
159 void RS_ActionSelectWindow::updateToolBar()
160 {
161         if (!isFinished())
162                 //RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
163                 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSelect);
164         else
165                 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSelect);
166 }
167
168 // EOF