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