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