]> Shamusworld >> Repos - architektonas/blob - src/actions/actionmodifyrotate.cpp
Bugfixes related to removing Snapper class.
[architektonas] / src / actions / actionmodifyrotate.cpp
1 // actionmodifyrotate.cpp
2 //
3 // Part of the Architektonas Project
4 // Originally part of QCad Community Edition by Andrew Mustun
5 // Extensively rewritten and refactored by James L. Hammons
6 // Portions copyright (C) 2001-2003 RibbonSoft
7 // Copyright (C) 2010 Underground Software
8 // See the README and GPLv2 files for licensing and warranty information
9 //
10 // JLH = James L. Hammons <jlhamm@acm.org>
11 //
12 // Who  When        What
13 // ---  ----------  -----------------------------------------------------------
14 // JLH  06/04/2010  Added this text. :-)
15 //
16
17 #include "actionmodifyrotate.h"
18
19 #include "debug.h"
20 #include "dialogfactory.h"
21
22 ActionModifyRotate::ActionModifyRotate(EntityContainer & container, GraphicView & graphicView):
23         ActionInterface("Rotate Entities",
24                 container, graphicView)
25 {
26 }
27
28 ActionModifyRotate::~ActionModifyRotate()
29 {
30 }
31
32 void ActionModifyRotate::init(int status)
33 {
34         ActionInterface::init(status);
35 }
36
37 void ActionModifyRotate::trigger()
38 {
39         DEBUG->print("ActionModifyRotate::trigger()");
40
41         Modification m(*container, graphicView);
42         m.rotate(data);
43
44         DIALOGFACTORY->updateSelectionWidget(container->countSelected());
45 }
46
47 void ActionModifyRotate::mouseMoveEvent(QMouseEvent * e)
48 {
49         DEBUG->print("ActionModifyRotate::mouseMoveEvent begin");
50
51         if (getStatus() == SetReferencePoint)
52         {
53                 Vector mouse = snapPoint(e);
54
55                 switch (getStatus())
56                 {
57                 case SetReferencePoint:
58                         referencePoint = mouse;
59                         break;
60
61                 default:
62                         break;
63                 }
64         }
65
66         DEBUG->print("ActionModifyRotate::mouseMoveEvent end");
67 }
68
69 void ActionModifyRotate::mouseReleaseEvent(QMouseEvent * e)
70 {
71         if (e->button() == Qt::LeftButton)
72         {
73                 Vector ce(snapPoint(e));
74                 coordinateEvent(&ce);
75         }
76         else if (e->button() == Qt::RightButton)
77         {
78                 deletePreview();
79                 deleteSnapper();
80                 init(getStatus() - 1);
81         }
82 }
83
84 void ActionModifyRotate::coordinateEvent(Vector * e)
85 {
86         if (e == NULL)
87                 return;
88
89         Vector pos = *e;
90
91         switch (getStatus())
92         {
93         case SetReferencePoint:
94                 referencePoint = pos;
95                 setStatus(ShowDialog);
96
97                 if (DIALOGFACTORY->requestRotateDialog(data))
98                 {
99                         data.center = referencePoint;
100                         trigger();
101                         finish();
102                 }
103                 break;
104
105         default:
106                 break;
107         }
108 }
109
110 void ActionModifyRotate::updateMouseButtonHints()
111 {
112         switch (getStatus())
113         {
114         case SetReferencePoint:
115                 DIALOGFACTORY->updateMouseWidget(tr("Specify reference point"),
116                         tr("Back"));
117                 break;
118
119         default:
120                 DIALOGFACTORY->updateMouseWidget("", "");
121                 break;
122         }
123 }
124
125 void ActionModifyRotate::updateMouseCursor()
126 {
127         graphicView->setMouseCursor(RS2::CadCursor);
128 }
129
130 void ActionModifyRotate::updateToolBar()
131 {
132         switch (getStatus())
133         {
134         case SetReferencePoint:
135                 DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
136                 break;
137
138         default:
139                 DIALOGFACTORY->requestToolBar(RS2::ToolBarModify);
140                 break;
141         }
142 }