Changeset View
Changeset View
Standalone View
Standalone View
tools/selection/image/kpToolFreeFormSelection.cpp
Show All 19 Lines | 2 | /* | |||
---|---|---|---|---|---|
20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
21 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 21 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
22 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 22 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
23 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 23 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
25 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | 26 | */ | ||
27 | 27 | | |||
28 | | ||||
29 | #define DEBUG_KP_TOOL_FREE_FROM_SELECTION 0 | | |||
30 | | ||||
31 | | ||||
32 | #include "kpToolFreeFormSelection.h" | 28 | #include "kpToolFreeFormSelection.h" | ||
33 | 29 | | |||
34 | #include "kpLogCategories.h" | 30 | #include "kpLogCategories.h" | ||
35 | #include <KLocalizedString> | 31 | #include <KLocalizedString> | ||
36 | 32 | | |||
37 | #include "document/kpDocument.h" | 33 | #include "document/kpDocument.h" | ||
38 | #include "layers/selections/image/kpFreeFormImageSelection.h" | 34 | #include "layers/selections/image/kpFreeFormImageSelection.h" | ||
39 | #include "environments/tools/selection/kpToolSelectionEnvironment.h" | 35 | #include "environments/tools/selection/kpToolSelectionEnvironment.h" | ||
Show All 19 Lines | |||||
59 | //--------------------------------------------------------------------- | 55 | //--------------------------------------------------------------------- | ||
60 | 56 | | |||
61 | // protected virtual [base kpAbstractSelectionTool] | 57 | // protected virtual [base kpAbstractSelectionTool] | ||
62 | bool kpToolFreeFormSelection::drawCreateMoreSelectionAndUpdateStatusBar ( | 58 | bool kpToolFreeFormSelection::drawCreateMoreSelectionAndUpdateStatusBar ( | ||
63 | bool dragAccepted, | 59 | bool dragAccepted, | ||
64 | const QPoint &accidentalDragAdjustedPoint, | 60 | const QPoint &accidentalDragAdjustedPoint, | ||
65 | const QRect &/*normalizedRect*/) | 61 | const QRect &/*normalizedRect*/) | ||
66 | { | 62 | { | ||
67 | #if DEBUG_KP_TOOL_FREE_FROM_SELECTION | | |||
68 | qCDebug(kpLogTools) << "kpToolFreeFormSelection::createMoreSelectionAndUpdateStatusBar(" | 63 | qCDebug(kpLogTools) << "kpToolFreeFormSelection::createMoreSelectionAndUpdateStatusBar(" | ||
69 | << "dragAccepted=" << dragAccepted | 64 | << "dragAccepted=" << dragAccepted | ||
70 | << ",accidentalDragAdjustedPoint=" << accidentalDragAdjustedPoint | 65 | << ",accidentalDragAdjustedPoint=" << accidentalDragAdjustedPoint | ||
71 | << ")" << endl; | 66 | << ")"; | ||
72 | #endif | | |||
73 | 67 | | |||
74 | // Prevent unintentional creation of 1-pixel selections. | 68 | // Prevent unintentional creation of 1-pixel selections. | ||
75 | if (!dragAccepted && accidentalDragAdjustedPoint == startPoint ()) | 69 | if (!dragAccepted && accidentalDragAdjustedPoint == startPoint ()) | ||
76 | { | 70 | { | ||
77 | #if DEBUG_KP_TOOL_FREE_FROM_SELECTION && 1 | | |||
78 | qCDebug(kpLogTools) << "\tnon-text NOP - return"; | 71 | qCDebug(kpLogTools) << "\tnon-text NOP - return"; | ||
79 | #endif | | |||
80 | setUserShapePoints (accidentalDragAdjustedPoint); | 72 | setUserShapePoints (accidentalDragAdjustedPoint); | ||
81 | return false; | 73 | return false; | ||
82 | } | 74 | } | ||
83 | 75 | | |||
84 | Q_ASSERT (accidentalDragAdjustedPoint == currentPoint ()); | 76 | Q_ASSERT (accidentalDragAdjustedPoint == currentPoint ()); | ||
85 | Q_ASSERT (dragAccepted == static_cast<bool> (document ()->selection ())); | 77 | Q_ASSERT (dragAccepted == static_cast<bool> (document ()->selection ())); | ||
86 | 78 | | |||
87 | const kpFreeFormImageSelection *oldPointsSel = nullptr; | 79 | const kpFreeFormImageSelection *oldPointsSel = nullptr; | ||
Show All 16 Lines | |||||
104 | else | 96 | else | ||
105 | { | 97 | { | ||
106 | if ( !oldPointsSel ) // assert above says we never reach this, but let's make coverity happy | 98 | if ( !oldPointsSel ) // assert above says we never reach this, but let's make coverity happy | ||
107 | return false; | 99 | return false; | ||
108 | 100 | | |||
109 | // Get existing points in selection. | 101 | // Get existing points in selection. | ||
110 | points = oldPointsSel->cardinallyAdjacentPoints (); | 102 | points = oldPointsSel->cardinallyAdjacentPoints (); | ||
111 | } | 103 | } | ||
112 | | ||||
113 | | ||||
114 | #if DEBUG_KP_TOOL_FREE_FROM_SELECTION | | |||
115 | qCDebug(kpLogTools) << "\tlast old point=" << points.last (); | 104 | qCDebug(kpLogTools) << "\tlast old point=" << points.last (); | ||
116 | #endif | | |||
117 | 105 | | |||
118 | // TODO: There should be an upper limit on this before drawing the | 106 | // TODO: There should be an upper limit on this before drawing the | ||
119 | // polygon becomes too slow. | 107 | // polygon becomes too slow. | ||
120 | points.append (accidentalDragAdjustedPoint); | 108 | points.append (accidentalDragAdjustedPoint); | ||
121 | 109 | | |||
122 | 110 | | |||
123 | document ()->setSelection ( | 111 | document ()->setSelection ( | ||
124 | kpFreeFormImageSelection (points, environ ()->imageSelectionTransparency ())); | 112 | kpFreeFormImageSelection (points, environ ()->imageSelectionTransparency ())); | ||
125 | 113 | | |||
126 | // Prevent accidental usage of dangling pointer to old selection | 114 | // Prevent accidental usage of dangling pointer to old selection | ||
127 | // (deleted by kpDocument::setSelection()). | 115 | // (deleted by kpDocument::setSelection()). | ||
128 | oldPointsSel = nullptr; | 116 | oldPointsSel = nullptr; | ||
129 | 117 | | |||
130 | #if DEBUG_KP_TOOL_FREE_FROM_SELECTION && 1 | | |||
131 | qCDebug(kpLogTools) << "\t\tfreeform; #points=" | 118 | qCDebug(kpLogTools) << "\t\tfreeform; #points=" | ||
132 | << document ()->selection ()->calculatePoints ().count () | 119 | << document ()->selection ()->calculatePoints ().count (); | ||
133 | << endl; | | |||
134 | #endif | | |||
135 | 120 | | |||
136 | setUserShapePoints (accidentalDragAdjustedPoint); | 121 | setUserShapePoints (accidentalDragAdjustedPoint); | ||
137 | 122 | | |||
138 | return true; | 123 | return true; | ||
139 | } | 124 | } | ||
140 | 125 | | |||
141 | //--------------------------------------------------------------------- | 126 | //--------------------------------------------------------------------- |