1 
2 /*
3    Copyright (c) 2003-2007 Clarence Dang <dang@kde.org>
4    All rights reserved.
5 
6    Redistribution and use in source and binary forms, with or without
7    modification, are permitted provided that the following conditions
8    are met:
9 
10    1. Redistributions of source code must retain the above copyright
11       notice, this list of conditions and the following disclaimer.
12    2. Redistributions in binary form must reproduce the above copyright
13       notice, this list of conditions and the following disclaimer in the
14       documentation and/or other materials provided with the distribution.
15 
16    THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17    IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18    OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19    IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20    INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
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
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
25    THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27 
28 
29 #ifndef kpFreeFormImageSelection_H
30 #define kpFreeFormImageSelection_H
31 
32 
33 #include "layers/selections/image/kpAbstractImageSelection.h"
34 
35 
36 class kpFreeFormImageSelection : public kpAbstractImageSelection
37 {
38 Q_OBJECT
39 
40 public:
41     kpFreeFormImageSelection (const kpImageSelectionTransparency &transparency =
42         kpImageSelectionTransparency ());
43 
44     kpFreeFormImageSelection (const QPolygon &points,
45         const kpImage &baseImage = kpImage (),
46         const kpImageSelectionTransparency &transparency =
47             kpImageSelectionTransparency ());
48 
49     kpFreeFormImageSelection (const QPolygon &points,
50         const kpImageSelectionTransparency &transparency =
51             kpImageSelectionTransparency ());
52 
53     kpFreeFormImageSelection (const kpFreeFormImageSelection &rhs);
54 
55     kpFreeFormImageSelection &operator= (const kpFreeFormImageSelection &rhs);
56 
57     kpFreeFormImageSelection *clone () const override;
58 
59     ~kpFreeFormImageSelection () override;
60 
61 
62 //
63 // Marshalling
64 //
65 
66 public:
67     static const int SerialID = 2;
68     int serialID () const override;
69 
70     bool readFromStream (QDataStream &stream) override;
71 
72     void writeToStream (QDataStream &stream) const override;
73 
74 
75 //
76 // General Queries
77 //
78 
79 public:
80     kpCommandSize::SizeType size () const override;
81 
82     bool isRectangular () const override;
83 
84     // (as passed to the constructor)
85     QPolygon originalPoints () const;
86 
87 
88 //
89 // Cardinally Adjacent Points
90 //
91 
92 protected:
93     void recalculateCardinallyAdjacentPoints ();
94 
95 public:
96     // Returns the originalPoints() interpolated to be cardinally adjacent.
97     QPolygon cardinallyAdjacentPoints () const;
98 
99     // Returns cardinallyAdjacentPoints() but with extra points interpolated
100     // from the last point to the first point (the original points are
101     // thought of as a polygon where the first and last points are connected,
102     // rather than as a string of points).
103     //
104     // As used by the shape mask methods.
105     QPolygon cardinallyAdjacentPointsLoop () const;
106 
107 
108 //
109 // Position & Dimensions
110 //
111 
112 public:
113     // Implements kpAbstractSelection interface - same as
114     // cardinallyAdjacentPointsLoop ().
115     // This implementation is fast.
116     QPolygon calculatePoints () const override;
117 
118 
119 //
120 // Shape Mask
121 //
122 
123 public:
124     QRegion shapeRegion () const override;
125 
126 
127 //
128 // Point Testing
129 //
130 
131 public:
132     bool contains (const QPoint &point) const override;
133 
134 
135 //
136 // Mutation
137 //
138 
139 public:
140     void moveBy (int dx, int dy) override;
141 
142     void flip (bool horiz, bool vert) override;
143 
144 
145 //
146 // Rendering
147 //
148 
149 public:
150     void paintBorder (QImage *destPixmap, const QRect &docRect,
151         bool selectionFinished) const override;
152 
153 
154 private:
155     struct kpFreeFormImageSelectionPrivate * const d;
156 };
157 
158 
159 #endif  // kpFreeFormImageSelection_H
160