diff options
author | Warwick Allison <warwick.allison@nokia.com> | 2009-06-23 01:26:47 (GMT) |
---|---|---|
committer | Warwick Allison <warwick.allison@nokia.com> | 2009-06-23 01:26:47 (GMT) |
commit | a661bbf81258f73bc8734302f69a5b6e3ca5e317 (patch) | |
tree | 5ed76e6c4163b01b2c7a5c2b665f295c7f64ce3f /src/declarative | |
parent | c7fcd4b772092cf0764cfd97463c3aa3d7cc9e9f (diff) | |
download | Qt-a661bbf81258f73bc8734302f69a5b6e3ca5e317.zip Qt-a661bbf81258f73bc8734302f69a5b6e3ca5e317.tar.gz Qt-a661bbf81258f73bc8734302f69a5b6e3ca5e317.tar.bz2 |
Move cacheSize property to QFxPaintedItem from QFxWebView.
Was missed in the refactoring.
Diffstat (limited to 'src/declarative')
-rw-r--r-- | src/declarative/fx/qfxpainteditem.cpp | 47 | ||||
-rw-r--r-- | src/declarative/fx/qfxpainteditem.h | 12 | ||||
-rw-r--r-- | src/declarative/fx/qfxpainteditem_p.h | 2 | ||||
-rw-r--r-- | src/declarative/fx/qfxwebview.cpp | 84 | ||||
-rw-r--r-- | src/declarative/fx/qfxwebview.h | 5 |
5 files changed, 60 insertions, 90 deletions
diff --git a/src/declarative/fx/qfxpainteditem.cpp b/src/declarative/fx/qfxpainteditem.cpp index 44adba7..29d11ff 100644 --- a/src/declarative/fx/qfxpainteditem.cpp +++ b/src/declarative/fx/qfxpainteditem.cpp @@ -337,4 +337,51 @@ void QFxPaintedItem::paintGLContents(GLPainter &p) #endif } +/*! + \qmlproperty int PaintedItem::cacheSize + + This property holds the maximum number of pixels of image cache to + allow. The default is 0.1 megapixels. The cache will not be larger + than the (unscaled) size of the item. +*/ + +/*! + \property QFxPaintedItem::cacheSize + + The maximum number of pixels of image cache to allow. The default + is 0.1 megapixels. The cache will not be larger than the (unscaled) + size of the QFxPaintedItem. +*/ +int QFxPaintedItem::cacheSize() const +{ + Q_D(const QFxPaintedItem); + return d->max_imagecache_size; +} + +void QFxPaintedItem::setCacheSize(int pixels) +{ + Q_D(QFxPaintedItem); + if (pixels < d->max_imagecache_size) { + int cachesize=0; + for (int i=0; i<d->imagecache.count(); ++i) { + QRect area = d->imagecache[i]->area; + cachesize += area.width()*area.height(); + } + while (d->imagecache.count() && cachesize > pixels) { + int oldest=-1; + int age=-1; + for (int i=0; i<d->imagecache.count(); ++i) { + int a = d->imagecache[i]->age; + if (a > age) { + oldest = i; + age = a; + } + } + cachesize -= d->imagecache[oldest]->area.width()*d->imagecache[oldest]->area.height(); + d->imagecache.removeAt(oldest); + } + } + d->max_imagecache_size = pixels; +} + QT_END_NAMESPACE diff --git a/src/declarative/fx/qfxpainteditem.h b/src/declarative/fx/qfxpainteditem.h index e086894..b7db2d9 100644 --- a/src/declarative/fx/qfxpainteditem.h +++ b/src/declarative/fx/qfxpainteditem.h @@ -56,12 +56,14 @@ class QFxPaintedItemPrivate; class Q_DECLARATIVE_EXPORT QFxPaintedItem : public QFxItem { Q_OBJECT -public: - QFxPaintedItem(QFxItem *parent=0); - ~QFxPaintedItem(); Q_PROPERTY(QSize contentsSize READ contentsSize WRITE setContentsSize) Q_PROPERTY(bool smooth READ isSmooth WRITE setSmooth) + Q_PROPERTY(int cacheSize READ cacheSize WRITE setCacheSize) + +public: + QFxPaintedItem(QFxItem *parent=0); + ~QFxPaintedItem(); #if defined(QFX_RENDER_QPAINTER) void paintContents(QPainter &painter); @@ -74,6 +76,10 @@ public: void setSmooth(bool); void setContentsSize(const QSize &); + + int cacheSize() const; + void setCacheSize(int pixels); + protected: QFxPaintedItem(QFxPaintedItemPrivate &dd, QFxItem *parent); diff --git a/src/declarative/fx/qfxpainteditem_p.h b/src/declarative/fx/qfxpainteditem_p.h index d8d1a2a..61d89fd 100644 --- a/src/declarative/fx/qfxpainteditem_p.h +++ b/src/declarative/fx/qfxpainteditem_p.h @@ -86,7 +86,7 @@ public: QList<ImageCacheItem*> imagecache; - const int max_imagecache_size; + int max_imagecache_size; bool smooth; QSize contentsSize; }; diff --git a/src/declarative/fx/qfxwebview.cpp b/src/declarative/fx/qfxwebview.cpp index d5dc874..adb33e8 100644 --- a/src/declarative/fx/qfxwebview.cpp +++ b/src/declarative/fx/qfxwebview.cpp @@ -150,47 +150,17 @@ class QFxWebViewPrivate : public QFxPaintedItemPrivate public: QFxWebViewPrivate() : QFxPaintedItemPrivate(), page(0), idealwidth(0), idealheight(0), interactive(true), lastPress(0), lastRelease(0), mouseX(0), mouseY(0), - max_imagecache_size(100000), progress(1.0), pending(PendingNone) + progress(1.0), pending(PendingNone) { } QWebPage *page; - struct ImageCacheItem { - ImageCacheItem() : age(0) {} - ~ImageCacheItem() { } - int age; - QRect area; -#if defined(QFX_RENDER_QPAINTER) - QPixmap image; -#else - GLTexture image; -#endif - }; - QList<ImageCacheItem*> imagecache; - void dirtyCache(const QRect& dirt) - { - for (int i=0; i<imagecache.count(); ) { - if (imagecache[i]->area.intersects(dirt)) { - imagecache.removeAt(i); - } else { - ++i; - } - } - } - void clearCache() - { - foreach (ImageCacheItem* i, imagecache) - delete i; - imagecache.clear(); - } - int idealwidth; int idealheight; bool interactive; QMouseEvent *lastPress, *lastRelease; int mouseX, mouseY; - int max_imagecache_size; qreal progress; QBasicTimer dcTimer; QString statusBarMessage; @@ -460,9 +430,8 @@ void QFxWebView::setInteractive(bool i) void QFxWebView::updateCacheForVisibility() { - Q_D(QFxWebView); if (!isVisible()) - d->clearCache(); + clearCache(); } void QFxWebView::expandToWebPage() @@ -479,7 +448,7 @@ void QFxWebView::expandToWebPage() cs.setHeight(height()); if (cs != page()->viewportSize()) { page()->setViewportSize(cs); - d->clearCache(); + clearCache(); setImplicitWidth(cs.width()); setImplicitHeight(cs.height()); } @@ -502,53 +471,6 @@ void QFxWebView::paintPage(const QRect& r) update(); } -/*! - \qmlproperty int WebView::cacheSize - - This property holds the maximum number of pixels of image cache to - allow. The default is 0.1 megapixels. The cache will not be larger - than the (unscaled) size of the WebView. -*/ - -/*! - \property QFxWebView::cacheSize - - The maximum number of pixels of image cache to allow. The default - is 0.1 megapixels. The cache will not be larger than the (unscaled) - size of the QFxWebView. -*/ -int QFxWebView::cacheSize() const -{ - Q_D(const QFxWebView); - return d->max_imagecache_size; -} - -void QFxWebView::setCacheSize(int pixels) -{ - Q_D(QFxWebView); - if (pixels < d->max_imagecache_size) { - int cachesize=0; - for (int i=0; i<d->imagecache.count(); ++i) { - QRect area = d->imagecache[i]->area; - cachesize += area.width()*area.height(); - } - while (d->imagecache.count() && cachesize > pixels) { - int oldest=-1; - int age=-1; - for (int i=0; i<d->imagecache.count(); ++i) { - int a = d->imagecache[i]->age; - if (a > age) { - oldest = i; - age = a; - } - } - cachesize -= d->imagecache[oldest]->area.width()*d->imagecache[oldest]->area.height(); - d->imagecache.removeAt(oldest); - } - } - d->max_imagecache_size = pixels; -} - void QFxWebView::dump(int depth) { QByteArray ba(depth * 4, ' '); diff --git a/src/declarative/fx/qfxwebview.h b/src/declarative/fx/qfxwebview.h index e9b6d37..c9a62cc 100644 --- a/src/declarative/fx/qfxwebview.h +++ b/src/declarative/fx/qfxwebview.h @@ -96,8 +96,6 @@ class Q_DECLARATIVE_EXPORT QFxWebView : public QFxPaintedItem Q_PROPERTY(bool interactive READ interactive WRITE setInteractive NOTIFY interactiveChanged) - Q_PROPERTY(int cacheSize READ cacheSize WRITE setCacheSize) - Q_PROPERTY(QObject* reload READ reloadAction) Q_PROPERTY(QObject* back READ backAction) Q_PROPERTY(QObject* forward READ forwardAction) @@ -125,9 +123,6 @@ public: bool interactive() const; void setInteractive(bool); - int cacheSize() const; - void setCacheSize(int pixels); - int mouseX() const; int mouseY() const; |