]> Shamusworld >> Repos - architektonas/blob - src/actions/actioneditcopy.cpp
Bugfixes related to removing Snapper class.
[architektonas] / src / actions / actioneditcopy.cpp
1 // actioneditcopy.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  05/22/2010  Added this text. :-)
15 //
16
17 #include "actioneditcopy.h"
18
19 #include "dialogfactory.h"
20 #include "modification.h"
21
22 /**
23  * Constructor.
24  *
25  * @param undo true for undo and false for redo.
26  */
27 ActionEditCopy::ActionEditCopy(bool copy, EntityContainer & container, GraphicView & graphicView):
28         ActionInterface("Edit Copy", container, graphicView)
29 {
30         this->copy = copy;
31 }
32
33 ActionEditCopy::~ActionEditCopy()
34 {
35 }
36
37 void ActionEditCopy::init(int status)
38 {
39         ActionInterface::init(status);
40 }
41
42 void ActionEditCopy::trigger()
43 {
44         deleteSnapper();
45
46         Modification m(*container, graphicView);
47         m.copy(referencePoint, !copy);
48
49         finish();
50         graphicView->killSelectActions();
51         DIALOGFACTORY->updateSelectionWidget(container->countSelected());
52 }
53
54 void ActionEditCopy::mouseMoveEvent(QMouseEvent * e)
55 {
56         snapPoint(e);
57 }
58
59 void ActionEditCopy::mouseReleaseEvent(QMouseEvent * e)
60 {
61         if (e->button() == Qt::LeftButton)
62         {
63                 Vector ce(snapPoint(e));
64                 coordinateEvent(&ce);
65         }
66         else if (e->button() == Qt::RightButton)
67         {
68                 deleteSnapper();
69                 init(getStatus() - 1);
70         }
71 }
72
73 void ActionEditCopy::coordinateEvent(Vector * e)
74 {
75         if (e == NULL)
76                 return;
77
78         referencePoint = *e;
79         trigger();
80 }
81
82 void ActionEditCopy::updateMouseButtonHints()
83 {
84         switch (getStatus())
85         {
86         case SetReferencePoint:
87                 DIALOGFACTORY->updateMouseWidget(tr("Specify reference point"),
88                         tr("Cancel"));
89                 break;
90
91         default:
92                 DIALOGFACTORY->updateMouseWidget("", "");
93                 break;
94         }
95 }
96
97 void ActionEditCopy::updateMouseCursor()
98 {
99         graphicView->setMouseCursor(RS2::CadCursor);
100 }
101
102 void ActionEditCopy::updateToolBar()
103 {
104         if (!isFinished())
105                 DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
106         else
107                 DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
108 }