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_dialogfactory.h"
20 #include "rs_graphicview.h"
21 #include "rs_preview.h"
23 RS_ActionDrawText::RS_ActionDrawText(RS_EntityContainer & container, 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 Vector 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(Vector * e)
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)
208 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
209 + getAvailableCommands().join(", "));
217 if (checkCommand("text", c))
222 graphicView->disableCoordinateInput();
229 setText(e->getCommand());
231 if (RS_DIALOGFACTORY != NULL)
232 RS_DIALOGFACTORY->requestOptions(this, true, true);
234 graphicView->enableCoordinateInput();
243 QStringList RS_ActionDrawText::getAvailableCommands()
247 if (getStatus() == SetPos)
248 cmd += command("text");
253 void RS_ActionDrawText::showOptions()
255 RS_ActionInterface::showOptions();
257 if (RS_DIALOGFACTORY != NULL)
258 RS_DIALOGFACTORY->requestOptions(this, true, true);
261 void RS_ActionDrawText::hideOptions()
263 RS_ActionInterface::hideOptions();
265 if (RS_DIALOGFACTORY != NULL)
266 RS_DIALOGFACTORY->requestOptions(this, false);
269 void RS_ActionDrawText::updateMouseButtonHints()
271 if (RS_DIALOGFACTORY == NULL)
277 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify insertion point"), tr("Cancel"));
281 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter text:"), tr("Back"));
285 RS_DIALOGFACTORY->updateMouseWidget("", "");
290 void RS_ActionDrawText::updateMouseCursor()
292 graphicView->setMouseCursor(RS2::CadCursor);
295 void RS_ActionDrawText::updateToolBar()
297 if (RS_DIALOGFACTORY == NULL)
303 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
307 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
312 void RS_ActionDrawText::setText(const QString & t)
318 QString RS_ActionDrawText::getText()
323 void RS_ActionDrawText::setAngle(double a)
329 double RS_ActionDrawText::getAngle()