|
1 /* |
|
2 * Copyright (c) 2009 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 #ifndef HGMEDIAWALLRENDERER_H |
|
18 #define HGMEDIAWALLRENDERER_H |
|
19 |
|
20 #include <qmatrix4x4> |
|
21 #include <qobject> |
|
22 |
|
23 class HgQuadRenderer; |
|
24 class HgMediaWallDataProvider; |
|
25 class QPointF; |
|
26 class QPainter; |
|
27 class QTimer; |
|
28 class QStateMachine; |
|
29 class HgAnimatedQuad; |
|
30 class HgQuad; |
|
31 class HgImageFader; |
|
32 class HgImage; |
|
33 class QPolygonF; |
|
34 |
|
35 /** |
|
36 * MediaWall rendering engine class. |
|
37 */ |
|
38 class HgMediaWallRenderer : public QObject |
|
39 { |
|
40 Q_OBJECT |
|
41 Q_PROPERTY(qreal animationAlpha READ animationAlpha WRITE setAnimationAlpha) |
|
42 Q_PROPERTY(qreal stateAnimationAlpha READ stateAnimationAlpha WRITE setStateAnimationAlpha) |
|
43 public: |
|
44 |
|
45 enum OpeningAnimationType |
|
46 { |
|
47 OpeningAnimationFlip, |
|
48 OpeningAnimationZoomIn, |
|
49 OpeningAnimationZoomOver |
|
50 }; |
|
51 |
|
52 explicit HgMediaWallRenderer(HgMediaWallDataProvider* provider); |
|
53 |
|
54 virtual ~HgMediaWallRenderer(); |
|
55 |
|
56 void setCameraDistance(qreal distance); |
|
57 qreal getCameraDistance() const; |
|
58 void setCameraRotationY(qreal angle); |
|
59 qreal getCameraRotationY() const; |
|
60 void setCameraRotationZ(qreal angle); |
|
61 qreal getCameraRotationZ() const; |
|
62 |
|
63 void draw( |
|
64 const QPointF& startPosition, |
|
65 const QPointF& position, |
|
66 const QPointF& targetPosition, |
|
67 qreal springVelocity, |
|
68 QPainter* painter); |
|
69 |
|
70 void setFlipAnimationAngle(qreal angleInDegrees); |
|
71 |
|
72 void setOpeningAnimationType(OpeningAnimationType type); |
|
73 |
|
74 void setOpeningAnimationDuration(int msecs); |
|
75 |
|
76 void setOrientation(Qt::Orientation orientation, bool animate=false); |
|
77 Qt::Orientation getOrientation() const; |
|
78 |
|
79 void enableCoverflowMode(bool enabled); |
|
80 bool coverflowModeEnabled() const; |
|
81 |
|
82 void setRowCount(int rowCount, const QSizeF& newImageSize, bool animate=false); |
|
83 int getRowCount() const; |
|
84 |
|
85 HgQuad* getQuadAt(const QPointF& position) const; |
|
86 |
|
87 void setRect(const QRectF& windowRect); |
|
88 const QRectF& getRect() const; |
|
89 void setSpacing(const QSizeF& spacing); |
|
90 const QSizeF& getSpacing() const; |
|
91 void setImageSize(const QSizeF& imageSize); |
|
92 const QSizeF& getImageSize() const; |
|
93 |
|
94 void setFrontCoverElevationFactor(qreal elevation); |
|
95 qreal getFrontCoverElevationFactor() const; |
|
96 |
|
97 void openItem(int index, bool animate); |
|
98 void closeItem(bool animate); |
|
99 bool isItemOpen() const; |
|
100 |
|
101 void enableReflections(bool enabled); |
|
102 bool reflectionsEnabled() const; |
|
103 |
|
104 qreal getWorldWidth() const; |
|
105 |
|
106 void beginRemoveRows(int start, int end); |
|
107 void endRemoveRows(); |
|
108 |
|
109 int getSelectedItem() const; |
|
110 |
|
111 void initialize(QPainter* painter); |
|
112 bool initialized() const; |
|
113 |
|
114 HgQuadRenderer* getRenderer(); |
|
115 |
|
116 bool getItemPoints(int index, QPolygonF& points) const; |
|
117 |
|
118 QList<HgQuad*> getVisibleQuads() const; |
|
119 |
|
120 signals: |
|
121 void renderingNeeded(); |
|
122 void itemOpened(int index); |
|
123 void itemClosed(int index); |
|
124 void itemMarked(int index); |
|
125 void toggleItem(); |
|
126 void toggleState(); |
|
127 void itemsRemoved(int start, int end); |
|
128 private slots: |
|
129 void onIdleState(); |
|
130 void onOpenedState(); |
|
131 void emitUpdate(); |
|
132 protected: |
|
133 |
|
134 struct State |
|
135 { |
|
136 QList<HgQuad*> mQuads; |
|
137 }; |
|
138 |
|
139 void setAnimationAlpha(qreal alpha); |
|
140 qreal animationAlpha() const; |
|
141 |
|
142 void createStateMachine(); |
|
143 void recordState(State& state); |
|
144 |
|
145 void updateStateAnimation(qreal alpha); |
|
146 void setStateAnimationAlpha(qreal alpha); |
|
147 qreal stateAnimationAlpha() const; |
|
148 void setupStateAnimation(QPainter* painter); |
|
149 |
|
150 void setupRows( |
|
151 const QPointF& startPosition, |
|
152 const QPointF& position, |
|
153 const QPointF& targetPosition, |
|
154 qreal springVelocity, |
|
155 QPainter* painter); |
|
156 |
|
157 void drawQuads(QPainter* painter); |
|
158 void resetQuads(); |
|
159 void updateCameraMatrices(); |
|
160 void updateSpacingAndImageSize(); |
|
161 qreal getRowPosY(int row); |
|
162 qreal getColumnPosX(int column); |
|
163 QPointF mapFromWindow(const QPointF& point) const; |
|
164 void applyOpeningAnimation(HgQuad* quad); |
|
165 void startStateAnimation(QPainter* painter); |
|
166 |
|
167 |
|
168 void setupCoverflow(const QPointF& startPosition, |
|
169 const QPointF& position, |
|
170 const QPointF& targetPosition, |
|
171 qreal springVelocity, |
|
172 QPainter* painter); |
|
173 |
|
174 void setupGridPortrait(const QPointF& startPosition, |
|
175 const QPointF& position, |
|
176 const QPointF& targetPosition, |
|
177 qreal springVelocity, |
|
178 QPainter* painter); |
|
179 |
|
180 void setupGridLandscape(const QPointF& startPosition, |
|
181 const QPointF& position, |
|
182 const QPointF& targetPosition, |
|
183 qreal springVelocity, |
|
184 QPainter* painter); |
|
185 |
|
186 void setupGridRow(qreal posY, int itemIndex, int& quadIndex); |
|
187 void setupGridColumn(qreal posX, int itemIndex, int& quadIndex); |
|
188 void setupDefaultQuad(const QVector3D& pos, int itemIndex, bool reflectionsEnabled, int& quadIndex); |
|
189 void setupIndicator(HgQuad* parent, |
|
190 HgQuad* indicator, const HgImage* indicatorImage, int itemIndex); |
|
191 bool initializeRenderer(QPainter* painter); |
|
192 |
|
193 protected: |
|
194 |
|
195 enum ItemState |
|
196 { |
|
197 ItemClosed, |
|
198 ItemOpening, |
|
199 ItemOpened, |
|
200 ItemClosing |
|
201 }; |
|
202 |
|
203 HgMediaWallDataProvider* mDataProvider; |
|
204 HgQuadRenderer* mRenderer; |
|
205 HgQuadRenderer* mIndicatorRenderer; |
|
206 bool mRendererInitialized; |
|
207 |
|
208 Qt::Orientation mOrientation; |
|
209 Qt::Orientation mNextOrientation; |
|
210 |
|
211 qreal mStateAnimationAlpha; |
|
212 bool mStateAnimationOnGoing; |
|
213 |
|
214 qreal mAnimationAlpha; |
|
215 |
|
216 OpeningAnimationType mOpeningAnimationType; |
|
217 int mOpeningAnimationDuration; |
|
218 int mOpenedItem; |
|
219 int mSelectedItem; |
|
220 qreal mFlipAngle; |
|
221 QTimer* mAnimationTimer; |
|
222 QMatrix4x4 mViewMatrix; |
|
223 QMatrix4x4 mProjMatrix; |
|
224 QStateMachine* mStateMachine; |
|
225 qreal mZoomAmount; |
|
226 bool mCoverflowMode; |
|
227 int mRowCount; |
|
228 int mNextRowCount; |
|
229 |
|
230 QList<HgAnimatedQuad*> mAnimatedQuads; |
|
231 int mStateAnimationDuration; |
|
232 qreal mStep; |
|
233 qreal mZfar; |
|
234 QRectF mRect; |
|
235 |
|
236 QSizeF mSpacing2D; |
|
237 QSizeF mSpacing3D; |
|
238 QSizeF mImageSize2D; |
|
239 QSizeF mImageSize3D; |
|
240 |
|
241 qreal mCameraDistance; |
|
242 qreal mCameraRotationY; |
|
243 qreal mCameraRotationZ; |
|
244 |
|
245 qreal mFrontCoverElevation; |
|
246 |
|
247 State mOldState; |
|
248 State mNextState; |
|
249 |
|
250 |
|
251 bool mReflectionsEnabled; |
|
252 HgImageFader* mImageFader; |
|
253 |
|
254 QSizeF mNextImageSize; |
|
255 |
|
256 bool mItemCountChanged; |
|
257 int mRemoveStart; |
|
258 int mRemoveEnd; |
|
259 int mInsertStart; |
|
260 int mInsertEnd; |
|
261 int mColumnCount; |
|
262 |
|
263 ItemState mOpenedItemState; |
|
264 |
|
265 private: |
|
266 Q_DISABLE_COPY(HgMediaWallRenderer) |
|
267 }; |
|
268 |
|
269 #endif |