graphicsview/qgraphicsscene.cpp

Switch to Source codePreprocessed file
LineSource CodeCoverage
1 -
2 -
3 -
4 -
5 -
6 -
7 -
8 -
9 -
10bool qt_sendSpontaneousEvent(QObject *receiver, QEvent *event); -
11 -
12static void _q_hoverFromMouseEvent(QGraphicsSceneHoverEvent *hover, const QGraphicsSceneMouseEvent *mouseEvent) -
13{ -
14 hover->setWidget(mouseEvent->widget()); -
15 hover->setPos(mouseEvent->pos()); -
16 hover->setScenePos(mouseEvent->scenePos()); -
17 hover->setScreenPos(mouseEvent->screenPos()); -
18 hover->setLastPos(mouseEvent->lastPos()); -
19 hover->setLastScenePos(mouseEvent->lastScenePos()); -
20 hover->setLastScreenPos(mouseEvent->lastScreenPos()); -
21 hover->setModifiers(mouseEvent->modifiers()); -
22 hover->setAccepted(mouseEvent->isAccepted()); -
23}
-
24 -
25 -
26 -
27 -
28QGraphicsScenePrivate::QGraphicsScenePrivate() -
29 : indexMethod(QGraphicsScene::BspTreeIndex), -
30 index(0), -
31 lastItemCount(0), -
32 hasSceneRect(false), -
33 dirtyGrowingItemsBoundingRect(true), -
34 updateAll(false), -
35 calledEmitUpdated(false), -
36 processDirtyItemsEmitted(false), -
37 needSortTopLevelItems(true), -
38 holesInTopLevelSiblingIndex(false), -
39 topLevelSequentialOrdering(true), -
40 scenePosDescendantsUpdatePending(false), -
41 stickyFocus(false), -
42 hasFocus(false), -
43 lastMouseGrabberItemHasImplicitMouseGrab(false), -
44 allItemsIgnoreHoverEvents(true), -
45 allItemsUseDefaultCursor(true), -
46 painterStateProtection(true), -
47 sortCacheEnabled(false), -
48 allItemsIgnoreTouchEvents(true), -
49 selectionChanging(0), -
50 rectAdjust(2), -
51 focusItem(0), -
52 lastFocusItem(0), -
53 passiveFocusItem(0), -
54 tabFocusFirst(0), -
55 activePanel(0), -
56 lastActivePanel(0), -
57 activationRefCount(0), -
58 childExplicitActivation(0), -
59 lastMouseGrabberItem(0), -
60 dragDropItem(0), -
61 enterWidget(0), -
62 lastDropAction(Qt::IgnoreAction), -
63 style(0) -
64{ -
65}
-
66 -
67 -
68 -
69 -
70void QGraphicsScenePrivate::init() -
71{ -
72 QGraphicsScene * const q = q_func(); -
73 -
74 index = new QGraphicsSceneBspTreeIndex(q); -
75 -
76 -
77 changedSignalIndex = signalIndex("changed(QList<QRectF>)"); -
78 processDirtyItemsIndex = q->metaObject()->indexOfSlot("_q_processDirtyItems()"); -
79 polishItemsIndex = q->metaObject()->indexOfSlot("_q_polishItems()"); -
80 -
81 (static_cast<QApplication *>(QCoreApplication::instance()))->d_func()->scene_list.append(q); -
82 q->update(); -
83}
-
84 -
85 -
86 -
87 -
88QGraphicsScenePrivate *QGraphicsScenePrivate::get(QGraphicsScene *q) -
89{ -
90 return q->d_func();
-
91} -
92 -
93void QGraphicsScenePrivate::_q_emitUpdated() -
94{ -
95 QGraphicsScene * const q = q_func(); -
96 calledEmitUpdated = false; -
97 -
98 if (dirtyGrowingItemsBoundingRect) {
-
99 if (!hasSceneRect) {
-
100 const QRectF oldGrowingItemsBoundingRect = growingItemsBoundingRect; -
101 growingItemsBoundingRect |= q->itemsBoundingRect(); -
102 if (oldGrowingItemsBoundingRect != growingItemsBoundingRect)
-
103 q->sceneRectChanged(growingItemsBoundingRect);
-
104 }
-
105 dirtyGrowingItemsBoundingRect = false; -
106 }
-
107 -
108 -
109 -
110 -
111 -
112 if (isSignalConnected(changedSignalIndex)) {
-
113 for (int i = 0; i < views.size(); ++i) {
-
114 QGraphicsView *view = views.at(i); -
115 if (!view->d_func()->connectedToScene) {
-
116 view->d_func()->connectedToScene = true; -
117 q->connect(q, "2""changed(QList<QRectF>)", -
118 views.at(i), "1""updateScene(QList<QRectF>)"); -
119 }
-
120 }
-
121 } else {
-
122 if (views.isEmpty()) {
-
123 updateAll = false; -
124 return;
-
125 } -
126 for (int i = 0; i < views.size(); ++i)
-
127 views.at(i)->d_func()->processPendingUpdates();
-
128 -
129 for (int i = 0; i < views.size(); ++i)
-
130 views.at(i)->d_func()->dispatchPendingUpdateRequests();
-
131 return;
-
132 } -
133 -
134 -
135 QList<QRectF> oldUpdatedRects; -
136 oldUpdatedRects = updateAll ? (QList<QRectF>() << q->sceneRect()) : updatedRects;
-
137 updateAll = false; -
138 updatedRects.clear(); -
139 q->changed(oldUpdatedRects); -
140}
-
141 -
142 -
143 -
144 -
145 -
146 -
147void QGraphicsScenePrivate::registerTopLevelItem(QGraphicsItem *item) -
148{ -
149 item->d_ptr->ensureSequentialSiblingIndex(); -
150 needSortTopLevelItems = true; -
151 item->d_ptr->siblingIndex = topLevelItems.size(); -
152 topLevelItems.append(item); -
153}
-
154 -
155 -
156 -
157 -
158 -
159 -
160void QGraphicsScenePrivate::unregisterTopLevelItem(QGraphicsItem *item) -
161{ -
162 if (!holesInTopLevelSiblingIndex)
-
163 holesInTopLevelSiblingIndex = item->d_ptr->siblingIndex != topLevelItems.size() - 1;
-
164 if (topLevelSequentialOrdering && !holesInTopLevelSiblingIndex)
-
165 topLevelItems.removeAt(item->d_ptr->siblingIndex);
-
166 else -
167 topLevelItems.removeOne(item);
-
168 -
169 -
170 -
171 item->d_ptr->siblingIndex = -1; -
172 if (topLevelSequentialOrdering)
-
173 topLevelSequentialOrdering = !holesInTopLevelSiblingIndex;
-
174}
-
175 -
176 -
177 -
178 -
179void QGraphicsScenePrivate::_q_polishItems() -
180{ -
181 if (unpolishedItems.isEmpty())
-
182 return;
-
183 -
184 const QVariant booleanTrueVariant(true); -
185 QGraphicsItem *item = 0; -
186 QGraphicsItemPrivate *itemd = 0; -
187 const int oldUnpolishedCount = unpolishedItems.count(); -
188 -
189 for (int i = 0; i < oldUnpolishedCount; ++i) {
-
190 item = unpolishedItems.at(i); -
191 if (!item)
-
192 continue;
-
193 itemd = item->d_ptr.data(); -
194 itemd->pendingPolish = false; -
195 if (!itemd->explicitlyHidden) {
-
196 item->itemChange(QGraphicsItem::ItemVisibleChange, booleanTrueVariant); -
197 item->itemChange(QGraphicsItem::ItemVisibleHasChanged, booleanTrueVariant); -
198 }
-
199 if (itemd->isWidget) {
-
200 QEvent event(QEvent::Polish); -
201 QApplication::sendEvent((QGraphicsWidget *)item, &event); -
202 }
-
203 }
-
204 -
205 if (unpolishedItems.count() == oldUnpolishedCount) {
-
206 -
207 unpolishedItems.clear(); -
208 } else {
-
209 -
210 unpolishedItems.remove(0, oldUnpolishedCount); -
211 unpolishedItems.squeeze(); -
212 QMetaObject::invokeMethod(q_ptr, "_q_polishItems", Qt::QueuedConnection); -
213 }
-
214} -
215 -
216void QGraphicsScenePrivate::_q_processDirtyItems() -
217{ -
218 processDirtyItemsEmitted = false; -
219 -
220 if (updateAll) {
-
221 qt_noop(); -
222 -
223 -
224 for (int i = 0; i < topLevelItems.size(); ++i)
-
225 resetDirtyItem(topLevelItems.at(i), true);
-
226 return;
-
227 } -
228 -
229 const bool wasPendingSceneUpdate = calledEmitUpdated; -
230 const QRectF oldGrowingItemsBoundingRect = growingItemsBoundingRect; -
231 -
232 -
233 for (int i = 0; i < topLevelItems.size(); ++i)
-
234 processDirtyItemsRecursive(topLevelItems.at(i));
-
235 -
236 dirtyGrowingItemsBoundingRect = false; -
237 if (!hasSceneRect && oldGrowingItemsBoundingRect != growingItemsBoundingRect)
-
238 q_func()->sceneRectChanged(growingItemsBoundingRect);
-
239 -
240 if (wasPendingSceneUpdate)
-
241 return;
-
242 -
243 for (int i = 0; i < views.size(); ++i)
-
244 views.at(i)->d_func()->processPendingUpdates();
-
245 -
246 if (calledEmitUpdated) {
-
247 -
248 -
249 -
250 _q_emitUpdated(); -
251 }
-
252 -
253 -
254 for (int i = 0; i < views.size(); ++i)
-
255 views.at(i)->d_func()->dispatchPendingUpdateRequests();
-
256}
-
257 -
258 -
259 -
260 -
261void QGraphicsScenePrivate::setScenePosItemEnabled(QGraphicsItem *item, bool enabled) -
262{ -
263 QGraphicsItem *p = item->d_ptr->parent; -
264 while (p) {
-
265 p->d_ptr->scenePosDescendants = enabled; -
266 p = p->d_ptr->parent; -
267 }
-
268 if (!enabled && !scenePosDescendantsUpdatePending) {
-
269 scenePosDescendantsUpdatePending = true; -
270 QMetaObject::invokeMethod(q_func(), "_q_updateScenePosDescendants", Qt::QueuedConnection); -
271 }
-
272}
-
273 -
274 -
275 -
276 -
277void QGraphicsScenePrivate::registerScenePosItem(QGraphicsItem *item) -
278{ -
279 scenePosItems.insert(item); -
280 setScenePosItemEnabled(item, true); -
281}
-
282 -
283 -
284 -
285 -
286void QGraphicsScenePrivate::unregisterScenePosItem(QGraphicsItem *item) -
287{ -
288 scenePosItems.remove(item); -
289 setScenePosItemEnabled(item, false); -
290}
-
291 -
292 -
293 -
294 -
295void QGraphicsScenePrivate::_q_updateScenePosDescendants() -
296{ -
297 for (QForeachContainer<__typeof__(scenePosItems)> _container_(scenePosItems); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (QGraphicsItem *item = *_container_.i;; __extension__ ({--_container_.brk; break;})) { -
298 QGraphicsItem *p = item->d_ptr->parent; -
299 while (p) {
-
300 p->d_ptr->scenePosDescendants = 1; -
301 p = p->d_ptr->parent; -
302 }
-
303 }
-
304 scenePosDescendantsUpdatePending = false; -
305}
-
306void QGraphicsScenePrivate::removeItemHelper(QGraphicsItem *item) -
307{ -
308 QGraphicsScene * const q = q_func(); -
309 -
310 -
311 item->clearFocus(); -
312 -
313 markDirty(item, QRectF(), false, false, -
314 false, true); -
315 -
316 if (item->d_ptr->inDestructor) {
-
317 -
318 index->deleteItem(item); -
319 } else {
-
320 -
321 -
322 index->removeItem(item); -
323 }
-
324 -
325 item->d_ptr->clearSubFocus(); -
326 -
327 if (item->flags() & QGraphicsItem::ItemSendsScenePositionChanges)
-
328 unregisterScenePosItem(item);
-
329 -
330 QGraphicsScene *oldScene = item->d_func()->scene; -
331 item->d_func()->scene = 0; -
332 -
333 -
334 -
335 if (!item->d_ptr->inDestructor) {
-
336 -
337 for (int i = 0; i < item->d_ptr->children.size(); ++i)
-
338 q->removeItem(item->d_ptr->children.at(i));
-
339 }
-
340 -
341 if (!item->d_ptr->inDestructor && item == tabFocusFirst) {
-
342 QGraphicsWidget *widget = static_cast<QGraphicsWidget *>(item); -
343 widget->d_func()->fixFocusChainBeforeReparenting(0, oldScene, 0); -
344 }
-
345 -
346 -
347 item->d_ptr->resetFocusProxy(); -
348 -
349 -
350 if (QGraphicsItem *parentItem = item->parentItem()) {
-
351 if (parentItem->scene()) {
-
352 qt_noop(); -
353 -
354 item->setParentItem(0); -
355 }
-
356 } else {
-
357 unregisterTopLevelItem(item); -
358 }
-
359 -
360 -
361 if (item == focusItem)
-
362 focusItem = 0;
-
363 if (item == lastFocusItem)
-
364 lastFocusItem = 0;
-
365 if (item == passiveFocusItem)
-
366 passiveFocusItem = 0;
-
367 if (item == activePanel) {
-
368 -
369 activePanel = 0; -
370 }
-
371 if (item == lastActivePanel)
-
372 lastActivePanel = 0;
-
373 -
374 -
375 { -
376 QMap<int, QGraphicsItem *>::iterator it = itemForTouchPointId.begin(); -
377 while (it != itemForTouchPointId.end()) {
-
378 if (it.value() == item) {
-
379 sceneCurrentTouchPoints.remove(it.key()); -
380 it = itemForTouchPointId.erase(it); -
381 } else {
-
382 ++it; -
383 }
-
384 } -
385 } -
386 -
387 -
388 ++selectionChanging; -
389 int oldSelectedItemsSize = selectedItems.size(); -
390 -
391 -
392 selectedItems.remove(item); -
393 hoverItems.removeAll(item); -
394 cachedItemsUnderMouse.removeAll(item); -
395 if (item->d_ptr->pendingPolish) {
-
396 const int unpolishedIndex = unpolishedItems.indexOf(item); -
397 if (unpolishedIndex != -1)
-
398 unpolishedItems[unpolishedIndex] = 0;
-
399 item->d_ptr->pendingPolish = false; -
400 }
-
401 resetDirtyItem(item); -
402 -
403 -
404 QMultiMap<QGraphicsItem*, QGraphicsItem*>::iterator iterator = sceneEventFilters.begin(); -
405 while (iterator != sceneEventFilters.end()) {
-
406 if (iterator.value() == item || iterator.key() == item)
-
407 iterator = sceneEventFilters.erase(iterator);
-
408 else -
409 ++iterator;
-
410 } -
411 -
412 if (item->isPanel() && item->isVisible() && item->panelModality() != QGraphicsItem::NonModal)
-
413 leaveModal(item);
-
414 -
415 -
416 if (mouseGrabberItems.contains(item))
-
417 ungrabMouse(item, item->d_ptr->inDestructor);
-
418 -
419 -
420 if (keyboardGrabberItems.contains(item))
-
421 ungrabKeyboard(item, item->d_ptr->inDestructor);
-
422 -
423 -
424 if (item == lastMouseGrabberItem)
-
425 lastMouseGrabberItem = 0;
-
426 -
427 -
428 if (item == dragDropItem)
-
429 dragDropItem = 0;
-
430 -
431 -
432 --selectionChanging; -
433 if (!selectionChanging && selectedItems.size() != oldSelectedItemsSize)
-
434 q->selectionChanged();
-
435 -
436 -
437 QHash<QGesture *, QGraphicsObject *>::iterator it; -
438 for (it = gestureTargets.begin(); it != gestureTargets.end();) {
-
439 if (it.value() == item)
-
440 it = gestureTargets.erase(it);
-
441 else -
442 ++it;
-
443 } -
444 -
445 QGraphicsObject *dummy = static_cast<QGraphicsObject *>(item); -
446 cachedTargetItems.removeOne(dummy); -
447 cachedItemGestures.remove(dummy); -
448 cachedAlreadyDeliveredGestures.remove(dummy); -
449 -
450 for (QForeachContainer<__typeof__(item->d_ptr->gestureContext.keys())> _container_(item->d_ptr->gestureContext.keys()); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (Qt::GestureType gesture = *_container_.i;; __extension__ ({--_container_.brk; break;})) -
451 ungrabGesture(item, gesture);
-
452 -
453}
-
454 -
455 -
456 -
457 -
458void QGraphicsScenePrivate::setActivePanelHelper(QGraphicsItem *item, bool duringActivationEvent) -
459{ -
460 QGraphicsScene * const q = q_func(); -
461 if (item && item->scene() != q) {
-
462 QMessageLogger("graphicsview/qgraphicsscene.cpp", 731728, __PRETTY_FUNCTION__).warning("QGraphicsScene::setActivePanel: item %p must be part of this scene", -
463 item); -
464 return;
-
465 } -
466 -
467 -
468 q->setFocus(Qt::ActiveWindowFocusReason); -
469 -
470 -
471 QGraphicsItem *panel = item ? item->panel() : 0;
-
472 lastActivePanel = panel ? activePanel : 0;
-
473 if (panel == activePanel || (!q->isActive() && !duringActivationEvent))
-
474 return;
-
475 -
476 -
477 if (activePanel) {
-
478 if (QGraphicsItem *fi = activePanel->focusItem()) {
-
479 -
480 if (fi == q->focusItem())
-
481 q->setFocusItem(0, Qt::ActiveWindowFocusReason);
-
482 }
-
483 -
484 QEvent event(QEvent::WindowDeactivate); -
485 q->sendEvent(activePanel, &event); -
486 } else if (panel && !duringActivationEvent) {
-
487 -
488 QEvent event(QEvent::WindowDeactivate); -
489 for (QForeachContainer<__typeof__(q->items())> _container_(q->items()); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (QGraphicsItem *item = *_container_.i;; __extension__ ({--_container_.brk; break;})) { -
490 if (item->isVisible() && !item->isPanel() && !item->parentItem())
-
491 q->sendEvent(item, &event);
-
492 }
-
493 }
-
494 -
495 -
496 activePanel = panel; -
497 QEvent event(QEvent::ActivationChange); -
498 QApplication::sendEvent(q, &event); -
499 -
500 -
501 if (panel) {
-
502 QEvent event(QEvent::WindowActivate); -
503 q->sendEvent(panel, &event); -
504 -
505 -
506 if (QGraphicsItem *focusItem = panel->focusItem())
-
507 focusItem->setFocus(Qt::ActiveWindowFocusReason);
-
508 } else if (q->isActive()) {
-
509 -
510 QEvent event(QEvent::WindowActivate); -
511 for (QForeachContainer<__typeof__(q->items())> _container_(q->items()); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (QGraphicsItem *item = *_container_.i;; __extension__ ({--_container_.brk; break;})) { -
512 if (item->isVisible() && !item->isPanel() && !item->parentItem())
-
513 q->sendEvent(item, &event);
-
514 }
-
515 }
-
516} -
517 -
518 -
519 -
520 -
521void QGraphicsScenePrivate::setFocusItemHelper(QGraphicsItem *item, -
522 Qt::FocusReason focusReason) -
523{ -
524 QGraphicsScene * const q = q_func(); -
525 if (item == focusItem)
evaluated: item == focusItem
TRUEFALSE
yes
Evaluation Count:124
yes
Evaluation Count:21
21-124
526 return;
executed: return;
Execution Count:124
124
527 -
528 -
529 -
530 if (item && (!(item->flags() & QGraphicsItem::ItemIsFocusable)
evaluated: item
TRUEFALSE
yes
Evaluation Count:13
yes
Evaluation Count:8
partially evaluated: !(item->flags() & QGraphicsItem::ItemIsFocusable)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:13
0-13
531 || !item->isVisible() || !item->isEnabled())) {
partially evaluated: !item->isVisible()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:13
partially evaluated: !item->isEnabled()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:13
0-13
532 item = 0; -
533 }
never executed: }
0
534 -
535 -
536 if (item) {
evaluated: item
TRUEFALSE
yes
Evaluation Count:13
yes
Evaluation Count:8
8-13
537 q->setFocus(focusReason); -
538 if (item == focusItem)
partially evaluated: item == focusItem
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:13
0-13
539 return;
never executed: return;
0
540 }
executed: }
Execution Count:13
13
541 -
542 if (focusItem) {
evaluated: focusItem
TRUEFALSE
yes
Evaluation Count:13
yes
Evaluation Count:8
8-13
543 lastFocusItem = focusItem; -
544 -
545 -
546 if (lastFocusItem->flags() & QGraphicsItem::ItemAcceptsInputMethod) {
evaluated: lastFocusItem->flags() & QGraphicsItem::ItemAcceptsInputMethod
TRUEFALSE
yes
Evaluation Count:8
yes
Evaluation Count:5
5-8
547 -
548 -
549 -
550 -
551 if ((static_cast<QApplication *>(QCoreApplication::instance())))
partially evaluated: (static_cast<QApplication *>(QCoreApplication::instance()))
TRUEFALSE
yes
Evaluation Count:8
no
Evaluation Count:0
0-8
552 (static_cast<QApplication *>(QCoreApplication::instance()))->inputMethod()->commit();
executed: (static_cast<QApplication *>(QCoreApplication::instance()))->inputMethod()->commit();
Execution Count:8
8
553 }
executed: }
Execution Count:8
8
554 -
555 -
556 focusItem = 0; -
557 QFocusEvent event(QEvent::FocusOut, focusReason); -
558 sendEvent(lastFocusItem, &event); -
559 }
executed: }
Execution Count:13
13
560 -
561 -
562 -
563 if (item && item->scene() != q)
evaluated: item
TRUEFALSE
yes
Evaluation Count:13
yes
Evaluation Count:8
partially evaluated: item->scene() != q
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:13
0-13
564 item = 0;
never executed: item = 0;
0
565 -
566 if (item)
evaluated: item
TRUEFALSE
yes
Evaluation Count:13
yes
Evaluation Count:8
8-13
567 focusItem = item;
executed: focusItem = item;
Execution Count:13
13
568 updateInputMethodSensitivityInViews(); -
569 -
570 if (focusItem) {8-13
if (QGraphicsObject *focusObj = focusItem->toGraphicsObject()) {
QAccessibleEvent event(focusObj, QAccessible::Focus);
QAccessible::updateAccessibility(&event);
}
}if (item) {
evaluated: item
TRUEFALSE
yes
Evaluation Count:13
yes
Evaluation Count:8
571 QFocusEvent event(QEvent::FocusIn, focusReason); -
572 sendEvent(item, &event); -
573 }
executed: }
Execution Count:13
13
574}
executed: }
Execution Count:21
21
575 -
576 -
577 -
578 -
579void QGraphicsScenePrivate::addPopup(QGraphicsWidget *widget) -
580{ -
581 qt_noop(); -
582 qt_noop(); -
583 popupWidgets << widget; -
584 if (QGraphicsWidget *focusWidget = widget->focusWidget()) {
-
585 focusWidget->setFocus(Qt::PopupFocusReason); -
586 } else {
-
587 grabKeyboard((QGraphicsItem *)widget); -
588 if (focusItem && popupWidgets.size() == 1) {
-
589 QFocusEvent event(QEvent::FocusOut, Qt::PopupFocusReason); -
590 sendEvent(focusItem, &event); -
591 }
-
592 }
-
593 grabMouse((QGraphicsItem *)widget); -
594}
-
595void QGraphicsScenePrivate::removePopup(QGraphicsWidget *widget, bool itemIsDying) -
596{ -
597 qt_noop(); -
598 int index = popupWidgets.indexOf(widget); -
599 qt_noop(); -
600 -
601 for (int i = popupWidgets.size() - 1; i >= index; --i) {
-
602 QGraphicsWidget *widget = popupWidgets.takeLast(); -
603 ungrabMouse(widget, itemIsDying); -
604 if (focusItem && popupWidgets.isEmpty()) {
-
605 QFocusEvent event(QEvent::FocusIn, Qt::PopupFocusReason); -
606 sendEvent(focusItem, &event); -
607 } else if (keyboardGrabberItems.contains(static_cast<QGraphicsItem *>(widget))) {
-
608 ungrabKeyboard(static_cast<QGraphicsItem *>(widget), itemIsDying); -
609 }
-
610 if (!itemIsDying && widget->isVisible()) {
-
611 widget->QGraphicsItem::d_ptr->setVisibleHelper(false, false); -
612 }
-
613 }
-
614}
-
615 -
616 -
617 -
618 -
619void QGraphicsScenePrivate::grabMouse(QGraphicsItem *item, bool implicit) -
620{ -
621 -
622 if (mouseGrabberItems.contains(item)) {
-
623 if (mouseGrabberItems.last() == item) {
-
624 qt_noop(); -
625 if (!lastMouseGrabberItemHasImplicitMouseGrab) {
-
626 QMessageLogger("graphicsview/qgraphicsscene.cpp", 913902, __PRETTY_FUNCTION__).warning("QGraphicsItem::grabMouse: already a mouse grabber"); -
627 } else {
-
628 -
629 lastMouseGrabberItemHasImplicitMouseGrab = false; -
630 }
-
631 } else { -
632 QMessageLogger("graphicsview/qgraphicsscene.cpp", 919908, __PRETTY_FUNCTION__).warning("QGraphicsItem::grabMouse: already blocked by mouse grabber: %p", -
633 mouseGrabberItems.last()); -
634 }
-
635 return;
-
636 } -
637 -
638 -
639 if (!mouseGrabberItems.isEmpty()) {
-
640 QGraphicsItem *last = mouseGrabberItems.last(); -
641 if (lastMouseGrabberItemHasImplicitMouseGrab) {
-
642 -
643 last->ungrabMouse(); -
644 } else {
-
645 -
646 QEvent ungrabEvent(QEvent::UngrabMouse); -
647 sendEvent(last, &ungrabEvent); -
648 }
-
649 } -
650 -
651 mouseGrabberItems << item; -
652 lastMouseGrabberItemHasImplicitMouseGrab = implicit; -
653 -
654 -
655 QEvent grabEvent(QEvent::GrabMouse); -
656 sendEvent(item, &grabEvent); -
657}
-
658 -
659 -
660 -
661 -
662void QGraphicsScenePrivate::ungrabMouse(QGraphicsItem *item, bool itemIsDying) -
663{ -
664 int index = mouseGrabberItems.indexOf(item); -
665 if (index == -1) {
-
666 QMessageLogger("graphicsview/qgraphicsscene.cpp", 953942, __PRETTY_FUNCTION__).warning("QGraphicsItem::ungrabMouse: not a mouse grabber"); -
667 return;
-
668 } -
669 -
670 if (item != mouseGrabberItems.last()) {
-
671 -
672 -
673 ungrabMouse(mouseGrabberItems.at(index + 1), itemIsDying); -
674 }
-
675 if (!popupWidgets.isEmpty() && item == popupWidgets.last()) {
-
676 -
677 -
678 -
679 removePopup((QGraphicsWidget *)item, itemIsDying); -
680 return;
-
681 } -
682 -
683 -
684 if (!itemIsDying) {
-
685 QEvent event(QEvent::UngrabMouse); -
686 sendEvent(item, &event); -
687 }
-
688 -
689 -
690 -
691 -
692 -
693 mouseGrabberItems.takeLast(); -
694 lastMouseGrabberItemHasImplicitMouseGrab = false; -
695 -
696 -
697 -
698 -
699 if (!itemIsDying && !mouseGrabberItems.isEmpty()) {
-
700 QGraphicsItem *last = mouseGrabberItems.last(); -
701 QEvent event(QEvent::GrabMouse); -
702 sendEvent(last, &event); -
703 }
-
704}
-
705 -
706 -
707 -
708 -
709void QGraphicsScenePrivate::clearMouseGrabber() -
710{ -
711 if (!mouseGrabberItems.isEmpty())
-
712 mouseGrabberItems.first()->ungrabMouse();
-
713 lastMouseGrabberItem = 0; -
714}
-
715 -
716 -
717 -
718 -
719void QGraphicsScenePrivate::grabKeyboard(QGraphicsItem *item) -
720{ -
721 if (keyboardGrabberItems.contains(item)) {
-
722 if (keyboardGrabberItems.last() == item)
-
723 QMessageLogger("graphicsview/qgraphicsscene.cpp", 1010999, __PRETTY_FUNCTION__).warning("QGraphicsItem::grabKeyboard: already a keyboard grabber");
-
724 else -
725 QMessageLogger("graphicsview/qgraphicsscene.cpp", 10121001, __PRETTY_FUNCTION__).warning("QGraphicsItem::grabKeyboard: already blocked by keyboard grabber: %p", -
726 keyboardGrabberItems.last());
-
727 return;
-
728 } -
729 -
730 -
731 if (!keyboardGrabberItems.isEmpty()) {
-
732 -
733 QEvent ungrabEvent(QEvent::UngrabKeyboard); -
734 sendEvent(keyboardGrabberItems.last(), &ungrabEvent); -
735 }
-
736 -
737 keyboardGrabberItems << item; -
738 -
739 -
740 QEvent grabEvent(QEvent::GrabKeyboard); -
741 sendEvent(item, &grabEvent); -
742}
-
743 -
744 -
745 -
746 -
747void QGraphicsScenePrivate::ungrabKeyboard(QGraphicsItem *item, bool itemIsDying) -
748{ -
749 int index = keyboardGrabberItems.lastIndexOf(item); -
750 if (index == -1) {
-
751 QMessageLogger("graphicsview/qgraphicsscene.cpp", 10381027, __PRETTY_FUNCTION__).warning("QGraphicsItem::ungrabKeyboard: not a keyboard grabber"); -
752 return;
-
753 } -
754 if (item != keyboardGrabberItems.last()) {
-
755 -
756 -
757 ungrabKeyboard(keyboardGrabberItems.at(index + 1), itemIsDying); -
758 }
-
759 -
760 -
761 if (!itemIsDying) {
-
762 QEvent event(QEvent::UngrabKeyboard); -
763 sendEvent(item, &event); -
764 }
-
765 -
766 -
767 keyboardGrabberItems.takeLast(); -
768 -
769 -
770 if (!itemIsDying && !keyboardGrabberItems.isEmpty()) {
-
771 QGraphicsItem *last = keyboardGrabberItems.last(); -
772 QEvent event(QEvent::GrabKeyboard); -
773 sendEvent(last, &event); -
774 }
-
775}
-
776 -
777 -
778 -
779 -
780void QGraphicsScenePrivate::clearKeyboardGrabber() -
781{ -
782 if (!keyboardGrabberItems.isEmpty())
-
783 ungrabKeyboard(keyboardGrabberItems.first());
-
784}
-
785 -
786void QGraphicsScenePrivate::enableMouseTrackingOnViews() -
787{ -
788 for (QForeachContainer<__typeof__(views)> _container_(views); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (QGraphicsView *view = *_container_.i;; __extension__ ({--_container_.brk; break;})) -
789 view->viewport()->setMouseTracking(true);
-
790}
-
791 -
792 -
793 -
794 -
795QList<QGraphicsItem *> QGraphicsScenePrivate::itemsAtPosition(const QPoint &screenPos, -
796 const QPointF &scenePos, -
797 QWidget *widget) const -
798{ -
799 const QGraphicsScene * const q = q_func(); -
800 QGraphicsView *view = widget ? qobject_cast<QGraphicsView *>(widget->parentWidget()) : 0;
-
801 if (!view)
-
802 return q->items(scenePos, Qt::IntersectsItemShape, Qt::DescendingOrder, QTransform());
-
803 -
804 const QRectF pointRect(QPointF(widget->mapFromGlobal(screenPos)), QSizeF(1, 1)); -
805 if (!view->isTransformed())
-
806 return q->items(pointRect, Qt::IntersectsItemShape, Qt::DescendingOrder);
-
807 -
808 const QTransform viewTransform = view->viewportTransform(); -
809 if (viewTransform.type() <= QTransform::TxScale) {
-
810 return q->items(viewTransform.inverted().mapRect(pointRect), Qt::IntersectsItemShape, -
811 Qt::DescendingOrder, viewTransform);
-
812 } -
813 return q->items(viewTransform.inverted().map(pointRect), Qt::IntersectsItemShape, -
814 Qt::DescendingOrder, viewTransform);
-
815} -
816 -
817 -
818 -
819 -
820void QGraphicsScenePrivate::storeMouseButtonsForMouseGrabber(QGraphicsSceneMouseEvent *event) -
821{ -
822 for (int i = 0x1; i <= 0x10; i <<= 1) {
-
823 if (event->buttons() & i) {
-
824 mouseGrabberButtonDownPos.insert(Qt::MouseButton(i), -
825 mouseGrabberItems.last()->d_ptr->genericMapFromScene(event->scenePos(), -
826 event->widget())); -
827 mouseGrabberButtonDownScenePos.insert(Qt::MouseButton(i), event->scenePos()); -
828 mouseGrabberButtonDownScreenPos.insert(Qt::MouseButton(i), event->screenPos()); -
829 }
-
830 }
-
831}
-
832 -
833 -
834 -
835 -
836void QGraphicsScenePrivate::installSceneEventFilter(QGraphicsItem *watched, QGraphicsItem *filter) -
837{ -
838 sceneEventFilters.insert(watched, filter); -
839}
-
840 -
841 -
842 -
843 -
844void QGraphicsScenePrivate::removeSceneEventFilter(QGraphicsItem *watched, QGraphicsItem *filter) -
845{ -
846 if (!sceneEventFilters.contains(watched))
-
847 return;
-
848 -
849 QMultiMap<QGraphicsItem *, QGraphicsItem *>::Iterator it = sceneEventFilters.lowerBound(watched); -
850 QMultiMap<QGraphicsItem *, QGraphicsItem *>::Iterator end = sceneEventFilters.upperBound(watched); -
851 do { -
852 if (it.value() == filter)
-
853 it = sceneEventFilters.erase(it);
-
854 else -
855 ++it;
-
856 } while (it != end);
-
857}
-
858 -
859 -
860 -
861 -
862bool QGraphicsScenePrivate::filterDescendantEvent(QGraphicsItem *item, QEvent *event) -
863{ -
864 if (item && (item->d_ptr->ancestorFlags & QGraphicsItemPrivate::AncestorFiltersChildEvents)) {
-
865 QGraphicsItem *parent = item->parentItem(); -
866 while (parent) {
-
867 if (parent->d_ptr->filtersDescendantEvents && parent->sceneEventFilter(item, event))
-
868 return true;
-
869 if (!(parent->d_ptr->ancestorFlags & QGraphicsItemPrivate::AncestorFiltersChildEvents))
-
870 return false;
-
871 parent = parent->parentItem(); -
872 }
-
873 }
-
874 return false;
-
875} -
876 -
877 -
878 -
879 -
880bool QGraphicsScenePrivate::filterEvent(QGraphicsItem *item, QEvent *event) -
881{ -
882 if (item && !sceneEventFilters.contains(item))
-
883 return false;
-
884 -
885 QMultiMap<QGraphicsItem *, QGraphicsItem *>::Iterator it = sceneEventFilters.lowerBound(item); -
886 QMultiMap<QGraphicsItem *, QGraphicsItem *>::Iterator end = sceneEventFilters.upperBound(item); -
887 while (it != end) {
-
888 -
889 if (it.value()->sceneEventFilter(it.key(), event))
-
890 return true;
-
891 ++it; -
892 }
-
893 return false;
-
894} -
895bool QGraphicsScenePrivate::sendEvent(QGraphicsItem *item, QEvent *event) -
896{ -
897 if (QGraphicsObject *object = item->toGraphicsObject()) {
-
898 -
899 QGestureManager *gestureManager = QApplicationPrivate::instance()->gestureManager; -
900 if (gestureManager) {
-
901 if (gestureManager->filterEvent(object, event))
-
902 return true;
-
903 }
-
904 -
905 }
-
906 -
907 if (filterEvent(item, event))
-
908 return false;
-
909 if (filterDescendantEvent(item, event))
-
910 return false;
-
911 if (!item || !item->isEnabled())
-
912 return false;
-
913 if (QGraphicsObject *o = item->toGraphicsObject()) {
-
914 bool spont = event->spontaneous(); -
915 if (spont ? qt_sendSpontaneousEvent(o, event) : QApplication::sendEvent(o, event))
-
916 return true;
-
917 event->spont = spont; -
918 }
-
919 return item->sceneEvent(event);
-
920} -
921 -
922 -
923 -
924 -
925void QGraphicsScenePrivate::cloneDragDropEvent(QGraphicsSceneDragDropEvent *dest, -
926 QGraphicsSceneDragDropEvent *source) -
927{ -
928 dest->setWidget(source->widget()); -
929 dest->setPos(source->pos()); -
930 dest->setScenePos(source->scenePos()); -
931 dest->setScreenPos(source->screenPos()); -
932 dest->setButtons(source->buttons()); -
933 dest->setModifiers(source->modifiers()); -
934 dest->setPossibleActions(source->possibleActions()); -
935 dest->setProposedAction(source->proposedAction()); -
936 dest->setDropAction(source->dropAction()); -
937 dest->setSource(source->source()); -
938 dest->setMimeData(source->mimeData()); -
939}
-
940 -
941 -
942 -
943 -
944void QGraphicsScenePrivate::sendDragDropEvent(QGraphicsItem *item, -
945 QGraphicsSceneDragDropEvent *dragDropEvent) -
946{ -
947 dragDropEvent->setPos(item->d_ptr->genericMapFromScene(dragDropEvent->scenePos(), dragDropEvent->widget())); -
948 sendEvent(item, dragDropEvent); -
949}
-
950 -
951 -
952 -
953 -
954void QGraphicsScenePrivate::sendHoverEvent(QEvent::Type type, QGraphicsItem *item, -
955 QGraphicsSceneHoverEvent *hoverEvent) -
956{ -
957 QGraphicsSceneHoverEvent event(type); -
958 event.setWidget(hoverEvent->widget()); -
959 event.setPos(item->d_ptr->genericMapFromScene(hoverEvent->scenePos(), hoverEvent->widget())); -
960 event.setScenePos(hoverEvent->scenePos()); -
961 event.setScreenPos(hoverEvent->screenPos()); -
962 event.setLastPos(item->d_ptr->genericMapFromScene(hoverEvent->lastScenePos(), hoverEvent->widget())); -
963 event.setLastScenePos(hoverEvent->lastScenePos()); -
964 event.setLastScreenPos(hoverEvent->lastScreenPos()); -
965 event.setModifiers(hoverEvent->modifiers()); -
966 sendEvent(item, &event); -
967}
-
968 -
969 -
970 -
971 -
972void QGraphicsScenePrivate::sendMouseEvent(QGraphicsSceneMouseEvent *mouseEvent) -
973{ -
974 if (mouseEvent->button() == 0 && mouseEvent->buttons() == 0 && lastMouseGrabberItemHasImplicitMouseGrab) {
-
975 -
976 -
977 clearMouseGrabber(); -
978 return;
-
979 } -
980 -
981 QGraphicsItem *item = mouseGrabberItems.last(); -
982 if (item->isBlockedByModalPanel())
-
983 return;
-
984 -
985 for (int i = 0x1; i <= 0x10; i <<= 1) {
-
986 Qt::MouseButton button = Qt::MouseButton(i); -
987 mouseEvent->setButtonDownPos(button, mouseGrabberButtonDownPos.value(button, item->d_ptr->genericMapFromScene(mouseEvent->scenePos(), mouseEvent->widget()))); -
988 mouseEvent->setButtonDownScenePos(button, mouseGrabberButtonDownScenePos.value(button, mouseEvent->scenePos())); -
989 mouseEvent->setButtonDownScreenPos(button, mouseGrabberButtonDownScreenPos.value(button, mouseEvent->screenPos())); -
990 }
-
991 mouseEvent->setPos(item->d_ptr->genericMapFromScene(mouseEvent->scenePos(), mouseEvent->widget())); -
992 mouseEvent->setLastPos(item->d_ptr->genericMapFromScene(mouseEvent->lastScenePos(), mouseEvent->widget())); -
993 sendEvent(item, mouseEvent); -
994}
-
995 -
996 -
997 -
998 -
999void QGraphicsScenePrivate::mousePressEventHandler(QGraphicsSceneMouseEvent *mouseEvent) -
1000{ -
1001 QGraphicsScene * const q = q_func(); -
1002 -
1003 -
1004 mouseEvent->ignore(); -
1005 -
1006 -
1007 if (!mouseGrabberItems.isEmpty()) {
-
1008 if (mouseGrabberItems.last()->isBlockedByModalPanel())
-
1009 return;
-
1010 -
1011 -
1012 sendMouseEvent(mouseEvent); -
1013 return;
-
1014 } -
1015 -
1016 -
1017 -
1018 if (cachedItemsUnderMouse.isEmpty()) {
-
1019 cachedItemsUnderMouse = itemsAtPosition(mouseEvent->screenPos(), -
1020 mouseEvent->scenePos(), -
1021 mouseEvent->widget()); -
1022 }
-
1023 -
1024 -
1025 QGraphicsItem *topItem = cachedItemsUnderMouse.value(0); -
1026 QGraphicsWidget *newActiveWindow = topItem ? topItem->window() : 0;
-
1027 if (newActiveWindow && newActiveWindow->isBlockedByModalPanel(&topItem)) {
-
1028 -
1029 newActiveWindow = topItem ? topItem->window() : 0;
-
1030 }
-
1031 -
1032 if (newActiveWindow != q->activeWindow())
-
1033 q->setActiveWindow(newActiveWindow);
-
1034 -
1035 -
1036 bool setFocus = false; -
1037 -
1038 for (QForeachContainer<__typeof__(cachedItemsUnderMouse)> _container_(cachedItemsUnderMouse); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (QGraphicsItem *item = *_container_.i;; __extension__ ({--_container_.brk; break;})) { -
1039 if (item->isBlockedByModalPanel()
-
1040 || (item->d_ptr->flags & QGraphicsItem::ItemStopsFocusHandling)) {
-
1041 -
1042 setFocus = true; -
1043 break;
-
1044 } -
1045 if (item->isEnabled() && ((item->flags() & QGraphicsItem::ItemIsFocusable))) {
-
1046 if (!item->isWidget() || ((QGraphicsWidget *)item)->focusPolicy() & Qt::ClickFocus) {
-
1047 setFocus = true; -
1048 if (item != q->focusItem() && item->d_ptr->mouseSetsFocus)
-
1049 q->setFocusItem(item, Qt::MouseFocusReason);
-
1050 break;
-
1051 } -
1052 }
-
1053 if (item->isPanel())
-
1054 break;
-
1055 if (item->d_ptr->flags & QGraphicsItem::ItemStopsClickFocusPropagation)
-
1056 break;
-
1057 }
-
1058 -
1059 -
1060 bool sceneModality = false; -
1061 for (int i = 0; i < modalPanels.size(); ++i) {
-
1062 if (modalPanels.at(i)->panelModality() == QGraphicsItem::SceneModal) {
-
1063 sceneModality = true; -
1064 break;
-
1065 } -
1066 }
-
1067 -
1068 -
1069 if (!stickyFocus && !setFocus && !sceneModality)
-
1070 q->setFocusItem(0, Qt::MouseFocusReason);
-
1071 -
1072 -
1073 if (sceneModality && cachedItemsUnderMouse.isEmpty())
-
1074 cachedItemsUnderMouse << modalPanels.first();
-
1075 -
1076 -
1077 -
1078 -
1079 -
1080 for (QForeachContainer<__typeof__(cachedItemsUnderMouse)> _container_(cachedItemsUnderMouse); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (QGraphicsItem *item = *_container_.i;; __extension__ ({--_container_.brk; break;})) { -
1081 if (!(item->acceptedMouseButtons() & mouseEvent->button())) {
-
1082 -
1083 continue;
-
1084 } -
1085 -
1086 -
1087 -
1088 (void) item->isBlockedByModalPanel(&item); -
1089 -
1090 grabMouse(item, true); -
1091 mouseEvent->accept(); -
1092 -
1093 -
1094 bool disabled = !item->isEnabled(); -
1095 bool isPanel = item->isPanel(); -
1096 if (mouseEvent->type() == QEvent::GraphicsSceneMouseDoubleClick
-
1097 && item != lastMouseGrabberItem && lastMouseGrabberItem) {
-
1098 -
1099 -
1100 -
1101 -
1102 QGraphicsSceneMouseEvent mousePress(QEvent::GraphicsSceneMousePress); -
1103 mousePress.spont = mouseEvent->spont; -
1104 mousePress.accept(); -
1105 mousePress.setButton(mouseEvent->button()); -
1106 mousePress.setButtons(mouseEvent->buttons()); -
1107 mousePress.setScreenPos(mouseEvent->screenPos()); -
1108 mousePress.setScenePos(mouseEvent->scenePos()); -
1109 mousePress.setModifiers(mouseEvent->modifiers()); -
1110 mousePress.setWidget(mouseEvent->widget()); -
1111 mousePress.setButtonDownPos(mouseEvent->button(), -
1112 mouseEvent->buttonDownPos(mouseEvent->button())); -
1113 mousePress.setButtonDownScenePos(mouseEvent->button(), -
1114 mouseEvent->buttonDownScenePos(mouseEvent->button())); -
1115 mousePress.setButtonDownScreenPos(mouseEvent->button(), -
1116 mouseEvent->buttonDownScreenPos(mouseEvent->button())); -
1117 sendMouseEvent(&mousePress); -
1118 mouseEvent->setAccepted(mousePress.isAccepted()); -
1119 } else {
-
1120 sendMouseEvent(mouseEvent); -
1121 }
-
1122 -
1123 bool dontSendUngrabEvents = mouseGrabberItems.isEmpty() || mouseGrabberItems.last() != item;
-
1124 if (disabled) {
-
1125 ungrabMouse(item, dontSendUngrabEvents); -
1126 break;
-
1127 } -
1128 if (mouseEvent->isAccepted()) {
-
1129 if (!mouseGrabberItems.isEmpty())
-
1130 storeMouseButtonsForMouseGrabber(mouseEvent);
-
1131 lastMouseGrabberItem = item; -
1132 return;
-
1133 } -
1134 ungrabMouse(item, dontSendUngrabEvents); -
1135 -
1136 -
1137 if (isPanel)
-
1138 break;
-
1139 }
-
1140 -
1141 -
1142 -
1143 -
1144 -
1145 if (!mouseEvent->isAccepted()) {
-
1146 clearMouseGrabber(); -
1147 -
1148 QGraphicsView *view = mouseEvent->widget() ? qobject_cast<QGraphicsView *>(mouseEvent->widget()->parentWidget()) : 0;
-
1149 bool dontClearSelection = view && view->dragMode() == QGraphicsView::ScrollHandDrag;
-
1150 if (!dontClearSelection) {
-
1151 -
1152 -
1153 -
1154 q->clearSelection(); -
1155 }
-
1156 }
-
1157}
-
1158void QGraphicsScenePrivate::ensureSequentialTopLevelSiblingIndexes() -
1159{ -
1160 if (!topLevelSequentialOrdering) {
-
1161 std::sort(topLevelItems.begin(), topLevelItems.end(), QGraphicsItemPrivate::insertionOrder); -
1162 topLevelSequentialOrdering = true; -
1163 needSortTopLevelItems = 1; -
1164 }
-
1165 if (holesInTopLevelSiblingIndex) {
-
1166 holesInTopLevelSiblingIndex = 0; -
1167 for (int i = 0; i < topLevelItems.size(); ++i)
-
1168 topLevelItems[i]->d_ptr->siblingIndex = i;
-
1169 }
-
1170}
-
1171 -
1172 -
1173 -
1174 -
1175 -
1176 -
1177 -
1178void QGraphicsScenePrivate::setFont_helper(const QFont &font) -
1179{ -
1180 if (this->font == font && this->font.resolve() == font.resolve())
-
1181 return;
-
1182 updateFont(font); -
1183}
-
1184 -
1185 -
1186 -
1187 -
1188 -
1189 -
1190 -
1191void QGraphicsScenePrivate::resolveFont() -
1192{ -
1193 QFont naturalFont = QApplication::font(); -
1194 naturalFont.resolve(0); -
1195 QFont resolvedFont = font.resolve(naturalFont); -
1196 updateFont(resolvedFont); -
1197}
-
1198 -
1199 -
1200 -
1201 -
1202 -
1203 -
1204 -
1205void QGraphicsScenePrivate::updateFont(const QFont &font) -
1206{ -
1207 QGraphicsScene * const q = q_func(); -
1208 -
1209 -
1210 this->font = font; -
1211 -
1212 -
1213 -
1214 for (QForeachContainer<__typeof__(q->items())> _container_(q->items()); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (QGraphicsItem *item = *_container_.i;; __extension__ ({--_container_.brk; break;})) { -
1215 if (!item->parentItem()) {
-
1216 -
1217 -
1218 -
1219 item->d_ptr->resolveFont(font.resolve()); -
1220 }
-
1221 }
-
1222 -
1223 -
1224 QEvent event(QEvent::FontChange); -
1225 QApplication::sendEvent(q, &event); -
1226}
-
1227 -
1228 -
1229 -
1230 -
1231 -
1232 -
1233 -
1234void QGraphicsScenePrivate::setPalette_helper(const QPalette &palette) -
1235{ -
1236 if (this->palette == palette && this->palette.resolve() == palette.resolve())
-
1237 return;
-
1238 updatePalette(palette); -
1239}
-
1240 -
1241 -
1242 -
1243 -
1244 -
1245 -
1246 -
1247void QGraphicsScenePrivate::resolvePalette() -
1248{ -
1249 QPalette naturalPalette = QApplication::palette(); -
1250 naturalPalette.resolve(0); -
1251 QPalette resolvedPalette = palette.resolve(naturalPalette); -
1252 updatePalette(resolvedPalette); -
1253}
-
1254 -
1255 -
1256 -
1257 -
1258 -
1259 -
1260 -
1261void QGraphicsScenePrivate::updatePalette(const QPalette &palette) -
1262{ -
1263 QGraphicsScene * const q = q_func(); -
1264 -
1265 -
1266 this->palette = palette; -
1267 -
1268 -
1269 -
1270 for (QForeachContainer<__typeof__(q->items())> _container_(q->items()); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (QGraphicsItem *item = *_container_.i;; __extension__ ({--_container_.brk; break;})) { -
1271 if (!item->parentItem()) {
-
1272 -
1273 -
1274 -
1275 item->d_ptr->resolvePalette(palette.resolve()); -
1276 }
-
1277 }
-
1278 -
1279 -
1280 QEvent event(QEvent::PaletteChange); -
1281 QApplication::sendEvent(q, &event); -
1282}
-
1283 -
1284 -
1285 -
1286 -
1287 -
1288QGraphicsScene::QGraphicsScene(QObject *parent) -
1289 : QObject(*new QGraphicsScenePrivate, parent) -
1290{ -
1291 d_func()->init(); -
1292}
-
1293QGraphicsScene::QGraphicsScene(const QRectF &sceneRect, QObject *parent) -
1294 : QObject(*new QGraphicsScenePrivate, parent) -
1295{ -
1296 d_func()->init(); -
1297 setSceneRect(sceneRect); -
1298}
-
1299QGraphicsScene::QGraphicsScene(qreal x, qreal y, qreal width, qreal height, QObject *parent) -
1300 : QObject(*new QGraphicsScenePrivate, parent) -
1301{ -
1302 d_func()->init(); -
1303 setSceneRect(x, y, width, height); -
1304}
-
1305 -
1306 -
1307 -
1308 -
1309 -
1310 -
1311 -
1312QGraphicsScene::~QGraphicsScene() -
1313{ -
1314 QGraphicsScenePrivate * const d = d_func(); -
1315 -
1316 -
1317 if (!QApplicationPrivate::is_app_closing)
-
1318 (static_cast<QApplication *>(QCoreApplication::instance()))->d_func()->scene_list.removeAll(this);
-
1319 -
1320 clear(); -
1321 -
1322 -
1323 for (int j = 0; j < d->views.size(); ++j)
-
1324 d->views.at(j)->setScene(0);
-
1325}
-
1326QRectF QGraphicsScene::sceneRect() const -
1327{ -
1328 const QGraphicsScenePrivate * const d = d_func(); -
1329 if (d->hasSceneRect)
-
1330 return d->sceneRect;
-
1331 -
1332 if (d->dirtyGrowingItemsBoundingRect) {
-
1333 -
1334 QGraphicsScenePrivate *thatd = const_cast<QGraphicsScenePrivate *>(d); -
1335 QRectF oldGrowingBoundingRect = thatd->growingItemsBoundingRect; -
1336 thatd->growingItemsBoundingRect |= itemsBoundingRect(); -
1337 thatd->dirtyGrowingItemsBoundingRect = false; -
1338 if (oldGrowingBoundingRect != thatd->growingItemsBoundingRect)
-
1339 const_cast<QGraphicsScene *>(this)->sceneRectChanged(thatd->growingItemsBoundingRect);
-
1340 }
-
1341 return d->growingItemsBoundingRect;
-
1342} -
1343void QGraphicsScene::setSceneRect(const QRectF &rect) -
1344{ -
1345 QGraphicsScenePrivate * const d = d_func(); -
1346 if (rect != d->sceneRect) {
-
1347 d->hasSceneRect = !rect.isNull(); -
1348 d->sceneRect = rect; -
1349 sceneRectChanged(d->hasSceneRect ? rect : d->growingItemsBoundingRect); -
1350 }
-
1351}
-
1352void QGraphicsScene::render(QPainter *painter, const QRectF &target, const QRectF &source, -
1353 Qt::AspectRatioMode aspectRatioMode) -
1354{ -
1355 -
1356 -
1357 -
1358 QRectF sourceRect = source; -
1359 if (sourceRect.isNull())
-
1360 sourceRect = sceneRect();
-
1361 -
1362 -
1363 QRectF targetRect = target; -
1364 if (targetRect.isNull()) {
-
1365 if (painter->device()->devType() == QInternal::Picture)
-
1366 targetRect = sourceRect;
-
1367 else -
1368 targetRect.setRect(0, 0, painter->device()->width(), painter->device()->height());
-
1369 } -
1370 -
1371 -
1372 qreal xratio = targetRect.width() / sourceRect.width(); -
1373 qreal yratio = targetRect.height() / sourceRect.height(); -
1374 -
1375 -
1376 switch (aspectRatioMode) { -
1377 case Qt::KeepAspectRatio: -
1378 xratio = yratio = qMin(xratio, yratio); -
1379 break;
-
1380 case Qt::KeepAspectRatioByExpanding: -
1381 xratio = yratio = qMax(xratio, yratio); -
1382 break;
-
1383 case Qt::IgnoreAspectRatio: -
1384 break;
-
1385 } -
1386 -
1387 -
1388 -
1389 QList<QGraphicsItem *> itemList = items(sourceRect, Qt::IntersectsItemBoundingRect); -
1390 QGraphicsItem **itemArray = new QGraphicsItem *[itemList.size()]; -
1391 int numItems = itemList.size(); -
1392 for (int i = 0; i < numItems; ++i)
-
1393 itemArray[numItems - i - 1] = itemList.at(i);
-
1394 itemList.clear(); -
1395 -
1396 painter->save(); -
1397 -
1398 -
1399 painter->setClipRect(targetRect, Qt::IntersectClip); -
1400 QTransform painterTransform; -
1401 painterTransform *= QTransform() -
1402 .translate(targetRect.left(), targetRect.top()) -
1403 .scale(xratio, yratio) -
1404 .translate(-sourceRect.left(), -sourceRect.top()); -
1405 painter->setWorldTransform(painterTransform, true); -
1406 -
1407 -
1408 QLineF v1(0, 0, 1, 0); -
1409 QLineF v2(0, 0, 0, 1); -
1410 -
1411 -
1412 QStyleOptionGraphicsItem *styleOptionArray = new QStyleOptionGraphicsItem[numItems]; -
1413 for (int i = 0; i < numItems; ++i)
-
1414 itemArray[i]->d_ptr->initStyleOption(&styleOptionArray[i], painterTransform, targetRect.toRect());
-
1415 -
1416 -
1417 drawBackground(painter, sourceRect); -
1418 drawItems(painter, numItems, itemArray, styleOptionArray); -
1419 drawForeground(painter, sourceRect); -
1420 -
1421 delete [] itemArray; -
1422 delete [] styleOptionArray; -
1423 -
1424 painter->restore(); -
1425}
-
1426QGraphicsScene::ItemIndexMethod QGraphicsScene::itemIndexMethod() const -
1427{ -
1428 const QGraphicsScenePrivate * const d = d_func(); -
1429 return d->indexMethod;
-
1430} -
1431void QGraphicsScene::setItemIndexMethod(ItemIndexMethod method) -
1432{ -
1433 QGraphicsScenePrivate * const d = d_func(); -
1434 if (d->indexMethod == method)
-
1435 return;
-
1436 -
1437 d->indexMethod = method; -
1438 -
1439 QList<QGraphicsItem *> oldItems = d->index->items(Qt::DescendingOrder); -
1440 delete d->index; -
1441 if (method == BspTreeIndex)
-
1442 d->index = new QGraphicsSceneBspTreeIndex(this);
-
1443 else -
1444 d->index = new QGraphicsSceneLinearIndex(this);
-
1445 for (int i = oldItems.size() - 1; i >= 0; --i)
-
1446 d->index->addItem(oldItems.at(i));
-
1447}
-
1448int QGraphicsScene::bspTreeDepth() const -
1449{ -
1450 const QGraphicsScenePrivate * const d = d_func(); -
1451 QGraphicsSceneBspTreeIndex *bspTree = qobject_cast<QGraphicsSceneBspTreeIndex *>(d->index); -
1452 return bspTree ? bspTree->bspTreeDepth() : 0;
-
1453} -
1454void QGraphicsScene::setBspTreeDepth(int depth) -
1455{ -
1456 QGraphicsScenePrivate * const d = d_func(); -
1457 if (depth < 0) {
-
1458 QMessageLogger("graphicsview/qgraphicsscene.cpp", 18831872, __PRETTY_FUNCTION__).warning("QGraphicsScene::setBspTreeDepth: invalid depth %d ignored; must be >= 0", depth); -
1459 return;
-
1460 } -
1461 -
1462 QGraphicsSceneBspTreeIndex *bspTree = qobject_cast<QGraphicsSceneBspTreeIndex *>(d->index); -
1463 if (!bspTree) {
-
1464 QMessageLogger("graphicsview/qgraphicsscene.cpp", 18891878, __PRETTY_FUNCTION__).warning("QGraphicsScene::setBspTreeDepth: can not apply if indexing method is not BSP"); -
1465 return;
-
1466 } -
1467 bspTree->setBspTreeDepth(depth); -
1468}
-
1469bool QGraphicsScene::isSortCacheEnabled() const -
1470{ -
1471 const QGraphicsScenePrivate * const d = d_func(); -
1472 return d->sortCacheEnabled;
-
1473} -
1474void QGraphicsScene::setSortCacheEnabled(bool enabled) -
1475{ -
1476 QGraphicsScenePrivate * const d = d_func(); -
1477 if (d->sortCacheEnabled == enabled)
-
1478 return;
-
1479 d->sortCacheEnabled = enabled; -
1480}
-
1481QRectF QGraphicsScene::itemsBoundingRect() const -
1482{ -
1483 -
1484 QRectF boundingRect; -
1485 for (QForeachContainer<__typeof__(items())> _container_(items()); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (QGraphicsItem *item = *_container_.i;; __extension__ ({--_container_.brk; break;})) -
1486 boundingRect |= item->sceneBoundingRect();
-
1487 return boundingRect;
-
1488} -
1489 -
1490 -
1491 -
1492 -
1493 -
1494 -
1495 -
1496QList<QGraphicsItem *> QGraphicsScene::items(Qt::SortOrder order) const -
1497{ -
1498 const QGraphicsScenePrivate * const d = d_func(); -
1499 return d->index->items(order);
-
1500} -
1501QList<QGraphicsItem *> QGraphicsScene::items(const QPointF &pos, Qt::ItemSelectionMode mode, -
1502 Qt::SortOrder order, const QTransform &deviceTransform) const -
1503{ -
1504 const QGraphicsScenePrivate * const d = d_func(); -
1505 return d->index->items(pos, mode, order, deviceTransform);
-
1506} -
1507QList<QGraphicsItem *> QGraphicsScene::items(const QRectF &rect, Qt::ItemSelectionMode mode, -
1508 Qt::SortOrder order, const QTransform &deviceTransform) const -
1509{ -
1510 const QGraphicsScenePrivate * const d = d_func(); -
1511 return d->index->items(rect, mode, order, deviceTransform);
-
1512} -
1513QList<QGraphicsItem *> QGraphicsScene::items(const QPolygonF &polygon, Qt::ItemSelectionMode mode, -
1514 Qt::SortOrder order, const QTransform &deviceTransform) const -
1515{ -
1516 const QGraphicsScenePrivate * const d = d_func(); -
1517 return d->index->items(polygon, mode, order, deviceTransform);
-
1518} -
1519QList<QGraphicsItem *> QGraphicsScene::items(const QPainterPath &path, Qt::ItemSelectionMode mode, -
1520 Qt::SortOrder order, const QTransform &deviceTransform) const -
1521{ -
1522 const QGraphicsScenePrivate * const d = d_func(); -
1523 return d->index->items(path, mode, order, deviceTransform);
-
1524} -
1525QList<QGraphicsItem *> QGraphicsScene::collidingItems(const QGraphicsItem *item, -
1526 Qt::ItemSelectionMode mode) const -
1527{ -
1528 const QGraphicsScenePrivate * const d = d_func(); -
1529 if (!item) {
-
1530 QMessageLogger("graphicsview/qgraphicsscene.cpp", 20902079, __PRETTY_FUNCTION__).warning("QGraphicsScene::collidingItems: cannot find collisions for null item"); -
1531 return QList<QGraphicsItem *>();
-
1532 } -
1533 -
1534 -
1535 QList<QGraphicsItem *> tmp; -
1536 for (QForeachContainer<__typeof__(d->index->estimateItems(item->sceneBoundingRect(), Qt::DescendingOrder))> _container_(d->index->estimateItems(item->sceneBoundingRect(), Qt::DescendingOrder)); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (QGraphicsItem *itemInVicinity = *_container_.i;; __extension__ ({--_container_.brk; break;})) { -
1537 if (item != itemInVicinity && item->collidesWithItem(itemInVicinity, mode))
-
1538 tmp << itemInVicinity;
-
1539 }
-
1540 return tmp;
-
1541} -
1542QGraphicsItem *QGraphicsScene::itemAt(const QPointF &position, const QTransform &deviceTransform) const -
1543{ -
1544 QList<QGraphicsItem *> itemsAtPoint = items(position, Qt::IntersectsItemShape, -
1545 Qt::DescendingOrder, deviceTransform); -
1546 return itemsAtPoint.isEmpty() ? 0 : itemsAtPoint.first();
-
1547} -
1548QList<QGraphicsItem *> QGraphicsScene::selectedItems() const -
1549{ -
1550 const QGraphicsScenePrivate * const d = d_func(); -
1551 -
1552 -
1553 QGraphicsScene *that = const_cast<QGraphicsScene *>(this); -
1554 QSet<QGraphicsItem *> actuallySelectedSet; -
1555 for (QForeachContainer<__typeof__(that->d_func()->selectedItems)> _container_(that->d_func()->selectedItems); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (QGraphicsItem *item = *_container_.i;; __extension__ ({--_container_.brk; break;})) { -
1556 if (item->isSelected())
-
1557 actuallySelectedSet << item;
-
1558 }
-
1559 -
1560 that->d_func()->selectedItems = actuallySelectedSet; -
1561 -
1562 return d->selectedItems.values();
-
1563} -
1564QPainterPath QGraphicsScene::selectionArea() const -
1565{ -
1566 const QGraphicsScenePrivate * const d = d_func(); -
1567 return d->selectionArea;
-
1568} -
1569void QGraphicsScene::setSelectionArea(const QPainterPath &path, const QTransform &deviceTransform) -
1570{ -
1571 setSelectionArea(path, Qt::IntersectsItemShape, deviceTransform); -
1572}
-
1573void QGraphicsScene::setSelectionArea(const QPainterPath &path, Qt::ItemSelectionMode mode, -
1574 const QTransform &deviceTransform) -
1575{ -
1576 QGraphicsScenePrivate * const d = d_func(); -
1577 -
1578 -
1579 -
1580 -
1581 -
1582 d->selectionArea = path; -
1583 -
1584 QSet<QGraphicsItem *> unselectItems = d->selectedItems; -
1585 -
1586 -
1587 ++d->selectionChanging; -
1588 bool changed = false; -
1589 -
1590 -
1591 for (QForeachContainer<__typeof__(items(path, mode, Qt::DescendingOrder, deviceTransform))> _container_(items(path, mode, Qt::DescendingOrder, deviceTransform)); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (QGraphicsItem *item = *_container_.i;; __extension__ ({--_container_.brk; break;})) { -
1592 if (item->flags() & QGraphicsItem::ItemIsSelectable) {
-
1593 if (!item->isSelected())
-
1594 changed = true;
-
1595 unselectItems.remove(item); -
1596 item->setSelected(true); -
1597 }
-
1598 }
-
1599 -
1600 -
1601 for (QForeachContainer<__typeof__(unselectItems)> _container_(unselectItems); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (QGraphicsItem *item = *_container_.i;; __extension__ ({--_container_.brk; break;})) { -
1602 item->setSelected(false); -
1603 changed = true; -
1604 }
-
1605 -
1606 -
1607 --d->selectionChanging; -
1608 -
1609 if (!d->selectionChanging && changed)
-
1610 selectionChanged();
-
1611}
-
1612 -
1613 -
1614 -
1615 -
1616 -
1617 -
1618void QGraphicsScene::clearSelection() -
1619{ -
1620 QGraphicsScenePrivate * const d = d_func(); -
1621 -
1622 -
1623 ++d->selectionChanging; -
1624 bool changed = !d->selectedItems.isEmpty(); -
1625 -
1626 for (QForeachContainer<__typeof__(d->selectedItems)> _container_(d->selectedItems); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (QGraphicsItem *item = *_container_.i;; __extension__ ({--_container_.brk; break;})) -
1627 item->setSelected(false);
-
1628 d->selectedItems.clear(); -
1629 -
1630 -
1631 --d->selectionChanging; -
1632 -
1633 if (!d->selectionChanging && changed)
-
1634 selectionChanged();
-
1635}
-
1636void QGraphicsScene::clear() -
1637{ -
1638 QGraphicsScenePrivate * const d = d_func(); -
1639 -
1640 -
1641 d->index->clear(); -
1642 -
1643 while (!d->topLevelItems.isEmpty())
-
1644 delete d->topLevelItems.first();
-
1645 qt_noop(); -
1646 d->lastItemCount = 0; -
1647 d->allItemsIgnoreHoverEvents = true; -
1648 d->allItemsUseDefaultCursor = true; -
1649 d->allItemsIgnoreTouchEvents = true; -
1650}
-
1651QGraphicsItemGroup *QGraphicsScene::createItemGroup(const QList<QGraphicsItem *> &items) -
1652{ -
1653 -
1654 QList<QGraphicsItem *> ancestors; -
1655 int n = 0; -
1656 if (!items.isEmpty()) {
-
1657 QGraphicsItem *parent = items.at(n++); -
1658 while ((parent = parent->parentItem()))
-
1659 ancestors.append(parent);
-
1660 }
-
1661 -
1662 -
1663 QGraphicsItem *commonAncestor = 0; -
1664 if (!ancestors.isEmpty()) {
-
1665 while (n < items.size()) {
-
1666 int commonIndex = -1; -
1667 QGraphicsItem *parent = items.at(n++); -
1668 do { -
1669 int index = ancestors.indexOf(parent, qMax(0, commonIndex)); -
1670 if (index != -1) {
-
1671 commonIndex = index; -
1672 break;
-
1673 } -
1674 } while ((parent = parent->parentItem()));
-
1675 -
1676 if (commonIndex == -1) {
-
1677 commonAncestor = 0; -
1678 break;
-
1679 } -
1680 -
1681 commonAncestor = ancestors.at(commonIndex); -
1682 }
-
1683 }
-
1684 -
1685 -
1686 QGraphicsItemGroup *group = new QGraphicsItemGroup(commonAncestor); -
1687 if (!commonAncestor)
-
1688 addItem(group);
-
1689 for (QForeachContainer<__typeof__(items)> _container_(items); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (QGraphicsItem *item = *_container_.i;; __extension__ ({--_container_.brk; break;})) -
1690 group->addToGroup(item);
-
1691 return group;
-
1692} -
1693void QGraphicsScene::destroyItemGroup(QGraphicsItemGroup *group) -
1694{ -
1695 for (QForeachContainer<__typeof__(group->childItems())> _container_(group->childItems()); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (QGraphicsItem *item = *_container_.i;; __extension__ ({--_container_.brk; break;})) -
1696 group->removeFromGroup(item);
-
1697 removeItem(group); -
1698 delete group; -
1699}
-
1700void QGraphicsScene::addItem(QGraphicsItem *item) -
1701{ -
1702 QGraphicsScenePrivate * const d = d_func(); -
1703 if (!item) {
-
1704 QMessageLogger("graphicsview/qgraphicsscene.cpp", 24312420, __PRETTY_FUNCTION__).warning("QGraphicsScene::addItem: cannot add null item"); -
1705 return;
-
1706 } -
1707 if (item->d_ptr->scene == this) {
-
1708 QMessageLogger("graphicsview/qgraphicsscene.cpp", 24352424, __PRETTY_FUNCTION__).warning("QGraphicsScene::addItem: item has already been added to this scene"); -
1709 return;
-
1710 } -
1711 -
1712 if (QGraphicsScene *oldScene = item->d_ptr->scene)
-
1713 oldScene->removeItem(item);
-
1714 -
1715 -
1716 -
1717 const QVariant newSceneVariant(item->itemChange(QGraphicsItem::ItemSceneChange, -
1718 QVariant::fromValue<QGraphicsScene *>(this))); -
1719 QGraphicsScene *targetScene = qvariant_cast<QGraphicsScene *>(newSceneVariant); -
1720 if (targetScene != this) {
-
1721 if (targetScene && item->d_ptr->scene != targetScene)
-
1722 targetScene->addItem(item);
-
1723 return;
-
1724 } -
1725 -
1726 -
1727 -
1728 if (!item->d_ptr->isDeclarativeItem) {
-
1729 if (d->unpolishedItems.isEmpty()) {
-
1730 QMetaMethod method = metaObject()->method(d->polishItemsIndex); -
1731 method.invoke(this, Qt::QueuedConnection); -
1732 }
-
1733 d->unpolishedItems.append(item); -
1734 item->d_ptr->pendingPolish = true; -
1735 }
-
1736 -
1737 -
1738 -
1739 if (QGraphicsItem *itemParent = item->d_ptr->parent) {
-
1740 if (itemParent->d_ptr->scene != this)
-
1741 item->setParentItem(0);
-
1742 }
-
1743 -
1744 -
1745 item->d_func()->scene = targetScene; -
1746 -
1747 -
1748 d->index->addItem(item); -
1749 -
1750 -
1751 if (!item->d_ptr->parent)
-
1752 d->registerTopLevelItem(item);
-
1753 -
1754 -
1755 -
1756 -
1757 d->markDirty(item); -
1758 d->dirtyGrowingItemsBoundingRect = true; -
1759 -
1760 -
1761 ++d->selectionChanging; -
1762 int oldSelectedItemSize = d->selectedItems.size(); -
1763 -
1764 -
1765 if (d->allItemsIgnoreHoverEvents && d->itemAcceptsHoverEvents_helper(item)) {
-
1766 d->allItemsIgnoreHoverEvents = false; -
1767 d->enableMouseTrackingOnViews(); -
1768 }
-
1769 -
1770 if (d->allItemsUseDefaultCursor && item->d_ptr->hasCursor) {
-
1771 d->allItemsUseDefaultCursor = false; -
1772 if (d->allItemsIgnoreHoverEvents)
-
1773 d->enableMouseTrackingOnViews();
-
1774 }
-
1775 -
1776 -
1777 -
1778 if (d->allItemsIgnoreTouchEvents && item->d_ptr->acceptTouchEvents) {
-
1779 d->allItemsIgnoreTouchEvents = false; -
1780 d->enableTouchEventsOnViews(); -
1781 }
-
1782 -
1783 -
1784 for (QForeachContainer<__typeof__(item->d_ptr->gestureContext.keys())> _container_(item->d_ptr->gestureContext.keys()); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (Qt::GestureType gesture = *_container_.i;; __extension__ ({--_container_.brk; break;})) -
1785 d->grabGesture(item, gesture);
-
1786 -
1787 -
1788 -
1789 if (item->isSelected())
-
1790 d->selectedItems << item;
-
1791 if (item->isWidget() && item->isVisible() && static_cast<QGraphicsWidget *>(item)->windowType() == Qt::Popup)
-
1792 d->addPopup(static_cast<QGraphicsWidget *>(item));
-
1793 if (item->isPanel() && item->isVisible() && item->panelModality() != QGraphicsItem::NonModal)
-
1794 d->enterModal(item);
-
1795 -
1796 -
1797 -
1798 if (item->isWidget()) {
-
1799 QGraphicsWidget *widget = static_cast<QGraphicsWidget *>(item); -
1800 if (!d->tabFocusFirst) {
-
1801 -
1802 -
1803 d->tabFocusFirst = widget; -
1804 } else if (!widget->parentWidget()) {
-
1805 -
1806 QGraphicsWidget *last = d->tabFocusFirst->d_func()->focusPrev; -
1807 QGraphicsWidget *lastNew = widget->d_func()->focusPrev; -
1808 last->d_func()->focusNext = widget; -
1809 widget->d_func()->focusPrev = last; -
1810 d->tabFocusFirst->d_func()->focusPrev = lastNew; -
1811 lastNew->d_func()->focusNext = d->tabFocusFirst; -
1812 }
-
1813 } -
1814 -
1815 -
1816 item->d_ptr->ensureSortedChildren(); -
1817 for (int i = 0; i < item->d_ptr->children.size(); ++i)
-
1818 addItem(item->d_ptr->children.at(i));
-
1819 -
1820 -
1821 item->d_ptr->resolveFont(d->font.resolve()); -
1822 item->d_ptr->resolvePalette(d->palette.resolve()); -
1823 -
1824 -
1825 -
1826 --d->selectionChanging; -
1827 if (!d->selectionChanging && d->selectedItems.size() != oldSelectedItemSize)
-
1828 selectionChanged();
-
1829 -
1830 -
1831 item->itemChange(QGraphicsItem::ItemSceneHasChanged, newSceneVariant); -
1832 -
1833 -
1834 bool autoActivate = true; -
1835 if (!d->childExplicitActivation && item->d_ptr->explicitActivate)
-
1836 d->childExplicitActivation = item->d_ptr->wantsActive ? 1 : 2;
-
1837 if (d->childExplicitActivation && item->isPanel()) {
-
1838 if (d->childExplicitActivation == 1)
-
1839 setActivePanel(item);
-
1840 else -
1841 autoActivate = false;
-
1842 d->childExplicitActivation = 0; -
1843 } else if (!item->d_ptr->parent) {
-
1844 d->childExplicitActivation = 0; -
1845 }
-
1846 -
1847 -
1848 if (autoActivate) {
-
1849 if (!d->lastActivePanel && !d->activePanel && item->isPanel()) {
-
1850 if (isActive())
-
1851 setActivePanel(item);
-
1852 else -
1853 d->lastActivePanel = item;
-
1854 } -
1855 }
-
1856 -
1857 if (item->d_ptr->flags & QGraphicsItem::ItemSendsScenePositionChanges)
-
1858 d->registerScenePosItem(item);
-
1859 -
1860 -
1861 -
1862 if (!d->focusItem && item != d->lastFocusItem && item->focusItem() == item)
-
1863 item->focusItem()->setFocus();
-
1864 -
1865 d->updateInputMethodSensitivityInViews(); -
1866}
-
1867QGraphicsEllipseItem *QGraphicsScene::addEllipse(const QRectF &rect, const QPen &pen, const QBrush &brush) -
1868{ -
1869 QGraphicsEllipseItem *item = new QGraphicsEllipseItem(rect); -
1870 item->setPen(pen); -
1871 item->setBrush(brush); -
1872 addItem(item); -
1873 return item;
-
1874} -
1875QGraphicsLineItem *QGraphicsScene::addLine(const QLineF &line, const QPen &pen) -
1876{ -
1877 QGraphicsLineItem *item = new QGraphicsLineItem(line); -
1878 item->setPen(pen); -
1879 addItem(item); -
1880 return item;
-
1881} -
1882QGraphicsPathItem *QGraphicsScene::addPath(const QPainterPath &path, const QPen &pen, const QBrush &brush) -
1883{ -
1884 QGraphicsPathItem *item = new QGraphicsPathItem(path); -
1885 item->setPen(pen); -
1886 item->setBrush(brush); -
1887 addItem(item); -
1888 return item;
-
1889} -
1890QGraphicsPixmapItem *QGraphicsScene::addPixmap(const QPixmap &pixmap) -
1891{ -
1892 QGraphicsPixmapItem *item = new QGraphicsPixmapItem(pixmap); -
1893 addItem(item); -
1894 return item;
-
1895} -
1896QGraphicsPolygonItem *QGraphicsScene::addPolygon(const QPolygonF &polygon, -
1897 const QPen &pen, const QBrush &brush) -
1898{ -
1899 QGraphicsPolygonItem *item = new QGraphicsPolygonItem(polygon); -
1900 item->setPen(pen); -
1901 item->setBrush(brush); -
1902 addItem(item); -
1903 return item;
-
1904} -
1905QGraphicsRectItem *QGraphicsScene::addRect(const QRectF &rect, const QPen &pen, const QBrush &brush) -
1906{ -
1907 QGraphicsRectItem *item = new QGraphicsRectItem(rect); -
1908 item->setPen(pen); -
1909 item->setBrush(brush); -
1910 addItem(item); -
1911 return item;
-
1912} -
1913QGraphicsTextItem *QGraphicsScene::addText(const QString &text, const QFont &font) -
1914{ -
1915 QGraphicsTextItem *item = new QGraphicsTextItem(text); -
1916 item->setFont(font); -
1917 addItem(item); -
1918 return item;
-
1919} -
1920QGraphicsSimpleTextItem *QGraphicsScene::addSimpleText(const QString &text, const QFont &font) -
1921{ -
1922 QGraphicsSimpleTextItem *item = new QGraphicsSimpleTextItem(text); -
1923 item->setFont(font); -
1924 addItem(item); -
1925 return item;
-
1926} -
1927QGraphicsProxyWidget *QGraphicsScene::addWidget(QWidget *widget, Qt::WindowFlags wFlags) -
1928{ -
1929 QGraphicsProxyWidget *proxy = new QGraphicsProxyWidget(0, wFlags); -
1930 proxy->setWidget(widget); -
1931 addItem(proxy); -
1932 return proxy;
-
1933} -
1934void QGraphicsScene::removeItem(QGraphicsItem *item) -
1935{ -
1936 -
1937 QGraphicsScenePrivate * const d = d_func(); -
1938 if (!item) {
-
1939 QMessageLogger("graphicsview/qgraphicsscene.cpp", 28442833, __PRETTY_FUNCTION__).warning("QGraphicsScene::removeItem: cannot remove 0-item"); -
1940 return;
-
1941 } -
1942 if (item->scene() != this) {
-
1943 QMessageLogger("graphicsview/qgraphicsscene.cpp", 28482837, __PRETTY_FUNCTION__).warning("QGraphicsScene::removeItem: item %p's scene (%p)" -
1944 " is different from this scene (%p)", -
1945 item, item->scene(), this); -
1946 return;
-
1947 } -
1948 -
1949 -
1950 -
1951 const QVariant newSceneVariant(item->itemChange(QGraphicsItem::ItemSceneChange, -
1952 QVariant::fromValue<QGraphicsScene *>(0))); -
1953 QGraphicsScene *targetScene = qvariant_cast<QGraphicsScene *>(newSceneVariant); -
1954 if (targetScene != 0 && targetScene != this) {
-
1955 targetScene->addItem(item); -
1956 return;
-
1957 } -
1958 -
1959 d->removeItemHelper(item); -
1960 -
1961 -
1962 item->itemChange(QGraphicsItem::ItemSceneHasChanged, newSceneVariant); -
1963 -
1964 d->updateInputMethodSensitivityInViews(); -
1965}
-
1966QGraphicsItem *QGraphicsScene::focusItem() const -
1967{ -
1968 const QGraphicsScenePrivate * const d = d_func(); -
1969 return isActive() ? d->focusItem : d->passiveFocusItem;
-
1970} -
1971void QGraphicsScene::setFocusItem(QGraphicsItem *item, Qt::FocusReason focusReason) -
1972{ -
1973 QGraphicsScenePrivate * const d = d_func(); -
1974 if (item)
-
1975 item->setFocus(focusReason);
-
1976 else -
1977 d->setFocusItemHelper(item, focusReason);
-
1978} -
1979bool QGraphicsScene::hasFocus() const -
1980{ -
1981 const QGraphicsScenePrivate * const d = d_func(); -
1982 return d->hasFocus;
-
1983} -
1984void QGraphicsScene::setFocus(Qt::FocusReason focusReason) -
1985{ -
1986 QGraphicsScenePrivate * const d = d_func(); -
1987 if (d->hasFocus || !isActive())
-
1988 return;
-
1989 QFocusEvent event(QEvent::FocusIn, focusReason); -
1990 QCoreApplication::sendEvent(this, &event); -
1991}
-
1992void QGraphicsScene::clearFocus() -
1993{ -
1994 QGraphicsScenePrivate * const d = d_func(); -
1995 if (d->hasFocus) {
-
1996 d->hasFocus = false; -
1997 d->passiveFocusItem = d->focusItem; -
1998 setFocusItem(0, Qt::OtherFocusReason); -
1999 }
-
2000}
-
2001void QGraphicsScene::setStickyFocus(bool enabled) -
2002{ -
2003 QGraphicsScenePrivate * const d = d_func(); -
2004 d->stickyFocus = enabled; -
2005}
-
2006bool QGraphicsScene::stickyFocus() const -
2007{ -
2008 const QGraphicsScenePrivate * const d = d_func(); -
2009 return d->stickyFocus;
-
2010} -
2011QGraphicsItem *QGraphicsScene::mouseGrabberItem() const -
2012{ -
2013 const QGraphicsScenePrivate * const d = d_func(); -
2014 return !d->mouseGrabberItems.isEmpty() ? d->mouseGrabberItems.last() : 0;
-
2015} -
2016QBrush QGraphicsScene::backgroundBrush() const -
2017{ -
2018 const QGraphicsScenePrivate * const d = d_func(); -
2019 return d->backgroundBrush;
-
2020} -
2021void QGraphicsScene::setBackgroundBrush(const QBrush &brush) -
2022{ -
2023 QGraphicsScenePrivate * const d = d_func(); -
2024 d->backgroundBrush = brush; -
2025 for (QForeachContainer<__typeof__(d->views)> _container_(d->views); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (QGraphicsView *view = *_container_.i;; __extension__ ({--_container_.brk; break;})) { -
2026 view->resetCachedContent(); -
2027 view->viewport()->update(); -
2028 }
-
2029 update(); -
2030}
-
2031QBrush QGraphicsScene::foregroundBrush() const -
2032{ -
2033 const QGraphicsScenePrivate * const d = d_func(); -
2034 return d->foregroundBrush;
-
2035} -
2036void QGraphicsScene::setForegroundBrush(const QBrush &brush) -
2037{ -
2038 QGraphicsScenePrivate * const d = d_func(); -
2039 d->foregroundBrush = brush; -
2040 for (QForeachContainer<__typeof__(views())> _container_(views()); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (QGraphicsView *view = *_container_.i;; __extension__ ({--_container_.brk; break;})) -
2041 view->viewport()->update();
-
2042 update(); -
2043}
-
2044QVariant QGraphicsScene::inputMethodQuery(Qt::InputMethodQuery query) const -
2045{ -
2046 const QGraphicsScenePrivate * const d = d_func(); -
2047 if (!d->focusItem || !(d->focusItem->flags() & QGraphicsItem::ItemAcceptsInputMethod))
-
2048 return QVariant();
-
2049 const QTransform matrix = d->focusItem->sceneTransform(); -
2050 QVariant value = d->focusItem->inputMethodQuery(query); -
2051 if (value.type() == QVariant::RectF)
-
2052 value = matrix.mapRect(value.toRectF());
-
2053 else if (value.type() == QVariant::PointF)
-
2054 value = matrix.map(value.toPointF());
-
2055 else if (value.type() == QVariant::Rect)
-
2056 value = matrix.mapRect(value.toRect());
-
2057 else if (value.type() == QVariant::Point)
-
2058 value = matrix.map(value.toPoint());
-
2059 return value;
-
2060} -
2061 -
2062 -
2063 -
2064 -
2065 -
2066 -
2067 -
2068void QGraphicsScene::update(const QRectF &rect) -
2069{ -
2070 QGraphicsScenePrivate * const d = d_func(); -
2071 if (d->updateAll || (rect.isEmpty() && !rect.isNull()))
-
2072 return;
-
2073 -
2074 -
2075 -
2076 bool directUpdates = !(d->isSignalConnected(d->changedSignalIndex)) && !d->views.isEmpty();
-
2077 if (rect.isNull()) {
-
2078 d->updateAll = true; -
2079 d->updatedRects.clear(); -
2080 if (directUpdates) {
-
2081 -
2082 for (int i = 0; i < d->views.size(); ++i)
-
2083 d->views.at(i)->d_func()->fullUpdatePending = true;
-
2084 }
-
2085 } else {
-
2086 if (directUpdates) {
-
2087 -
2088 for (int i = 0; i < d->views.size(); ++i) {
-
2089 QGraphicsView *view = d->views.at(i); -
2090 if (view->isTransformed())
-
2091 view->d_func()->updateRectF(view->viewportTransform().mapRect(rect));
-
2092 else -
2093 view->d_func()->updateRectF(rect);
-
2094 } -
2095 } else {
-
2096 d->updatedRects << rect; -
2097 }
-
2098 } -
2099 -
2100 if (!d->calledEmitUpdated) {
-
2101 d->calledEmitUpdated = true; -
2102 QMetaObject::invokeMethod(this, "_q_emitUpdated", Qt::QueuedConnection); -
2103 }
-
2104}
-
2105void QGraphicsScene::invalidate(const QRectF &rect, SceneLayers layers) -
2106{ -
2107 for (QForeachContainer<__typeof__(views())> _container_(views()); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (QGraphicsView *view = *_container_.i;; __extension__ ({--_container_.brk; break;})) -
2108 view->invalidateScene(rect, layers);
-
2109 update(rect); -
2110}
-
2111QList <QGraphicsView *> QGraphicsScene::views() const -
2112{ -
2113 const QGraphicsScenePrivate * const d = d_func(); -
2114 return d->views;
-
2115} -
2116void QGraphicsScene::advance() -
2117{ -
2118 for (int i = 0; i < 2; ++i) {
-
2119 for (QForeachContainer<__typeof__(items())> _container_(items()); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (QGraphicsItem *item = *_container_.i;; __extension__ ({--_container_.brk; break;})) -
2120 item->advance(i);
-
2121 }
-
2122}
-
2123bool QGraphicsScene::event(QEvent *event) -
2124{ -
2125 QGraphicsScenePrivate * const d = d_func(); -
2126 -
2127 switch (event->type()) { -
2128 case QEvent::GraphicsSceneMousePress: -
2129 case QEvent::GraphicsSceneMouseMove: -
2130 case QEvent::GraphicsSceneMouseRelease: -
2131 case QEvent::GraphicsSceneMouseDoubleClick: -
2132 case QEvent::GraphicsSceneHoverEnter: -
2133 case QEvent::GraphicsSceneHoverLeave: -
2134 case QEvent::GraphicsSceneHoverMove: -
2135 case QEvent::TouchBegin: -
2136 case QEvent::TouchUpdate: -
2137 case QEvent::TouchEnd: -
2138 -
2139 -
2140 -
2141 -
2142 -
2143 -
2144 -
2145 d->cachedItemsUnderMouse.clear(); -
2146 default: -
2147 break;
-
2148 } -
2149 -
2150 switch (event->type()) { -
2151 case QEvent::GraphicsSceneDragEnter: -
2152 dragEnterEvent(static_cast<QGraphicsSceneDragDropEvent *>(event)); -
2153 break;
-
2154 case QEvent::GraphicsSceneDragMove: -
2155 dragMoveEvent(static_cast<QGraphicsSceneDragDropEvent *>(event)); -
2156 break;
-
2157 case QEvent::GraphicsSceneDragLeave: -
2158 dragLeaveEvent(static_cast<QGraphicsSceneDragDropEvent *>(event)); -
2159 break;
-
2160 case QEvent::GraphicsSceneDrop: -
2161 dropEvent(static_cast<QGraphicsSceneDragDropEvent *>(event)); -
2162 break;
-
2163 case QEvent::GraphicsSceneContextMenu: -
2164 contextMenuEvent(static_cast<QGraphicsSceneContextMenuEvent *>(event)); -
2165 break;
-
2166 case QEvent::KeyPress: -
2167 if (!d->focusItem) {
-
2168 QKeyEvent *k = static_cast<QKeyEvent *>(event); -
2169 if (k->key() == Qt::Key_Tab || k->key() == Qt::Key_Backtab) {
-
2170 if (!(k->modifiers() & (Qt::ControlModifier | Qt::AltModifier))) {
-
2171 bool res = false; -
2172 if (k->key() == Qt::Key_Backtab
-
2173 || (k->key() == Qt::Key_Tab && (k->modifiers() & Qt::ShiftModifier))) {
-
2174 res = focusNextPrevChild(false); -
2175 } else if (k->key() == Qt::Key_Tab) {
-
2176 res = focusNextPrevChild(true); -
2177 }
-
2178 if (!res)
-
2179 event->ignore();
-
2180 return true;
-
2181 } -
2182 }
-
2183 }
-
2184 keyPressEvent(static_cast<QKeyEvent *>(event)); -
2185 break;
-
2186 case QEvent::KeyRelease: -
2187 keyReleaseEvent(static_cast<QKeyEvent *>(event)); -
2188 break;
-
2189 case QEvent::ShortcutOverride: { -
2190 QGraphicsItem *parent = focusItem(); -
2191 while (parent) {
-
2192 d->sendEvent(parent, event); -
2193 if (event->isAccepted())
-
2194 return true;
-
2195 parent = parent->parentItem(); -
2196 }
-
2197 } -
2198 return false;
-
2199 case QEvent::GraphicsSceneMouseMove: -
2200 { -
2201 QGraphicsSceneMouseEvent *mouseEvent = static_cast<QGraphicsSceneMouseEvent *>(event); -
2202 d->lastSceneMousePos = mouseEvent->scenePos(); -
2203 mouseMoveEvent(mouseEvent); -
2204 break;
-
2205 } -
2206 case QEvent::GraphicsSceneMousePress: -
2207 mousePressEvent(static_cast<QGraphicsSceneMouseEvent *>(event)); -
2208 break;
-
2209 case QEvent::GraphicsSceneMouseRelease: -
2210 mouseReleaseEvent(static_cast<QGraphicsSceneMouseEvent *>(event)); -
2211 break;
-
2212 case QEvent::GraphicsSceneMouseDoubleClick: -
2213 mouseDoubleClickEvent(static_cast<QGraphicsSceneMouseEvent *>(event)); -
2214 break;
-
2215 case QEvent::GraphicsSceneWheel: -
2216 wheelEvent(static_cast<QGraphicsSceneWheelEvent *>(event)); -
2217 break;
-
2218 case QEvent::FocusIn: -
2219 focusInEvent(static_cast<QFocusEvent *>(event)); -
2220 break;
-
2221 case QEvent::FocusOut: -
2222 focusOutEvent(static_cast<QFocusEvent *>(event)); -
2223 break;
-
2224 case QEvent::GraphicsSceneHoverEnter: -
2225 case QEvent::GraphicsSceneHoverLeave: -
2226 case QEvent::GraphicsSceneHoverMove: -
2227 { -
2228 QGraphicsSceneHoverEvent *hoverEvent = static_cast<QGraphicsSceneHoverEvent *>(event); -
2229 d->lastSceneMousePos = hoverEvent->scenePos(); -
2230 d->dispatchHoverEvent(hoverEvent); -
2231 break;
-
2232 } -
2233 case QEvent::Leave: -
2234 -
2235 d->leaveScene(reinterpret_cast<QWidget *>(event->d)); -
2236 break;
-
2237 case QEvent::GraphicsSceneHelp: -
2238 helpEvent(static_cast<QGraphicsSceneHelpEvent *>(event)); -
2239 break;
-
2240 case QEvent::InputMethod: -
2241 inputMethodEvent(static_cast<QInputMethodEvent *>(event)); -
2242 break;
-
2243 case QEvent::WindowActivate: -
2244 if (!d->activationRefCount++) {
-
2245 if (d->lastActivePanel) {
-
2246 -
2247 d->setActivePanelHelper(d->lastActivePanel, true); -
2248 } else if (d->tabFocusFirst && d->tabFocusFirst->isPanel()) {
-
2249 -
2250 -
2251 d->setActivePanelHelper(d->tabFocusFirst, true); -
2252 } else {
-
2253 -
2254 QEvent event(QEvent::WindowActivate); -
2255 for (QForeachContainer<__typeof__(items())> _container_(items()); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (QGraphicsItem *item = *_container_.i;; __extension__ ({--_container_.brk; break;})) { -
2256 if (item->isVisible() && !item->isPanel() && !item->parentItem())
-
2257 sendEvent(item, &event);
-
2258 }
-
2259 }
-
2260 } -
2261 break;
-
2262 case QEvent::WindowDeactivate: -
2263 if (!--d->activationRefCount) {
-
2264 if (d->activePanel) {
-
2265 -
2266 -
2267 QGraphicsItem *lastActivePanel = d->activePanel; -
2268 d->setActivePanelHelper(0, true); -
2269 d->lastActivePanel = lastActivePanel; -
2270 } else {
-
2271 -
2272 QEvent event(QEvent::WindowDeactivate); -
2273 for (QForeachContainer<__typeof__(items())> _container_(items()); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (QGraphicsItem *item = *_container_.i;; __extension__ ({--_container_.brk; break;})) { -
2274 if (item->isVisible() && !item->isPanel() && !item->parentItem())
-
2275 sendEvent(item, &event);
-
2276 }
-
2277 }
-
2278 } -
2279 break;
-
2280 case QEvent::ApplicationFontChange: { -
2281 -
2282 d->resolveFont(); -
2283 break;
-
2284 } -
2285 case QEvent::FontChange: -
2286 -
2287 update(); -
2288 break;
-
2289 case QEvent::ApplicationPaletteChange: { -
2290 -
2291 d->resolvePalette(); -
2292 break;
-
2293 } -
2294 case QEvent::PaletteChange: -
2295 -
2296 update(); -
2297 break;
-
2298 case QEvent::StyleChange: -
2299 -
2300 -
2301 update(); -
2302 break;
-
2303 case QEvent::StyleAnimationUpdate: -
2304 -
2305 -
2306 update(); -
2307 break;
-
2308 case QEvent::TouchBegin: -
2309 case QEvent::TouchUpdate: -
2310 case QEvent::TouchEnd: -
2311 d->touchEventHandler(static_cast<QTouchEvent *>(event)); -
2312 break;
-
2313 -
2314 case QEvent::Gesture: -
2315 case QEvent::GestureOverride: -
2316 d->gestureEventHandler(static_cast<QGestureEvent *>(event)); -
2317 break;
-
2318 -
2319 default: -
2320 return QObject::event(event);
-
2321 } -
2322 return true;
-
2323} -
2324 -
2325 -
2326 -
2327 -
2328 -
2329 -
2330 -
2331bool QGraphicsScene::eventFilter(QObject *watched, QEvent *event) -
2332{ -
2333 if (watched != (static_cast<QApplication *>(QCoreApplication::instance())))
-
2334 return false;
-
2335 -
2336 switch (event->type()) { -
2337 case QEvent::ApplicationPaletteChange: -
2338 QApplication::postEvent(this, new QEvent(QEvent::ApplicationPaletteChange)); -
2339 break;
-
2340 case QEvent::ApplicationFontChange: -
2341 QApplication::postEvent(this, new QEvent(QEvent::ApplicationFontChange)); -
2342 break;
-
2343 default: -
2344 break;
-
2345 } -
2346 return false;
-
2347} -
2348void QGraphicsScene::contextMenuEvent(QGraphicsSceneContextMenuEvent *contextMenuEvent) -
2349{ -
2350 QGraphicsScenePrivate * const d = d_func(); -
2351 -
2352 contextMenuEvent->ignore(); -
2353 -
2354 -
2355 -
2356 for (QForeachContainer<__typeof__(d->itemsAtPosition(contextMenuEvent->screenPos(), contextMenuEvent->scenePos(), contextMenuEvent->widget()))> _container_(d->itemsAtPosition(contextMenuEvent->screenPos(), contextMenuEvent->scenePos(), contextMenuEvent->widget())); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (QGraphicsItem *item = *_container_.i;; __extension__ ({--_container_.brk; break;})) { -
2357 -
2358 -
2359 contextMenuEvent->setPos(item->d_ptr->genericMapFromScene(contextMenuEvent->scenePos(), -
2360 contextMenuEvent->widget())); -
2361 contextMenuEvent->accept(); -
2362 if (!d->sendEvent(item, contextMenuEvent))
-
2363 break;
-
2364 -
2365 if (contextMenuEvent->isAccepted())
-
2366 break;
-
2367 }
-
2368}
-
2369void QGraphicsScene::dragEnterEvent(QGraphicsSceneDragDropEvent *event) -
2370{ -
2371 QGraphicsScenePrivate * const d = d_func(); -
2372 d->dragDropItem = 0; -
2373 d->lastDropAction = Qt::IgnoreAction; -
2374 event->accept(); -
2375}
-
2376void QGraphicsScene::dragMoveEvent(QGraphicsSceneDragDropEvent *event) -
2377{ -
2378 QGraphicsScenePrivate * const d = d_func(); -
2379 event->ignore(); -
2380 -
2381 if (!d->mouseGrabberItems.isEmpty()) {
-
2382 -
2383 d->clearMouseGrabber(); -
2384 d->mouseGrabberButtonDownPos.clear(); -
2385 d->mouseGrabberButtonDownScenePos.clear(); -
2386 d->mouseGrabberButtonDownScreenPos.clear(); -
2387 }
-
2388 -
2389 bool eventDelivered = false; -
2390 -
2391 -
2392 -
2393 for (QForeachContainer<__typeof__(d->itemsAtPosition(event->screenPos(), event->scenePos(), event->widget()))> _container_(d->itemsAtPosition(event->screenPos(), event->scenePos(), event->widget())); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (QGraphicsItem *item = *_container_.i;; __extension__ ({--_container_.brk; break;})) { -
2394 -
2395 -
2396 if (!item->isEnabled() || !item->acceptDrops())
-
2397 continue;
-
2398 -
2399 if (item != d->dragDropItem) {
-
2400 -
2401 -
2402 QGraphicsSceneDragDropEvent dragEnter(QEvent::GraphicsSceneDragEnter); -
2403 d->cloneDragDropEvent(&dragEnter, event); -
2404 dragEnter.setDropAction(event->proposedAction()); -
2405 d->sendDragDropEvent(item, &dragEnter); -
2406 event->setAccepted(dragEnter.isAccepted()); -
2407 event->setDropAction(dragEnter.dropAction()); -
2408 if (!event->isAccepted()) {
-
2409 -
2410 continue;
-
2411 } -
2412 -
2413 d->lastDropAction = event->dropAction(); -
2414 -
2415 if (d->dragDropItem) {
-
2416 -
2417 -
2418 -
2419 -
2420 QGraphicsSceneDragDropEvent dragLeave(QEvent::GraphicsSceneDragLeave); -
2421 d->cloneDragDropEvent(&dragLeave, event); -
2422 d->sendDragDropEvent(d->dragDropItem, &dragLeave); -
2423 }
-
2424 -
2425 -
2426 d->dragDropItem = item; -
2427 }
-
2428 -
2429 -
2430 event->setDropAction(d->lastDropAction); -
2431 event->accept(); -
2432 d->sendDragDropEvent(item, event); -
2433 if (event->isAccepted())
-
2434 d->lastDropAction = event->dropAction();
-
2435 eventDelivered = true; -
2436 break;
-
2437 } -
2438 -
2439 if (!eventDelivered) {
-
2440 if (d->dragDropItem) {
-
2441 -
2442 QGraphicsSceneDragDropEvent dragLeave(QEvent::GraphicsSceneDragLeave); -
2443 d->cloneDragDropEvent(&dragLeave, event); -
2444 d->sendDragDropEvent(d->dragDropItem, &dragLeave); -
2445 d->dragDropItem = 0; -
2446 }
-
2447 -
2448 event->setDropAction(Qt::IgnoreAction); -
2449 }
-
2450}
-
2451void QGraphicsScene::dragLeaveEvent(QGraphicsSceneDragDropEvent *event) -
2452{ -
2453 QGraphicsScenePrivate * const d = d_func(); -
2454 if (d->dragDropItem) {
-
2455 -
2456 d->sendDragDropEvent(d->dragDropItem, event); -
2457 d->dragDropItem = 0; -
2458 }
-
2459}
-
2460void QGraphicsScene::dropEvent(QGraphicsSceneDragDropEvent *event) -
2461{ -
2462 (void)event;; -
2463 QGraphicsScenePrivate * const d = d_func(); -
2464 if (d->dragDropItem) {
-
2465 -
2466 d->sendDragDropEvent(d->dragDropItem, event); -
2467 d->dragDropItem = 0; -
2468 }
-
2469}
-
2470void QGraphicsScene::focusInEvent(QFocusEvent *focusEvent) -
2471{ -
2472 QGraphicsScenePrivate * const d = d_func(); -
2473 -
2474 d->hasFocus = true; -
2475 switch (focusEvent->reason()) { -
2476 case Qt::TabFocusReason: -
2477 if (!focusNextPrevChild(true))
-
2478 focusEvent->ignore();
-
2479 break;
-
2480 case Qt::BacktabFocusReason: -
2481 if (!focusNextPrevChild(false))
-
2482 focusEvent->ignore();
-
2483 break;
-
2484 default: -
2485 if (d->passiveFocusItem) {
-
2486 -
2487 setFocusItem(d->passiveFocusItem, focusEvent->reason()); -
2488 }
-
2489 break;
-
2490 } -
2491}
-
2492void QGraphicsScene::focusOutEvent(QFocusEvent *focusEvent) -
2493{ -
2494 QGraphicsScenePrivate * const d = d_func(); -
2495 d->hasFocus = false; -
2496 d->passiveFocusItem = d->focusItem; -
2497 setFocusItem(0, focusEvent->reason()); -
2498 -
2499 -
2500 if (!d->popupWidgets.isEmpty())
-
2501 d->removePopup(d->popupWidgets.first());
-
2502}
-
2503void QGraphicsScene::helpEvent(QGraphicsSceneHelpEvent *helpEvent) -
2504{ -
2505 -
2506 -
2507 -
2508 -
2509 QGraphicsScenePrivate * const d = d_func(); -
2510 QList<QGraphicsItem *> itemsAtPos = d->itemsAtPosition(helpEvent->screenPos(), -
2511 helpEvent->scenePos(), -
2512 helpEvent->widget()); -
2513 QGraphicsItem *toolTipItem = 0; -
2514 for (int i = 0; i < itemsAtPos.size(); ++i) {
-
2515 QGraphicsItem *tmp = itemsAtPos.at(i); -
2516 if (tmp->d_func()->isProxyWidget()) {
-
2517 -
2518 sendEvent(tmp, helpEvent); -
2519 if (helpEvent->isAccepted())
-
2520 return;
-
2521 }
-
2522 if (!tmp->toolTip().isEmpty()) {
-
2523 toolTipItem = tmp; -
2524 break;
-
2525 } -
2526 }
-
2527 -
2528 -
2529 QString text; -
2530 QPoint point; -
2531 if (toolTipItem && !toolTipItem->toolTip().isEmpty()) {
-
2532 text = toolTipItem->toolTip(); -
2533 point = helpEvent->screenPos(); -
2534 }
-
2535 QToolTip::showText(point, text, helpEvent->widget()); -
2536 helpEvent->setAccepted(!text.isEmpty()); -
2537 -
2538}
-
2539 -
2540bool QGraphicsScenePrivate::itemAcceptsHoverEvents_helper(const QGraphicsItem *item) const -
2541{ -
2542 return (item->d_ptr->acceptsHover -
2543 || (item->d_ptr->isWidget -
2544 && static_cast<const QGraphicsWidget *>(item)->d_func()->hasDecoration())) -
2545 && !item->isBlockedByModalPanel();
-
2546} -
2547bool QGraphicsScenePrivate::dispatchHoverEvent(QGraphicsSceneHoverEvent *hoverEvent) -
2548{ -
2549 if (allItemsIgnoreHoverEvents)
-
2550 return false;
-
2551 -
2552 -
2553 -
2554 if (cachedItemsUnderMouse.isEmpty()) {
-
2555 cachedItemsUnderMouse = itemsAtPosition(hoverEvent->screenPos(), -
2556 hoverEvent->scenePos(), -
2557 hoverEvent->widget()); -
2558 }
-
2559 -
2560 QGraphicsItem *item = 0; -
2561 for (int i = 0; i < cachedItemsUnderMouse.size(); ++i) {
-
2562 QGraphicsItem *tmp = cachedItemsUnderMouse.at(i); -
2563 if (itemAcceptsHoverEvents_helper(tmp)) {
-
2564 item = tmp; -
2565 break;
-
2566 } -
2567 }
-
2568 -
2569 -
2570 -
2571 QGraphicsItem *commonAncestorItem = (item && !hoverItems.isEmpty()) ? item->commonAncestorItem(hoverItems.last()) : 0;
-
2572 while (commonAncestorItem && !itemAcceptsHoverEvents_helper(commonAncestorItem))
-
2573 commonAncestorItem = commonAncestorItem->parentItem();
-
2574 if (commonAncestorItem && commonAncestorItem->panel() != item->panel()) {
-
2575 -
2576 -
2577 commonAncestorItem = 0; -
2578 }
-
2579 -
2580 -
2581 int index = commonAncestorItem ? hoverItems.indexOf(commonAncestorItem) : -1;
-
2582 -
2583 -
2584 for (int i = hoverItems.size() - 1; i > index; --i) {
-
2585 QGraphicsItem *lastItem = hoverItems.takeLast(); -
2586 if (itemAcceptsHoverEvents_helper(lastItem))
-
2587 sendHoverEvent(QEvent::GraphicsSceneHoverLeave, lastItem, hoverEvent);
-
2588 }
-
2589 -
2590 -
2591 -
2592 QList<QGraphicsItem *> parents; -
2593 QGraphicsItem *parent = item; -
2594 while (parent && parent != commonAncestorItem) {
-
2595 parents.prepend(parent); -
2596 if (parent->isPanel()) {
-
2597 -
2598 break;
-
2599 } -
2600 parent = parent->parentItem(); -
2601 }
-
2602 for (int i = 0; i < parents.size(); ++i) {
-
2603 parent = parents.at(i); -
2604 hoverItems << parent; -
2605 if (itemAcceptsHoverEvents_helper(parent))
-
2606 sendHoverEvent(QEvent::GraphicsSceneHoverEnter, parent, hoverEvent);
-
2607 }
-
2608 -
2609 -
2610 if (item
-
2611 && !hoverItems.isEmpty()
-
2612 && item == hoverItems.last()) {
-
2613 sendHoverEvent(QEvent::GraphicsSceneHoverMove, item, hoverEvent); -
2614 return true;
-
2615 } -
2616 return false;
-
2617} -
2618 -
2619 -
2620 -
2621 -
2622 -
2623 -
2624 -
2625void QGraphicsScenePrivate::leaveScene(QWidget *viewport) -
2626{ -
2627 -
2628 QToolTip::hideText(); -
2629 -
2630 QGraphicsView *view = qobject_cast<QGraphicsView *>(viewport->parent()); -
2631 -
2632 QGraphicsSceneHoverEvent hoverEvent; -
2633 hoverEvent.setWidget(viewport); -
2634 -
2635 if (view) {
-
2636 QPoint cursorPos = QCursor::pos(); -
2637 hoverEvent.setScenePos(view->mapToScene(viewport->mapFromGlobal(cursorPos))); -
2638 hoverEvent.setLastScenePos(hoverEvent.scenePos()); -
2639 hoverEvent.setScreenPos(cursorPos); -
2640 hoverEvent.setLastScreenPos(hoverEvent.screenPos()); -
2641 }
-
2642 -
2643 while (!hoverItems.isEmpty()) {
-
2644 QGraphicsItem *lastItem = hoverItems.takeLast(); -
2645 if (itemAcceptsHoverEvents_helper(lastItem))
-
2646 sendHoverEvent(QEvent::GraphicsSceneHoverLeave, lastItem, &hoverEvent);
-
2647 }
-
2648}
-
2649void QGraphicsScene::keyPressEvent(QKeyEvent *keyEvent) -
2650{ -
2651 -
2652 -
2653 QGraphicsScenePrivate * const d = d_func(); -
2654 QGraphicsItem *item = !d->keyboardGrabberItems.isEmpty() ? d->keyboardGrabberItems.last() : 0;
-
2655 if (!item)
-
2656 item = focusItem();
-
2657 if (item) {
-
2658 QGraphicsItem *p = item; -
2659 do { -
2660 -
2661 keyEvent->accept(); -
2662 -
2663 -
2664 if (p->isBlockedByModalPanel())
-
2665 break;
-
2666 if (!d->sendEvent(p, keyEvent))
-
2667 break;
-
2668 } while (!keyEvent->isAccepted() && !p->isPanel() && (p = p->parentItem()));
-
2669 } else {
-
2670 keyEvent->ignore(); -
2671 }
-
2672} -
2673void QGraphicsScene::keyReleaseEvent(QKeyEvent *keyEvent) -
2674{ -
2675 -
2676 -
2677 QGraphicsScenePrivate * const d = d_func(); -
2678 QGraphicsItem *item = !d->keyboardGrabberItems.isEmpty() ? d->keyboardGrabberItems.last() : 0;
-
2679 if (!item)
-
2680 item = focusItem();
-
2681 if (item) {
-
2682 QGraphicsItem *p = item; -
2683 do { -
2684 -
2685 keyEvent->accept(); -
2686 -
2687 -
2688 if (p->isBlockedByModalPanel())
-
2689 break;
-
2690 if (!d->sendEvent(p, keyEvent))
-
2691 break;
-
2692 } while (!keyEvent->isAccepted() && !p->isPanel() && (p = p->parentItem()));
-
2693 } else {
-
2694 keyEvent->ignore(); -
2695 }
-
2696} -
2697void QGraphicsScene::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent) -
2698{ -
2699 QGraphicsScenePrivate * const d = d_func(); -
2700 if (d->mouseGrabberItems.isEmpty()) {
-
2701 -
2702 QGraphicsSceneHoverEvent hover; -
2703 _q_hoverFromMouseEvent(&hover, mouseEvent); -
2704 d->dispatchHoverEvent(&hover); -
2705 }
-
2706 -
2707 d->mousePressEventHandler(mouseEvent); -
2708}
-
2709void QGraphicsScene::mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent) -
2710{ -
2711 QGraphicsScenePrivate * const d = d_func(); -
2712 if (d->mouseGrabberItems.isEmpty()) {
-
2713 if (mouseEvent->buttons())
-
2714 return;
-
2715 QGraphicsSceneHoverEvent hover; -
2716 _q_hoverFromMouseEvent(&hover, mouseEvent); -
2717 mouseEvent->setAccepted(d->dispatchHoverEvent(&hover)); -
2718 return;
-
2719 } -
2720 -
2721 -
2722 d->sendMouseEvent(mouseEvent); -
2723 mouseEvent->accept(); -
2724}
-
2725void QGraphicsScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent) -
2726{ -
2727 QGraphicsScenePrivate * const d = d_func(); -
2728 if (d->mouseGrabberItems.isEmpty()) {
-
2729 mouseEvent->ignore(); -
2730 return;
-
2731 } -
2732 -
2733 -
2734 d->sendMouseEvent(mouseEvent); -
2735 mouseEvent->accept(); -
2736 -
2737 -
2738 if (!mouseEvent->buttons()) {
-
2739 if (!d->mouseGrabberItems.isEmpty()) {
-
2740 d->lastMouseGrabberItem = d->mouseGrabberItems.last(); -
2741 if (d->lastMouseGrabberItemHasImplicitMouseGrab)
-
2742 d->mouseGrabberItems.last()->ungrabMouse();
-
2743 } else {
-
2744 d->lastMouseGrabberItem = 0; -
2745 }
-
2746 -
2747 -
2748 QGraphicsSceneHoverEvent hoverEvent; -
2749 _q_hoverFromMouseEvent(&hoverEvent, mouseEvent); -
2750 d->dispatchHoverEvent(&hoverEvent); -
2751 }
-
2752}
-
2753void QGraphicsScene::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *mouseEvent) -
2754{ -
2755 QGraphicsScenePrivate * const d = d_func(); -
2756 d->mousePressEventHandler(mouseEvent); -
2757}
-
2758void QGraphicsScene::wheelEvent(QGraphicsSceneWheelEvent *wheelEvent) -
2759{ -
2760 QGraphicsScenePrivate * const d = d_func(); -
2761 QList<QGraphicsItem *> wheelCandidates = d->itemsAtPosition(wheelEvent->screenPos(), -
2762 wheelEvent->scenePos(), -
2763 wheelEvent->widget()); -
2764 QList<QGraphicsWidget *>::const_iterator iter = d->popupWidgets.constEnd(); -
2765 while (--iter >= d->popupWidgets.constBegin() && !wheelCandidates.isEmpty()) {
-
2766 if (wheelCandidates.first() == *iter || (*iter)->isAncestorOf(wheelCandidates.first()))
-
2767 break;
-
2768 d->removePopup(*iter); -
2769 }
-
2770 -
2771 -
2772 bool hasSetFocus = false; -
2773 for (QForeachContainer<__typeof__(wheelCandidates)> _container_(wheelCandidates); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (QGraphicsItem *item = *_container_.i;; __extension__ ({--_container_.brk; break;})) { -
2774 if (!hasSetFocus && item->isEnabled()
-
2775 && ((item->flags() & QGraphicsItem::ItemIsFocusable) && item->d_ptr->mouseSetsFocus)) {
-
2776 if (item->isWidget() && static_cast<QGraphicsWidget *>(item)->focusPolicy() == Qt::WheelFocus) {
-
2777 hasSetFocus = true; -
2778 if (item != focusItem())
-
2779 setFocusItem(item, Qt::MouseFocusReason);
-
2780 }
-
2781 }
-
2782 -
2783 wheelEvent->setPos(item->d_ptr->genericMapFromScene(wheelEvent->scenePos(), -
2784 wheelEvent->widget())); -
2785 wheelEvent->accept(); -
2786 bool isPanel = item->isPanel(); -
2787 d->sendEvent(item, wheelEvent); -
2788 if (isPanel || wheelEvent->isAccepted())
-
2789 break;
-
2790 }
-
2791}
-
2792void QGraphicsScene::inputMethodEvent(QInputMethodEvent *event) -
2793{ -
2794 QGraphicsScenePrivate * const d = d_func(); -
2795 if (d->focusItem && (d->focusItem->flags() & QGraphicsItem::ItemAcceptsInputMethod))
-
2796 d->sendEvent(d->focusItem, event);
-
2797}
-
2798void QGraphicsScene::drawBackground(QPainter *painter, const QRectF &rect) -
2799{ -
2800 QGraphicsScenePrivate * const d = d_func(); -
2801 -
2802 if (d->backgroundBrush.style() != Qt::NoBrush) {
-
2803 if (d->painterStateProtection)
-
2804 painter->save();
-
2805 painter->setBrushOrigin(0, 0); -
2806 painter->fillRect(rect, backgroundBrush()); -
2807 if (d->painterStateProtection)
-
2808 painter->restore();
-
2809 }
-
2810}
-
2811void QGraphicsScene::drawForeground(QPainter *painter, const QRectF &rect) -
2812{ -
2813 QGraphicsScenePrivate * const d = d_func(); -
2814 -
2815 if (d->foregroundBrush.style() != Qt::NoBrush) {
-
2816 if (d->painterStateProtection)
-
2817 painter->save();
-
2818 painter->setBrushOrigin(0, 0); -
2819 painter->fillRect(rect, foregroundBrush()); -
2820 if (d->painterStateProtection)
-
2821 painter->restore();
-
2822 }
-
2823}
-
2824 -
2825static void _q_paintItem(QGraphicsItem *item, QPainter *painter, -
2826 const QStyleOptionGraphicsItem *option, QWidget *widget, -
2827 bool useWindowOpacity, bool painterStateProtection) -
2828{ -
2829 if (!item->isWidget()) {
-
2830 item->paint(painter, option, widget); -
2831 return;
-
2832 } -
2833 QGraphicsWidget *widgetItem = static_cast<QGraphicsWidget *>(item); -
2834 QGraphicsProxyWidget *proxy = qobject_cast<QGraphicsProxyWidget *>(widgetItem); -
2835 const qreal windowOpacity = (proxy && proxy->widget() && useWindowOpacity)
-
2836 ? proxy->widget()->windowOpacity() : 1.0; -
2837 const qreal oldPainterOpacity = painter->opacity(); -
2838 -
2839 if (qFuzzyIsNull(windowOpacity))
-
2840 return;
-
2841 -
2842 if (windowOpacity < 1.0)
-
2843 painter->setOpacity(oldPainterOpacity * windowOpacity);
-
2844 -
2845 -
2846 Qt::LayoutDirection oldLayoutDirection = painter->layoutDirection(); -
2847 painter->setLayoutDirection(widgetItem->layoutDirection()); -
2848 -
2849 if (widgetItem->isWindow() && widgetItem->windowType() != Qt::Popup && widgetItem->windowType() != Qt::ToolTip
-
2850 && !(widgetItem->windowFlags() & Qt::FramelessWindowHint)) {
-
2851 if (painterStateProtection)
-
2852 painter->save();
-
2853 widgetItem->paintWindowFrame(painter, option, widget); -
2854 if (painterStateProtection)
-
2855 painter->restore();
-
2856 } else if (widgetItem->autoFillBackground()) {
-
2857 painter->fillRect(option->exposedRect, widgetItem->palette().window()); -
2858 }
-
2859 -
2860 widgetItem->paint(painter, option, widget); -
2861 -
2862 -
2863 painter->setLayoutDirection(oldLayoutDirection); -
2864 -
2865 if (windowOpacity < 1.0)
-
2866 painter->setOpacity(oldPainterOpacity);
-
2867}
-
2868 -
2869static void _q_paintIntoCache(QPixmap *pix, QGraphicsItem *item, const QRegion &pixmapExposed, -
2870 const QTransform &itemToPixmap, QPainter::RenderHints renderHints, -
2871 const QStyleOptionGraphicsItem *option, bool painterStateProtection) -
2872{ -
2873 QPixmap subPix; -
2874 QPainter pixmapPainter; -
2875 QRect br = pixmapExposed.boundingRect(); -
2876 -
2877 -
2878 if (pixmapExposed.isEmpty() || (pixmapExposed.rectCount() == 1 && br.contains(pix->rect()))) {
-
2879 pix->fill(Qt::transparent); -
2880 pixmapPainter.begin(pix); -
2881 } else {
-
2882 subPix = QPixmap(br.size()); -
2883 subPix.fill(Qt::transparent); -
2884 pixmapPainter.begin(&subPix); -
2885 pixmapPainter.translate(-br.topLeft()); -
2886 if (!pixmapExposed.isEmpty()) {
-
2887 -
2888 -
2889 pixmapPainter.setClipRegion(pixmapExposed); -
2890 }
-
2891 }
-
2892 -
2893 pixmapPainter.setRenderHints(pixmapPainter.renderHints(), false); -
2894 pixmapPainter.setRenderHints(renderHints, true); -
2895 pixmapPainter.setWorldTransform(itemToPixmap, true); -
2896 -
2897 -
2898 _q_paintItem(item, &pixmapPainter, option, 0, false, painterStateProtection); -
2899 pixmapPainter.end(); -
2900 -
2901 if (!subPix.isNull()) {
-
2902 -
2903 pixmapPainter.begin(pix); -
2904 pixmapPainter.setCompositionMode(QPainter::CompositionMode_Source); -
2905 pixmapPainter.setClipRegion(pixmapExposed); -
2906 pixmapPainter.drawPixmap(br.topLeft(), subPix); -
2907 pixmapPainter.end(); -
2908 }
-
2909}
-
2910 -
2911 -
2912 -
2913static inline bool transformIsSimple(const QTransform& transform) -
2914{ -
2915 QTransform::TransformationType type = transform.type(); -
2916 if (type <= QTransform::TxScale) {
-
2917 return true;
-
2918 } else if (type == QTransform::TxRotate) {
-
2919 -
2920 qreal m11 = transform.m11(); -
2921 qreal m12 = transform.m12(); -
2922 qreal m21 = transform.m21(); -
2923 qreal m22 = transform.m22(); -
2924 if (m11 == 0.0f && m22 == 0.0f) {
-
2925 if (m12 == 1.0f && m21 == -1.0f)
-
2926 return true;
-
2927 else if (m12 == -1.0f && m21 == 1.0f)
-
2928 return true;
-
2929 else if (m12 == -1.0f && m21 == -1.0f)
-
2930 return true;
-
2931 else if (m12 == 1.0f && m21 == 1.0f)
-
2932 return true;
-
2933 } -
2934 }
-
2935 return false;
-
2936} -
2937 -
2938 -
2939 -
2940 -
2941 -
2942 -
2943void QGraphicsScenePrivate::drawItemHelper(QGraphicsItem *item, QPainter *painter, -
2944 const QStyleOptionGraphicsItem *option, QWidget *widget, -
2945 bool painterStateProtection) -
2946{ -
2947 QGraphicsItemPrivate *itemd = item->d_ptr.data(); -
2948 QGraphicsItem::CacheMode cacheMode = QGraphicsItem::CacheMode(itemd->cacheMode); -
2949 -
2950 -
2951 if (cacheMode == QGraphicsItem::NoCache
-
2952 -
2953 -
2954 -
2955 ) { -
2956 _q_paintItem(static_cast<QGraphicsWidget *>(item), painter, option, widget, true, painterStateProtection); -
2957 return;
-
2958 } -
2959 -
2960 const qreal oldPainterOpacity = painter->opacity(); -
2961 qreal newPainterOpacity = oldPainterOpacity; -
2962 QGraphicsProxyWidget *proxy = item->isWidget() ? qobject_cast<QGraphicsProxyWidget *>(static_cast<QGraphicsWidget *>(item)) : 0;
-
2963 if (proxy && proxy->widget()) {
-
2964 const qreal windowOpacity = proxy->widget()->windowOpacity(); -
2965 if (windowOpacity < 1.0)
-
2966 newPainterOpacity *= windowOpacity;
-
2967 }
-
2968 -
2969 -
2970 QRectF brect = item->boundingRect(); -
2971 QRectF adjustedBrect(brect); -
2972 _q_adjustRect(&adjustedBrect); -
2973 if (adjustedBrect.isEmpty())
-
2974 return;
-
2975 -
2976 -
2977 QPixmapCache::Key pixmapKey; -
2978 QPixmap pix; -
2979 bool pixmapFound; -
2980 QGraphicsItemCache *itemCache = itemd->extraItemCache(); -
2981 if (cacheMode == QGraphicsItem::ItemCoordinateCache) {
-
2982 pixmapKey = itemCache->key; -
2983 } else {
-
2984 pixmapKey = itemCache->deviceData.value(widget).key; -
2985 }
-
2986 -
2987 -
2988 pixmapFound = QPixmapCache::find(pixmapKey, &pix); -
2989 -
2990 -
2991 if (cacheMode == QGraphicsItem::ItemCoordinateCache) {
-
2992 QSize pixmapSize; -
2993 bool fixedCacheSize = false; -
2994 QRect br = brect.toAlignedRect(); -
2995 if ((fixedCacheSize = itemCache->fixedSize.isValid())) {
-
2996 pixmapSize = itemCache->fixedSize; -
2997 } else {
-
2998 pixmapSize = br.size(); -
2999 }
-
3000 -
3001 -
3002 int adjust = itemCache->fixedSize.isValid() ? 0 : 2;
-
3003 QSize adjustSize(adjust*2, adjust*2); -
3004 br.adjust(-adjust, -adjust, adjust, adjust); -
3005 if (pix.isNull() || (!fixedCacheSize && (pixmapSize + adjustSize) != pix.size())) {
-
3006 pix = QPixmap(pixmapSize + adjustSize); -
3007 itemCache->boundingRect = br; -
3008 itemCache->exposed.clear(); -
3009 itemCache->allExposed = true; -
3010 } else if (itemCache->boundingRect != br) {
-
3011 itemCache->boundingRect = br; -
3012 itemCache->exposed.clear(); -
3013 itemCache->allExposed = true; -
3014 }
-
3015 -
3016 -
3017 if (itemCache->allExposed || !itemCache->exposed.isEmpty()) {
-
3018 -
3019 -
3020 -
3021 if (pixmapFound)
-
3022 QPixmapCache::remove(pixmapKey);
-
3023 -
3024 -
3025 QTransform itemToPixmap; -
3026 if (fixedCacheSize) {
-
3027 const QPointF scale(pixmapSize.width() / brect.width(), pixmapSize.height() / brect.height()); -
3028 itemToPixmap.scale(scale.x(), scale.y()); -
3029 }
-
3030 itemToPixmap.translate(-br.x(), -br.y()); -
3031 -
3032 -
3033 -
3034 styleOptionTmp = *option; -
3035 QRegion pixmapExposed; -
3036 QRectF exposedRect; -
3037 if (!itemCache->allExposed) {
-
3038 for (int i = 0; i < itemCache->exposed.size(); ++i) {
-
3039 QRectF r = itemCache->exposed.at(i); -
3040 exposedRect |= r; -
3041 pixmapExposed += itemToPixmap.mapRect(r).toAlignedRect(); -
3042 }
-
3043 } else {
-
3044 exposedRect = brect; -
3045 }
-
3046 styleOptionTmp.exposedRect = exposedRect; -
3047 -
3048 -
3049 _q_paintIntoCache(&pix, item, pixmapExposed, itemToPixmap, painter->renderHints(), -
3050 &styleOptionTmp, painterStateProtection); -
3051 -
3052 -
3053 itemCache->key = QPixmapCache::insert(pix); -
3054 -
3055 -
3056 itemCache->allExposed = false; -
3057 itemCache->exposed.clear(); -
3058 }
-
3059 -
3060 -
3061 -
3062 -
3063 if (newPainterOpacity != oldPainterOpacity) {
-
3064 painter->setOpacity(newPainterOpacity); -
3065 painter->drawPixmap(br.topLeft(), pix); -
3066 painter->setOpacity(oldPainterOpacity); -
3067 } else {
-
3068 painter->drawPixmap(br.topLeft(), pix); -
3069 }
-
3070 return;
-
3071 } -
3072 -
3073 -
3074 if (cacheMode == QGraphicsItem::DeviceCoordinateCache) {
-
3075 -
3076 QRectF deviceBounds = painter->worldTransform().mapRect(brect); -
3077 QRect deviceRect = deviceBounds.toRect().adjusted(-1, -1, 1, 1); -
3078 if (deviceRect.isEmpty())
-
3079 return;
-
3080 QRect viewRect = widget ? widget->rect() : QRect();
-
3081 if (widget && !viewRect.intersects(deviceRect))
-
3082 return;
-
3083 -
3084 -
3085 -
3086 QSize maximumCacheSize = -
3087 itemd->extra(QGraphicsItemPrivate::ExtraMaxDeviceCoordCacheSize).toSize(); -
3088 if (!maximumCacheSize.isEmpty()
-
3089 && (deviceRect.width() > maximumCacheSize.width()
-
3090 || deviceRect.height() > maximumCacheSize.height())) {
-
3091 _q_paintItem(static_cast<QGraphicsWidget *>(item), painter, option, widget, -
3092 oldPainterOpacity != newPainterOpacity, painterStateProtection); -
3093 return;
-
3094 } -
3095 -
3096 -
3097 -
3098 -
3099 bool pixModified = false; -
3100 QGraphicsItemCache::DeviceData *deviceData = &itemCache->deviceData[widget]; -
3101 bool invertable = true; -
3102 QTransform diff = deviceData->lastTransform.inverted(&invertable); -
3103 if (invertable)
-
3104 diff *= painter->worldTransform();
-
3105 deviceData->lastTransform = painter->worldTransform(); -
3106 bool allowPartialCacheExposure = false; -
3107 bool simpleTransform = invertable && diff.type() <= QTransform::TxTranslate
-
3108 && transformIsSimple(painter->worldTransform());
-
3109 if (!simpleTransform) {
-
3110 pixModified = true; -
3111 itemCache->allExposed = true; -
3112 itemCache->exposed.clear(); -
3113 deviceData->cacheIndent = QPoint(); -
3114 pix = QPixmap(); -
3115 } else if (!viewRect.isNull()) {
-
3116 allowPartialCacheExposure = deviceData->cacheIndent != QPoint(); -
3117 }
-
3118 -
3119 -
3120 -
3121 if (!allowPartialCacheExposure && !viewRect.isNull() && !viewRect.contains(deviceRect)) {
-
3122 allowPartialCacheExposure = (viewRect.width() * 1.2 < deviceRect.width())
-
3123 || (viewRect.height() * 1.2 < deviceRect.height());
-
3124 }
-
3125 -
3126 QRegion scrollExposure; -
3127 if (allowPartialCacheExposure) {
-
3128 -
3129 -
3130 -
3131 -
3132 int dx = deviceRect.left() < viewRect.left() ? viewRect.left() - deviceRect.left() : 0;
-
3133 int dy = deviceRect.top() < viewRect.top() ? viewRect.top() - deviceRect.top() : 0;
-
3134 QPoint newCacheIndent(dx, dy); -
3135 deviceRect &= viewRect; -
3136 -
3137 if (pix.isNull()) {
-
3138 deviceData->cacheIndent = QPoint(); -
3139 itemCache->allExposed = true; -
3140 itemCache->exposed.clear(); -
3141 pixModified = true; -
3142 }
-
3143 -
3144 -
3145 -
3146 if (newCacheIndent != deviceData->cacheIndent || deviceRect.size() != pix.size()) {
-
3147 QPoint diff = newCacheIndent - deviceData->cacheIndent; -
3148 QPixmap newPix(deviceRect.size()); -
3149 -
3150 -
3151 newPix.fill(Qt::transparent); -
3152 if (!pix.isNull()) {
-
3153 QPainter newPixPainter(&newPix); -
3154 newPixPainter.drawPixmap(-diff, pix); -
3155 newPixPainter.end(); -
3156 }
-
3157 QRegion exposed; -
3158 exposed += newPix.rect(); -
3159 if (!pix.isNull())
-
3160 exposed -= QRect(-diff, pix.size());
-
3161 scrollExposure = exposed; -
3162 -
3163 pix = newPix; -
3164 pixModified = true; -
3165 }
-
3166 deviceData->cacheIndent = newCacheIndent; -
3167 } else {
-
3168 -
3169 deviceData->cacheIndent = QPoint(); -
3170 -
3171 -
3172 if (deviceRect.size() != pix.size()) {
-
3173 -
3174 pix = QPixmap(deviceRect.size()); -
3175 pixModified = true; -
3176 itemCache->allExposed = true; -
3177 itemCache->exposed.clear(); -
3178 }
-
3179 }
-
3180 -
3181 -
3182 if (itemCache->allExposed || !itemCache->exposed.isEmpty() || !scrollExposure.isEmpty()) {
-
3183 -
3184 -
3185 if (pixmapFound)
-
3186 QPixmapCache::remove(pixmapKey);
-
3187 -
3188 -
3189 QPointF p = deviceRect.topLeft(); -
3190 QTransform itemToPixmap = painter->worldTransform(); -
3191 if (!p.isNull())
-
3192 itemToPixmap *= QTransform::fromTranslate(-p.x(), -p.y());
-
3193 -
3194 -
3195 QRegion pixmapExposed = scrollExposure; -
3196 if (!itemCache->allExposed) {
-
3197 const QVector<QRectF> &exposed = itemCache->exposed; -
3198 for (int i = 0; i < exposed.size(); ++i)
-
3199 pixmapExposed += itemToPixmap.mapRect(exposed.at(i)).toRect().adjusted(-1, -1, 1, 1);
-
3200 }
-
3201 -
3202 -
3203 QRectF br; -
3204 if (itemCache->allExposed) {
-
3205 br = item->boundingRect(); -
3206 } else {
-
3207 const QVector<QRectF> &exposed = itemCache->exposed; -
3208 for (int i = 0; i < exposed.size(); ++i)
-
3209 br |= exposed.at(i);
-
3210 QTransform pixmapToItem = itemToPixmap.inverted(); -
3211 for (QForeachContainer<__typeof__(scrollExposure.rects())> _container_(scrollExposure.rects()); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (const QRect &r = *_container_.i;; __extension__ ({--_container_.brk; break;})) -
3212 br |= pixmapToItem.mapRect(r);
-
3213 }
-
3214 styleOptionTmp = *option; -
3215 styleOptionTmp.exposedRect = br.adjusted(-1, -1, 1, 1); -
3216 -
3217 -
3218 _q_paintIntoCache(&pix, item, pixmapExposed, itemToPixmap, painter->renderHints(), -
3219 &styleOptionTmp, painterStateProtection); -
3220 -
3221 -
3222 pixModified = true; -
3223 itemCache->allExposed = false; -
3224 itemCache->exposed.clear(); -
3225 }
-
3226 -
3227 if (pixModified) {
-
3228 -
3229 deviceData->key = QPixmapCache::insert(pix); -
3230 }
-
3231 -
3232 -
3233 -
3234 QTransform restoreTransform = painter->worldTransform(); -
3235 painter->setWorldTransform(QTransform()); -
3236 if (newPainterOpacity != oldPainterOpacity) {
-
3237 painter->setOpacity(newPainterOpacity); -
3238 painter->drawPixmap(deviceRect.topLeft(), pix); -
3239 painter->setOpacity(oldPainterOpacity); -
3240 } else {
-
3241 painter->drawPixmap(deviceRect.topLeft(), pix); -
3242 }
-
3243 painter->setWorldTransform(restoreTransform); -
3244 return;
-
3245 } -
3246}
-
3247 -
3248void QGraphicsScenePrivate::drawItems(QPainter *painter, const QTransform *const viewTransform, -
3249 QRegion *exposedRegion, QWidget *widget) -
3250{ -
3251 -
3252 if (!unpolishedItems.isEmpty())
-
3253 _q_polishItems();
-
3254 -
3255 updateAll = false; -
3256 QRectF exposedSceneRect; -
3257 if (exposedRegion && indexMethod != QGraphicsScene::NoIndex) {
-
3258 exposedSceneRect = exposedRegion->boundingRect().adjusted(-1, -1, 1, 1); -
3259 if (viewTransform)
-
3260 exposedSceneRect = viewTransform->inverted().mapRect(exposedSceneRect);
-
3261 }
-
3262 const QList<QGraphicsItem *> tli = index->estimateTopLevelItems(exposedSceneRect, Qt::AscendingOrder); -
3263 for (int i = 0; i < tli.size(); ++i)
-
3264 drawSubtreeRecursive(tli.at(i), painter, viewTransform, exposedRegion, widget);
-
3265}
-
3266 -
3267void QGraphicsScenePrivate::drawSubtreeRecursive(QGraphicsItem *item, QPainter *painter, -
3268 const QTransform *const viewTransform, -
3269 QRegion *exposedRegion, QWidget *widget, -
3270 qreal parentOpacity, const QTransform *const effectTransform) -
3271{ -
3272 qt_noop(); -
3273 -
3274 if (!item->d_ptr->visible)
-
3275 return;
-
3276 -
3277 const bool itemHasContents = !(item->d_ptr->flags & QGraphicsItem::ItemHasNoContents); -
3278 const bool itemHasChildren = !item->d_ptr->children.isEmpty(); -
3279 if (!itemHasContents && !itemHasChildren)
-
3280 return;
-
3281 -
3282 const qreal opacity = item->d_ptr->combineOpacityFromParent(parentOpacity); -
3283 const bool itemIsFullyTransparent = QGraphicsItemPrivate::isOpacityNull(opacity); -
3284 if (itemIsFullyTransparent && (!itemHasChildren || item->d_ptr->childrenCombineOpacity()))
-
3285 return;
-
3286 -
3287 QTransform transform(Qt::Uninitialized); -
3288 QTransform *transformPtr = 0; -
3289 bool translateOnlyTransform = false; -
3290 bool wasDirtyParentSceneTransform = false; -
3291 const bool itemIsUntransformable = item->d_ptr->itemIsUntransformable(); -
3292 if (itemIsUntransformable) {
-
3293 transform = item->deviceTransform(viewTransform ? *viewTransform : QTransform()); -
3294 transformPtr = &transform; -
3295 } else if (item->d_ptr->dirtySceneTransform) {
-
3296 item->d_ptr->updateSceneTransformFromParent(); -
3297 qt_noop(); -
3298 wasDirtyParentSceneTransform = true; -
3299 }
-
3300 -
3301 const bool itemClipsChildrenToShape = (item->d_ptr->flags & QGraphicsItem::ItemClipsChildrenToShape); -
3302 bool drawItem = itemHasContents && !itemIsFullyTransparent;
-
3303 if (drawItem) {
-
3304 const QRectF brect = adjustedItemEffectiveBoundingRect(item); -
3305 if (!transformPtr) { qt_noop(); if (viewTransform) { transform = item->d_ptr->sceneTransform; transform *= *viewTransform; transformPtr = &transform; } else { transformPtr = &item->d_ptr->sceneTransform; translateOnlyTransform = item->d_ptr->sceneTransformTranslateOnly; } }
-
3306 QRect viewBoundingRect = translateOnlyTransform ? brect.translated(transformPtr->dx(), transformPtr->dy()).toAlignedRect()
-
3307 : transformPtr->mapRect(brect).toAlignedRect(); -
3308 viewBoundingRect.adjust(-int(rectAdjust), -int(rectAdjust), rectAdjust, rectAdjust); -
3309 if (widget)
-
3310 item->d_ptr->paintedViewBoundingRects.insert(widget, viewBoundingRect);
-
3311 drawItem = exposedRegion ? exposedRegion->intersects(viewBoundingRect)
-
3312 : !viewBoundingRect.normalized().isEmpty(); -
3313 if (!drawItem) {
-
3314 if (!itemHasChildren)
-
3315 return;
-
3316 if (itemClipsChildrenToShape) {
-
3317 if (wasDirtyParentSceneTransform)
-
3318 item->d_ptr->invalidateChildrenSceneTransform();
-
3319 return;
-
3320 } -
3321 }
-
3322 }
-
3323 -
3324 if (itemHasChildren && itemClipsChildrenToShape)
-
3325 if (!transformPtr) { qt_noop(); if (viewTransform) { transform = item->d_ptr->sceneTransform; transform *= *viewTransform; transformPtr = &transform; } else { transformPtr = &item->d_ptr->sceneTransform; translateOnlyTransform = item->d_ptr->sceneTransformTranslateOnly; } };
-
3326 -
3327 -
3328 if (item->d_ptr->graphicsEffect && item->d_ptr->graphicsEffect->isEnabled()) {
-
3329 if (!transformPtr) { qt_noop(); if (viewTransform) { transform = item->d_ptr->sceneTransform; transform *= *viewTransform; transformPtr = &transform; } else { transformPtr = &item->d_ptr->sceneTransform; translateOnlyTransform = item->d_ptr->sceneTransformTranslateOnly; } };
-
3330 QGraphicsItemPaintInfo info(viewTransform, transformPtr, effectTransform, exposedRegion, widget, &styleOptionTmp, -
3331 painter, opacity, wasDirtyParentSceneTransform, itemHasContents && !itemIsFullyTransparent); -
3332 QGraphicsEffectSource *source = item->d_ptr->graphicsEffect->d_func()->source; -
3333 QGraphicsItemEffectSourcePrivate *sourced = static_cast<QGraphicsItemEffectSourcePrivate *> -
3334 (source->d_func()); -
3335 sourced->info = &info; -
3336 const QTransform restoreTransform = painter->worldTransform(); -
3337 if (effectTransform)
-
3338 painter->setWorldTransform(*transformPtr * *effectTransform);
-
3339 else -
3340 painter->setWorldTransform(*transformPtr);
-
3341 painter->setOpacity(opacity); -
3342 -
3343 if (sourced->currentCachedSystem() != Qt::LogicalCoordinates
-
3344 && sourced->lastEffectTransform != painter->worldTransform())
-
3345 { -
3346 if (sourced->lastEffectTransform.type() <= QTransform::TxTranslate
-
3347 && painter->worldTransform().type() <= QTransform::TxTranslate)
-
3348 { -
3349 QRectF sourceRect = sourced->boundingRect(Qt::DeviceCoordinates); -
3350 QRect effectRect = sourced->paddedEffectRect(Qt::DeviceCoordinates, sourced->currentCachedMode(), sourceRect); -
3351 -
3352 sourced->setCachedOffset(effectRect.topLeft()); -
3353 } else {
-
3354 sourced->invalidateCache(QGraphicsEffectSourcePrivate::TransformChanged); -
3355 }
-
3356 -
3357 sourced->lastEffectTransform = painter->worldTransform(); -
3358 }
-
3359 -
3360 item->d_ptr->graphicsEffect->draw(painter); -
3361 painter->setWorldTransform(restoreTransform); -
3362 sourced->info = 0; -
3363 } else
-
3364 -
3365 { -
3366 draw(item, painter, viewTransform, transformPtr, exposedRegion, widget, opacity, -
3367 effectTransform, wasDirtyParentSceneTransform, drawItem); -
3368 }
-
3369} -
3370 -
3371static inline void setClip(QPainter *painter, QGraphicsItem *item) -
3372{ -
3373 painter->save(); -
3374 QRectF clipRect; -
3375 const QPainterPath clipPath(item->shape()); -
3376 if (QPathClipper::pathToRect(clipPath, &clipRect))
-
3377 painter->setClipRect(clipRect, Qt::IntersectClip);
-
3378 else -
3379 painter->setClipPath(clipPath, Qt::IntersectClip);
-
3380} -
3381 -
3382static inline void setWorldTransform(QPainter *painter, const QTransform *const transformPtr, -
3383 const QTransform *effectTransform) -
3384{ -
3385 qt_noop(); -
3386 if (effectTransform)
-
3387 painter->setWorldTransform(*transformPtr * *effectTransform);
-
3388 else -
3389 painter->setWorldTransform(*transformPtr);
-
3390} -
3391 -
3392void QGraphicsScenePrivate::draw(QGraphicsItem *item, QPainter *painter, const QTransform *const viewTransform, -
3393 const QTransform *const transformPtr, QRegion *exposedRegion, QWidget *widget, -
3394 qreal opacity, const QTransform *effectTransform, -
3395 bool wasDirtyParentSceneTransform, bool drawItem) -
3396{ -
3397 const bool itemIsFullyTransparent = QGraphicsItemPrivate::isOpacityNull(opacity); -
3398 const bool itemClipsChildrenToShape = (item->d_ptr->flags & QGraphicsItem::ItemClipsChildrenToShape); -
3399 const bool itemHasChildren = !item->d_ptr->children.isEmpty(); -
3400 bool setChildClip = itemClipsChildrenToShape; -
3401 bool itemHasChildrenStackedBehind = false; -
3402 -
3403 int i = 0; -
3404 if (itemHasChildren) {
-
3405 if (itemClipsChildrenToShape)
-
3406 setWorldTransform(painter, transformPtr, effectTransform);
-
3407 -
3408 item->d_ptr->ensureSortedChildren(); -
3409 -
3410 -
3411 itemHasChildrenStackedBehind = (item->d_ptr->children.at(0)->d_ptr->flags -
3412 & QGraphicsItem::ItemStacksBehindParent); -
3413 -
3414 if (itemHasChildrenStackedBehind) {
-
3415 if (itemClipsChildrenToShape) {
-
3416 setClip(painter, item); -
3417 setChildClip = false; -
3418 }
-
3419 -
3420 -
3421 for (i = 0; i < item->d_ptr->children.size(); ++i) {
-
3422 QGraphicsItem *child = item->d_ptr->children.at(i); -
3423 if (wasDirtyParentSceneTransform)
-
3424 child->d_ptr->dirtySceneTransform = 1;
-
3425 if (!(child->d_ptr->flags & QGraphicsItem::ItemStacksBehindParent))
-
3426 break;
-
3427 if (itemIsFullyTransparent && !(child->d_ptr->flags & QGraphicsItem::ItemIgnoresParentOpacity))
-
3428 continue;
-
3429 drawSubtreeRecursive(child, painter, viewTransform, exposedRegion, widget, opacity, effectTransform); -
3430 }
-
3431 }
-
3432 }
-
3433 -
3434 -
3435 if (drawItem) {
-
3436 qt_noop(); -
3437 qt_noop(); -
3438 qt_noop(); -
3439 item->d_ptr->initStyleOption(&styleOptionTmp, *transformPtr, exposedRegion -
3440 ? *exposedRegion : QRegion(), exposedRegion == 0); -
3441 -
3442 const bool itemClipsToShape = item->d_ptr->flags & QGraphicsItem::ItemClipsToShape; -
3443 bool restorePainterClip = false; -
3444 -
3445 if (!itemHasChildren || !itemClipsChildrenToShape) {
-
3446 -
3447 setWorldTransform(painter, transformPtr, effectTransform); -
3448 if ((restorePainterClip = itemClipsToShape))
-
3449 setClip(painter, item);
-
3450 } else if (itemHasChildrenStackedBehind){
-
3451 -
3452 -
3453 if (itemClipsToShape) {
-
3454 -
3455 setWorldTransform(painter, transformPtr, effectTransform); -
3456 } else {
-
3457 -
3458 painter->restore(); -
3459 setChildClip = true; -
3460 }
-
3461 } else if (itemClipsToShape) {
-
3462 -
3463 -
3464 -
3465 setClip(painter, item); -
3466 setChildClip = false; -
3467 }
-
3468 -
3469 if (painterStateProtection && !restorePainterClip)
-
3470 painter->save();
-
3471 -
3472 painter->setOpacity(opacity); -
3473 if (!item->d_ptr->cacheMode && !item->d_ptr->isWidget)
-
3474 item->paint(painter, &styleOptionTmp, widget);
-
3475 else -
3476 drawItemHelper(item, painter, &styleOptionTmp, widget, painterStateProtection);
-
3477 -
3478 if (painterStateProtection || restorePainterClip)
-
3479 painter->restore();
-
3480 -
3481 static int drawRect = qgetenv("QT_DRAW_SCENE_ITEM_RECTS").toInt(); -
3482 if (drawRect) {
-
3483 QPen oldPen = painter->pen(); -
3484 QBrush oldBrush = painter->brush(); -
3485 quintptr ptr = reinterpret_cast<quintptr>(item); -
3486 const QColor color = QColor::fromHsv(ptr % 255, 255, 255); -
3487 painter->setPen(color); -
3488 painter->setBrush(Qt::NoBrush); -
3489 painter->drawRect(adjustedItemBoundingRect(item)); -
3490 painter->setPen(oldPen); -
3491 painter->setBrush(oldBrush); -
3492 }
-
3493 }
-
3494 -
3495 -
3496 if (itemHasChildren) {
-
3497 if (setChildClip)
-
3498 setClip(painter, item);
-
3499 -
3500 for (; i < item->d_ptr->children.size(); ++i) {
-
3501 QGraphicsItem *child = item->d_ptr->children.at(i); -
3502 if (wasDirtyParentSceneTransform)
-
3503 child->d_ptr->dirtySceneTransform = 1;
-
3504 if (itemIsFullyTransparent && !(child->d_ptr->flags & QGraphicsItem::ItemIgnoresParentOpacity))
-
3505 continue;
-
3506 drawSubtreeRecursive(child, painter, viewTransform, exposedRegion, widget, opacity, effectTransform); -
3507 }
-
3508 -
3509 -
3510 if (itemClipsChildrenToShape)
-
3511 painter->restore();
-
3512 }
-
3513}
-
3514 -
3515void QGraphicsScenePrivate::markDirty(QGraphicsItem *item, const QRectF &rect, bool invalidateChildren, -
3516 bool force, bool ignoreOpacity, bool removingItemFromScene, -
3517 bool updateBoundingRect) -
3518{ -
3519 qt_noop(); -
3520 if (updateAll)
-
3521 return;
-
3522 -
3523 if (removingItemFromScene && !ignoreOpacity && !item->d_ptr->ignoreOpacity) {
-
3524 -
3525 -
3526 -
3527 -
3528 -
3529 -
3530 -
3531 QGraphicsItem *p = item->d_ptr->parent; -
3532 while (p) {
-
3533 if (p->d_ptr->ignoreOpacity) {
-
3534 item->d_ptr->ignoreOpacity = true; -
3535 break;
-
3536 } -
3537 p = p->d_ptr->parent; -
3538 }
-
3539 }
-
3540 -
3541 if (item->d_ptr->discardUpdateRequest( force, -
3542 removingItemFromScene || invalidateChildren, -
3543 ignoreOpacity)) {
-
3544 if (item->d_ptr->dirty) {
-
3545 -
3546 -
3547 -
3548 -
3549 if (force)
-
3550 item->d_ptr->ignoreVisible = 1;
-
3551 if (ignoreOpacity)
-
3552 item->d_ptr->ignoreOpacity = 1;
-
3553 }
-
3554 return;
-
3555 } -
3556 -
3557 const bool fullItemUpdate = rect.isNull(); -
3558 if (!fullItemUpdate && rect.isEmpty())
-
3559 return;
-
3560 -
3561 if (!processDirtyItemsEmitted) {
-
3562 QMetaMethod method = q_ptr->metaObject()->method(processDirtyItemsIndex); -
3563 method.invoke(q_ptr, Qt::QueuedConnection); -
3564 -
3565 processDirtyItemsEmitted = true; -
3566 }
-
3567 -
3568 if (removingItemFromScene) {
-
3569 -
3570 -
3571 if (isSignalConnected(changedSignalIndex) || views.isEmpty()) {
-
3572 -
3573 -
3574 -
3575 q_func()->update(); -
3576 return;
-
3577 } -
3578 -
3579 for (int i = 0; i < views.size(); ++i) {
-
3580 QGraphicsViewPrivate *viewPrivate = views.at(i)->d_func(); -
3581 QRect rect = item->d_ptr->paintedViewBoundingRects.value(viewPrivate->viewport); -
3582 rect.translate(viewPrivate->dirtyScrollOffset); -
3583 viewPrivate->updateRect(rect); -
3584 }
-
3585 return;
-
3586 } -
3587 -
3588 bool hasNoContents = item->d_ptr->flags & QGraphicsItem::ItemHasNoContents; -
3589 if (!hasNoContents) {
-
3590 item->d_ptr->dirty = 1; -
3591 if (fullItemUpdate)
-
3592 item->d_ptr->fullUpdatePending = 1;
-
3593 else if (!item->d_ptr->fullUpdatePending)
-
3594 item->d_ptr->needsRepaint |= rect;
-
3595 } else if (item->d_ptr->graphicsEffect) {
-
3596 invalidateChildren = true; -
3597 }
-
3598 -
3599 if (invalidateChildren) {
-
3600 item->d_ptr->allChildrenDirty = 1; -
3601 item->d_ptr->dirtyChildren = 1; -
3602 }
-
3603 -
3604 if (force)
-
3605 item->d_ptr->ignoreVisible = 1;
-
3606 if (ignoreOpacity)
-
3607 item->d_ptr->ignoreOpacity = 1;
-
3608 -
3609 if (!updateBoundingRect)
-
3610 item->d_ptr->markParentDirty();
-
3611}
-
3612 -
3613static inline bool updateHelper(QGraphicsViewPrivate *view, QGraphicsItemPrivate *item, -
3614 const QRectF &rect, bool itemIsUntransformable) -
3615{ -
3616 qt_noop(); -
3617 qt_noop(); -
3618 -
3619 QGraphicsItem *itemq = static_cast<QGraphicsItem *>(item->q_ptr); -
3620 QGraphicsView *viewq = static_cast<QGraphicsView *>(view->q_ptr); -
3621 -
3622 if (itemIsUntransformable) {
-
3623 const QTransform xform = itemq->deviceTransform(viewq->viewportTransform()); -
3624 if (!item->hasBoundingRegionGranularity)
-
3625 return view->updateRectF(xform.mapRect(rect));
-
3626 return view->updateRegion(rect, xform);
-
3627 } -
3628 -
3629 if (item->sceneTransformTranslateOnly && view->identityMatrix) {
-
3630 const qreal dx = item->sceneTransform.dx(); -
3631 const qreal dy = item->sceneTransform.dy(); -
3632 QRectF r(rect); -
3633 r.translate(dx - view->horizontalScroll(), dy - view->verticalScroll()); -
3634 return view->updateRectF(r);
-
3635 } -
3636 -
3637 if (!viewq->isTransformed()) {
-
3638 if (!item->hasBoundingRegionGranularity)
-
3639 return view->updateRectF(item->sceneTransform.mapRect(rect));
-
3640 return view->updateRegion(rect, item->sceneTransform);
-
3641 } -
3642 -
3643 QTransform xform = item->sceneTransform; -
3644 xform *= viewq->viewportTransform(); -
3645 if (!item->hasBoundingRegionGranularity)
-
3646 return view->updateRectF(xform.mapRect(rect));
-
3647 return view->updateRegion(rect, xform);
-
3648} -
3649 -
3650void QGraphicsScenePrivate::processDirtyItemsRecursive(QGraphicsItem *item, bool dirtyAncestorContainsChildren, -
3651 qreal parentOpacity) -
3652{ -
3653 QGraphicsScene * const q = q_func(); -
3654 qt_noop(); -
3655 qt_noop(); -
3656 -
3657 if (!item->d_ptr->dirty && !item->d_ptr->dirtyChildren) {
-
3658 resetDirtyItem(item); -
3659 return;
-
3660 } -
3661 -
3662 const bool itemIsHidden = !item->d_ptr->ignoreVisible && !item->d_ptr->visible;
-
3663 if (itemIsHidden) {
-
3664 resetDirtyItem(item, true); -
3665 return;
-
3666 } -
3667 -
3668 bool itemHasContents = !(item->d_ptr->flags & QGraphicsItem::ItemHasNoContents); -
3669 const bool itemHasChildren = !item->d_ptr->children.isEmpty(); -
3670 if (!itemHasContents) {
-
3671 if (!itemHasChildren) {
-
3672 resetDirtyItem(item); -
3673 return;
-
3674 } -
3675 if (item->d_ptr->graphicsEffect)
-
3676 itemHasContents = true;
-
3677 }
-
3678 -
3679 const qreal opacity = item->d_ptr->combineOpacityFromParent(parentOpacity); -
3680 const bool itemIsFullyTransparent = !item->d_ptr->ignoreOpacity
-
3681 && QGraphicsItemPrivate::isOpacityNull(opacity);
-
3682 if (itemIsFullyTransparent && (!itemHasChildren || item->d_ptr->childrenCombineOpacity())) {
-
3683 resetDirtyItem(item, itemHasChildren); -
3684 return;
-
3685 } -
3686 -
3687 bool wasDirtyParentSceneTransform = item->d_ptr->dirtySceneTransform; -
3688 const bool itemIsUntransformable = item->d_ptr->itemIsUntransformable(); -
3689 if (wasDirtyParentSceneTransform && !itemIsUntransformable) {
-
3690 item->d_ptr->updateSceneTransformFromParent(); -
3691 qt_noop(); -
3692 }
-
3693 -
3694 const bool wasDirtyParentViewBoundingRects = item->d_ptr->paintedViewBoundingRectsNeedRepaint; -
3695 if (itemIsFullyTransparent || !itemHasContents || dirtyAncestorContainsChildren) {
-
3696 -
3697 item->d_ptr->dirty = 0; -
3698 item->d_ptr->fullUpdatePending = 0; -
3699 -
3700 if (itemIsFullyTransparent || !itemHasContents)
-
3701 item->d_ptr->paintedViewBoundingRectsNeedRepaint = 0;
-
3702 }
-
3703 -
3704 if (!hasSceneRect && item->d_ptr->geometryChanged && item->d_ptr->visible) {
-
3705 -
3706 if (item->d_ptr->sceneTransformTranslateOnly) {
-
3707 growingItemsBoundingRect |= item->boundingRect().translated(item->d_ptr->sceneTransform.dx(), -
3708 item->d_ptr->sceneTransform.dy()); -
3709 } else {
-
3710 growingItemsBoundingRect |= item->d_ptr->sceneTransform.mapRect(item->boundingRect()); -
3711 }
-
3712 } -
3713 -
3714 -
3715 if (item->d_ptr->dirty || item->d_ptr->paintedViewBoundingRectsNeedRepaint) {
-
3716 const bool useCompatUpdate = views.isEmpty() || isSignalConnected(changedSignalIndex);
-
3717 const QRectF itemBoundingRect = adjustedItemEffectiveBoundingRect(item); -
3718 -
3719 if (useCompatUpdate && !itemIsUntransformable && qFuzzyIsNull(item->boundingRegionGranularity())) {
-
3720 -
3721 -
3722 -
3723 if (item->d_ptr->sceneTransformTranslateOnly) {
-
3724 q->update(itemBoundingRect.translated(item->d_ptr->sceneTransform.dx(), -
3725 item->d_ptr->sceneTransform.dy())); -
3726 } else {
-
3727 QRectF rect = item->d_ptr->sceneTransform.mapRect(itemBoundingRect); -
3728 if (!rect.isEmpty())
-
3729 q->update(rect);
-
3730 }
-
3731 } else { -
3732 QRectF dirtyRect; -
3733 bool uninitializedDirtyRect = true; -
3734 -
3735 for (int j = 0; j < views.size(); ++j) {
-
3736 QGraphicsView *view = views.at(j); -
3737 QGraphicsViewPrivate *viewPrivate = view->d_func(); -
3738 QRect &paintedViewBoundingRect = item->d_ptr->paintedViewBoundingRects[viewPrivate->viewport]; -
3739 if (viewPrivate->fullUpdatePending
-
3740 || viewPrivate->viewportUpdateMode == QGraphicsView::NoViewportUpdate) {
-
3741 -
3742 -
3743 -
3744 paintedViewBoundingRect = QRect(-1, -1, -1, -1); -
3745 continue;
-
3746 } -
3747 -
3748 if (item->d_ptr->paintedViewBoundingRectsNeedRepaint) {
-
3749 paintedViewBoundingRect.translate(viewPrivate->dirtyScrollOffset); -
3750 if (!viewPrivate->updateRect(paintedViewBoundingRect))
-
3751 paintedViewBoundingRect = QRect(-1, -1, -1, -1);
-
3752 }
-
3753 -
3754 if (!item->d_ptr->dirty)
-
3755 continue;
-
3756 -
3757 if (!item->d_ptr->paintedViewBoundingRectsNeedRepaint
-
3758 && paintedViewBoundingRect.x() == -1 && paintedViewBoundingRect.y() == -1
-
3759 && paintedViewBoundingRect.width() == -1 && paintedViewBoundingRect.height() == -1) {
-
3760 continue;
-
3761 } -
3762 -
3763 if (uninitializedDirtyRect) {
-
3764 dirtyRect = itemBoundingRect; -
3765 if (!item->d_ptr->fullUpdatePending) {
-
3766 _q_adjustRect(&item->d_ptr->needsRepaint); -
3767 dirtyRect &= item->d_ptr->needsRepaint; -
3768 }
-
3769 uninitializedDirtyRect = false; -
3770 }
-
3771 -
3772 if (dirtyRect.isEmpty())
-
3773 continue;
-
3774 -
3775 if (!updateHelper(viewPrivate, item->d_ptr.data(), dirtyRect, itemIsUntransformable)
-
3776 && item->d_ptr->paintedViewBoundingRectsNeedRepaint) {
-
3777 paintedViewBoundingRect = QRect(-1, -1, -1, -1); -
3778 }
-
3779 }
-
3780 }
-
3781 } -
3782 -
3783 -
3784 if (itemHasChildren && item->d_ptr->dirtyChildren) {
-
3785 const bool itemClipsChildrenToShape = item->d_ptr->flags & QGraphicsItem::ItemClipsChildrenToShape; -
3786 -
3787 -
3788 -
3789 -
3790 const bool bypassUpdateClip = !itemHasContents && wasDirtyParentViewBoundingRects;
-
3791 if (itemClipsChildrenToShape && !bypassUpdateClip) {
-
3792 -
3793 for (int i = 0; i < views.size(); ++i)
-
3794 views.at(i)->d_func()->setUpdateClip(item);
-
3795 }
-
3796 if (!dirtyAncestorContainsChildren) {
-
3797 dirtyAncestorContainsChildren = item->d_ptr->fullUpdatePending
-
3798 && itemClipsChildrenToShape;
-
3799 }
-
3800 const bool allChildrenDirty = item->d_ptr->allChildrenDirty; -
3801 const bool parentIgnoresVisible = item->d_ptr->ignoreVisible; -
3802 const bool parentIgnoresOpacity = item->d_ptr->ignoreOpacity; -
3803 for (int i = 0; i < item->d_ptr->children.size(); ++i) {
-
3804 QGraphicsItem *child = item->d_ptr->children.at(i); -
3805 if (wasDirtyParentSceneTransform)
-
3806 child->d_ptr->dirtySceneTransform = 1;
-
3807 if (wasDirtyParentViewBoundingRects)
-
3808 child->d_ptr->paintedViewBoundingRectsNeedRepaint = 1;
-
3809 if (parentIgnoresVisible)
-
3810 child->d_ptr->ignoreVisible = 1;
-
3811 if (parentIgnoresOpacity)
-
3812 child->d_ptr->ignoreOpacity = 1;
-
3813 if (allChildrenDirty) {
-
3814 child->d_ptr->dirty = 1; -
3815 child->d_ptr->fullUpdatePending = 1; -
3816 child->d_ptr->dirtyChildren = 1; -
3817 child->d_ptr->allChildrenDirty = 1; -
3818 }
-
3819 processDirtyItemsRecursive(child, dirtyAncestorContainsChildren, opacity); -
3820 }
-
3821 -
3822 if (itemClipsChildrenToShape) {
-
3823 -
3824 for (int i = 0; i < views.size(); ++i)
-
3825 views.at(i)->d_func()->setUpdateClip(0);
-
3826 }
-
3827 } else if (wasDirtyParentSceneTransform) {
-
3828 item->d_ptr->invalidateChildrenSceneTransform(); -
3829 }
-
3830 -
3831 resetDirtyItem(item); -
3832}
-
3833void QGraphicsScene::drawItems(QPainter *painter, -
3834 int numItems, -
3835 QGraphicsItem *items[], -
3836 const QStyleOptionGraphicsItem options[], QWidget *widget) -
3837{ -
3838 QGraphicsScenePrivate * const d = d_func(); -
3839 -
3840 if (!d->unpolishedItems.isEmpty())
-
3841 d->_q_polishItems();
-
3842 -
3843 const qreal opacity = painter->opacity(); -
3844 QTransform viewTransform = painter->worldTransform(); -
3845 (void)options;; -
3846 -
3847 -
3848 QGraphicsView *view = widget ? qobject_cast<QGraphicsView *>(widget->parentWidget()) : 0;
-
3849 QRegion *expose = 0; -
3850 const quint32 oldRectAdjust = d->rectAdjust; -
3851 if (view) {
-
3852 d->updateAll = false; -
3853 expose = &view->d_func()->exposedRegion; -
3854 if (view->d_func()->optimizationFlags & QGraphicsView::DontAdjustForAntialiasing)
-
3855 d->rectAdjust = 1;
-
3856 else -
3857 d->rectAdjust = 2;
-
3858 } -
3859 -
3860 -
3861 QList<QGraphicsItem *> topLevelItems; -
3862 for (int i = 0; i < numItems; ++i) {
-
3863 QGraphicsItem *item = items[i]->topLevelItem(); -
3864 if (!item->d_ptr->itemDiscovered) {
-
3865 topLevelItems << item; -
3866 item->d_ptr->itemDiscovered = 1; -
3867 d->drawSubtreeRecursive(item, painter, &viewTransform, expose, widget); -
3868 }
-
3869 }
-
3870 -
3871 d->rectAdjust = oldRectAdjust; -
3872 -
3873 for (int i = 0; i < topLevelItems.size(); ++i)
-
3874 topLevelItems.at(i)->d_ptr->itemDiscovered = 0;
-
3875 -
3876 painter->setWorldTransform(viewTransform); -
3877 painter->setOpacity(opacity); -
3878}
-
3879bool QGraphicsScene::focusNextPrevChild(bool next) -
3880{ -
3881 QGraphicsScenePrivate * const d = d_func(); -
3882 -
3883 QGraphicsItem *item = focusItem(); -
3884 if (item && !item->isWidget()) {
-
3885 -
3886 return false;
-
3887 } -
3888 if (!item) {
-
3889 if (d->lastFocusItem && !d->lastFocusItem->isWidget()) {
-
3890 -
3891 -
3892 setFocusItem(d->lastFocusItem, next ? Qt::TabFocusReason : Qt::BacktabFocusReason); -
3893 return true;
-
3894 } -
3895 }
-
3896 if (!d->tabFocusFirst) {
-
3897 -
3898 return false;
-
3899 } -
3900 -
3901 -
3902 QGraphicsWidget *widget = 0; -
3903 if (!item) {
-
3904 widget = next ? d->tabFocusFirst : d->tabFocusFirst->d_func()->focusPrev;
-
3905 } else {
-
3906 QGraphicsWidget *test = static_cast<QGraphicsWidget *>(item); -
3907 widget = next ? test->d_func()->focusNext : test->d_func()->focusPrev;
-
3908 if ((next && widget == d->tabFocusFirst) || (!next && widget == d->tabFocusFirst->d_func()->focusPrev))
-
3909 return false;
-
3910 }
-
3911 QGraphicsWidget *widgetThatHadFocus = widget; -
3912 -
3913 -
3914 do { -
3915 if (widget->flags() & QGraphicsItem::ItemIsFocusable
-
3916 && widget->isEnabled() && widget->isVisibleTo(0)
-
3917 && (widget->focusPolicy() & Qt::TabFocus)
-
3918 && (!item || !item->isPanel() || item->isAncestorOf(widget))
-
3919 ) { -
3920 setFocusItem(widget, next ? Qt::TabFocusReason : Qt::BacktabFocusReason); -
3921 return true;
-
3922 } -
3923 widget = next ? widget->d_func()->focusNext : widget->d_func()->focusPrev;
-
3924 if ((next && widget == d->tabFocusFirst) || (!next && widget == d->tabFocusFirst->d_func()->focusPrev))
-
3925 return false;
-
3926 } while (widget != widgetThatHadFocus);
-
3927 -
3928 return false;
-
3929} -
3930QStyle *QGraphicsScene::style() const -
3931{ -
3932 const QGraphicsScenePrivate * const d = d_func(); -
3933 -
3934 return d->style ? d->style : QApplication::style();
-
3935} -
3936void QGraphicsScene::setStyle(QStyle *style) -
3937{ -
3938 QGraphicsScenePrivate * const d = d_func(); -
3939 -
3940 if (style == d->style)
-
3941 return;
-
3942 -
3943 -
3944 delete d->style; -
3945 if ((d->style = style))
-
3946 d->style->setParent(this);
-
3947 -
3948 -
3949 QEvent event(QEvent::StyleChange); -
3950 QApplication::sendEvent(this, &event); -
3951 -
3952 -
3953 for (QForeachContainer<__typeof__(items())> _container_(items()); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (QGraphicsItem *item = *_container_.i;; __extension__ ({--_container_.brk; break;})) { -
3954 if (item->isWidget()) {
-
3955 QGraphicsWidget *widget = static_cast<QGraphicsWidget *>(item); -
3956 if (!widget->testAttribute(Qt::WA_SetStyle))
-
3957 QApplication::sendEvent(widget, &event);
-
3958 }
-
3959 }
-
3960}
-
3961QFont QGraphicsScene::font() const -
3962{ -
3963 const QGraphicsScenePrivate * const d = d_func(); -
3964 return d->font;
-
3965} -
3966void QGraphicsScene::setFont(const QFont &font) -
3967{ -
3968 QGraphicsScenePrivate * const d = d_func(); -
3969 QFont naturalFont = QApplication::font(); -
3970 naturalFont.resolve(0); -
3971 QFont resolvedFont = font.resolve(naturalFont); -
3972 d->setFont_helper(resolvedFont); -
3973}
-
3974QPalette QGraphicsScene::palette() const -
3975{ -
3976 const QGraphicsScenePrivate * const d = d_func(); -
3977 return d->palette;
-
3978} -
3979void QGraphicsScene::setPalette(const QPalette &palette) -
3980{ -
3981 QGraphicsScenePrivate * const d = d_func(); -
3982 QPalette naturalPalette = QApplication::palette(); -
3983 naturalPalette.resolve(0); -
3984 QPalette resolvedPalette = palette.resolve(naturalPalette); -
3985 d->setPalette_helper(resolvedPalette); -
3986}
-
3987bool QGraphicsScene::isActive() const -
3988{ -
3989 const QGraphicsScenePrivate * const d = d_func(); -
3990 return d->activationRefCount > 0;
-
3991} -
3992 -
3993 -
3994 -
3995 -
3996 -
3997 -
3998 -
3999QGraphicsItem *QGraphicsScene::activePanel() const -
4000{ -
4001 const QGraphicsScenePrivate * const d = d_func(); -
4002 return d->activePanel;
-
4003} -
4004void QGraphicsScene::setActivePanel(QGraphicsItem *item) -
4005{ -
4006 QGraphicsScenePrivate * const d = d_func(); -
4007 d->setActivePanelHelper(item, false); -
4008}
-
4009QGraphicsWidget *QGraphicsScene::activeWindow() const -
4010{ -
4011 const QGraphicsScenePrivate * const d = d_func(); -
4012 if (d->activePanel && d->activePanel->isWindow())
-
4013 return static_cast<QGraphicsWidget *>(d->activePanel);
-
4014 return 0;
-
4015} -
4016void QGraphicsScene::setActiveWindow(QGraphicsWidget *widget) -
4017{ -
4018 if (widget && widget->scene() != this) {
-
4019 QMessageLogger("graphicsview/qgraphicsscene.cpp", 56115600, __PRETTY_FUNCTION__).warning("QGraphicsScene::setActiveWindow: widget %p must be part of this scene", -
4020 widget); -
4021 return;
-
4022 } -
4023 -
4024 -
4025 QGraphicsItem *panel = widget ? widget->panel() : 0;
-
4026 setActivePanel(panel); -
4027 -
4028 -
4029 if (panel) {
-
4030 QList<QGraphicsItem *> siblingWindows; -
4031 QGraphicsItem *parent = panel->parentItem(); -
4032 -
4033 for (QForeachContainer<__typeof__(parent ? parent->childItems() : items())> _container_(parent ? parent->childItems() : items()); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (QGraphicsItem *sibling = *_container_.i;; __extension__ ({--_container_.brk; break;})) { -
4034 if (sibling != panel && sibling->isWindow())
-
4035 siblingWindows << sibling;
-
4036 }
-
4037 -
4038 -
4039 qreal z = panel->zValue(); -
4040 for (int i = 0; i < siblingWindows.size(); ++i)
-
4041 z = qMax(z, siblingWindows.at(i)->zValue());
-
4042 -
4043 -
4044 const qreal litt = qreal(0.001); -
4045 panel->setZValue(z + litt); -
4046 }
-
4047}
-
4048bool QGraphicsScene::sendEvent(QGraphicsItem *item, QEvent *event) -
4049{ -
4050 QGraphicsScenePrivate * const d = d_func(); -
4051 if (!item) {
-
4052 QMessageLogger("graphicsview/qgraphicsscene.cpp", 56575646, __PRETTY_FUNCTION__).warning("QGraphicsScene::sendEvent: cannot send event to a null item"); -
4053 return false;
-
4054 } -
4055 if (item->scene() != this) {
-
4056 QMessageLogger("graphicsview/qgraphicsscene.cpp", 56615650, __PRETTY_FUNCTION__).warning("QGraphicsScene::sendEvent: item %p's scene (%p)" -
4057 " is different from this scene (%p)", -
4058 item, item->scene(), this); -
4059 return false;
-
4060 } -
4061 return d->sendEvent(item, event);
-
4062} -
4063 -
4064void QGraphicsScenePrivate::addView(QGraphicsView *view) -
4065{ -
4066 views << view; -
4067 -
4068 for (QForeachContainer<__typeof__(grabbedGestures.keys())> _container_(grabbedGestures.keys()); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (Qt::GestureType gesture = *_container_.i;; __extension__ ({--_container_.brk; break;})) -
4069 view->viewport()->grabGesture(gesture);
-
4070 -
4071}
-
4072 -
4073void QGraphicsScenePrivate::removeView(QGraphicsView *view) -
4074{ -
4075 views.removeAll(view); -
4076}
-
4077 -
4078void QGraphicsScenePrivate::updateTouchPointsForItem(QGraphicsItem *item, QTouchEvent *touchEvent) -
4079{ -
4080 QList<QTouchEvent::TouchPoint> touchPoints = touchEvent->touchPoints(); -
4081 for (int i = 0; i < touchPoints.count(); ++i) {
-
4082 QTouchEvent::TouchPoint &touchPoint = touchPoints[i]; -
4083 touchPoint.setRect(item->mapFromScene(touchPoint.sceneRect()).boundingRect()); -
4084 touchPoint.setStartPos(item->d_ptr->genericMapFromScene(touchPoint.startScenePos(), static_cast<QWidget *>(touchEvent->target()))); -
4085 touchPoint.setLastPos(item->d_ptr->genericMapFromScene(touchPoint.lastScenePos(), static_cast<QWidget *>(touchEvent->target()))); -
4086 }
-
4087 touchEvent->setTouchPoints(touchPoints); -
4088}
-
4089 -
4090int QGraphicsScenePrivate::findClosestTouchPointId(const QPointF &scenePos) -
4091{ -
4092 int closestTouchPointId = -1; -
4093 qreal closestDistance = qreal(0.); -
4094 for (QForeachContainer<__typeof__(sceneCurrentTouchPoints)> _container_(sceneCurrentTouchPoints); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (const QTouchEvent::TouchPoint &touchPoint = *_container_.i;; __extension__ ({--_container_.brk; break;})) { -
4095 qreal distance = QLineF(scenePos, touchPoint.scenePos()).length(); -
4096 if (closestTouchPointId == -1|| distance < closestDistance) {
-
4097 closestTouchPointId = touchPoint.id(); -
4098 closestDistance = distance; -
4099 }
-
4100 }
-
4101 return closestTouchPointId;
-
4102} -
4103 -
4104void QGraphicsScenePrivate::touchEventHandler(QTouchEvent *sceneTouchEvent) -
4105{ -
4106 typedef QPair<Qt::TouchPointStates, QList<QTouchEvent::TouchPoint> > StatesAndTouchPoints; -
4107 QHash<QGraphicsItem *, StatesAndTouchPoints> itemsNeedingEvents; -
4108 -
4109 for (int i = 0; i < sceneTouchEvent->touchPoints().count(); ++i) {
-
4110 const QTouchEvent::TouchPoint &touchPoint = sceneTouchEvent->touchPoints().at(i); -
4111 -
4112 -
4113 QGraphicsItem *item = 0; -
4114 if (touchPoint.state() == Qt::TouchPointPressed) {
-
4115 if (sceneTouchEvent->device()->type() == QTouchDevice::TouchPad) {
-
4116 -
4117 item = itemForTouchPointId.isEmpty()
-
4118 ? 0 -
4119 : itemForTouchPointId.constBegin().value(); -
4120 }
-
4121 -
4122 if (!item) {
-
4123 -
4124 cachedItemsUnderMouse = itemsAtPosition(touchPoint.screenPos().toPoint(), -
4125 touchPoint.scenePos(), -
4126 static_cast<QWidget *>(sceneTouchEvent->target())); -
4127 item = cachedItemsUnderMouse.isEmpty() ? 0 : cachedItemsUnderMouse.first();
-
4128 }
-
4129 -
4130 if (sceneTouchEvent->device()->type() == QTouchDevice::TouchScreen) {
-
4131 -
4132 int closestTouchPointId = findClosestTouchPointId(touchPoint.scenePos()); -
4133 QGraphicsItem *closestItem = itemForTouchPointId.value(closestTouchPointId); -
4134 if (!item || (closestItem && cachedItemsUnderMouse.contains(closestItem)))
-
4135 item = closestItem;
-
4136 }
-
4137 if (!item)
-
4138 continue;
-
4139 -
4140 itemForTouchPointId.insert(touchPoint.id(), item); -
4141 sceneCurrentTouchPoints.insert(touchPoint.id(), touchPoint); -
4142 } else if (touchPoint.state() == Qt::TouchPointReleased) {
-
4143 item = itemForTouchPointId.take(touchPoint.id()); -
4144 if (!item)
-
4145 continue;
-
4146 -
4147 sceneCurrentTouchPoints.remove(touchPoint.id()); -
4148 } else {
-
4149 item = itemForTouchPointId.value(touchPoint.id()); -
4150 if (!item)
-
4151 continue;
-
4152 qt_noop(); -
4153 sceneCurrentTouchPoints[touchPoint.id()] = touchPoint; -
4154 }
-
4155 -
4156 StatesAndTouchPoints &statesAndTouchPoints = itemsNeedingEvents[item]; -
4157 statesAndTouchPoints.first |= touchPoint.state(); -
4158 statesAndTouchPoints.second.append(touchPoint); -
4159 }
-
4160 -
4161 if (itemsNeedingEvents.isEmpty()) {
-
4162 sceneTouchEvent->accept(); -
4163 return;
-
4164 } -
4165 -
4166 bool ignoreSceneTouchEvent = true; -
4167 QHash<QGraphicsItem *, StatesAndTouchPoints>::ConstIterator it = itemsNeedingEvents.constBegin(); -
4168 const QHash<QGraphicsItem *, StatesAndTouchPoints>::ConstIterator end = itemsNeedingEvents.constEnd(); -
4169 for (; it != end; ++it) {
-
4170 QGraphicsItem *item = it.key(); -
4171 -
4172 (void) item->isBlockedByModalPanel(&item); -
4173 -
4174 -
4175 QEvent::Type eventType; -
4176 switch (it.value().first) { -
4177 case Qt::TouchPointPressed: -
4178 -
4179 eventType = QEvent::TouchBegin; -
4180 break;
-
4181 case Qt::TouchPointReleased: -
4182 -
4183 eventType = QEvent::TouchEnd; -
4184 break;
-
4185 case Qt::TouchPointStationary: -
4186 -
4187 continue;
-
4188 default: -
4189 -
4190 eventType = QEvent::TouchUpdate; -
4191 break;
-
4192 } -
4193 -
4194 QTouchEvent touchEvent(eventType); -
4195 touchEvent.setWindow(sceneTouchEvent->window()); -
4196 touchEvent.setTarget(sceneTouchEvent->target()); -
4197 touchEvent.setDevice(sceneTouchEvent->device()); -
4198 touchEvent.setModifiers(sceneTouchEvent->modifiers()); -
4199 touchEvent.setTouchPointStates(it.value().first); -
4200 touchEvent.setTouchPoints(it.value().second); -
4201 touchEvent.setTimestamp(sceneTouchEvent->timestamp()); -
4202 -
4203 switch (touchEvent.type()) { -
4204 case QEvent::TouchBegin: -
4205 { -
4206 -
4207 -
4208 item->d_ptr->acceptedTouchBeginEvent = true; -
4209 bool res = sendTouchBeginEvent(item, &touchEvent)
-
4210 && touchEvent.isAccepted();
-
4211 if (!res) {
-
4212 -
4213 for (int i = 0; i < touchEvent.touchPoints().count(); ++i) {
-
4214 const QTouchEvent::TouchPoint &touchPoint = touchEvent.touchPoints().at(i); -
4215 itemForTouchPointId.remove(touchPoint.id()); -
4216 sceneCurrentTouchPoints.remove(touchPoint.id()); -
4217 }
-
4218 ignoreSceneTouchEvent = false; -
4219 }
-
4220 break;
-
4221 } -
4222 default: -
4223 if (item->d_ptr->acceptedTouchBeginEvent) {
-
4224 updateTouchPointsForItem(item, &touchEvent); -
4225 (void) sendEvent(item, &touchEvent); -
4226 ignoreSceneTouchEvent = false; -
4227 }
-
4228 break;
-
4229 } -
4230 }
-
4231 sceneTouchEvent->setAccepted(ignoreSceneTouchEvent); -
4232}
-
4233 -
4234bool QGraphicsScenePrivate::sendTouchBeginEvent(QGraphicsItem *origin, QTouchEvent *touchEvent) -
4235{ -
4236 QGraphicsScene * const q = q_func(); -
4237 -
4238 if (cachedItemsUnderMouse.isEmpty() || cachedItemsUnderMouse.first() != origin) {
-
4239 const QTouchEvent::TouchPoint &firstTouchPoint = touchEvent->touchPoints().first(); -
4240 cachedItemsUnderMouse = itemsAtPosition(firstTouchPoint.screenPos().toPoint(), -
4241 firstTouchPoint.scenePos(), -
4242 static_cast<QWidget *>(touchEvent->target())); -
4243 }
-
4244 -
4245 -
4246 bool setFocus = false; -
4247 -
4248 for (QForeachContainer<__typeof__(cachedItemsUnderMouse)> _container_(cachedItemsUnderMouse); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (QGraphicsItem *item = *_container_.i;; __extension__ ({--_container_.brk; break;})) { -
4249 if (item->isEnabled() && ((item->flags() & QGraphicsItem::ItemIsFocusable) && item->d_ptr->mouseSetsFocus)) {
-
4250 if (!item->isWidget() || ((QGraphicsWidget *)item)->focusPolicy() & Qt::ClickFocus) {
-
4251 setFocus = true; -
4252 if (item != q->focusItem())
-
4253 q->setFocusItem(item, Qt::MouseFocusReason);
-
4254 break;
-
4255 } -
4256 }
-
4257 if (item->isPanel())
-
4258 break;
-
4259 if (item->d_ptr->flags & QGraphicsItem::ItemStopsClickFocusPropagation)
-
4260 break;
-
4261 if (item->d_ptr->flags & QGraphicsItem::ItemStopsFocusHandling) {
-
4262 -
4263 setFocus = true; -
4264 break;
-
4265 } -
4266 }
-
4267 -
4268 -
4269 if (!stickyFocus && !setFocus)
-
4270 q->setFocusItem(0, Qt::MouseFocusReason);
-
4271 -
4272 bool res = false; -
4273 bool eventAccepted = touchEvent->isAccepted(); -
4274 for (QForeachContainer<__typeof__(cachedItemsUnderMouse)> _container_(cachedItemsUnderMouse); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (QGraphicsItem *item = *_container_.i;; __extension__ ({--_container_.brk; break;})) { -
4275 -
4276 updateTouchPointsForItem(item, touchEvent); -
4277 bool acceptTouchEvents = item->acceptTouchEvents(); -
4278 touchEvent->setAccepted(acceptTouchEvents); -
4279 res = acceptTouchEvents && sendEvent(item, touchEvent);
-
4280 eventAccepted = touchEvent->isAccepted(); -
4281 if (itemForTouchPointId.value(touchEvent->touchPoints().first().id()) == 0) {
-
4282 -
4283 item = 0; -
4284 } else {
-
4285 item->d_ptr->acceptedTouchBeginEvent = (res && eventAccepted);
-
4286 }
-
4287 touchEvent->spont = false; -
4288 if (res && eventAccepted) {
-
4289 -
4290 for (int i = 0; i < touchEvent->touchPoints().count(); ++i) {
-
4291 const QTouchEvent::TouchPoint &touchPoint = touchEvent->touchPoints().at(i); -
4292 itemForTouchPointId[touchPoint.id()] = item; -
4293 }
-
4294 break;
-
4295 } -
4296 if (item && item->isPanel())
-
4297 break;
-
4298 }
-
4299 -
4300 touchEvent->setAccepted(eventAccepted); -
4301 return res;
-
4302} -
4303 -
4304void QGraphicsScenePrivate::enableTouchEventsOnViews() -
4305{ -
4306 for (QForeachContainer<__typeof__(views)> _container_(views); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (QGraphicsView *view = *_container_.i;; __extension__ ({--_container_.brk; break;})) -
4307 view->viewport()->setAttribute(Qt::WA_AcceptTouchEvents, true);
-
4308}
-
4309 -
4310void QGraphicsScenePrivate::updateInputMethodSensitivityInViews() -
4311{ -
4312 for (int i = 0; i < views.size(); ++i)
-
4313 views.at(i)->d_func()->updateInputMethodSensitivity();
-
4314}
-
4315 -
4316void QGraphicsScenePrivate::enterModal(QGraphicsItem *panel, QGraphicsItem::PanelModality previousModality) -
4317{ -
4318 QGraphicsScene * const q = q_func(); -
4319 qt_noop(); -
4320 -
4321 QGraphicsItem::PanelModality panelModality = panel->d_ptr->panelModality; -
4322 if (previousModality != QGraphicsItem::NonModal) {
-
4323 -
4324 -
4325 panel->d_ptr->panelModality = previousModality; -
4326 }
-
4327 -
4328 QSet<QGraphicsItem *> blockedPanels; -
4329 QList<QGraphicsItem *> items = q->items(); -
4330 for (int i = 0; i < items.count(); ++i) {
-
4331 QGraphicsItem *item = items.at(i); -
4332 if (item->isPanel() && item->isBlockedByModalPanel())
-
4333 blockedPanels.insert(item);
-
4334 }
-
4335 -
4336 -
4337 if (previousModality != QGraphicsItem::NonModal) {
-
4338 -
4339 panel->d_ptr->panelModality = panelModality; -
4340 -
4341 modalPanels.removeAll(panel); -
4342 }
-
4343 -
4344 modalPanels.prepend(panel); -
4345 -
4346 if (!hoverItems.isEmpty()) {
-
4347 -
4348 QGraphicsSceneHoverEvent hoverEvent; -
4349 hoverEvent.setScenePos(lastSceneMousePos); -
4350 dispatchHoverEvent(&hoverEvent); -
4351 }
-
4352 -
4353 if (!mouseGrabberItems.isEmpty() && lastMouseGrabberItemHasImplicitMouseGrab) {
-
4354 QGraphicsItem *item = mouseGrabberItems.last(); -
4355 if (item->isBlockedByModalPanel())
-
4356 ungrabMouse(item, false);
-
4357 }
-
4358 -
4359 QEvent windowBlockedEvent(QEvent::WindowBlocked); -
4360 QEvent windowUnblockedEvent(QEvent::WindowUnblocked); -
4361 for (int i = 0; i < items.count(); ++i) {
-
4362 QGraphicsItem *item = items.at(i); -
4363 if (item->isPanel()) {
-
4364 if (!blockedPanels.contains(item) && item->isBlockedByModalPanel()) {
-
4365 -
4366 sendEvent(item, &windowBlockedEvent); -
4367 } else if (blockedPanels.contains(item) && !item->isBlockedByModalPanel()) {
-
4368 -
4369 -
4370 sendEvent(item, &windowUnblockedEvent); -
4371 }
-
4372 } -
4373 }
-
4374}
-
4375 -
4376void QGraphicsScenePrivate::leaveModal(QGraphicsItem *panel) -
4377{ -
4378 QGraphicsScene * const q = q_func(); -
4379 qt_noop(); -
4380 -
4381 QSet<QGraphicsItem *> blockedPanels; -
4382 QList<QGraphicsItem *> items = q->items(); -
4383 for (int i = 0; i < items.count(); ++i) {
-
4384 QGraphicsItem *item = items.at(i); -
4385 if (item->isPanel() && item->isBlockedByModalPanel())
-
4386 blockedPanels.insert(item);
-
4387 }
-
4388 -
4389 modalPanels.removeAll(panel); -
4390 -
4391 QEvent e(QEvent::WindowUnblocked); -
4392 for (int i = 0; i < items.count(); ++i) {
-
4393 QGraphicsItem *item = items.at(i); -
4394 if (item->isPanel() && blockedPanels.contains(item) && !item->isBlockedByModalPanel())
-
4395 sendEvent(item, &e);
-
4396 }
-
4397 -
4398 -
4399 QGraphicsSceneHoverEvent hoverEvent; -
4400 hoverEvent.setScenePos(lastSceneMousePos); -
4401 dispatchHoverEvent(&hoverEvent); -
4402}
-
4403 -
4404 -
4405void QGraphicsScenePrivate::gestureTargetsAtHotSpots(const QSet<QGesture *> &gestures, -
4406 Qt::GestureFlag flag, -
4407 QHash<QGraphicsObject *, QSet<QGesture *> > *targets, -
4408 QSet<QGraphicsObject *> *itemsSet, -
4409 QSet<QGesture *> *normal, -
4410 QSet<QGesture *> *conflicts) -
4411{ -
4412 QSet<QGesture *> normalGestures; -
4413 for (QForeachContainer<__typeof__(gestures)> _container_(gestures); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (QGesture *gesture = *_container_.i;; __extension__ ({--_container_.brk; break;})) { -
4414 if (!gesture->hasHotSpot())
-
4415 continue;
-
4416 const Qt::GestureType gestureType = gesture->gestureType(); -
4417 QList<QGraphicsItem *> items = itemsAtPosition(QPoint(), gesture->d_func()->sceneHotSpot, 0); -
4418 for (int j = 0; j < items.size(); ++j) {
-
4419 QGraphicsItem *item = items.at(j); -
4420 -
4421 -
4422 -
4423 (void) item->isBlockedByModalPanel(&item); -
4424 -
4425 if (QGraphicsObject *itemobj = item->toGraphicsObject()) {
-
4426 QGraphicsItemPrivate *d = item->QGraphicsItem::d_func(); -
4427 QMap<Qt::GestureType, Qt::GestureFlags>::const_iterator it = -
4428 d->gestureContext.constFind(gestureType); -
4429 if (it != d->gestureContext.constEnd() && (!flag || (it.value() & flag))) {
-
4430 if (normalGestures.contains(gesture)) {
-
4431 normalGestures.remove(gesture); -
4432 if (conflicts)
-
4433 conflicts->insert(gesture);
-
4434 } else {
-
4435 normalGestures.insert(gesture); -
4436 }
-
4437 if (targets)
-
4438 (*targets)[itemobj].insert(gesture);
-
4439 if (itemsSet)
-
4440 (*itemsSet).insert(itemobj);
-
4441 }
-
4442 }
-
4443 -
4444 if (item->isPanel())
-
4445 break;
-
4446 }
-
4447 }
-
4448 if (normal)
-
4449 *normal = normalGestures;
-
4450}
-
4451 -
4452void QGraphicsScenePrivate::gestureEventHandler(QGestureEvent *event) -
4453{ -
4454 QWidget *viewport = event->widget(); -
4455 if (!viewport)
-
4456 return;
-
4457 QGraphicsView *graphicsView = qobject_cast<QGraphicsView *>(viewport->parent()); -
4458 if (!graphicsView)
-
4459 return;
-
4460 -
4461 QList<QGesture *> allGestures = event->gestures(); -
4462 if (0) QMessageLogger("graphicsview/qgraphicsscene.cpp", 60676056, __PRETTY_FUNCTION__).debug() << "QGraphicsScenePrivate::gestureEventHandler:"
-
4463 << "Gestures:" << allGestures;
-
4464 -
4465 QSet<QGesture *> startedGestures; -
4466 QPoint delta = viewport->mapFromGlobal(QPoint()); -
4467 QTransform toScene = QTransform::fromTranslate(delta.x(), delta.y()) -
4468 * graphicsView->viewportTransform().inverted(); -
4469 for (QForeachContainer<__typeof__(allGestures)> _container_(allGestures); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (QGesture *gesture = *_container_.i;; __extension__ ({--_container_.brk; break;})) { -
4470 -
4471 if (gesture->hasHotSpot()) {
-
4472 gesture->d_func()->sceneHotSpot = toScene.map(gesture->hotSpot()); -
4473 } else {
-
4474 gesture->d_func()->sceneHotSpot = QPointF(); -
4475 }
-
4476 -
4477 QGraphicsObject *target = gestureTargets.value(gesture, 0); -
4478 if (!target) {
-
4479 -
4480 -
4481 if (gesture->state() == Qt::GestureStarted)
-
4482 startedGestures.insert(gesture);
-
4483 }
-
4484 }
-
4485 -
4486 if (!startedGestures.isEmpty()) {
-
4487 QSet<QGesture *> normalGestures; -
4488 QSet<QGesture *> conflictedGestures; -
4489 gestureTargetsAtHotSpots(startedGestures, Qt::GestureFlag(0), &cachedItemGestures, 0, -
4490 &normalGestures, &conflictedGestures); -
4491 cachedTargetItems = cachedItemGestures.keys(); -
4492 std::sort(cachedTargetItems.begin(), cachedTargetItems.end(), qt_closestItemFirst); -
4493 if (0) QMessageLogger("graphicsview/qgraphicsscene.cpp", 60986087, __PRETTY_FUNCTION__).debug() << "QGraphicsScenePrivate::gestureEventHandler:"
-
4494 << "Normal gestures:" << normalGestures -
4495 << "Conflicting gestures:" << conflictedGestures;
-
4496 -
4497 -
4498 -
4499 if (!conflictedGestures.isEmpty()) {
-
4500 for (int i = 0; i < cachedTargetItems.size(); ++i) {
-
4501 QPointer<QGraphicsObject> item = cachedTargetItems.at(i); -
4502 -
4503 -
4504 QSet<QGesture *> gestures = conflictedGestures & cachedItemGestures.value(item.data()); -
4505 if (gestures.isEmpty())
-
4506 continue;
-
4507 -
4508 if (0) QMessageLogger("graphicsview/qgraphicsscene.cpp", 61136102, __PRETTY_FUNCTION__).debug() << "QGraphicsScenePrivate::gestureEventHandler:"
-
4509 << "delivering override to" -
4510 << item.data() << gestures;
-
4511 -
4512 QGestureEvent ev(gestures.toList()); -
4513 ev.t = QEvent::GestureOverride; -
4514 ev.setWidget(event->widget()); -
4515 -
4516 ev.ignore(); -
4517 for (QForeachContainer<__typeof__(gestures)> _container_(gestures); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (QGesture *g = *_container_.i;; __extension__ ({--_container_.brk; break;})) -
4518 ev.setAccepted(g, false);
-
4519 sendEvent(item.data(), &ev); -
4520 -
4521 for (QForeachContainer<__typeof__(gestures)> _container_(gestures); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (QGesture *g = *_container_.i;; __extension__ ({--_container_.brk; break;})) { -
4522 if (ev.isAccepted() || ev.isAccepted(g)) {
-
4523 conflictedGestures.remove(g); -
4524 -
4525 if (item) {
-
4526 gestureTargets.insert(g, item.data()); -
4527 QHash<QGraphicsObject *, QSet<QGesture *> >::iterator it, e; -
4528 it = cachedItemGestures.begin(); -
4529 e = cachedItemGestures.end(); -
4530 for(; it != e; ++it)
-
4531 it.value().remove(g);
-
4532 cachedItemGestures[item.data()].insert(g); -
4533 }
-
4534 if (0) QMessageLogger("graphicsview/qgraphicsscene.cpp", 61396128, __PRETTY_FUNCTION__).debug() << "QGraphicsScenePrivate::gestureEventHandler:"
-
4535 << "override was accepted:" -
4536 << g << item.data();
-
4537 }
-
4538 -
4539 -
4540 -
4541 if (!gestureTargets.contains(g) && item)
-
4542 gestureTargets.insert(g, item.data());
-
4543 -
4544 }
-
4545 if (conflictedGestures.isEmpty())
-
4546 break;
-
4547 }
-
4548 }
-
4549 -
4550 -
4551 if (!normalGestures.isEmpty()) {
-
4552 for (int i = 0; i < cachedTargetItems.size() && !normalGestures.isEmpty(); ++i) {
-
4553 QGraphicsObject *item = cachedTargetItems.at(i); -
4554 -
4555 -
4556 for (QForeachContainer<__typeof__(cachedItemGestures.value(item))> _container_(cachedItemGestures.value(item)); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (QGesture *g = *_container_.i;; __extension__ ({--_container_.brk; break;})) { -
4557 if (!gestureTargets.contains(g)) {
-
4558 gestureTargets.insert(g, item); -
4559 normalGestures.remove(g); -
4560 }
-
4561 }
-
4562 }
-
4563 }
-
4564 }
-
4565 -
4566 -
4567 -
4568 QSet<QGesture *> undeliveredGestures; -
4569 QSet<QGesture *> parentPropagatedGestures; -
4570 for (QForeachContainer<__typeof__(allGestures)> _container_(allGestures); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (QGesture *gesture = *_container_.i;; __extension__ ({--_container_.brk; break;})) { -
4571 if (QGraphicsObject *target = gestureTargets.value(gesture, 0)) {
-
4572 cachedItemGestures[target].insert(gesture); -
4573 cachedTargetItems.append(target); -
4574 undeliveredGestures.insert(gesture); -
4575 QGraphicsItemPrivate *d = target->QGraphicsItem::d_func(); -
4576 const Qt::GestureFlags flags = d->gestureContext.value(gesture->gestureType()); -
4577 if (flags & Qt::IgnoredGesturesPropagateToParent)
-
4578 parentPropagatedGestures.insert(gesture);
-
4579 } else {
-
4580 if (0) QMessageLogger("graphicsview/qgraphicsscene.cpp", 61856174, __PRETTY_FUNCTION__).debug() << "QGraphicsScenePrivate::gestureEventHandler:"
-
4581 << "no target for" << gesture << "at" -
4582 << gesture->hotSpot() << gesture->d_func()->sceneHotSpot;
-
4583 }
-
4584 } -
4585 std::sort(cachedTargetItems.begin(), cachedTargetItems.end(), qt_closestItemFirst); -
4586 for (int i = 0; i < cachedTargetItems.size(); ++i) {
-
4587 QPointer<QGraphicsObject> receiver = cachedTargetItems.at(i); -
4588 QSet<QGesture *> gestures = -
4589 undeliveredGestures & cachedItemGestures.value(receiver.data()); -
4590 gestures -= cachedAlreadyDeliveredGestures.value(receiver.data()); -
4591 -
4592 if (gestures.isEmpty())
-
4593 continue;
-
4594 -
4595 cachedAlreadyDeliveredGestures[receiver.data()] += gestures; -
4596 const bool isPanel = receiver.data()->isPanel(); -
4597 -
4598 if (0) QMessageLogger("graphicsview/qgraphicsscene.cpp", 62036192, __PRETTY_FUNCTION__).debug() << "QGraphicsScenePrivate::gestureEventHandler:"
-
4599 << "delivering to" -
4600 << receiver.data() << gestures;
-
4601 QGestureEvent ev(gestures.toList()); -
4602 ev.setWidget(event->widget()); -
4603 sendEvent(receiver.data(), &ev); -
4604 QSet<QGesture *> ignoredGestures; -
4605 for (QForeachContainer<__typeof__(gestures)> _container_(gestures); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (QGesture *g = *_container_.i;; __extension__ ({--_container_.brk; break;})) { -
4606 if (!ev.isAccepted() && !ev.isAccepted(g)) {
-
4607 -
4608 -
4609 -
4610 -
4611 -
4612 if (receiver && receiver.data() == gestureTargets.value(g, 0))
-
4613 ignoredGestures.insert(g);
-
4614 } else {
-
4615 if (receiver && g->state() == Qt::GestureStarted) {
-
4616 -
4617 -
4618 gestureTargets[g] = receiver.data(); -
4619 }
-
4620 undeliveredGestures.remove(g); -
4621 }
-
4622 } -
4623 if (undeliveredGestures.isEmpty())
-
4624 break;
-
4625 -
4626 -
4627 -
4628 if (!ignoredGestures.isEmpty() && !isPanel) {
-
4629 -
4630 -
4631 -
4632 QSet<QGraphicsObject *> targetsSet = cachedTargetItems.toSet(); -
4633 -
4634 if (receiver) {
-
4635 -
4636 for (QSet<QGesture *>::iterator it = ignoredGestures.begin(); -
4637 it != ignoredGestures.end();) {
-
4638 if (parentPropagatedGestures.contains(*it)) {
-
4639 QGesture *gesture = *it; -
4640 const Qt::GestureType gestureType = gesture->gestureType(); -
4641 QGraphicsItem *item = receiver.data(); -
4642 while (item) {
-
4643 if (QGraphicsObject *obj = item->toGraphicsObject()) {
-
4644 if (item->d_func()->gestureContext.contains(gestureType)) {
-
4645 targetsSet.insert(obj); -
4646 cachedItemGestures[obj].insert(gesture); -
4647 }
-
4648 }
-
4649 if (item->isPanel())
-
4650 break;
-
4651 item = item->parentItem(); -
4652 }
-
4653 -
4654 it = ignoredGestures.erase(it); -
4655 continue;
-
4656 } -
4657 ++it; -
4658 }
-
4659 }
-
4660 -
4661 gestureTargetsAtHotSpots(ignoredGestures, Qt::ReceivePartialGestures, -
4662 &cachedItemGestures, &targetsSet, 0, 0); -
4663 -
4664 cachedTargetItems = targetsSet.toList(); -
4665 std::sort(cachedTargetItems.begin(), cachedTargetItems.end(), qt_closestItemFirst); -
4666 if (0) QMessageLogger("graphicsview/qgraphicsscene.cpp", 62716260, __PRETTY_FUNCTION__).debug() << "QGraphicsScenePrivate::gestureEventHandler:"
-
4667 << "new targets:" << cachedTargetItems;
-
4668 i = -1; -
4669 continue;
-
4670 } -
4671 }
-
4672 -
4673 for (QForeachContainer<__typeof__(startedGestures)> _container_(startedGestures); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (QGesture *g = *_container_.i;; __extension__ ({--_container_.brk; break;})) { -
4674 if (g->gestureCancelPolicy() == QGesture::CancelAllInContext) {
-
4675 if (0) QMessageLogger("graphicsview/qgraphicsscene.cpp", 62806269, __PRETTY_FUNCTION__).debug() << "lets try to cancel some";
-
4676 -
4677 cancelGesturesForChildren(g); -
4678 }
-
4679 }
-
4680 -
4681 -
4682 for (QForeachContainer<__typeof__(allGestures)> _container_(allGestures); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (QGesture *g = *_container_.i;; __extension__ ({--_container_.brk; break;})) { -
4683 switch (g->state()) { -
4684 case Qt::GestureFinished: -
4685 case Qt::GestureCanceled: -
4686 gestureTargets.remove(g); -
4687 break;
-
4688 default: -
4689 break;
-
4690 } -
4691 }
-
4692 -
4693 cachedTargetItems.clear(); -
4694 cachedItemGestures.clear(); -
4695 cachedAlreadyDeliveredGestures.clear(); -
4696}
-
4697 -
4698void QGraphicsScenePrivate::cancelGesturesForChildren(QGesture *original) -
4699{ -
4700 qt_noop(); -
4701 QGraphicsItem *originalItem = gestureTargets.value(original); -
4702 if (originalItem == 0)
-
4703 return;
-
4704 -
4705 -
4706 -
4707 -
4708 QSet<QGesture *> canceledGestures; -
4709 QHash<QGesture *, QGraphicsObject *>::Iterator iter = gestureTargets.begin(); -
4710 while (iter != gestureTargets.end()) {
-
4711 QGraphicsObject *item = iter.value(); -
4712 -
4713 if (item != originalItem && originalItem->isAncestorOf(item)) {
-
4714 if (0) QMessageLogger("graphicsview/qgraphicsscene.cpp", 63196308, __PRETTY_FUNCTION__).debug() << " found a gesture to cancel" << iter.key();
-
4715 iter.key()->d_func()->state = Qt::GestureCanceled; -
4716 canceledGestures << iter.key(); -
4717 }
-
4718 ++iter; -
4719 }
-
4720 -
4721 -
4722 QSet<QGesture *> almostCanceledGestures = canceledGestures; -
4723 QSet<QGesture *>::Iterator setIter; -
4724 while (!almostCanceledGestures.isEmpty()) {
-
4725 QGraphicsObject *target = 0; -
4726 QSet<QGesture*> gestures; -
4727 setIter = almostCanceledGestures.begin(); -
4728 -
4729 while (setIter != almostCanceledGestures.end()) {
-
4730 QGraphicsObject *item = gestureTargets.value(*setIter); -
4731 if (target == 0)
-
4732 target = item;
-
4733 if (target == item) {
-
4734 gestures << *setIter; -
4735 setIter = almostCanceledGestures.erase(setIter); -
4736 } else {
-
4737 ++setIter; -
4738 }
-
4739 } -
4740 qt_noop(); -
4741 -
4742 QList<QGesture *> list = gestures.toList(); -
4743 QGestureEvent ev(list); -
4744 sendEvent(target, &ev); -
4745 -
4746 for (QForeachContainer<__typeof__(list)> _container_(list); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (QGesture *g = *_container_.i;; __extension__ ({--_container_.brk; break;})) { -
4747 if (ev.isAccepted() || ev.isAccepted(g))
-
4748 gestures.remove(g);
-
4749 }
-
4750 -
4751 for (QForeachContainer<__typeof__(gestures)> _container_(gestures); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (QGesture *g = *_container_.i;; __extension__ ({--_container_.brk; break;})) { -
4752 if (!g->hasHotSpot())
-
4753 continue;
-
4754 -
4755 QList<QGraphicsItem *> items = itemsAtPosition(QPoint(), g->d_func()->sceneHotSpot, 0); -
4756 for (int j = 0; j < items.size(); ++j) {
-
4757 QGraphicsObject *item = items.at(j)->toGraphicsObject(); -
4758 if (!item)
-
4759 continue;
-
4760 QGraphicsItemPrivate *d = item->QGraphicsItem::d_func(); -
4761 if (d->gestureContext.contains(g->gestureType())) {
-
4762 QList<QGesture *> list; -
4763 list << g; -
4764 QGestureEvent ev(list); -
4765 sendEvent(item, &ev); -
4766 if (ev.isAccepted() || ev.isAccepted(g))
-
4767 break;
-
4768 }
-
4769 }
-
4770 }
-
4771 }
-
4772 -
4773 QGestureManager *gestureManager = QApplicationPrivate::instance()->gestureManager; -
4774 qt_noop(); -
4775 for (setIter = canceledGestures.begin(); setIter != canceledGestures.end(); ++setIter) {
-
4776 gestureManager->recycle(*setIter); -
4777 gestureTargets.remove(*setIter); -
4778 }
-
4779}
-
4780 -
4781void QGraphicsScenePrivate::grabGesture(QGraphicsItem *, Qt::GestureType gesture) -
4782{ -
4783 (void)QGestureManager::instance(); -
4784 if (!grabbedGestures[gesture]++) {
-
4785 for (QForeachContainer<__typeof__(views)> _container_(views); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (QGraphicsView *view = *_container_.i;; __extension__ ({--_container_.brk; break;})) -
4786 view->viewport()->grabGesture(gesture);
-
4787 }
-
4788}
-
4789 -
4790void QGraphicsScenePrivate::ungrabGesture(QGraphicsItem *item, Qt::GestureType gesture) -
4791{ -
4792 -
4793 qt_noop(); -
4794 QGraphicsObject *obj = static_cast<QGraphicsObject *>(item); -
4795 QGestureManager::instance()->cleanupCachedGestures(obj, gesture); -
4796 if (!--grabbedGestures[gesture]) {
-
4797 for (QForeachContainer<__typeof__(views)> _container_(views); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (QGraphicsView *view = *_container_.i;; __extension__ ({--_container_.brk; break;})) -
4798 view->viewport()->ungrabGesture(gesture);
-
4799 }
-
4800}
-
4801 -
4802 -
4803 -
4804 -
4805 -
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial