]> Shamusworld >> Repos - architektonas/blob - src/actions/rs_actioneditpaste.cpp
40f3110b19831df128803df135a12eef97680ca9
[architektonas] / src / actions / rs_actioneditpaste.cpp
1 // rs_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 "rs_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 RS_ActionEditPaste::RS_ActionEditPaste(RS_EntityContainer & container, GraphicView & graphicView): RS_PreviewActionInterface("Edit Paste",
29                 container, graphicView)
30 {
31 }
32
33 RS_ActionEditPaste::~RS_ActionEditPaste()
34 {
35 }
36
37 void RS_ActionEditPaste::init(int status)
38 {
39         RS_PreviewActionInterface::init(status);
40         //trigger();
41 }
42
43 void RS_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         //std::cout << *RS_Clipboard::instance();
52
53         graphicView->redraw();
54         finish();
55 }
56
57 void RS_ActionEditPaste::mouseMoveEvent(QMouseEvent * e)
58 {
59         switch (getStatus())
60         {
61         case SetTargetPoint:
62                 targetPoint = snapPoint(e);
63
64                 deletePreview();
65                 clearPreview();
66                 preview->addAllFrom(*RS_CLIPBOARD->getGraphic());
67                 preview->move(targetPoint);
68
69                 if (graphic != NULL)
70                 {
71                         RS2::Unit sourceUnit = RS_CLIPBOARD->getGraphic()->getUnit();
72                         RS2::Unit targetUnit = graphic->getUnit();
73                         double f = RS_Units::convert(1.0, sourceUnit, targetUnit);
74                         preview->scale(targetPoint, Vector(f, f));
75                 }
76                 drawPreview();
77                 break;
78
79         default:
80                 break;
81         }
82 }
83
84 void RS_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 RS_ActionEditPaste::coordinateEvent(Vector * e)
99 {
100         if (e == NULL)
101                 return;
102
103         targetPoint = *e;
104         trigger();
105 }
106
107 void RS_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 RS_ActionEditPaste::updateMouseCursor()
123 {
124         graphicView->setMouseCursor(RS2::CadCursor);
125 }
126
127 void RS_ActionEditPaste::updateToolBar()
128 {
129         if (!isFinished())
130                 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
131         else
132                 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
133 }
134
135 // EOF