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