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