1 // rs_actiondrawimage.cpp
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
8 // JLH = James L. Hammons <jlhamm@acm.org>
11 // --- ---------- -----------------------------------------------------------
12 // JLH 05/22/2010 Added this text. :-)
15 #include "rs_actiondrawimage.h"
17 #include "rs_creation.h"
18 #include "rs_dialogfactory.h"
19 #include "rs_graphicview.h"
20 #include "rs_preview.h"
25 RS_ActionDrawImage::RS_ActionDrawImage(RS_EntityContainer & container, RS_GraphicView & graphicView):
26 RS_PreviewActionInterface("Image", container, graphicView)
30 RS_ActionDrawImage::~RS_ActionDrawImage()
34 /*virtual*/ RS2::ActionType RS_ActionDrawImage::rtti()
36 return RS2::ActionDrawImage;
39 void RS_ActionDrawImage::init(int status)
41 RS_PreviewActionInterface::init(status);
45 data.file = RS_DIALOGFACTORY->requestImageOpenDialog();
46 graphicView->redraw();
48 if (!data.file.isEmpty())
50 //std::cout << "file: " << data.file << "\n";
52 img = QImage(data.file);
53 setStatus(SetTargetPoint);
59 //RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
63 void RS_ActionDrawImage::reset()
65 data = RS_ImageData(0,
74 void RS_ActionDrawImage::trigger()
80 if (!data.file.isEmpty())
82 RS_Creation creation(container, graphicView);
83 creation.createImage(data);
86 graphicView->redraw();
87 //RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
92 void RS_ActionDrawImage::mouseMoveEvent(QMouseEvent * e)
97 data.insertionPoint = snapPoint(e);
101 //RS_Creation creation(preview, NULL, false);
102 //creation.createInsert(data);
104 line = new RS_Line(preview, RS_LineData(Vector(0, 0), Vector(img.width(), 0)));
105 preview->addEntity(line);
106 line = new RS_Line(preview,
107 RS_LineData(Vector(img.width(), 0), Vector(img.width(), img.height())));
108 preview->addEntity(line);
109 line = new RS_Line(preview,
110 RS_LineData(Vector(img.width(), img.height()), Vector(0, img.height())));
111 preview->addEntity(line);
112 line = new RS_Line(preview, RS_LineData(Vector(0, img.height()), Vector(0, 0)));
113 preview->addEntity(line);
114 preview->scale(Vector(0, 0), Vector(data.uVector.magnitude(), data.uVector.magnitude()));
115 preview->rotate(Vector(0, 0), data.uVector.angle());
116 preview->move(data.insertionPoint);
126 void RS_ActionDrawImage::mouseReleaseEvent(QMouseEvent * e)
128 // if (RS2::qtToRsButtonState(e->button()) == RS2::LeftButton)
129 if (e->button() == Qt::LeftButton)
131 Vector ce(snapPoint(e));
132 coordinateEvent(&ce);
134 // else if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton)
135 else if (e->button() == Qt::RightButton)
138 //init(getStatus()-1);
143 void RS_ActionDrawImage::coordinateEvent(Vector * e)
148 data.insertionPoint = *e;
152 void RS_ActionDrawImage::commandEvent(RS_CommandEvent * e)
154 QString c = e->getCommand().toLower();
156 if (checkCommand("help", c))
158 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
159 + getAvailableCommands().join(", "));
167 if (checkCommand("angle", c))
172 lastStatus = (Status)getStatus();
175 else if (checkCommand("factor", c))
180 lastStatus = (Status)getStatus();
181 setStatus(SetFactor);
188 double a = RS_Math::eval(c, &ok);
191 setAngle(RS_Math::deg2rad(a));
193 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
194 RS_DIALOGFACTORY->requestOptions(this, true, true);
195 setStatus(lastStatus);
202 double f = RS_Math::eval(c, &ok);
207 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
208 RS_DIALOGFACTORY->requestOptions(this, true, true);
209 setStatus(lastStatus);
218 QStringList RS_ActionDrawImage::getAvailableCommands()
225 cmd += command("angle");
226 cmd += command("factor");
236 void RS_ActionDrawImage::showOptions()
238 RS_ActionInterface::showOptions();
240 RS_DIALOGFACTORY->requestOptions(this, true);
243 void RS_ActionDrawImage::hideOptions()
245 RS_ActionInterface::hideOptions();
247 RS_DIALOGFACTORY->requestOptions(this, false);
250 void RS_ActionDrawImage::updateMouseButtonHints()
255 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify reference point"), tr("Cancel"));
259 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter angle:"), "");
263 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter factor:"), "");
267 RS_DIALOGFACTORY->updateMouseWidget("", "");
272 void RS_ActionDrawImage::updateMouseCursor()
274 graphicView->setMouseCursor(RS2::CadCursor);
277 void RS_ActionDrawImage::updateToolBar()
280 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
282 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
285 double RS_ActionDrawImage::getAngle()
287 return data.uVector.angle();
290 void RS_ActionDrawImage::setAngle(double a)
292 double l = data.uVector.magnitude();
293 data.uVector.setPolar(l, a);
294 data.vVector.setPolar(l, a + M_PI / 2);
297 double RS_ActionDrawImage::getFactor()
299 return data.uVector.magnitude();
302 void RS_ActionDrawImage::setFactor(double f)
304 double a = data.uVector.angle();
305 data.uVector.setPolar(f, a);
306 data.vVector.setPolar(f, a + M_PI / 2);