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 #include <hbframeitem.h> |
|
18 #include <hbactivitymanager.h> |
|
19 |
|
20 #include "cxenamespace.h" |
|
21 #include "cxesettings.h" |
|
22 #include "cxuiscenemodeview.h" |
|
23 #include "cxuienums.h" |
|
24 #include "cxutils.h" |
|
25 #include "cxuicapturekeyhandler.h" |
|
26 #include "cxuisettingsinfo.h" |
|
27 #include "cxeviewfindercontrol.h" |
|
28 #include "cxecameradevicecontrol.h" |
|
29 #include "cxuidocumentloader.h" |
|
30 |
|
31 using namespace Cxe; |
|
32 using namespace CxUi; |
|
33 using namespace CxUiLayout; |
|
34 using namespace CxUiSettings; |
|
35 using namespace CxeSettingIds; |
|
36 |
|
37 const int CXUI_SCENES_TRANSITION_TIME = 350; // 350 milliseconds |
|
38 const int CXUI_SCENES_CAMERA_TIMEOUT = 60000; // 60 seconds for the camera hw release timeout |
|
39 const QString CXUI_SCENES_AUTOMATIC_IMAGE=":/camerax/scene_automatic.png"; |
|
40 const QString CXUI_SCENES_LANDSCAPE_IMAGE=":/camerax/scene_landscape.png"; |
|
41 const QString CXUI_SCENES_CLOSEUP_IMAGE=":/camerax/scene_close-up.png"; |
|
42 const QString CXUI_SCENES_PORTRAIT_IMAGE=":/camerax/scene_portrait.png"; |
|
43 const QString CXUI_SCENES_SPORT_IMAGE=":/camerax/scene_sport.png"; |
|
44 const QString CXUI_SCENES_NIGHT_IMAGE=":/camerax/scene_night.png"; |
|
45 const QString CXUI_SCENES_NIGHT_PORTRAIT_IMAGE=":/camerax/scene_nightportrait.png"; |
|
46 const QString CXUI_SCENES_LOW_LIGHT_IMAGE=":/camerax/scene_lowlight.png"; |
|
47 |
|
48 |
|
49 /*! |
|
50 * Constructor |
|
51 */ |
|
52 CxuiSceneModeView::CxuiSceneModeView(QGraphicsItem *parent) : |
|
53 CxuiView(parent), |
|
54 mSettingsInfo(NULL), |
|
55 mScenesBackground(NULL), |
|
56 mScenesHeading(NULL) |
|
57 { |
|
58 CX_DEBUG_IN_FUNCTION(); |
|
59 } |
|
60 |
|
61 /*! |
|
62 * Destructor |
|
63 */ |
|
64 CxuiSceneModeView::~CxuiSceneModeView() |
|
65 { |
|
66 CX_DEBUG_ENTER_FUNCTION(); |
|
67 CX_DEBUG_EXIT_FUNCTION(); |
|
68 } |
|
69 |
|
70 /*! |
|
71 * Construct-method handles initialisation tasks for this class. Needs to be called |
|
72 * before the instance of this class is used. |
|
73 * @param mainwindow |
|
74 * @param engine |
|
75 * @param documentLoader |
|
76 * @param keyHandler |
|
77 */ |
|
78 void CxuiSceneModeView::construct(HbMainWindow *mainwindow, |
|
79 CxeEngine *engine, |
|
80 CxuiDocumentLoader *documentLoader, |
|
81 CxuiCaptureKeyHandler *keyHandler, |
|
82 HbActivityManager *activityManager) |
|
83 { |
|
84 CX_DEBUG_ENTER_FUNCTION(); |
|
85 CxuiView::construct(mainwindow, engine, documentLoader, keyHandler, activityManager); |
|
86 |
|
87 mSettingsInfo = new CxuiSettingsInfo(mEngine); |
|
88 setContentFullScreen(true); |
|
89 loadDefaultWidgets(); |
|
90 |
|
91 mCameraReleaseTimer.setInterval(CXUI_SCENES_CAMERA_TIMEOUT); |
|
92 mCameraReleaseTimer.setSingleShot(true); |
|
93 connect(&mCameraReleaseTimer, SIGNAL(timeout()), this, SLOT(releaseCamera()), Qt::UniqueConnection); |
|
94 |
|
95 CX_DEBUG_EXIT_FUNCTION(); |
|
96 } |
|
97 |
|
98 /*! |
|
99 * Load widgets from DocML. |
|
100 */ |
|
101 void CxuiSceneModeView::loadDefaultWidgets() |
|
102 { |
|
103 CX_DEBUG_ENTER_FUNCTION(); |
|
104 CX_DEBUG_ASSERT(mDocumentLoader); |
|
105 |
|
106 QGraphicsWidget *widget = NULL; |
|
107 |
|
108 widget = mDocumentLoader->findWidget(SCENE_MODE_VIEW_CONTAINER); |
|
109 mScenesContainer = qobject_cast<HbWidget *> (widget); |
|
110 |
|
111 mScenesHeading = qobject_cast<HbLabel *>( |
|
112 mDocumentLoader->findWidget(SCENE_MODE_VIEW_HEADING_WIDGET)); |
|
113 CX_ASSERT_ALWAYS(mScenesHeading); |
|
114 |
|
115 //Now let's retreive the pointer to icon widget |
|
116 widget = mDocumentLoader->findWidget(SCENE_MODE_VIEW_BG_IMAGE); |
|
117 mScenesBackground = qobject_cast<HbLabel *> (widget); |
|
118 |
|
119 widget = mDocumentLoader->findWidget(SCENE_MODE_VIEW_BG_IMAGE2); |
|
120 mScenesBackground2 = qobject_cast<HbLabel *> (widget); |
|
121 |
|
122 //Assuming that the automatic scene mode is always the default one |
|
123 CX_DEBUG(("CxuiSceneModeView::loadDefaultWidgets -> Now setting default image")); |
|
124 HbIcon background(CXUI_SCENES_AUTOMATIC_IMAGE); |
|
125 background.setMirroringMode(HbIcon::LayoutDirection); |
|
126 mScenesBackground->setIcon(background); |
|
127 mScenesBackground2->setIcon(background); |
|
128 |
|
129 widget = mDocumentLoader->findWidget(SCENE_MODE_VIEW_RADIOBUTTONS); |
|
130 mScenesList = qobject_cast<CxuiSettingRadioButtonList *> (widget); |
|
131 |
|
132 mTransitionAnimation = new QPropertyAnimation(mScenesBackground2, "opacity"); |
|
133 mTransitionAnimation->setDuration(CXUI_SCENES_TRANSITION_TIME); |
|
134 |
|
135 createWidgetBackgroundGraphic(mScenesContainer, TRANSPARENT_BACKGROUND_GRAPHIC); |
|
136 |
|
137 //!@todo: View flags property is missing from HbView, |
|
138 // so can't properly hide title bar / status bar there. |
|
139 hideControls(); |
|
140 |
|
141 connectSignals(); |
|
142 |
|
143 CX_DEBUG_EXIT_FUNCTION(); |
|
144 } |
|
145 |
|
146 /*! |
|
147 * Helper function to connect signals needed in this class. |
|
148 */ |
|
149 void CxuiSceneModeView::connectSignals() |
|
150 { |
|
151 connect(mScenesList, SIGNAL(itemSelected(int)), this, SLOT(handleSceneRadiobuttonPress(int))); |
|
152 connect(mTransitionAnimation, SIGNAL(finished()), this, SLOT(finishScenesTransition())); |
|
153 } |
|
154 |
|
155 /*! |
|
156 * This public method assumes that the view is already properly constructed |
|
157 */ |
|
158 void CxuiSceneModeView::loadBackgroundImages() |
|
159 { |
|
160 CX_DEBUG_ENTER_FUNCTION(); |
|
161 RadioButtonListParams data; |
|
162 if (mEngine->mode() == Cxe::ImageMode) { |
|
163 mSettingsInfo->getSettingsContent(CxeSettingIds::IMAGE_SCENE, data); |
|
164 } else { |
|
165 mSettingsInfo->getSettingsContent(CxeSettingIds::VIDEO_SCENE, data); |
|
166 } |
|
167 mSettingPairList = data.mSettingPairList; |
|
168 mScenesList->init(&data); |
|
169 |
|
170 if (mScenesHeading) { |
|
171 mScenesHeading->setPlainText(data.mHeading); |
|
172 } |
|
173 |
|
174 if (mScenesBackground) { |
|
175 QString sceneId = mEngine->settings().get<QString>(data.mSettingId); |
|
176 HbIcon background(backgroundForScene(sceneId)); |
|
177 background.setMirroringMode(HbIcon::LayoutDirection); |
|
178 mScenesBackground->setIcon(background); |
|
179 } else { |
|
180 //First time displaying a list |
|
181 //Assuming that the automatic scene mode is always the default one and is on top of the list |
|
182 mScenesList->setSelected(0); |
|
183 } |
|
184 CX_DEBUG_EXIT_FUNCTION(); |
|
185 } |
|
186 |
|
187 /*! |
|
188 * Save view state to activity. Scene mode view doesn't have it's own activity, just save |
|
189 * correct pre-capture view. |
|
190 */ |
|
191 void CxuiSceneModeView::saveActivity() |
|
192 { |
|
193 CX_DEBUG_ENTER_FUNCTION(); |
|
194 QVariantMap data; |
|
195 QVariantHash params; |
|
196 |
|
197 //@todo: add pre-capture icon as screenshot |
|
198 if (mEngine->mode() == Cxe::ImageMode) { |
|
199 mActivityManager->removeActivity(CxuiActivityIds::STILL_PRECAPTURE_ACTIVITY); |
|
200 mActivityManager->addActivity(CxuiActivityIds::STILL_PRECAPTURE_ACTIVITY, data, params); |
|
201 } else { |
|
202 mActivityManager->removeActivity(CxuiActivityIds::VIDEO_PRECAPTURE_ACTIVITY); |
|
203 mActivityManager->addActivity(CxuiActivityIds::VIDEO_PRECAPTURE_ACTIVITY, data, params); |
|
204 } |
|
205 |
|
206 CX_DEBUG_EXIT_FUNCTION(); |
|
207 } |
|
208 |
|
209 /*! |
|
210 * Handle selecting value in scene list. |
|
211 */ |
|
212 void CxuiSceneModeView::handleSceneRadiobuttonPress(int index) |
|
213 { |
|
214 CX_DEBUG_ENTER_FUNCTION(); |
|
215 |
|
216 CxUiSettings::SettingItem item = mSettingPairList.at(index); |
|
217 QString sceneId = item.mValue.toString(); |
|
218 HbIcon background(backgroundForScene(sceneId)); |
|
219 background.setMirroringMode(HbIcon::LayoutDirection); |
|
220 mScenesBackground2->setIcon(background); |
|
221 startBackgroundTransition(); |
|
222 CX_DEBUG_EXIT_FUNCTION(); |
|
223 } |
|
224 |
|
225 |
|
226 /*! |
|
227 * Helper method for getting the background graphic name |
|
228 * for each of the scenes. |
|
229 */ |
|
230 QString CxuiSceneModeView::backgroundForScene(const QString& sceneId) |
|
231 { |
|
232 //!@todo: This mapping should be added to the setting xml. |
|
233 if (sceneId == Cxe::IMAGE_SCENE_AUTO) { |
|
234 return CXUI_SCENES_AUTOMATIC_IMAGE; |
|
235 } else if (sceneId == Cxe::IMAGE_SCENE_PORTRAIT) { |
|
236 return CXUI_SCENES_PORTRAIT_IMAGE; |
|
237 } else if (sceneId == Cxe::IMAGE_SCENE_SCENERY) { |
|
238 return CXUI_SCENES_LANDSCAPE_IMAGE; |
|
239 } else if (sceneId == Cxe::IMAGE_SCENE_MACRO) { |
|
240 return CXUI_SCENES_CLOSEUP_IMAGE; |
|
241 } else if (sceneId == Cxe::IMAGE_SCENE_SPORTS) { |
|
242 return CXUI_SCENES_SPORT_IMAGE; |
|
243 } else if (sceneId == Cxe::IMAGE_SCENE_NIGHT) { |
|
244 return CXUI_SCENES_NIGHT_IMAGE; |
|
245 } else if (sceneId == Cxe::IMAGE_SCENE_NIGHTPORTRAIT) { |
|
246 return CXUI_SCENES_NIGHT_PORTRAIT_IMAGE; |
|
247 } else if (sceneId == Cxe::VIDEO_SCENE_AUTO) { |
|
248 return CXUI_SCENES_AUTOMATIC_IMAGE; |
|
249 } else if (sceneId == Cxe::VIDEO_SCENE_LOWLIGHT) { |
|
250 return CXUI_SCENES_LOW_LIGHT_IMAGE; |
|
251 } else if (sceneId == Cxe::VIDEO_SCENE_NIGHT) { |
|
252 return CXUI_SCENES_NIGHT_IMAGE; |
|
253 } else { |
|
254 return ""; |
|
255 } |
|
256 |
|
257 } |
|
258 |
|
259 /*! |
|
260 * Start animation for changing the scene background graphic. |
|
261 */ |
|
262 void CxuiSceneModeView::startBackgroundTransition() |
|
263 { |
|
264 mTransitionAnimation->setStartValue(0.0); |
|
265 mTransitionAnimation->setEndValue(1.0); |
|
266 mTransitionAnimation->start(); |
|
267 |
|
268 } |
|
269 |
|
270 /*! |
|
271 * Handle scene background graphic animation finishing. |
|
272 */ |
|
273 void CxuiSceneModeView::finishScenesTransition() |
|
274 { |
|
275 mScenesBackground->setIcon(mScenesBackground2->icon()); |
|
276 mScenesBackground2->setOpacity(0); |
|
277 mScenesBackground2->setIcon(HbIcon()); |
|
278 } |
|
279 |
|
280 /*! |
|
281 * Handle press of ok button. |
|
282 */ |
|
283 void CxuiSceneModeView::handleOkButtonPress() |
|
284 { |
|
285 CX_DEBUG_ENTER_FUNCTION(); |
|
286 mScenesList->handleSelectionAccepted(); |
|
287 closeView(); |
|
288 CX_DEBUG_EXIT_FUNCTION(); |
|
289 } |
|
290 |
|
291 /*! |
|
292 * Handle press of cancel button. |
|
293 */ |
|
294 void CxuiSceneModeView::handleCancelButtonPress() |
|
295 { |
|
296 CX_DEBUG_ENTER_FUNCTION(); |
|
297 closeView(); |
|
298 CX_DEBUG_EXIT_FUNCTION(); |
|
299 } |
|
300 |
|
301 /*! |
|
302 * This view is about to be shown. |
|
303 * Update the view to match currently selected scene. |
|
304 */ |
|
305 void CxuiSceneModeView::showEvent(QShowEvent *event) |
|
306 { |
|
307 CX_DEBUG_ENTER_FUNCTION(); |
|
308 mScenesList->scrollTo(mScenesList->currentIndex(), HbAbstractItemView::PositionAtTop); |
|
309 |
|
310 mEngine->viewfinderControl().stop(); |
|
311 mCameraReleaseTimer.start(); |
|
312 QGraphicsWidget::showEvent(event); |
|
313 CX_DEBUG_EXIT_FUNCTION(); |
|
314 } |
|
315 |
|
316 /*! |
|
317 * Allow showing UI controls? |
|
318 * Title bar and other UI chrome is never shown in scene mode view. |
|
319 */ |
|
320 bool CxuiSceneModeView::allowShowControls() const |
|
321 { |
|
322 return false; |
|
323 } |
|
324 |
|
325 /*! |
|
326 * Play feedback when touching view outside of any widget? |
|
327 * Feedback is not played in scene mode view. |
|
328 */ |
|
329 bool CxuiSceneModeView::isFeedbackEnabled() const |
|
330 { |
|
331 return false; |
|
332 } |
|
333 |
|
334 /*! |
|
335 * Slot to handle capture key full press. |
|
336 */ |
|
337 void CxuiSceneModeView::handleCaptureKeyPressed() |
|
338 { |
|
339 CX_DEBUG_ENTER_FUNCTION(); |
|
340 closeView(); |
|
341 CX_DEBUG_EXIT_FUNCTION(); |
|
342 } |
|
343 |
|
344 /*! |
|
345 * Slot to handle capture key half press / autofocus key press. |
|
346 */ |
|
347 void CxuiSceneModeView::handleAutofocusKeyPressed() |
|
348 { |
|
349 CX_DEBUG_ENTER_FUNCTION(); |
|
350 closeView(); |
|
351 CX_DEBUG_EXIT_FUNCTION(); |
|
352 } |
|
353 |
|
354 /*! |
|
355 * Closing the view and reactivating camera hw if needed |
|
356 */ |
|
357 void CxuiSceneModeView::closeView() |
|
358 { |
|
359 CX_DEBUG_ENTER_FUNCTION(); |
|
360 mScenesList->handleClose(); |
|
361 mScenesBackground->setIcon(HbIcon()); |
|
362 mScenesHeading = NULL; |
|
363 emit viewCloseEvent(); |
|
364 CX_DEBUG_EXIT_FUNCTION(); |
|
365 } |
|
366 |
|
367 // end of file |
|
368 |
|