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