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