]> Shamusworld >> Repos - architektonas/blob - src/actions/rs_actioneditpaste.cpp
Initial import
[architektonas] / src / actions / rs_actioneditpaste.cpp
1 /****************************************************************************
2 ** $Id: rs_actioneditpaste.cpp 1134 2004-07-13 23:26:13Z andrew $
3 **
4 ** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
5 **
6 ** This file is part of the qcadlib Library project.
7 **
8 ** This file may be distributed and/or modified under the terms of the
9 ** GNU General Public License version 2 as published by the Free Software
10 ** Foundation and appearing in the file LICENSE.GPL included in the
11 ** packaging of this file.
12 **
13 ** Licensees holding valid qcadlib Professional Edition licenses may use
14 ** this file in accordance with the qcadlib Commercial License
15 ** Agreement provided with the Software.
16 **
17 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
18 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19 **
20 ** See http://www.ribbonsoft.com for further details.
21 **
22 ** Contact info@ribbonsoft.com if any conditions of this licensing are
23 ** not clear to you.
24 **
25 **********************************************************************/
26
27 #include "rs_actioneditpaste.h"
28
29 #include "rs_clipboard.h"
30 #include "rs_modification.h"
31 #include "rs_units.h"
32
33 /**
34  * Constructor.
35  *
36  * @param undo true for undo and false for redo.
37  */
38 RS_ActionEditPaste::RS_ActionEditPaste( RS_EntityContainer& container,
39                                         RS_GraphicView& graphicView)
40         :RS_PreviewActionInterface("Edit Paste",
41                            container, graphicView)
42 {
43 }
44
45 RS_ActionEditPaste::~RS_ActionEditPaste()
46 {
47 }
48
49 QAction* RS_ActionEditPaste::createGUIAction(RS2::ActionType /*type*/, QObject* parent)
50 {
51         //icon = QPixmap(editpaste_xpm);
52         QAction * action = new QAction(QIcon(":/res/editpaste2.png"), tr("&Paste"), parent);
53         action->setShortcut(Qt::CTRL + Qt::Key_V);
54 //      QAction* action = new QAction(tr("Paste"),
55 //                                                                      qPixmapFromMimeSource("editpaste2.png"), tr("&Paste"),
56 //                                                                      Qt::CTRL+Qt::Key_V, parent);
57         action->setStatusTip(tr("Pastes the clipboard contents"));
58         return action;
59 }
60
61 void RS_ActionEditPaste::init(int status)
62 {
63     RS_PreviewActionInterface::init(status);
64     //trigger();
65 }
66
67 void RS_ActionEditPaste::trigger()
68 {
69     deleteSnapper();
70     deletePreview();
71     clearPreview();
72
73     RS_Modification m(*container, graphicView);
74     m.paste(RS_PasteData(targetPoint, 1.0, 0.0, false, ""));
75     //std::cout << *RS_Clipboard::instance();
76
77     graphicView->redraw();
78     finish();
79 }
80
81
82 void RS_ActionEditPaste::mouseMoveEvent(QMouseEvent* e) {
83     switch (getStatus()) {
84     case SetTargetPoint:
85         targetPoint = snapPoint(e);
86
87         deletePreview();
88         clearPreview();
89         preview->addAllFrom(*RS_CLIPBOARD->getGraphic());
90         preview->move(targetPoint);
91
92                 if (graphic!=NULL) {
93                         RS2::Unit sourceUnit = RS_CLIPBOARD->getGraphic()->getUnit();
94                         RS2::Unit targetUnit = graphic->getUnit();
95                         double f = RS_Units::convert(1.0, sourceUnit, targetUnit);
96                 preview->scale(targetPoint, Vector(f,f));
97                 }
98         drawPreview();
99         break;
100
101     default:
102         break;
103     }
104 }
105
106
107
108 void RS_ActionEditPaste::mouseReleaseEvent(QMouseEvent* e) {
109     if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) {
110         RS_CoordinateEvent ce(snapPoint(e));
111         coordinateEvent(&ce);
112     } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) {
113         deleteSnapper();
114         init(getStatus()-1);
115     }
116 }
117
118
119
120 void RS_ActionEditPaste::coordinateEvent(RS_CoordinateEvent* e) {
121     if (e==NULL) {
122         return;
123     }
124
125     targetPoint = e->getCoordinate();
126     trigger();
127 }
128
129
130
131 void RS_ActionEditPaste::updateMouseButtonHints() {
132     switch (getStatus()) {
133     case SetTargetPoint:
134         RS_DIALOGFACTORY->updateMouseWidget(tr("Set reference point"),
135                                             tr("Cancel"));
136         break;
137     default:
138         RS_DIALOGFACTORY->updateMouseWidget("", "");
139         break;
140     }
141 }
142
143
144
145 void RS_ActionEditPaste::updateMouseCursor() {
146     graphicView->setMouseCursor(RS2::CadCursor);
147 }
148
149
150
151 void RS_ActionEditPaste::updateToolBar() {
152     if (!isFinished()) {
153         RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
154     } else {
155         RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
156     }
157 }
158
159
160 // EOF