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_actiondrawlinerectangle.h"
30
#include "rs_dialogfactory.h"
31
#include "rs_graphicview.h"
32
#include "rs_commandevent.h"
36
RS_ActionDrawLineRectangle::RS_ActionDrawLineRectangle(
37
RS_EntityContainer& container,
38
RS_GraphicView& graphicView)
39
:RS_PreviewActionInterface("Draw rectangles",
40
container, graphicView) {
46
RS_ActionDrawLineRectangle::~RS_ActionDrawLineRectangle() {}
48
QAction* RS_ActionDrawLineRectangle::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/) {
50
QAction* action = new QAction(tr("Rectangle"), NULL);
51
action->setIcon(QIcon(":/extui/linesrect.png"));
52
//action->zetStatusTip(tr("Draw rectangles"));
57
void RS_ActionDrawLineRectangle::reset() {
58
for (int i=0; i<4; ++i) {
59
data[i] = RS_LineData(RS_Vector(false),
66
void RS_ActionDrawLineRectangle::init(int status) {
67
RS_PreviewActionInterface::init(status);
74
void RS_ActionDrawLineRectangle::trigger() {
75
RS_PreviewActionInterface::trigger();
80
// create and add rectangle:
81
for (int i=0; i<4; ++i) {
82
line[i] = new RS_Line(container,
84
line[i]->setLayerToActive();
85
line[i]->setPenToActive();
86
container->addEntity(line[i]);
91
document->startUndoCycle();
92
for (int i=0; i<4; ++i) {
93
document->addUndoable(line[i]);
95
document->endUndoCycle();
99
graphicView->redraw(RS2::RedrawDrawing);
100
graphicView->moveRelativeZero(corner2);
105
void RS_ActionDrawLineRectangle::mouseMoveEvent(QMouseEvent* e) {
106
RS_DEBUG->print("RS_ActionDrawLineRectangle::mouseMoveEvent begin");
108
RS_Vector mouse = snapPoint(e);
109
if (getStatus()==SetCorner2 && corner1.valid) {
115
for (int i=0; i<4; ++i) {
116
preview->addEntity(new RS_Line(preview, data[i]));
121
RS_DEBUG->print("RS_ActionDrawLineRectangle::mouseMoveEvent end");
125
void RS_ActionDrawLineRectangle::mouseReleaseEvent(QMouseEvent* e) {
126
if (e->button()==Qt::LeftButton) {
127
RS_CoordinateEvent ce(snapPoint(e));
128
coordinateEvent(&ce);
129
} else if (e->button()==Qt::RightButton) {
137
void RS_ActionDrawLineRectangle::preparePreview() {
138
data[0] = RS_LineData(corner1, RS_Vector(corner2.x, corner1.y));
139
data[1] = RS_LineData(RS_Vector(corner2.x, corner1.y), corner2);
140
data[2] = RS_LineData(corner2, RS_Vector(corner1.x, corner2.y));
141
data[3] = RS_LineData(RS_Vector(corner1.x, corner2.y), corner1);
145
void RS_ActionDrawLineRectangle::coordinateEvent(RS_CoordinateEvent* e) {
150
RS_Vector mouse = e->getCoordinate();
152
switch (getStatus()) {
155
graphicView->moveRelativeZero(mouse);
156
setStatus(SetCorner2);
162
setStatus(SetCorner1);
172
void RS_ActionDrawLineRectangle::commandEvent(RS_CommandEvent* e) {
173
QString c = e->getCommand().toLower();
175
if (checkCommand("help", c)) {
176
if (RS_DIALOGFACTORY!=NULL) {
177
RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
178
+ getAvailableCommands().join(", "));
186
QStringList RS_ActionDrawLineRectangle::getAvailableCommands() {
192
void RS_ActionDrawLineRectangle::updateMouseButtonHints() {
193
if (RS_DIALOGFACTORY!=NULL) {
194
switch (getStatus()) {
196
RS_DIALOGFACTORY->updateMouseWidget(tr("Specify first corner"),
200
RS_DIALOGFACTORY->updateMouseWidget(tr("Specify second corner"),
204
RS_DIALOGFACTORY->updateMouseWidget("", "");
211
void RS_ActionDrawLineRectangle::updateMouseCursor() {
212
graphicView->setMouseCursor(RS2::CadCursor);
216
//void RS_ActionDrawLineRectangle::updateToolBar() {
217
// if (RS_DIALOGFACTORY!=NULL) {
218
// if (isFinished()) {
219
// RS_DIALOGFACTORY->resetToolBar();