]> Shamusworld >> Repos - architektonas/blob - src/actions/rs_actioneditcopy.cpp
Initial import
[architektonas] / src / actions / rs_actioneditcopy.cpp
1 // rs_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 "rs_actioneditcopy.h"
16
17 #include "rs_modification.h"
18
19 /**
20  * Constructor.
21  *
22  * @param undo true for undo and false for redo.
23  */
24 RS_ActionEditCopy::RS_ActionEditCopy(bool copy,
25         RS_EntityContainer& container, RS_GraphicView& graphicView):
26         RS_ActionInterface("Edit Copy", container, graphicView)
27 {
28     this->copy = copy;
29 }
30
31 RS_ActionEditCopy::~RS_ActionEditCopy()
32 {
33 }
34
35 QAction * RS_ActionEditCopy::createGUIAction(RS2::ActionType type, QObject * parent)
36 {
37         QAction * action;
38
39         if (type == RS2::ActionEditCopy)
40         {
41                 //QPixmap icon = QPixmap(editcopy_xpm);
42                 action = new QAction(QIcon(":/res/editcopy2.png"), tr("&Copy"), parent);
43                 action->setShortcut(Qt::CTRL + Qt::Key_C);
44 //              action = new QAction(tr("Copy"), QPixmap::fromMimeSource("editcopy2.png"), tr("&Copy"),
45 //                                                              CTRL+Key_C, parent);
46                 action->setStatusTip(tr("Copies entities to the clipboard"));
47         }
48         else
49         {
50                 //icon = QPixmap(editcut_xpm);
51                 action = new QAction(QIcon(":/res/editcut2.png"), tr("Cu&t"), parent);
52                 action->setShortcut(Qt::CTRL + Qt::Key_X);
53 //              action = new QAction(tr("Cut"), QPixmap::fromMimeSource("editcut2.png"), tr("Cu&t"),
54 //                                                              CTRL+Key_X, parent);
55                 action->setStatusTip(tr("Cuts entities to the clipboard"));
56         }
57
58         return action;
59 }
60
61 void RS_ActionEditCopy::init(int status)
62 {
63     RS_ActionInterface::init(status);
64     //trigger();
65 }
66
67
68
69 void RS_ActionEditCopy::trigger() {
70
71     deleteSnapper();
72
73     RS_Modification m(*container, graphicView);
74     m.copy(referencePoint, !copy);
75
76     //graphicView->redraw();
77     finish();
78     graphicView->killSelectActions();
79     //init(getStatus()-1);
80     RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
81 }
82
83
84 void RS_ActionEditCopy::mouseMoveEvent(QMouseEvent* e) {
85     snapPoint(e);
86 }
87
88
89
90 void RS_ActionEditCopy::mouseReleaseEvent(QMouseEvent* e) {
91     if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) {
92         RS_CoordinateEvent ce(snapPoint(e));
93         coordinateEvent(&ce);
94     } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) {
95         deleteSnapper();
96         init(getStatus()-1);
97     }
98 }
99
100
101
102 void RS_ActionEditCopy::coordinateEvent(RS_CoordinateEvent* e) {
103     if (e==NULL) {
104         return;
105     }
106
107     referencePoint = e->getCoordinate();
108     trigger();
109 }
110
111
112
113 void RS_ActionEditCopy::updateMouseButtonHints() {
114     switch (getStatus()) {
115     case SetReferencePoint:
116         RS_DIALOGFACTORY->updateMouseWidget(tr("Specify reference point"),
117                                             tr("Cancel"));
118         break;
119     default:
120         RS_DIALOGFACTORY->updateMouseWidget("", "");
121         break;
122     }
123 }
124
125
126
127 void RS_ActionEditCopy::updateMouseCursor() {
128     graphicView->setMouseCursor(RS2::CadCursor);
129 }
130
131
132
133 void RS_ActionEditCopy::updateToolBar() {
134     if (!isFinished()) {
135         RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
136     } else {
137         RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
138     }
139 }
140
141
142 // EOF