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