|
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 #ifndef HGCONTAINER_H |
|
19 #define HGCONTAINER_H |
|
20 |
|
21 #include <QTime> |
|
22 #include <hbwidget.h> |
|
23 #include <hgwidgets/hgwidgets.h> |
|
24 |
|
25 #include "hgmediawalldataprovider.h" |
|
26 #include "hgdrag.h" |
|
27 #include "hgspring.h" |
|
28 |
|
29 class HgWidgetItem; |
|
30 class HgQuadRenderer; |
|
31 class HgMediaWallRenderer; |
|
32 class QPanGesture; |
|
33 class HbAbstractViewItem; |
|
34 class HbGestureSceneFilter; |
|
35 class HgLongPressVisualizer; |
|
36 |
|
37 class HgContainer: public HbWidget, public HgMediaWallDataProvider |
|
38 { |
|
39 Q_OBJECT |
|
40 Q_DISABLE_COPY(HgContainer) |
|
41 |
|
42 public: |
|
43 explicit HgContainer(QGraphicsItem* parent = 0); |
|
44 virtual ~HgContainer(); |
|
45 |
|
46 void setItemCount(int count); |
|
47 int itemCount() const; |
|
48 int rowCount() const; |
|
49 |
|
50 QList<HgWidgetItem*> items() const; |
|
51 HgWidgetItem* itemByIndex(const QModelIndex &index) const; |
|
52 HgWidgetItem* itemByIndex(const int &index) const; |
|
53 |
|
54 void setSelectionModel(QItemSelectionModel *selectionModel); |
|
55 QItemSelectionModel *selectionModel() const; |
|
56 void setSelectionMode(HgWidget::SelectionMode mode, bool resetSelection); |
|
57 HgWidget::SelectionMode selectionMode() const; |
|
58 |
|
59 void dimensions(qreal &screenSize, qreal &worldSize); |
|
60 Qt::Orientation orientation() const; |
|
61 void setOrientation(Qt::Orientation orientation, bool animate=true); |
|
62 |
|
63 // new size for the widget. calls resize. |
|
64 void scrollToPosition(qreal value, bool animate = false); |
|
65 virtual void scrollToPosition(const QPointF& pos, bool animate); |
|
66 void scrollTo(const QModelIndex &index); |
|
67 |
|
68 void itemDataChanged(const QModelIndex &firstIndex, const QModelIndex &lastIndex); |
|
69 |
|
70 void addItems(int start, int end); |
|
71 void removeItems(int start, int end); |
|
72 void moveItems(int start, int end, int destination); |
|
73 |
|
74 bool getItemPoints(int index, QPolygonF& points); |
|
75 |
|
76 QList<QModelIndex> getVisibleItemIndices() const; |
|
77 |
|
78 virtual void itemDataChanged(const int &firstIndex, const int &lastIndex); |
|
79 |
|
80 void init(Qt::Orientation scrollDirection); |
|
81 |
|
82 signals: |
|
83 |
|
84 // emit this signal when scrolling. for example scrollbar can be connected to this signal. |
|
85 void scrollPositionChanged(qreal value, bool scrollBarAnimation); |
|
86 void centerItemChanged(const QModelIndex &index); |
|
87 void activated(const QModelIndex &index); |
|
88 void longPressed(const QModelIndex &index, const QPointF &coords); |
|
89 void scrollingStarted(); |
|
90 void scrollingEnded(); |
|
91 |
|
92 private slots: |
|
93 |
|
94 void updateBySpringPosition(); |
|
95 void redraw(); |
|
96 void updateLongPressVisualizer(); |
|
97 void updateByCurrentIndex(const QModelIndex ¤t); |
|
98 void onScrollingEnded(); |
|
99 |
|
100 protected: // from HgMediaWallDataProvider |
|
101 |
|
102 int imageCount() const; |
|
103 const HgImage *image(int index) const; |
|
104 int flags(int index) const; |
|
105 const HgImage *indicator(int flags) const; |
|
106 |
|
107 protected: // events |
|
108 |
|
109 virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); |
|
110 |
|
111 virtual void resizeEvent(QGraphicsSceneResizeEvent *event); |
|
112 |
|
113 // this needs to be implemented for gesture framework to work |
|
114 virtual void mousePressEvent(QGraphicsSceneMouseEvent *event); |
|
115 // From HbWidget for gestures. |
|
116 virtual void gestureEvent(QGestureEvent *event); |
|
117 protected: |
|
118 |
|
119 virtual HgMediaWallRenderer* createRenderer()=0; |
|
120 virtual qreal getCameraDistance(qreal springVelocity); |
|
121 virtual qreal getCameraRotationY(qreal springVelocity); |
|
122 virtual void handleTapAction(const QPointF& pos, HgWidgetItem* hitItem, int hitItemIndex); |
|
123 virtual void handleLongTapAction(const QPointF& pos, HgWidgetItem* hitItem, int hitItemIndex); |
|
124 virtual void onScrollPositionChanged(qreal pos); |
|
125 virtual void handleCurrentChanged(const QModelIndex ¤t); |
|
126 |
|
127 protected: |
|
128 |
|
129 enum ItemActionType |
|
130 { |
|
131 LongTap = 1, |
|
132 DoubleTap, |
|
133 NormalTap, |
|
134 TapStart, |
|
135 LongTapStart |
|
136 }; |
|
137 |
|
138 qreal worldWidth() const; |
|
139 void initSpringForScrollBar(); |
|
140 void initSpringForScrolling(); |
|
141 void boundSpring(); |
|
142 void handlePanning(QPanGesture *gesture); |
|
143 void handleTap(Qt::GestureState state, const QPointF &pos); |
|
144 void handleLongTap(Qt::GestureState state, const QPointF &pos); |
|
145 void handleItemAction(const QPointF &pos, ItemActionType action); |
|
146 |
|
147 void selectItem(); |
|
148 void updateSelectedItem(); |
|
149 void unselectItem(); |
|
150 |
|
151 HgWidgetItem* getItemAt(const QPointF& pos, int& index); |
|
152 void startLongPressWatcher(const QPointF& pos); |
|
153 void stopLongPressWatcher(); |
|
154 bool updateSelectionModel(HgWidgetItem* item); |
|
155 |
|
156 QTransform qtToVgTransform() const; |
|
157 QPointF mapQtToVg(const QPointF& p) const; |
|
158 |
|
159 protected: // data |
|
160 |
|
161 QList<HgWidgetItem *> mItems; |
|
162 //int mRowCount; |
|
163 //int mColumnCount; |
|
164 |
|
165 //HbLabel *mLabel; |
|
166 HgQuadRenderer *mQuadRenderer; |
|
167 HgMediaWallRenderer *mRenderer; |
|
168 |
|
169 HgSpring mSpring; |
|
170 HgDrag mDrag; |
|
171 |
|
172 QTime mTapDuration; // Temp hack until HbTapGesture is available |
|
173 QTime mDoubleTapDuration; |
|
174 int mTapCount; |
|
175 |
|
176 bool mAnimateUsingScrollBar; |
|
177 |
|
178 HgWidget::SelectionMode mSelectionMode; |
|
179 QItemSelectionModel *mSelectionModel; |
|
180 HgImage *mMarkImage; |
|
181 |
|
182 qreal mSpringVelAtDragStart; |
|
183 bool mDragged; |
|
184 int mFramesDragged; |
|
185 |
|
186 HbAbstractViewItem* mHitItemView; |
|
187 QPixmap mHitItemPixmap; |
|
188 |
|
189 HgLongPressVisualizer* mLongPressVisualizer; |
|
190 QTimer* mLongPressTimer; |
|
191 HgWidgetItem* mHitItem; |
|
192 int mHitItemIndex; |
|
193 |
|
194 QPointF mOffsetAtDragStart; |
|
195 QTime mLongTapDuration; |
|
196 bool mScrollBarPressed; |
|
197 |
|
198 }; |
|
199 |
|
200 #endif |