Changeset View
Changeset View
Standalone View
Standalone View
document/kpDocument_Selection.cpp
Show First 20 Lines • Show All 70 Lines • ▼ Show 20 Line(s) | |||||
71 | } | 71 | } | ||
72 | 72 | | |||
73 | //--------------------------------------------------------------------- | 73 | //--------------------------------------------------------------------- | ||
74 | 74 | | |||
75 | // public | 75 | // public | ||
76 | void kpDocument::setSelection (const kpAbstractSelection &selection) | 76 | void kpDocument::setSelection (const kpAbstractSelection &selection) | ||
77 | { | 77 | { | ||
78 | qCDebug(kpLogDocument) << "kpDocument::setSelection() sel boundingRect=" | 78 | qCDebug(kpLogDocument) << "kpDocument::setSelection() sel boundingRect=" | ||
79 | << selection.boundingRect () | 79 | << selection.boundingRect (); | ||
80 | << endl; | | |||
81 | 80 | | |||
82 | d->environ->setQueueViewUpdates (); | 81 | d->environ->setQueueViewUpdates (); | ||
83 | { | 82 | { | ||
84 | const bool hadSelection = static_cast<bool> (m_selection); | 83 | const bool hadSelection = static_cast<bool> (m_selection); | ||
85 | kpAbstractSelection *oldSelection = m_selection; | 84 | auto *oldSelection = m_selection; | ||
86 | 85 | | |||
87 | 86 | | |||
88 | // (must be called before giving the document a new selection, to | 87 | // (must be called before giving the document a new selection, to | ||
89 | // avoid a potential mess where switchToCompatibleTool() ends | 88 | // avoid a potential mess where switchToCompatibleTool() ends | ||
90 | // the current selection tool, killing the new selection) | 89 | // the current selection tool, killing the new selection) | ||
91 | bool isTextChanged = false; | 90 | bool isTextChanged = false; | ||
92 | d->environ->switchToCompatibleTool (selection, &isTextChanged); | 91 | d->environ->switchToCompatibleTool (selection, &isTextChanged); | ||
93 | Q_ASSERT (m_selection == oldSelection); | 92 | Q_ASSERT (m_selection == oldSelection); | ||
Show All 19 Lines | |||||
113 | 112 | | |||
114 | // | 113 | // | ||
115 | // Now all kpDocument and environment state has been set. | 114 | // Now all kpDocument and environment state has been set. | ||
116 | // We can _only_ fire signals after that, as the signal receivers (the | 115 | // We can _only_ fire signals after that, as the signal receivers (the | ||
117 | // "wider environment") may access the document and the environment. | 116 | // "wider environment") may access the document and the environment. | ||
118 | // | 117 | // | ||
119 | 118 | | |||
120 | qCDebug(kpLogDocument) << "\tcheck sel " << (int *) m_selection | 119 | qCDebug(kpLogDocument) << "\tcheck sel " << (int *) m_selection | ||
121 | << " boundingRect=" << m_selection->boundingRect () | 120 | << " boundingRect=" << m_selection->boundingRect (); | ||
122 | << endl; | | |||
123 | if (oldSelection) | 121 | if (oldSelection) | ||
124 | { | 122 | { | ||
125 | if (oldSelection->hasContent ()) | 123 | if (oldSelection->hasContent ()) { | ||
126 | slotContentsChanged (oldSelection->boundingRect ()); | 124 | slotContentsChanged (oldSelection->boundingRect ()); | ||
127 | else | 125 | } | ||
126 | else { | ||||
128 | emit contentsChanged (oldSelection->boundingRect ()); | 127 | emit contentsChanged (oldSelection->boundingRect ()); | ||
128 | } | ||||
129 | 129 | | |||
130 | delete oldSelection; | 130 | delete oldSelection; | ||
131 | oldSelection = nullptr; | 131 | oldSelection = nullptr; | ||
132 | } | 132 | } | ||
133 | 133 | | |||
134 | if (m_selection->hasContent ()) | 134 | if (m_selection->hasContent ()) { | ||
135 | slotContentsChanged (m_selection->boundingRect ()); | 135 | slotContentsChanged (m_selection->boundingRect ()); | ||
136 | else | 136 | } | ||
137 | else { | ||||
137 | emit contentsChanged (m_selection->boundingRect ()); | 138 | emit contentsChanged (m_selection->boundingRect ()); | ||
139 | } | ||||
138 | 140 | | |||
139 | 141 | | |||
140 | if (!hadSelection) | 142 | if (!hadSelection) { | ||
141 | emit selectionEnabled (true); | 143 | emit selectionEnabled (true); | ||
144 | } | ||||
142 | 145 | | |||
143 | if (isTextChanged) | 146 | if (isTextChanged) { | ||
144 | emit selectionIsTextChanged (textSelection ()); | 147 | emit selectionIsTextChanged (textSelection ()); | ||
145 | } | 148 | } | ||
149 | } | ||||
146 | d->environ->restoreQueueViewUpdates (); | 150 | d->environ->restoreQueueViewUpdates (); | ||
147 | 151 | | |||
148 | qCDebug(kpLogDocument) << "\tkpDocument::setSelection() ended"; | 152 | qCDebug(kpLogDocument) << "\tkpDocument::setSelection() ended"; | ||
149 | } | 153 | } | ||
150 | 154 | | |||
151 | //--------------------------------------------------------------------- | 155 | //--------------------------------------------------------------------- | ||
152 | 156 | | |||
153 | // public | 157 | // public | ||
154 | kpImage kpDocument::getSelectedBaseImage () const | 158 | kpImage kpDocument::getSelectedBaseImage () const | ||
155 | { | 159 | { | ||
156 | kpAbstractImageSelection *imageSel = imageSelection (); | 160 | auto *imageSel = imageSelection (); | ||
157 | Q_ASSERT (imageSel); | 161 | Q_ASSERT (imageSel); | ||
158 | 162 | | |||
159 | // Easy if we already have it :) | 163 | // Easy if we already have it :) | ||
160 | const kpImage image = imageSel->baseImage (); | 164 | const auto image = imageSel->baseImage (); | ||
161 | if (!image.isNull ()) | 165 | if (!image.isNull ()) { | ||
162 | return image; | 166 | return image; | ||
167 | } | ||||
163 | 168 | | |||
164 | 169 | | |||
165 | const QRect boundingRect = imageSel->boundingRect (); | 170 | const auto boundingRect = imageSel->boundingRect (); | ||
166 | Q_ASSERT (boundingRect.isValid ()); | 171 | Q_ASSERT (boundingRect.isValid ()); | ||
167 | 172 | | |||
168 | // OPT: This is very slow. Image / More Effects ... calls us twice | 173 | // OPT: This is very slow. Image / More Effects ... calls us twice | ||
169 | // unnecessarily. | 174 | // unnecessarily. | ||
170 | return imageSel->givenImageMaskedByShape (getImageAt (boundingRect)); | 175 | return imageSel->givenImageMaskedByShape (getImageAt (boundingRect)); | ||
171 | } | 176 | } | ||
172 | 177 | | |||
173 | //--------------------------------------------------------------------- | 178 | //--------------------------------------------------------------------- | ||
174 | 179 | | |||
175 | // public | 180 | // public | ||
176 | void kpDocument::imageSelectionPullFromDocument (const kpColor &backgroundColor) | 181 | void kpDocument::imageSelectionPullFromDocument (const kpColor &backgroundColor) | ||
177 | { | 182 | { | ||
178 | kpAbstractImageSelection *imageSel = imageSelection (); | 183 | auto *imageSel = imageSelection (); | ||
179 | Q_ASSERT (imageSel); | 184 | Q_ASSERT (imageSel); | ||
180 | 185 | | |||
181 | // Should not already have an image or we would not be pulling. | 186 | // Should not already have an image or we would not be pulling. | ||
182 | Q_ASSERT (!imageSel->hasContent ()); | 187 | Q_ASSERT (!imageSel->hasContent ()); | ||
183 | 188 | | |||
184 | const QRect boundingRect = imageSel->boundingRect (); | 189 | const auto boundingRect = imageSel->boundingRect (); | ||
185 | Q_ASSERT (boundingRect.isValid ()); | 190 | Q_ASSERT (boundingRect.isValid ()); | ||
186 | 191 | | |||
187 | // | 192 | // | ||
188 | // Get selection image from document | 193 | // Get selection image from document | ||
189 | // | 194 | // | ||
190 | 195 | | |||
191 | kpImage selectedImage = getSelectedBaseImage (); | 196 | auto selectedImage = getSelectedBaseImage (); | ||
192 | 197 | | |||
193 | d->environ->setQueueViewUpdates (); | 198 | d->environ->setQueueViewUpdates (); | ||
194 | 199 | | |||
195 | imageSel->setBaseImage (selectedImage); | 200 | imageSel->setBaseImage (selectedImage); | ||
196 | 201 | | |||
197 | // | 202 | // | ||
198 | // Fill opaque bits of the hole in the document | 203 | // Fill opaque bits of the hole in the document | ||
199 | // | 204 | // | ||
Show All 31 Lines | 224 | #endif | |||
231 | d->environ->restoreQueueViewUpdates (); | 236 | d->environ->restoreQueueViewUpdates (); | ||
232 | } | 237 | } | ||
233 | 238 | | |||
234 | //--------------------------------------------------------------------- | 239 | //--------------------------------------------------------------------- | ||
235 | 240 | | |||
236 | // public | 241 | // public | ||
237 | void kpDocument::selectionDelete () | 242 | void kpDocument::selectionDelete () | ||
238 | { | 243 | { | ||
239 | if ( !m_selection ) | 244 | if ( !m_selection ) { | ||
240 | return; | 245 | return; | ||
246 | } | ||||
241 | 247 | | |||
242 | const QRect boundingRect = m_selection->boundingRect (); | 248 | const auto boundingRect = m_selection->boundingRect (); | ||
243 | Q_ASSERT (boundingRect.isValid ()); | 249 | Q_ASSERT (boundingRect.isValid ()); | ||
244 | 250 | | |||
245 | const bool selectionHadContent = m_selection->hasContent (); | 251 | const auto selectionHadContent = m_selection->hasContent (); | ||
246 | 252 | | |||
247 | delete m_selection; | 253 | delete m_selection; | ||
248 | m_selection = nullptr; | 254 | m_selection = nullptr; | ||
249 | 255 | | |||
250 | 256 | | |||
251 | // HACK to prevent document from being modified when | 257 | // HACK to prevent document from being modified when | ||
252 | // user cancels dragging out a new selection | 258 | // user cancels dragging out a new selection | ||
253 | // REFACTOR: Extract this out into a method. | 259 | // REFACTOR: Extract this out into a method. | ||
254 | if (selectionHadContent) | 260 | if (selectionHadContent) { | ||
255 | slotContentsChanged (boundingRect); | 261 | slotContentsChanged (boundingRect); | ||
256 | else | 262 | } | ||
263 | else { | ||||
257 | emit contentsChanged (boundingRect); | 264 | emit contentsChanged (boundingRect); | ||
265 | } | ||||
258 | 266 | | |||
259 | emit selectionEnabled (false); | 267 | emit selectionEnabled (false); | ||
260 | } | 268 | } | ||
261 | 269 | | |||
262 | //--------------------------------------------------------------------- | 270 | //--------------------------------------------------------------------- | ||
263 | 271 | | |||
264 | // public | 272 | // public | ||
265 | void kpDocument::selectionCopyOntoDocument (bool applySelTransparency) | 273 | void kpDocument::selectionCopyOntoDocument (bool applySelTransparency) | ||
266 | { | 274 | { | ||
267 | // Empty selection, just doing nothing | 275 | // Empty selection, just doing nothing | ||
268 | if ( !m_selection || !m_selection->hasContent() ) | 276 | if ( !m_selection || !m_selection->hasContent() ) { | ||
269 | return; | 277 | return; | ||
278 | } | ||||
270 | 279 | | |||
271 | const QRect boundingRect = m_selection->boundingRect (); | 280 | const QRect boundingRect = m_selection->boundingRect (); | ||
272 | Q_ASSERT (boundingRect.isValid ()); | 281 | Q_ASSERT (boundingRect.isValid ()); | ||
273 | 282 | | |||
274 | if (imageSelection ()) | 283 | if (imageSelection ()) | ||
275 | { | 284 | { | ||
276 | if (applySelTransparency) | 285 | if (applySelTransparency) { | ||
277 | imageSelection ()->paint (m_image, rect ()); | 286 | imageSelection ()->paint (m_image, rect ()); | ||
278 | else | 287 | } | ||
288 | else { | ||||
279 | imageSelection ()->paintWithBaseImage (m_image, rect ()); | 289 | imageSelection ()->paintWithBaseImage (m_image, rect ()); | ||
280 | } | 290 | } | ||
291 | } | ||||
281 | else | 292 | else | ||
282 | { | 293 | { | ||
283 | // (for antialiasing with background) | 294 | // (for antialiasing with background) | ||
284 | m_selection->paint (m_image, rect ()); | 295 | m_selection->paint (m_image, rect ()); | ||
285 | } | 296 | } | ||
286 | 297 | | |||
287 | slotContentsChanged (boundingRect); | 298 | slotContentsChanged (boundingRect); | ||
288 | } | 299 | } | ||
Show All 16 Lines | 314 | { | |||
305 | 316 | | |||
306 | // Have selection? | 317 | // Have selection? | ||
307 | // | 318 | // | ||
308 | // It need not have any content because e.g. a text box with an opaque | 319 | // It need not have any content because e.g. a text box with an opaque | ||
309 | // background, but no content, is still visually there. | 320 | // background, but no content, is still visually there. | ||
310 | if (m_selection) | 321 | if (m_selection) | ||
311 | { | 322 | { | ||
312 | qCDebug(kpLogDocument) << "\tselection @ " << m_selection->boundingRect (); | 323 | qCDebug(kpLogDocument) << "\tselection @ " << m_selection->boundingRect (); | ||
313 | kpImage output = *m_image; | 324 | auto output = *m_image; | ||
314 | 325 | | |||
315 | // (this is a NOP for image selections without content) | 326 | // (this is a NOP for image selections without content) | ||
316 | m_selection->paint (&output, rect ()); | 327 | m_selection->paint (&output, rect ()); | ||
317 | 328 | | |||
318 | return output; | 329 | return output; | ||
319 | } | 330 | } | ||
320 | else | 331 | | ||
321 | { | | |||
322 | qCDebug(kpLogDocument) << "\tno selection"; | 332 | qCDebug(kpLogDocument) << "\tno selection"; | ||
323 | return *m_image; | 333 | return *m_image; | ||
324 | } | 334 | } | ||
325 | } | | |||
326 | 335 | | |||
327 | //--------------------------------------------------------------------- | 336 | //--------------------------------------------------------------------- |