]> Shamusworld >> Repos - architektonas/blob - src/forms/cadtoolbarsnap.cpp
Refactoring: Moved RS_GraphicView to GraphicView.
[architektonas] / src / forms / cadtoolbarsnap.cpp
1 // cadtoolbarsnap.cpp
2 //
3 // Originally part of QCad Community Edition by Andrew Mustun
4 // Extensively rewritten and refactored by James L. Hammons
5 // (C) 2010 Underground Software
6 //
7 // JLH = James L. Hammons <jlhamm@acm.org>
8 //
9 // Who  When        What
10 // ---  ----------  -----------------------------------------------------------
11 // JLH  05/10/2010  Created this file. :-)
12 //
13
14 #include "cadtoolbarsnap.h"
15
16 #include "cadtoolbar.h"
17 #include "qg_actionhandler.h"
18 #include "rs_debug.h"
19
20 CadToolBarSnap::CadToolBarSnap(QWidget * parent/*= 0*/, Qt::WindowFlags flags/*= 0*/):
21         QWidget(parent, flags), actionHandler(NULL), cadToolBar(NULL)
22 {
23         ui.setupUi(this);
24 }
25
26 CadToolBarSnap::~CadToolBarSnap()
27 {
28 }
29
30 //void CadToolBarSnap::mousePressEvent(QMouseEvent* e) {
31 //    if (e->button()==RightButton && cadToolBar!=NULL) {
32 //cadToolBar->back();
33 //        e->accept();
34 //    }
35 //}
36
37 void CadToolBarSnap::contextMenuEvent(QContextMenuEvent * e)
38 {
39         e->accept();
40 }
41
42 void CadToolBarSnap::setCadToolBar(CadToolBar * tb)
43 {
44         cadToolBar = tb;
45
46         if (tb!=NULL)
47         {
48                 actionHandler = tb->getActionHandler();
49                 actionHandler->setCadToolBarSnap(this);
50         }
51         else
52                 RS_DEBUG->print(RS_Debug::D_ERROR, "CadToolBarSnap::setCadToolBar(): No valid toolbar set.");
53 }
54
55 void CadToolBarSnap::snapFree()
56 {
57         if (actionHandler!=NULL)
58         {
59                 disableSnaps();
60                 ui.bFree->setChecked(true);
61                 actionHandler->slotSnapFree();
62         }
63 }
64
65 void CadToolBarSnap::snapGrid()
66 {
67         if (actionHandler!=NULL)
68         {
69                 actionHandler->slotSnapGrid();
70                 disableSnaps();
71                 ui.bGrid->setChecked(true);
72         }
73 }
74
75 void CadToolBarSnap::snapEndpoint() {
76         if (actionHandler!=NULL) {
77                 actionHandler->slotSnapEndpoint();
78                 disableSnaps();
79                 ui.bEndpoint->setChecked(true);
80         }
81 }
82
83 void CadToolBarSnap::snapOnEntity() {
84         if (actionHandler!=NULL) {
85                 actionHandler->slotSnapOnEntity();
86                 disableSnaps();
87                 ui.bOnEntity->setChecked(true);
88         }
89 }
90
91 void CadToolBarSnap::snapCenter() {
92         if (actionHandler!=NULL) {
93                 actionHandler->slotSnapCenter();
94                 disableSnaps();
95                 ui.bCenter->setChecked(true);
96         }
97 }
98
99 void CadToolBarSnap::snapMiddle() {
100         if (actionHandler!=NULL) {
101                 actionHandler->slotSnapMiddle();
102                 disableSnaps();
103                 ui.bMiddle->setChecked(true);
104         }
105 }
106
107 void CadToolBarSnap::snapDist() {
108         if (actionHandler!=NULL) {
109                 actionHandler->slotSnapDist();
110                 disableSnaps();
111                 ui.bDist->setChecked(true);
112         }
113 }
114
115 void CadToolBarSnap::snapIntersection() {
116         if (actionHandler!=NULL) {
117                 actionHandler->slotSnapIntersection();
118                 disableSnaps();
119                 ui.bIntersection->setChecked(true);
120         }
121 }
122
123 void CadToolBarSnap::snapIntersectionManual()
124 {
125         if (actionHandler!=NULL)
126         {
127                 actionHandler->slotSnapIntersectionManual();
128                 //disableSnaps();
129                 //bIntersectionManual->setChecked(true);
130         }
131 }
132
133 void CadToolBarSnap::restrictNothing()
134 {
135         if (actionHandler!=NULL)
136         {
137                 actionHandler->slotRestrictNothing();
138                 disableRestrictions();
139                 ui.bResNothing->setChecked(true);
140         }
141 }
142
143 void CadToolBarSnap::restrictOrthogonal()
144 {
145         if (actionHandler!=NULL)
146         {
147                 actionHandler->slotRestrictOrthogonal();
148                 disableRestrictions();
149                 ui.bResOrthogonal->setChecked(true);
150         }
151 }
152
153 void CadToolBarSnap::restrictHorizontal()
154 {
155         if (actionHandler!=NULL)
156         {
157                 actionHandler->slotRestrictHorizontal();
158                 disableRestrictions();
159                 ui.bResHorizontal->setChecked(true);
160         }
161 }
162
163 void CadToolBarSnap::restrictVertical()
164 {
165         if (actionHandler!=NULL)
166         {
167                 actionHandler->slotRestrictVertical();
168                 disableRestrictions();
169                 ui.bResVertical->setChecked(true);
170         }
171 }
172
173 void CadToolBarSnap::disableSnaps()
174 {
175         if (ui.bFree->isChecked())
176                 ui.bFree->setChecked(false);
177
178         if (ui.bGrid->isChecked())
179                 ui.bGrid->setChecked(false);
180
181         if (ui.bEndpoint->isChecked())
182                 ui.bEndpoint->setChecked(false);
183
184         if (ui.bOnEntity->isChecked())
185                 ui.bOnEntity->setChecked(false);
186
187         if (ui.bCenter->isChecked())
188                 ui.bCenter->setChecked(false);
189
190         if (ui.bMiddle->isChecked())
191                 ui.bMiddle->setChecked(false);
192
193         if (ui.bDist->isChecked())
194                 ui.bDist->setChecked(false);
195
196         if (ui.bIntersection->isChecked())
197                 ui.bIntersection->setChecked(false);
198
199         if (ui.bIntersectionManual->isChecked())
200                 ui.bIntersectionManual->setChecked(false);
201 }
202
203 void CadToolBarSnap::disableRestrictions()
204 {
205         if (ui.bResNothing->isChecked())
206                 ui.bResNothing->setChecked(false);
207
208         if (ui.bResOrthogonal->isChecked())
209                 ui.bResOrthogonal->setChecked(false);
210
211         if (ui.bResHorizontal->isChecked())
212                 ui.bResHorizontal->setChecked(false);
213
214         if (ui.bResVertical->isChecked())
215                 ui.bResVertical->setChecked(false);
216 }
217
218 void CadToolBarSnap::setSnapMode(int sm)
219 {
220         switch (sm)
221         {
222         case RS2::SnapFree:
223                 ui.bFree->setChecked(true);
224                 break;
225         case RS2::SnapEndpoint:
226                 ui.bEndpoint->setChecked(true);
227                 break;
228         case RS2::SnapGrid:
229                 ui.bGrid->setChecked(true);
230                 break;
231         case RS2::SnapOnEntity:
232                 ui.bOnEntity->setChecked(true);
233                 break;
234         case RS2::SnapCenter:
235                 ui.bCenter->setChecked(true);
236                 break;
237         case RS2::SnapMiddle:
238                 ui.bMiddle->setChecked(true);
239                 break;
240         case RS2::SnapDist:
241                 ui.bDist->setChecked(true);
242                 break;
243         case RS2::SnapIntersection:
244                 ui.bIntersection->setChecked(true);
245                 break;
246         default:
247                 break;
248         }
249 }
250
251 void CadToolBarSnap::setSnapRestriction(int sr)
252 {
253         switch (sr)
254         {
255         default:
256         case RS2::RestrictNothing:
257                 ui.bResNothing->setChecked(true);
258                 break;
259         case RS2::RestrictOrthogonal:
260                 ui.bResOrthogonal->setChecked(true);
261                 break;
262         case RS2::RestrictHorizontal:
263                 ui.bResHorizontal->setChecked(true);
264                 break;
265         case RS2::RestrictVertical:
266                 ui.bResVertical->setChecked(true);
267                 break;
268         }
269 }
270
271 void CadToolBarSnap::setRelativeZero()
272 {
273         if (cadToolBar!=NULL && actionHandler!=NULL)
274                 actionHandler->slotSetRelativeZero();
275 }
276
277 void CadToolBarSnap::lockRelativeZero(bool on)
278 {
279         if (cadToolBar!=NULL && actionHandler!=NULL)
280                 actionHandler->slotLockRelativeZero(on);
281 }
282
283 void CadToolBarSnap::setLockRelativeZero(bool on)
284 {
285         ui.bLockRelZero->setChecked(on);
286 }
287
288 void CadToolBarSnap::back()
289 {
290         if (cadToolBar != NULL)
291                 cadToolBar->back();
292 }