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 // Portions copyright (C) 2001-2003 RibbonSoft
7 // Copyright (C) 2010 Underground Software
8 // See the README and GPLv2 files for licensing and warranty information
10 // JLH = James L. Hammons <jlhamm@acm.org>
13 // --- ---------- -----------------------------------------------------------
14 // JLH 05/22/2010 Added this text. :-)
17 #include "actiondrawimage.h"
19 #include "commandevent.h"
21 #include "dialogfactory.h"
22 #include "graphicview.h"
28 ActionDrawImage::ActionDrawImage(EntityContainer & container, GraphicView & graphicView):
29 ActionInterface("Image", container, graphicView)
33 ActionDrawImage::~ActionDrawImage()
37 /*virtual*/ RS2::ActionType ActionDrawImage::rtti()
39 return RS2::ActionDrawImage;
42 void ActionDrawImage::init(int status)
44 ActionInterface::init(status);
48 data.file = DIALOGFACTORY->requestImageOpenDialog();
49 graphicView->redraw();
51 if (!data.file.isEmpty())
53 //std::cout << "file: " << data.file << "\n";
55 img = QImage(data.file);
56 setStatus(SetTargetPoint);
62 //DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
66 void ActionDrawImage::reset()
77 void ActionDrawImage::trigger()
83 if (!data.file.isEmpty())
85 Creation creation(container, graphicView);
86 creation.createImage(data);
89 graphicView->redraw();
94 void ActionDrawImage::mouseMoveEvent(QMouseEvent * e)
99 data.insertionPoint = snapPoint(e);
104 // line = new Line(preview, LineData(Vector(0, 0), Vector(img.width(), 0)));
105 // preview->addEntity(line);
106 // line = new Line(preview,
107 // LineData(Vector(img.width(), 0), Vector(img.width(), img.height())));
108 // preview->addEntity(line);
109 // line = new Line(preview,
110 // LineData(Vector(img.width(), img.height()), Vector(0, img.height())));
111 // preview->addEntity(line);
112 // line = new Line(preview, 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 ActionDrawImage::mouseReleaseEvent(QMouseEvent * e)
128 if (e->button() == Qt::LeftButton)
130 Vector ce(snapPoint(e));
131 coordinateEvent(&ce);
133 else if (e->button() == Qt::RightButton)
140 void ActionDrawImage::coordinateEvent(Vector * e)
145 data.insertionPoint = *e;
149 void ActionDrawImage::commandEvent(CommandEvent * e)
151 QString c = e->getCommand().toLower();
153 if (checkCommand("help", c))
155 DIALOGFACTORY->commandMessage(msgAvailableCommands()
156 + getAvailableCommands().join(", "));
164 if (checkCommand("angle", c))
169 lastStatus = (Status)getStatus();
172 else if (checkCommand("factor", c))
177 lastStatus = (Status)getStatus();
178 setStatus(SetFactor);
185 double a = Math::eval(c, &ok);
188 setAngle(Math::deg2rad(a));
190 DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
192 DIALOGFACTORY->requestOptions(this, true, true);
193 setStatus(lastStatus);
200 double f = Math::eval(c, &ok);
205 DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
207 DIALOGFACTORY->requestOptions(this, true, true);
208 setStatus(lastStatus);
217 QStringList ActionDrawImage::getAvailableCommands()
224 cmd += command("angle");
225 cmd += command("factor");
235 void ActionDrawImage::showOptions()
237 ActionInterface::showOptions();
239 DIALOGFACTORY->requestOptions(this, true);
242 void ActionDrawImage::hideOptions()
244 ActionInterface::hideOptions();
246 DIALOGFACTORY->requestOptions(this, false);
249 void ActionDrawImage::updateMouseButtonHints()
254 DIALOGFACTORY->updateMouseWidget(tr("Specify reference point"), tr("Cancel"));
258 DIALOGFACTORY->updateMouseWidget(tr("Enter angle:"), "");
262 DIALOGFACTORY->updateMouseWidget(tr("Enter factor:"), "");
266 DIALOGFACTORY->updateMouseWidget("", "");
271 void ActionDrawImage::updateMouseCursor()
273 graphicView->setMouseCursor(RS2::CadCursor);
276 void ActionDrawImage::updateToolBar()
279 DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
281 DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
284 double ActionDrawImage::getAngle()
286 return data.uVector.angle();
289 void ActionDrawImage::setAngle(double a)
291 double l = data.uVector.magnitude();
292 data.uVector.setPolar(l, a);
293 data.vVector.setPolar(l, a + M_PI / 2);
296 double ActionDrawImage::getFactor()
298 return data.uVector.magnitude();
301 void ActionDrawImage::setFactor(double f)
303 double a = data.uVector.angle();
304 data.uVector.setPolar(f, a);
305 data.vVector.setPolar(f, a + M_PI / 2);