Changeset View
Changeset View
Standalone View
Standalone View
views/manager/kpViewManager.cpp
Show First 20 Lines • Show All 113 Lines • ▼ Show 20 Line(s) | |||||
114 | //--------------------------------------------------------------------- | 114 | //--------------------------------------------------------------------- | ||
115 | 115 | | |||
116 | // public | 116 | // public | ||
117 | void kpViewManager::unregisterView (kpView *view) | 117 | void kpViewManager::unregisterView (kpView *view) | ||
118 | { | 118 | { | ||
119 | Q_ASSERT (view); | 119 | Q_ASSERT (view); | ||
120 | Q_ASSERT (d->views.contains (view)); | 120 | Q_ASSERT (d->views.contains (view)); | ||
121 | 121 | | |||
122 | if (view == d->viewUnderCursor) | 122 | if (view == d->viewUnderCursor) { | ||
123 | d->viewUnderCursor = nullptr; | 123 | d->viewUnderCursor = nullptr; | ||
124 | } | ||||
124 | 125 | | |||
125 | view->unsetCursor (); | 126 | view->unsetCursor (); | ||
126 | d->views.removeAll (view); | 127 | d->views.removeAll (view); | ||
127 | } | 128 | } | ||
128 | 129 | | |||
129 | //--------------------------------------------------------------------- | 130 | //--------------------------------------------------------------------- | ||
130 | 131 | | |||
131 | // public | 132 | // public | ||
132 | void kpViewManager::unregisterAllViews () | 133 | void kpViewManager::unregisterAllViews () | ||
133 | { | 134 | { | ||
134 | d->views.clear (); | 135 | d->views.clear (); | ||
135 | } | 136 | } | ||
136 | 137 | | |||
137 | //--------------------------------------------------------------------- | 138 | //--------------------------------------------------------------------- | ||
138 | 139 | | |||
139 | // public | 140 | // public | ||
140 | kpView *kpViewManager::viewUnderCursor (bool usingQt) const | 141 | kpView *kpViewManager::viewUnderCursor (bool usingQt) const | ||
141 | { | 142 | { | ||
142 | if (!usingQt) | 143 | if (!usingQt) | ||
143 | { | 144 | { | ||
144 | Q_ASSERT (!d->viewUnderCursor || d->views.contains (d->viewUnderCursor)); | 145 | Q_ASSERT (!d->viewUnderCursor || d->views.contains (d->viewUnderCursor)); | ||
145 | return d->viewUnderCursor; | 146 | return d->viewUnderCursor; | ||
146 | } | 147 | } | ||
147 | else | 148 | | ||
148 | { | 149 | | ||
149 | for (QLinkedList <kpView *>::const_iterator it = d->views.begin (); | 150 | for (QLinkedList <kpView *>::const_iterator it = d->views.begin (); | ||
150 | it != d->views.end (); | 151 | it != d->views.end (); | ||
151 | ++it) | 152 | ++it) | ||
152 | { | 153 | { | ||
153 | if ((*it)->underMouse ()) | 154 | if ((*it)->underMouse ()) { | ||
154 | return (*it); | 155 | return (*it); | ||
155 | } | 156 | } | ||
157 | } | ||||
156 | 158 | | |||
157 | return nullptr; | 159 | return nullptr; | ||
158 | } | 160 | } | ||
159 | } | | |||
160 | 161 | | |||
161 | //--------------------------------------------------------------------- | 162 | //--------------------------------------------------------------------- | ||
162 | 163 | | |||
163 | // public | 164 | // public | ||
164 | void kpViewManager::setViewUnderCursor (kpView *view) | 165 | void kpViewManager::setViewUnderCursor (kpView *view) | ||
165 | { | 166 | { | ||
166 | qCDebug(kpLogViews) << "kpViewManager::setViewUnderCursor (" | 167 | qCDebug(kpLogViews) << "kpViewManager::setViewUnderCursor (" | ||
167 | << (view ? view->objectName () : "(none)") << ")" | 168 | << (view ? view->objectName () : "(none)") << ")" | ||
168 | << " old=" << (d->viewUnderCursor ? d->viewUnderCursor->objectName () : "(none)") | 169 | << " old=" << (d->viewUnderCursor ? d->viewUnderCursor->objectName () : "(none)"); | ||
169 | << endl; | 170 | if (view == d->viewUnderCursor) { | ||
170 | if (view == d->viewUnderCursor) | | |||
171 | return; | 171 | return; | ||
172 | } | ||||
172 | 173 | | |||
173 | d->viewUnderCursor = view; | 174 | d->viewUnderCursor = view; | ||
174 | 175 | | |||
175 | if (d->viewUnderCursor) | 176 | if (d->viewUnderCursor) { | ||
176 | d->viewUnderCursor->setAttribute (Qt::WA_InputMethodEnabled, d->inputMethodEnabled); | 177 | d->viewUnderCursor->setAttribute (Qt::WA_InputMethodEnabled, d->inputMethodEnabled); | ||
178 | } | ||||
177 | 179 | | |||
178 | if (!d->viewUnderCursor) | 180 | if (!d->viewUnderCursor) | ||
179 | { | 181 | { | ||
180 | // Hide the brush if the mouse cursor just left the view. | 182 | // Hide the brush if the mouse cursor just left the view. | ||
181 | if (d->tempImage && d->tempImage->isBrush ()) | 183 | if (d->tempImage && d->tempImage->isBrush ()) | ||
182 | { | 184 | { | ||
183 | qCDebug(kpLogViews) << "\thiding brush pixmap since cursor left view"; | 185 | qCDebug(kpLogViews) << "\thiding brush pixmap since cursor left view"; | ||
184 | updateViews (d->tempImage->rect ()); | 186 | updateViews (d->tempImage->rect ()); | ||
Show All 13 Lines | |||||
198 | 200 | | |||
199 | // public | 201 | // public | ||
200 | bool kpViewManager::hasAViewWithFocus () const | 202 | bool kpViewManager::hasAViewWithFocus () const | ||
201 | { | 203 | { | ||
202 | for (QLinkedList <kpView *>::const_iterator it = d->views.begin (); | 204 | for (QLinkedList <kpView *>::const_iterator it = d->views.begin (); | ||
203 | it != d->views.end (); | 205 | it != d->views.end (); | ||
204 | ++it) | 206 | ++it) | ||
205 | { | 207 | { | ||
206 | if ((*it)->isActiveWindow ()) | 208 | if ((*it)->isActiveWindow ()) { | ||
207 | return true; | 209 | return true; | ||
208 | } | 210 | } | ||
211 | } | ||||
209 | 212 | | |||
210 | return false; | 213 | return false; | ||
211 | } | 214 | } | ||
212 | 215 | | |||
213 | //--------------------------------------------------------------------- | 216 | //--------------------------------------------------------------------- | ||
214 | 217 | | |||
215 | // public | 218 | // public | ||
216 | void kpViewManager::setCursor (const QCursor &cursor) | 219 | void kpViewManager::setCursor (const QCursor &cursor) | ||
Show All 35 Lines | |||||
252 | 255 | | |||
253 | // public | 256 | // public | ||
254 | void kpViewManager::setTempImage (const kpTempImage &tempImage) | 257 | void kpViewManager::setTempImage (const kpTempImage &tempImage) | ||
255 | { | 258 | { | ||
256 | qCDebug(kpLogViews) << "kpViewManager::setTempImage(isBrush=" | 259 | qCDebug(kpLogViews) << "kpViewManager::setTempImage(isBrush=" | ||
257 | << tempImage.isBrush () | 260 | << tempImage.isBrush () | ||
258 | << ",topLeft=" << tempImage.topLeft () | 261 | << ",topLeft=" << tempImage.topLeft () | ||
259 | << ",image.rect=" << tempImage.image ().rect () | 262 | << ",image.rect=" << tempImage.image ().rect () | ||
260 | << ")" << endl; | 263 | << ")"; | ||
261 | 264 | | |||
262 | QRect oldRect; | 265 | QRect oldRect; | ||
263 | 266 | | |||
264 | if (d->tempImage) | 267 | if (d->tempImage) | ||
265 | { | 268 | { | ||
266 | oldRect = d->tempImage->rect (); | 269 | oldRect = d->tempImage->rect (); | ||
267 | delete d->tempImage; | 270 | delete d->tempImage; | ||
268 | d->tempImage = nullptr; | 271 | d->tempImage = nullptr; | ||
269 | } | 272 | } | ||
270 | 273 | | |||
271 | d->tempImage = new kpTempImage (tempImage); | 274 | d->tempImage = new kpTempImage (tempImage); | ||
272 | 275 | | |||
273 | setQueueUpdates (); | 276 | setQueueUpdates (); | ||
274 | { | 277 | { | ||
275 | if (oldRect.isValid ()) | 278 | if (oldRect.isValid ()) { | ||
276 | updateViews (oldRect); | 279 | updateViews (oldRect); | ||
280 | } | ||||
277 | updateViews (d->tempImage->rect ()); | 281 | updateViews (d->tempImage->rect ()); | ||
278 | } | 282 | } | ||
279 | restoreQueueUpdates (); | 283 | restoreQueueUpdates (); | ||
280 | } | 284 | } | ||
281 | 285 | | |||
282 | //--------------------------------------------------------------------- | 286 | //--------------------------------------------------------------------- | ||
283 | 287 | | |||
284 | // public | 288 | // public | ||
285 | void kpViewManager::invalidateTempImage () | 289 | void kpViewManager::invalidateTempImage () | ||
286 | { | 290 | { | ||
287 | if (!d->tempImage) | 291 | if (!d->tempImage) { | ||
288 | return; | 292 | return; | ||
293 | } | ||||
289 | 294 | | |||
290 | QRect oldRect = d->tempImage->rect (); | 295 | QRect oldRect = d->tempImage->rect (); | ||
291 | 296 | | |||
292 | delete d->tempImage; | 297 | delete d->tempImage; | ||
293 | d->tempImage = nullptr; | 298 | d->tempImage = nullptr; | ||
294 | 299 | | |||
295 | updateViews (oldRect); | 300 | updateViews (oldRect); | ||
296 | } | 301 | } | ||
297 | 302 | | |||
298 | //--------------------------------------------------------------------- | 303 | //--------------------------------------------------------------------- | ||
299 | 304 | | |||
300 | // public | 305 | // public | ||
301 | bool kpViewManager::selectionBorderVisible () const | 306 | bool kpViewManager::selectionBorderVisible () const | ||
302 | { | 307 | { | ||
303 | return d->selectionBorderVisible; | 308 | return d->selectionBorderVisible; | ||
304 | } | 309 | } | ||
305 | 310 | | |||
306 | //--------------------------------------------------------------------- | 311 | //--------------------------------------------------------------------- | ||
307 | 312 | | |||
308 | // public | 313 | // public | ||
309 | void kpViewManager::setSelectionBorderVisible (bool yes) | 314 | void kpViewManager::setSelectionBorderVisible (bool yes) | ||
310 | { | 315 | { | ||
311 | if (d->selectionBorderVisible == yes) | 316 | if (d->selectionBorderVisible == yes) { | ||
312 | return; | 317 | return; | ||
318 | } | ||||
313 | 319 | | |||
314 | d->selectionBorderVisible = yes; | 320 | d->selectionBorderVisible = yes; | ||
315 | 321 | | |||
316 | if (document ()->selection ()) | 322 | if (document ()->selection ()) { | ||
317 | updateViews (document ()->selection ()->boundingRect ()); | 323 | updateViews (document ()->selection ()->boundingRect ()); | ||
318 | } | 324 | } | ||
325 | } | ||||
319 | 326 | | |||
320 | //--------------------------------------------------------------------- | 327 | //--------------------------------------------------------------------- | ||
321 | 328 | | |||
322 | // public | 329 | // public | ||
323 | bool kpViewManager::selectionBorderFinished () const | 330 | bool kpViewManager::selectionBorderFinished () const | ||
324 | { | 331 | { | ||
325 | return d->selectionBorderFinished; | 332 | return d->selectionBorderFinished; | ||
326 | } | 333 | } | ||
327 | 334 | | |||
328 | //--------------------------------------------------------------------- | 335 | //--------------------------------------------------------------------- | ||
329 | 336 | | |||
330 | // public | 337 | // public | ||
331 | void kpViewManager::setSelectionBorderFinished (bool yes) | 338 | void kpViewManager::setSelectionBorderFinished (bool yes) | ||
332 | { | 339 | { | ||
333 | if (d->selectionBorderFinished == yes) | 340 | if (d->selectionBorderFinished == yes) { | ||
334 | return; | 341 | return; | ||
342 | } | ||||
335 | 343 | | |||
336 | d->selectionBorderFinished = yes; | 344 | d->selectionBorderFinished = yes; | ||
337 | 345 | | |||
338 | if (document ()->selection ()) | 346 | if (document ()->selection ()) { | ||
339 | updateViews (document ()->selection ()->boundingRect ()); | 347 | updateViews (document ()->selection ()->boundingRect ()); | ||
340 | } | 348 | } | ||
349 | } | ||||
341 | 350 | | |||
342 | //--------------------------------------------------------------------- | 351 | //--------------------------------------------------------------------- | ||
343 | 352 | | |||
344 | void kpViewManager::setInputMethodEnabled (bool inputMethodEnabled) | 353 | void kpViewManager::setInputMethodEnabled (bool inputMethodEnabled) | ||
345 | { | 354 | { | ||
346 | d->inputMethodEnabled = inputMethodEnabled; | 355 | d->inputMethodEnabled = inputMethodEnabled; | ||
347 | if (d->viewUnderCursor) | 356 | if (d->viewUnderCursor) { | ||
348 | d->viewUnderCursor->setAttribute (Qt::WA_InputMethodEnabled, inputMethodEnabled); | 357 | d->viewUnderCursor->setAttribute (Qt::WA_InputMethodEnabled, inputMethodEnabled); | ||
349 | } | 358 | } | ||
359 | } |