]> Shamusworld >> Repos - architektonas/blob - src/actions/rs_actionmodifyrotate2.cpp
Initial import
[architektonas] / src / actions / rs_actionmodifyrotate2.cpp
1 /****************************************************************************
2 ** $Id: rs_actionmodifyrotate2.cpp 1161 2004-12-09 23:10:09Z andrew $
3 **
4 ** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
5 **
6 ** This file is part of the qcadlib Library project.
7 **
8 ** This file may be distributed and/or modified under the terms of the
9 ** GNU General Public License version 2 as published by the Free Software
10 ** Foundation and appearing in the file LICENSE.GPL included in the
11 ** packaging of this file.
12 **
13 ** Licensees holding valid qcadlib Professional Edition licenses may use
14 ** this file in accordance with the qcadlib Commercial License
15 ** Agreement provided with the Software.
16 **
17 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
18 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19 **
20 ** See http://www.ribbonsoft.com for further details.
21 **
22 ** Contact info@ribbonsoft.com if any conditions of this licensing are
23 ** not clear to you.
24 **
25 **********************************************************************/
26
27 #include "rs_actionmodifyrotate2.h"
28
29 #include "rs_snapper.h"
30
31 RS_ActionModifyRotate2::RS_ActionModifyRotate2(
32         RS_EntityContainer& container, RS_GraphicView& graphicView):
33         RS_PreviewActionInterface("Rotate Entities around two centers", container, graphicView)
34 {
35 }
36
37 QAction* RS_ActionModifyRotate2::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/)
38 {
39         QAction * action = new QAction(tr("Rotate T&wo"), 0);
40 //      QAction* action = new QAction(tr("Rotate Two"), tr("Rotate T&wo"),
41 //                                                      QKeySequence(), NULL);
42         action->setStatusTip(tr("Rotate Entities around two centers"));
43         return action;
44 }
45
46 void RS_ActionModifyRotate2::init(int status)
47 {
48     RS_ActionInterface::init(status);
49 }
50
51
52
53 void RS_ActionModifyRotate2::trigger() {
54
55     RS_DEBUG->print("RS_ActionModifyRotate2::trigger()");
56
57     RS_Modification m(*container, graphicView);
58     m.rotate2(data);
59
60     finish();
61
62         RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
63 }
64
65
66
67 void RS_ActionModifyRotate2::mouseMoveEvent(QMouseEvent* e) {
68     RS_DEBUG->print("RS_ActionModifyRotate2::mouseMoveEvent begin");
69
70     if (getStatus()==SetReferencePoint1 ||
71             getStatus()==SetReferencePoint2) {
72
73         Vector mouse = snapPoint(e);
74         switch (getStatus()) {
75         case SetReferencePoint1:
76             data.center1 = mouse;
77             break;
78
79         case SetReferencePoint2:
80             if (data.center1.valid) {
81                 data.center2 = mouse;
82                 //data.offset = data.center2-data.center1;
83
84                 /*deletePreview();
85                 clearPreview();
86                 preview->addSelectionFrom(*container);
87                 preview->rotate(data.center1, data.angle);
88                 preview->move(data.offset);
89                 drawPreview();
90                 */
91             }
92             break;
93
94         default:
95             break;
96         }
97     }
98
99     RS_DEBUG->print("RS_ActionModifyRotate2::mouseMoveEvent end");
100 }
101
102
103
104 void RS_ActionModifyRotate2::mouseReleaseEvent(QMouseEvent* e) {
105     if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) {
106         RS_CoordinateEvent ce(snapPoint(e));
107         coordinateEvent(&ce);
108     } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) {
109         deletePreview();
110         deleteSnapper();
111         init(getStatus()-1);
112     }
113 }
114
115
116
117 void RS_ActionModifyRotate2::coordinateEvent(RS_CoordinateEvent* e) {
118     if (e==NULL) {
119         return;
120     }
121
122     Vector pos = e->getCoordinate();
123
124     switch (getStatus()) {
125     case SetReferencePoint1:
126         data.center1 = pos;
127         setStatus(SetReferencePoint2);
128         break;
129
130     case SetReferencePoint2:
131         data.center2 = pos;
132         setStatus(ShowDialog);
133         if (RS_DIALOGFACTORY->requestRotate2Dialog(data)) {
134             trigger();
135             //finish();
136         }
137         break;
138
139     default:
140         break;
141     }
142 }
143
144
145 void RS_ActionModifyRotate2::commandEvent(RS_CommandEvent* /*e*/) {
146 }
147
148
149
150 QStringList RS_ActionModifyRotate2::getAvailableCommands() {
151     QStringList cmd;
152     return cmd;
153 }
154
155
156
157
158 void RS_ActionModifyRotate2::updateMouseButtonHints() {
159     switch (getStatus()) {
160     case SetReferencePoint1:
161         RS_DIALOGFACTORY->updateMouseWidget(tr("Specify absolute reference point"),
162                                             tr("Cancel"));
163         break;
164     case SetReferencePoint2:
165         RS_DIALOGFACTORY->updateMouseWidget(tr("Specify relative reference point"),
166                                             tr("Back"));
167         break;
168     default:
169         RS_DIALOGFACTORY->updateMouseWidget("", "");
170         break;
171     }
172 }
173
174
175
176 void RS_ActionModifyRotate2::updateMouseCursor() {
177     graphicView->setMouseCursor(RS2::CadCursor);
178 }
179
180
181
182 void RS_ActionModifyRotate2::updateToolBar() {
183     switch (getStatus()) {
184     case SetReferencePoint1:
185     case SetReferencePoint2:
186         RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
187         break;
188     default:
189         RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarModify);
190         break;
191     }
192 }
193
194
195 // EOF