Code

Merge and cleanup of GSoC C++-ification project.
[inkscape.git] / src / snap-preferences.cpp
1 #define __SNAPPREFERENCES_CPP__
3 /**
4  *  \file snap-preferences.cpp
5  *  \brief Storing of snapping preferences
6  *
7  * Authors:
8  *   Diederik van Lierop <mail@diedenrezi.nl>
9  *
10  * Copyright (C) 2008 Authors
11  *
12  * Released under GNU GPL, read the file 'COPYING' for more information
13  */
15 #include "inkscape.h"
16 #include "snap-preferences.h"
18 Inkscape::SnapPreferences::SnapPreferences() :
19     _include_item_center(false),
20     _intersectionGG(true),
21     _snap_to_grids(true),
22     _snap_to_guides(true),
23     _snap_enabled_globally(true),
24     _snap_postponed_globally(false),
25     _snap_to_itemnode(true), _snap_to_itempath(true),
26     _snap_to_bboxnode(true), _snap_to_bboxpath(true),
27     _snap_to_page_border(false),
28     _strict_snapping(true)
29 {
30     setSnapFrom(SnapSourceType(SNAPSOURCE_BBOX_CATEGORY | SNAPSOURCE_NODE_CATEGORY | SNAPSOURCE_OTHER_CATEGORY), true); //Snap any point. In v0.45 and earlier, this was controlled in the preferences tab
31 }
33 /*
34  *  The snappers have too many parameters to adjust individually. Therefore only
35  *  two snapping modes are presented to the user: snapping bounding box corners (to
36  *  other bounding boxes, grids or guides), and/or snapping nodes (to other nodes,
37  *  paths, grids or guides). To select either of these modes (or both), use the
38  *  methods defined below: setSnapModeBBox() and setSnapModeNode().
39  *
40  * */
43 void Inkscape::SnapPreferences::setSnapModeBBox(bool enabled)
44 {
45     if (enabled) {
46         _snap_from = SnapSourceType(_snap_from | Inkscape::SNAPSOURCE_BBOX_CATEGORY);
47     } else {
48         _snap_from = SnapSourceType(_snap_from & ~Inkscape::SNAPSOURCE_BBOX_CATEGORY);
49     }
50 }
52 bool Inkscape::SnapPreferences::getSnapModeBBox() const
53 {
54     return (_snap_from & Inkscape::SNAPSOURCE_BBOX_CATEGORY);
55 }
57 void Inkscape::SnapPreferences::setSnapModeNode(bool enabled)
58 {
59     if (enabled) {
60         _snap_from = SnapSourceType(_snap_from | Inkscape::SNAPSOURCE_NODE_CATEGORY);
61     } else {
62         _snap_from = SnapSourceType(_snap_from & ~Inkscape::SNAPSOURCE_NODE_CATEGORY);
63     }
64 }
66 bool Inkscape::SnapPreferences::getSnapModeNode() const
67 {
68     return (_snap_from & Inkscape::SNAPSOURCE_NODE_CATEGORY);
69 }
71 bool Inkscape::SnapPreferences::getSnapModeBBoxOrNodes() const
72 {
73     return (_snap_from & (Inkscape::SNAPSOURCE_BBOX_CATEGORY | Inkscape::SNAPSOURCE_NODE_CATEGORY) );
74 }
76 bool Inkscape::SnapPreferences::getSnapModeAny() const
77 {
78     return (_snap_from != 0);
79 }
81 void Inkscape::SnapPreferences::setSnapModeGuide(bool enabled)
82 {
83     if (enabled) {
84         _snap_from = SnapSourceType(_snap_from | Inkscape::SNAPSOURCE_OTHER_CATEGORY);
85     } else {
86         _snap_from = SnapSourceType(_snap_from & ~Inkscape::SNAPSOURCE_OTHER_CATEGORY);
87     }
88 }
90 bool Inkscape::SnapPreferences::getSnapModeGuide() const
91 {
92     return (_snap_from & Inkscape::SNAPSOURCE_OTHER_CATEGORY);
93 }
95 /**
96  *  Turn on/off snapping of specific point types.
97  *  \param t Point type.
98  *  \param s true to snap to this point type, otherwise false;
99  */
100 void Inkscape::SnapPreferences::setSnapFrom(Inkscape::SnapSourceType t, bool s)
102     if (s) {
103         _snap_from = SnapSourceType(_snap_from | t);
104     } else {
105         _snap_from = SnapSourceType(_snap_from & ~t);
106     }
109 /**
110  *  \param t Point type.
111  *  \return true if snapper will snap this type of point, otherwise false.
112  */
113 bool Inkscape::SnapPreferences::getSnapFrom(Inkscape::SnapSourceType t) const
115     return (_snap_from & t);
118 /*
119   Local Variables:
120   mode:c++
121   c-file-style:"stroustrup"
122   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
123   indent-tabs-mode:nil
124   fill-column:99
125   End:
126 */
127 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :