35 mDescriptionLabel(0), |
35 mDescriptionLabel(0), |
36 mTitlePosition(HgMediawall::PositionAboveImage), |
36 mTitlePosition(HgMediawall::PositionAboveImage), |
37 mDescriptionPosition(HgMediawall::PositionNone), |
37 mDescriptionPosition(HgMediawall::PositionNone), |
38 mPrevPos(-1), |
38 mPrevPos(-1), |
39 mAspectRatio(1), |
39 mAspectRatio(1), |
40 mDrawableRect(rect()) |
40 mAnimationAboutToEndReacted(false) |
41 { |
41 { |
42 mTitleLabel = new HbLabel(this); |
42 mTitleLabel = new HbLabel(this); |
43 mTitleLabel->setZValue(zValue()+1); |
43 mTitleLabel->setZValue(zValue()+1); |
44 mTitleLabel->setAlignment(Qt::AlignCenter); |
44 mTitleLabel->setAlignment(Qt::AlignCenter); |
45 mTitleLabel->setVisible(false); |
45 mTitleLabel->setVisible(false); |
46 |
46 |
47 mDescriptionLabel = new HbLabel(this); |
47 mDescriptionLabel = new HbLabel(this); |
48 mDescriptionLabel->setZValue(zValue()+1); |
48 mDescriptionLabel->setZValue(zValue()+1); |
49 mDescriptionLabel->setAlignment(Qt::AlignCenter); |
49 mDescriptionLabel->setAlignment(Qt::AlignCenter); |
50 mDescriptionLabel->setVisible(false); |
50 mDescriptionLabel->setVisible(false); |
51 |
51 |
52 mUserItemSize = QSize(250,250); |
52 mUserItemSize = QSize(250,250); |
53 mUserItemSpacing = QSize(1,1); |
53 mUserItemSpacing = QSize(1,1); |
54 } |
54 } |
55 |
55 |
56 HgCoverflowContainer::~HgCoverflowContainer() |
56 HgCoverflowContainer::~HgCoverflowContainer() |
58 } |
58 } |
59 |
59 |
60 // events |
60 // events |
61 void HgCoverflowContainer::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
61 void HgCoverflowContainer::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
62 { |
62 { |
|
63 painter->setRenderHint(QPainter::Antialiasing, true); |
63 HgContainer::paint(painter, option, widget); |
64 HgContainer::paint(painter, option, widget); |
|
65 painter->setRenderHint(QPainter::Antialiasing, false); |
64 } |
66 } |
65 |
67 |
66 void HgCoverflowContainer::resizeEvent(QGraphicsSceneResizeEvent *event) |
68 void HgCoverflowContainer::resizeEvent(QGraphicsSceneResizeEvent *event) |
67 { |
69 { |
68 FUNC_LOG; |
70 FUNC_LOG; |
69 |
71 |
70 HbWidget::resizeEvent(event); |
72 HbWidget::resizeEvent(event); |
71 |
73 |
72 updatePositions(); |
74 updatePositions(); |
73 } |
75 } |
74 |
76 |
75 // from HgContainer |
77 // from HgContainer |
76 HgMediaWallRenderer* HgCoverflowContainer::createRenderer(Qt::Orientation scrollDirection) |
78 HgMediaWallRenderer* HgCoverflowContainer::createRenderer(Qt::Orientation scrollDirection) |
77 { |
79 { |
78 HgMediaWallRenderer* renderer = new HgMediaWallRenderer(this, scrollDirection, true); |
80 HgMediaWallRenderer* renderer = new HgMediaWallRenderer(this, scrollDirection, scrollDirection, true); |
79 renderer->setImageSize(mUserItemSize); |
81 renderer->setImageSize(mUserItemSize); |
80 renderer->enableCoverflowMode(true); |
82 renderer->enableCoverflowMode(true); |
81 renderer->setRowCount(1, renderer->getImageSize(), false); |
83 renderer->setRowCount(1, renderer->getImageSize(), false); |
82 renderer->enableReflections(true); |
84 renderer->enableReflections(true); |
83 renderer->setSpacing(mUserItemSpacing); |
85 renderer->setSpacing(mUserItemSpacing); |
118 |
120 |
119 void HgCoverflowContainer::onScrollPositionChanged(qreal pos) |
121 void HgCoverflowContainer::onScrollPositionChanged(qreal pos) |
120 { |
122 { |
121 HgContainer::onScrollPositionChanged(pos); |
123 HgContainer::onScrollPositionChanged(pos); |
122 |
124 |
|
125 if(!mAnimationAboutToEndReacted) { |
|
126 qreal endPos = mSpring.endPos().x(); |
|
127 qreal abs = qAbs(endPos - mSpring.pos().x()); |
|
128 |
|
129 if( abs <= 0.5f ) { |
|
130 HgWidgetItem* item = itemByIndex((int)endPos); |
|
131 if (item) { |
|
132 emit animationAboutToEnd( item->modelIndex() ); |
|
133 mAnimationAboutToEndReacted = true; |
|
134 } |
|
135 } |
|
136 } |
|
137 |
123 qreal ipos = floorf(pos); |
138 qreal ipos = floorf(pos); |
124 qreal frac = pos - ipos; |
139 qreal frac = pos - ipos; |
125 qreal p = frac > 0.5 ? ipos + 1.0f : ipos; |
140 qreal p = frac > 0.5 ? ipos + 1.0f : ipos; |
126 |
141 |
127 if (mPrevPos != (int)p) { |
142 if (mPrevPos != (int)p) { |
128 mPrevPos = (int)p; |
143 mPrevPos = (int)p; |
129 HgWidgetItem* item = itemByIndex((int)p); |
144 HgWidgetItem* item = itemByIndex((int)p); |
130 if (item && item->modelIndex() != mSelectionModel->currentIndex()) { |
145 if (item && item->modelIndex() != mSelectionModel->currentIndex()) { |
131 mSelectionModel->setCurrentIndex(item->modelIndex(), QItemSelectionModel::Current); |
146 mSelectionModel->setCurrentIndex(item->modelIndex(), QItemSelectionModel::Current); |
132 } |
147 } |
133 } |
148 } |
|
149 } |
|
150 |
|
151 void HgCoverflowContainer::onScrollingStarted() |
|
152 { |
|
153 mAnimationAboutToEndReacted = false; //reset |
|
154 } |
|
155 |
|
156 void HgCoverflowContainer::onScrollingEnded() |
|
157 { |
|
158 mAnimationAboutToEndReacted = false; //reset |
134 } |
159 } |
135 |
160 |
136 void HgCoverflowContainer::handleCurrentChanged(const QModelIndex ¤t) |
161 void HgCoverflowContainer::handleCurrentChanged(const QModelIndex ¤t) |
137 { |
162 { |
138 FUNC_LOG; |
163 FUNC_LOG; |
254 } |
279 } |
255 if (mDescriptionPosition != HgMediawall::PositionNone) { |
280 if (mDescriptionPosition != HgMediawall::PositionNone) { |
256 usableHeight -= (descriptionHeight+KLabelMargin); |
281 usableHeight -= (descriptionHeight+KLabelMargin); |
257 } |
282 } |
258 |
283 |
259 usableHeight *= 0.8; // Leave some space for the reflection |
|
260 if (usableHeight <= 0) return; |
284 if (usableHeight <= 0) return; |
261 |
285 |
262 qreal usableWidth = width/2; |
286 qreal usableWidth = width/1.4; |
263 if (usableWidth <= 0) return; |
287 if (usableWidth <= 0) return; |
264 |
288 |
265 mDrawableRect = rect(); |
289 QRectF imageRect = rect(); |
266 QSizeF imageSize; |
|
267 if (usableWidth/usableHeight > mAspectRatio) { |
290 if (usableWidth/usableHeight > mAspectRatio) { |
268 imageSize.setHeight(usableHeight); |
291 imageRect.setHeight(usableHeight); |
269 imageSize.setWidth(mAspectRatio*usableHeight); |
292 imageRect.setWidth(mAspectRatio*usableHeight); |
|
293 imageRect.moveLeft((width-imageRect.width())/2); |
270 } |
294 } |
271 else { |
295 else { |
272 imageSize.setWidth(usableWidth); |
296 imageRect.setWidth(usableWidth); |
273 imageSize.setHeight(usableWidth/mAspectRatio); |
297 imageRect.setHeight(usableWidth/mAspectRatio); |
274 mDrawableRect.setTop((usableHeight-imageSize.height())/2); |
298 imageRect.moveTop((usableHeight-imageRect.height())/2); |
275 } |
299 imageRect.moveLeft((width-imageRect.width())/2); |
276 |
300 } |
277 QRectF titleGeometry(0, mDrawableRect.top()+KLabelMargin, width, titleHeight); |
301 |
278 QRectF descriptionGeometry(0, mDrawableRect.top()+KLabelMargin, width, descriptionHeight); |
302 QRectF titleGeometry(0, imageRect.top()+KLabelMargin, width, titleHeight); |
|
303 QRectF descriptionGeometry(0, imageRect.top()+KLabelMargin, width, descriptionHeight); |
279 |
304 |
280 if (mTitlePosition == HgMediawall::PositionAboveImage && |
305 if (mTitlePosition == HgMediawall::PositionAboveImage && |
281 mDescriptionPosition == HgMediawall::PositionAboveImage) { |
306 mDescriptionPosition == HgMediawall::PositionAboveImage) { |
282 // titleGeometry default is ok |
307 // titleGeometry default is ok |
283 descriptionGeometry.moveTop(titleGeometry.bottom()+KLabelMargin); |
308 descriptionGeometry.moveTop(titleGeometry.bottom()+KLabelMargin); |
284 mDrawableRect.setTop(descriptionGeometry.bottom()+KLabelMargin); |
309 imageRect.moveTop(descriptionGeometry.bottom()+KLabelMargin); |
285 } |
310 } |
286 else if (mTitlePosition == HgMediawall::PositionBelowImage && |
311 else if (mTitlePosition == HgMediawall::PositionBelowImage && |
287 mDescriptionPosition == HgMediawall::PositionBelowImage) { |
312 mDescriptionPosition == HgMediawall::PositionBelowImage) { |
288 titleGeometry.moveTop(mDrawableRect.top()+imageSize.height()+KLabelMargin); |
313 titleGeometry.moveTop(imageRect.bottom()+KLabelMargin); |
289 descriptionGeometry.moveTop(titleGeometry.bottom()+KLabelMargin); |
314 descriptionGeometry.moveTop(titleGeometry.bottom()+KLabelMargin); |
290 } |
315 } |
291 else { |
316 else { |
292 if (mTitlePosition == HgMediawall::PositionAboveImage) { |
317 if (mTitlePosition == HgMediawall::PositionAboveImage) { |
293 // titleGeometry default is ok |
318 // titleGeometry default is ok |
294 mDrawableRect.setTop(titleGeometry.bottom()+KLabelMargin); |
319 imageRect.moveTop(titleGeometry.bottom()+KLabelMargin); |
295 } |
320 } |
296 else if (mDescriptionPosition == HgMediawall::PositionAboveImage) { |
321 else if (mDescriptionPosition == HgMediawall::PositionAboveImage) { |
297 // descriptionGeometry default is ok |
322 // descriptionGeometry default is ok |
298 mDrawableRect.setTop(descriptionGeometry.bottom()+KLabelMargin); |
323 imageRect.moveTop(descriptionGeometry.bottom()+KLabelMargin); |
299 } |
324 } |
300 |
325 |
301 if (mTitlePosition == HgMediawall::PositionBelowImage) { |
326 if (mTitlePosition == HgMediawall::PositionBelowImage) { |
302 titleGeometry.moveTop(mDrawableRect.top()+imageSize.height()+KLabelMargin); |
327 titleGeometry.moveTop(imageRect.bottom()+KLabelMargin); |
303 } |
328 } |
304 else if (mDescriptionPosition == HgMediawall::PositionBelowImage) { |
329 else if (mDescriptionPosition == HgMediawall::PositionBelowImage) { |
305 descriptionGeometry.moveTop(mDrawableRect.top()+imageSize.height()+KLabelMargin); |
330 descriptionGeometry.moveTop(imageRect.bottom()+KLabelMargin); |
306 } |
331 } |
307 } |
332 } |
308 |
333 |
309 INFO("Setting image size to:" << imageSize << "(total size:" << QSize(width, height) |
334 INFO("Setting image rect to:" << imageRect << "(total size:" << QSize(width, height) |
310 << "usable size:" << QSizeF(usableWidth, usableHeight) << ", aspect ratio is:" << mAspectRatio << ")" << "Drawable rect:" << mDrawableRect); |
335 << "usable size:" << QSizeF(usableWidth, usableHeight) << ", aspect ratio is:" << mAspectRatio << ")"); |
311 mRenderer->setImageSize(imageSize); |
336 |
312 mAutoSize = imageSize; |
337 mRenderer->setImageSize(imageRect.size()); |
313 mDrawableRect.setHeight(imageSize.height()/0.8); |
338 qreal diff = rect().center().y()-imageRect.center().y(); |
|
339 |
|
340 INFO("Setting front item position to:" << QPointF(0, -diff) << "(rect:" << rect() |
|
341 << "imageRect:" << imageRect << ")"); |
|
342 mRenderer->setFrontItemPosition(QPointF(0, -diff)); |
|
343 |
|
344 mAutoSize = imageRect.size(); |
314 |
345 |
315 if (mTitlePosition != HgMediawall::PositionNone) { |
346 if (mTitlePosition != HgMediawall::PositionNone) { |
316 INFO("Title geometry:" << titleGeometry); |
347 INFO("Title geometry:" << titleGeometry); |
317 mTitleLabel->setGeometry(titleGeometry); |
348 mTitleLabel->setGeometry(titleGeometry); |
318 mTitleLabel->setVisible(true); |
349 mTitleLabel->setVisible(true); |
331 |
362 |
332 // This may be called before selection model is set. |
363 // This may be called before selection model is set. |
333 if (mSelectionModel && mSelectionModel->currentIndex().isValid()) { |
364 if (mSelectionModel && mSelectionModel->currentIndex().isValid()) { |
334 updateLabels(mSelectionModel->currentIndex().row()); |
365 updateLabels(mSelectionModel->currentIndex().row()); |
335 } |
366 } |
336 |
367 |
337 mRenderer->setSpacing(QSizeF(1,1)); |
368 mRenderer->setSpacing(QSizeF(1,1)); |
338 |
369 |
339 } |
370 } |
340 |
371 |
341 void HgCoverflowContainer::positionLabels() |
372 void HgCoverflowContainer::positionLabels() |
342 { |
373 { |
343 FUNC_LOG; |
374 FUNC_LOG; |
344 HANDLE_ERROR_NULL(mTitleLabel); |
375 HANDLE_ERROR_NULL(mTitleLabel); |
345 HANDLE_ERROR_NULL(mDescriptionLabel); |
376 HANDLE_ERROR_NULL(mDescriptionLabel); |
346 HANDLE_ERROR_NULL(mSelectionModel); |
|
347 |
377 |
348 int centerIconTop = (size().height() - mRenderer->getImageSize().height()) / 2; |
378 int centerIconTop = (size().height() - mRenderer->getImageSize().height()) / 2; |
349 |
379 |
350 int height = size().height(); |
380 int height = size().height(); |
351 int width = size().width(); |
381 int width = size().width(); |