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 "rs_actionmodifyscale.h"
28
29 #include <QAction>
30 #include <QMouseEvent>
31 #include "rs_dialogfactory.h"
32 #include "rs_graphicview.h"
33 #include "rs_coordinateevent.h"
34 #include "rs_modification.h"
35 #include "rs_preview.h"
36 #include "rs_debug.h"
37
38 struct RS_ActionModifyScale::Points {
39 RS_ScaleData data;
40 RS_Vector referencePoint;
41 };
42
RS_ActionModifyScale(RS_EntityContainer & container,RS_GraphicView & graphicView)43 RS_ActionModifyScale::RS_ActionModifyScale(RS_EntityContainer& container,
44 RS_GraphicView& graphicView)
45 :RS_PreviewActionInterface("Scale Entities",
46 container, graphicView)
47 , pPoints(new Points{})
48 {
49 actionType=RS2::ActionModifyScale;
50 }
51
52 RS_ActionModifyScale::~RS_ActionModifyScale() = default;
53
54
init(int status)55 void RS_ActionModifyScale::init(int status) {
56 RS_ActionInterface::init(status);
57
58 }
59
trigger()60 void RS_ActionModifyScale::trigger() {
61
62 RS_DEBUG->print("RS_ActionModifyScale::trigger()");
63 if(pPoints->data.factor.valid){
64 RS_Modification m(*container, graphicView);
65 m.scale(pPoints->data);
66
67 RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected(),container->totalSelectedLength());
68 }
69 }
70
71
72
mouseMoveEvent(QMouseEvent * e)73 void RS_ActionModifyScale::mouseMoveEvent(QMouseEvent* e) {
74 RS_DEBUG->print("RS_ActionModifyScale::mouseMoveEvent begin");
75
76 if (getStatus()==SetReferencePoint) {
77
78 RS_Vector mouse = snapPoint(e);
79 switch (getStatus()) {
80 case SetReferencePoint:
81 pPoints->referencePoint = mouse;
82 break;
83
84 default:
85 break;
86 }
87 }
88
89 RS_DEBUG->print("RS_ActionModifyScale::mouseMoveEvent end");
90 }
91
92
93
mouseReleaseEvent(QMouseEvent * e)94 void RS_ActionModifyScale::mouseReleaseEvent(QMouseEvent* e) {
95 if (e->button()==Qt::LeftButton) {
96 if (getStatus()== SetReferencePoint){
97 RS_CoordinateEvent ce(snapPoint(e));
98 coordinateEvent(&ce);
99 }
100 } else if (e->button()==Qt::RightButton) {
101 deletePreview();
102 init(getStatus()-1);
103 }
104 }
105
coordinateEvent(RS_CoordinateEvent * e)106 void RS_ActionModifyScale::coordinateEvent(RS_CoordinateEvent* e) {
107
108 if (e==NULL || getStatus() != SetReferencePoint) {
109 return;
110 }
111
112 RS_Vector mouse = e->getCoordinate();
113 setStatus(ShowDialog);
114 if (RS_DIALOGFACTORY->requestScaleDialog(pPoints->data)) {
115 pPoints->data.referencePoint = mouse;
116 trigger();
117 finish();
118 }
119 }
120
updateMouseButtonHints()121 void RS_ActionModifyScale::updateMouseButtonHints() {
122 switch (getStatus()) {
123 /*case Select:
124 RS_DIALOGFACTORY->updateMouseWidget(tr("Pick entities to scale"),
125 tr("Cancel"));
126 break;*/
127 case SetReferencePoint:
128 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify reference point"),
129 tr("Cancel"));
130 break;
131 default:
132 RS_DIALOGFACTORY->updateMouseWidget();
133 break;
134 }
135 }
136
137
138
updateMouseCursor()139 void RS_ActionModifyScale::updateMouseCursor() {
140 graphicView->setMouseCursor(RS2::CadCursor);
141 }
142
143 // EOF
144