diff -r 7516d6d86cf5 -r ed14f46c0e55 src/hbwidgets/itemviews/hbabstractviewitem_p.h --- a/src/hbwidgets/itemviews/hbabstractviewitem_p.h Mon Oct 04 17:49:30 2010 +0300 +++ b/src/hbwidgets/itemviews/hbabstractviewitem_p.h Mon Oct 18 18:23:13 2010 +0300 @@ -31,21 +31,97 @@ #include #include #include +#include +#include +#include +#include #include +#include #include #include #include #include +#include -class HbAbstractItemView; -class QGraphicsItem; +class QGraphicsObject; class QTimer; class QGestureEvent; #define HB_SD(Class) Class##Shared * sd = (Class##Shared *)(d->mSharedData.data()) #define HB_SDD(Class) Q_D(Class); Class##Shared * sd = (Class##Shared *)(d->mSharedData.data()) +class HbViewItemPixmapPainter : public QGraphicsItem +{ +public: + + HbViewItemPixmapPainter(int zValue, QGraphicsItem *parent) : + QGraphicsItem(parent), + mPixmap(0), + mBoundingRect(parent->boundingRect()) + { + setZValue(zValue); + + QGraphicsItem::GraphicsItemFlags itemFlags = flags(); + itemFlags &= ~QGraphicsItem::ItemUsesExtendedStyleOption; + itemFlags |= QGraphicsItem::ItemHasNoContents; + setFlags(itemFlags); + } + + ~HbViewItemPixmapPainter() + { + delete mPixmap; + } + + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) + { + Q_UNUSED(option); + Q_UNUSED(widget); + + if (mPixmap) { + painter->drawPixmap(QPoint(0,0), *mPixmap); + } + } + + QRectF boundingRect() const + { + return mBoundingRect; + } + + void setPixmap(QPixmap *pixmap) + { + if (pixmap != mPixmap) { + if (pixmap) { + if (!mPixmap) { + setFlag(QGraphicsItem::ItemHasNoContents, false); + } + } else { + if (mPixmap) { + setFlag(QGraphicsItem::ItemHasNoContents, true); + } + } + + delete mPixmap; + mPixmap = pixmap; + } + } + + inline QPixmap *pixmap() const + { + return mPixmap; + } + + void setSize(const QSizeF &size) { + prepareGeometryChange(); + mBoundingRect = QRectF(QPointF(), size); + } + +private: + + QPixmap *mPixmap; + QRectF mBoundingRect; +}; + class HbAbstractViewItemShared : public QObject, public QSharedData { Q_OBJECT @@ -58,13 +134,30 @@ mDefaultFrame(), mItemType("viewitem"), mPressStateChangeTimer(0), - mPressedItem(0) + mPressedItem(0), + mLowGraphicsMemory(false) + { + HbOogmWatcher *watcher = HbOogmWatcher::instance(); + + connect(watcher, SIGNAL(graphicsMemoryLow()), this, SLOT(disablePixmapCaches())); + connect(watcher, SIGNAL(graphicsMemoryGood()), this, SLOT(enablePixmapCaches())); + } + + virtual ~HbAbstractViewItemShared() { } + void updateIconItemsAsyncMode(); + + void setItemView(HbAbstractItemView *view); + public slots: void pressStateChangeTimerTriggered(); + void disablePixmapCaches(); + void enablePixmapCaches(); + + void scrollingStarted(); public: @@ -78,8 +171,10 @@ static const int ViewItemDeferredDeleteEvent; QTimer *mPressStateChangeTimer; - HbAbstractViewItem *mPressedItem; + QPointer mPressedItem; bool mAnimatePress; + + bool mLowGraphicsMemory; }; class HbAbstractViewItemPrivate : public HbWidgetPrivate @@ -90,19 +185,22 @@ explicit HbAbstractViewItemPrivate(HbAbstractViewItem *prototype, HbAbstractViewItemShared *shared = 0) : HbWidgetPrivate(), - mFocused(false), mBackgroundItem(0), mFrame(0), mCheckState(Qt::Unchecked), mSelectionItem(0), mModelItemType(Hb::StandardItem), - mRepolishRequested(false), mContentChangedSupported(false), mItemsChanged(false), mPressed(false), mFocusItem(0), mMultiSelectionTouchArea(0), - mSharedData(shared) + mSharedData(shared), + mBackPixmapPainter(0), + mFrontPixmapPainter(0), + mInPaintItems(false), + mNonCachableItem(0), + mResetPixmapCache(true) { if (!mSharedData) { mSharedData = new HbAbstractViewItemShared; @@ -113,45 +211,56 @@ HbAbstractViewItemPrivate(const HbAbstractViewItemPrivate &source) : HbWidgetPrivate(), mIndex(source.mIndex), - mFocused(source.mFocused), mBackgroundItem(0), mFrame(0), mCheckState(source.mCheckState), mSelectionItem(0), mModelItemType(source.mModelItemType), - mRepolishRequested(false), mContentChangedSupported(source.mContentChangedSupported), mItemsChanged(false), mPressed(false), mFocusItem(0), mMultiSelectionTouchArea(0), - mSharedData(source.mSharedData) + mSharedData(source.mSharedData), + mBackPixmapPainter(0), + mFrontPixmapPainter(0), + mInPaintItems(false), + mNonCachableItem(source.mNonCachableItem), + mResetPixmapCache(true) { } HbAbstractViewItemPrivate &operator=(const HbAbstractViewItemPrivate &source) { mIndex = source.mIndex; - mFocused = source.mFocused; mBackgroundItem = 0; mBackground = QVariant(); mFrame = 0; mCheckState = Qt::Unchecked; mModelItemType = source.mModelItemType; mSelectionItem = 0; - mRepolishRequested = false; mContentChangedSupported = source.mContentChangedSupported; mItemsChanged = false; mPressed = false; mFocusItem = 0; mSharedData = source.mSharedData; mMultiSelectionTouchArea = 0; + mBackPixmapPainter = 0; + mFrontPixmapPainter = 0; + mInPaintItems = false; + mNonCachableItem = source.mNonCachableItem; + mResetPixmapCache = true; return *this; } void init(); + static HbAbstractViewItemPrivate *d_ptr(HbAbstractViewItem *item) { + Q_ASSERT(item); + return item->d_func(); + } + inline bool isPrototype() const { Q_Q(const HbAbstractViewItem); @@ -162,6 +271,7 @@ virtual int modelItemType() const; void _q_animationFinished(const HbEffect::EffectStatus &status); + void _q_childrenChanged(); void repolishCloneItems(); void updateCloneItems(bool updateChildItems); @@ -174,20 +284,45 @@ void setPressed(bool pressed, bool animate); + void paintItems(QPainter *painter, QStyleOptionGraphicsItem *option, QGraphicsItem *startItem, QGraphicsItem *endItem); + void paintChildItemsRecursively(QGraphicsItem *child, QPainter *painter,QStyleOptionGraphicsItem *option, const QPointF &translatePosition); + void drawSubPixmap(QPixmap *pixmap, + QPainter *painter, + const QStyleOptionGraphicsItem *option); + void setChildFlags(QGraphicsItem *child, bool pixmapCacheEnabled); + void setChildFlagRecursively(bool pixmapCacheEnabled); + + inline bool usePixmapCache() const; + + void updatePixmap(QPixmap *pixmap, + QPainter *painter, + const QStyleOptionGraphicsItem *option, + QGraphicsItem *startItem, + QGraphicsItem *endItem); + + void releasePixmaps(); + + static bool iconLoadedCallback(HbIconItem *target, void *param); + + bool iconLoaded(HbIconItem *target); + + void updateIconItemsAsyncMode(QGraphicsItem *item); + + inline void repolishItem(); + inline bool viewAnimating(); + public: QPersistentModelIndex mIndex; - bool mFocused; - QGraphicsItem *mBackgroundItem; + QGraphicsObject *mBackgroundItem; QVariant mBackground; - QGraphicsItem *mFrame; + QGraphicsObject *mFrame; Qt::CheckState mCheckState; - QGraphicsItem *mSelectionItem; + QGraphicsObject *mSelectionItem; int mModelItemType; - bool mRepolishRequested; // whether mContentChanged flag is supported bool mContentChangedSupported; @@ -195,11 +330,47 @@ bool mItemsChanged; bool mPressed; - QGraphicsItem *mFocusItem; + QGraphicsObject *mFocusItem; - QGraphicsItem *mMultiSelectionTouchArea; + QGraphicsObject *mMultiSelectionTouchArea; QExplicitlySharedDataPointer mSharedData; + + HbViewItemPixmapPainter *mBackPixmapPainter; + HbViewItemPixmapPainter *mFrontPixmapPainter; + + QVector mUpdateItems; + + bool mInPaintItems; + + QGraphicsItem *mNonCachableItem; + bool mResetPixmapCache; + + QList mChildren; + + friend class HbAbstractViewItemShared; }; +bool HbAbstractViewItemPrivate::usePixmapCache() const +{ + if (mSharedData->mItemView + && mSharedData->mItemView->itemPixmapCacheEnabled() + && !mSharedData->mLowGraphicsMemory) { + return true; + } else { + return false; + } +} + +void HbAbstractViewItemPrivate::repolishItem() +{ + Q_Q(HbAbstractViewItem); + q->repolish(); +} + +bool HbAbstractViewItemPrivate::viewAnimating() +{ + return mSharedData->mItemView && mSharedData->mItemView->d_func()->mIsAnimating; +} + #endif /*HBABSTRACTVIEWITEM_P_H*/