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