src/gui/graphicsview/qgraphicsview.cpp
branchRCL_3
changeset 7 3f74d0d4af4c
parent 4 3b1da2848fc7
equal deleted inserted replaced
6:dee5afe5301f 7:3f74d0d4af4c
  2746                         connect(d->scene, SIGNAL(changed(QList<QRectF>)),
  2746                         connect(d->scene, SIGNAL(changed(QList<QRectF>)),
  2747                                 this, SLOT(updateScene(QList<QRectF>)));
  2747                                 this, SLOT(updateScene(QList<QRectF>)));
  2748                     }
  2748                     }
  2749                 }
  2749                 }
  2750             }
  2750             }
  2751             d->scene->d_func()->updateAll = false;
       
  2752         }
  2751         }
  2753         break;
  2752         break;
  2754     case QEvent::TouchBegin:
  2753     case QEvent::TouchBegin:
  2755     case QEvent::TouchUpdate:
  2754     case QEvent::TouchUpdate:
  2756     case QEvent::TouchEnd:
  2755     case QEvent::TouchEnd:
  3359         if (!d->backgroundPixmapExposed.isEmpty()) {
  3358         if (!d->backgroundPixmapExposed.isEmpty()) {
  3360             QPainter backgroundPainter(&d->backgroundPixmap);
  3359             QPainter backgroundPainter(&d->backgroundPixmap);
  3361             backgroundPainter.setClipRegion(d->backgroundPixmapExposed, Qt::ReplaceClip);
  3360             backgroundPainter.setClipRegion(d->backgroundPixmapExposed, Qt::ReplaceClip);
  3362             if (viewTransformed)
  3361             if (viewTransformed)
  3363                 backgroundPainter.setTransform(viewTransform);
  3362                 backgroundPainter.setTransform(viewTransform);
  3364 #ifdef Q_WS_X11
       
  3365 #undef X11
       
  3366             if (backgroundPainter.paintEngine()->type() != QPaintEngine::X11)
       
  3367 #define X11 qt_x11Data
       
  3368 #endif
       
  3369                 backgroundPainter.setCompositionMode(QPainter::CompositionMode_Source);
       
  3370             QRectF backgroundExposedSceneRect = mapToScene(d->backgroundPixmapExposed.boundingRect()).boundingRect();
  3363             QRectF backgroundExposedSceneRect = mapToScene(d->backgroundPixmapExposed.boundingRect()).boundingRect();
  3371             drawBackground(&backgroundPainter, backgroundExposedSceneRect);
  3364             drawBackground(&backgroundPainter, backgroundExposedSceneRect);
  3372             d->backgroundPixmapExposed = QRegion();
  3365             d->backgroundPixmapExposed = QRegion();
  3373         }
  3366         }
  3374 
  3367 
  3399         // IndirectPainting (the else branch), because in that case we always save()
  3392         // IndirectPainting (the else branch), because in that case we always save()
  3400         // and restore() in QGraphicsScene::drawItems().
  3393         // and restore() in QGraphicsScene::drawItems().
  3401         if (!d->scene->d_func()->painterStateProtection)
  3394         if (!d->scene->d_func()->painterStateProtection)
  3402             painter.setWorldTransform(viewTransform);
  3395             painter.setWorldTransform(viewTransform);
  3403     } else {
  3396     } else {
       
  3397         // Make sure we don't have unpolished items before we draw
       
  3398         if (!d->scene->d_func()->unpolishedItems.isEmpty())
       
  3399             d->scene->d_func()->_q_polishItems();
       
  3400         // We reset updateAll here (after we've issued polish events)
       
  3401         // so that we can discard update requests coming from polishEvent().
       
  3402         d->scene->d_func()->updateAll = false;
       
  3403 
  3404         // Find all exposed items
  3404         // Find all exposed items
  3405         bool allItems = false;
  3405         bool allItems = false;
  3406         QList<QGraphicsItem *> itemList = d->findItems(d->exposedRegion, &allItems, viewTransform);
  3406         QList<QGraphicsItem *> itemList = d->findItems(d->exposedRegion, &allItems, viewTransform);
  3407         if (!itemList.isEmpty()) {
  3407         if (!itemList.isEmpty()) {
  3408             // Generate the style options.
  3408             // Generate the style options.
  3409             const int numItems = itemList.size();
  3409             const int numItems = itemList.size();
  3410             QGraphicsItem **itemArray = &itemList[0]; // Relies on QList internals, but is perfectly valid.
  3410             QGraphicsItem **itemArray = &itemList[0]; // Relies on QList internals, but is perfectly valid.
  3411             QStyleOptionGraphicsItem *styleOptionArray = d->allocStyleOptionsArray(numItems);
  3411             QStyleOptionGraphicsItem *styleOptionArray = d->allocStyleOptionsArray(numItems);
       
  3412             QTransform transform(Qt::Uninitialized);
  3412             for (int i = 0; i < numItems; ++i) {
  3413             for (int i = 0; i < numItems; ++i) {
  3413                 itemArray[i]->d_ptr->initStyleOption(&styleOptionArray[i], viewTransform,
  3414                 QGraphicsItem *item = itemArray[i];
  3414                                                      d->exposedRegion, allItems);
  3415                 QGraphicsItemPrivate *itemd = item->d_ptr.data();
       
  3416                 itemd->initStyleOption(&styleOptionArray[i], viewTransform, d->exposedRegion, allItems);
       
  3417                 // Cache the item's area in view coordinates.
       
  3418                 // Note that we have to do this here in case the base class implementation
       
  3419                 // (QGraphicsScene::drawItems) is not called. If it is, we'll do this
       
  3420                 // operation twice, but that's the price one has to pay for using indirect
       
  3421                 // painting :-/.
       
  3422                 const QRectF brect = adjustedItemEffectiveBoundingRect(item);
       
  3423                 if (!itemd->itemIsUntransformable()) {
       
  3424                     transform = item->sceneTransform();
       
  3425                     if (viewTransformed)
       
  3426                         transform *= viewTransform;
       
  3427                 } else {
       
  3428                     transform = item->deviceTransform(viewTransform);
       
  3429                 }
       
  3430                 itemd->paintedViewBoundingRects.insert(d->viewport, transform.mapRect(brect).toRect());
  3415             }
  3431             }
  3416             // Draw the items.
  3432             // Draw the items.
  3417             drawItems(&painter, numItems, itemArray, styleOptionArray);
  3433             drawItems(&painter, numItems, itemArray, styleOptionArray);
  3418             d->freeStyleOptionsArray(styleOptionArray);
  3434             d->freeStyleOptionsArray(styleOptionArray);
  3419         }
  3435         }
  3608 
  3624 
  3609     painter->fillRect(rect, d->foregroundBrush);
  3625     painter->fillRect(rect, d->foregroundBrush);
  3610 }
  3626 }
  3611 
  3627 
  3612 /*!
  3628 /*!
       
  3629     \obsolete 
       
  3630 
  3613     Draws the items \a items in the scene using \a painter, after the
  3631     Draws the items \a items in the scene using \a painter, after the
  3614     background and before the foreground are drawn. \a numItems is the number
  3632     background and before the foreground are drawn. \a numItems is the number
  3615     of items in \a items and options in \a options. \a options is a list of
  3633     of items in \a items and options in \a options. \a options is a list of
  3616     styleoptions; one for each item. Reimplement this function to provide
  3634     styleoptions; one for each item. Reimplement this function to provide
  3617     custom item drawing for this view.
  3635     custom item drawing for this view.
  3618 
  3636 
  3619     The default implementation calls the scene's drawItems() function.
  3637     The default implementation calls the scene's drawItems() function.
  3620 
  3638 
  3621     \obsolete Since Qt 4.6, this function is not called anymore unless
  3639     Since Qt 4.6, this function is not called anymore unless
  3622     the QGraphicsView::IndirectPainting flag is given as an Optimization
  3640     the QGraphicsView::IndirectPainting flag is given as an Optimization
  3623     flag.
  3641     flag.
  3624 
  3642 
  3625     \sa drawForeground(), drawBackground(), QGraphicsScene::drawItems()
  3643     \sa drawForeground(), drawBackground(), QGraphicsScene::drawItems()
  3626 */
  3644 */