16 */ |
16 */ |
17 |
17 |
18 #include <QGesture> |
18 #include <QGesture> |
19 #include <QPainter> |
19 #include <QPainter> |
20 #include <QTimer> |
20 #include <QTimer> |
21 #include <HbLabel> |
|
22 #include <HbGridViewItem> |
21 #include <HbGridViewItem> |
23 #include <HbMainWindow> |
22 #include <HbMainWindow> |
24 #include "hggridcontainer.h" |
23 #include "hggridcontainer.h" |
25 #include "hgmediawallrenderer.h" |
24 #include "hgmediawallrenderer.h" |
26 #include "hgquad.h" |
25 #include "hgquad.h" |
27 #include "hgvgquadrenderer.h" |
|
28 #include "hgvgimage.h" |
|
29 #include "hgwidgetitem.h" |
26 #include "hgwidgetitem.h" |
30 #include "trace.h" |
27 #include "trace.h" |
31 |
28 |
32 #include <HbGridView> |
29 #include <HbGridView> |
33 #include <HbIconItem> |
30 #include <HbIconItem> |
34 #include <QAbstractItemModel> |
31 #include <QAbstractItemModel> |
35 #include "hglongpressvisualizer.h" |
32 #include "hglongpressvisualizer.h" |
36 |
33 #include <HbPinchGesture> |
|
34 #include <QGraphicsSceneMouseEvent> |
37 |
35 |
38 static const qreal KCameraMaxYAngle(20); |
36 static const qreal KCameraMaxYAngle(20); |
39 static const qreal KSpringVelocityToCameraYAngleFactor(2); |
37 static const qreal KSpringVelocityToCameraYAngleFactor(2); |
40 |
38 |
41 HgGridContainer::HgGridContainer(QGraphicsItem *parent) : |
39 HgGridContainer::HgGridContainer(QGraphicsItem *parent) : |
42 HgContainer(parent), |
40 HgContainer(parent), |
43 mEffect3dEnabled(true) |
41 mEffect3dEnabled(true), |
44 { |
42 mPinchEnabled(false), |
45 |
43 mPinchingOngoing(false), |
|
44 mTempImageHeightForLineGrid(-1), |
|
45 mTempImageHeightFinal(-1), |
|
46 mTempRowCount(-1), |
|
47 mPinchEndAlreadyHandled(false), |
|
48 mReactToOnlyPanGestures(false), |
|
49 mHorizontalRowCount(3), |
|
50 mVerticalColumnCount(3), |
|
51 mHorizontalPinchLevels(QPair<int,int>(2,3)), |
|
52 mVerticalPinchLevels(QPair<int,int>(2,5)) |
|
53 { |
46 mUserItemSize = QSize(120,120); |
54 mUserItemSize = QSize(120,120); |
47 mUserItemSpacing = QSize(1,1); |
55 mUserItemSpacing = QSize(0,0); |
48 |
|
49 } |
56 } |
50 |
57 |
51 HgGridContainer::~HgGridContainer() |
58 HgGridContainer::~HgGridContainer() |
52 { |
59 { |
53 |
|
54 } |
60 } |
55 |
61 |
56 void HgGridContainer::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
62 void HgGridContainer::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
57 { |
63 { |
58 HgContainer::paint(painter, option, widget); |
64 HgContainer::paint(painter, option, widget); |
|
65 |
|
66 // Draw these only while pinching |
|
67 if(mPinchingOngoing) |
|
68 { |
|
69 const QPen& oldPen = painter->pen(); |
|
70 |
|
71 // dim the background, i.e. draw trasparent black screen-sized rect (alpha is 100 of 255) |
|
72 painter->fillRect(rect(), QColor(0, 0, 0, 100)); |
|
73 |
|
74 QPen pen = painter->pen(); |
|
75 pen.setColor(Qt::white); |
|
76 pen.setWidth(4); |
|
77 painter->setPen(pen); |
|
78 |
|
79 int imageXCount; |
|
80 int imageYCount; |
|
81 int widthSpacingPlusImage; |
|
82 int heightSpacingPlusImage; |
|
83 // Use temp values that are updated during pinching |
|
84 QSize imageSize(mTempImageHeightForLineGrid, mTempImageHeightForLineGrid); |
|
85 |
|
86 if (scrollDirection() == Qt::Horizontal ) //landscape mode |
|
87 { |
|
88 imageXCount = rect().width() / imageSize.width(); |
|
89 imageYCount = mTempRowCount; |
|
90 widthSpacingPlusImage = mRenderer->getSpacing().height() + imageSize.height(); |
|
91 heightSpacingPlusImage = mRenderer->getSpacing().width() + imageSize.width(); |
|
92 } |
|
93 else //portrait mode |
|
94 { |
|
95 imageXCount = mTempRowCount; |
|
96 imageYCount = rect().height() / imageSize.height(); |
|
97 widthSpacingPlusImage = mRenderer->getSpacing().width() + imageSize.width(); |
|
98 heightSpacingPlusImage = mRenderer->getSpacing().height() + imageSize.height(); |
|
99 } |
|
100 |
|
101 int yOffset(0); |
|
102 if (scrollDirection() == Qt::Horizontal ) { |
|
103 yOffset = (rect().height() - (mUserItemSize.height()*mHorizontalRowCount))/2; |
|
104 } |
|
105 |
|
106 for (int xCounter = 0; xCounter < (imageXCount+1); ++xCounter) |
|
107 { |
|
108 for (int yCounter = 0; yCounter < (imageYCount+1); ++yCounter) |
|
109 { |
|
110 painter->drawLine(QPoint(0, yOffset + yCounter * heightSpacingPlusImage), |
|
111 QPoint(rect().width(), yOffset + yCounter * heightSpacingPlusImage)); |
|
112 } |
|
113 |
|
114 painter->drawLine(QPoint(xCounter * widthSpacingPlusImage, yOffset), |
|
115 QPoint(xCounter * widthSpacingPlusImage, rect().height()-yOffset)); |
|
116 } |
|
117 |
|
118 painter->setPen(oldPen); |
|
119 |
|
120 } |
59 |
121 |
60 updateSelectedItem(); |
122 updateSelectedItem(); |
61 } |
123 } |
62 |
124 |
63 HgMediaWallRenderer* HgGridContainer::createRenderer(Qt::Orientation scrollDirection) |
125 HgMediaWallRenderer* HgGridContainer::createRenderer(Qt::Orientation scrollDirection) |
64 { |
126 { |
65 |
127 |
66 HgMediaWallRenderer* renderer = new HgMediaWallRenderer(this, scrollDirection, scrollDirection, false); |
128 HgMediaWallRenderer* renderer = new HgMediaWallRenderer(this, scrollDirection, scrollDirection, false); |
67 renderer->enableCoverflowMode(false); |
129 renderer->enableCoverflowMode(false); |
68 renderer->setImageSize(mUserItemSize); |
130 renderer->setImageSize(mUserItemSize); |
69 renderer->setRowCount(3, renderer->getImageSize(), false); |
131 const int rowCount = scrollDirection == Qt::Horizontal ? mHorizontalRowCount : mVerticalColumnCount; |
|
132 renderer->setRowCount(rowCount, renderer->getImageSize(), false); |
70 renderer->enableReflections(false); |
133 renderer->enableReflections(false); |
71 renderer->setSpacing(mUserItemSpacing); |
134 renderer->setSpacing(mUserItemSpacing); |
72 renderer->setFrontCoverElevationFactor(0.5); |
135 renderer->setFrontCoverElevationFactor(0.5); |
73 |
136 |
74 return renderer; |
137 return renderer; |
88 return 0; |
151 return 0; |
89 |
152 |
90 return qBound(-KCameraMaxYAngle, springVelocity * KSpringVelocityToCameraYAngleFactor, KCameraMaxYAngle); |
153 return qBound(-KCameraMaxYAngle, springVelocity * KSpringVelocityToCameraYAngleFactor, KCameraMaxYAngle); |
91 } |
154 } |
92 |
155 |
93 void HgGridContainer::handleTapAction(const QPointF& pos, HgWidgetItem* hitItem, int hitItemIndex) |
156 bool HgGridContainer::handleTapAction(const QPointF& pos, HgWidgetItem* hitItem, int hitItemIndex) |
94 { |
157 { |
95 Q_UNUSED(pos) |
158 Q_UNUSED(pos) |
|
159 |
|
160 if (mSelectionMode != HgWidget::NoSelection) { |
|
161 return handleItemSelection(hitItem); |
|
162 } |
|
163 |
|
164 if (!mIgnoreGestureAction) { |
|
165 selectItem(hitItemIndex); |
|
166 emit activated(hitItem->modelIndex()); |
|
167 } else { |
|
168 mSpring.resetVelocity(); |
|
169 update(); |
|
170 mIgnoreGestureAction = false; |
|
171 } |
|
172 return true; |
|
173 } |
|
174 |
|
175 bool HgGridContainer::handleLongTapAction(const QPointF& pos, HgWidgetItem* hitItem, int hitItemIndex) |
|
176 { |
96 Q_UNUSED(hitItemIndex) |
177 Q_UNUSED(hitItemIndex) |
97 |
178 |
98 selectItem(hitItemIndex); |
179 INFO("Long tap:" << hitItem->modelIndex().row()); |
99 emit activated(hitItem->modelIndex()); |
|
100 } |
|
101 |
|
102 void HgGridContainer::handleLongTapAction(const QPointF& pos, HgWidgetItem* hitItem, int hitItemIndex) |
|
103 { |
|
104 Q_UNUSED(hitItemIndex) |
|
105 |
180 |
106 selectItem(hitItemIndex); |
181 selectItem(hitItemIndex); |
107 emit longPressed(hitItem->modelIndex(), pos); |
182 |
|
183 if (!mIgnoreGestureAction) { |
|
184 if (mHandleLongPress){ |
|
185 emit longPressed(hitItem->modelIndex(), pos); |
|
186 } |
|
187 } else { |
|
188 mSpring.resetVelocity(); |
|
189 update(); |
|
190 mIgnoreGestureAction = false; |
|
191 } |
|
192 return true; |
108 } |
193 } |
109 |
194 |
110 void HgGridContainer::onScrollPositionChanged(qreal pos) |
195 void HgGridContainer::onScrollPositionChanged(qreal pos) |
111 { |
196 { |
112 HgContainer::onScrollPositionChanged(pos); |
197 HgContainer::onScrollPositionChanged(pos); |
113 |
198 |
114 if (pos < 0) return; |
199 if (pos < 0) return; |
115 const int index = ((int)pos)*rowCount(); |
200 const int index = ((int)pos)*currentRowCount(); |
116 if (index > itemCount()) return; |
201 if (index > itemCount()) return; |
117 |
202 |
118 HgWidgetItem* item = itemByIndex(index); |
203 HgWidgetItem* item = itemByIndex(index); |
119 if (item && item->modelIndex() != mSelectionModel->currentIndex()) { |
204 if (item && item->modelIndex() != mSelectionModel->currentIndex()) { |
120 mSelectionModel->setCurrentIndex(item->modelIndex(), QItemSelectionModel::Current); |
205 mSelectionModel->setCurrentIndex(item->modelIndex(), QItemSelectionModel::Current); |
132 |
217 |
133 bool HgGridContainer::effect3dEnabled() const |
218 bool HgGridContainer::effect3dEnabled() const |
134 { |
219 { |
135 return mEffect3dEnabled; |
220 return mEffect3dEnabled; |
136 } |
221 } |
|
222 |
|
223 bool HgGridContainer::handleTap(Qt::GestureState state, const QPointF &pos) |
|
224 { |
|
225 FUNC_LOG; |
|
226 |
|
227 bool handleGesture = false; |
|
228 |
|
229 if (hasItemAt(pos)) { |
|
230 switch (state) |
|
231 { |
|
232 case Qt::GestureStarted: |
|
233 { |
|
234 // TODO IS THIS IF REALLY NEEDED |
|
235 if(mSpring.isActive()) { |
|
236 qreal springPos = mSpring.pos().x(); |
|
237 int gridTotalHeightInImages = ceilf( mItems.count() / mRenderer->getRowCount() ); |
|
238 qreal currentViewHeightInImages; |
|
239 if (scrollDirection() == Qt::Horizontal ) { |
|
240 int rowHeight = mRenderer->getImageSize().width() + mRenderer->getSpacing().width(); |
|
241 currentViewHeightInImages = rect().width() / rowHeight; |
|
242 } else { |
|
243 int rowHeight = mRenderer->getImageSize().height() + mRenderer->getSpacing().height(); |
|
244 currentViewHeightInImages = rect().height() / rowHeight; |
|
245 } |
|
246 |
|
247 // If list does not currently fill the whole screen (some theme background behind the list |
|
248 // is visible), and list is moving, then do not react to tapping. |
|
249 if( springPos >= 0 |
|
250 && springPos <= (gridTotalHeightInImages - currentViewHeightInImages) ) { |
|
251 mSpring.cancel(); |
|
252 mEmitScrollingEnded = true; |
|
253 } |
|
254 mIgnoreGestureAction = true; |
|
255 } else if (mHandleLongPress){ |
|
256 startLongPressWatcher(pos); |
|
257 } |
|
258 break; |
|
259 } |
|
260 case Qt::GestureFinished: |
|
261 { |
|
262 int hitItemindex = -1; |
|
263 HgWidgetItem* hitItem = getItemAt(pos,hitItemindex); |
|
264 handleGesture = handleTapAction(pos, hitItem, hitItemindex); |
|
265 if (mEmitScrollingEnded) { |
|
266 mEmitScrollingEnded = false; |
|
267 emit scrollingEnded(); |
|
268 } |
|
269 } |
|
270 case Qt::GestureUpdated: |
|
271 case Qt::GestureCanceled: |
|
272 default: |
|
273 stopLongPressWatcher(); |
|
274 break; |
|
275 } |
|
276 |
|
277 handleGesture = true; |
|
278 } else { |
|
279 if (state == Qt::GestureFinished) { |
|
280 mSpring.resetVelocity(); |
|
281 mSpring.cancel(); |
|
282 update(); |
|
283 emit emptySpacePressed(); |
|
284 } |
|
285 } |
|
286 return handleGesture; |
|
287 } |
|
288 |
|
289 bool HgGridContainer::handleLongTap(Qt::GestureState state, const QPointF &pos) |
|
290 { |
|
291 // HContainer handles the long tap if there is item at the pos. |
|
292 bool handled = HgContainer::handleLongTap(state,pos); |
|
293 if (!handled && state == Qt::GestureFinished) { |
|
294 mSpring.resetVelocity(); |
|
295 mSpring.cancel(); |
|
296 update(); |
|
297 emit emptySpacePressed(); |
|
298 } |
|
299 return handled; |
|
300 } |
|
301 |
|
302 void HgGridContainer::setPinchEnabled(bool pinchEnabled) |
|
303 { |
|
304 if (mPinchEnabled != pinchEnabled) { |
|
305 mPinchEnabled = pinchEnabled; |
|
306 if (mPinchEnabled) { |
|
307 grabGesture(Qt::PinchGesture); |
|
308 iFadeAnimation.setTargetObject(this); |
|
309 iFadeAnimation.setPropertyName("opacity"); |
|
310 iFadeAnimation.setDuration(500); |
|
311 iFadeAnimation.setStartValue(1.0); |
|
312 iFadeAnimation.setEndValue(0.0); |
|
313 connect(&iFadeAnimation, SIGNAL(finished()), SLOT(effectFinished())); |
|
314 |
|
315 } else { |
|
316 iFadeAnimation.stop(); |
|
317 setOpacity(1); |
|
318 disconnect(&iFadeAnimation,SIGNAL(finished()), this, SLOT(effectFinished())); |
|
319 ungrabGesture(Qt::PinchGesture); |
|
320 } |
|
321 } |
|
322 } |
|
323 |
|
324 bool HgGridContainer::pinchEnabled() const |
|
325 { |
|
326 return mPinchEnabled; |
|
327 } |
|
328 |
|
329 void HgGridContainer::mousePressEvent(QGraphicsSceneMouseEvent *event) |
|
330 { |
|
331 if(event->type() == QEvent::GraphicsSceneMousePress) |
|
332 { |
|
333 //reset, just in case |
|
334 mPinchingOngoing = false; |
|
335 mPinchEndAlreadyHandled = false; |
|
336 mTempImageHeightForLineGrid = -1; |
|
337 mTempImageHeightFinal = -1; |
|
338 } |
|
339 } |
|
340 |
|
341 void HgGridContainer::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) |
|
342 { |
|
343 if(event->type() == QEvent::GraphicsSceneMouseRelease) |
|
344 { |
|
345 handlePinchEnd(); |
|
346 } |
|
347 } |
|
348 |
|
349 void HgGridContainer::gestureEvent(QGestureEvent* event) |
|
350 { |
|
351 if (mItems.count() == 0) { |
|
352 // we have no items so no need to handle the gesture. |
|
353 event->ignore(); |
|
354 return; |
|
355 } |
|
356 |
|
357 if (!mPinchingOngoing) { |
|
358 HgContainer::gestureEvent(event); |
|
359 } |
|
360 |
|
361 bool eventHandled(false); |
|
362 |
|
363 QGesture* pinchGesture = event->gesture(Qt::PinchGesture); |
|
364 if(mPinchEnabled && !mReactToOnlyPanGestures && pinchGesture) |
|
365 { |
|
366 HbPinchGesture* pinch = static_cast<HbPinchGesture *>(pinchGesture); |
|
367 switch (pinch->state()) |
|
368 { |
|
369 case Qt::GestureUpdated: |
|
370 handlePinchUpdate( pinch ); |
|
371 break; |
|
372 case Qt::GestureStarted: |
|
373 mTempRowCount = -1; //reset, just in case |
|
374 mTempImageHeightForLineGrid = -1; //reset, just in case |
|
375 mTempImageHeightFinal = -1; //reset, just in case |
|
376 iTargetRowCountList.clear(); |
|
377 mPinchingOngoing = true; |
|
378 mPinchEndAlreadyHandled = false; |
|
379 break; |
|
380 case Qt::GestureCanceled: |
|
381 mPinchingOngoing = false; |
|
382 mPinchEndAlreadyHandled = true; |
|
383 update(); //redraw |
|
384 break; |
|
385 case Qt::GestureFinished: |
|
386 handlePinchEnd(); |
|
387 break; |
|
388 default: |
|
389 break; |
|
390 } |
|
391 |
|
392 eventHandled = true; |
|
393 } |
|
394 |
|
395 eventHandled ? event->accept() : event->ignore(); |
|
396 } |
|
397 |
|
398 void HgGridContainer::handlePinchUpdate(HbPinchGesture* pinch) |
|
399 { |
|
400 // while user is scaling down scale factor changes from 1 -> 0. When scaling up scale factor |
|
401 // changes from 1 -> x |
|
402 qreal change = 0.0; |
|
403 qreal scaleFactor = pinch->scaleFactor();// + pinch->lastScaleFactor())/2; |
|
404 if (scaleFactor < 1) { |
|
405 change = -5*(1-scaleFactor); |
|
406 } else { |
|
407 change = scaleFactor - 1; |
|
408 } |
|
409 |
|
410 qreal wannaBeRowCount = mRenderer->getRowCount() + change*1.5; |
|
411 |
|
412 int minRowCount = scrollDirection() == Qt::Horizontal ? |
|
413 mHorizontalPinchLevels.first : mVerticalPinchLevels.first; |
|
414 int maxRowCount = scrollDirection() == Qt::Horizontal ? |
|
415 mHorizontalPinchLevels.second : mVerticalPinchLevels.second; |
|
416 |
|
417 if(wannaBeRowCount < minRowCount) { |
|
418 wannaBeRowCount = minRowCount; |
|
419 } |
|
420 else if(wannaBeRowCount > maxRowCount) { |
|
421 wannaBeRowCount = maxRowCount; |
|
422 } |
|
423 |
|
424 mTempRowCount = (int)wannaBeRowCount; |
|
425 |
|
426 while (iTargetRowCountList.count() >= 4) { |
|
427 iTargetRowCountList.dequeue(); |
|
428 } |
|
429 |
|
430 iTargetRowCountList.enqueue(wannaBeRowCount); |
|
431 |
|
432 |
|
433 qreal averageRowCount = 0; |
|
434 int count = iTargetRowCountList.count(); |
|
435 if (count >= 2 ) { |
|
436 averageRowCount += iTargetRowCountList.at(count-1); |
|
437 averageRowCount += iTargetRowCountList.at(count-2); |
|
438 averageRowCount /= 2; |
|
439 } else { |
|
440 averageRowCount = wannaBeRowCount; |
|
441 } |
|
442 |
|
443 if (scrollDirection() == Qt::Horizontal ) { |
|
444 int centerAreaheight = mUserItemSize.height()*mHorizontalRowCount; |
|
445 mTempImageHeightForLineGrid = (centerAreaheight - ((int)averageRowCount + 1) * mRenderer->getSpacing().height()) / averageRowCount; |
|
446 } else { |
|
447 mTempImageHeightForLineGrid = (rect().width() - ((int)averageRowCount + 1) * mRenderer->getSpacing().width()) / averageRowCount; |
|
448 } |
|
449 |
|
450 update(); //redraw |
|
451 } |
|
452 |
|
453 void HgGridContainer::handlePinchEnd() |
|
454 { |
|
455 if(mPinchingOngoing && !mPinchEndAlreadyHandled) { |
|
456 mPinchingOngoing = false; |
|
457 mPinchEndAlreadyHandled = true; |
|
458 |
|
459 qreal averageRowCount = 0; |
|
460 int count = iTargetRowCountList.count(); |
|
461 while (!iTargetRowCountList.isEmpty()) { |
|
462 qreal value = iTargetRowCountList.dequeue(); |
|
463 averageRowCount += value; |
|
464 } |
|
465 |
|
466 averageRowCount /= count; |
|
467 |
|
468 qreal temp = floorf(averageRowCount); |
|
469 averageRowCount = (averageRowCount - temp > 0.5f) ? ceilf(averageRowCount) : temp; |
|
470 mTempRowCount = averageRowCount; |
|
471 |
|
472 // change the row count if it has been changed by pinching |
|
473 if ( (mTempRowCount != -1) |
|
474 && (mTempRowCount != mRenderer->getRowCount()) ) { |
|
475 |
|
476 if (scrollDirection() == Qt::Horizontal ) { |
|
477 int centerAreaheight = mUserItemSize.height()*mHorizontalRowCount; |
|
478 mTempImageHeightFinal = (centerAreaheight - ((int)mTempRowCount + 1) * mRenderer->getSpacing().height()) / (int)mTempRowCount; |
|
479 } else { |
|
480 mTempImageHeightFinal = (rect().width() - ((int)mTempRowCount + 1) * mRenderer->getSpacing().width()) / (int)mTempRowCount; |
|
481 } |
|
482 |
|
483 mTargetRowCount = mTempRowCount; |
|
484 mTargetImageSize = QSizeF(mTempImageHeightFinal,mTempImageHeightFinal); |
|
485 iFadeAnimation.setDirection(QAbstractAnimation::Forward); |
|
486 iFadeAnimation.start(); |
|
487 } |
|
488 } |
|
489 } |
|
490 |
|
491 bool HgGridContainer::event(QEvent *e) |
|
492 { |
|
493 if (e->type() == QEvent::TouchBegin) |
|
494 { |
|
495 // The TouchBegin event must be accepted (i.e. return true) to be able to receive Pinch events. |
|
496 return true; |
|
497 } |
|
498 else if(e->type() == QEvent::Gesture) |
|
499 { |
|
500 // Since pinch gesture is not forwarded to |
|
501 // gestureEvent function so lets handle it here. |
|
502 QGestureEvent* gesture = static_cast<QGestureEvent*>(e); |
|
503 gestureEvent(gesture); |
|
504 return true; |
|
505 } |
|
506 |
|
507 return QGraphicsObject::event(e); |
|
508 } |
|
509 |
|
510 void HgGridContainer::effectFinished() |
|
511 { |
|
512 if (iFadeAnimation.direction() == QAbstractAnimation::Forward) { |
|
513 mRenderer->setRowCount(mTargetRowCount, mTargetImageSize); |
|
514 mRenderer->setImageSize(mTargetImageSize); |
|
515 // mSpring.setDamping( mTargetRowCount != 3 ? |
|
516 // KSpringDampingScrolling*(mTargetRowCount-3)*4 : KSpringDampingScrolling ); |
|
517 // mSpring.setK( mTargetRowCount != 3 ? |
|
518 // KSpringKScrolling/((mTargetRowCount-3)*4) : KSpringKScrolling ); |
|
519 scrollTo(mSelectionModel->currentIndex()); |
|
520 iFadeAnimation.setDirection(QAbstractAnimation::Backward); |
|
521 iFadeAnimation.start(); |
|
522 } |
|
523 } |
|
524 |
|
525 void HgGridContainer::setRowCount(int count, Qt::Orientation scrollDirection) |
|
526 { |
|
527 if (scrollDirection == Qt::Horizontal) { |
|
528 mHorizontalRowCount = count; |
|
529 } else { |
|
530 mVerticalColumnCount = count; |
|
531 } |
|
532 } |
|
533 |
|
534 int HgGridContainer::rowCount(Qt::Orientation scrollDirection) const |
|
535 { |
|
536 return scrollDirection == Qt::Horizontal ? mHorizontalRowCount : mVerticalColumnCount; |
|
537 } |
|
538 |
|
539 void HgGridContainer::setOrientation(Qt::Orientation orientation, bool animate) |
|
540 { |
|
541 HgContainer::setOrientation(orientation, animate); |
|
542 |
|
543 if (orientation == Qt::Horizontal) { |
|
544 mRenderer->enableReflections(false); |
|
545 mRenderer->setImageSize(mUserItemSize); |
|
546 if (currentRowCount() != mHorizontalRowCount) { |
|
547 mRenderer->setRowCount(mHorizontalRowCount, mUserItemSize, false); |
|
548 scrollTo(mSelectionModel->currentIndex()); |
|
549 } |
|
550 } else { |
|
551 mRenderer->enableReflections(false); |
|
552 mRenderer->setImageSize(mUserItemSize); |
|
553 if (currentRowCount() != mVerticalColumnCount) { |
|
554 mRenderer->setRowCount(mVerticalColumnCount, mUserItemSize, false); |
|
555 scrollTo(mSelectionModel->currentIndex()); |
|
556 } |
|
557 } |
|
558 } |
|
559 |
|
560 void HgGridContainer::setPinchLevels(QPair<int,int> levels, Qt::Orientation scrollDirection) |
|
561 { |
|
562 if (scrollDirection == Qt::Horizontal) { |
|
563 mHorizontalPinchLevels = levels; |
|
564 } else { |
|
565 mVerticalPinchLevels = levels; |
|
566 } |
|
567 } |
|
568 |
|
569 QPair<int,int> HgGridContainer::pinchLevels(Qt::Orientation scrollDirection) const |
|
570 { |
|
571 return scrollDirection == Qt::Horizontal ? |
|
572 mHorizontalPinchLevels : mVerticalPinchLevels; |
|
573 } |
|
574 |
|
575 // End of file |