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_commandevent.h"
18 #include "rs_creation.h"
19 #include "rs_dialogfactory.h"
20 #include "graphicview.h"
21 #include "rs_preview.h"
26 RS_ActionDrawImage::RS_ActionDrawImage(RS_EntityContainer & container, GraphicView & graphicView):
27 RS_PreviewActionInterface("Image", container, graphicView)
31 RS_ActionDrawImage::~RS_ActionDrawImage()
35 /*virtual*/ RS2::ActionType RS_ActionDrawImage::rtti()
37 return RS2::ActionDrawImage;
40 void RS_ActionDrawImage::init(int status)
42 RS_PreviewActionInterface::init(status);
46 data.file = RS_DIALOGFACTORY->requestImageOpenDialog();
47 graphicView->redraw();
49 if (!data.file.isEmpty())
51 //std::cout << "file: " << data.file << "\n";
53 img = QImage(data.file);
54 setStatus(SetTargetPoint);
60 //RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
64 void RS_ActionDrawImage::reset()
66 data = RS_ImageData(0,
75 void RS_ActionDrawImage::trigger()
81 if (!data.file.isEmpty())
83 RS_Creation creation(container, graphicView);
84 creation.createImage(data);
87 graphicView->redraw();
88 //RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
93 void RS_ActionDrawImage::mouseMoveEvent(QMouseEvent * e)
98 data.insertionPoint = snapPoint(e);
102 //RS_Creation creation(preview, NULL, false);
103 //creation.createInsert(data);
105 line = new RS_Line(preview, RS_LineData(Vector(0, 0), Vector(img.width(), 0)));
106 preview->addEntity(line);
107 line = new RS_Line(preview,
108 RS_LineData(Vector(img.width(), 0), Vector(img.width(), img.height())));
109 preview->addEntity(line);
110 line = new RS_Line(preview,
111 RS_LineData(Vector(img.width(), img.height()), Vector(0, img.height())));
112 preview->addEntity(line);
113 line = new RS_Line(preview, RS_LineData(Vector(0, img.height()), Vector(0, 0)));
114 preview->addEntity(line);
115 preview->scale(Vector(0, 0), Vector(data.uVector.magnitude(), data.uVector.magnitude()));
116 preview->rotate(Vector(0, 0), data.uVector.angle());
117 preview->move(data.insertionPoint);
127 void RS_ActionDrawImage::mouseReleaseEvent(QMouseEvent * e)
129 // if (e->button() == Qt::LeftButton)
130 if (e->button() == Qt::LeftButton)
132 Vector ce(snapPoint(e));
133 coordinateEvent(&ce);
135 // else if (e->button() == Qt::RightButton)
136 else if (e->button() == Qt::RightButton)
139 //init(getStatus()-1);
144 void RS_ActionDrawImage::coordinateEvent(Vector * e)
149 data.insertionPoint = *e;
153 void RS_ActionDrawImage::commandEvent(RS_CommandEvent * e)
155 QString c = e->getCommand().toLower();
157 if (checkCommand("help", c))
159 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
160 + getAvailableCommands().join(", "));
168 if (checkCommand("angle", c))
173 lastStatus = (Status)getStatus();
176 else if (checkCommand("factor", c))
181 lastStatus = (Status)getStatus();
182 setStatus(SetFactor);
189 double a = RS_Math::eval(c, &ok);
192 setAngle(RS_Math::deg2rad(a));
194 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
195 RS_DIALOGFACTORY->requestOptions(this, true, true);
196 setStatus(lastStatus);
203 double f = RS_Math::eval(c, &ok);
208 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
209 RS_DIALOGFACTORY->requestOptions(this, true, true);
210 setStatus(lastStatus);
219 QStringList RS_ActionDrawImage::getAvailableCommands()
226 cmd += command("angle");
227 cmd += command("factor");
237 void RS_ActionDrawImage::showOptions()
239 RS_ActionInterface::showOptions();
241 RS_DIALOGFACTORY->requestOptions(this, true);
244 void RS_ActionDrawImage::hideOptions()
246 RS_ActionInterface::hideOptions();
248 RS_DIALOGFACTORY->requestOptions(this, false);
251 void RS_ActionDrawImage::updateMouseButtonHints()
256 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify reference point"), tr("Cancel"));
260 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter angle:"), "");
264 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter factor:"), "");
268 RS_DIALOGFACTORY->updateMouseWidget("", "");
273 void RS_ActionDrawImage::updateMouseCursor()
275 graphicView->setMouseCursor(RS2::CadCursor);
278 void RS_ActionDrawImage::updateToolBar()
281 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
283 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
286 double RS_ActionDrawImage::getAngle()
288 return data.uVector.angle();
291 void RS_ActionDrawImage::setAngle(double a)
293 double l = data.uVector.magnitude();
294 data.uVector.setPolar(l, a);
295 data.vVector.setPolar(l, a + M_PI / 2);
298 double RS_ActionDrawImage::getFactor()
300 return data.uVector.magnitude();
303 void RS_ActionDrawImage::setFactor(double f)
305 double a = data.uVector.angle();
306 data.uVector.setPolar(f, a);
307 data.vVector.setPolar(f, a + M_PI / 2);