|
1 /* |
|
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <QGesture> |
|
19 #include <QPainter> |
|
20 #include <QTimer> |
|
21 #include <hblabel.h> |
|
22 #include <hbgridviewitem> |
|
23 #include <hbmainwindow> |
|
24 #include "hggridcontainer.h" |
|
25 #include "hgmediawallrenderer.h" |
|
26 #include "hgquad.h" |
|
27 #include "hgvgquadrenderer.h" |
|
28 #include "hgvgimage.h" |
|
29 #include "hgwidgetitem.h" |
|
30 #include "trace.h" |
|
31 |
|
32 #include <hbgridviewitem> |
|
33 #include <hbgridview> |
|
34 #include <hbiconitem> |
|
35 #include <qabstractitemmodel> |
|
36 #include "hglongpressvisualizer.h" |
|
37 |
|
38 |
|
39 static const qreal KCameraMaxYAngle(20); |
|
40 static const qreal KSpringVelocityToCameraYAngleFactor(2); |
|
41 |
|
42 HgGridContainer::HgGridContainer(QGraphicsItem *parent) : HgContainer(parent) |
|
43 { |
|
44 |
|
45 } |
|
46 |
|
47 HgGridContainer::~HgGridContainer() |
|
48 { |
|
49 |
|
50 } |
|
51 |
|
52 void HgGridContainer::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
53 { |
|
54 HgContainer::paint(painter, option, widget); |
|
55 |
|
56 updateSelectedItem(); |
|
57 } |
|
58 |
|
59 HgMediaWallRenderer* HgGridContainer::createRenderer() |
|
60 { |
|
61 |
|
62 HgMediaWallRenderer* renderer = new HgMediaWallRenderer(this); |
|
63 renderer->enableCoverflowMode(false); |
|
64 renderer->setImageSize(QSizeF(105, 80)); |
|
65 renderer->setRowCount(3, renderer->getImageSize(), false); |
|
66 renderer->enableReflections(false); |
|
67 renderer->setSpacing(QSizeF(1,1)); |
|
68 renderer->setFrontCoverElevationFactor(0.5); |
|
69 |
|
70 return renderer; |
|
71 } |
|
72 |
|
73 qreal HgGridContainer::getCameraDistance(qreal springVelocity) |
|
74 { |
|
75 if (mRenderer->getOrientation() == Qt::Vertical) |
|
76 return 0; |
|
77 |
|
78 return qAbs(springVelocity * 0.01f); |
|
79 } |
|
80 |
|
81 qreal HgGridContainer::getCameraRotationY(qreal springVelocity) |
|
82 { |
|
83 if (mRenderer->getOrientation() == Qt::Vertical) |
|
84 return 0; |
|
85 |
|
86 return qBound(-KCameraMaxYAngle, springVelocity * KSpringVelocityToCameraYAngleFactor, KCameraMaxYAngle); |
|
87 } |
|
88 |
|
89 void HgGridContainer::handleTapAction(const QPointF& pos, HgWidgetItem* hitItem, int hitItemIndex) |
|
90 { |
|
91 Q_UNUSED(pos) |
|
92 Q_UNUSED(hitItemIndex) |
|
93 |
|
94 selectItem(); |
|
95 emit activated(hitItem->modelIndex()); |
|
96 } |
|
97 |
|
98 void HgGridContainer::handleLongTapAction(const QPointF& pos, HgWidgetItem* hitItem, int hitItemIndex) |
|
99 { |
|
100 Q_UNUSED(hitItemIndex) |
|
101 |
|
102 selectItem(); |
|
103 emit longPressed(hitItem->modelIndex(), pos); |
|
104 } |