1
/****************************************************************************
3
** This file is part of the LibreCAD project, a 2D CAD program
5
** Copyright (C) 2010 R. van Twisk (librecad@rvt.dds.nl)
6
** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
9
** This file may be distributed and/or modified under the terms of the
10
** GNU General Public License version 2 as published by the Free Software
11
** Foundation and appearing in the file gpl-2.0.txt included in the
12
** packaging of this file.
14
** This program is distributed in the hope that it will be useful,
15
** but WITHOUT ANY WARRANTY; without even the implied warranty of
16
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
** GNU General Public License for more details.
19
** You should have received a copy of the GNU General Public License
20
** along with this program; if not, write to the Free Software
21
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23
** This copyright notice MUST APPEAR in all copies of the script!
25
**********************************************************************/
27
#include "rs_actiondrawtext.h"
30
#include "rs_dialogfactory.h"
31
#include "rs_graphicview.h"
32
#include "rs_commandevent.h"
36
RS_ActionDrawText::RS_ActionDrawText(RS_EntityContainer& container,
37
RS_GraphicView& graphicView)
38
:RS_PreviewActionInterface("Draw Text",
39
container, graphicView) {
42
pos = RS_Vector(false);
43
secPos = RS_Vector(false);
48
QAction* RS_ActionDrawText::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/) {
50
QAction* action = new QAction(tr("&Text"), NULL);
51
action->setIcon(QIcon(":/extui/menutext.png"));
52
//action->zetStatusTip(tr("Draw Text Entities"));
57
void RS_ActionDrawText::init(int status) {
58
RS_ActionInterface::init(status);
59
if (RS_DIALOGFACTORY!=NULL) {
65
RS_Text tmp(NULL, data);
66
if (RS_DIALOGFACTORY->requestTextDialog(&tmp)) {
78
RS_DIALOGFACTORY->requestOptions(this, true, true);
80
preview->setVisible(true);
92
void RS_ActionDrawText::reset() {
93
data = RS_TextData(RS_Vector(0.0,0.0), RS_Vector(0.0,0.0),
95
RS_TextData::VABaseline,
106
void RS_ActionDrawText::trigger() {
108
RS_DEBUG->print("RS_ActionDrawText::trigger()");
113
RS_Text* text = new RS_Text(container, data);
115
container->addEntity(text);
118
document->startUndoCycle();
119
document->addUndoable(text);
120
document->endUndoCycle();
123
graphicView->redraw(RS2::RedrawDrawing);
126
secPos = RS_Vector(false);
132
void RS_ActionDrawText::preparePreview() {
133
if (data.halign == RS_TextData::HAFit || data.halign == RS_TextData::HAAligned) {
135
RS_Line* text = new RS_Line(pos, secPos);
136
preview->addEntity(text);
139
data.insertionPoint = pos;
140
RS_Text* text = new RS_Text(preview, data);
142
preview->addEntity(text);
148
void RS_ActionDrawText::mouseMoveEvent(QMouseEvent* e) {
149
RS_DEBUG->print("RS_ActionDrawText::mouseMoveEvent begin");
151
if (getStatus()==SetPos) {
152
RS_Vector mouse = snapPoint(e);
153
RS_Vector mov = mouse-pos;
155
if (textChanged || pos.valid == false || preview->isEmpty()) {
160
preview->setVisible(true);
163
} else if (getStatus()==SetSecPos) {
164
secPos = snapPoint(e);
170
RS_DEBUG->print("RS_ActionDrawText::mouseMoveEvent end");
175
void RS_ActionDrawText::mouseReleaseEvent(QMouseEvent* e) {
176
if (e->button()==Qt::LeftButton) {
177
RS_CoordinateEvent ce(snapPoint(e));
178
coordinateEvent(&ce);
179
} else if (e->button()==Qt::RightButton) {
181
//init(getStatus()-1);
188
void RS_ActionDrawText::coordinateEvent(RS_CoordinateEvent* e) {
193
RS_Vector mouse = e->getCoordinate();
195
switch (getStatus()) {
200
data.insertionPoint = mouse;
201
if (data.halign == RS_TextData::HAFit || data.halign == RS_TextData::HAAligned)
202
setStatus(SetSecPos);
208
data.secondPoint = mouse;
219
void RS_ActionDrawText::commandEvent(RS_CommandEvent* e) {
220
QString c = e->getCommand().toLower();
222
if (checkCommand("help", c)) {
223
if (RS_DIALOGFACTORY!=NULL) {
224
RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
225
+ getAvailableCommands().join(", "));
230
switch (getStatus()) {
232
if (checkCommand("text", c)) {
234
graphicView->disableCoordinateInput();
240
setText(e->getCommand());
241
if (RS_DIALOGFACTORY!=NULL) {
242
RS_DIALOGFACTORY->requestOptions(this, true, true);
244
graphicView->enableCoordinateInput();
256
QStringList RS_ActionDrawText::getAvailableCommands() {
258
if (getStatus()==SetPos) {
259
cmd += command("text");
266
void RS_ActionDrawText::showOptions() {
267
RS_ActionInterface::showOptions();
269
if (RS_DIALOGFACTORY!=NULL) {
270
RS_DIALOGFACTORY->requestOptions(this, true, true);
276
void RS_ActionDrawText::hideOptions() {
277
RS_ActionInterface::hideOptions();
279
if (RS_DIALOGFACTORY!=NULL) {
280
RS_DIALOGFACTORY->requestOptions(this, false);
286
void RS_ActionDrawText::updateMouseButtonHints() {
287
if (RS_DIALOGFACTORY!=NULL) {
288
switch (getStatus()) {
290
RS_DIALOGFACTORY->updateMouseWidget(tr("Specify insertion point"),
294
RS_DIALOGFACTORY->updateMouseWidget(tr("Specify second point"),
299
RS_DIALOGFACTORY->updateMouseWidget(tr("Enter text:"),
303
RS_DIALOGFACTORY->updateMouseWidget("", "");
311
void RS_ActionDrawText::updateMouseCursor() {
312
graphicView->setMouseCursor(RS2::CadCursor);
315
//void RS_ActionDrawText::updateToolBar() {
316
// if(isFinished()) {
317
// if (RS_DIALOGFACTORY!=NULL) {
318
// RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
322
// //not needed any more with new snap
324
// if (RS_DIALOGFACTORY!=NULL) {
325
// switch (getStatus()) {
327
// RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
330
// RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
339
void RS_ActionDrawText::setText(const QString& t) {
346
QString RS_ActionDrawText::getText() {
351
void RS_ActionDrawText::setAngle(double a) {
356
double RS_ActionDrawText::getAngle() {