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_commandevent.h"
20 #include "rs_dialogfactory.h"
21 #include "graphicview.h"
22 #include "rs_preview.h"
24 RS_ActionDrawText::RS_ActionDrawText(RS_EntityContainer & container, GraphicView & graphicView): RS_PreviewActionInterface("Draw Text", container, graphicView)
30 RS_ActionDrawText::~RS_ActionDrawText()
34 /*virtual*/ RS2::ActionType RS_ActionDrawText::rtti()
36 return RS2::ActionDrawText;
39 void RS_ActionDrawText::init(int status)
41 RS_ActionInterface::init(status);
43 if (RS_DIALOGFACTORY == NULL)
53 RS_Text tmp(NULL, data);
55 if (RS_DIALOGFACTORY->requestTextDialog(&tmp))
59 preview->setVisible(false);
70 graphicView->redraw();
75 RS_DIALOGFACTORY->requestOptions(this, true, true);
83 void RS_ActionDrawText::reset()
85 data = RS_TextData(Vector(0.0, 0.0), 1.0, 100.0, RS2::VAlignTop,
86 RS2::HAlignLeft, RS2::LeftToRight, RS2::Exact, 1.0, data.text,
87 "standard", 0.0, RS2::Update);
90 void RS_ActionDrawText::trigger()
92 RS_DEBUG->print("RS_ActionDrawText::trigger()");
96 //removing *this* causes previews not to be drawn correctly...
101 RS_Text * text = new RS_Text(container, data);
103 container->addEntity(text);
107 document->startUndoCycle();
108 document->addUndoable(text);
109 document->endUndoCycle();
113 // graphicView->drawEntity(text);
120 void RS_ActionDrawText::preparePreview()
123 data.insertionPoint = Vector(0.0, 0.0);
124 RS_Text * text = new RS_Text(preview, data);
126 //text->setVisible(false);
127 preview->addEntity(text);
131 void RS_ActionDrawText::mouseMoveEvent(QMouseEvent * e)
133 RS_DEBUG->print("RS_ActionDrawText::mouseMoveEvent begin");
135 if (getStatus() == SetPos)
137 Vector mouse = snapPoint(e);
140 //without this, nothing is shown...
141 //Which shows that the preview rendering pipeline is seriously fucked up.
142 //Need to fix this shit!
148 if (!preview->isVisible())
149 preview->setVisible(true);
151 offset = Vector(graphicView->toGuiDX(pos.x), -graphicView->toGuiDY(pos.y));
155 RS_DEBUG->print("RS_ActionDrawText::mouseMoveEvent end");
158 void RS_ActionDrawText::mouseReleaseEvent(QMouseEvent * e)
160 if (e->button() == Qt::LeftButton)
162 Vector ce(snapPoint(e));
163 coordinateEvent(&ce);
165 else if (e->button() == Qt::RightButton)
167 // The problem is that even though the preview entity has been deleted, the rendering
168 // pipeline still thinks it's valid (because it's not NULL).
171 //init(getStatus()-1);
172 //Clear the preview entity so something else doesn't try to draw it after it's
173 //been deleted, then redraw the graphicView...
175 graphicView->redraw();
180 void RS_ActionDrawText::coordinateEvent(Vector * e)
193 data.insertionPoint = mouse;
202 void RS_ActionDrawText::commandEvent(RS_CommandEvent * e)
204 QString c = e->getCommand().toLower();
206 if (checkCommand("help", c))
208 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"));
282 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter text:"), tr("Back"));
286 RS_DIALOGFACTORY->updateMouseWidget("", "");
291 void RS_ActionDrawText::updateMouseCursor()
293 graphicView->setMouseCursor(RS2::CadCursor);
296 void RS_ActionDrawText::updateToolBar()
298 if (RS_DIALOGFACTORY == NULL)
304 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
308 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
313 void RS_ActionDrawText::setText(const QString & t)
319 QString RS_ActionDrawText::getText()
324 void RS_ActionDrawText::setAngle(double a)
330 double RS_ActionDrawText::getAngle()