~librecad-dev/librecad/librecad

« back to all changes in this revision

Viewing changes to librecad/src/actions/rs_actiondrawlinehorvert.cpp

  • Committer: Scott Howard
  • Date: 2014-02-21 19:07:55 UTC
  • Revision ID: showard@debian.org-20140221190755-csjax9wb146hgdq4
first commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** This file is part of the LibreCAD project, a 2D CAD program
 
4
**
 
5
** Copyright (C) 2010 R. van Twisk (librecad@rvt.dds.nl)
 
6
** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
 
7
**
 
8
**
 
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.
 
13
**
 
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.
 
18
**
 
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
 
22
**
 
23
** This copyright notice MUST APPEAR in all copies of the script!
 
24
**
 
25
**********************************************************************/
 
26
 
 
27
#include "rs_actiondrawlinehorvert.h"
 
28
 
 
29
#include <QAction>
 
30
#include "rs_dialogfactory.h"
 
31
#include "rs_graphicview.h"
 
32
 
 
33
 
 
34
 
 
35
RS_ActionDrawLineHorVert::RS_ActionDrawLineHorVert(
 
36
    RS_EntityContainer& container,
 
37
    RS_GraphicView& graphicView)
 
38
        :RS_PreviewActionInterface("Draw horizontal/vertical lines",
 
39
                           container, graphicView) {
 
40
    reset();
 
41
    RS_DEBUG->print("RS_ActionDrawLineHorVert::constructor");
 
42
}
 
43
 
 
44
 
 
45
 
 
46
RS_ActionDrawLineHorVert::~RS_ActionDrawLineHorVert() {}
 
47
 
 
48
 
 
49
QAction* RS_ActionDrawLineHorVert::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/) {
 
50
/* RVT_PORT    QAction* action = new QAction(tr("hor./vert. line"),
 
51
                                  tr("H&orizontal / Vertical"),
 
52
                                  QKeySequence(), NULL); */
 
53
    QAction* action = new QAction(tr("Vertical"), NULL);
 
54
    //action->zetStatusTip(tr("Draw horizontal/vertical lines"));
 
55
    return action;
 
56
}
 
57
 
 
58
void RS_ActionDrawLineHorVert::reset() {
 
59
    data = RS_LineData(RS_Vector(false),
 
60
                       RS_Vector(false));
 
61
}
 
62
 
 
63
 
 
64
 
 
65
void RS_ActionDrawLineHorVert::init(int status) {
 
66
    RS_PreviewActionInterface::init(status);
 
67
 
 
68
    reset();
 
69
    RS_DEBUG->print("RS_ActionDrawLineHorVert::init");
 
70
}
 
71
 
 
72
 
 
73
 
 
74
void RS_ActionDrawLineHorVert::trigger() {
 
75
    RS_PreviewActionInterface::trigger();
 
76
 
 
77
    RS_Line* line = new RS_Line(container, data);
 
78
    line->setLayerToActive();
 
79
    line->setPenToActive();
 
80
    container->addEntity(line);
 
81
 
 
82
    // upd. undo list:
 
83
    if (document!=NULL) {
 
84
        document->startUndoCycle();
 
85
        document->addUndoable(line);
 
86
        document->endUndoCycle();
 
87
    }
 
88
 
 
89
        graphicView->redraw(RS2::RedrawDrawing);
 
90
    graphicView->moveRelativeZero(line->getMiddlePoint());
 
91
    RS_DEBUG->print("RS_ActionDrawLineHorVert::trigger():"
 
92
                    " line added: %d", line->getId());
 
93
 
 
94
}
 
95
 
 
96
 
 
97
 
 
98
void RS_ActionDrawLineHorVert::mouseMoveEvent(QMouseEvent* e) {
 
99
    RS_DEBUG->print("RS_ActionDrawLineHorVert::mouseMoveEvent begin");
 
100
 
 
101
    RS_Vector mouse = snapPoint(e);
 
102
    if (getStatus()==SetEndpoint && p1.valid) {
 
103
        RS_Vector p2x = RS_Vector(mouse.x, p1.y);
 
104
        RS_Vector p2y = RS_Vector(p1.x, mouse.y);
 
105
        if (mouse.distanceTo(p2y) > mouse.distanceTo(p2x))
 
106
            p2 = p2x;
 
107
        else
 
108
            p2 = p2y;
 
109
        deletePreview();
 
110
        data = RS_LineData(p1, p2);
 
111
        preview->addEntity(new RS_Line(preview, data));
 
112
        drawPreview();
 
113
    }
 
114
 
 
115
    RS_DEBUG->print("RS_ActionDrawLineHorVert::mouseMoveEvent end");
 
116
}
 
117
 
 
118
 
 
119
 
 
120
void RS_ActionDrawLineHorVert::mouseReleaseEvent(QMouseEvent* e) {
 
121
    if (e->button()==Qt::LeftButton) {
 
122
        RS_Vector mouse = snapPoint(e);
 
123
 
 
124
        switch (getStatus()) {
 
125
        case SetStartpoint:
 
126
            p1 = mouse;
 
127
            setStatus(SetEndpoint);
 
128
            break;
 
129
 
 
130
        case SetEndpoint:
 
131
            p2 = mouse;
 
132
            trigger();
 
133
            setStatus(SetStartpoint);
 
134
            break;
 
135
 
 
136
        default:
 
137
            break;
 
138
        }
 
139
    } else if (e->button()==Qt::RightButton) {
 
140
        deletePreview();
 
141
        init(getStatus()-1);
 
142
    }
 
143
}
 
144
 
 
145
 
 
146
 
 
147
void RS_ActionDrawLineHorVert::updateMouseButtonHints() {
 
148
    switch (getStatus()) {
 
149
    case SetStartpoint:
 
150
        RS_DIALOGFACTORY->updateMouseWidget(tr("Specify first point"),
 
151
                                            tr("Cancel"));
 
152
        break;
 
153
    case SetEndpoint:
 
154
        RS_DIALOGFACTORY->updateMouseWidget(tr("Specify second point"),
 
155
                                            tr("Back"));
 
156
        break;
 
157
    default:
 
158
        RS_DIALOGFACTORY->updateMouseWidget("", "");
 
159
        break;
 
160
    }
 
161
}
 
162
 
 
163
 
 
164
void RS_ActionDrawLineHorVert::updateMouseCursor() {
 
165
    graphicView->setMouseCursor(RS2::CadCursor);
 
166
}
 
167
 
 
168
 
 
169
void RS_ActionDrawLineHorVert::updateToolBar() {
 
170
    if (RS_DIALOGFACTORY!=NULL) {
 
171
        if (isFinished()) {
 
172
            RS_DIALOGFACTORY->resetToolBar();
 
173
        }
 
174
    }
 
175
}
 
176
 
 
177
// EOF