|
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: Graphical effects/animations for nmail ui. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "nmuiheaders.h" |
|
19 |
|
20 static const char *NmSendAnimation = ":/effects/mail_send.fxml"; |
|
21 |
|
22 /*! |
|
23 \class NmEffects |
|
24 \brief This class is for launching the effects |
|
25 */ |
|
26 |
|
27 /*! |
|
28 Constructor |
|
29 */ |
|
30 NmUiEffects::NmUiEffects(HbMainWindow &mainWindow) : |
|
31 mMainWindow(mainWindow), |
|
32 mSendAnimationScreenShot(NULL), |
|
33 mDoSendAnimation(false) |
|
34 { |
|
35 NM_FUNCTION; |
|
36 } |
|
37 |
|
38 /*! |
|
39 Destructor |
|
40 */ |
|
41 NmUiEffects::~NmUiEffects() |
|
42 { |
|
43 NM_FUNCTION; |
|
44 |
|
45 // Clean send animation if sendAnimationComplete slot is not called for some reason. |
|
46 // E.g. red key pressed. |
|
47 resetSendAnimation(); |
|
48 } |
|
49 |
|
50 /*! |
|
51 Function will perform needed initializations for selected effect. |
|
52 */ |
|
53 void NmUiEffects::prepareEffect(NmUiEffectType effect) |
|
54 { |
|
55 NM_FUNCTION; |
|
56 |
|
57 switch (effect) { |
|
58 case NmEditorSendMessageAnimation: { |
|
59 // delete any existing stuff |
|
60 resetSendAnimation(); |
|
61 |
|
62 // This effect is for editor send message. Get the screen capture of |
|
63 // editor view for animation which will be lauched soon. |
|
64 mDoSendAnimation = true; |
|
65 |
|
66 // take screen shot |
|
67 mSendAnimationScreenShot = screenShot(); |
|
68 |
|
69 if (mSendAnimationScreenShot){ |
|
70 // Create graphics item based pixmap image but don't show it yet. |
|
71 mSendAnimationScreenShot->hide(); |
|
72 mSendAnimationScreenShot->setPos(0,0); |
|
73 mSendAnimationScreenShot->setZValue(0); |
|
74 |
|
75 // Adds or moves the item and all its childen to this scene. |
|
76 // This scene takes ownership of the item. |
|
77 mMainWindow.scene()->addItem(mSendAnimationScreenShot); |
|
78 |
|
79 // Set editor screen capture visible before old view is popped. |
|
80 // New view is drawn under this image. |
|
81 mSendAnimationScreenShot->show(); |
|
82 |
|
83 HbEffect::add(mSendAnimationScreenShot, NmSendAnimation, "mail_send"); |
|
84 } |
|
85 break; |
|
86 } |
|
87 } |
|
88 } |
|
89 |
|
90 /*! |
|
91 Function will start the selected effect. |
|
92 */ |
|
93 void NmUiEffects::startEffect(NmUiEffectType effect) |
|
94 { |
|
95 NM_FUNCTION; |
|
96 |
|
97 switch (effect) { |
|
98 case NmEditorSendMessageAnimation: { |
|
99 // Send message animation for editor view. |
|
100 if (mDoSendAnimation && mSendAnimationScreenShot) { |
|
101 mDoSendAnimation = false; |
|
102 // Start animation and connect completion signal to sendAnimationComplete slot. |
|
103 HbEffect::start(mSendAnimationScreenShot, "mail_send", this, "sendAnimationComplete"); |
|
104 } |
|
105 break; |
|
106 } |
|
107 } |
|
108 } |
|
109 |
|
110 /*! |
|
111 Generates a screenshot of the current screen. Picture is rotated |
|
112 according to the main window orientation. |
|
113 */ |
|
114 QGraphicsPixmapItem *NmUiEffects::screenShot() |
|
115 { |
|
116 NM_FUNCTION; |
|
117 |
|
118 // Grab whole view into pixmap image (also chrome is included) |
|
119 QPixmap screenCapture = QPixmap::grabWindow(mMainWindow.internalWinId()); |
|
120 QGraphicsPixmapItem *ret(NULL); |
|
121 |
|
122 // for landscape, the screenshot must be rotated |
|
123 if(mMainWindow.orientation() == Qt::Horizontal) { |
|
124 QMatrix mat; |
|
125 mat.rotate(-90); // rotate 90 degrees counter-clockwise |
|
126 ret = new QGraphicsPixmapItem(screenCapture.transformed(mat)); |
|
127 } |
|
128 else { |
|
129 ret = new QGraphicsPixmapItem(screenCapture); |
|
130 } |
|
131 |
|
132 return ret; |
|
133 } |
|
134 |
|
135 /*! |
|
136 Clean up for send animation |
|
137 */ |
|
138 void NmUiEffects::resetSendAnimation() |
|
139 { |
|
140 NM_FUNCTION; |
|
141 |
|
142 if (mSendAnimationScreenShot) { |
|
143 // Clean send animation |
|
144 HbEffect::remove(mSendAnimationScreenShot, NmSendAnimation, "mail_send"); |
|
145 // Ownership of QGraphicsPixmapItem is tranferred to GraphicsScene when it has been added |
|
146 // to it GraphicsScene. |
|
147 // GraphicsPixmapItem needs to be removed from the GraphicsScene before deleting |
|
148 // it to prevent double deletion. |
|
149 mMainWindow.scene()->removeItem(mSendAnimationScreenShot); |
|
150 delete mSendAnimationScreenShot; |
|
151 mSendAnimationScreenShot = NULL; |
|
152 mDoSendAnimation = false; |
|
153 } |
|
154 } |
|
155 |
|
156 /*! |
|
157 Slot is called when send message animation for editor view has been completed. |
|
158 */ |
|
159 void NmUiEffects::sendAnimationComplete(HbEffect::EffectStatus status) |
|
160 { |
|
161 NM_FUNCTION; |
|
162 |
|
163 Q_UNUSED(status); |
|
164 resetSendAnimation(); |
|
165 } |