]> Shamusworld >> Repos - architektonas/blob - src/actions/actioneditpaste.cpp
7d4ac423bdcc96dfa9bc897fffb720d4641bccfe
[architektonas] / src / actions / actioneditpaste.cpp
1 // actioneditpaste.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  06/04/2010  Added this text. :-)
13 //
14
15 #include "actioneditpaste.h"
16
17 #include "rs_clipboard.h"
18 #include "rs_dialogfactory.h"
19 #include "rs_modification.h"
20 #include "rs_preview.h"
21 #include "rs_units.h"
22
23 /**
24  * Constructor.
25  *
26  * @param undo true for undo and false for redo.
27  */
28 ActionEditPaste::ActionEditPaste(RS_EntityContainer & container, GraphicView & graphicView): ActionInterface("Edit Paste",
29                 container, graphicView)
30 {
31 }
32
33 ActionEditPaste::~ActionEditPaste()
34 {
35 }
36
37 void ActionEditPaste::init(int status)
38 {
39         ActionInterface::init(status);
40         //trigger();
41 }
42
43 void ActionEditPaste::trigger()
44 {
45         deleteSnapper();
46         deletePreview();
47         clearPreview();
48
49         RS_Modification m(*container, graphicView);
50         m.paste(RS_PasteData(targetPoint, 1.0, 0.0, false, ""));
51
52         graphicView->redraw();
53         finish();
54 }
55
56 void ActionEditPaste::mouseMoveEvent(QMouseEvent * e)
57 {
58         switch (getStatus())
59         {
60         case SetTargetPoint:
61                 targetPoint = snapPoint(e);
62
63                 deletePreview();
64                 clearPreview();
65 //              preview->addAllFrom(*RS_CLIPBOARD->getGraphic());
66 //              preview->move(targetPoint);
67
68                 if (graphic)
69                 {
70                         RS2::Unit sourceUnit = RS_CLIPBOARD->getGraphic()->getUnit();
71                         RS2::Unit targetUnit = graphic->getUnit();
72                         double f = RS_Units::convert(1.0, sourceUnit, targetUnit);
73 //                      preview->scale(targetPoint, Vector(f, f));
74                 }
75
76                 drawPreview();
77                 break;
78
79         default:
80                 break;
81         }
82 }
83
84 void ActionEditPaste::mouseReleaseEvent(QMouseEvent * e)
85 {
86         if (e->button() == Qt::LeftButton)
87         {
88                 Vector ce(snapPoint(e));
89                 coordinateEvent(&ce);
90         }
91         else if (e->button() == Qt::RightButton)
92         {
93                 deleteSnapper();
94                 init(getStatus() - 1);
95         }
96 }
97
98 void ActionEditPaste::coordinateEvent(Vector * e)
99 {
100         if (e == NULL)
101                 return;
102
103         targetPoint = *e;
104         trigger();
105 }
106
107 void ActionEditPaste::updateMouseButtonHints()
108 {
109         switch (getStatus())
110         {
111         case SetTargetPoint:
112                 RS_DIALOGFACTORY->updateMouseWidget(tr("Set reference point"),
113                         tr("Cancel"));
114                 break;
115
116         default:
117                 RS_DIALOGFACTORY->updateMouseWidget("", "");
118                 break;
119         }
120 }
121
122 void ActionEditPaste::updateMouseCursor()
123 {
124         graphicView->setMouseCursor(RS2::CadCursor);
125 }
126
127 void ActionEditPaste::updateToolBar()
128 {
129         if (!isFinished())
130                 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
131         else
132                 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
133 }