void RenderImage::setPixmap( const QPixmap &p, const QRect& r, CachedImage *o) { if(o != image) { RenderReplaced::setPixmap(p, r, o); return; } bool iwchanged = false; if(o->isErrorImage()) { int iw = p.width() + 8; int ih = p.height() + 8; // we have an alt and the user meant it (its not a text we invented) if ( element() && !alt.isEmpty() && !element()->getAttribute( ATTR_ALT ).isNull()) { const QFontMetrics &fm = style()->fontMetrics(); QRect br = fm.boundingRect ( 0, 0, 1024, 256, Qt::AlignAuto|Qt::WordBreak, alt.string() ); if ( br.width() > iw ) iw = br.width(); if ( br.height() > ih ) ih = br.height(); } if ( iw != intrinsicWidth() ) { setIntrinsicWidth( iw ); iwchanged = true; } if ( ih != intrinsicHeight() ) { setIntrinsicHeight( ih ); iwchanged = true; } } berrorPic = o->isErrorImage(); bool needlayout = false; // Image dimensions have been changed, see what needs to be done if ( ( o->pixmap_size().width() != intrinsicWidth() || o->pixmap_size().height() != intrinsicHeight() || iwchanged) ) { // qDebug("image dimensions have been changed, old: %d/%d new: %d/%d", // intrinsicWidth(), intrinsicHeight(), // o->pixmap_size().width(), o->pixmap_size().height()); if(!o->isErrorImage()) { setIntrinsicWidth( o->pixmap_size().width() ); setIntrinsicHeight( o->pixmap_size().height() ); } // In the case of generated image content using :before/:after, we might not be in the // render tree yet. In that case, we don't need to worry about check for layout, since we'll get a // layout when we get added in to the render tree hierarchy later. if (containingBlock()) { // lets see if we need to relayout at all.. int oldwidth = m_width; int oldheight = m_height; calcWidth(); calcHeight(); if(iwchanged || m_width != oldwidth || m_height != oldheight) needlayout = true; m_width = oldwidth; m_height = oldheight; } } #if APPLE_CHANGES && !KWIQ //FIXME: testing for animations // Stop the previous image, if it may be animating. pix.stopAnimations(); #endif #if APPLE_CHANGES pix.decreaseUseCount(); #endif pix = p; #if APPLE_CHANGES p.increaseUseCount(); #endif if (needlayout) { if (!selfNeedsLayout()) setNeedsLayout(true); if (minMaxKnown()) setMinMaxKnown(false); } else { #if APPLE_CHANGES // FIXME: We always just do a complete repaint, since we always pass in the full pixmap // rect at the moment anyway. resizeCache = QPixmap(); repaintRectangle(QRect(borderLeft()+paddingLeft(), borderTop()+paddingTop(), contentWidth(), contentHeight())); #else // FIXME: This code doesn't handle scaling properly, since it doesn't scale |r|. bool completeRepaint = !resizeCache.isNull(); int cHeight = contentHeight(); int scaledHeight = intrinsicHeight() ? ((o->valid_rect().height()*cHeight)/intrinsicHeight()) : 0; // don't bog down X server doing xforms if(completeRepaint && cHeight >= 5 && o->valid_rect().height() < intrinsicHeight() && (scaledHeight / (cHeight/5) == resizeCache.height() / (cHeight/5))) return; resizeCache = QPixmap(); // for resized animations if(completeRepaint) repaintRectangle(QRect(borderLeft()+paddingLeft(), borderTop()+paddingTop(), contentWidth(), contentHeight())); else { repaintRectangle(QRect(r.x() + borderLeft() + paddingLeft(), r.y() + borderTop() + paddingTop(), r.width(), r.height())); } #endif } }