Changeset View
Changeset View
Standalone View
Standalone View
layers/selections/kpAbstractSelection.cpp
Show First 20 Lines • Show All 55 Lines • ▼ Show 20 Line(s) | 55 | : QObject (), | |||
---|---|---|---|---|---|
56 | d (new kpAbstractSelectionPrivate ()) | 56 | d (new kpAbstractSelectionPrivate ()) | ||
57 | { | 57 | { | ||
58 | d->rect = rect; | 58 | d->rect = rect; | ||
59 | } | 59 | } | ||
60 | 60 | | |||
61 | // protected | 61 | // protected | ||
62 | kpAbstractSelection &kpAbstractSelection::operator= (const kpAbstractSelection &rhs) | 62 | kpAbstractSelection &kpAbstractSelection::operator= (const kpAbstractSelection &rhs) | ||
63 | { | 63 | { | ||
64 | if (this == &rhs) | 64 | if (this == &rhs) { | ||
65 | return *this; | 65 | return *this; | ||
66 | } | ||||
66 | 67 | | |||
67 | d->rect = rhs.d->rect; | 68 | d->rect = rhs.d->rect; | ||
68 | 69 | | |||
69 | return *this; | 70 | return *this; | ||
70 | } | 71 | } | ||
71 | 72 | | |||
72 | // protected | 73 | // protected | ||
73 | kpAbstractSelection::~kpAbstractSelection () | 74 | kpAbstractSelection::~kpAbstractSelection () | ||
Show All 16 Lines | 90 | { | |||
90 | stream << d->rect; | 91 | stream << d->rect; | ||
91 | } | 92 | } | ||
92 | 93 | | |||
93 | // friend | 94 | // friend | ||
94 | QDataStream &operator<< (QDataStream &stream, const kpAbstractSelection &selection) | 95 | QDataStream &operator<< (QDataStream &stream, const kpAbstractSelection &selection) | ||
95 | { | 96 | { | ||
96 | #if DEBUG_KP_SELECTION && 1 | 97 | #if DEBUG_KP_SELECTION && 1 | ||
97 | qCDebug(kpLogLayers) << "kpAbstractSelection::operator<<(sel: rect=" << | 98 | qCDebug(kpLogLayers) << "kpAbstractSelection::operator<<(sel: rect=" << | ||
98 | selection.boundingRect () << endl; | 99 | selection.boundingRect (); | ||
99 | #endif | 100 | #endif | ||
100 | stream << selection.serialID (); | 101 | stream << selection.serialID (); | ||
101 | selection.writeToStream (stream); | 102 | selection.writeToStream (stream); | ||
102 | return stream; | 103 | return stream; | ||
103 | } | 104 | } | ||
104 | 105 | | |||
105 | 106 | | |||
106 | // public virtual | 107 | // public virtual | ||
107 | kpCommandSize::SizeType kpAbstractSelection::size () const | 108 | kpCommandSize::SizeType kpAbstractSelection::size () const | ||
108 | { | 109 | { | ||
109 | return 0/*constant size*/; | 110 | return 0/*constant size*/; | ||
110 | } | 111 | } | ||
111 | 112 | | |||
112 | 113 | | |||
113 | // public | 114 | // public | ||
114 | QSize kpAbstractSelection::minimumSize () const | 115 | QSize kpAbstractSelection::minimumSize () const | ||
115 | { | 116 | { | ||
116 | return QSize (minimumWidth (), minimumHeight ()); | 117 | return {minimumWidth (), minimumHeight ()}; | ||
117 | } | 118 | } | ||
118 | 119 | | |||
119 | 120 | | |||
120 | // public | 121 | // public | ||
121 | int kpAbstractSelection::x () const | 122 | int kpAbstractSelection::x () const | ||
122 | { | 123 | { | ||
123 | return d->rect.x (); | 124 | return d->rect.x (); | ||
124 | } | 125 | } | ||
Show All 32 Lines | |||||
157 | // public static | 158 | // public static | ||
158 | QPolygon kpAbstractSelection::CalculatePointsForRectangle (const QRect &rect) | 159 | QPolygon kpAbstractSelection::CalculatePointsForRectangle (const QRect &rect) | ||
159 | { | 160 | { | ||
160 | QPolygon points; | 161 | QPolygon points; | ||
161 | 162 | | |||
162 | // OPT: not space optimal - current code adds duplicate corner points. | 163 | // OPT: not space optimal - current code adds duplicate corner points. | ||
163 | 164 | | |||
164 | // top | 165 | // top | ||
165 | for (int x = 0; x < rect.width (); x++) | 166 | for (int x = 0; x < rect.width (); x++) { | ||
166 | points.append (QPoint (rect.x () + x, rect.top ())); | 167 | points.append (QPoint (rect.x () + x, rect.top ())); | ||
168 | } | ||||
167 | 169 | | |||
168 | // right | 170 | // right | ||
169 | for (int y = 0; y < rect.height (); y++) | 171 | for (int y = 0; y < rect.height (); y++) { | ||
170 | points.append (QPoint (rect.right (), rect.y () + y)); | 172 | points.append (QPoint (rect.right (), rect.y () + y)); | ||
173 | } | ||||
171 | 174 | | |||
172 | // bottom | 175 | // bottom | ||
173 | for (int x = rect.width () - 1; x >= 0; x--) | 176 | for (int x = rect.width () - 1; x >= 0; x--) { | ||
174 | points.append (QPoint (rect.x () + x, rect.bottom ())); | 177 | points.append (QPoint (rect.x () + x, rect.bottom ())); | ||
178 | } | ||||
175 | 179 | | |||
176 | // left | 180 | // left | ||
177 | for (int y = rect.height () - 1; y >= 0; y--) | 181 | for (int y = rect.height () - 1; y >= 0; y--) { | ||
178 | points.append (QPoint (rect.left (), rect.y () + y)); | 182 | points.append (QPoint (rect.left (), rect.y () + y)); | ||
183 | } | ||||
179 | 184 | | |||
180 | return points; | 185 | return points; | ||
181 | } | 186 | } | ||
182 | 187 | | |||
183 | 188 | | |||
184 | // public | 189 | // public | ||
185 | bool kpAbstractSelection::contains (int x, int y) const | 190 | bool kpAbstractSelection::contains (int x, int y) const | ||
186 | { | 191 | { | ||
187 | return contains (QPoint (x, y)); | 192 | return contains (QPoint (x, y)); | ||
188 | } | 193 | } | ||
189 | 194 | | |||
190 | 195 | | |||
191 | // public virtual | 196 | // public virtual | ||
192 | void kpAbstractSelection::moveBy (int dx, int dy) | 197 | void kpAbstractSelection::moveBy (int dx, int dy) | ||
193 | { | 198 | { | ||
194 | #if DEBUG_KP_SELECTION && 1 | 199 | #if DEBUG_KP_SELECTION && 1 | ||
195 | qCDebug(kpLogLayers) << "kpAbstractSelection::moveBy(" << dx << "," << dy << ")"; | 200 | qCDebug(kpLogLayers) << "kpAbstractSelection::moveBy(" << dx << "," << dy << ")"; | ||
196 | #endif | 201 | #endif | ||
197 | 202 | | |||
198 | if (dx == 0 && dy == 0) | 203 | if (dx == 0 && dy == 0) { | ||
199 | return; | 204 | return; | ||
205 | } | ||||
200 | 206 | | |||
201 | QRect oldRect = boundingRect (); | 207 | QRect oldRect = boundingRect (); | ||
202 | 208 | | |||
203 | #if DEBUG_KP_SELECTION && 1 | 209 | #if DEBUG_KP_SELECTION && 1 | ||
204 | qCDebug(kpLogLayers) << "\toldRect=" << oldRect; | 210 | qCDebug(kpLogLayers) << "\toldRect=" << oldRect; | ||
205 | #endif | 211 | #endif | ||
206 | 212 | | |||
207 | d->rect.translate (dx, dy); | 213 | d->rect.translate (dx, dy); | ||
Show All 16 Lines | |||||
224 | { | 230 | { | ||
225 | #if DEBUG_KP_SELECTION && 1 | 231 | #if DEBUG_KP_SELECTION && 1 | ||
226 | qCDebug(kpLogLayers) << "kpAbstractSelection::moveTo(" << topLeftPoint << ")"; | 232 | qCDebug(kpLogLayers) << "kpAbstractSelection::moveTo(" << topLeftPoint << ")"; | ||
227 | #endif | 233 | #endif | ||
228 | QRect oldBoundingRect = boundingRect (); | 234 | QRect oldBoundingRect = boundingRect (); | ||
229 | #if DEBUG_KP_SELECTION && 1 | 235 | #if DEBUG_KP_SELECTION && 1 | ||
230 | qCDebug(kpLogLayers) << "\toldBoundingRect=" << oldBoundingRect; | 236 | qCDebug(kpLogLayers) << "\toldBoundingRect=" << oldBoundingRect; | ||
231 | #endif | 237 | #endif | ||
232 | if (topLeftPoint == oldBoundingRect.topLeft ()) | 238 | if (topLeftPoint == oldBoundingRect.topLeft ()) { | ||
233 | return; | 239 | return; | ||
240 | } | ||||
234 | 241 | | |||
235 | QPoint delta (topLeftPoint - oldBoundingRect.topLeft ()); | 242 | QPoint delta (topLeftPoint - oldBoundingRect.topLeft ()); | ||
236 | moveBy (delta.x (), delta.y ()); | 243 | moveBy (delta.x (), delta.y ()); | ||
237 | } | 244 | } | ||
238 | 245 | | |||
239 | //--------------------------------------------------------------------- | 246 | //--------------------------------------------------------------------- | ||
240 | 247 | | |||
241 | // protected | 248 | // protected | ||
242 | void kpAbstractSelection::paintRectangularBorder (QImage *destPixmap, | 249 | void kpAbstractSelection::paintRectangularBorder (QImage *destPixmap, | ||
243 | const QRect &docRect, | 250 | const QRect &docRect, | ||
244 | bool selectionFinished) const | 251 | bool selectionFinished) const | ||
245 | { | 252 | { | ||
246 | (void) selectionFinished; | 253 | (void) selectionFinished; | ||
247 | 254 | | |||
248 | #if DEBUG_KP_SELECTION && 1 | 255 | #if DEBUG_KP_SELECTION && 1 | ||
249 | qCDebug(kpLogLayers) << "kpAbstractSelection::paintRectangularBorder() boundingRect=" | 256 | qCDebug(kpLogLayers) << "kpAbstractSelection::paintRectangularBorder() boundingRect=" | ||
250 | << boundingRect () << endl; | 257 | << boundingRect (); | ||
251 | #endif | 258 | #endif | ||
252 | 259 | | |||
253 | #if DEBUG_KP_SELECTION && 1 | 260 | #if DEBUG_KP_SELECTION && 1 | ||
254 | qCDebug(kpLogLayers) << "\tselection border = rectangle"; | 261 | qCDebug(kpLogLayers) << "\tselection border = rectangle"; | ||
255 | qCDebug(kpLogLayers) << "\t\tx=" << boundingRect ().x () - docRect.x () | 262 | qCDebug(kpLogLayers) << "\t\tx=" << boundingRect ().x () - docRect.x () | ||
256 | << " y=" << boundingRect ().y () - docRect.y () | 263 | << " y=" << boundingRect ().y () - docRect.y () | ||
257 | << " w=" << boundingRect ().width () | 264 | << " w=" << boundingRect ().width () | ||
258 | << " h=" << boundingRect ().height () | 265 | << " h=" << boundingRect ().height (); | ||
259 | << endl; | | |||
260 | #endif | 266 | #endif | ||
261 | kpPixmapFX::drawStippleRect(destPixmap, | 267 | kpPixmapFX::drawStippleRect(destPixmap, | ||
262 | boundingRect ().x () - docRect.x (), | 268 | boundingRect ().x () - docRect.x (), | ||
263 | boundingRect ().y () - docRect.y (), | 269 | boundingRect ().y () - docRect.y (), | ||
264 | boundingRect ().width (), | 270 | boundingRect ().width (), | ||
265 | boundingRect ().height (), | 271 | boundingRect ().height (), | ||
266 | kpColor::Blue, | 272 | kpColor::Blue, | ||
267 | kpColor::Yellow); | 273 | kpColor::Yellow); | ||
268 | } | 274 | } | ||
269 | 275 | | |||
270 | //--------------------------------------------------------------------- | 276 | //--------------------------------------------------------------------- | ||
271 | 277 | | |||
272 | // protected | 278 | // protected | ||
273 | void kpAbstractSelection::paintPolygonalBorder (const QPolygon &points, | 279 | void kpAbstractSelection::paintPolygonalBorder (const QPolygon &points, | ||
274 | QImage *destPixmap, | 280 | QImage *destPixmap, | ||
275 | const QRect &docRect, | 281 | const QRect &docRect, | ||
276 | bool selectionFinished) const | 282 | bool selectionFinished) const | ||
277 | { | 283 | { | ||
278 | #if DEBUG_KP_SELECTION && 1 | 284 | #if DEBUG_KP_SELECTION && 1 | ||
279 | qCDebug(kpLogLayers) << "kpAbstractSelection::paintPolygonalBorder() boundingRect=" | 285 | qCDebug(kpLogLayers) << "kpAbstractSelection::paintPolygonalBorder() boundingRect=" | ||
280 | << boundingRect () << endl; | 286 | << boundingRect (); | ||
281 | #endif | 287 | #endif | ||
282 | 288 | | |||
283 | QPolygon pointsTranslated = points; | 289 | QPolygon pointsTranslated = points; | ||
284 | pointsTranslated.translate (-docRect.x (), -docRect.y ()); | 290 | pointsTranslated.translate (-docRect.x (), -docRect.y ()); | ||
285 | 291 | | |||
286 | if ( !selectionFinished ) | 292 | if ( !selectionFinished ) | ||
287 | { | 293 | { | ||
288 | kpPixmapFX::drawPolyline(destPixmap, | 294 | kpPixmapFX::drawPolyline(destPixmap, | ||
Show All 21 Lines |