diff options
author | Aaron Kennedy <aaron.kennedy@nokia.com> | 2009-06-01 04:06:39 (GMT) |
---|---|---|
committer | Aaron Kennedy <aaron.kennedy@nokia.com> | 2009-06-01 04:06:39 (GMT) |
commit | 111c9143dc34be69c503a90bf9d6f6e5f5f67041 (patch) | |
tree | d196c26b30a06efa46d650c7094dc73c873aea98 /src/declarative/fx | |
parent | 596d9378943755bc63b486919b5616132efa7ab3 (diff) | |
parent | b9f484ae5d415d95df897e18059c054527111374 (diff) | |
download | Qt-111c9143dc34be69c503a90bf9d6f6e5f5f67041.zip Qt-111c9143dc34be69c503a90bf9d6f6e5f5f67041.tar.gz Qt-111c9143dc34be69c503a90bf9d6f6e5f5f67041.tar.bz2 |
Merge branch 'kinetic-declarativeui' of git@scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
Diffstat (limited to 'src/declarative/fx')
-rw-r--r-- | src/declarative/fx/qfxblendedimage.cpp | 8 | ||||
-rw-r--r-- | src/declarative/fx/qfxblendedimage.h | 4 | ||||
-rw-r--r-- | src/declarative/fx/qfxhighlightfilter.cpp | 4 | ||||
-rw-r--r-- | src/declarative/fx/qfximage.cpp | 39 | ||||
-rw-r--r-- | src/declarative/fx/qfximage_p.h | 2 | ||||
-rw-r--r-- | src/declarative/fx/qfxpainteditem.cpp | 16 | ||||
-rw-r--r-- | src/declarative/fx/qfxpainteditem_p.h | 2 | ||||
-rw-r--r-- | src/declarative/fx/qfxparticles.cpp | 8 | ||||
-rw-r--r-- | src/declarative/fx/qfxpixmap.cpp | 220 | ||||
-rw-r--r-- | src/declarative/fx/qfxpixmap.h | 8 | ||||
-rw-r--r-- | src/declarative/fx/qfxrect.cpp | 80 | ||||
-rw-r--r-- | src/declarative/fx/qfxrect.h | 18 | ||||
-rw-r--r-- | src/declarative/fx/qfxrect_p.h | 2 | ||||
-rw-r--r-- | src/declarative/fx/qfxscalegrid.h | 1 | ||||
-rw-r--r-- | src/declarative/fx/qfxtext.cpp | 56 | ||||
-rw-r--r-- | src/declarative/fx/qfxtext_p.h | 8 | ||||
-rw-r--r-- | src/declarative/fx/qfxtextedit.cpp | 36 | ||||
-rw-r--r-- | src/declarative/fx/qfxtextedit.h | 5 | ||||
-rw-r--r-- | src/declarative/fx/qfxtextedit_p.h | 7 | ||||
-rw-r--r-- | src/declarative/fx/qfxwebview.cpp | 2 |
20 files changed, 258 insertions, 268 deletions
diff --git a/src/declarative/fx/qfxblendedimage.cpp b/src/declarative/fx/qfxblendedimage.cpp index 73eb3c4..4c6eb58 100644 --- a/src/declarative/fx/qfxblendedimage.cpp +++ b/src/declarative/fx/qfxblendedimage.cpp @@ -192,9 +192,9 @@ void QFxBlendedImage::paintContents(QPainter &p) } if (_blend < 0.75) - p.drawImage(0, 0, primPix); + p.drawPixmap(0, 0, primPix); else - p.drawImage(0, 0, secPix); + p.drawPixmap(0, 0, secPix); if (_smooth) { p.restore(); @@ -212,8 +212,8 @@ void QFxBlendedImage::paintGLContents(GLPainter &p) if (dirty) { prim.clear(); sec.clear(); - prim.setImage(primPix); - sec.setImage(secPix); + prim.setImage(primPix.toImage()); + sec.setImage(secPix.toImage()); dirty = false; } diff --git a/src/declarative/fx/qfxblendedimage.h b/src/declarative/fx/qfxblendedimage.h index 4e6204d..baf4b64 100644 --- a/src/declarative/fx/qfxblendedimage.h +++ b/src/declarative/fx/qfxblendedimage.h @@ -99,8 +99,8 @@ private: GLTexture prim; GLTexture sec; #endif - QFxPixmap primPix; - QFxPixmap secPix; + QPixmap primPix; + QPixmap secPix; }; QML_DECLARE_TYPE(QFxBlendedImage) diff --git a/src/declarative/fx/qfxhighlightfilter.cpp b/src/declarative/fx/qfxhighlightfilter.cpp index 9807e21..6bf3148 100644 --- a/src/declarative/fx/qfxhighlightfilter.cpp +++ b/src/declarative/fx/qfxhighlightfilter.cpp @@ -135,10 +135,10 @@ QString QFxHighlightFilter::source() const void QFxHighlightFilter::imageLoaded() { - QImage img = QFxPixmap(d->url); + QPixmap img = QFxPixmap(d->url); #if defined(QFX_RENDER_OPENGL2) if (!img.isNull()) - d->tex.setImage(img); + d->tex.setImage(img.toImage()); #endif emit sourceChanged(d->source); update(); diff --git a/src/declarative/fx/qfximage.cpp b/src/declarative/fx/qfximage.cpp index 55aecd7..22e5d97 100644 --- a/src/declarative/fx/qfximage.cpp +++ b/src/declarative/fx/qfximage.cpp @@ -141,16 +141,15 @@ QFxImage::~QFxImage() QPixmap QFxImage::pixmap() const { Q_D(const QFxImage); - return d->_pix.pixmap(); + return d->_pix; } void QFxImage::setPixmap(const QPixmap &pix) { Q_D(QFxImage); d->url = QUrl(); - d->_pix.setPixmap(pix); + d->_pix = pix; d->_opaque=false; - d->_pix.setOpaque(false); setImplicitWidth(d->_pix.width()); setImplicitHeight(d->_pix.height()); @@ -255,7 +254,6 @@ void QFxImage::setOpaque(bool o) if (o == d->_opaque) return; d->_opaque = o; - d->_pix.setOpaque(o); update(); } @@ -326,21 +324,21 @@ void QFxImage::paintContents(QPainter &p) if (d->_smooth) p.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform, d->_smooth); - QSimpleCanvasConfig::Image pix = d->_pix; + QPixmap pix = d->_pix; if (d->_tiled) { p.save(); p.setClipRect(0, 0, width(), height(), Qt::IntersectClip); QRect me = QRect(0, 0, width(), height()); - int pw = d->_pix.width(); - int ph = d->_pix.height(); + int pw = pix.width(); + int ph = pix.height(); int yy = 0; while(yy < height()) { int xx = 0; while(xx < width()) { - p.drawImage(xx, yy, d->_pix); + p.drawPixmap(xx, yy, pix); xx += pw; } yy += ph; @@ -354,10 +352,10 @@ void QFxImage::paintContents(QPainter &p) height() / qreal(pix.height())); QTransform old = p.transform(); p.setWorldTransform(scale * old); - p.drawImage(0, 0, pix); + p.drawPixmap(0, 0, pix); p.setWorldTransform(old); } else { - p.drawImage(0, 0, pix); + p.drawPixmap(0, 0, pix); } } else { int sgl = d->_scaleGrid->left(); @@ -377,40 +375,40 @@ void QFxImage::paintContents(QPainter &p) // Upper left if (sgt && sgl) - p.drawImage(QRect(0, 0, sgl, sgt), pix, QRect(0, 0, sgl, sgt)); + p.drawPixmap(QRect(0, 0, sgl, sgt), pix, QRect(0, 0, sgl, sgt)); // Upper middle if (pix.width() - xSide && sgt) - p.drawImage(QRect(sgl, 0, w - xSide, sgt), pix, + p.drawPixmap(QRect(sgl, 0, w - xSide, sgt), pix, QRect(sgl, 0, pix.width() - xSide, sgt)); // Upper right if (sgt && pix.width() - sgr) - p.drawImage(QPoint(w-sgr, 0), pix, + p.drawPixmap(QPoint(w-sgr, 0), pix, QRect(pix.width()-sgr, 0, sgr, sgt)); // Middle left if (sgl && pix.height() - ySide) - p.drawImage(QRect(0, sgt, sgl, h - ySide), pix, + p.drawPixmap(QRect(0, sgt, sgl, h - ySide), pix, QRect(0, sgt, sgl, pix.height() - ySide)); // Middle if (pix.width() - xSide && pix.height() - ySide) - p.drawImage(QRect(sgl, sgt, w - xSide, h - ySide), + p.drawPixmap(QRect(sgl, sgt, w - xSide, h - ySide), pix, QRect(sgl, sgt, pix.width() - xSide, pix.height() - ySide)); // Middle right if (sgr && pix.height() - ySide) - p.drawImage(QRect(w-sgr, sgt, sgr, h - ySide), pix, + p.drawPixmap(QRect(w-sgr, sgt, sgr, h - ySide), pix, QRect(pix.width()-sgr, sgt, sgr, pix.height() - ySide)); // Lower left if (sgl && sgr) - p.drawImage(QPoint(0, h - sgb), pix, + p.drawPixmap(QPoint(0, h - sgb), pix, QRect(0, pix.height() - sgb, sgl, sgb)); // Lower Middle if (pix.width() - xSide && sgb) - p.drawImage(QRect(sgl, h - sgb, w - xSide, sgb), pix, + p.drawPixmap(QRect(sgl, h - sgb, w - xSide, sgb), pix, QRect(sgl, pix.height() - sgb, pix.width() - xSide, sgb)); // Lower Right if (sgr && sgb) - p.drawImage(QPoint(w-sgr, h - sgb), pix, + p.drawPixmap(QPoint(w-sgr, h - sgb), pix, QRect(pix.width()-sgr, pix.height() - sgb, sgr, sgb)); } @@ -461,7 +459,7 @@ uint QFxImage::glSimpleItemData(float *vertices, float *texVertices, void QFxImagePrivate::checkDirty() { if (_texDirty && !_pix.isNull()) { - _tex.setImage(_pix); + _tex.setImage(_pix.toImage()); _tex.setHorizontalWrap(GLTexture::Repeat); _tex.setVerticalWrap(GLTexture::Repeat); } @@ -945,7 +943,6 @@ void QFxImage::requestFinished() d->status = Error; } d->_pix = QFxPixmap(d->url); - d->_pix.setOpaque(d->_opaque); setOptions(QFxImage::SimpleItem, true); } setImplicitWidth(d->_pix.width()); diff --git a/src/declarative/fx/qfximage_p.h b/src/declarative/fx/qfximage_p.h index 8227ce4..b3cccf9 100644 --- a/src/declarative/fx/qfximage_p.h +++ b/src/declarative/fx/qfximage_p.h @@ -95,7 +95,7 @@ public: } QFxScaleGrid *_scaleGrid; - QFxPixmap _pix; + QPixmap _pix; bool _tiled : 1; bool _smooth : 1; bool _opaque : 1; diff --git a/src/declarative/fx/qfxpainteditem.cpp b/src/declarative/fx/qfxpainteditem.cpp index 4d2e327..44adba7 100644 --- a/src/declarative/fx/qfxpainteditem.cpp +++ b/src/declarative/fx/qfxpainteditem.cpp @@ -271,7 +271,7 @@ void QFxPaintedItem::paintGLContents(GLPainter &p) QRect area = d->imagecache[i]->area; if (topaint.contains(area)) { QRectF target(area.x(), area.y(), area.width(), area.height()); - p.drawImage(target.toRect(), d->imagecache[i]->image); + p.drawPixmap(target.toRect(), d->imagecache[i]->image); topaint -= area; d->imagecache[i]->age=0; } else { @@ -303,12 +303,8 @@ void QFxPaintedItem::paintGLContents(GLPainter &p) const QVector<QRect> rects = bigger.rects(); for (int i = 0; i < rects.count(); ++i) { const QRect &r = rects.at(i); -#if defined(QFX_RENDER_QPAINTER) - QImage img(r.size(),QImage::Format_ARGB32_Premultiplied); -#else - QImage img(r.size(),QImage::Format_ARGB32); -#endif - img.fill(0); + QPixmap img(r.size()); + img.fill(Qt::transparent); { QPainter qp(&img); qp.translate(-r.x(),-r.y()); @@ -317,13 +313,13 @@ void QFxPaintedItem::paintGLContents(GLPainter &p) QFxPaintedItemPrivate::ImageCacheItem *newitem = new QFxPaintedItemPrivate::ImageCacheItem; newitem->area = r; #if defined(QFX_RENDER_QPAINTER) - newitem->image = QSimpleCanvasConfig::Image(QSimpleCanvasConfig::toImage(img)); + newitem->image = img; #else - newitem->image.setImage(img); + newitem->image.setImage(img.toImage()); #endif d->imagecache.append(newitem); QRectF target(r.x(), r.y(), r.width(), r.height()); - p.drawImage(target.toRect(), newitem->image); + p.drawPixmap(target.toRect(), newitem->image); } } #if defined(QFX_RENDER_OPENGL2) diff --git a/src/declarative/fx/qfxpainteditem_p.h b/src/declarative/fx/qfxpainteditem_p.h index 5d5da6b..d8d1a2a 100644 --- a/src/declarative/fx/qfxpainteditem_p.h +++ b/src/declarative/fx/qfxpainteditem_p.h @@ -78,7 +78,7 @@ public: int age; QRect area; #if defined(QFX_RENDER_QPAINTER) - QSimpleCanvasConfig::Image image; + QPixmap image; #else GLTexture image; #endif diff --git a/src/declarative/fx/qfxparticles.cpp b/src/declarative/fx/qfxparticles.cpp index e9f38b0..41fb5bc 100644 --- a/src/declarative/fx/qfxparticles.cpp +++ b/src/declarative/fx/qfxparticles.cpp @@ -397,7 +397,7 @@ public: QString source; QUrl url; - QSimpleCanvasConfig::Image image; + QPixmap image; int count; int lifeSpan; int lifeSpanDev; @@ -671,7 +671,7 @@ void QFxParticles::setSource(const QString &name) if (name.isEmpty()) { d->source = name; d->url = QUrl(); - d->image = QSimpleCanvasConfig::Image(); + d->image = QPixmap(); #if defined(QFX_RENDER_OPENGL) d->texDirty = true; d->tex.clear(); @@ -1124,7 +1124,7 @@ void QFxParticlesPainter::paintContents(QPainter &p) for (int i = 0; i < d->particles.count(); ++i) { const QFxParticle &particle = d->particles.at(i); p.setOpacity(particle.opacity); - p.drawImage(particle.x - myX, particle.y - myY, d->image); + p.drawPixmap(particle.x - myX, particle.y - myY, d->image); } update();//Should I need this? (GV does) } @@ -1143,7 +1143,7 @@ void QFxParticlesPainter::paintGLContents(GLPainter &p) updateSize(); if (d->texDirty && !d->image.isNull()) { - d->tex.setImage(d->image); + d->tex.setImage(d->image.toImage()); d->tex.setHorizontalWrap(GLTexture::Repeat); d->tex.setVerticalWrap(GLTexture::Repeat); } diff --git a/src/declarative/fx/qfxpixmap.cpp b/src/declarative/fx/qfxpixmap.cpp index 0e5a10f..0ea94f5 100644 --- a/src/declarative/fx/qfxpixmap.cpp +++ b/src/declarative/fx/qfxpixmap.cpp @@ -42,44 +42,49 @@ #include "qfxpixmap.h" #include <QHash> #include <QNetworkReply> +#include <QPixmapCache> #include <qfxperf.h> #include <QtDeclarative/qmlengine.h> #include <QFile> - QT_BEGIN_NAMESPACE -class QFxPixmapCacheItem; -typedef QHash<QString, QFxPixmapCacheItem *> QFxPixmapCache; -static QFxPixmapCache qfxPixmapCache; +class QSharedNetworkReply; +typedef QHash<QString, QSharedNetworkReply *> QFxSharedNetworkReplyHash; +static QFxSharedNetworkReplyHash qfxActiveNetworkReplies; -class QFxPixmapCacheItem +class QSharedNetworkReply { public: - QFxPixmapCacheItem() : reply(0), refCount(1) {} - QString key; + QSharedNetworkReply(QNetworkReply *r) : reply(r), refCount(1) {} + ~QSharedNetworkReply() + { + reply->deleteLater(); + } QNetworkReply *reply; -#if defined(QFX_RENDER_OPENGL) - QImage image; -#else - QImage image; - QImage opaqueImage; -#endif int refCount; - void addRef() { ++refCount; } - void release() { Q_ASSERT(refCount > 0); --refCount; if (refCount == 0) { qfxPixmapCache.remove(key); delete this; } } + void addRef() + { + ++refCount; + } + void release() + { + Q_ASSERT(refCount > 0); + --refCount; + if (refCount == 0) { + QString key = reply->url().toString(); + qfxActiveNetworkReplies.remove(key); + delete this; + } + } }; -static QFxPixmapCacheItem qfxPixmapCacheDummyItem; - class QFxPixmapPrivate { public: - QFxPixmapPrivate() - : opaque(false), pixmap(&qfxPixmapCacheDummyItem) { pixmap->addRef(); } + QFxPixmapPrivate() {} - bool opaque; - QFxPixmapCacheItem *pixmap; + QPixmap pixmap; }; /*! @@ -102,131 +107,71 @@ QFxPixmap::QFxPixmap(const QUrl &url) #ifdef Q_ENABLE_PERFORMANCE_LOG QFxPerfTimer<QFxPerf::PixmapLoad> perf; #endif - QString key = url.toString(); - QFxPixmapCache::Iterator iter = qfxPixmapCache.find(key); - if (iter == qfxPixmapCache.end()) { - qWarning() << "QFxPixmap: URL not loaded" << url; - } else { - QNetworkReply *reply = (*iter)->reply; - if (reply) { - if (reply->error()) { - qWarning() << "Error loading" << url << reply->errorString(); +#ifndef QT_NO_LOCALFILE_OPTIMIZED_QML + if (url.scheme()==QLatin1String("file")) { + d->pixmap.load(url.toLocalFile()); + } else +#endif + { + QString key = url.toString(); + if (!QPixmapCache::find(key,&d->pixmap)) { + QFxSharedNetworkReplyHash::Iterator iter = qfxActiveNetworkReplies.find(key); + if (iter == qfxActiveNetworkReplies.end()) { + // API usage error + qWarning() << "QFxPixmap: URL not loaded" << url; } else { - (*iter)->image.load(reply, 0); + if ((*iter)->reply->error()) { + qWarning() << "Network error loading" << url << (*iter)->reply->errorString(); + } else { + QImage img; + if (img.load((*iter)->reply, 0)) { + d->pixmap = QPixmap::fromImage(img); + QPixmapCache::insert(key, d->pixmap); + } else { + qWarning() << "Format error loading" << url; + } + } + (*iter)->release(); } - reply->deleteLater(); - (*iter)->reply = 0; } - (*iter)->addRef(); } - - d->pixmap = *iter; } QFxPixmap::QFxPixmap(const QFxPixmap &o) : d(new QFxPixmapPrivate) { - d->opaque = o.d->opaque; - o.d->pixmap->addRef(); - d->pixmap->release(); d->pixmap = o.d->pixmap; } QFxPixmap::~QFxPixmap() { - d->pixmap->release(); delete d; } QFxPixmap &QFxPixmap::operator=(const QFxPixmap &o) { - d->opaque = o.d->opaque; - o.d->pixmap->addRef(); - d->pixmap->release(); d->pixmap = o.d->pixmap; return *this; } bool QFxPixmap::isNull() const { - return d->pixmap->image.isNull(); -} - -bool QFxPixmap::opaque() const -{ - return d->opaque; -} - -void QFxPixmap::setOpaque(bool o) -{ - d->opaque = o; + return d->pixmap.isNull(); } int QFxPixmap::width() const { - return d->pixmap->image.width(); + return d->pixmap.width(); } int QFxPixmap::height() const { - return d->pixmap->image.height(); -} - -QPixmap QFxPixmap::pixmap() const -{ - return QPixmap::fromImage(d->pixmap->image); + return d->pixmap.height(); } -void QFxPixmap::setPixmap(const QPixmap &pix) +QFxPixmap::operator const QPixmap &() const { - QFxPixmapCache::Iterator iter = qfxPixmapCache.find(QString::number(pix.cacheKey())); - if (iter == qfxPixmapCache.end()) { - QFxPixmapCacheItem *item = new QFxPixmapCacheItem; - item->key = QString::number(pix.cacheKey()); - if (d->pixmap) - d->pixmap->release(); - d->pixmap = item; - d->pixmap->image = pix.toImage(); - qfxPixmapCache.insert(QString::number(pix.cacheKey()), item); - } else { - (*iter)->addRef(); - d->pixmap = *iter; - } - -#if 0 - int size = 0; - for (QFxPixmapCache::Iterator iter = qfxPixmapCache.begin(); iter != qfxPixmapCache.end(); ++iter) { - size += (*iter)->image.width() * (*iter)->image.height(); - } - qWarning() << qfxPixmapCache.count() << size; -#endif -} - -QFxPixmap::operator const QSimpleCanvasConfig::Image &() const -{ -#if defined(QFX_RENDER_OPENGL) - return d->pixmap->image; -#else - if (d->opaque) { - if (!d->pixmap->image.isNull() && d->pixmap->opaqueImage.isNull()) { -#ifdef Q_ENABLE_PERFORMANCE_LOG - QFxPerfTimer<QFxPerf::PixmapLoad> perf; -#endif - d->pixmap->opaqueImage = d->pixmap->image.convertToFormat(QPixmap::defaultDepth() == 16 ? - QImage::Format_RGB16 : - QImage::Format_RGB32); - } - return d->pixmap->opaqueImage; - } else { - if (!d->pixmap->image.isNull() && d->pixmap->image.format() != QImage::Format_ARGB32_Premultiplied) { -#ifdef Q_ENABLE_PERFORMANCE_LOG - QFxPerfTimer<QFxPerf::PixmapLoad> perf; -#endif - d->pixmap->image = d->pixmap->image.convertToFormat(QImage::Format_ARGB32_Premultiplied); - } - return d->pixmap->image; - } -#endif + return d->pixmap; } /*! @@ -239,37 +184,33 @@ QFxPixmap::operator const QSimpleCanvasConfig::Image &() const */ QNetworkReply *QFxPixmap::get(QmlEngine *engine, const QUrl& url, QObject* obj, const char* slot) { - QString key = url.toString(); - QFxPixmapCache::Iterator iter = qfxPixmapCache.find(key); - if (iter == qfxPixmapCache.end()) { - QFxPixmapCacheItem *item = new QFxPixmapCacheItem; - item->addRef(); // XXX - will never get deleted. Need to revisit caching - item->key = key; #ifndef QT_NO_LOCALFILE_OPTIMIZED_QML - if (url.scheme()==QLatin1String("file")) { - item->image.load(url.toLocalFile(), 0); - } else -#endif - { - QNetworkRequest req(url); - req.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache); - item->reply = engine->networkAccessManager()->get(req); - } - iter = qfxPixmapCache.insert(item->key, item); - } else { - (*iter)->addRef(); + if (url.scheme()==QLatin1String("file")) { + QObject dummy; + QObject::connect(&dummy, SIGNAL(destroyed()), obj, slot); + return 0; } - if ((*iter)->reply) { - // still loading - QObject::connect((*iter)->reply, SIGNAL(finished()), obj, slot); - return (*iter)->reply; - } else { - // already loaded +#endif + + QString key = url.toString(); + if (QPixmapCache::find(key,0)) { QObject dummy; QObject::connect(&dummy, SIGNAL(destroyed()), obj, slot); + return 0; + } + + QFxSharedNetworkReplyHash::Iterator iter = qfxActiveNetworkReplies.find(key); + if (iter == qfxActiveNetworkReplies.end()) { + QNetworkRequest req(url); + req.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache); + QSharedNetworkReply *item = new QSharedNetworkReply(engine->networkAccessManager()->get(req)); + iter = qfxActiveNetworkReplies.insert(key, item); + } else { + (*iter)->addRef(); } - return 0; + QObject::connect((*iter)->reply, SIGNAL(finished()), obj, slot); + return (*iter)->reply; } /*! @@ -282,12 +223,11 @@ QNetworkReply *QFxPixmap::get(QmlEngine *engine, const QUrl& url, QObject* obj, void QFxPixmap::cancelGet(const QUrl& url, QObject* obj) { QString key = url.toString(); - QFxPixmapCache::Iterator iter = qfxPixmapCache.find(key); - if (iter == qfxPixmapCache.end()) + QFxSharedNetworkReplyHash::Iterator iter = qfxActiveNetworkReplies.find(key); + if (iter == qfxActiveNetworkReplies.end()) return; - if ((*iter)->reply) - QObject::disconnect((*iter)->reply, 0, obj, 0); - // XXX - loading not cancelled. Need to revisit caching + QObject::disconnect((*iter)->reply, 0, obj, 0); + (*iter)->release(); } QT_END_NAMESPACE diff --git a/src/declarative/fx/qfxpixmap.h b/src/declarative/fx/qfxpixmap.h index fd56ee4..ae693c1 100644 --- a/src/declarative/fx/qfxpixmap.h +++ b/src/declarative/fx/qfxpixmap.h @@ -71,16 +71,10 @@ public: bool isNull() const; - bool opaque() const; - void setOpaque(bool); - int width() const; int height() const; - QPixmap pixmap() const; - void setPixmap(const QPixmap &pix); - - operator const QSimpleCanvasConfig::Image &() const; + operator const QPixmap &() const; private: QFxPixmapPrivate *d; diff --git a/src/declarative/fx/qfxrect.cpp b/src/declarative/fx/qfxrect.cpp index 4271022..c156753 100644 --- a/src/declarative/fx/qfxrect.cpp +++ b/src/declarative/fx/qfxrect.cpp @@ -133,6 +133,12 @@ void QFxPen::setWidth(int w) Sets a \e color at a \e position in a gradient. */ +void QFxGradientStop::updateGradient() +{ + if (QFxGradient *grad = qobject_cast<QFxGradient*>(parent())) + grad->doUpdate(); +} + /*! \qmlclass Gradient QFxGradient \brief The Gradient item defines a gradient fill. @@ -171,6 +177,13 @@ const QGradient *QFxGradient::gradient() const return m_gradient; } +void QFxGradient::doUpdate() +{ + delete m_gradient; + m_gradient = 0; + emit updated(); +} + QML_DEFINE_TYPE(QFxRect,Rect) /*! @@ -240,7 +253,7 @@ void QFxRect::doUpdate() { #if defined(QFX_RENDER_QPAINTER) Q_D(QFxRect); - d->_rectImage = QSimpleCanvasConfig::Image(); + d->_rectImage = QPixmap(); #endif #if defined(QFX_RENDER_OPENGL) Q_D(QFxRect); @@ -308,7 +321,14 @@ QFxGradient *QFxRect::gradient() const void QFxRect::setGradient(QFxGradient *gradient) { Q_D(QFxRect); + if (d->gradient == gradient) + return; + if (d->gradient) + disconnect(d->gradient, SIGNAL(updated()), this, SLOT(doUpdate())); d->gradient = gradient; + if (d->gradient) + connect(d->gradient, SIGNAL(updated()), this, SLOT(doUpdate())); + update(); } @@ -339,7 +359,7 @@ void QFxRect::setRadius(qreal radius) d->_radius = radius; #if defined(QFX_RENDER_QPAINTER) - d->_rectImage = QSimpleCanvasConfig::Image(); + d->_rectImage = QPixmap(); #elif defined(QFX_RENDER_OPENGL) d->_rectTexture.clear(); #endif @@ -385,7 +405,7 @@ void QFxRect::setColor(const QColor &c) d->_color = c; #if defined(QFX_RENDER_QPAINTER) - d->_rectImage = QSimpleCanvasConfig::Image(); + d->_rectImage = QPixmap(); #endif #if defined(QFX_RENDER_OPENGL) d->_rectTexture.clear(); @@ -463,8 +483,8 @@ void QFxRect::generateRoundedRect() Q_D(QFxRect); if (d->_rectImage.isNull()) { const int pw = d->_pen && d->_pen->isValid() ? d->_pen->width() : 0; - d->_rectImage = QImage(d->_radius*2 + 3 + pw*2, d->_radius*2 + 3 + pw*2, QImage::Format_ARGB32_Premultiplied); - d->_rectImage.fill(0); + d->_rectImage = QPixmap(d->_radius*2 + 3 + pw*2, d->_radius*2 + 3 + pw*2); + d->_rectImage.fill(Qt::transparent); QPainter p(&(d->_rectImage)); p.setRenderHint(QPainter::Antialiasing); if (d->_pen && d->_pen->isValid()) { @@ -483,8 +503,8 @@ void QFxRect::generateBorderedRect() Q_D(QFxRect); if (d->_rectImage.isNull()) { const int pw = d->_pen && d->_pen->isValid() ? d->_pen->width() : 0; - d->_rectImage = QImage(d->pen()->width()*2 + 3 + pw*2, d->pen()->width()*2 + 3 + pw*2, QImage::Format_ARGB32_Premultiplied); - d->_rectImage.fill(0); + d->_rectImage = QPixmap(d->pen()->width()*2 + 3 + pw*2, d->pen()->width()*2 + 3 + pw*2); + d->_rectImage.fill(Qt::transparent); QPainter p(&(d->_rectImage)); p.setRenderHint(QPainter::Antialiasing); if (d->_pen && d->_pen->isValid()) { @@ -607,39 +627,39 @@ void QFxRect::drawRect(QPainter &p) } // Upper left - p.drawImage(QRect(-pw/2, -pw/2, xOffset, yOffset), d->_rectImage, QRect(0, 0, xOffset, yOffset)); + p.drawPixmap(QRect(-pw/2, -pw/2, xOffset, yOffset), d->_rectImage, QRect(0, 0, xOffset, yOffset)); // Upper middle if (xMiddles) - p.drawImage(QRect(xOffset-pw/2, -pw/2, width() - xSide + pw, yOffset), d->_rectImage, + p.drawPixmap(QRect(xOffset-pw/2, -pw/2, width() - xSide + pw, yOffset), d->_rectImage, QRect(d->_rectImage.width()/2, 0, 1, yOffset)); // Upper right - p.drawImage(QPoint(width()-xOffset+pw/2, -pw/2), d->_rectImage, + p.drawPixmap(QPoint(width()-xOffset+pw/2, -pw/2), d->_rectImage, QRect(d->_rectImage.width()-xOffset, 0, xOffset, yOffset)); // Middle left if (yMiddles) - p.drawImage(QRect(-pw/2, yOffset-pw/2, xOffset, height() - ySide + pw), d->_rectImage, + p.drawPixmap(QRect(-pw/2, yOffset-pw/2, xOffset, height() - ySide + pw), d->_rectImage, QRect(0, d->_rectImage.height()/2, xOffset, 1)); // Middle if (xMiddles && yMiddles) // XXX paint errors in animation example //p.fillRect(xOffset-pw/2, yOffset-pw/2, width() - xSide + pw, height() - ySide + pw, d->getColor()); - p.drawImage(QRect(xOffset-pw/2, yOffset-pw/2, width() - xSide + pw, height() - ySide + pw), d->_rectImage, + p.drawPixmap(QRect(xOffset-pw/2, yOffset-pw/2, width() - xSide + pw, height() - ySide + pw), d->_rectImage, QRect(d->_rectImage.width()/2, d->_rectImage.height()/2, 1, 1)); // Middle right if (yMiddles) - p.drawImage(QRect(width()-xOffset+pw/2, yOffset-pw/2, xOffset, height() - ySide + pw), d->_rectImage, + p.drawPixmap(QRect(width()-xOffset+pw/2, yOffset-pw/2, xOffset, height() - ySide + pw), d->_rectImage, QRect(d->_rectImage.width()-xOffset, d->_rectImage.height()/2, xOffset, 1)); // Lower left - p.drawImage(QPoint(-pw/2, height() - yOffset + pw/2), d->_rectImage, QRect(0, d->_rectImage.height() - yOffset, xOffset, yOffset)); + p.drawPixmap(QPoint(-pw/2, height() - yOffset + pw/2), d->_rectImage, QRect(0, d->_rectImage.height() - yOffset, xOffset, yOffset)); // Lower Middle if (xMiddles) - p.drawImage(QRect(xOffset-pw/2, height() - yOffset +pw/2, width() - xSide + pw, yOffset), d->_rectImage, + p.drawPixmap(QRect(xOffset-pw/2, height() - yOffset +pw/2, width() - xSide + pw, yOffset), d->_rectImage, QRect(d->_rectImage.width()/2, d->_rectImage.height() - yOffset, 1, yOffset)); // Lower Right - p.drawImage(QPoint(width()-xOffset+pw/2, height() - yOffset+pw/2), d->_rectImage, + p.drawPixmap(QPoint(width()-xOffset+pw/2, height() - yOffset+pw/2), d->_rectImage, QRect(d->_rectImage.width()-xOffset, d->_rectImage.height() - yOffset, xOffset, yOffset)); } } @@ -652,7 +672,7 @@ void QFxRect::paintGLContents(GLPainter &p) { Q_D(QFxRect); if (d->_radius == 0 && (!d->_pen || !d->_pen->isValid())) { - if (d->_gradcolor.isValid()) { + if (d->gradient) { float widthV = width(); float heightV = height(); @@ -661,20 +681,16 @@ void QFxRect::paintGLContents(GLPainter &p) 0, 0, widthV, 0 }; - float r = d->_color.redF(); - float g = d->_color.greenF(); - float b = d->_color.blueF(); - float a = d->_color.alphaF() * p.activeOpacity; - - float r2 = d->_gradcolor.redF(); - float g2 = d->_gradcolor.greenF(); - float b2 = d->_gradcolor.blueF(); - float a2 = d->_gradcolor.alphaF() * p.activeOpacity; - - GLfloat colors[] = { r2, g2, b2, a2, - r2, g2, b2, a2, - r, g, b, a, - r, g, b, a }; + int count = d->gradient->stops()->size(); + GLfloat colors[count*8]; + for (int i = 0; i < count; i += 8) { + QFxGradientStop *g = d->gradient->stops()->at(i); + QColor c = g->color(); + colors[i] = c.redF(); colors[i+4] = colors[i]; + colors[i+1] = c.greenF(); colors[i+5] = colors[i+1]; + colors[i+2] = c.blueF(); colors[i+6] = colors[i+2]; + colors[i+3] = c.alphaF() * p.activeOpacity; colors[i+7] = colors[i+3]; + } ColorShader *shader = basicShaders()->color(); shader->enable(); @@ -682,7 +698,7 @@ void QFxRect::paintGLContents(GLPainter &p) shader->setAttributeArray(ColorShader::Vertices, vertices, 2); shader->setAttributeArray(ColorShader::Colors, colors, 4); - glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + glDrawArrays(GL_TRIANGLE_STRIP, 0, count*2); shader->disableAttributeArray(ColorShader::Vertices); shader->disableAttributeArray(ColorShader::Colors); } else { diff --git a/src/declarative/fx/qfxrect.h b/src/declarative/fx/qfxrect.h index 2c59914..c279a1c 100644 --- a/src/declarative/fx/qfxrect.h +++ b/src/declarative/fx/qfxrect.h @@ -90,10 +90,13 @@ public: QFxGradientStop(QObject *parent=0) : QObject(parent) {} qreal position() const { return m_position; } - void setPosition(qreal position) { m_position = position; } + void setPosition(qreal position) { m_position = position; updateGradient(); } QColor color() const { return m_color; } - void setColor(const QColor &color) { m_color = color; } + void setColor(const QColor &color) { m_color = color; updateGradient(); } + +private: + void updateGradient(); private: qreal m_position; @@ -109,16 +112,23 @@ class Q_DECLARATIVE_EXPORT QFxGradient : public QObject Q_CLASSINFO("DefaultProperty", "stops") public: - QFxGradient(QObject *parent=0) : QObject(parent), m_gradient(0), m_created(false) {} + QFxGradient(QObject *parent=0) : QObject(parent), m_gradient(0) {} + ~QFxGradient() { delete m_gradient; } QList<QFxGradientStop *> *stops() { return &m_stops; } const QGradient *gradient() const; +Q_SIGNALS: + void updated(); + +private: + void doUpdate(); + private: QList<QFxGradientStop *> m_stops; mutable QGradient *m_gradient; - mutable bool m_created; + friend class QFxGradientStop; }; QML_DECLARE_TYPE(QFxGradient) diff --git a/src/declarative/fx/qfxrect_p.h b/src/declarative/fx/qfxrect_p.h index 8faaa38..8cafcbb 100644 --- a/src/declarative/fx/qfxrect_p.h +++ b/src/declarative/fx/qfxrect_p.h @@ -100,7 +100,7 @@ public: QFxPen *_pen; qreal _radius; #if defined(QFX_RENDER_QPAINTER) - QSimpleCanvasConfig::Image _rectImage; + QPixmap _rectImage; #endif }; diff --git a/src/declarative/fx/qfxscalegrid.h b/src/declarative/fx/qfxscalegrid.h index 2a20de7..c59cb32 100644 --- a/src/declarative/fx/qfxscalegrid.h +++ b/src/declarative/fx/qfxscalegrid.h @@ -44,7 +44,6 @@ #include <QtCore/QString> #include <QtCore/QObject> -#include <QtGui/QImage> #include <QtDeclarative/qfxglobal.h> #include <QtDeclarative/qsimplecanvas.h> #include <QtDeclarative/qfxpixmap.h> diff --git a/src/declarative/fx/qfxtext.cpp b/src/declarative/fx/qfxtext.cpp index 94a1712..702ec81 100644 --- a/src/declarative/fx/qfxtext.cpp +++ b/src/declarative/fx/qfxtext.cpp @@ -525,42 +525,44 @@ QString QFxText::propertyInfo() const void QFxTextPrivate::drawOutline() { - QImage img = QImage(imgCache.size(), QImage::Format_ARGB32_Premultiplied); + QPixmap img = QPixmap(imgCache.size()); + img.fill(Qt::transparent); + QPainter ppm(&img); - img.fill(qRgba(0, 0, 0, 0)); QPoint pos(imgCache.rect().topLeft()); pos += QPoint(-1, 0); - ppm.drawImage(pos, imgStyleCache); + ppm.drawPixmap(pos, imgStyleCache); pos += QPoint(2, 0); - ppm.drawImage(pos, imgStyleCache); + ppm.drawPixmap(pos, imgStyleCache); pos += QPoint(-1, -1); - ppm.drawImage(pos, imgStyleCache); + ppm.drawPixmap(pos, imgStyleCache); pos += QPoint(0, 2); - ppm.drawImage(pos, imgStyleCache); + ppm.drawPixmap(pos, imgStyleCache); pos += QPoint(0, -1); - QPainter &p = ppm; - p.drawImage(pos, imgCache); + ppm.drawPixmap(pos, imgCache); + ppm.end(); - imgCache = QSimpleCanvasConfig::toImage(img); + imgCache = img; } void QFxTextPrivate::drawOutline(int yOffset) { - QImage img = QImage(imgCache.size(), QImage::Format_ARGB32_Premultiplied); + QPixmap img = QPixmap(imgCache.size()); + img.fill(Qt::transparent); + QPainter ppm(&img); - img.fill(qRgba(0, 0, 0, 0)); QPoint pos(imgCache.rect().topLeft()); pos += QPoint(0, yOffset); - ppm.drawImage(pos, imgStyleCache); + ppm.drawPixmap(pos, imgStyleCache); pos += QPoint(0, -yOffset); - QPainter &p = ppm; - p.drawImage(pos, imgCache); + ppm.drawPixmap(pos, imgCache); + ppm.end(); - imgCache = QSimpleCanvasConfig::toImage(img); + imgCache = img; } QSize QFxTextPrivate::setupTextLayout(QTextLayout *layout) @@ -600,7 +602,7 @@ QSize QFxTextPrivate::setupTextLayout(QTextLayout *layout) return QSize((int)widthUsed, height); } -QImage QFxTextPrivate::wrappedTextImage(bool drawStyle) +QPixmap QFxTextPrivate::wrappedTextImage(bool drawStyle) { //do layout QFont f; if (_font) f = _font->font(); @@ -620,8 +622,8 @@ QImage QFxTextPrivate::wrappedTextImage(bool drawStyle) } //paint text - QImage img(size, QImage::Format_ARGB32_Premultiplied); - img.fill(0); + QPixmap img(size); + img.fill(Qt::transparent); QPainter p(&img); if (drawStyle) { p.setPen(styleColor); @@ -633,13 +635,13 @@ QImage QFxTextPrivate::wrappedTextImage(bool drawStyle) return img; } -QImage QFxTextPrivate::richTextImage(bool drawStyle) +QPixmap QFxTextPrivate::richTextImage(bool drawStyle) { QSize size = doc->size().toSize(); //paint text - QImage img(size, QImage::Format_ARGB32_Premultiplied); - img.fill(0); + QPixmap img(size); + img.fill(Qt::transparent); QPainter p(&img); if (drawStyle) { @@ -667,14 +669,14 @@ void QFxTextPrivate::checkImgCache() bool empty = text.isEmpty(); if (empty) { - imgCache = QSimpleCanvasConfig::Image(); - imgStyleCache = QImage(); + imgCache = QPixmap(); + imgStyleCache = QPixmap(); } else if (richText) { - imgCache = QSimpleCanvasConfig::toImage(richTextImage(false)); + imgCache = richTextImage(false); if (style != QFxText::Normal) imgStyleCache = richTextImage(true); //### should use styleColor } else { - imgCache = QSimpleCanvasConfig::toImage(wrappedTextImage(false)); + imgCache = wrappedTextImage(false); if (style != QFxText::Normal) imgStyleCache = wrappedTextImage(true); //### should use styleColor } @@ -694,7 +696,7 @@ void QFxTextPrivate::checkImgCache() } #if defined(QFX_RENDER_OPENGL) - tex.setImage(imgCache); + tex.setImage(imgCache.toImage()); #endif imgDirty = false; @@ -745,7 +747,7 @@ void QFxText::paintContents(QPainter &p) p.save(); p.setClipRect(boundingRect()); } - p.drawImage(x, y, d->imgCache); + p.drawPixmap(x, y, d->imgCache); if (needClip) p.restore(); } diff --git a/src/declarative/fx/qfxtext_p.h b/src/declarative/fx/qfxtext_p.h index 8bb3142..dfaef63 100644 --- a/src/declarative/fx/qfxtext_p.h +++ b/src/declarative/fx/qfxtext_p.h @@ -94,8 +94,8 @@ public: void drawOutline(); void drawOutline(int yOffset); - QImage wrappedTextImage(bool drawStyle); - QImage richTextImage(bool drawStyle); + QPixmap wrappedTextImage(bool drawStyle); + QPixmap richTextImage(bool drawStyle); QSize setupTextLayout(QTextLayout *layout); QString text; @@ -118,8 +118,8 @@ public: #if defined(QFX_RENDER_OPENGL) GLTexture tex; #endif - QSimpleCanvasConfig::Image imgCache; - QImage imgStyleCache; + QPixmap imgCache; + QPixmap imgStyleCache; QFxText::HAlignment hAlign; QFxText::VAlignment vAlign; Qt::TextElideMode elideMode; diff --git a/src/declarative/fx/qfxtextedit.cpp b/src/declarative/fx/qfxtextedit.cpp index fc73ecd..c7a7700 100644 --- a/src/declarative/fx/qfxtextedit.cpp +++ b/src/declarative/fx/qfxtextedit.cpp @@ -49,6 +49,7 @@ #endif #include <qfxperf.h> +#include "qfxevents_p.h" #include <QTextLayout> #include <QTextLine> #include <QTextDocument> @@ -158,6 +159,8 @@ QString QFxTextEdit::text() const void QFxTextEdit::setText(const QString &text) { Q_D(QFxTextEdit); + if (QFxTextEdit::text() == text) + return; d->text = text; d->richText = d->format == RichText || (d->format == AutoText && Qt::mightBeRichText(text)); if (d->richText) { @@ -472,6 +475,21 @@ void QFxTextEdit::setPreserveSelection(bool on) d->preserveSelection = on; } +qreal QFxTextEdit::textMargin() const +{ + Q_D(const QFxTextEdit); + return d->textMargin; +} + +void QFxTextEdit::setTextMargin(qreal margin) +{ + Q_D(QFxTextEdit); + if (d->textMargin == margin) + return; + d->textMargin = margin; + d->document->setDocumentMargin(d->textMargin); +} + void QFxTextEdit::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) { @@ -657,6 +675,13 @@ Handles the given key \a event. void QFxTextEdit::keyPressEvent(QKeyEvent *event) { Q_D(QFxTextEdit); + //### experiment with allowing 'overrides' to key events + QFxKeyEvent ke(*event); + emit keyPress(&ke); + event->setAccepted(ke.isAccepted()); + if (event->isAccepted()) + return; + QTextCursor c = textCursor(); QTextCursor::MoveOperation op = QTextCursor::NoMove; if (event == QKeySequence::MoveToNextChar) { @@ -686,6 +711,13 @@ Handles the given key \a event. void QFxTextEdit::keyReleaseEvent(QKeyEvent *event) { Q_D(QFxTextEdit); + //### experiment with allowing 'overrides' to key events + QFxKeyEvent ke(*event); + emit keyRelease(&ke); + event->setAccepted(ke.isAccepted()); + if (event->isAccepted()) + return; + d->control->processEvent(event, QPointF(0, 0)); } @@ -819,7 +851,7 @@ void QFxTextEditPrivate::init() document = control->document(); document->setDefaultFont(font.font()); - document->setDocumentMargin(0); + document->setDocumentMargin(textMargin); document->setUndoRedoEnabled(false); // flush undo buffer. document->setUndoRedoEnabled(true); updateDefaultTextOption(); @@ -849,7 +881,7 @@ void QFxTextEdit::updateSize() else if (d->vAlign == AlignVCenter) yoff = dy/2; } - setBaselineOffset(fm.ascent() + yoff); + setBaselineOffset(fm.ascent() + yoff + d->textMargin); if (!widthValid()) { int newWidth = (int)d->document->idealWidth(); d->document->setTextWidth(newWidth); // ### QTextDoc> Alignment will not work unless textWidth is set diff --git a/src/declarative/fx/qfxtextedit.h b/src/declarative/fx/qfxtextedit.h index 37bc327..e30b9ed 100644 --- a/src/declarative/fx/qfxtextedit.h +++ b/src/declarative/fx/qfxtextedit.h @@ -79,7 +79,7 @@ class Q_DECLARATIVE_EXPORT QFxTextEdit : public QFxPaintedItem Q_PROPERTY(bool cursorVisible READ isCursorVisible WRITE setCursorVisible) Q_PROPERTY(bool focusOnPress READ focusOnPress WRITE setFocusOnPress) Q_PROPERTY(bool preserveSelection READ preserveSelection WRITE setPreserveSelection) - Q_CLASSINFO("DefaultProperty", "text") + Q_PROPERTY(qreal textMargin READ textMargin WRITE setTextMargin) public: QFxTextEdit(QFxItem *parent=0); @@ -135,6 +135,9 @@ public: bool preserveSelection() const; void setPreserveSelection(bool on); + qreal textMargin() const; + void setTextMargin(qreal margin); + virtual void dump(int depth); virtual QString propertyInfo() const; diff --git a/src/declarative/fx/qfxtextedit_p.h b/src/declarative/fx/qfxtextedit_p.h index 78b0018..f733a4c 100644 --- a/src/declarative/fx/qfxtextedit_p.h +++ b/src/declarative/fx/qfxtextedit_p.h @@ -70,7 +70,7 @@ public: QFxTextEditPrivate() : font(0), color("black"), imgDirty(true), hAlign(QFxTextEdit::AlignLeft), vAlign(QFxTextEdit::AlignTop), dirty(false), wrap(false), richText(false), cursorVisible(false), focusOnPress(false), preserveSelection(true), - format(QFxTextEdit::AutoText), document(0) + textMargin(0.0), format(QFxTextEdit::AutoText), document(0) { } @@ -89,8 +89,8 @@ public: #if defined(QFX_RENDER_OPENGL) GLTexture texture; #endif - QSimpleCanvasConfig::Image imgCache; - QImage imgStyleCache; + QPixmap imgCache; + QPixmap imgStyleCache; QFxTextEdit::HAlignment hAlign; QFxTextEdit::VAlignment vAlign; bool dirty; @@ -99,6 +99,7 @@ public: bool cursorVisible; bool focusOnPress; bool preserveSelection; + qreal textMargin; QFxTextEdit::TextFormat format; QTextDocument *document; QTextControl *control; diff --git a/src/declarative/fx/qfxwebview.cpp b/src/declarative/fx/qfxwebview.cpp index 4c35cae..bfccd34 100644 --- a/src/declarative/fx/qfxwebview.cpp +++ b/src/declarative/fx/qfxwebview.cpp @@ -161,7 +161,7 @@ public: int age; QRect area; #if defined(QFX_RENDER_QPAINTER) - QSimpleCanvasConfig::Image image; + QPixmap image; #else GLTexture image; #endif |