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 "actiondrawtext.h"
19 #include "rs_commandevent.h"
20 #include "rs_dialogfactory.h"
21 #include "graphicview.h"
22 #include "rs_preview.h"
24 ActionDrawText::ActionDrawText(RS_EntityContainer & container, GraphicView & graphicView): ActionInterface("Draw Text", container, graphicView)
30 ActionDrawText::~ActionDrawText()
34 /*virtual*/ RS2::ActionType ActionDrawText::rtti()
36 return RS2::ActionDrawText;
39 void ActionDrawText::init(int status)
41 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 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 ActionDrawText::trigger()
92 RS_DEBUG->print("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 ActionDrawText::preparePreview()
123 data.insertionPoint = Vector(0.0, 0.0);
124 RS_Text * text = new RS_Text(preview, data);
126 preview->addEntity(text);
127 textChanged = false;*/
130 void ActionDrawText::mouseMoveEvent(QMouseEvent * e)
132 RS_DEBUG->print("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("ActionDrawText::mouseMoveEvent end");
157 void 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 ActionDrawText::coordinateEvent(Vector * e)
192 data.insertionPoint = mouse;
201 void 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)
232 RS_DIALOGFACTORY->requestOptions(this, true, true);
234 graphicView->enableCoordinateInput();
243 QStringList ActionDrawText::getAvailableCommands()
247 if (getStatus() == SetPos)
248 cmd += command("text");
253 void ActionDrawText::showOptions()
255 ActionInterface::showOptions();
257 if (RS_DIALOGFACTORY)
258 RS_DIALOGFACTORY->requestOptions(this, true, true);
261 void ActionDrawText::hideOptions()
263 ActionInterface::hideOptions();
265 if (RS_DIALOGFACTORY)
266 RS_DIALOGFACTORY->requestOptions(this, false);
269 void ActionDrawText::updateMouseButtonHints()
271 if (!RS_DIALOGFACTORY)
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 ActionDrawText::updateMouseCursor()
292 graphicView->setMouseCursor(RS2::CadCursor);
295 void ActionDrawText::updateToolBar()
297 if (!RS_DIALOGFACTORY)
303 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
307 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
312 void ActionDrawText::setText(const QString & t)
318 QString ActionDrawText::getText()
323 void ActionDrawText::setAngle(double a)
329 double ActionDrawText::getAngle()