1 /****************************************************************************
2 ** $Id: rs_actioneditpaste.cpp 1134 2004-07-13 23:26:13Z andrew $
4 ** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
6 ** This file is part of the qcadlib Library project.
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.
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.
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.
20 ** See http://www.ribbonsoft.com for further details.
22 ** Contact info@ribbonsoft.com if any conditions of this licensing are
25 **********************************************************************/
27 #include "rs_actioneditpaste.h"
29 #include "rs_clipboard.h"
30 #include "rs_modification.h"
36 * @param undo true for undo and false for redo.
38 RS_ActionEditPaste::RS_ActionEditPaste( RS_EntityContainer& container,
39 RS_GraphicView& graphicView)
40 :RS_PreviewActionInterface("Edit Paste",
41 container, graphicView)
45 RS_ActionEditPaste::~RS_ActionEditPaste()
49 QAction* RS_ActionEditPaste::createGUIAction(RS2::ActionType /*type*/, QObject* parent)
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"));
61 void RS_ActionEditPaste::init(int status)
63 RS_PreviewActionInterface::init(status);
67 void RS_ActionEditPaste::trigger()
73 RS_Modification m(*container, graphicView);
74 m.paste(RS_PasteData(targetPoint, 1.0, 0.0, false, ""));
75 //std::cout << *RS_Clipboard::instance();
77 graphicView->redraw();
82 void RS_ActionEditPaste::mouseMoveEvent(QMouseEvent* e) {
83 switch (getStatus()) {
85 targetPoint = snapPoint(e);
89 preview->addAllFrom(*RS_CLIPBOARD->getGraphic());
90 preview->move(targetPoint);
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));
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) {
120 void RS_ActionEditPaste::coordinateEvent(RS_CoordinateEvent* e) {
125 targetPoint = e->getCoordinate();
131 void RS_ActionEditPaste::updateMouseButtonHints() {
132 switch (getStatus()) {
134 RS_DIALOGFACTORY->updateMouseWidget(tr("Set reference point"),
138 RS_DIALOGFACTORY->updateMouseWidget("", "");
145 void RS_ActionEditPaste::updateMouseCursor() {
146 graphicView->setMouseCursor(RS2::CadCursor);
151 void RS_ActionEditPaste::updateToolBar() {
153 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
155 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);