87 */ |
87 */ |
88 |
88 |
89 // XXX bug in WebKit - can call repaintRequested and other cache-changing functions from within render! |
89 // XXX bug in WebKit - can call repaintRequested and other cache-changing functions from within render! |
90 static int inpaint=0; |
90 static int inpaint=0; |
91 static int inpaint_clearcache=0; |
91 static int inpaint_clearcache=0; |
|
92 |
|
93 extern Q_GUI_EXPORT bool qt_applefontsmoothing_enabled; |
92 |
94 |
93 /*! |
95 /*! |
94 Marks areas of the cache that intersect with the given \a rect as dirty and |
96 Marks areas of the cache that intersect with the given \a rect as dirty and |
95 in need of being refreshed. |
97 in need of being refreshed. |
96 |
98 |
149 */ |
151 */ |
150 void QDeclarativePaintedItem::setContentsSize(const QSize &size) |
152 void QDeclarativePaintedItem::setContentsSize(const QSize &size) |
151 { |
153 { |
152 Q_D(QDeclarativePaintedItem); |
154 Q_D(QDeclarativePaintedItem); |
153 if (d->contentsSize == size) return; |
155 if (d->contentsSize == size) return; |
|
156 prepareGeometryChange(); |
154 d->contentsSize = size; |
157 d->contentsSize = size; |
155 setImplicitWidth(size.width()*d->contentsScale); |
|
156 setImplicitHeight(size.height()*d->contentsScale); |
|
157 clearCache(); |
158 clearCache(); |
158 update(); |
159 update(); |
159 emit contentsSizeChanged(); |
160 emit contentsSizeChanged(); |
160 } |
161 } |
161 |
162 |
168 void QDeclarativePaintedItem::setContentsScale(qreal scale) |
169 void QDeclarativePaintedItem::setContentsScale(qreal scale) |
169 { |
170 { |
170 Q_D(QDeclarativePaintedItem); |
171 Q_D(QDeclarativePaintedItem); |
171 if (d->contentsScale == scale) return; |
172 if (d->contentsScale == scale) return; |
172 d->contentsScale = scale; |
173 d->contentsScale = scale; |
173 setImplicitWidth(d->contentsSize.width()*scale); |
|
174 setImplicitHeight(d->contentsSize.height()*scale); |
|
175 clearCache(); |
174 clearCache(); |
176 update(); |
175 update(); |
177 emit contentsScaleChanged(); |
176 emit contentsScaleChanged(); |
178 } |
177 } |
179 |
178 |
230 return; |
229 return; |
231 d->cachefrozen = frozen; |
230 d->cachefrozen = frozen; |
232 // XXX clear cache? |
231 // XXX clear cache? |
233 } |
232 } |
234 |
233 |
|
234 QRectF QDeclarativePaintedItem::boundingRect() const |
|
235 { |
|
236 Q_D(const QDeclarativePaintedItem); |
|
237 qreal w = d->mWidth; |
|
238 QSizeF sz = d->contentsSize * d->contentsScale; |
|
239 if (w < sz.width()) |
|
240 w = sz.width(); |
|
241 qreal h = d->mHeight; |
|
242 if (h < sz.height()) |
|
243 h = sz.height(); |
|
244 return QRectF(0.0,0.0,w,h); |
|
245 } |
|
246 |
235 /*! |
247 /*! |
236 \internal |
248 \internal |
237 */ |
249 */ |
238 void QDeclarativePaintedItem::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *) |
250 void QDeclarativePaintedItem::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *) |
239 { |
251 { |
240 Q_D(QDeclarativePaintedItem); |
252 Q_D(QDeclarativePaintedItem); |
241 const QRect content(0,0,qCeil(d->contentsSize.width()*d->contentsScale), |
253 const QRect content = boundingRect().toRect(); |
242 qCeil(d->contentsSize.height()*d->contentsScale)); |
|
243 if (content.width() <= 0 || content.height() <= 0) |
254 if (content.width() <= 0 || content.height() <= 0) |
244 return; |
255 return; |
245 |
256 |
246 ++inpaint; |
257 ++inpaint; |
247 |
258 |
276 QRect area = d->imagecache[i]->area; |
287 QRect area = d->imagecache[i]->area; |
277 if (topaint.contains(area)) { |
288 if (topaint.contains(area)) { |
278 QRectF target(area.x(), area.y(), area.width(), area.height()); |
289 QRectF target(area.x(), area.y(), area.width(), area.height()); |
279 if (!d->cachefrozen) { |
290 if (!d->cachefrozen) { |
280 if (!d->imagecache[i]->dirty.isNull() && topaint.contains(d->imagecache[i]->dirty)) { |
291 if (!d->imagecache[i]->dirty.isNull() && topaint.contains(d->imagecache[i]->dirty)) { |
|
292 #ifdef Q_WS_MAC |
|
293 bool oldSmooth = qt_applefontsmoothing_enabled; |
|
294 qt_applefontsmoothing_enabled = false; |
|
295 #endif |
281 QPainter qp(&d->imagecache[i]->image); |
296 QPainter qp(&d->imagecache[i]->image); |
|
297 #ifdef Q_WS_MAC |
|
298 qt_applefontsmoothing_enabled = oldSmooth; |
|
299 #endif |
282 qp.setRenderHints(QPainter::HighQualityAntialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform, d->smoothCache); |
300 qp.setRenderHints(QPainter::HighQualityAntialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform, d->smoothCache); |
283 qp.translate(-area.x(), -area.y()); |
301 qp.translate(-area.x(), -area.y()); |
284 qp.scale(d->contentsScale,d->contentsScale); |
302 qp.scale(d->contentsScale,d->contentsScale); |
285 QRect clip = d->imagecache[i]->dirty; |
303 QRect clip = d->imagecache[i]->dirty; |
286 QRect sclip(qFloor(clip.x()/d->contentsScale), |
304 QRect sclip(qFloor(clip.x()/d->contentsScale), |
338 const QRect &r = rects.at(i); |
356 const QRect &r = rects.at(i); |
339 QPixmap img(r.size()); |
357 QPixmap img(r.size()); |
340 if (d->fillColor.isValid()) |
358 if (d->fillColor.isValid()) |
341 img.fill(d->fillColor); |
359 img.fill(d->fillColor); |
342 { |
360 { |
|
361 #ifdef Q_WS_MAC |
|
362 bool oldSmooth = qt_applefontsmoothing_enabled; |
|
363 qt_applefontsmoothing_enabled = false; |
|
364 #endif |
343 QPainter qp(&img); |
365 QPainter qp(&img); |
|
366 #ifdef Q_WS_MAC |
|
367 qt_applefontsmoothing_enabled = oldSmooth; |
|
368 #endif |
344 qp.setRenderHints(QPainter::HighQualityAntialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform, d->smoothCache); |
369 qp.setRenderHints(QPainter::HighQualityAntialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform, d->smoothCache); |
345 |
370 |
346 qp.translate(-r.x(),-r.y()); |
371 qp.translate(-r.x(),-r.y()); |
347 qp.scale(d->contentsScale,d->contentsScale); |
372 qp.scale(d->contentsScale,d->contentsScale); |
348 QRect sclip(qFloor(r.x()/d->contentsScale), |
373 QRect sclip(qFloor(r.x()/d->contentsScale), |