29 |
29 |
30 #include <hbwidget_p.h> |
30 #include <hbwidget_p.h> |
31 #include <hbeffect.h> |
31 #include <hbeffect.h> |
32 #include <hbframebackground.h> |
32 #include <hbframebackground.h> |
33 #include <hbnamespace.h> |
33 #include <hbnamespace.h> |
|
34 #include <hboogmwatcher_p.h> |
|
35 #include <hbabstractitemview.h> |
|
36 #include <hbabstractitemview_p.h> |
|
37 #include <hbstyle.h> |
34 |
38 |
35 #include <QObject> |
39 #include <QObject> |
|
40 #include <QGraphicsItem> |
36 #include <QPersistentModelIndex> |
41 #include <QPersistentModelIndex> |
37 #include <QPointer> |
42 #include <QPointer> |
38 #include <QExplicitlySharedDataPointer> |
43 #include <QExplicitlySharedDataPointer> |
39 #include <QSharedData> |
44 #include <QSharedData> |
40 |
45 #include <QPainter> |
41 class HbAbstractItemView; |
46 |
42 class QGraphicsItem; |
47 class QGraphicsObject; |
43 class QTimer; |
48 class QTimer; |
44 class QGestureEvent; |
49 class QGestureEvent; |
45 |
50 |
46 #define HB_SD(Class) Class##Shared * sd = (Class##Shared *)(d->mSharedData.data()) |
51 #define HB_SD(Class) Class##Shared * sd = (Class##Shared *)(d->mSharedData.data()) |
47 #define HB_SDD(Class) Q_D(Class); Class##Shared * sd = (Class##Shared *)(d->mSharedData.data()) |
52 #define HB_SDD(Class) Q_D(Class); Class##Shared * sd = (Class##Shared *)(d->mSharedData.data()) |
|
53 |
|
54 class HbViewItemPixmapPainter : public QGraphicsItem |
|
55 { |
|
56 public: |
|
57 |
|
58 HbViewItemPixmapPainter(int zValue, QGraphicsItem *parent) : |
|
59 QGraphicsItem(parent), |
|
60 mPixmap(0), |
|
61 mBoundingRect(parent->boundingRect()) |
|
62 { |
|
63 setZValue(zValue); |
|
64 |
|
65 QGraphicsItem::GraphicsItemFlags itemFlags = flags(); |
|
66 itemFlags &= ~QGraphicsItem::ItemUsesExtendedStyleOption; |
|
67 itemFlags |= QGraphicsItem::ItemHasNoContents; |
|
68 setFlags(itemFlags); |
|
69 } |
|
70 |
|
71 ~HbViewItemPixmapPainter() |
|
72 { |
|
73 delete mPixmap; |
|
74 } |
|
75 |
|
76 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) |
|
77 { |
|
78 Q_UNUSED(option); |
|
79 Q_UNUSED(widget); |
|
80 |
|
81 if (mPixmap) { |
|
82 painter->drawPixmap(QPoint(0,0), *mPixmap); |
|
83 } |
|
84 } |
|
85 |
|
86 QRectF boundingRect() const |
|
87 { |
|
88 return mBoundingRect; |
|
89 } |
|
90 |
|
91 void setPixmap(QPixmap *pixmap) |
|
92 { |
|
93 if (pixmap != mPixmap) { |
|
94 if (pixmap) { |
|
95 if (!mPixmap) { |
|
96 setFlag(QGraphicsItem::ItemHasNoContents, false); |
|
97 } |
|
98 } else { |
|
99 if (mPixmap) { |
|
100 setFlag(QGraphicsItem::ItemHasNoContents, true); |
|
101 } |
|
102 } |
|
103 |
|
104 delete mPixmap; |
|
105 mPixmap = pixmap; |
|
106 } |
|
107 } |
|
108 |
|
109 inline QPixmap *pixmap() const |
|
110 { |
|
111 return mPixmap; |
|
112 } |
|
113 |
|
114 void setSize(const QSizeF &size) { |
|
115 prepareGeometryChange(); |
|
116 mBoundingRect = QRectF(QPointF(), size); |
|
117 } |
|
118 |
|
119 private: |
|
120 |
|
121 QPixmap *mPixmap; |
|
122 QRectF mBoundingRect; |
|
123 }; |
48 |
124 |
49 class HbAbstractViewItemShared : public QObject, public QSharedData |
125 class HbAbstractViewItemShared : public QObject, public QSharedData |
50 { |
126 { |
51 Q_OBJECT |
127 Q_OBJECT |
52 |
128 |
56 mPrototype(0), |
132 mPrototype(0), |
57 mItemView(0), |
133 mItemView(0), |
58 mDefaultFrame(), |
134 mDefaultFrame(), |
59 mItemType("viewitem"), |
135 mItemType("viewitem"), |
60 mPressStateChangeTimer(0), |
136 mPressStateChangeTimer(0), |
61 mPressedItem(0) |
137 mPressedItem(0), |
62 { |
138 mLowGraphicsMemory(false) |
63 } |
139 { |
|
140 HbOogmWatcher *watcher = HbOogmWatcher::instance(); |
|
141 |
|
142 connect(watcher, SIGNAL(graphicsMemoryLow()), this, SLOT(disablePixmapCaches())); |
|
143 connect(watcher, SIGNAL(graphicsMemoryGood()), this, SLOT(enablePixmapCaches())); |
|
144 } |
|
145 |
|
146 virtual ~HbAbstractViewItemShared() |
|
147 { |
|
148 } |
|
149 |
|
150 void updateIconItemsAsyncMode(); |
|
151 |
|
152 void setItemView(HbAbstractItemView *view); |
64 |
153 |
65 public slots: |
154 public slots: |
66 |
155 |
67 void pressStateChangeTimerTriggered(); |
156 void pressStateChangeTimerTriggered(); |
|
157 void disablePixmapCaches(); |
|
158 void enablePixmapCaches(); |
|
159 |
|
160 void scrollingStarted(); |
68 |
161 |
69 public: |
162 public: |
70 |
163 |
71 HbAbstractViewItem *mPrototype; |
164 HbAbstractViewItem *mPrototype; |
72 HbAbstractItemView *mItemView; |
165 HbAbstractItemView *mItemView; |
76 |
169 |
77 QString mItemType; |
170 QString mItemType; |
78 static const int ViewItemDeferredDeleteEvent; |
171 static const int ViewItemDeferredDeleteEvent; |
79 |
172 |
80 QTimer *mPressStateChangeTimer; |
173 QTimer *mPressStateChangeTimer; |
81 HbAbstractViewItem *mPressedItem; |
174 QPointer <HbAbstractViewItem> mPressedItem; |
82 bool mAnimatePress; |
175 bool mAnimatePress; |
|
176 |
|
177 bool mLowGraphicsMemory; |
83 }; |
178 }; |
84 |
179 |
85 class HbAbstractViewItemPrivate : public HbWidgetPrivate |
180 class HbAbstractViewItemPrivate : public HbWidgetPrivate |
86 { |
181 { |
87 Q_DECLARE_PUBLIC( HbAbstractViewItem ) |
182 Q_DECLARE_PUBLIC( HbAbstractViewItem ) |
88 |
183 |
89 public: |
184 public: |
90 |
185 |
91 explicit HbAbstractViewItemPrivate(HbAbstractViewItem *prototype, HbAbstractViewItemShared *shared = 0) : |
186 explicit HbAbstractViewItemPrivate(HbAbstractViewItem *prototype, HbAbstractViewItemShared *shared = 0) : |
92 HbWidgetPrivate(), |
187 HbWidgetPrivate(), |
93 mFocused(false), |
|
94 mBackgroundItem(0), |
188 mBackgroundItem(0), |
95 mFrame(0), |
189 mFrame(0), |
96 mCheckState(Qt::Unchecked), |
190 mCheckState(Qt::Unchecked), |
97 mSelectionItem(0), |
191 mSelectionItem(0), |
98 mModelItemType(Hb::StandardItem), |
192 mModelItemType(Hb::StandardItem), |
99 mRepolishRequested(false), |
|
100 mContentChangedSupported(false), |
193 mContentChangedSupported(false), |
101 mItemsChanged(false), |
194 mItemsChanged(false), |
102 mPressed(false), |
195 mPressed(false), |
103 mFocusItem(0), |
196 mFocusItem(0), |
104 mMultiSelectionTouchArea(0), |
197 mMultiSelectionTouchArea(0), |
105 mSharedData(shared) |
198 mSharedData(shared), |
|
199 mBackPixmapPainter(0), |
|
200 mFrontPixmapPainter(0), |
|
201 mInPaintItems(false), |
|
202 mNonCachableItem(0), |
|
203 mResetPixmapCache(true) |
106 { |
204 { |
107 if (!mSharedData) { |
205 if (!mSharedData) { |
108 mSharedData = new HbAbstractViewItemShared; |
206 mSharedData = new HbAbstractViewItemShared; |
109 } |
207 } |
110 mSharedData->mPrototype = prototype; |
208 mSharedData->mPrototype = prototype; |
111 } |
209 } |
112 |
210 |
113 HbAbstractViewItemPrivate(const HbAbstractViewItemPrivate &source) : |
211 HbAbstractViewItemPrivate(const HbAbstractViewItemPrivate &source) : |
114 HbWidgetPrivate(), |
212 HbWidgetPrivate(), |
115 mIndex(source.mIndex), |
213 mIndex(source.mIndex), |
116 mFocused(source.mFocused), |
|
117 mBackgroundItem(0), |
214 mBackgroundItem(0), |
118 mFrame(0), |
215 mFrame(0), |
119 mCheckState(source.mCheckState), |
216 mCheckState(source.mCheckState), |
120 mSelectionItem(0), |
217 mSelectionItem(0), |
121 mModelItemType(source.mModelItemType), |
218 mModelItemType(source.mModelItemType), |
122 mRepolishRequested(false), |
|
123 mContentChangedSupported(source.mContentChangedSupported), |
219 mContentChangedSupported(source.mContentChangedSupported), |
124 mItemsChanged(false), |
220 mItemsChanged(false), |
125 mPressed(false), |
221 mPressed(false), |
126 mFocusItem(0), |
222 mFocusItem(0), |
127 mMultiSelectionTouchArea(0), |
223 mMultiSelectionTouchArea(0), |
128 mSharedData(source.mSharedData) |
224 mSharedData(source.mSharedData), |
|
225 mBackPixmapPainter(0), |
|
226 mFrontPixmapPainter(0), |
|
227 mInPaintItems(false), |
|
228 mNonCachableItem(source.mNonCachableItem), |
|
229 mResetPixmapCache(true) |
129 { |
230 { |
130 } |
231 } |
131 |
232 |
132 HbAbstractViewItemPrivate &operator=(const HbAbstractViewItemPrivate &source) |
233 HbAbstractViewItemPrivate &operator=(const HbAbstractViewItemPrivate &source) |
133 { |
234 { |
134 mIndex = source.mIndex; |
235 mIndex = source.mIndex; |
135 mFocused = source.mFocused; |
|
136 mBackgroundItem = 0; |
236 mBackgroundItem = 0; |
137 mBackground = QVariant(); |
237 mBackground = QVariant(); |
138 mFrame = 0; |
238 mFrame = 0; |
139 mCheckState = Qt::Unchecked; |
239 mCheckState = Qt::Unchecked; |
140 mModelItemType = source.mModelItemType; |
240 mModelItemType = source.mModelItemType; |
141 mSelectionItem = 0; |
241 mSelectionItem = 0; |
142 mRepolishRequested = false; |
|
143 mContentChangedSupported = source.mContentChangedSupported; |
242 mContentChangedSupported = source.mContentChangedSupported; |
144 mItemsChanged = false; |
243 mItemsChanged = false; |
145 mPressed = false; |
244 mPressed = false; |
146 mFocusItem = 0; |
245 mFocusItem = 0; |
147 mSharedData = source.mSharedData; |
246 mSharedData = source.mSharedData; |
148 mMultiSelectionTouchArea = 0; |
247 mMultiSelectionTouchArea = 0; |
|
248 mBackPixmapPainter = 0; |
|
249 mFrontPixmapPainter = 0; |
|
250 mInPaintItems = false; |
|
251 mNonCachableItem = source.mNonCachableItem; |
|
252 mResetPixmapCache = true; |
149 |
253 |
150 return *this; |
254 return *this; |
151 } |
255 } |
152 |
256 |
153 void init(); |
257 void init(); |
154 |
258 |
|
259 static HbAbstractViewItemPrivate *d_ptr(HbAbstractViewItem *item) { |
|
260 Q_ASSERT(item); |
|
261 return item->d_func(); |
|
262 } |
|
263 |
155 inline bool isPrototype() const |
264 inline bool isPrototype() const |
156 { |
265 { |
157 Q_Q(const HbAbstractViewItem); |
266 Q_Q(const HbAbstractViewItem); |
158 return q == mSharedData->mPrototype; |
267 return q == mSharedData->mPrototype; |
159 } |
268 } |
160 |
269 |
161 |
270 |
162 virtual int modelItemType() const; |
271 virtual int modelItemType() const; |
163 |
272 |
164 void _q_animationFinished(const HbEffect::EffectStatus &status); |
273 void _q_animationFinished(const HbEffect::EffectStatus &status); |
|
274 void _q_childrenChanged(); |
165 |
275 |
166 void repolishCloneItems(); |
276 void repolishCloneItems(); |
167 void updateCloneItems(bool updateChildItems); |
277 void updateCloneItems(bool updateChildItems); |
168 |
278 |
169 virtual void setInsidePopup(bool insidePopup); |
279 virtual void setInsidePopup(bool insidePopup); |
172 |
282 |
173 void revealItem(); |
283 void revealItem(); |
174 |
284 |
175 void setPressed(bool pressed, bool animate); |
285 void setPressed(bool pressed, bool animate); |
176 |
286 |
|
287 void paintItems(QPainter *painter, QStyleOptionGraphicsItem *option, QGraphicsItem *startItem, QGraphicsItem *endItem); |
|
288 void paintChildItemsRecursively(QGraphicsItem *child, QPainter *painter,QStyleOptionGraphicsItem *option, const QPointF &translatePosition); |
|
289 void drawSubPixmap(QPixmap *pixmap, |
|
290 QPainter *painter, |
|
291 const QStyleOptionGraphicsItem *option); |
|
292 void setChildFlags(QGraphicsItem *child, bool pixmapCacheEnabled); |
|
293 void setChildFlagRecursively(bool pixmapCacheEnabled); |
|
294 |
|
295 inline bool usePixmapCache() const; |
|
296 |
|
297 void updatePixmap(QPixmap *pixmap, |
|
298 QPainter *painter, |
|
299 const QStyleOptionGraphicsItem *option, |
|
300 QGraphicsItem *startItem, |
|
301 QGraphicsItem *endItem); |
|
302 |
|
303 void releasePixmaps(); |
|
304 |
|
305 static bool iconLoadedCallback(HbIconItem *target, void *param); |
|
306 |
|
307 bool iconLoaded(HbIconItem *target); |
|
308 |
|
309 void updateIconItemsAsyncMode(QGraphicsItem *item); |
|
310 |
|
311 inline void repolishItem(); |
|
312 inline bool viewAnimating(); |
|
313 |
177 public: |
314 public: |
178 QPersistentModelIndex mIndex; |
315 QPersistentModelIndex mIndex; |
179 bool mFocused; |
316 |
180 |
317 QGraphicsObject *mBackgroundItem; |
181 QGraphicsItem *mBackgroundItem; |
|
182 QVariant mBackground; |
318 QVariant mBackground; |
183 |
319 |
184 QGraphicsItem *mFrame; |
320 QGraphicsObject *mFrame; |
185 |
321 |
186 Qt::CheckState mCheckState; |
322 Qt::CheckState mCheckState; |
187 QGraphicsItem *mSelectionItem; |
323 QGraphicsObject *mSelectionItem; |
188 |
324 |
189 int mModelItemType; |
325 int mModelItemType; |
190 bool mRepolishRequested; |
|
191 |
326 |
192 // whether mContentChanged flag is supported |
327 // whether mContentChanged flag is supported |
193 bool mContentChangedSupported; |
328 bool mContentChangedSupported; |
194 // Status of child item existence changed. |
329 // Status of child item existence changed. |
195 bool mItemsChanged; |
330 bool mItemsChanged; |
196 bool mPressed; |
331 bool mPressed; |
197 |
332 |
198 QGraphicsItem *mFocusItem; |
333 QGraphicsObject *mFocusItem; |
199 |
334 |
200 QGraphicsItem *mMultiSelectionTouchArea; |
335 QGraphicsObject *mMultiSelectionTouchArea; |
201 |
336 |
202 QExplicitlySharedDataPointer<HbAbstractViewItemShared> mSharedData; |
337 QExplicitlySharedDataPointer<HbAbstractViewItemShared> mSharedData; |
|
338 |
|
339 HbViewItemPixmapPainter *mBackPixmapPainter; |
|
340 HbViewItemPixmapPainter *mFrontPixmapPainter; |
|
341 |
|
342 QVector<QGraphicsItem*> mUpdateItems; |
|
343 |
|
344 bool mInPaintItems; |
|
345 |
|
346 QGraphicsItem *mNonCachableItem; |
|
347 bool mResetPixmapCache; |
|
348 |
|
349 QList<QGraphicsItem *> mChildren; |
|
350 |
|
351 friend class HbAbstractViewItemShared; |
203 }; |
352 }; |
204 |
353 |
|
354 bool HbAbstractViewItemPrivate::usePixmapCache() const |
|
355 { |
|
356 if (mSharedData->mItemView |
|
357 && mSharedData->mItemView->itemPixmapCacheEnabled() |
|
358 && !mSharedData->mLowGraphicsMemory) { |
|
359 return true; |
|
360 } else { |
|
361 return false; |
|
362 } |
|
363 } |
|
364 |
|
365 void HbAbstractViewItemPrivate::repolishItem() |
|
366 { |
|
367 Q_Q(HbAbstractViewItem); |
|
368 q->repolish(); |
|
369 } |
|
370 |
|
371 bool HbAbstractViewItemPrivate::viewAnimating() |
|
372 { |
|
373 return mSharedData->mItemView && mSharedData->mItemView->d_func()->mIsAnimating; |
|
374 } |
|
375 |
205 #endif /*HBABSTRACTVIEWITEM_P_H*/ |
376 #endif /*HBABSTRACTVIEWITEM_P_H*/ |