1 // rs_actiondrawtext.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/28/2010 Added this text. :-)
13 // JLH 05/28/2010 Fixed crashing bug when right-clicking out of a text
17 #include "rs_actiondrawtext.h"
19 #include "rs_graphicview.h"
20 #include "rs_snapper.h"
22 RS_ActionDrawText::RS_ActionDrawText(RS_EntityContainer & container,
23 RS_GraphicView & graphicView): RS_PreviewActionInterface("Draw Text", container, graphicView)
29 RS_ActionDrawText::~RS_ActionDrawText()
33 /*virtual*/ RS2::ActionType RS_ActionDrawText::rtti()
35 return RS2::ActionDrawText;
38 void RS_ActionDrawText::init(int status)
40 RS_ActionInterface::init(status);
42 if (RS_DIALOGFACTORY == NULL)
52 RS_Text tmp(NULL, data);
54 if (RS_DIALOGFACTORY->requestTextDialog(&tmp))
58 preview->setVisible(false);
69 graphicView->redraw();
74 RS_DIALOGFACTORY->requestOptions(this, true, true);
82 void RS_ActionDrawText::reset()
84 data = RS_TextData(Vector(0.0, 0.0), 1.0, 100.0, RS2::VAlignTop,
85 RS2::HAlignLeft, RS2::LeftToRight, RS2::Exact, 1.0, data.text,
86 "standard", 0.0, RS2::Update);
89 void RS_ActionDrawText::trigger()
91 RS_DEBUG->print("RS_ActionDrawText::trigger()");
95 //removing *this* causes previews not to be drawn correctly...
100 RS_Text * text = new RS_Text(container, data);
102 container->addEntity(text);
106 document->startUndoCycle();
107 document->addUndoable(text);
108 document->endUndoCycle();
112 // graphicView->drawEntity(text);
119 void RS_ActionDrawText::preparePreview()
122 data.insertionPoint = Vector(0.0, 0.0);
123 RS_Text * text = new RS_Text(preview, data);
125 //text->setVisible(false);
126 preview->addEntity(text);
130 void RS_ActionDrawText::mouseMoveEvent(QMouseEvent * e)
132 RS_DEBUG->print("RS_ActionDrawText::mouseMoveEvent begin");
134 if (getStatus() == SetPos)
136 Vector mouse = snapPoint(e);
139 //without this, nothing is shown...
140 //Which shows that the preview rendering pipeline is seriously fucked up.
141 //Need to fix this shit!
147 if (!preview->isVisible())
148 preview->setVisible(true);
150 offset = Vector(graphicView->toGuiDX(pos.x), -graphicView->toGuiDY(pos.y));
154 RS_DEBUG->print("RS_ActionDrawText::mouseMoveEvent end");
157 void RS_ActionDrawText::mouseReleaseEvent(QMouseEvent * e)
159 if (e->button() == Qt::LeftButton)
161 RS_CoordinateEvent ce(snapPoint(e));
162 coordinateEvent(&ce);
164 else if (e->button() == Qt::RightButton)
166 // The problem is that even though the preview entity has been deleted, the rendering
167 // pipeline still thinks it's valid (because it's not NULL).
170 //init(getStatus()-1);
171 //Clear the preview entity so something else doesn't try to draw it after it's
172 //been deleted, then redraw the graphicView...
174 graphicView->redraw();
179 void RS_ActionDrawText::coordinateEvent(RS_CoordinateEvent * e)
184 Vector mouse = e->getCoordinate();
192 data.insertionPoint = mouse;
201 void RS_ActionDrawText::commandEvent(RS_CommandEvent * e)
203 QString c = e->getCommand().toLower();
205 if (checkCommand("help", c))
207 if (RS_DIALOGFACTORY != NULL)
209 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
210 + getAvailableCommands().join(", "));
218 if (checkCommand("text", c))
223 graphicView->disableCoordinateInput();
230 setText(e->getCommand());
232 if (RS_DIALOGFACTORY != NULL)
233 RS_DIALOGFACTORY->requestOptions(this, true, true);
235 graphicView->enableCoordinateInput();
244 QStringList RS_ActionDrawText::getAvailableCommands()
248 if (getStatus() == SetPos)
249 cmd += command("text");
254 void RS_ActionDrawText::showOptions()
256 RS_ActionInterface::showOptions();
258 if (RS_DIALOGFACTORY != NULL)
259 RS_DIALOGFACTORY->requestOptions(this, true, true);
262 void RS_ActionDrawText::hideOptions()
264 RS_ActionInterface::hideOptions();
266 if (RS_DIALOGFACTORY != NULL)
267 RS_DIALOGFACTORY->requestOptions(this, false);
270 void RS_ActionDrawText::updateMouseButtonHints()
272 if (RS_DIALOGFACTORY == NULL)
278 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify insertion point"), tr("Cancel"));
281 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter text:"), tr("Back"));
284 RS_DIALOGFACTORY->updateMouseWidget("", "");
289 void RS_ActionDrawText::updateMouseCursor()
291 graphicView->setMouseCursor(RS2::CadCursor);
294 void RS_ActionDrawText::updateToolBar()
296 if (RS_DIALOGFACTORY == NULL)
302 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
305 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
310 void RS_ActionDrawText::setText(const QString & t)
316 QString RS_ActionDrawText::getText()
321 void RS_ActionDrawText::setAngle(double a)
327 double RS_ActionDrawText::getAngle()