~librecad-dev/librecad/librecad

« back to all changes in this revision

Viewing changes to librecad/src/actions/rs_actionselectwindow.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_actionselectwindow.h"
 
28
 
 
29
#include <QAction>
 
30
#include "rs_dialogfactory.h"
 
31
#include "rs_graphicview.h"
 
32
#include "rs_selection.h"
 
33
#include "rs_overlaybox.h"
 
34
 
 
35
 
 
36
/**
 
37
 * Constructor.
 
38
 *
 
39
 * @param select true: select window. false: deselect window
 
40
 */
 
41
RS_ActionSelectWindow::RS_ActionSelectWindow(RS_EntityContainer& container,
 
42
        RS_GraphicView& graphicView,
 
43
        bool select)
 
44
        : RS_PreviewActionInterface("Select Window",
 
45
                            container, graphicView) {
 
46
 
 
47
    this->select = select;
 
48
}
 
49
 
 
50
 
 
51
QAction* RS_ActionSelectWindow::createGUIAction(RS2::ActionType type, QObject* /*parent*/) {
 
52
    QAction* action;
 
53
 
 
54
    if (type==RS2::ActionSelectWindow) {
 
55
        action = new QAction(tr("Select Window"),  NULL);
 
56
                action->setIcon(QIcon(":/extui/selectwindow.png"));
 
57
        //action->zetStatusTip(tr("Selects all Entities in a given Window"));
 
58
    } else {
 
59
        action = new QAction(tr("Deselect Window"), NULL);
 
60
                action->setIcon(QIcon(":/extui/deselectwindow.png"));
 
61
        //action->zetStatusTip(tr("Deselects all Entities in a given Window"));
 
62
        }
 
63
    return action;
 
64
}
 
65
 
 
66
 
 
67
void RS_ActionSelectWindow::init(int status) {
 
68
    RS_PreviewActionInterface::init(status);
 
69
    v1 = v2 = RS_Vector(false);
 
70
    //snapMode.clear();
 
71
    //snapMode.restriction = RS2::RestrictNothing;
 
72
}
 
73
 
 
74
 
 
75
 
 
76
void RS_ActionSelectWindow::trigger() {
 
77
    RS_PreviewActionInterface::trigger();
 
78
 
 
79
    if (v1.valid && v2.valid) {
 
80
        if (graphicView->toGuiDX(v1.distanceTo(v2))>10) {
 
81
 
 
82
            bool cross = (v1.x>v2.x);
 
83
 
 
84
            RS_Selection s(*container, graphicView);
 
85
            s.selectWindow(v1, v2, select, cross);
 
86
 
 
87
            RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected(),container->totalSelectedLength());
 
88
 
 
89
            init();
 
90
        }
 
91
    }
 
92
}
 
93
 
 
94
 
 
95
 
 
96
void RS_ActionSelectWindow::mouseMoveEvent(QMouseEvent* e) {
 
97
    snapFree(e);
 
98
    drawSnapper();
 
99
    if (getStatus()==SetCorner2 && v1.valid) {
 
100
        v2 = snapFree(e);
 
101
        deletePreview();
 
102
                RS_Pen pen_f(RS_Color(50,50,255,40), RS2::Width00, RS2::SolidLine);
 
103
                RS_OverlayBox* ob=new RS_OverlayBox(preview, RS_OverlayBoxData(v1, v2));
 
104
                ob->setPen(pen_f);
 
105
                preview->addEntity(ob);
 
106
 
 
107
                //RLZ: not needed overlay have contour
 
108
/*                RS_Pen pen(RS_Color(218,105,24), RS2::Width00, RS2::SolidLine);
 
109
 
 
110
                // TODO change to a rs_box sort of entity
 
111
                RS_Line* e=new RS_Line(preview, RS_LineData(RS_Vector(v1.x, v1.y),  RS_Vector(v2.x, v1.y)));
 
112
                e->setPen(pen);
 
113
        preview->addEntity(e);
 
114
 
 
115
                e=new RS_Line(preview, RS_LineData(RS_Vector(v2.x, v1.y),  RS_Vector(v2.x, v2.y)));
 
116
                e->setPen(pen);
 
117
        preview->addEntity(e);
 
118
 
 
119
                e=new RS_Line(preview, RS_LineData(RS_Vector(v2.x, v2.y),  RS_Vector(v1.x, v2.y)));
 
120
                e->setPen(pen);
 
121
        preview->addEntity(e);
 
122
 
 
123
                e=new RS_Line(preview, RS_LineData(RS_Vector(v1.x, v2.y),  RS_Vector(v1.x, v1.y)));
 
124
                e->setPen(pen);
 
125
        preview->addEntity(e);*/
 
126
 
 
127
        drawPreview();
 
128
    }
 
129
}
 
130
 
 
131
 
 
132
 
 
133
void RS_ActionSelectWindow::mousePressEvent(QMouseEvent* e) {
 
134
    if (e->button()==Qt::LeftButton) {
 
135
        switch (getStatus()) {
 
136
        case SetCorner1:
 
137
            v1 = snapFree(e);
 
138
            setStatus(SetCorner2);
 
139
            break;
 
140
 
 
141
        default:
 
142
            break;
 
143
        }
 
144
    }
 
145
 
 
146
    RS_DEBUG->print("RS_ActionSelectWindow::mousePressEvent(): %f %f",
 
147
                    v1.x, v1.y);
 
148
}
 
149
 
 
150
 
 
151
 
 
152
void RS_ActionSelectWindow::mouseReleaseEvent(QMouseEvent* e) {
 
153
    RS_DEBUG->print("RS_ActionSelectWindow::mouseReleaseEvent()");
 
154
 
 
155
    if (e->button()==Qt::LeftButton) {
 
156
        if (getStatus()==SetCorner2) {
 
157
            v2 = snapFree(e);
 
158
            trigger();
 
159
        }
 
160
    } else if (e->button()==Qt::RightButton) {
 
161
        if (getStatus()==SetCorner2) {
 
162
            deletePreview();
 
163
        }
 
164
        init(getStatus()-1);
 
165
    }
 
166
}
 
167
 
 
168
 
 
169
 
 
170
void RS_ActionSelectWindow::updateMouseButtonHints() {
 
171
    switch (getStatus()) {
 
172
    case SetCorner1:
 
173
        RS_DIALOGFACTORY->updateMouseWidget(tr("Click and drag for the selection window"), tr("Cancel"));
 
174
        break;
 
175
    case SetCorner2:
 
176
        RS_DIALOGFACTORY->updateMouseWidget(tr("Choose second edge"), tr("Back"));
 
177
        break;
 
178
    default:
 
179
        RS_DIALOGFACTORY->updateMouseWidget("", "");
 
180
        break;
 
181
    }
 
182
}
 
183
 
 
184
 
 
185
 
 
186
void RS_ActionSelectWindow::updateMouseCursor() {
 
187
    graphicView->setMouseCursor(RS2::SelectCursor);
 
188
}
 
189
 
 
190
 
 
191
 
 
192
void RS_ActionSelectWindow::updateToolBar() {
 
193
    //not needed any more
 
194
    return;
 
195
    if (!isFinished()) {
 
196
        //RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
 
197
        RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSelect);
 
198
    } else {
 
199
        RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSelect);
 
200
    }
 
201
}
 
202
 
 
203
// EOF