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 "rs_commandevent.h"
22 #include "rs_dialogfactory.h"
23 #include "graphicview.h"
24 #include "rs_preview.h"
26 ActionDrawText::ActionDrawText(RS_EntityContainer & container, GraphicView & graphicView): ActionInterface("Draw Text", container, graphicView)
32 ActionDrawText::~ActionDrawText()
36 /*virtual*/ RS2::ActionType ActionDrawText::rtti()
38 return RS2::ActionDrawText;
41 void ActionDrawText::init(int status)
43 ActionInterface::init(status);
45 if (RS_DIALOGFACTORY == NULL)
55 RS_Text tmp(NULL, data);
57 if (RS_DIALOGFACTORY->requestTextDialog(&tmp))
61 // preview->setVisible(false);
72 graphicView->redraw();
77 RS_DIALOGFACTORY->requestOptions(this, true, true);
85 void ActionDrawText::reset()
87 data = RS_TextData(Vector(0.0, 0.0), 1.0, 100.0, RS2::VAlignTop,
88 RS2::HAlignLeft, RS2::LeftToRight, RS2::Exact, 1.0, data.text,
89 "standard", 0.0, RS2::Update);
92 void ActionDrawText::trigger()
94 RS_DEBUG->print("ActionDrawText::trigger()");
98 //removing *this* causes previews not to be drawn correctly...
103 RS_Text * text = new RS_Text(container, data);
105 container->addEntity(text);
109 document->startUndoCycle();
110 document->addUndoable(text);
111 document->endUndoCycle();
115 // graphicView->drawEntity(text);
122 void ActionDrawText::preparePreview()
125 data.insertionPoint = Vector(0.0, 0.0);
126 RS_Text * text = new RS_Text(preview, data);
128 preview->addEntity(text);
129 textChanged = false;*/
132 void ActionDrawText::mouseMoveEvent(QMouseEvent * e)
134 RS_DEBUG->print("ActionDrawText::mouseMoveEvent begin");
136 if (getStatus() == SetPos)
138 Vector mouse = snapPoint(e);
141 //without this, nothing is shown...
142 //Which shows that the preview rendering pipeline is seriously fucked up.
143 //Need to fix this shit!
149 // if (!preview->isVisible())
150 // preview->setVisible(true);
152 // offset = Vector(graphicView->toGuiDX(pos.x), -graphicView->toGuiDY(pos.y));
156 RS_DEBUG->print("ActionDrawText::mouseMoveEvent end");
159 void ActionDrawText::mouseReleaseEvent(QMouseEvent * e)
161 if (e->button() == Qt::LeftButton)
163 Vector ce(snapPoint(e));
164 coordinateEvent(&ce);
166 else if (e->button() == Qt::RightButton)
168 // The problem is that even though the preview entity has been deleted, the rendering
169 // pipeline still thinks it's valid (because it's not NULL).
172 //init(getStatus()-1);
173 //Clear the preview entity so something else doesn't try to draw it after it's
174 //been deleted, then redraw the graphicView...
176 graphicView->redraw();
181 void ActionDrawText::coordinateEvent(Vector * e)
194 data.insertionPoint = mouse;
203 void ActionDrawText::commandEvent(RS_CommandEvent * e)
205 QString c = e->getCommand().toLower();
207 if (checkCommand("help", c))
209 if (RS_DIALOGFACTORY != NULL)
210 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
211 + getAvailableCommands().join(", "));
219 if (checkCommand("text", c))
224 graphicView->disableCoordinateInput();
231 setText(e->getCommand());
233 if (RS_DIALOGFACTORY)
234 RS_DIALOGFACTORY->requestOptions(this, true, true);
236 graphicView->enableCoordinateInput();
245 QStringList ActionDrawText::getAvailableCommands()
249 if (getStatus() == SetPos)
250 cmd += command("text");
255 void ActionDrawText::showOptions()
257 ActionInterface::showOptions();
259 if (RS_DIALOGFACTORY)
260 RS_DIALOGFACTORY->requestOptions(this, true, true);
263 void ActionDrawText::hideOptions()
265 ActionInterface::hideOptions();
267 if (RS_DIALOGFACTORY)
268 RS_DIALOGFACTORY->requestOptions(this, false);
271 void ActionDrawText::updateMouseButtonHints()
273 if (!RS_DIALOGFACTORY)
279 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify insertion point"), tr("Cancel"));
283 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter text:"), tr("Back"));
287 RS_DIALOGFACTORY->updateMouseWidget("", "");
292 void ActionDrawText::updateMouseCursor()
294 graphicView->setMouseCursor(RS2::CadCursor);
297 void ActionDrawText::updateToolBar()
299 if (!RS_DIALOGFACTORY)
305 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
309 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
314 void ActionDrawText::setText(const QString & t)
320 QString ActionDrawText::getText()
325 void ActionDrawText::setAngle(double a)
331 double ActionDrawText::getAngle()