1 /****************************************************************************
2 ** $Id: rs_actiondrawimage.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_actiondrawimage.h"
29 #include "rs_creation.h"
31 #include "rs_modification.h"
36 RS_ActionDrawImage::RS_ActionDrawImage(RS_EntityContainer & container,
37 RS_GraphicView & graphicView):
38 RS_PreviewActionInterface("Image", container, graphicView)
42 RS_ActionDrawImage::~RS_ActionDrawImage()
46 QAction * RS_ActionDrawImage::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/)
48 QAction * action = new QAction(tr("&Image"), 0);
49 // QAction* action = new QAction(tr("Image"), tr("&Image"),
50 // QKeySequence(), NULL);
51 action->setStatusTip(tr("Insert Image (Bitmap)"));
55 void RS_ActionDrawImage::init(int status)
57 RS_PreviewActionInterface::init(status);
61 data.file = RS_DIALOGFACTORY->requestImageOpenDialog();
62 graphicView->redraw();
64 if (!data.file.isEmpty())
66 //std::cout << "file: " << data.file << "\n";
68 img = QImage(data.file);
69 setStatus(SetTargetPoint);
75 //RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
79 void RS_ActionDrawImage::reset()
81 data = RS_ImageData(0,
90 void RS_ActionDrawImage::trigger()
96 if (!data.file.isEmpty())
98 RS_Creation creation(container, graphicView);
99 creation.createImage(data);
102 graphicView->redraw();
103 //RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
108 void RS_ActionDrawImage::mouseMoveEvent(QMouseEvent * e)
113 data.insertionPoint = snapPoint(e);
117 //RS_Creation creation(preview, NULL, false);
118 //creation.createInsert(data);
120 line = new RS_Line(preview, RS_LineData(Vector(0, 0), Vector(img.width(), 0)));
121 preview->addEntity(line);
122 line = new RS_Line(preview,
123 RS_LineData(Vector(img.width(), 0), Vector(img.width(), img.height())));
124 preview->addEntity(line);
125 line = new RS_Line(preview,
126 RS_LineData(Vector(img.width(), img.height()), Vector(0, img.height())));
127 preview->addEntity(line);
128 line = new RS_Line(preview, RS_LineData(Vector(0, img.height()), Vector(0, 0)));
129 preview->addEntity(line);
130 preview->scale(Vector(0,0), Vector(data.uVector.magnitude(), data.uVector.magnitude()));
131 preview->rotate(Vector(0,0), data.uVector.angle());
132 preview->move(data.insertionPoint);
142 void RS_ActionDrawImage::mouseReleaseEvent(QMouseEvent * e)
144 if (RS2::qtToRsButtonState(e->button()) == RS2::LeftButton)
146 RS_CoordinateEvent ce(snapPoint(e));
147 coordinateEvent(&ce);
149 else if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton)
152 //init(getStatus()-1);
157 void RS_ActionDrawImage::coordinateEvent(RS_CoordinateEvent * e)
162 data.insertionPoint = e->getCoordinate();
166 void RS_ActionDrawImage::commandEvent(RS_CommandEvent * e)
168 QString c = e->getCommand().toLower();
170 if (checkCommand("help", c))
172 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
173 + getAvailableCommands().join(", "));
180 if (checkCommand("angle", c))
185 lastStatus = (Status)getStatus();
188 else if (checkCommand("factor", c))
193 lastStatus = (Status)getStatus();
194 setStatus(SetFactor);
201 double a = RS_Math::eval(c, &ok);
203 setAngle(RS_Math::deg2rad(a));
205 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
207 RS_DIALOGFACTORY->requestOptions(this, true, true);
208 setStatus(lastStatus);
215 double f = RS_Math::eval(c, &ok);
219 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
221 RS_DIALOGFACTORY->requestOptions(this, true, true);
222 setStatus(lastStatus);
231 QStringList RS_ActionDrawImage::getAvailableCommands()
238 cmd += command("angle");
239 cmd += command("factor");
248 void RS_ActionDrawImage::showOptions()
250 RS_ActionInterface::showOptions();
252 RS_DIALOGFACTORY->requestOptions(this, true);
255 void RS_ActionDrawImage::hideOptions()
257 RS_ActionInterface::hideOptions();
259 RS_DIALOGFACTORY->requestOptions(this, false);
262 void RS_ActionDrawImage::updateMouseButtonHints()
267 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify reference point"), tr("Cancel"));
270 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter angle:"), "");
273 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter factor:"), "");
276 RS_DIALOGFACTORY->updateMouseWidget("", "");
281 void RS_ActionDrawImage::updateMouseCursor()
283 graphicView->setMouseCursor(RS2::CadCursor);
286 void RS_ActionDrawImage::updateToolBar()
289 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
291 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);