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