27 #include "hblistlayout_p_p.h" |
27 #include "hblistlayout_p_p.h" |
28 #include "hblayoututils_p.h" |
28 #include "hblayoututils_p.h" |
29 |
29 |
30 #include "hbwidgetbase.h" |
30 #include "hbwidgetbase.h" |
31 #include "hbabstractitemcontainer.h" |
31 #include "hbabstractitemcontainer.h" |
32 #include <hbeffect.h> |
|
33 |
32 |
34 #include <QWidget> // for QWIDGETSIZE_MAX |
33 #include <QWidget> // for QWIDGETSIZE_MAX |
35 #include <QTimer> |
|
36 #include <QDebug> |
34 #include <QDebug> |
37 |
35 |
38 /* |
36 /* |
39 \class HbListLayout |
37 \class HbListLayout |
40 \brief HbListLayout manages geometries of list view contents. |
38 \brief HbListLayout manages geometries of list view contents. |
140 return false; |
137 return false; |
141 } |
138 } |
142 } |
139 } |
143 |
140 |
144 /*! |
141 /*! |
145 Updates the animation progress. |
|
146 */ |
|
147 void HbListLayoutPrivate::update() |
|
148 { |
|
149 QMapIterator<QGraphicsLayoutItem*, bool> i(mShrinkingItems); |
|
150 while (i.hasNext()) { |
|
151 i.next(); |
|
152 mShrinkingItems[i.key()] = true; |
|
153 |
|
154 if (!HbEffect::effectRunning(i.key()->graphicsItem(), "disappear")) { |
|
155 mShrinkingItems.remove(i.key()); |
|
156 } |
|
157 } |
|
158 |
|
159 QMapIterator<QGraphicsLayoutItem*, bool> j(mGrowingItems); |
|
160 while (j.hasNext()) { |
|
161 j.next(); |
|
162 mGrowingItems[j.key()] = true; |
|
163 |
|
164 if (!HbEffect::effectRunning(j.key()->graphicsItem(), "appear")) { |
|
165 mGrowingItems.remove(j.key()); |
|
166 } |
|
167 } |
|
168 |
|
169 q->invalidate(); |
|
170 |
|
171 if (mGrowingItems.size() == 0 && mShrinkingItems.size() == 0) { |
|
172 delete mTimer; |
|
173 mTimer = 0; |
|
174 } |
|
175 } |
|
176 |
|
177 /*! |
|
178 Constructor. |
142 Constructor. |
179 \param parent parent layout item. |
143 \param parent parent layout item. |
180 */ |
144 */ |
181 HbListLayout::HbListLayout( QGraphicsLayoutItem *parent ) |
145 HbListLayout::HbListLayout( QGraphicsLayoutItem *parent ) |
182 : QGraphicsLayout( parent ), d(new HbListLayoutPrivate(this)) |
146 : QGraphicsLayout( parent ), d(new HbListLayoutPrivate(this)) |
190 for each of them. |
154 for each of them. |
191 */ |
155 */ |
192 HbListLayout::~HbListLayout() |
156 HbListLayout::~HbListLayout() |
193 { |
157 { |
194 if (d) { |
158 if (d) { |
195 for (int i = count() - 1; i >= 0; --i) { |
159 for (int i = count() - 1; i >= 0; --i) { |
196 QGraphicsLayoutItem *item = itemAt(i); |
160 QGraphicsLayoutItem *item = itemAt(i); |
197 // The following lines can be removed, but this removes the item |
161 // The following lines can be removed, but this removes the item |
198 // from the layout more efficiently than the implementation of |
162 // from the layout more efficiently than the implementation of |
199 // ~QGraphicsLayoutItem. |
163 // ~QGraphicsLayoutItem. |
200 removeAt(i); |
164 removeAt(i); |
235 \param item layout item to be inserted to stack. |
199 \param item layout item to be inserted to stack. |
236 \param animate true if layout should smoothly expand to give room for the new item |
200 \param animate true if layout should smoothly expand to give room for the new item |
237 */ |
201 */ |
238 void HbListLayout::insertItem(int index, QGraphicsLayoutItem *item, bool animate) |
202 void HbListLayout::insertItem(int index, QGraphicsLayoutItem *item, bool animate) |
239 { |
203 { |
240 if (animate) { |
204 Q_UNUSED(animate); |
241 d->mGrowingItems[item] = false; |
|
242 if (!d->mTimer) { |
|
243 d->mTimer = new QTimer(d); |
|
244 QObject::connect(d->mTimer, SIGNAL(timeout()), d, SLOT(update())); |
|
245 d->mTimer->start(25); |
|
246 } |
|
247 } |
|
248 |
|
249 // If some items are shrinking while the item is being inserted, the container's |
|
250 // item list and the layout's item list may not be at sync. |
|
251 // The following code block checks if any item *before* the index is shrinking and |
|
252 // thus not apparent in the container index passed as a parameter. |
|
253 if (!d->mShrinkingItems.isEmpty()) { |
|
254 for (int i = 0; i < index; i++) { |
|
255 if (d->mShrinkingItems.contains(d->mItems.at(i))) { |
|
256 index++; |
|
257 } |
|
258 } |
|
259 } |
|
260 |
205 |
261 index = qMin(index, d->mItems.count()); |
206 index = qMin(index, d->mItems.count()); |
262 if (index < 0) { |
207 if (index < 0) { |
263 index = d->mItems.count(); |
208 index = d->mItems.count(); |
264 } |
209 } |
293 \sa removeAt |
238 \sa removeAt |
294 */ |
239 */ |
295 void HbListLayout::removeItem( QGraphicsLayoutItem *item, bool animate ) |
240 void HbListLayout::removeItem( QGraphicsLayoutItem *item, bool animate ) |
296 { |
241 { |
297 if (animate) { |
242 if (animate) { |
298 d->mShrinkingItems[item] = false; |
|
299 if (d->mGrowingItems.contains(item)) { |
|
300 d->mShrinkingItems[item] = d->mGrowingItems[item]; |
|
301 } |
|
302 |
|
303 if (!d->mTimer) { |
|
304 d->mTimer = new QTimer(d); |
|
305 QObject::connect(d->mTimer, SIGNAL(timeout()), d, SLOT(update())); |
|
306 d->mTimer->start(25); |
|
307 } |
|
308 invalidate(); |
243 invalidate(); |
309 } else { |
244 } else { |
310 removeAt(indexOf(item)); |
245 removeAt(indexOf(item)); |
311 } |
246 } |
312 |
|
313 if (d->mGrowingItems.contains(item)) { |
|
314 d->mGrowingItems.remove(item); |
|
315 } |
|
316 |
|
317 } |
247 } |
318 |
248 |
319 /*! |
249 /*! |
320 Returns the smallest item height. |
250 Returns the smallest item height. |
321 */ |
251 */ |
364 QGraphicsLayoutItem *item = itemAt(index); |
294 QGraphicsLayoutItem *item = itemAt(index); |
365 if ( item ) { |
295 if ( item ) { |
366 d->mItems.removeAt(index); |
296 d->mItems.removeAt(index); |
367 item->setParentLayoutItem(0); |
297 item->setParentLayoutItem(0); |
368 invalidate(); |
298 invalidate(); |
369 |
|
370 if (d->mShrinkingItems.contains(item)) { |
|
371 d->mShrinkingItems.remove(item); |
|
372 } |
|
373 } |
299 } |
374 } |
300 } |
375 |
301 |
376 /*! |
302 /*! |
377 From QGraphicsLayout. |
303 From QGraphicsLayout. |
391 for ( int i = 0; i < itemCount; i++ ) { |
317 for ( int i = 0; i < itemCount; i++ ) { |
392 QGraphicsLayoutItem *item = itemAt( i ); |
318 QGraphicsLayoutItem *item = itemAt( i ); |
393 qreal itemHeight = item->preferredHeight(); |
319 qreal itemHeight = item->preferredHeight(); |
394 if (item->graphicsItem()->transform().isScaling()) { |
320 if (item->graphicsItem()->transform().isScaling()) { |
395 itemHeight *= item->graphicsItem()->transform().m22(); |
321 itemHeight *= item->graphicsItem()->transform().m22(); |
396 } |
|
397 |
|
398 if (d->mGrowingItems.contains(item) && d->mGrowingItems[item] == false) { |
|
399 itemHeight = 0; |
|
400 } |
322 } |
401 |
323 |
402 QRectF itemRect(effectiveRect.x(), y, effectiveRect.width(), itemHeight); |
324 QRectF itemRect(effectiveRect.x(), y, effectiveRect.width(), itemHeight); |
403 item->setGeometry(itemRect); |
325 item->setGeometry(itemRect); |
404 y += itemHeight; |
326 y += itemHeight; |