]> Shamusworld >> Repos - architektonas/blob - src/actions/actioninfodist2.cpp
Bugfixes related to removing Snapper class.
[architektonas] / src / actions / actioninfodist2.cpp
1 // actioninfodist2.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  06/04/2010  Added this text. :-)
15 //
16
17 #include "actioninfodist2.h"
18
19 #include "debug.h"
20 #include "dialogfactory.h"
21 #include "graphicview.h"
22 #include "preview.h"
23
24 ActionInfoDist2::ActionInfoDist2(EntityContainer & container, GraphicView & graphicView):
25         ActionInterface("Info Dist2", container, graphicView)
26 {
27 }
28
29 ActionInfoDist2::~ActionInfoDist2()
30 {
31 }
32
33 void ActionInfoDist2::init(int status)
34 {
35         ActionInterface::init(status);
36 }
37
38 void ActionInfoDist2::trigger()
39 {
40         DEBUG->print("ActionInfoDist2::trigger()");
41         deleteSnapper();
42
43         if (point.valid && entity != NULL)
44         {
45                 double dist = entity->getDistanceToPoint(point);
46                 QString str;
47                 str.sprintf("%.6f", dist);
48                 DIALOGFACTORY->commandMessage(tr("Distance: %1").arg(str));
49         }
50 }
51
52 void ActionInfoDist2::mouseMoveEvent(QMouseEvent * e)
53 {
54         DEBUG->print("ActionInfoDist2::mouseMoveEvent begin");
55
56         switch (getStatus())
57         {
58         case SetEntity:
59                 //entity = catchEntity(e);
60                 break;
61
62         case SetPoint:
63                 if (entity != NULL)
64                         point = snapPoint(e);
65
66                 break;
67
68         default:
69                 break;
70         }
71
72         DEBUG->print("ActionInfoDist2::mouseMoveEvent end");
73 }
74
75 void ActionInfoDist2::mouseReleaseEvent(QMouseEvent * e)
76 {
77         if (e->button() == Qt::LeftButton)
78         {
79                 switch (getStatus())
80                 {
81                 case SetEntity:
82                         entity = catchEntity(e);
83
84                         if (entity != NULL)
85                                 setStatus(SetPoint);
86                         break;
87
88                 case SetPoint:
89                 {
90                         Vector ce(snapPoint(e));
91                         coordinateEvent(&ce);
92                 }
93                         break;
94
95                 default:
96                         break;
97                 }
98         }
99         else if (e->button() == Qt::RightButton)
100         {
101                 deletePreview();
102                 deleteSnapper();
103                 init(getStatus() - 1);
104         }
105 }
106
107 void ActionInfoDist2::coordinateEvent(Vector * e)
108 {
109         if (e == NULL)
110                 return;
111
112         if (getStatus() == SetPoint && entity != NULL)
113         {
114                 point = *e;
115                 graphicView->moveRelativeZero(point);
116                 trigger();
117                 setStatus(SetEntity);
118         }
119 }
120
121 void ActionInfoDist2::updateMouseButtonHints()
122 {
123         switch (getStatus())
124         {
125         case SetEntity:
126                 DIALOGFACTORY->updateMouseWidget(tr("Specify entity"), tr("Cancel"));
127                 break;
128
129         case SetPoint:
130                 DIALOGFACTORY->updateMouseWidget(tr("Specify point"), tr("Back"));
131                 break;
132
133         default:
134                 DIALOGFACTORY->updateMouseWidget("", "");
135                 break;
136         }
137 }
138
139 void ActionInfoDist2::updateMouseCursor()
140 {
141         graphicView->setMouseCursor(RS2::CadCursor);
142 }
143
144 void ActionInfoDist2::updateToolBar()
145 {
146         switch (getStatus())
147         {
148         case SetPoint:
149         case SetEntity:
150                 DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
151                 break;
152
153         default:
154                 DIALOGFACTORY->requestToolBar(RS2::ToolBarInfo);
155                 break;
156         }
157 }