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_actioneditcopy.h"
28
29 #include <QAction>
30 #include <QMouseEvent>
31 #include "rs_dialogfactory.h"
32 #include "rs_graphicview.h"
33 #include "rs_modification.h"
34 #include "rs_coordinateevent.h"
35
36 /**
37 * Constructor.
38 *
39 * @param undo true for undo and false for redo.
40 */
RS_ActionEditCopy(bool copy,RS_EntityContainer & container,RS_GraphicView & graphicView)41 RS_ActionEditCopy::RS_ActionEditCopy(bool copy,
42 RS_EntityContainer& container,
43 RS_GraphicView& graphicView)
44 :RS_ActionInterface("Edit Copy",
45 container, graphicView)
46 , copy{copy}
47 , referencePoint{new RS_Vector{}}
48 {
49 }
50
51 RS_ActionEditCopy::~RS_ActionEditCopy() = default;
52
53
init(int status)54 void RS_ActionEditCopy::init(int status) {
55 RS_ActionInterface::init(status);
56 //trigger();
57 }
58
59
60
trigger()61 void RS_ActionEditCopy::trigger() {
62
63 RS_Modification m(*container, graphicView);
64 m.copy(*referencePoint, !copy);
65
66 //graphicView->redraw();
67 finish(false);
68 graphicView->killSelectActions();
69 //init(getStatus()-1);
70 RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected(),container->totalSelectedLength());
71 }
72
mouseMoveEvent(QMouseEvent * e)73 void RS_ActionEditCopy::mouseMoveEvent(QMouseEvent* e) {
74 if (getStatus()==SetReferencePoint)
75 (void) snapPoint(e);
76 else
77 deleteSnapper();
78 }
79
mouseReleaseEvent(QMouseEvent * e)80 void RS_ActionEditCopy::mouseReleaseEvent(QMouseEvent* e) {
81 if (e->button()==Qt::LeftButton) {
82 RS_CoordinateEvent ce(snapPoint(e));
83 coordinateEvent(&ce);
84 } else if (e->button()==Qt::RightButton) {
85 init(getStatus()-1);
86 }
87 }
88
89
90
coordinateEvent(RS_CoordinateEvent * e)91 void RS_ActionEditCopy::coordinateEvent(RS_CoordinateEvent* e) {
92 if (!e)
93 return;
94
95 *referencePoint = e->getCoordinate();
96 trigger();
97 }
98
99
100
updateMouseButtonHints()101 void RS_ActionEditCopy::updateMouseButtonHints() {
102 switch (getStatus()) {
103 case SetReferencePoint:
104 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify reference point"),
105 tr("Cancel"));
106 break;
107 default:
108 RS_DIALOGFACTORY->updateMouseWidget();
109 break;
110 }
111 }
112
113
114
updateMouseCursor()115 void RS_ActionEditCopy::updateMouseCursor() {
116 graphicView->setMouseCursor(RS2::CadCursor);
117 }
118
119 // EOF
120