1 /****************************************************************************
2 **
3 ** This file is part of the LibreCAD project, a 2D CAD program
4 **
5 ** Copyright (C) 2010 R. van Twisk (librecad@rvt.dds.nl)
6 ** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
7 **
8 **
9 ** This file may be distributed and/or modified under the terms of the
10 ** GNU General Public License version 2 as published by the Free Software
11 ** Foundation and appearing in the file gpl-2.0.txt included in the
12 ** packaging of this file.
13 **
14 ** This program is distributed in the hope that it will be useful,
15 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ** GNU General Public License for more details.
18 **
19 ** You should have received a copy of the GNU General Public License
20 ** along with this program; if not, write to the Free Software
21 ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 **
23 ** This copyright notice MUST APPEAR in all copies of the script!
24 **
25 **********************************************************************/
26
27 #include <QAction>
28 #include <QMouseEvent>
29 #include "rs_actioninfodist2.h"
30
31 #include "rs_dialogfactory.h"
32 #include "rs_graphicview.h"
33 #include "rs_graphic.h"
34 #include "rs_coordinateevent.h"
35 #include "rs_debug.h"
36
37
RS_ActionInfoDist2(RS_EntityContainer & container,RS_GraphicView & graphicView)38 RS_ActionInfoDist2::RS_ActionInfoDist2(RS_EntityContainer& container,
39 RS_GraphicView& graphicView)
40 :RS_PreviewActionInterface("Info Dist2",
41 container, graphicView)
42 ,entity(nullptr)
43 ,point(new RS_Vector{})
44 {
45 actionType=RS2::ActionInfoDist2;
46 }
47
~RS_ActionInfoDist2()48 RS_ActionInfoDist2::~RS_ActionInfoDist2() {
49 if(graphicView != NULL && graphicView->isCleanUp()==false){
50 if( entity && entity->isHighlighted()){
51 entity->setHighlighted(false);
52 graphicView->redraw(RS2::RedrawDrawing);
53 }
54 }
55 }
56
init(int status)57 void RS_ActionInfoDist2::init(int status) {
58 RS_ActionInterface::init(status);
59 }
60
61
62
trigger()63 void RS_ActionInfoDist2::trigger() {
64
65 RS_DEBUG->print("RS_ActionInfoDist2::trigger()");
66
67 if (point->valid && entity) {
68 double dist = entity->getDistanceToPoint(*point);
69 QString str = RS_Units::formatLinear(dist, graphic->getUnit(),
70 graphic->getLinearFormat(), graphic->getLinearPrecision());
71 RS_DIALOGFACTORY->commandMessage(tr("Distance: %1").arg(str));
72 entity->setHighlighted(false);
73 graphicView->redraw(RS2::RedrawDrawing);
74 }
75 }
76
77
78
mouseMoveEvent(QMouseEvent * e)79 void RS_ActionInfoDist2::mouseMoveEvent(QMouseEvent* e) {
80 RS_DEBUG->print("RS_ActionInfoDist2::mouseMoveEvent begin");
81
82 switch (getStatus()) {
83 case SetEntity:
84 suspend();
85 //entity = catchEntity(e);
86 deleteSnapper();
87 break;
88
89 case SetPoint:
90 if (entity) {
91 RS_Vector&& mouse=snapPoint(e);
92 *point = mouse;
93 }
94 break;
95
96 default:
97 break;
98 }
99
100 RS_DEBUG->print("RS_ActionInfoDist2::mouseMoveEvent end");
101 }
102
103
104
mouseReleaseEvent(QMouseEvent * e)105 void RS_ActionInfoDist2::mouseReleaseEvent(QMouseEvent* e) {
106 if (e->button()==Qt::LeftButton) {
107
108 switch (getStatus()) {
109 case SetEntity:
110 entity = catchEntity(e);
111 if (entity) {
112 entity->setHighlighted(true);
113 graphicView->redraw(RS2::RedrawDrawing);
114 setStatus(SetPoint);
115 }
116 break;
117
118 case SetPoint: {
119 RS_CoordinateEvent ce(snapPoint(e));
120 coordinateEvent(&ce);
121 }
122 break;
123
124 default:
125 break;
126 }
127 } else if (e->button()==Qt::RightButton) {
128 deletePreview();
129 init(getStatus()-1);
130 }
131 }
132
133
coordinateEvent(RS_CoordinateEvent * e)134 void RS_ActionInfoDist2::coordinateEvent(RS_CoordinateEvent* e) {
135 if (e==NULL) {
136 return;
137 }
138
139 if (getStatus()==SetPoint && entity) {
140 *point = e->getCoordinate();
141 graphicView->moveRelativeZero(*point);
142 trigger();
143 setStatus(SetEntity);
144 }
145 }
146
147
148
updateMouseButtonHints()149 void RS_ActionInfoDist2::updateMouseButtonHints() {
150 switch (getStatus()) {
151 case SetEntity:
152 RS_DIALOGFACTORY->updateMouseWidget(
153 tr("Specify entity"),
154 tr("Cancel"));
155 break;
156 case SetPoint:
157 RS_DIALOGFACTORY->updateMouseWidget(
158 tr("Specify point"),
159 tr("Back"));
160 break;
161 default:
162 RS_DIALOGFACTORY->updateMouseWidget();
163 break;
164 }
165 }
166
167
168
updateMouseCursor()169 void RS_ActionInfoDist2::updateMouseCursor() {
170 graphicView->setMouseCursor(RS2::CadCursor);
171 }
172
173 // EOF
174