~librecad-dev/librecad/librecad

« back to all changes in this revision

Viewing changes to librecad/src/ui/forms/qg_cadtoolbarsnap.cpp

  • Committer: Scott Howard
  • Date: 2014-02-21 19:07:55 UTC
  • Revision ID: showard@debian.org-20140221190755-csjax9wb146hgdq4
first commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** This file is part of the LibreCAD project, a 2D CAD program
 
4
**
 
5
** Copyright (C) 2010 R. van Twisk (librecad@rvt.dds.nl)
 
6
** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
 
7
**
 
8
**
 
9
** This file may be distributed and/or modified under the terms of the
 
10
** GNU General Public License version 2 as published by the Free Software 
 
11
** Foundation and appearing in the file gpl-2.0.txt included in the
 
12
** packaging of this file.
 
13
**
 
14
** This program is distributed in the hope that it will be useful,
 
15
** but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
** GNU General Public License for more details.
 
18
** 
 
19
** You should have received a copy of the GNU General Public License
 
20
** along with this program; if not, write to the Free Software
 
21
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 
22
**
 
23
** This copyright notice MUST APPEAR in all copies of the script!  
 
24
**
 
25
**********************************************************************/
 
26
#include "qg_cadtoolbarsnap.h"
 
27
 
 
28
#include "qg_cadtoolbar.h"
 
29
 
 
30
/*
 
31
 *  Constructs a QG_CadToolBarSnap as a child of 'parent', with the
 
32
 *  name 'name' and widget flags set to 'f'.
 
33
 */
 
34
QG_CadToolBarSnap::QG_CadToolBarSnap(QWidget* parent, Qt::WindowFlags fl)
 
35
    : QWidget(parent, fl)
 
36
{
 
37
    setupUi(this);
 
38
 
 
39
    init();
 
40
}
 
41
 
 
42
/*
 
43
 *  Destroys the object and frees any allocated resources
 
44
 */
 
45
QG_CadToolBarSnap::~QG_CadToolBarSnap()
 
46
{
 
47
    // no need to delete child widgets, Qt does it all for us
 
48
}
 
49
 
 
50
/*
 
51
 *  Sets the strings of the subwidgets using the current
 
52
 *  language.
 
53
 */
 
54
void QG_CadToolBarSnap::languageChange()
 
55
{
 
56
    retranslateUi(this);
 
57
}
 
58
 
 
59
void QG_CadToolBarSnap::init() {
 
60
    cadToolBar = NULL;
 
61
    actionHandler = NULL;
 
62
}
 
63
 
 
64
//void QG_CadToolBarSnap::mousePressEvent(QMouseEvent* e) {
 
65
//    if (e->button()==RightButton && cadToolBar!=NULL) {
 
66
//cadToolBar->back();
 
67
//        e->accept();
 
68
//    }
 
69
//}
 
70
 
 
71
void QG_CadToolBarSnap::contextMenuEvent(QContextMenuEvent *e) {
 
72
    e->accept();
 
73
}
 
74
 
 
75
void QG_CadToolBarSnap::setCadToolBar(QG_CadToolBar* tb) {
 
76
    cadToolBar = tb;
 
77
    if (tb!=NULL) {
 
78
        actionHandler = tb->getActionHandler();
 
79
        actionHandler->setCadToolBarSnap(this);
 
80
    } else {
 
81
        RS_DEBUG->print(RS_Debug::D_ERROR,
 
82
                        "QG_CadToolBarSnap::setCadToolBar(): No valid toolbar set.");
 
83
    }
 
84
}
 
85
 
 
86
void QG_CadToolBarSnap::snapFree() {
 
87
    if (actionHandler!=NULL) {
 
88
        disableSnaps();
 
89
        bFree->setChecked(true);
 
90
        actionHandler->slotSnapFree();
 
91
    }
 
92
}
 
93
 
 
94
void QG_CadToolBarSnap::snapGrid() {
 
95
    if (actionHandler!=NULL) {
 
96
        actionHandler->slotSnapGrid();
 
97
        disableSnaps();
 
98
        bGrid->setChecked(true);
 
99
    }
 
100
}
 
101
 
 
102
void QG_CadToolBarSnap::snapEndpoint() {
 
103
    if (actionHandler!=NULL) {
 
104
        actionHandler->slotSnapEndpoint();
 
105
        disableSnaps();
 
106
        bEndpoint->setChecked(true);
 
107
    }
 
108
}
 
109
 
 
110
void QG_CadToolBarSnap::snapOnEntity() {
 
111
    if (actionHandler!=NULL) {
 
112
        actionHandler->slotSnapOnEntity();
 
113
        disableSnaps();
 
114
        bOnEntity->setChecked(true);
 
115
    }
 
116
}
 
117
 
 
118
void QG_CadToolBarSnap::snapCenter() {
 
119
    if (actionHandler!=NULL) {
 
120
        actionHandler->slotSnapCenter();
 
121
        disableSnaps();
 
122
        bCenter->setChecked(true);
 
123
    }
 
124
}
 
125
 
 
126
void QG_CadToolBarSnap::snapMiddle() {
 
127
    if (actionHandler!=NULL) {
 
128
        actionHandler->slotSnapMiddle();
 
129
        disableSnaps();
 
130
        bMiddle->setChecked(true);
 
131
    }
 
132
}
 
133
 
 
134
void QG_CadToolBarSnap::snapDist() {
 
135
    if (actionHandler!=NULL) {
 
136
        actionHandler->slotSnapDist();
 
137
        disableSnaps();
 
138
        bDist->setChecked(true);
 
139
    }
 
140
}
 
141
 
 
142
void QG_CadToolBarSnap::snapIntersection() {
 
143
    if (actionHandler!=NULL) {
 
144
        actionHandler->slotSnapIntersection();
 
145
        disableSnaps();
 
146
        bIntersection->setChecked(true);
 
147
    }
 
148
}
 
149
 
 
150
void QG_CadToolBarSnap::snapIntersectionManual() {
 
151
    if (actionHandler!=NULL) {
 
152
        actionHandler->slotSnapIntersectionManual();
 
153
        //disableSnaps();
 
154
        //bIntersectionManual->setOn(true);
 
155
    }
 
156
}
 
157
 
 
158
void QG_CadToolBarSnap::restrictNothing() {
 
159
    if (actionHandler!=NULL) {
 
160
        actionHandler->slotRestrictNothing();
 
161
        disableRestrictions();
 
162
        bResNothing->setChecked(true);
 
163
    }
 
164
}
 
165
 
 
166
void QG_CadToolBarSnap::restrictOrthogonal() {
 
167
    if (actionHandler!=NULL) {
 
168
        actionHandler->slotRestrictOrthogonal();
 
169
        disableRestrictions();
 
170
        bResOrthogonal->setChecked(true);
 
171
    }
 
172
}
 
173
 
 
174
void QG_CadToolBarSnap::restrictHorizontal() {
 
175
    if (actionHandler!=NULL) {
 
176
        actionHandler->slotRestrictHorizontal();
 
177
        disableRestrictions();
 
178
        bResHorizontal->setChecked(true);
 
179
    }
 
180
}
 
181
 
 
182
void QG_CadToolBarSnap::restrictVertical() {
 
183
    if (actionHandler!=NULL) {
 
184
        actionHandler->slotRestrictVertical();
 
185
        disableRestrictions();
 
186
        bResVertical->setChecked(true);
 
187
    }
 
188
}
 
189
 
 
190
void QG_CadToolBarSnap::disableSnaps() {
 
191
    if (bFree->isChecked()) {
 
192
        bFree->setChecked(false);
 
193
    }
 
194
    if (bGrid->isChecked()) {
 
195
        bGrid->setChecked(false);
 
196
    }
 
197
    if (bEndpoint->isChecked()) {
 
198
        bEndpoint->setChecked(false);
 
199
    }
 
200
    if (bOnEntity->isChecked()) {
 
201
        bOnEntity->setChecked(false);
 
202
    }
 
203
    if (bCenter->isChecked()) {
 
204
        bCenter->setChecked(false);
 
205
    }
 
206
    if (bMiddle->isChecked()) {
 
207
        bMiddle->setChecked(false);
 
208
    }
 
209
    if (bDist->isChecked()) {
 
210
        bDist->setChecked(false);
 
211
    }
 
212
    if (bIntersection->isChecked()) {
 
213
        bIntersection->setChecked(false);
 
214
    }
 
215
    if (bIntersectionManual->isChecked()) {
 
216
        bIntersectionManual->setChecked(false);
 
217
    }
 
218
}
 
