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