Changeset 651 for trunk/src/gui/graphicsview/qgraphicsscene.cpp
- Timestamp:
- Mar 8, 2010, 12:52:58 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/vendor/nokia/qt/4.6.2 (added) merged: 650 /branches/vendor/nokia/qt/current merged: 649 /branches/vendor/nokia/qt/4.6.1 removed
- Property svn:mergeinfo changed
-
trunk/src/gui/graphicsview/qgraphicsscene.cpp
r561 r651 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 20 09Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation (qt-info@nokia.com) … … 252 252 #include <private/qgraphicseffect_p.h> 253 253 #include <private/qgesturemanager_p.h> 254 #include <private/qpathclipper_p.h> 254 255 255 256 // #define GESTURE_DEBUG … … 293 294 selectionChanging(0), 294 295 needSortTopLevelItems(true), 295 unpolishedItemsModified(true),296 296 holesInTopLevelSiblingIndex(false), 297 297 topLevelSequentialOrdering(true), … … 374 374 } 375 375 } else { 376 updateAll = false; 376 if (views.isEmpty()) { 377 updateAll = false; 378 return; 379 } 377 380 for (int i = 0; i < views.size(); ++i) 378 381 views.at(i)->d_func()->processPendingUpdates(); … … 430 433 void QGraphicsScenePrivate::_q_polishItems() 431 434 { 432 QSet<QGraphicsItem *>::Iterator it = unpolishedItems.begin(); 435 if (unpolishedItems.isEmpty()) 436 return; 437 433 438 const QVariant booleanTrueVariant(true); 434 while (!unpolishedItems.isEmpty()) { 435 QGraphicsItem *item = *it; 436 it = unpolishedItems.erase(it); 437 unpolishedItemsModified = false; 438 if (!item->d_ptr->explicitlyHidden) { 439 QGraphicsItem *item = 0; 440 QGraphicsItemPrivate *itemd = 0; 441 const int oldUnpolishedCount = unpolishedItems.count(); 442 443 for (int i = 0; i < oldUnpolishedCount; ++i) { 444 item = unpolishedItems.at(i); 445 if (!item) 446 continue; 447 itemd = item->d_ptr.data(); 448 itemd->pendingPolish = false; 449 if (!itemd->explicitlyHidden) { 439 450 item->itemChange(QGraphicsItem::ItemVisibleChange, booleanTrueVariant); 440 451 item->itemChange(QGraphicsItem::ItemVisibleHasChanged, booleanTrueVariant); 441 452 } 442 if (item ->isWidget()) {453 if (itemd->isWidget) { 443 454 QEvent event(QEvent::Polish); 444 455 QApplication::sendEvent((QGraphicsWidget *)item, &event); 445 456 } 446 if (unpolishedItemsModified) 447 it = unpolishedItems.begin(); 457 } 458 459 if (unpolishedItems.count() == oldUnpolishedCount) { 460 // No new items were added to the vector. 461 unpolishedItems.clear(); 462 } else { 463 // New items were appended; keep them and remove the old ones. 464 unpolishedItems.remove(0, oldUnpolishedCount); 465 unpolishedItems.squeeze(); 466 QMetaObject::invokeMethod(q_ptr, "_q_polishItems", Qt::QueuedConnection); 448 467 } 449 468 } … … 600 619 Q_ASSERT_X(parentItem->scene() == q, "QGraphicsScene::removeItem", 601 620 "Parent item's scene is different from this item's scene"); 602 item-> d_ptr->setParentItemHelper(0);621 item->setParentItem(0); 603 622 } 604 623 } else { … … 639 658 hoverItems.removeAll(item); 640 659 cachedItemsUnderMouse.removeAll(item); 641 unpolishedItems.remove(item); 642 unpolishedItemsModified = true; 660 if (item->d_ptr->pendingPolish) { 661 const int unpolishedIndex = unpolishedItems.indexOf(item); 662 if (unpolishedIndex != -1) 663 unpolishedItems[unpolishedIndex] = 0; 664 item->d_ptr->pendingPolish = false; 665 } 643 666 resetDirtyItem(item); 644 667 … … 1937 1960 1938 1961 This convenience function is equivalent to calling items(QRectF(\a x, \a y, \a w, \a h), \a mode). 1939 1962 1940 1963 This function is deprecated and returns incorrect results if the scene 1941 1964 contains items that ignore transformations. Use the overload that takes … … 2483 2506 return; 2484 2507 } 2485 if (item-> scene()== this) {2508 if (item->d_ptr->scene == this) { 2486 2509 qWarning("QGraphicsScene::addItem: item has already been added to this scene"); 2487 2510 return; 2488 2511 } 2489 2512 // Remove this item from its existing scene 2490 if (QGraphicsScene *oldScene = item-> scene())2513 if (QGraphicsScene *oldScene = item->d_ptr->scene) 2491 2514 oldScene->removeItem(item); 2492 2515 … … 2497 2520 QGraphicsScene *targetScene = qVariantValue<QGraphicsScene *>(newSceneVariant); 2498 2521 if (targetScene != this) { 2499 if (targetScene && item-> scene()!= targetScene)2522 if (targetScene && item->d_ptr->scene != targetScene) 2500 2523 targetScene->addItem(item); 2501 2524 return; 2502 2525 } 2503 2526 2527 if (d->unpolishedItems.isEmpty()) 2528 QMetaObject::invokeMethod(this, "_q_polishItems", Qt::QueuedConnection); 2529 d->unpolishedItems.append(item); 2530 item->d_ptr->pendingPolish = true; 2531 2504 2532 // Detach this item from its parent if the parent's scene is different 2505 2533 // from this scene. 2506 if (QGraphicsItem *itemParent = item-> parentItem()) {2507 if (itemParent-> scene()!= this)2534 if (QGraphicsItem *itemParent = item->d_ptr->parent) { 2535 if (itemParent->d_ptr->scene != this) 2508 2536 item->setParentItem(0); 2509 2537 } … … 2535 2563 } 2536 2564 #ifndef QT_NO_CURSOR 2537 if (d->allItemsUseDefaultCursor && item-> hasCursor()) {2565 if (d->allItemsUseDefaultCursor && item->d_ptr->hasCursor) { 2538 2566 d->allItemsUseDefaultCursor = false; 2539 2567 if (d->allItemsIgnoreHoverEvents) // already enabled otherwise … … 2543 2571 2544 2572 // Enable touch events if the item accepts touch events. 2545 if (d->allItemsIgnoreTouchEvents && item-> acceptTouchEvents()) {2573 if (d->allItemsIgnoreTouchEvents && item->d_ptr->acceptTouchEvents) { 2546 2574 d->allItemsIgnoreTouchEvents = false; 2547 2575 d->enableTouchEventsOnViews(); … … 2576 2604 2577 2605 // Add all children recursively 2578 foreach (QGraphicsItem *child, item->children()) 2579 addItem(child); 2606 item->d_ptr->ensureSortedChildren(); 2607 for (int i = 0; i < item->d_ptr->children.size(); ++i) 2608 addItem(item->d_ptr->children.at(i)); 2580 2609 2581 2610 // Resolve font and palette. … … 2583 2612 item->d_ptr->resolvePalette(d->palette.resolve()); 2584 2613 2585 if (d->unpolishedItems.isEmpty())2586 QMetaObject::invokeMethod(this, "_q_polishItems", Qt::QueuedConnection);2587 d->unpolishedItems.insert(item);2588 d->unpolishedItemsModified = true;2589 2614 2590 2615 // Reenable selectionChanged() for individual items … … 2620 2645 } 2621 2646 2622 if (item-> flags()& QGraphicsItem::ItemSendsScenePositionChanges)2647 if (item->d_ptr->flags & QGraphicsItem::ItemSendsScenePositionChanges) 2623 2648 d->registerScenePosItem(item); 2624 2649 … … 3767 3792 bool QGraphicsScenePrivate::itemAcceptsHoverEvents_helper(const QGraphicsItem *item) const 3768 3793 { 3769 return ( !item->isBlockedByModalPanel() &&3770 (item->acceptHoverEvents()3771 || (item->isWidget()3772 && static_cast<const QGraphicsWidget *>(item)->d_func()->hasDecoration())));3794 return (item->d_ptr->acceptsHover 3795 || (item->d_ptr->isWidget 3796 && static_cast<const QGraphicsWidget *>(item)->d_func()->hasDecoration())) 3797 && !item->isBlockedByModalPanel(); 3773 3798 } 3774 3799 … … 4583 4608 _q_polishItems(); 4584 4609 4610 updateAll = false; 4585 4611 QRectF exposedSceneRect; 4586 4612 if (exposedRegion && indexMethod != QGraphicsScene::NoIndex) { … … 4610 4636 4611 4637 const qreal opacity = item->d_ptr->combineOpacityFromParent(parentOpacity); 4612 const bool itemIsFullyTransparent = (opacity < 0.0001);4638 const bool itemIsFullyTransparent = QGraphicsItemPrivate::isOpacityNull(opacity); 4613 4639 if (itemIsFullyTransparent && (!itemHasChildren || item->d_ptr->childrenCombineOpacity())) 4614 4640 return; … … 4687 4713 && sourced->lastEffectTransform != painter->worldTransform()) 4688 4714 { 4715 bool unclipped = false; 4716 if (sourced->lastEffectTransform.type() <= QTransform::TxTranslate 4717 && painter->worldTransform().type() <= QTransform::TxTranslate) 4718 { 4719 QRectF itemRect = item->boundingRect(); 4720 if (!item->d_ptr->children.isEmpty()) 4721 itemRect |= item->childrenBoundingRect(); 4722 4723 QRectF oldSourceRect = sourced->lastEffectTransform.mapRect(itemRect); 4724 QRectF newSourceRect = painter->worldTransform().mapRect(itemRect); 4725 4726 QRect oldEffectRect = sourced->paddedEffectRect(sourced->currentCachedSystem(), sourced->currentCachedMode(), oldSourceRect); 4727 QRect newEffectRect = sourced->paddedEffectRect(sourced->currentCachedSystem(), sourced->currentCachedMode(), newSourceRect); 4728 4729 QRect deviceRect(0, 0, painter->device()->width(), painter->device()->height()); 4730 if (deviceRect.contains(oldEffectRect) && deviceRect.contains(newEffectRect)) { 4731 sourced->setCachedOffset(newEffectRect.topLeft()); 4732 unclipped = true; 4733 } 4734 } 4735 4689 4736 sourced->lastEffectTransform = painter->worldTransform(); 4690 sourced->invalidateCache(QGraphicsEffectSourcePrivate::TransformChanged); 4737 4738 if (!unclipped) 4739 sourced->invalidateCache(QGraphicsEffectSourcePrivate::TransformChanged); 4691 4740 } 4692 4741 … … 4707 4756 bool wasDirtyParentSceneTransform, bool drawItem) 4708 4757 { 4709 const bool itemIsFullyTransparent = (opacity < 0.0001);4758 const bool itemIsFullyTransparent = QGraphicsItemPrivate::isOpacityNull(opacity); 4710 4759 const bool itemClipsChildrenToShape = (item->d_ptr->flags & QGraphicsItem::ItemClipsChildrenToShape); 4711 4760 const bool itemHasChildren = !item->d_ptr->children.isEmpty(); … … 4722 4771 else 4723 4772 painter->setWorldTransform(*transformPtr); 4724 painter->setClipPath(item->shape(), Qt::IntersectClip); 4773 QRectF clipRect; 4774 const QPainterPath clipPath(item->shape()); 4775 if (QPathClipper::pathToRect(clipPath, &clipRect)) 4776 painter->setClipRect(clipRect, Qt::IntersectClip); 4777 else 4778 painter->setClipPath(clipPath, Qt::IntersectClip); 4725 4779 } 4726 4780 … … 4758 4812 } 4759 4813 4760 if (itemClipsToShape) 4761 painter->setClipPath(item->shape(), Qt::IntersectClip); 4814 if (itemClipsToShape) { 4815 QRectF clipRect; 4816 const QPainterPath clipPath(item->shape()); 4817 if (QPathClipper::pathToRect(clipPath, &clipRect)) 4818 painter->setClipRect(clipRect, Qt::IntersectClip); 4819 else 4820 painter->setClipPath(clipPath, Qt::IntersectClip); 4821 } 4762 4822 painter->setOpacity(opacity); 4763 4823 … … 4860 4920 item->d_ptr->ignoreOpacity = 1; 4861 4921 4862 QGraphicsItem *p = item->d_ptr->parent; 4863 while (p) { 4864 p->d_ptr->dirtyChildren = 1; 4865 #ifndef QT_NO_GRAPHICSEFFECT 4866 if (p->d_ptr->graphicsEffect && p->d_ptr->graphicsEffect->isEnabled()) { 4867 p->d_ptr->dirty = 1; 4868 p->d_ptr->fullUpdatePending = 1; 4869 } 4870 #endif //QT_NO_GRAPHICSEFFECT 4871 p = p->d_ptr->parent; 4872 } 4922 item->d_ptr->markParentDirty(); 4873 4923 } 4874 4924 … … 4945 4995 4946 4996 const qreal opacity = item->d_ptr->combineOpacityFromParent(parentOpacity); 4947 const bool itemIsFullyTransparent = !item->d_ptr->ignoreOpacity && opacity < 0.0001; 4997 const bool itemIsFullyTransparent = !item->d_ptr->ignoreOpacity 4998 && QGraphicsItemPrivate::isOpacityNull(opacity); 4948 4999 if (itemIsFullyTransparent && (!itemHasChildren || item->d_ptr->childrenCombineOpacity())) { 4949 5000 resetDirtyItem(item, /*recursive=*/itemHasChildren); … … 5118 5169 d->_q_polishItems(); 5119 5170 5171 d->updateAll = false; 5120 5172 QTransform viewTransform = painter->worldTransform(); 5121 5173 Q_UNUSED(options);
Note:
See TracChangeset
for help on using the changeset viewer.