1
/****************************************************************************
3
** This file is part of the LibreCAD project, a 2D CAD program
5
** Copyright (C) 2010 R. van Twisk (librecad@rvt.dds.nl)
6
** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
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.
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.
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
23
** This copyright notice MUST APPEAR in all copies of the script!
25
**********************************************************************/
26
#include "qg_cadtoolbarsnap.h"
28
#include "qg_cadtoolbar.h"
31
* Constructs a QG_CadToolBarSnap as a child of 'parent', with the
32
* name 'name' and widget flags set to 'f'.
34
QG_CadToolBarSnap::QG_CadToolBarSnap(QWidget* parent, Qt::WindowFlags fl)
43
* Destroys the object and frees any allocated resources
45
QG_CadToolBarSnap::~QG_CadToolBarSnap()
47
// no need to delete child widgets, Qt does it all for us
51
* Sets the strings of the subwidgets using the current
54
void QG_CadToolBarSnap::languageChange()
59
void QG_CadToolBarSnap::init() {
64
//void QG_CadToolBarSnap::mousePressEvent(QMouseEvent* e) {
65
// if (e->button()==RightButton && cadToolBar!=NULL) {
71
void QG_CadToolBarSnap::contextMenuEvent(QContextMenuEvent *e) {
75
void QG_CadToolBarSnap::setCadToolBar(QG_CadToolBar* tb) {
78
actionHandler = tb->getActionHandler();
79
actionHandler->setCadToolBarSnap(this);
81
RS_DEBUG->print(RS_Debug::D_ERROR,
82
"QG_CadToolBarSnap::setCadToolBar(): No valid toolbar set.");
86
void QG_CadToolBarSnap::snapFree() {
87
if (actionHandler!=NULL) {
89
bFree->setChecked(true);
90
actionHandler->slotSnapFree();
94
void QG_CadToolBarSnap::snapGrid() {
95
if (actionHandler!=NULL) {
96
actionHandler->slotSnapGrid();
98
bGrid->setChecked(true);
102
void QG_CadToolBarSnap::snapEndpoint() {
103
if (actionHandler!=NULL) {
104
actionHandler->slotSnapEndpoint();
106
bEndpoint->setChecked(true);
110
void QG_CadToolBarSnap::snapOnEntity() {
111
if (actionHandler!=NULL) {
112
actionHandler->slotSnapOnEntity();
114
bOnEntity->setChecked(true);
118
void QG_CadToolBarSnap::snapCenter() {
119
if (actionHandler!=NULL) {
120
actionHandler->slotSnapCenter();
122
bCenter->setChecked(true);
126
void QG_CadToolBarSnap::snapMiddle() {
127
if (actionHandler!=NULL) {
128
actionHandler->slotSnapMiddle();
130
bMiddle->setChecked(true);
134
void QG_CadToolBarSnap::snapDist() {
135
if (actionHandler!=NULL) {
136
actionHandler->slotSnapDist();
138
bDist->setChecked(true);
142
void QG_CadToolBarSnap::snapIntersection() {
143
if (actionHandler!=NULL) {
144
actionHandler->slotSnapIntersection();
146
bIntersection->setChecked(true);
150
void QG_CadToolBarSnap::snapIntersectionManual() {
151
if (actionHandler!=NULL) {
152
actionHandler->slotSnapIntersectionManual();
154
//bIntersectionManual->setOn(true);
158
void QG_CadToolBarSnap::restrictNothing() {
159
if (actionHandler!=NULL) {
160
actionHandler->slotRestrictNothing();
161
disableRestrictions();
162
bResNothing->setChecked(true);
166
void QG_CadToolBarSnap::restrictOrthogonal() {
167
if (actionHandler!=NULL) {
168
actionHandler->slotRestrictOrthogonal();
169
disableRestrictions();
170
bResOrthogonal->setChecked(true);
174
void QG_CadToolBarSnap::restrictHorizontal() {
175
if (actionHandler!=NULL) {
176
actionHandler->slotRestrictHorizontal();
177
disableRestrictions();
178
bResHorizontal->setChecked(true);
182
void QG_CadToolBarSnap::restrictVertical() {
183
if (actionHandler!=NULL) {
184
actionHandler->slotRestrictVertical();
185
disableRestrictions();
186
bResVertical->setChecked(true);
190
void QG_CadToolBarSnap::disableSnaps() {
191
if (bFree->isChecked()) {
192
bFree->setChecked(false);
194
if (bGrid->isChecked()) {
195
bGrid->setChecked(false);
197
if (bEndpoint->isChecked()) {
198
bEndpoint->setChecked(false);
200
if (bOnEntity->isChecked()) {
201
bOnEntity->setChecked(false);
203
if (bCenter->isChecked()) {
204
bCenter->setChecked(false);
206
if (bMiddle->isChecked()) {
207
bMiddle->setChecked(false);
209
if (bDist->isChecked()) {
210
bDist->setChecked(false);
212
if (bIntersection->isChecked()) {
213
bIntersection->setChecked(false);
215
if (bIntersectionManual->isChecked()) {
216
bIntersectionManual->setChecked(false);
220
void QG_CadToolBarSnap::disableRestrictions() {
221
if (bResNothing->isChecked()) {
222
bResNothing->setChecked(false);
224
if (bResOrthogonal->isChecked()) {
225
bResOrthogonal->setChecked(false);
227
if (bResHorizontal->isChecked()) {
228
bResHorizontal->setChecked(false);
230
if (bResVertical->isChecked()) {
231
bResVertical->setChecked(false);
235
void QG_CadToolBarSnap::setSnapMode(int sm) {
238
bFree->setChecked(true);
240
case RS2::SnapEndpoint:
241
bEndpoint->setChecked(true);
244
bGrid->setChecked(true);
246
case RS2::SnapOnEntity:
247
bOnEntity->setChecked(true);
249
case RS2::SnapCenter:
250
bCenter->setChecked(true);
252
case RS2::SnapMiddle:
253
bMiddle->setChecked(true);
256
bDist->setChecked(true);
258
case RS2::SnapIntersection:
259
bIntersection->setChecked(true);
266
void QG_CadToolBarSnap::setSnapRestriction(int sr) {
269
case RS2::RestrictNothing:
270
bResNothing->setChecked(true);
272
case RS2::RestrictOrthogonal:
273
bResOrthogonal->setChecked(true);
275
case RS2::RestrictHorizontal:
276
bResHorizontal->setChecked(true);
278
case RS2::RestrictVertical:
279
bResVertical->setChecked(true);
284
void QG_CadToolBarSnap::setRelativeZero() {
285
if (cadToolBar!=NULL && actionHandler!=NULL) {
286
actionHandler->slotSetRelativeZero();
290
void QG_CadToolBarSnap::lockRelativeZero(bool on) {
291
if (cadToolBar!=NULL && actionHandler!=NULL) {
292
actionHandler->slotLockRelativeZero(on);
296
void QG_CadToolBarSnap::setLockRelativeZero(bool on) {
297
bLockRelZero->setChecked(on);
300
void QG_CadToolBarSnap::back() {
302
if (actionHandler!=NULL) {
303
actionHandler-> disableSnaps();
305
if (cadToolBar!=NULL) {
306
snapFree(); //set to snapFree to hide all snapMode option widget displayed on toolbar