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/28/2010 Added this text. :-)
15 // JLH 05/28/2010 Fixed crashing bug when right-clicking out of a text
19 #include "actiondrawtext.h"
21 #include "commandevent.h"
23 #include "dialogfactory.h"
24 #include "graphicview.h"
27 ActionDrawText::ActionDrawText(EntityContainer & container, GraphicView & graphicView): ActionInterface("Draw Text", container, graphicView)
33 ActionDrawText::~ActionDrawText()
37 /*virtual*/ RS2::ActionType ActionDrawText::rtti()
39 return RS2::ActionDrawText;
42 void ActionDrawText::init(int status)
44 ActionInterface::init(status);
46 if (DIALOGFACTORY == NULL)
58 if (DIALOGFACTORY->requestTextDialog(&tmp))
62 // preview->setVisible(false);
73 graphicView->redraw();
78 DIALOGFACTORY->requestOptions(this, true, true);
86 void ActionDrawText::reset()
88 data = TextData(Vector(0.0, 0.0), 1.0, 100.0, RS2::VAlignTop,
89 RS2::HAlignLeft, RS2::LeftToRight, RS2::Exact, 1.0, data.text,
90 "standard", 0.0, RS2::Update);
93 void ActionDrawText::trigger()
95 DEBUG->print("ActionDrawText::trigger()");
99 //removing *this* causes previews not to be drawn correctly...
104 Text * text = new Text(container, data);
106 container->addEntity(text);
110 document->startUndoCycle();
111 document->addUndoable(text);
112 document->endUndoCycle();
116 // graphicView->drawEntity(text);
123 void ActionDrawText::preparePreview()
126 data.insertionPoint = Vector(0.0, 0.0);
127 Text * text = new Text(preview, data);
129 preview->addEntity(text);
130 textChanged = false;*/
133 void ActionDrawText::mouseMoveEvent(QMouseEvent * e)
135 DEBUG->print("ActionDrawText::mouseMoveEvent begin");
137 if (getStatus() == SetPos)
139 Vector mouse = snapPoint(e);
142 //without this, nothing is shown...
143 //Which shows that the preview rendering pipeline is seriously fucked up.
144 //Need to fix this shit!
150 // if (!preview->isVisible())
151 // preview->setVisible(true);
153 // offset = Vector(graphicView->toGuiDX(pos.x), -graphicView->toGuiDY(pos.y));
157 DEBUG->print("ActionDrawText::mouseMoveEvent end");
160 void ActionDrawText::mouseReleaseEvent(QMouseEvent * e)
162 if (e->button() == Qt::LeftButton)
164 Vector ce(snapPoint(e));
165 coordinateEvent(&ce);
167 else if (e->button() == Qt::RightButton)
169 // The problem is that even though the preview entity has been deleted, the rendering
170 // pipeline still thinks it's valid (because it's not NULL).
173 //init(getStatus()-1);
174 //Clear the preview entity so something else doesn't try to draw it after it's
175 //been deleted, then redraw the graphicView...
177 graphicView->redraw();
182 void ActionDrawText::coordinateEvent(Vector * e)
195 data.insertionPoint = mouse;
204 void ActionDrawText::commandEvent(CommandEvent * e)
206 QString c = e->getCommand().toLower();
208 if (checkCommand("help", c))
210 if (DIALOGFACTORY != NULL)
211 DIALOGFACTORY->commandMessage(msgAvailableCommands()
212 + getAvailableCommands().join(", "));
220 if (checkCommand("text", c))
225 graphicView->disableCoordinateInput();
232 setText(e->getCommand());
235 DIALOGFACTORY->requestOptions(this, true, true);
237 graphicView->enableCoordinateInput();
246 QStringList ActionDrawText::getAvailableCommands()
250 if (getStatus() == SetPos)
251 cmd += command("text");
256 void ActionDrawText::showOptions()
258 ActionInterface::showOptions();
261 DIALOGFACTORY->requestOptions(this, true, true);
264 void ActionDrawText::hideOptions()
266 ActionInterface::hideOptions();
269 DIALOGFACTORY->requestOptions(this, false);
272 void ActionDrawText::updateMouseButtonHints()
280 DIALOGFACTORY->updateMouseWidget(tr("Specify insertion point"), tr("Cancel"));
284 DIALOGFACTORY->updateMouseWidget(tr("Enter text:"), tr("Back"));
288 DIALOGFACTORY->updateMouseWidget("", "");
293 void ActionDrawText::updateMouseCursor()
295 graphicView->setMouseCursor(RS2::CadCursor);
298 void ActionDrawText::updateToolBar()
306 DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
310 DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
315 void ActionDrawText::setText(const QString & t)
321 QString ActionDrawText::getText()
326 void ActionDrawText::setAngle(double a)
332 double ActionDrawText::getAngle()