]> Shamusworld >> Repos - architektonas/blob - src/actions/actionselectwindow.cpp
Bugfixes related to removing Snapper class.
[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 // Portions copyright (C) 2001-2003 RibbonSoft
7 // Copyright (C) 2010 Underground Software
8 // See the README and GPLv2 files for licensing and warranty information
9 //
10 // JLH = James L. Hammons <jlhamm@acm.org>
11 //
12 // Who  When        What
13 // ---  ----------  -----------------------------------------------------------
14 // JLH  05/22/2010  Added this text. :-)
15 //
16
17 #include "actionselectwindow.h"
18
19 #include "debug.h"
20 #include "dialogfactory.h"
21 #include "graphicview.h"
22 #include "selection.h"
23 #include "preview.h"
24
25 /**
26  * Constructor.
27  *
28  * @param select true: select window. false: deselect window
29  */
30 ActionSelectWindow::ActionSelectWindow(EntityContainer & container,
31         GraphicView & graphicView, bool select):
32         ActionInterface("Select Window", container, graphicView)
33 {
34         this->select = select;
35 }
36
37 ActionSelectWindow::~ActionSelectWindow()
38 {
39 }
40
41 /*virtual*/ RS2::ActionType ActionSelectWindow::rtti()
42 {
43         return RS2::ActionSelectWindow;
44 }
45
46 void ActionSelectWindow::init(int status)
47 {
48         ActionInterface::init(status);
49         v1 = v2 = Vector(false);
50 /*      snapMode = RS2::SnapFree;
51         snapRes = RS2::RestrictNothing;*/
52 }
53
54 void ActionSelectWindow::trigger()
55 {
56         ActionInterface::trigger();
57
58         if (v1.valid && v2.valid)
59         {
60                 if (graphicView->toGuiDX(v1.distanceTo(v2)) > 10)
61                 {
62                         deleteSnapper();
63                         bool cross = (v2.y > v1.y);
64                         Selection s(*container, graphicView);
65                         s.selectWindow(v1, v2, select, cross);
66                         DIALOGFACTORY->updateSelectionWidget(container->countSelected());
67                         init();
68                 }
69         }
70 }
71
72 void ActionSelectWindow::mouseMoveEvent(QMouseEvent * e)
73 {
74         if (getStatus() == SetCorner2 && v1.valid)
75         {
76                 v2 = snapPoint(e);
77                 deletePreview();
78                 clearPreview();
79 /*              preview->addEntity(new Line(preview,
80                                 LineData(Vector(v1.x, v1.y), Vector(v2.x, v1.y))));
81                 preview->addEntity(new Line(preview,
82                                 LineData(Vector(v2.x, v1.y), Vector(v2.x, v2.y))));
83                 preview->addEntity(new Line(preview,
84                                 LineData(Vector(v2.x, v2.y), Vector(v1.x, v2.y))));
85                 preview->addEntity(new Line(preview,
86                                 LineData(Vector(v1.x, v2.y), Vector(v1.x, v1.y))));*/
87                 drawPreview();
88         }
89 }
90
91 void ActionSelectWindow::mousePressEvent(QMouseEvent * e)
92 {
93         if (e->button() == Qt::LeftButton)
94         {
95                 switch (getStatus())
96                 {
97                 case SetCorner1:
98                         v1 = snapPoint(e);
99                         setStatus(SetCorner2);
100                         break;
101
102                 default:
103                         break;
104                 }
105         }
106
107         DEBUG->print("ActionSelectWindow::mousePressEvent(): %f %f",
108                 v1.x, v1.y);
109 }
110
111 void ActionSelectWindow::mouseReleaseEvent(QMouseEvent * e)
112 {
113         DEBUG->print("ActionSelectWindow::mouseReleaseEvent()");
114
115         if (e->button() == Qt::LeftButton)
116         {
117                 if (getStatus() == SetCorner2)
118                 {
119                         v2 = snapPoint(e);
120                         trigger();
121                 }
122         }
123         else if (e->button() == Qt::RightButton)
124         {
125                 if (getStatus() == SetCorner2)
126                         deletePreview();
127
128                 deleteSnapper();
129                 init(getStatus() - 1);
130         }
131 }
132
133 void ActionSelectWindow::updateMouseButtonHints()
134 {
135         switch (getStatus())
136         {
137         case SetCorner1:
138                 DIALOGFACTORY->updateMouseWidget(tr("Choose first edge"), tr("Cancel"));
139                 break;
140
141         case SetCorner2:
142                 DIALOGFACTORY->updateMouseWidget(tr("Choose second edge"), tr("Back"));
143                 break;
144
145         default:
146                 DIALOGFACTORY->updateMouseWidget("", "");
147                 break;
148         }
149 }
150
151 void ActionSelectWindow::updateMouseCursor()
152 {
153         graphicView->setMouseCursor(RS2::SelectCursor);
154 }
155
156 void ActionSelectWindow::updateToolBar()
157 {
158         if (!isFinished())
159                 DIALOGFACTORY->requestToolBar(RS2::ToolBarSelect);
160         else
161                 DIALOGFACTORY->requestToolBar(RS2::ToolBarSelect);
162 }