219
 
 
220
void QG_CadToolBarSnap::disableRestrictions() {
 
221
    if (bResNothing->isChecked()) {
 
222
        bResNothing->setChecked(false);
 
223
    }
 
224
    if (bResOrthogonal->isChecked()) {
 
225
        bResOrthogonal->setChecked(false);
 
226
    }
 
227
    if (bResHorizontal->isChecked()) {
 
228
        bResHorizontal->setChecked(false);
 
229
    }
 
230
    if (bResVertical->isChecked()) {
 
231
        bResVertical->setChecked(false);
 
232
    }
 
233
}
 
234
 
 
235
void QG_CadToolBarSnap::setSnapMode(int sm) {
 
236
    switch (sm) {
 
237
    case RS2::SnapFree:
 
238
        bFree->setChecked(true);
 
239
        break;
 
240
    case RS2::SnapEndpoint:
 
241
        bEndpoint->setChecked(true);
 
242
        break;
 
243
    case RS2::SnapGrid:
 
244
        bGrid->setChecked(true);
 
245
        break;
 
246
    case RS2::SnapOnEntity:
 
247
        bOnEntity->setChecked(true);
 
248
        break;
 
249
    case RS2::SnapCenter:
 
250
        bCenter->setChecked(true);
 
251
        break;
 
252
    case RS2::SnapMiddle:
 
253
        bMiddle->setChecked(true);
 
254
        break;
 
255
    case RS2::SnapDist:
 
256
        bDist->setChecked(true);
 
257
        break;
 
258
    case RS2::SnapIntersection:
 
259
        bIntersection->setChecked(true);
 
260
        break;
 
261
    default:
 
262
        break;
 
263
    }
 
264
}
 
265
 
 
266
void QG_CadToolBarSnap::setSnapRestriction(int sr) {
 
267
    switch (sr) {
 
268
    default:
 
269
    case RS2::RestrictNothing:
 
270
        bResNothing->setChecked(true);
 
271
        break;
 
272
    case RS2::RestrictOrthogonal:
 
273
        bResOrthogonal->setChecked(true);
 
274
        break;
 
275
    case RS2::RestrictHorizontal:
 
276
        bResHorizontal->setChecked(true);
 
277
        break;
 
278
    case RS2::RestrictVertical:
 
279
        bResVertical->setChecked(true);
 
280
        break;
 
281
    }
 
282
}
 
283
 
 
284
void QG_CadToolBarSnap::setRelativeZero() {
 
285
     if (cadToolBar!=NULL && actionHandler!=NULL) {
 
286
         actionHandler->slotSetRelativeZero();
 
287
     }
 
288
}
 
289
 
 
290
void QG_CadToolBarSnap::lockRelativeZero(bool on) {
 
291
     if (cadToolBar!=NULL && actionHandler!=NULL) {
 
292
         actionHandler->slotLockRelativeZero(on);
 
293
     }
 
294
}
 
295
 
 
296
void QG_CadToolBarSnap::setLockRelativeZero(bool on) {
 
297
    bLockRelZero->setChecked(on);
 
298
}
 
299
 
 
300
void QG_CadToolBarSnap::back() {
 
301
 
 
302
     if (actionHandler!=NULL) {
 
303
         actionHandler-> disableSnaps();
 
304
     }
 
305
    if (cadToolBar!=NULL) {
 
306
        snapFree(); //set to snapFree to hide all snapMode option widget displayed on toolbar
 
307
        disableSnaps();
 
308
        cadToolBar->back();
 
309
    }
 
310
}