src/gui/graphicsview/qgraphicsview.cpp
changeset 19 fcece45ef507
parent 18 2f34d5167611
child 30 5dc02b23752f
equal deleted inserted replaced
18:2f34d5167611 19:fcece45ef507
  3358         if (!d->backgroundPixmapExposed.isEmpty()) {
  3358         if (!d->backgroundPixmapExposed.isEmpty()) {
  3359             QPainter backgroundPainter(&d->backgroundPixmap);
  3359             QPainter backgroundPainter(&d->backgroundPixmap);
  3360             backgroundPainter.setClipRegion(d->backgroundPixmapExposed, Qt::ReplaceClip);
  3360             backgroundPainter.setClipRegion(d->backgroundPixmapExposed, Qt::ReplaceClip);
  3361             if (viewTransformed)
  3361             if (viewTransformed)
  3362                 backgroundPainter.setTransform(viewTransform);
  3362                 backgroundPainter.setTransform(viewTransform);
  3363 #ifdef Q_WS_X11
       
  3364 #undef X11
       
  3365             if (backgroundPainter.paintEngine()->type() != QPaintEngine::X11)
       
  3366 #define X11 qt_x11Data
       
  3367 #endif
       
  3368                 backgroundPainter.setCompositionMode(QPainter::CompositionMode_Source);
       
  3369             QRectF backgroundExposedSceneRect = mapToScene(d->backgroundPixmapExposed.boundingRect()).boundingRect();
  3363             QRectF backgroundExposedSceneRect = mapToScene(d->backgroundPixmapExposed.boundingRect()).boundingRect();
  3370             drawBackground(&backgroundPainter, backgroundExposedSceneRect);
  3364             drawBackground(&backgroundPainter, backgroundExposedSceneRect);
  3371             d->backgroundPixmapExposed = QRegion();
  3365             d->backgroundPixmapExposed = QRegion();
  3372         }
  3366         }
  3373 
  3367 
  3398         // IndirectPainting (the else branch), because in that case we always save()
  3392         // IndirectPainting (the else branch), because in that case we always save()
  3399         // and restore() in QGraphicsScene::drawItems().
  3393         // and restore() in QGraphicsScene::drawItems().
  3400         if (!d->scene->d_func()->painterStateProtection)
  3394         if (!d->scene->d_func()->painterStateProtection)
  3401             painter.setWorldTransform(viewTransform);
  3395             painter.setWorldTransform(viewTransform);
  3402     } 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 
  3403         // Find all exposed items
  3404         // Find all exposed items
  3404         bool allItems = false;
  3405         bool allItems = false;
  3405         QList<QGraphicsItem *> itemList = d->findItems(d->exposedRegion, &allItems, viewTransform);
  3406         QList<QGraphicsItem *> itemList = d->findItems(d->exposedRegion, &allItems, viewTransform);
  3406         if (!itemList.isEmpty()) {
  3407         if (!itemList.isEmpty()) {
  3407             // Generate the style options.
  3408             // Generate the style options.
  3408             const int numItems = itemList.size();
  3409             const int numItems = itemList.size();
  3409             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.
  3410             QStyleOptionGraphicsItem *styleOptionArray = d->allocStyleOptionsArray(numItems);
  3411             QStyleOptionGraphicsItem *styleOptionArray = d->allocStyleOptionsArray(numItems);
       
  3412             QTransform transform(Qt::Uninitialized);
  3411             for (int i = 0; i < numItems; ++i) {
  3413             for (int i = 0; i < numItems; ++i) {
  3412                 itemArray[i]->d_ptr->initStyleOption(&styleOptionArray[i], viewTransform,
  3414                 QGraphicsItem *item = itemArray[i];
  3413                                                      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());
  3414             }
  3431             }
  3415             // Draw the items.
  3432             // Draw the items.
  3416             drawItems(&painter, numItems, itemArray, styleOptionArray);
  3433             drawItems(&painter, numItems, itemArray, styleOptionArray);
  3417             d->freeStyleOptionsArray(styleOptionArray);
  3434             d->freeStyleOptionsArray(styleOptionArray);
  3418         }
  3435         }